awacke1 commited on
Commit
d2956fc
·
verified ·
1 Parent(s): 9008de2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -25
app.py CHANGED
@@ -7,7 +7,6 @@ def load_aframe_and_extras():
7
  return """
8
  <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
9
  <script src="https://unpkg.com/[email protected]/dist/aframe-event-set-component.min.js"></script>
10
- <script src="https://unpkg.com/[email protected]/dist/aframe-look-at-component.min.js"></script>
11
  <script>
12
  let score = 0;
13
  let selectedEntity = null;
@@ -68,57 +67,50 @@ def load_aframe_and_extras():
68
  var rig = document.querySelector('#rig');
69
  var gw = 8, gh = 8;
70
  var center = {x: 0, y: 0, z: 0};
71
- var height = Math.max(gw, gh) * 1.5;
72
- var distance = Math.max(gw, gh) * 2; // Further increased distance to ensure the entire tilemap is in view
73
- var pos;
74
 
75
  switch(view) {
76
  case 'top':
77
  pos = {x: center.x, y: height, z: center.z};
78
- rig.setAttribute('position', pos);
79
- rig.setAttribute('rotation', {x: -90, y: 0, z: 0});
80
  break;
81
  case 'left':
82
  pos = {x: -distance, y: height, z: center.z};
83
- rig.setAttribute('position', pos);
84
- rig.setAttribute('look-at', center);
85
  break;
86
  case 'right':
87
  pos = {x: distance, y: height, z: center.z};
88
- rig.setAttribute('position', pos);
89
- rig.setAttribute('look-at', center);
90
  break;
91
  case 'front':
92
  pos = {x: center.x, y: height, z: -distance};
93
- rig.setAttribute('position', pos);
94
- rig.setAttribute('look-at', center);
95
  break;
96
  case 'back':
97
  pos = {x: center.x, y: height, z: distance};
98
- rig.setAttribute('position', pos);
99
- rig.setAttribute('look-at', center);
100
  break;
101
  case 'angle1':
102
  pos = {x: -distance, y: height, z: -distance};
103
- rig.setAttribute('position', pos);
104
- rig.setAttribute('look-at', center);
105
  break;
106
  case 'angle2':
107
  pos = {x: distance, y: height, z: -distance};
108
- rig.setAttribute('position', pos);
109
- rig.setAttribute('look-at', center);
110
  break;
111
  case 'angle3':
112
  pos = {x: -distance, y: height, z: distance};
113
- rig.setAttribute('position', pos);
114
- rig.setAttribute('look-at', center);
115
  break;
116
  case 'angle4':
117
  pos = {x: distance, y: height, z: distance};
118
- rig.setAttribute('position', pos);
119
- rig.setAttribute('look-at', center);
120
  break;
121
  }
 
 
122
  }
123
 
124
  function flyCamera(action) {
@@ -246,13 +238,11 @@ def generate_tilemap(files, dirpath, gw=8, gh=8):
246
 
247
  entities = ""
248
  if vids:
249
- # Use the first video as a large ground plane
250
  v = vids[0]; s = Path(v).stem
251
  entities += (f'<a-video src="#{s}" width="{gw}" height="{gh}" '
252
  f'rotation="-90 0 0" position="0 0.05 0" '
253
  'loop autoplay></a-video>')
254
  else:
255
- # Generate individual tiles if no video
256
  sx = -gw/2; sz = -gh/2
257
  for i in range(gw):
258
  for j in range(gh):
@@ -261,7 +251,6 @@ def generate_tilemap(files, dirpath, gw=8, gh=8):
261
  img = random.choice(imgs); s = Path(img).stem
262
  entities += (f'<a-plane src="#{s}" width="1" height="1" '
263
  f'rotation="-90 0 0" position="{x} 0 {z}"></a-plane>')
264
- # Always generate models
265
  sx = -gw/2; sz = -gh/2
266
  for i in range(gw):
267
  for j in range(gh):
 
7
  return """
8
  <script src="https://aframe.io/releases/1.2.0/aframe.min.js"></script>
9
  <script src="https://unpkg.com/[email protected]/dist/aframe-event-set-component.min.js"></script>
 
10
  <script>
11
  let score = 0;
12
  let selectedEntity = null;
 
67
  var rig = document.querySelector('#rig');
68
  var gw = 8, gh = 8;
69
  var center = {x: 0, y: 0, z: 0};
70
+ var height = Math.max(gw, gh) * 1.5; // y=12, high enough to see models
71
+ var distance = Math.max(gw, gh) * 2; // x/z distance=16, far enough to fit the tilemap
72
+ var pos, rot;
73
 
74
  switch(view) {
75
  case 'top':
76
  pos = {x: center.x, y: height, z: center.z};
77
+ rot = {x: -90, y: 0, z: 0};
 
78
  break;
79
  case 'left':
80
  pos = {x: -distance, y: height, z: center.z};
81
+ rot = {x: 0, y: 90, z: 0}; // Face right (towards center), y-axis up
 
82
  break;
83
  case 'right':
84
  pos = {x: distance, y: height, z: center.z};
85
+ rot = {x: 0, y: -90, z: 0}; // Face left (towards center), y-axis up
 
86
  break;
87
  case 'front':
88
  pos = {x: center.x, y: height, z: -distance};
89
+ rot = {x: 0, y: 0, z: 0}; // Face forward (towards center), y-axis up
 
90
  break;
91
  case 'back':
92
  pos = {x: center.x, y: height, z: distance};
93
+ rot = {x: 0, y: 180, z: 0}; // Face backward (towards center), y-axis up
 
94
  break;
95
  case 'angle1':
96
  pos = {x: -distance, y: height, z: -distance};
97
+ rot = {x: 0, y: 45, z: 0}; // Face towards center from top-left corner
 
98
  break;
99
  case 'angle2':
100
  pos = {x: distance, y: height, z: -distance};
101
+ rot = {x: 0, y: -45, z: 0}; // Face towards center from top-right corner
 
102
  break;
103
  case 'angle3':
104
  pos = {x: -distance, y: height, z: distance};
105
+ rot = {x: 0, y: 135, z: 0}; // Face towards center from bottom-left corner
 
106
  break;
107
  case 'angle4':
108
  pos = {x: distance, y: height, z: distance};
109
+ rot = {x: 0, y: -135, z: 0}; // Face towards center from bottom-right corner
 
110
  break;
111
  }
112
+ rig.setAttribute('position', pos);
113
+ rig.setAttribute('rotation', rot);
114
  }
115
 
116
  function flyCamera(action) {
 
238
 
239
  entities = ""
240
  if vids:
 
241
  v = vids[0]; s = Path(v).stem
242
  entities += (f'<a-video src="#{s}" width="{gw}" height="{gh}" '
243
  f'rotation="-90 0 0" position="0 0.05 0" '
244
  'loop autoplay></a-video>')
245
  else:
 
246
  sx = -gw/2; sz = -gh/2
247
  for i in range(gw):
248
  for j in range(gh):
 
251
  img = random.choice(imgs); s = Path(img).stem
252
  entities += (f'<a-plane src="#{s}" width="1" height="1" '
253
  f'rotation="-90 0 0" position="{x} 0 {z}"></a-plane>')
 
254
  sx = -gw/2; sz = -gh/2
255
  for i in range(gw):
256
  for j in range(gh):