AEUPH commited on
Commit
d14c4f3
·
verified ·
1 Parent(s): 156d14f

Update index.html

Browse files
Files changed (1) hide show
  1. index.html +55 -58
index.html CHANGED
@@ -91,63 +91,60 @@
91
  engine.resize();
92
  });
93
 
 
94
  async function createXRExperience() {
95
- try {
96
- const xrHelper = await scene.createDefaultXRExperienceAsync({
97
- floorMeshes: [scene.getMeshByName("ground")],
98
- // Do not explicitly disable all optional features; let the default setup run
99
- disableDefaultUI: false // Keep the default UI enabled to ensure the VR button works
100
- });
101
-
102
- // After initialization, specifically disable hand tracking if it was included
103
- const featuresManager = xrHelper.baseExperience.featuresManager;
104
-
105
- // This explicitly disables hand tracking if it was somehow included by default
106
- featuresManager.disableFeature(BABYLON.WebXRFeatureName.HAND_TRACKING);
107
-
108
- // Set up interactions
109
- setupControllerInteractions(xrHelper);
110
- scene.activeCamera = xrHelper.baseExperience.camera;
111
-
112
- } catch (err) {
113
- console.error('Failed to start VR session:', err);
114
- }
115
- }
116
-
117
- // Set up VR button and initialize VR experience on click
118
- const vrButton = document.createElement("button");
119
- vrButton.textContent = "Enter VR";
120
- vrButton.style.position = "absolute";
121
- vrButton.style.bottom = "10px";
122
- vrButton.style.left = "10px";
123
- vrButton.style.width = "200px";
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
- xrHelper.input.onControllerAddedObservable.add(controller => {
135
- controller.onMotionControllerInitObservable.add(motionController => {
136
- const thumbstick = motionController.getComponent("xr-standard-thumbstick");
137
-
138
- if (thumbstick) {
139
- thumbstick.onAxisValueChangedObservable.add((axisValues) => {
140
- const player = scene.getMeshByName("player");
141
-
142
- // Map thumbstick input to movement
143
- const speed = 0.05; // Adjust this value for faster/slower movement
144
- player.position.x += axisValues.x * speed; // Horizontal movement (left-right)
145
- player.position.z += axisValues.y * speed; // Vertical movement (forward-backward)
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 += <p>Player: ${message}</p>;
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 += <p>NPC: ${output}</p>;
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 += <p>${npcName}: ${greeting}</p>;
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>