-
Notifications
You must be signed in to change notification settings - Fork 0
/
truckWheels.html
110 lines (79 loc) · 2.54 KB
/
truckWheels.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
<html>
<body>
<script type="module">
// globals
import * as THREE from '../ThreeJS-CameraControls/resources/three-latest.js';
import { OrbitControls } from '../ThreeJS-CameraControls/resources/OrbitControl.js';
import { DragControls } from '../ThreeJS-CameraControls/resources/DragControl.js';
import * as GLTFLoader from '../ThreeJS-CameraControls/resources/GltfLoader.js';
var scene, camera, renderer, cubeObj, orbitControls;
var objects = [];
var waganZAxisVal = 0;
init();
animate();
function init(){
scene = new THREE.Scene();
var axesHelper = new THREE.AxesHelper( 1000 );
scene.add( axesHelper );
camera = new THREE.PerspectiveCamera( 50, window.innerWidth / window.innerHeight, 1, 1000 );
camera.position.z = 450;
camera.position.y = 50;
camera.position.x = -550;
// load wheels
this.gltfloader = new GLTFLoader();
this.gltfloader.setPath('assets/truck/');
this.gltfloader.load('truckWheels.gltf', function (gltf) {
gltf.scene.traverse(function (child) {
child.position.y = -0.5; // green
child.position.z = -1;
child.position.x = 0.65;
});
scene.add(gltf.scene);
});
renderer = new THREE.WebGLRenderer({
antialias : true
});
var spotLight = new THREE.SpotLight( 0xffffff );
spotLight.position.set( 100, 1000, 100 );
spotLight.castShadow = true;
spotLight.shadow.mapSize.width = 1024;
spotLight.shadow.mapSize.height = 1024;
spotLight.shadow.camera.near = 500;
spotLight.shadow.camera.far = 4000;
spotLight.shadow.camera.fov = 30;
//scene.add( spotLight );
var directionalLight = new THREE.DirectionalLight( 0xffffff, 0.8 );
scene.add( directionalLight );
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.setClearColor(0xcce0ff);
document.body.appendChild(renderer.domElement);
orbitControls = new OrbitControls(camera, renderer.domElement);
var dragControls = new DragControls(objects, camera,
renderer.domElement);
dragControls.addEventListener('dragstart', function() {
orbitControls.enabled = true;
});
dragControls.addEventListener('dragend', function() {
orbitControls.enabled = true;
});
document.addEventListener( 'keydown', onKeyDown, false );
}
function onKeyDown( event ) {
const step = 5; // world units
switch ( event.keyCode ) {
case 37:
camera.position.x -= step;
break;
case 39:
camera.position.x += step;
break;
}
}
function animate(){
orbitControls.update();
renderer.render(scene, camera);
requestAnimationFrame(animate);
}
</script>
</body>
</html>