Spaces:
Running
Running
Update index.html
Browse files- index.html +17 -2
index.html
CHANGED
@@ -136,14 +136,28 @@ vrButton.addEventListener("click", createXRExperience);
|
|
136 |
const xrRay = motionController.getComponent("xr-standard-trigger");
|
137 |
|
138 |
if (xrRay) {
|
|
|
|
|
139 |
xrRay.onButtonStateChangedObservable.add(() => {
|
140 |
-
if (xrRay.pressed) {
|
|
|
|
|
|
|
141 |
const pickResult = scene.pickWithRay(controller.pointerRay);
|
|
|
142 |
if (pickResult.hit && pickResult.pickedMesh) {
|
143 |
if (pickResult.pickedMesh.name === "npc1") {
|
144 |
-
|
|
|
|
|
|
|
145 |
}
|
146 |
}
|
|
|
|
|
|
|
|
|
|
|
147 |
}
|
148 |
});
|
149 |
}
|
@@ -152,6 +166,7 @@ vrButton.addEventListener("click", createXRExperience);
|
|
152 |
}
|
153 |
|
154 |
|
|
|
155 |
// Chat System with Transformers.js
|
156 |
async function setupChat() {
|
157 |
try {
|
|
|
136 |
const xrRay = motionController.getComponent("xr-standard-trigger");
|
137 |
|
138 |
if (xrRay) {
|
139 |
+
let isProcessing = false; // Debounce flag
|
140 |
+
|
141 |
xrRay.onButtonStateChangedObservable.add(() => {
|
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 |
}
|
|
|
166 |
}
|
167 |
|
168 |
|
169 |
+
|
170 |
// Chat System with Transformers.js
|
171 |
async function setupChat() {
|
172 |
try {
|