Spaces:
Running
Running
Update index.html
Browse files- index.html +55 -58
index.html
CHANGED
@@ -91,63 +91,60 @@
|
|
91 |
engine.resize();
|
92 |
});
|
93 |
|
|
|
94 |
async function createXRExperience() {
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
vrButton.style.height = "40px";
|
125 |
-
vrButton.style.background = "linear-gradient(to bottom, #6c543e, #4e342e)";
|
126 |
-
vrButton.style.color = "#e0d7c5";
|
127 |
-
vrButton.style.border = "none";
|
128 |
-
vrButton.style.cursor = "pointer";
|
129 |
-
document.body.appendChild(vrButton);
|
130 |
-
|
131 |
-
vrButton.addEventListener("click", createXRExperience);
|
132 |
|
133 |
function setupControllerInteractions(xrHelper) {
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
|
147 |
-
|
148 |
-
|
149 |
-
|
150 |
-
|
|
|
|
|
|
|
|
|
151 |
|
152 |
// Chat System with Transformers.js
|
153 |
async function setupChat() {
|
@@ -170,7 +167,7 @@
|
|
170 |
const message = inputField.value;
|
171 |
if (message.trim() === "" || !chatSetup) return;
|
172 |
|
173 |
-
chatLog.innerHTML +=
|
174 |
inputField.value = "";
|
175 |
|
176 |
const { model, tokenizer } = await chatSetup;
|
@@ -178,7 +175,7 @@
|
|
178 |
const response = await model.generate(inputs.input_ids, { max_length: 50 });
|
179 |
const output = tokenizer.decode(response[0], { skip_special_tokens: true });
|
180 |
|
181 |
-
chatLog.innerHTML +=
|
182 |
chatLog.scrollTop = chatLog.scrollHeight;
|
183 |
|
184 |
// Limit chat log entries to 50
|
@@ -189,9 +186,9 @@
|
|
189 |
|
190 |
function openChat(npcId, npcName, greeting) {
|
191 |
const chatLog = document.getElementById("chatLog");
|
192 |
-
chatLog.innerHTML +=
|
193 |
}
|
194 |
</script>
|
195 |
</body>
|
196 |
|
197 |
-
</html>
|
|
|
91 |
engine.resize();
|
92 |
});
|
93 |
|
94 |
+
// Initialize VR experience without unused features
|
95 |
async function createXRExperience() {
|
96 |
+
try {
|
97 |
+
const xrHelper = await scene.createDefaultXRExperienceAsync({
|
98 |
+
floorMeshes: [scene.getMeshByName("ground")]
|
99 |
+
// No optional features like hand-tracking or plane-detection are requested
|
100 |
+
});
|
101 |
+
|
102 |
+
setupControllerInteractions(xrHelper);
|
103 |
+
scene.activeCamera = xrHelper.baseExperience.camera;
|
104 |
+
|
105 |
+
} catch (err) {
|
106 |
+
console.error('Failed to start VR session:', err);
|
107 |
+
}
|
108 |
+
}
|
109 |
+
|
110 |
+
// Set up VR button and initialize VR experience on click
|
111 |
+
const vrButton = document.createElement("button");
|
112 |
+
vrButton.textContent = "Enter VR";
|
113 |
+
vrButton.style.position = "absolute";
|
114 |
+
vrButton.style.bottom = "10px";
|
115 |
+
vrButton.style.left = "10px";
|
116 |
+
vrButton.style.width = "200px";
|
117 |
+
vrButton.style.height = "40px";
|
118 |
+
vrButton.style.background = "linear-gradient(to bottom, #6c543e, #4e342e)";
|
119 |
+
vrButton.style.color = "#e0d7c5";
|
120 |
+
vrButton.style.border = "none";
|
121 |
+
vrButton.style.cursor = "pointer";
|
122 |
+
document.body.appendChild(vrButton);
|
123 |
+
|
124 |
+
vrButton.addEventListener("click", createXRExperience);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
125 |
|
126 |
function setupControllerInteractions(xrHelper) {
|
127 |
+
xrHelper.input.onControllerAddedObservable.add(controller => {
|
128 |
+
controller.onMotionControllerInitObservable.add(motionController => {
|
129 |
+
const xrRay = motionController.getComponent("xr-standard-trigger");
|
130 |
+
|
131 |
+
if (xrRay) {
|
132 |
+
xrRay.onButtonStateChangedObservable.add(() => {
|
133 |
+
if (xrRay.changes.pressed) {
|
134 |
+
if (xrRay.pressed) {
|
135 |
+
const pickResult = scene.pickWithRay(controller.pointerRay);
|
136 |
+
if (pickResult.hit && pickResult.pickedMesh) {
|
137 |
+
if (pickResult.pickedMesh.name === "npc1") {
|
138 |
+
openChat("npc1", "NPC-1", "Hello! How can I assist you today?");
|
139 |
+
}
|
140 |
+
}
|
141 |
+
}
|
142 |
+
}
|
143 |
+
});
|
144 |
+
}
|
145 |
+
});
|
146 |
+
});
|
147 |
+
}
|
148 |
|
149 |
// Chat System with Transformers.js
|
150 |
async function setupChat() {
|
|
|
167 |
const message = inputField.value;
|
168 |
if (message.trim() === "" || !chatSetup) return;
|
169 |
|
170 |
+
chatLog.innerHTML += `<p>Player: ${message}</p>`;
|
171 |
inputField.value = "";
|
172 |
|
173 |
const { model, tokenizer } = await chatSetup;
|
|
|
175 |
const response = await model.generate(inputs.input_ids, { max_length: 50 });
|
176 |
const output = tokenizer.decode(response[0], { skip_special_tokens: true });
|
177 |
|
178 |
+
chatLog.innerHTML += `<p>NPC: ${output}</p>`;
|
179 |
chatLog.scrollTop = chatLog.scrollHeight;
|
180 |
|
181 |
// Limit chat log entries to 50
|
|
|
186 |
|
187 |
function openChat(npcId, npcName, greeting) {
|
188 |
const chatLog = document.getElementById("chatLog");
|
189 |
+
chatLog.innerHTML += `<p>${npcName}: ${greeting}</p>`;
|
190 |
}
|
191 |
</script>
|
192 |
</body>
|
193 |
|
194 |
+
</html>
|