Metaprime commited on
Commit
2a4cdc9
·
verified ·
1 Parent(s): 8d78746

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +42 -15
index.html CHANGED
@@ -39,9 +39,8 @@
39
 
40
  <script>
41
  let videoPlanes = [];
42
- let spawnIndex = 0;
43
  let selectedPlane = null;
44
- let isDragging = false;
45
 
46
  function togglePanel() {
47
  const p = document.getElementById('panel');
@@ -53,9 +52,7 @@
53
  document.getElementById('mediaInput').click();
54
  }
55
 
56
- function launchSky() {
57
- document.getElementById('mediaInput').click();
58
- }
59
 
60
  document.getElementById('mediaInput').addEventListener('change', function(e) {
61
  const file = e.target.files[0];
@@ -69,7 +66,7 @@
69
  plane.setAttribute('height', '7');
70
  plane.setAttribute('position', '0 5 -12');
71
  plane.setAttribute('material', 'shader:flat; side:double; color:#fff');
72
- plane.setAttribute('class', 'draggable');
73
 
74
  scene.appendChild(plane);
75
 
@@ -80,7 +77,7 @@
80
 
81
  const texture = new THREE.VideoTexture(video);
82
 
83
- video.onloadeddata = function() {
84
  const mesh = plane.object3DMap.mesh;
85
  if (mesh && mesh.material) {
86
  mesh.material.map = texture;
@@ -91,22 +88,52 @@
91
 
92
  video.load();
93
 
94
- const planeData = { plane: plane, video: video, texture: texture, name: file.name };
95
- videoPlanes.push(planeData);
96
- spawnIndex++;
97
-
98
- alert(`✅ Video plane created - drag it to reposition`);
99
  });
100
 
101
- // Mouse dragging support
102
  document.addEventListener('mousedown', (e) => {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
  const raycaster = new THREE.Raycaster();
104
  const mouse = new THREE.Vector2(
105
  (e.clientX / window.innerWidth) * 2 - 1,
106
  -(e.clientY / window.innerHeight) * 2 + 1
107
  );
108
- raycaster.setFromCamera(mouse, document.querySelector('a-scene').camera);
109
- // Simple raycasting logic would go here
 
 
 
 
 
 
 
 
 
 
110
  });
111
  </script>
112
  </body>
 
39
 
40
  <script>
41
  let videoPlanes = [];
 
42
  let selectedPlane = null;
43
+ let offset = new THREE.Vector3();
44
 
45
  function togglePanel() {
46
  const p = document.getElementById('panel');
 
52
  document.getElementById('mediaInput').click();
53
  }
54
 
55
+ function launchSky() { document.getElementById('mediaInput').click(); }
 
 
56
 
57
  document.getElementById('mediaInput').addEventListener('change', function(e) {
58
  const file = e.target.files[0];
 
66
  plane.setAttribute('height', '7');
67
  plane.setAttribute('position', '0 5 -12');
68
  plane.setAttribute('material', 'shader:flat; side:double; color:#fff');
69
+ plane.setAttribute('class', 'video-plane');
70
 
71
  scene.appendChild(plane);
72
 
 
77
 
78
  const texture = new THREE.VideoTexture(video);
79
 
80
+ video.onloadeddata = () => {
81
  const mesh = plane.object3DMap.mesh;
82
  if (mesh && mesh.material) {
83
  mesh.material.map = texture;
 
88
 
89
  video.load();
90
 
91
+ videoPlanes.push({plane, video, texture, name: file.name});
 
 
 
 
92
  });
93
 
94
+ // Click to select + drag to move
95
  document.addEventListener('mousedown', (e) => {
96
+ const scene = document.querySelector('a-scene');
97
+ const raycaster = new THREE.Raycaster();
98
+ const mouse = new THREE.Vector2(
99
+ (e.clientX / window.innerWidth) * 2 - 1,
100
+ -(e.clientY / window.innerHeight) * 2 + 1
101
+ );
102
+
103
+ raycaster.setFromCamera(mouse, scene.camera);
104
+ const intersects = raycaster.intersectObjects(scene.object3D.children, true);
105
+
106
+ if (intersects.length > 0) {
107
+ const obj = intersects[0].object;
108
+ const plane = videoPlanes.find(p => p.plane.object3D === obj || p.plane.object3D.children.includes(obj));
109
+ if (plane) {
110
+ selectedPlane = plane.plane;
111
+ offset.copy(intersects[0].point).sub(selectedPlane.object3D.position);
112
+ }
113
+ }
114
+ });
115
+
116
+ document.addEventListener('mousemove', (e) => {
117
+ if (!selectedPlane) return;
118
+
119
+ const scene = document.querySelector('a-scene');
120
  const raycaster = new THREE.Raycaster();
121
  const mouse = new THREE.Vector2(
122
  (e.clientX / window.innerWidth) * 2 - 1,
123
  -(e.clientY / window.innerHeight) * 2 + 1
124
  );
125
+
126
+ raycaster.setFromCamera(mouse, scene.camera);
127
+ const intersects = raycaster.intersectObject(scene.object3D, true);
128
+
129
+ if (intersects.length > 0) {
130
+ selectedPlane.object3D.position.copy(intersects[0].point.sub(offset));
131
+ selectedPlane.object3D.position.y = Math.max(2, selectedPlane.object3D.position.y);
132
+ }
133
+ });
134
+
135
+ document.addEventListener('mouseup', () => {
136
+ selectedPlane = null;
137
  });
138
  </script>
139
  </body>