-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexperience.ts
38 lines (32 loc) · 1.4 KB
/
experience.ts
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
import { Engine, Scene, SceneLoader, StandardMaterial, VideoTexture, VideoTextureSettings } from "@babylonjs/core";
import "@babylonjs/loaders";
const canvas = <HTMLCanvasElement> document.getElementById("renderCanvas");
const engine = new Engine(canvas);
const scene = new Scene(engine);
scene.createDefaultCamera(true);
scene.createDefaultLight(true);
const filePrefix = "https://allotropeijk.blob.core.windows.net/2021summerexhibit/";
SceneLoader.ImportMeshAsync(null, filePrefix, "room.01.glb", scene).then((meshData) => {
console.log("model loaded");
scene.createDefaultXRExperienceAsync({ floorMeshes: meshData.meshes }).then((xr) => {
console.log("xr created");
xr.baseExperience.sessionManager.onXRSessionInit.add((session) => {
console.log("xr entered");
const videoTexture = new VideoTexture("videoTexture", filePrefix + "video.01.mp4", scene, false, true);
const videoMaterial = new StandardMaterial("videoMaterial", scene);
videoMaterial.diffuseTexture = videoTexture;
videoMaterial.emissiveTexture = videoTexture;
meshData.meshes?.forEach((mesh) => {
if (!!mesh.material) {
mesh.material = videoMaterial;
}
});
});
});
});
engine.runRenderLoop(() => {
scene.render();
});
window.addEventListener("resize", () => {
engine.resize();
});