Spaces:
Running
Running
Update index.html
Browse files- index.html +36 -15
index.html
CHANGED
@@ -130,7 +130,7 @@ document.body.appendChild(vrButton);
|
|
130 |
|
131 |
vrButton.addEventListener("click", createXRExperience);
|
132 |
|
133 |
-
|
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 |
-
//
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
if (pickResult.
|
150 |
-
|
151 |
-
|
152 |
-
|
153 |
-
|
|
|
|
|
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
|