-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.js
302 lines (270 loc) · 6.75 KB
/
index.js
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
290
291
292
293
294
295
296
297
298
299
300
301
302
import {
Engine,
Scene,
Vector3,
Texture,
PhotoDome,
VideoDome,
Animation,
UniversalCamera,
} from "@babylonjs/core";
import "@babylonjs/loaders";
import "@babylonjs/core/Particles/particleSystemComponent";
import "@babylonjs/core/Particles/webgl2ParticleSystem";
import {
AdvancedDynamicTexture,
StackPanel,
Button,
Control
} from "@babylonjs/gui";
import { WebXRDefaultExperience } from '@babylonjs/core/XR/webXRDefaultExperience.js'
// Enable GLTF/GLB loader for loading controller models from WebXR Input registry
import '@babylonjs/loaders/glTF'
// Without this next import, an error message like this occurs loading controller models:
// Build of NodeMaterial failed" error when loading controller model
// Uncaught (in promise) Build of NodeMaterial failed: input rgba from block
// FragmentOutput[FragmentOutputBlock] is not connected and is not optional.
import '@babylonjs/core/Materials/Node/Blocks'
import losAngeles from "./assets/forFacebook-8K-LA.jpg";
import athens from "./assets/Athens-8K.jpg";
import lakeTahao from "./assets/LakeTahao-10K.jpg";
import lakeTahao8k360video from "./assets/LakeTahao-8K-short-360.mp4";
const canvas = document.getElementById("renderCanvas");
const engine = new Engine(canvas, true);
const scene = new Scene(engine);
//var xrHelper = scene.createDefaultXRExperienceAsync();
//var vrHelper = scene.createDefaultVRExperience();
var vrHelper = scene.createDefaultVRExperience({createDeviceOrientationCamera:false});
const camera = new UniversalCamera(
"camera",
Vector3.Zero(),
scene
);
camera.attachControl(canvas, true);
engine.runRenderLoop(() => {
scene.render();
});
window.addEventListener("resize", () => {
engine.resize();
});
// Create the PhotoDome
var dome = new PhotoDome(
"sphere",
losAngeles,
{
resolution: 64,
size: 1000,
//halfDomeMode: true,
useDirectMapping: false
},
scene
);
dome.imageMode = PhotoDome.MODE_MONOSCOPIC;
vrHelper.enableInteractions();
// Create a GUI texture
const advancedTexture = AdvancedDynamicTexture.CreateFullscreenUI(
"UI"
);
// Create a stack panel to hold the buttons
const stackPanel = new StackPanel();
stackPanel.width = "300px";
stackPanel.horizontalAlignment =
Control.HORIZONTAL_ALIGNMENT_RIGHT;
stackPanel.verticalAlignment =
Control.VERTICAL_ALIGNMENT_CENTER;
advancedTexture.addControl(stackPanel);
// Create the buttons
const button1 = Button.CreateSimpleButton(
"button1",
"Los Angeles"
);
button1.width = "200px";
button1.height = "100px";
button1.paddingBottom ="30px";
button1.cornerRadius="10";
button1.shadowColor="black";
button1.shadowOffsetX="2";
button1.shadowOffsetY="2";
button1.shadowBlur="30";
button1.color = "white";
button1.thickness = 2;
button1.background = "gray";
button1.alpha = "0.5";
button1.onPointerUpObservable.add(() => {
button1.thickness = 2;
button2.thickness = 0;
button3.thickness = 0;
button4.thickness = 0;
transition(losAngeles);
});
stackPanel.addControl(button1);
const button2 = Button.CreateSimpleButton(
"button2",
"Athens, Greece"
);
button2.width = "200px";
button2.height = "100px";
button2.paddingBottom ="30px";
button2.cornerRadius="10";
button2.shadowColor="black";
button2.shadowOffsetX="2";
button2.shadowOffsetY="2";
button2.shadowBlur="30";
button2.color = "white";
button2.thickness = 0;
button2.background = "gray";
button2.alpha = "0.5";
button2.onPointerUpObservable.add(() => {
button1.thickness = 0;
button2.thickness = 2;
button3.thickness = 0;
button4.thickness = 0;
transition(athens);
});
stackPanel.addControl(button2);
const button3 = Button.CreateSimpleButton(
"button3",
"Lake Tahoe"
);
button3.width = "200px";
button3.height = "100px";
button3.paddingBottom ="30px";
button3.cornerRadius="10";
button3.shadowColor="black";
button3.shadowOffsetX="2";
button3.shadowOffsetY="2";
button3.shadowBlur="30";
button3.color = "white";
button3.thickness = 0;
button3.background = "gray";
button3.alpha = "0.5";
button3.onPointerUpObservable.add(() => {
button1.thickness = 0;
button2.thickness = 0;
button3.thickness = 2;
button4.thickness = 0;
transition(lakeTahao);
});
stackPanel.addControl(button3);
const button4 = Button.CreateSimpleButton(
"button4",
"360 Video"
);
button4.width = "200px";
button4.height = "100px";
button4.paddingBottom ="30px";
button4.cornerRadius="10";
button4.shadowColor="black";
button4.shadowOffsetX="2";
button4.shadowOffsetY="2";
button4.shadowBlur="30";
button4.color = "white";
button4.thickness = 0;
button4.background = "gray";
button4.alpha = "0.5";
button4.onPointerUpObservable.add(() => {
button1.thickness = 0;
button2.thickness = 0;
button3.thickness = 0;
button4.thickness = 2
transitionVideo(lakeTahao);
});
stackPanel.addControl(button4);
const transition = (image) => {
let anim = scene.beginDirectAnimation(
dome.mesh,
[fadeOutAnimation],
0,
120,
false
);
anim.onAnimationEnd = () => loadNewTexture(image);
};
const transitionVideo = (video) => {
let anim = scene.beginDirectAnimation(
dome.mesh,
[fadeOutAnimation],
0,
120,
false
);
anim.onAnimationEnd = () => loadNewVideoTexture(video);
};
const loadNewTexture = (image) => {
const newTexture = new Texture(image, scene);
newTexture.onLoadObservable.add(() => {
dome.dispose();
// Create a new dome with the new texture
dome = new PhotoDome(
"sphere",
image,
{
resolution: 128,
size: 1000,
useDirectMapping: false
},
scene
);
dome.mesh.material.alpha = 0;
dome.imageMode = PhotoDome.MODE_TOPBOTTOM;
scene.beginDirectAnimation(
dome.mesh,
[fadeInAnimation],
0,
120,
false
);
});
};
const loadNewVideoTexture = (video) => {
const newTexture = new Texture(video, scene);
newTexture.onLoadObservable.add(() => {
dome.dispose();
// Create the VideoDome
dome = new VideoDome(
"videoSphere",
lakeTahao8k360video,
{
resolution: 64,
size: 1000,
clickToPlay: true,
useDirectMapping: false
},
scene
);
dome.mesh.material.alpha = 0;
dome.imageMode = PhotoDome.MODE_TOPBOTTOM;
scene.beginDirectAnimation(
dome.mesh,
[fadeInAnimation],
0,
120,
false
);
});
};
const fadeOutAnimation = new Animation(
"fadeOut",
"material.alpha",
40,
Animation.ANIMATIONTYPE_FLOAT,
Animation.ANIMATIONLOOPMODE_CONSTANT
);
fadeOutAnimation.setKeys([
{ frame: 0, value: 1 },
{ frame: 120, value: 0 }
]);
const fadeInAnimation = new Animation(
"fadeIn",
"material.alpha",
40,
Animation.ANIMATIONTYPE_FLOAT,
Animation.ANIMATIONLOOPMODE_CONSTANT
);
fadeInAnimation.setKeys([
{ frame: 0, value: 0 },
{ frame: 120, value: 1 }
]);
// scene.onBeforeRenderObservable.add(() => {
//
// });