SamSak09 commited on
Commit
e4676ce
·
verified ·
1 Parent(s): 0075662

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +29 -16
index.html CHANGED
@@ -81,8 +81,8 @@
81
 
82
  const gridHelper = new THREE.GridHelper(100, 100, 0xcccccc, 0xcccccc);
83
  scene.add(gridHelper);
84
-
85
- // --- 3. CREATE THE 3D MANNEQUIN ---
86
  const maxPoints = 22;
87
  const boneConnections = [
88
  0,1, 0,2, 0,3,
@@ -95,29 +95,33 @@
95
  18,20, 19,21
96
  ];
97
 
98
- const jointMaterial = new THREE.MeshStandardMaterial({ color: 0x008080, roughness: 0.3, metalness: 0.2 });
99
- const boneMaterial = new THREE.MeshStandardMaterial({ color: 0xbbbbbb, roughness: 0.5, metalness: 0.1 });
 
100
 
101
  const jointMeshes = [];
102
- const sphereGeo = new THREE.SphereGeometry(0.04, 16, 16);
 
103
  for (let i = 0; i < maxPoints; i++) {
104
  const sphere = new THREE.Mesh(sphereGeo, jointMaterial);
105
- sphere.castShadow = true; // JOINTS CAST SHADOWS
106
  scene.add(sphere);
107
  jointMeshes.push(sphere);
108
  }
109
 
110
  const boneMeshes = [];
111
- const cylinderGeo = new THREE.CylinderGeometry(0.02, 0.02, 1, 8);
112
- cylinderGeo.rotateX(Math.PI / 2);
 
 
113
 
114
  for (let i = 0; i < boneConnections.length; i += 2) {
115
- const cylinder = new THREE.Mesh(cylinderGeo, boneMaterial);
116
- cylinder.castShadow = true; // BONES CAST SHADOWS
117
- scene.add(cylinder);
118
- boneMeshes.push(cylinder);
119
  }
120
-
121
  // --- 4. ANIMATION & STATE LOGIC ---
122
  let motionData = [];
123
  let currentFrame = 0;
@@ -203,11 +207,14 @@
203
  socketStatus.innerHTML = "🔴 Disconnected";
204
  socketStatus.style.color = "red";
205
  };
 
 
206
 
207
  ws.onmessage = (event) => {
208
  const data = JSON.parse(event.data);
209
 
210
- if (data.status === "success" && data.data) {
 
211
  motionData = data.data;
212
  currentFrame = 0;
213
  isPlaying = true;
@@ -217,12 +224,15 @@
217
  document.getElementById('payloadSize').textContent = `Payload Size: ${kbSize} KB`;
218
  statusText.textContent = "Rendering...";
219
  statusText.style.color = "teal";
 
 
220
  }
221
  };
222
 
223
  let typingTimer;
224
  const inputField = document.getElementById('promptInput');
225
 
 
226
  inputField.addEventListener('input', () => {
227
  clearTimeout(typingTimer);
228
  statusText.textContent = "Typing...";
@@ -232,13 +242,16 @@
232
  const promptText = inputField.value.trim();
233
 
234
  if (promptText.length > 0 && ws.readyState === WebSocket.OPEN) {
 
 
235
  statusText.textContent = "Transmitting to Edge GPU...";
236
- ws.send(JSON.stringify({ prompt: promptText }));
 
237
  } else if (promptText.length === 0) {
238
  statusText.textContent = "Waiting for input...";
239
  statusText.style.color = "teal";
240
  }
241
- }, 300); // Reduced debounce for a slightly snappier feel
242
  });
243
  </script>
244
  </body>
 
81
 
82
  const gridHelper = new THREE.GridHelper(100, 100, 0xcccccc, 0xcccccc);
83
  scene.add(gridHelper);
84
+
85
+ // --- 3. CREATE THE 3D MANNEQUIN (UPGRADED MESH) ---
86
  const maxPoints = 22;
87
  const boneConnections = [
88
  0,1, 0,2, 0,3,
 
95
  18,20, 19,21
96
  ];
97
 
98
+ // Give the mesh a sleek, modern plastic look
99
+ const jointMaterial = new THREE.MeshStandardMaterial({ color: 0x333333, roughness: 0.2, metalness: 0.8 });
100
+ const boneMaterial = new THREE.MeshStandardMaterial({ color: 0xe0e0e0, roughness: 0.5, metalness: 0.1 });
101
 
102
  const jointMeshes = [];
103
+ // Make joints larger to look like robotic hinges
104
+ const sphereGeo = new THREE.SphereGeometry(0.08, 32, 32);
105
  for (let i = 0; i < maxPoints; i++) {
106
  const sphere = new THREE.Mesh(sphereGeo, jointMaterial);
107
+ sphere.castShadow = true;
108
  scene.add(sphere);
109
  jointMeshes.push(sphere);
110
  }
111
 
112
  const boneMeshes = [];
113
+ // UPGRADE: Use CapsuleGeometry instead of thin cylinders for realistic body volume
114
+ // Arguments: radius, length, cap segments, radial segments
115
+ const capsuleGeo = new THREE.CylinderGeometry(0.06, 0.06, 1, 16);
116
+ capsuleGeo.rotateX(Math.PI / 2);
117
 
118
  for (let i = 0; i < boneConnections.length; i += 2) {
119
+ const boneMesh = new THREE.Mesh(capsuleGeo, boneMaterial);
120
+ boneMesh.castShadow = true;
121
+ scene.add(boneMesh);
122
+ boneMeshes.push(boneMesh);
123
  }
124
+
125
  // --- 4. ANIMATION & STATE LOGIC ---
126
  let motionData = [];
127
  let currentFrame = 0;
 
207
  socketStatus.innerHTML = "🔴 Disconnected";
208
  socketStatus.style.color = "red";
209
  };
210
+ // --- INSIDE index.html ---
211
+ let currentTicket = 0; // Keep track of the newest request
212
 
213
  ws.onmessage = (event) => {
214
  const data = JSON.parse(event.data);
215
 
216
+ // SECURITY CHECK: Only play the animation if the ticket matches our latest request!
217
+ if (data.status === "success" && data.ticket === currentTicket && data.data) {
218
  motionData = data.data;
219
  currentFrame = 0;
220
  isPlaying = true;
 
224
  document.getElementById('payloadSize').textContent = `Payload Size: ${kbSize} KB`;
225
  statusText.textContent = "Rendering...";
226
  statusText.style.color = "teal";
227
+ } else if (data.ticket !== currentTicket) {
228
+ console.log(`Dropped outdated packet. Ticket: ${data.ticket}, Current: ${currentTicket}`);
229
  }
230
  };
231
 
232
  let typingTimer;
233
  const inputField = document.getElementById('promptInput');
234
 
235
+ // Back to live listening!
236
  inputField.addEventListener('input', () => {
237
  clearTimeout(typingTimer);
238
  statusText.textContent = "Typing...";
 
242
  const promptText = inputField.value.trim();
243
 
244
  if (promptText.length > 0 && ws.readyState === WebSocket.OPEN) {
245
+ currentTicket++; // Generate a new ticket number for this specific word
246
+
247
  statusText.textContent = "Transmitting to Edge GPU...";
248
+ // Send the text AND the ticket number
249
+ ws.send(JSON.stringify({ prompt: promptText, ticket: currentTicket }));
250
  } else if (promptText.length === 0) {
251
  statusText.textContent = "Waiting for input...";
252
  statusText.style.color = "teal";
253
  }
254
+ }, 400); // 400ms debounce: waits just long enough for you to finish a word
255
  });
256
  </script>
257
  </body>