-
Notifications
You must be signed in to change notification settings - Fork 0
/
5_1_Complex3Dobjects.html
executable file
·94 lines (77 loc) · 2 KB
/
5_1_Complex3Dobjects.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
<!DOCTYPE html>
<html>
<head>
<script src="js/three.min.js"></script>
<script src="js/OBJLoader.js"></script>
<script src="js/OrbitControls.js"></script>
</head>
<body style="margin: 0; padding:0">
<script>
//global variables
var renderer;
var scene;
var camera;
var cameraControl;
function createRenderer() {
renderer = new THREE.WebGLRenderer();
renderer.setClearColor(0x000000, 1.0);
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.shadowMap.enabled = true;
}
function createCamera() {
camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1, 1000);
camera.position.x = 15;
camera.position.y = 16;
camera.position.z = 23;
camera.lookAt(scene.position);
cameraControl = new THREE.OrbitControls(camera);
}
function loadModel() {
var material = new THREE.MeshPhongMaterial( {
specular: 0x222222,
shininess: 35
} );
loader = new THREE.OBJLoader();
loader.load('assets/lee.obj', function(object) {
object.traverse( function ( child ) {
if ( child instanceof THREE.Mesh ) {
child.material = material;
child.position.y -= 10;
}
} );
scene.add(object);
});
}
function createLight() {
var spotLight = new THREE.SpotLight(0xffffff);
spotLight.position.set(10, 40, 20);
spotLight.shadowCameraNear = 20;
spotLight.shadowCameraFar = 50;
spotLight.castShadow = true;
scene.add(spotLight);
}
//init() gets executed once
function init() {
scene = new THREE.Scene();
createRenderer();
createCamera();
createLight();
loadModel();
document.body.appendChild(renderer.domElement);
//render() gets called at end of init
//as it looped forever
render();
}
//infinite loop
function render() {
cameraControl.update();
renderer.render(scene, camera);
requestAnimationFrame(render);
}
init()
</script>
</body>
</html>