forked from harpygg/draco-tester
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
106 lines (85 loc) · 3.58 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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Balor test</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script
src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r128/three.min.js"
integrity="sha512-dLxUelApnYxpLt6K2iomGngnHO83iUvZytA3YjDUCjT0HDOHKXnVYdf3hU4JjM8uEhxf9nD1/ey98U3t2vZ0qQ=="
crossorigin="anonymous"
referrerpolicy="no-referrer"
></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/controls/OrbitControls.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/GLTFLoader.js"></script>
<script src="https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/loaders/DRACOLoader.js"></script>
<script>
const scene = new THREE.Scene();
const plane = new THREE.Mesh(
new THREE.PlaneGeometry( 80, 80 ),
new THREE.MeshPhongMaterial( { color: 0xCCCCCC, specular: 0x101010 } )
);
plane.rotation.x = - Math.PI / 2;
plane.position.y = 0.03;
plane.receiveShadow = true;
scene.add( plane );
const renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.outputEncoding = THREE.sRGBEncoding;
renderer.shadowMap.enabled = true;
document.body.appendChild(renderer.domElement);
const camera = new THREE.PerspectiveCamera( 45, window.innerWidth / window.innerHeight, 1, 10000 );
const controls = new THREE.OrbitControls( camera, renderer.domElement );
camera.position.set( 0, 20, 100 );
controls.update();
const hemiLight = new THREE.HemisphereLight( 0x443333, 0x111122 );
scene.add( hemiLight );
const spotLight = new THREE.SpotLight();
spotLight.angle = Math.PI / 16;
spotLight.penumbra = 0.5;
spotLight.castShadow = true;
spotLight.position.set( -100, 100, 100 );
scene.add( spotLight );
const light = new THREE.AmbientLight(0x404040);
scene.add(light);
const texture = new THREE.TextureLoader().load(
'https://firebasestorage.googleapis.com/v0/b/harpy-prod.appspot.com/o/glb%2Fbalor_test.jpg?alt=media&token=ea330649-4d8a-479c-9700-b658a2fb42b1'
);
texture.encoding = THREE.sRGBEncoding;
const gltfLoader = new THREE.GLTFLoader();
const dracoLoader = new THREE.DRACOLoader();
dracoLoader.setDecoderPath('https://cdn.rawgit.com/mrdoob/three.js/master/examples/js/libs/draco/'); // Specify path to a folder containing WASM/JS decoding libraries.
dracoLoader.preload(); // Optional: Pre-fetch Draco WASM/JS module.
gltfLoader.setDRACOLoader(dracoLoader);
gltfLoader.load(
'https://firebasestorage.googleapis.com/v0/b/harpy-prod.appspot.com/o/glb%2Fbalor_test.glb?alt=media&token=cbbb7a66-d77b-4677-8358-3e0431f19507',
(gltf) => {
gltf.scene.traverse((object) => {
if (object.type === 'SkinnedMesh') {
texture.flipY = false;
object.material.normalMap = texture;
object.material.needsUpdate = true;
object.material.metalness = 0;
object.castShadow = true;
object.receiveShadow = true;
object.scale.set(0.4, 0.4, 0.4);
}
});
gltf.scene.name = 'Balor';
scene.add(gltf.scene);
}
);
const animate = function () {
requestAnimationFrame(animate);
controls.update();
renderer.render(scene, camera);
};
animate();
</script>
</body>
</html>