AEUPH commited on
Commit
0e33eb6
·
verified ·
1 Parent(s): 9592a40

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +36 -15
index.html CHANGED
@@ -130,7 +130,7 @@ document.body.appendChild(vrButton);
130
 
131
  vrButton.addEventListener("click", createXRExperience);
132
 
133
- function setupControllerInteractions(xrHelper) {
134
  xrHelper.input.onControllerAddedObservable.add(controller => {
135
  controller.onMotionControllerInitObservable.add(motionController => {
136
  const xrRay = motionController.getComponent("xr-standard-trigger");
@@ -142,22 +142,26 @@ vrButton.addEventListener("click", createXRExperience);
142
  if (xrRay.pressed && !isProcessing) {
143
  isProcessing = true;
144
 
145
- // Perform ray pick with minimal processing
146
- const pickResult = scene.pickWithRay(controller.pointerRay);
147
-
148
- if (pickResult.hit && pickResult.pickedMesh) {
149
- if (pickResult.pickedMesh.name === "npc1") {
150
- // Defer chat opening to avoid mid-frame changes
151
- setTimeout(() => {
152
- openChat("npc1", "NPC-1", "Hello! How can I assist you today?");
153
- }, 0);
 
 
154
  }
 
 
 
 
 
 
 
155
  }
156
-
157
- // Allow further interactions after a short delay
158
- setTimeout(() => {
159
- isProcessing = false;
160
- }, 200); // Adjust delay as necessary
161
  }
162
  });
163
  }
@@ -165,6 +169,23 @@ vrButton.addEventListener("click", createXRExperience);
165
  });
166
  }
167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
168
 
169
 
170
  // Chat System with Transformers.js
 
130
 
131
  vrButton.addEventListener("click", createXRExperience);
132
 
133
+ function setupControllerInteractions(xrHelper) {
134
  xrHelper.input.onControllerAddedObservable.add(controller => {
135
  controller.onMotionControllerInitObservable.add(motionController => {
136
  const xrRay = motionController.getComponent("xr-standard-trigger");
 
142
  if (xrRay.pressed && !isProcessing) {
143
  isProcessing = true;
144
 
145
+ // Use a try-catch block to handle any unexpected errors
146
+ try {
147
+ const pickResult = scene.pickWithRay(controller.pointerRay);
148
+
149
+ if (pickResult.hit && pickResult.pickedMesh) {
150
+ if (pickResult.pickedMesh.name === "npc1") {
151
+ // Defer chat opening to avoid mid-frame changes
152
+ setTimeout(() => {
153
+ openChat("npc1", "NPC-1", "Hello! How can I assist you today?");
154
+ }, 0);
155
+ }
156
  }
157
+ } catch (err) {
158
+ console.error('Error during ray interaction:', err);
159
+ } finally {
160
+ // Allow further interactions after a short delay
161
+ setTimeout(() => {
162
+ isProcessing = false;
163
+ }, 200); // Adjust delay as necessary
164
  }
 
 
 
 
 
165
  }
166
  });
167
  }
 
169
  });
170
  }
171
 
172
+ // Ensure the camera controls are reset when exiting VR mode
173
+ xrHelper.baseExperience.onExitXRObservable.add(() => {
174
+ scene.activeCamera.attachControl(canvas, true);
175
+ engine.resize();
176
+ });
177
+
178
+ engine.runRenderLoop(function () {
179
+ if (scene.activeCamera) {
180
+ scene.render();
181
+ }
182
+ });
183
+
184
+ window.addEventListener("resize", function () {
185
+ if (engine) {
186
+ engine.resize();
187
+ }
188
+ });
189
 
190
 
191
  // Chat System with Transformers.js