-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.html
289 lines (269 loc) · 10.8 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Playground</title>
<meta name="description" content="This scene is an example using every possible hubs components we support." />
<!-- <script src="https://aframe.io/releases/1.5.0/aframe.min.js"></script> -->
<script src="../../dist/aframe-master-custom-r172.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/c-frame/[email protected]/dist/aframe-extras.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/2.5.0/socket.io.slim.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/api/easyrtc.js"></script>
<script src="https://cdn.jsdelivr.net/npm/networked-aframe@^0.12.0/dist/networked-aframe.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/networked-aframe/[email protected]/examples/js/audio-system.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@fern-solutions/[email protected]/dist/mirror.umd.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/c-frame/[email protected]/dist/aframe-cursor-teleport-component.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/AdaRoseCannon/aframe-xr-boilerplate@bca4792/simple-navmesh-constraint.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/aframe-troika-text.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/aframe-look-at-component.min.js"></script>
<script src="https://cdn.jsdelivr.net/gh/networked-aframe/naf-valid-avatars@4b116a4/src/player-info.js"></script>
<script>
// @var url {string} The url as string.
window.absoluteURLForAsset = (url) => {
if (!url) return "";
if (url.startsWith("https://vr.unodo-design.com/assets/")) {
return url.replace("https://vr.unodo-design.com/assets/", "./");
}
return url;
};
</script>
<script src="../../dist/gltf-model-plus.min.js"></script>
<script>
AFRAME.registerComponent("shortcuts", {
init() {
this.onKeyup = this.onKeyup.bind(this);
},
play() {
window.addEventListener("keyup", this.onKeyup, false);
},
pause() {
window.removeEventListener("keyup", this.onKeyup);
},
onKeyup(evt) {
if (!AFRAME.utils.shouldCaptureKeyEvent(evt)) {
return;
}
if (evt.keyCode === 71) {
// g
this.cameraRig = document.querySelector("#rig");
if (this.cameraRig.getAttribute("movement-controls").fly) {
this.cameraRig.setAttribute("movement-controls", "fly", false);
if (this.cameraRig.hasAttribute("simple-navmesh-constraint")) {
this.cameraRig.setAttribute("simple-navmesh-constraint", "enabled", true);
}
} else {
this.cameraRig.setAttribute("movement-controls", "fly", true);
if (this.cameraRig.hasAttribute("simple-navmesh-constraint")) {
this.cameraRig.setAttribute("simple-navmesh-constraint", "enabled", false);
}
}
}
if (evt.code === "Space") {
this.el.sceneEl.systems.waypoint.toggleClickableWaypoints();
}
},
});
</script>
</head>
<body>
<template id="avatar-template">
<a-entity player-info>
<a-entity class="model">
<a-text
class="nametag"
align="center"
value="anonymous"
position="0 2.1 0"
scale=".5 .5 .5"
look-at="#player"
></a-text>
</a-entity>
<a-entity class="camera" position="0 1.6 0" networked-audio-source></a-entity>
</a-entity>
</template>
<div
id="help-box"
style="
backdrop-filter: blur(4px);
background: rgba(0, 0, 0, 0.3);
border-radius: 0.5rem;
color: #ffffff;
left: 1.5rem;
padding: 1rem;
position: absolute;
top: 1.5rem;
width: 22em;
z-index: 1;
"
>
<div class="help-header" style="display: flex; flex: row; justify-content: space-between">
<h2 style="margin: 0; font-size: 1.2rem">Help</h2>
<button
class="close"
style="background: rgba(255, 255, 255, 0.3); width: 1.5rem; height: 1.5rem; border-radius: 0.5rem"
>
x
</button>
</div>
<div id="help-content">
<ul style="margin: 0; padding: 0.5rem 0 0 0; list-style: none; font-size: 0.9rem">
<li>[wasd or arrows] move</li>
<li>[mouse left click drag] rotate camera</li>
<li>[left click on floor] teleport</li>
<li>[g] toggle fly mode</li>
<li>[shift down] move fast</li>
<li>[space] toggle visibility of clickable waypoints</li>
<li> </li>
<li>[click on the screen once] start the sound</li>
</ul>
</div>
</div>
<script>
const helpbox = document.querySelector("#help-box");
const btn = helpbox.querySelector("button.close");
const content = helpbox.querySelector("#help-content");
btn.addEventListener("click", () => {
if (content.hasAttribute("hidden")) {
content.style = "display:block;";
btn.innerHTML = "x";
content.removeAttribute("hidden");
} else {
content.style = "display:none;";
content.setAttribute("hidden", true);
btn.innerHTML = "v";
}
});
</script>
<a-scene
light="defaultLightsEnabled:false"
renderer="physicallyCorrectLights:true;colorManagement:true"
networked-scene="
connectOnLoad: false;
room: hub;
debug: true;
adapter: easyrtc;
audio: true;
"
shadow="type: pcfsoft"
gltf-model="meshoptDecoderPath:https://unpkg.com/[email protected]/meshopt_decoder.js"
raycaster="far: 5; objects: .clickable;"
cursor="rayOrigin: mouse"
shortcuts
>
<!-- We use above raycaster far: 5 instead of far: 100 to avoid issues when clicking on a waypoint of
a different level because this conflicts with cursor-teleport and navmesh.
For another scene, you probably want to set it to a higher value.
-->
<a-assets timeout="30000">
<a-asset-item id="sceneGLB" src="./hubs_components_example_006.glb"></a-asset-item>
</a-assets>
<a-entity
id="rig"
cursor-teleport="cameraRig: #rig; cameraHead: #player; collisionEntities: .navmesh; ignoreEntities: .clickable"
simple-navmesh-constraint="navmesh:.navmesh;fall:0.5;height:0;exclude:.navmesh-hole;"
movement-controls="fly:false;controls: gamepad, trackpad, keyboard, nipple;"
move-to-spawn-point
networked="template:#avatar-template;attachTemplateToLocal:false"
player-info="avatarSrc: https://cdn.jsdelivr.net/gh/c-frame/valid-avatars-glb@c539a28/avatars/Asian/Asian_F_2_Casual.glb"
>
<a-entity id="player" class="camera" camera position="0 1.6 0" look-controls></a-entity>
</a-entity>
<a-entity class="environment-settings" gltf-model-plus="#sceneGLB"></a-entity>
<a-entity light="type: point; color: #f4f4f4; intensity: 0.4; distance: 0" position="0 2 0"></a-entity>
<a-plane
class="clickable"
width="1.5"
height="0.5"
material="color:black"
text="value: sit on a\nnearby seat; width: 4; align: center"
position="-2.5 -3.5 -1"
billboard
move-to-unoccupied-waypoint
></a-plane>
<a-cylinder radius="0.25" height="0.5" position="-3.5 -4.74 -3" rotation="0 -150 0">
<a-waypoint
id="seat1"
position="0 0.27 0"
can-be-clicked="true"
can-be-occupied="true"
will-disable-motion="true"
></a-waypoint>
</a-cylinder>
<!-- <a-waypoint
id="seat1"
position="-4 -4.5 -2"
can-be-clicked="true"
can-be-occupied="true"
will-disable-motion="true"
></a-waypoint> -->
</a-scene>
<!--
See https://github.com/networked-aframe/naf-nametag-solidjs/blob/main/public/ui-components.html
for more details on how to use the web components.
-->
<script src="https://cdn.jsdelivr.net/gh/networked-aframe/naf-nametag-solidjs@49ccc23/public/dist/ui-components.js"></script>
<div class="naf-top-bar-right">
<button
class="btn"
onclick="javascript:this.parentNode.remove();document.getElementById('enterScreen').removeAttribute('style')"
>
connect to test multi-users if you used `npm start` locally
</button>
</div>
<div class="naf-centered-fullscreen" style="display: none" id="enterScreen">
<div style="display: flex; flex-direction: column; gap: 0.5rem">
<label for="username">Your name</label>
<naf-username-input entity="#rig" enable-color-picker="false"></naf-username-input>
</div>
<button
type="button"
class="btn"
style="min-width: 100px"
onclick="javascript:AFRAME.scenes[0].emit('connect');this.parentNode.remove();document.getElementById('uiInRoom').removeAttribute('style')"
>
Enter
</button>
</div>
<div class="naf-bottom-bar-center" style="display: none" id="uiInRoom">
<naf-mic-button entity="#rig"></naf-mic-button>
<naf-users-button></naf-users-button>
<naf-chat-button></naf-chat-button>
</div>
<script>
// Add the drag and drop event listeners to the document and process a dragged GLB file.
document.addEventListener(
"dragover",
function (e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = "copy";
},
false
);
document.addEventListener(
"drop",
function (e) {
e.stopPropagation();
e.preventDefault();
const files = e.dataTransfer.files; // Array of all files.
for (const file of files) {
// Process only GLB files.
if (file.name.endsWith(".glb")) {
const reader = new FileReader();
reader.onload = function (e) {
// Set the gltf-model-plus attribute of the gltf-model-plus component to the dropped file.
// Set an empty string as source as a workaround to force the "model-loaded" event
// when the same GLB is loaded again.
const gltfModelPlus = document.querySelector("[gltf-model-plus]");
gltfModelPlus.setAttribute("gltf-model-plus", "");
gltfModelPlus.setAttribute("gltf-model-plus", e.target.result);
};
reader.readAsDataURL(file);
}
}
},
false
);
</script>
</body>
</html>