-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-app.js
105 lines (80 loc) · 3.13 KB
/
example-app.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
import 'rvfc-polyfill';
import * as THREE from 'three';
import * as Depthkit from './lib/main.js'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
const renderer = new THREE.WebGLRenderer();
renderer.shadowMap.enabled = true;
renderer.shadowMap.type = THREE.PCFSoftShadowMap;
// blend the background into the floor
renderer.setClearColor(0x202020);
scene.add(new THREE.AmbientLight(0xffffff, 1.3)) // Add soft white light to the scene.
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.PlaneGeometry(2000, 2000);
geometry.rotateX(-Math.PI / 2)
const material = new THREE.MeshStandardMaterial( { color: 0xa0a0a0, metalness: 0.9, roughness: 0.7 } );
const base = new THREE.Mesh( geometry, material );
base.receiveShadow = true;
scene.add( base );
// add some nice lighting
let directionalLight = new THREE.SpotLight(0xffaaee, 60, 0, 0.7, 0.1);
directionalLight.position.set(2, 6, 2);
directionalLight.target.position.set(0,1.0,0);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.width = 1024;
directionalLight.shadow.mapSize.height = 1024;
scene.add(directionalLight);
directionalLight = new THREE.SpotLight(0xeeffaa, 60, 0, 0.5, 0.1);
directionalLight.position.set(0.5, 5, -4);
directionalLight.target.position.set(0,1.0,0);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.width = 1024;
directionalLight.shadow.mapSize.height = 1024;
scene.add(directionalLight);
directionalLight = new THREE.SpotLight(0xaaeeff, 60, 0, 0.9, 0.1);
directionalLight.position.set(-2, 4, -2);
directionalLight.target.position.set(0,1.0,0);
directionalLight.castShadow = true;
directionalLight.shadow.mapSize.width = 1024;
directionalLight.shadow.mapSize.height = 1024;
scene.add(directionalLight);
camera.position.z = 3;
camera.position.y = 1.5;
const controls = new OrbitControls( camera, renderer.domElement );
controls.target.y = 1.0;
controls.update();
// Add the depthkit object
const urlParams = new URLSearchParams(window.location.search);
const baseURL = './static';
let clipName = '3T02';
if (urlParams.get('c') != undefined) {
// clip name override via 'c' query parameter
clipName = urlParams.get('c');
}
const clipPath = `${baseURL}/${clipName}`;
// use query parameter 'wireframe' to enable wireframe preview
const showWireframe = (urlParams.get('wireframe') !== null);
Depthkit.setModuleConfig({debug: true});
let addedToScene = false;
const readyStateChangeCallback = () => {
if (!addedToScene && depthkit.readyState >= HTMLMediaElement.HAVE_CURRENT_DATA) {
depthkit.mesh.castShadow = true;
depthkit.material.wireframe = showWireframe;
scene.add(depthkit);
addedToScene = true;
}
};
const depthkit = new Depthkit.DracoMeshSequencePlayer({
clip: clipPath,
autoplay: true,
loop: true,
readyStateChangeCallback: readyStateChangeCallback
});
function animate() {
requestAnimationFrame( animate );
depthkit.updateReadyState();
renderer.render( scene, camera );
}
animate();