-
Notifications
You must be signed in to change notification settings - Fork 302
/
gltf.html
82 lines (71 loc) · 2.71 KB
/
gltf.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
<html>
<head>
<title></title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="../dist/claygl.js"></script>
</head>
<body style="margin:0px; background-color: black">
<canvas id="main"></canvas>
<script type="text/javascript">
var renderer = new clay.Renderer({
canvas: document.getElementById("main")
});
renderer.resize(window.innerWidth, window.innerHeight);
var shadowMapPass = new clay.prePass.ShadowMap();
var environmentMap = new clay.TextureCube({
width: 256,
height: 256
});
var environmentMapPass = new clay.prePass.EnvironmentMap({
texture: environmentMap
});
var timeline = new clay.Timeline();
timeline.start();
var loader = new clay.loader.GLTF();
loader.load("assets/models/basic_scene/scene.gltf");
loader.on('success', function(res) {
var scene = res.scene;
scene.rotation.rotateX(-Math.PI / 2);
var camera = new clay.camera.Perspective({
aspect: renderer.getViewportAspect(),
far: 100
});
camera.position.set(2, 2, 2);
camera.lookAt(scene.position);
camera.aspect = renderer.canvas.width / renderer.canvas.height;
var control = new clay.plugin.OrbitControl({
target: camera,
domElement: renderer.canvas,
sensitivity: 0.4
});
var light = new clay.light.Spot();
light.range = 30;
light.umbraAngle = 10;
light.penumbraAngle = 25;
light.shadowResolution = 2048;
light.shadowBias = 0.0002;
light.position.set(-5, -5, 5);
light.lookAt(scene.position);
scene.add(light);
scene.add(new clay.light.Ambient({
intensity: 0.3
}));
var suzanne = scene.getNode('Suzanne');
var suzanneMaterial = suzanne.material;
environmentMapPass.position.set(0, 0.25, 1.5);
suzanneMaterial.set('color', [1,1,1]);
suzanneMaterial.set('metalness', 1);
suzanneMaterial.set('roughness', 0.4);
environmentMapPass.render(renderer, scene);
suzanneMaterial.set('environmentMap', environmentMap);
timeline.on('frame', function(deltaTime) {
control.update(deltaTime);
shadowMapPass.render(renderer, scene);
renderer.render(scene, camera);
// shadowMapPass.renderDebug(renderer);
});
});
</script>
</body>
</html>