-
Notifications
You must be signed in to change notification settings - Fork 0
/
index3.html
113 lines (96 loc) · 2.41 KB
/
index3.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
106
107
108
109
110
111
112
113
<!doctype html>
<html>
<head>
<title>3D MOOC</title>
<script src="js/three.min.js"></script>
<script src="js/OrbitControls.js"></script>
<script src="js/OBJLoader.js"></script>
</head>
<body style="padding: 0; margin: 0;">
<script>
var scene;
var camera;
var renderer;
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 createLight() {
var spotLight = new THREE.SpotLight(0xffffff);
spotLight.position.set(10,40,20);
spotLight.shadowCameraNear = 20;
spotLight.shadowCameraFar = 50;
spotLight.castShadow = true;
spotLight.shadowMapWidth = 2048;
spotLight.shadowMapHeight = 2048;
scene.add(spotLight);
}
function loadModel() {
var texture = new THREE.Texture();
var loader = new THREE.ImageLoader ();
loader.load('assets/lee_diffuse.jpg', function (image){
texture.image = image;
texture.needsUpdate = true;
})
var normal_texture = new THREE.Texture();
var loader = new THREE.ImageLoader ();
loader.load('assets/lee_normal_tangent.jpg', function (image){
normal_texture.image = image;
normal_texture.needsUpdate = true;
})
var material = new THREE.MeshPhongMaterial({
specular: 0x222222,
shininess: 35,
map: texture,
normalMap: normal_texture,
normalScale: new THREE.Vector2(0.8, 0.8)
});
var 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;
child.receiveShadow = true;
child.castShadow = true;
}
});
object.name = 'model';
scene.add(object);
});
}
function init() {
scene = new THREE.Scene();
createRenderer();
createCamera();
createLight();
loadModel();
document.body.appendChild(renderer.domElement);
render();
}
function render() {
cameraControl.update();
if (scene.getObjectByName('model')) {
scene.getObjectByName('model').rotation.y += 5;
}
renderer.render(scene, camera);
requestAnimationFrame(render);
}
init();
</script>
</body>
</html>