-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (81 loc) · 2.25 KB
/
index.js
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
114
115
116
117
118
119
import { GLTFLoader } from 'https://threejs.org/examples/jsm/loaders/GLTFLoader.js';
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 80, window.innerWidth / window.innerHeight, 0.1, 1000 );
camera.position.set(0,0,10)
var renderer = new THREE.WebGLRenderer({ alpha: true, antialias: true });
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
renderer.setClearColor( 0x000000, 0);
renderer.toneMapping = THREE.ReinhardToneMapping;
renderer.toneMappingExposure = .5;
window.addEventListener( 'resize', () =>{
renderer.setSize(window.innerWidth, window.innerHeight);
camera.aspect = window.innerWidth/window.innerHeight;
camera.updateProjectionMatrix();
} );
var hemilight = new THREE.HemisphereLight(0xFFFFFF, 0x0B132B, 10);
var CameraLight = new THREE.SpotLight(0x6FFFE9,5);
scene.add(CameraLight);
scene.add(hemilight);
var loader = new GLTFLoader();
var pentool;
var carot;
loader.load(
'carots.gltf',
function ( gltf ) {
carot = gltf.scene;
scene.add( gltf.scene );
gltf.animations;
gltf.scene;
gltf.scenes;
gltf.cameras;
gltf.asset;
},
);
loader.load(
'pentool.gltf',
function ( gltf ) {
pentool = gltf.scene;
scene.add( gltf.scene );
gltf.animations;
gltf.scene;
gltf.scenes;
gltf.cameras;
gltf.asset;
},
);
var change_model_location = function(){
if(window.innerWidth <= 1200){
camera.position.set(0,0,13);
if(carot){
carot.position.y = 7;
carot.position.x = 0
}
if(pentool){
pentool.position.y = -7;
pentool.position.x = 0;
}
}
else{
camera.position.set(0,0,13);
if(pentool){
pentool.position.x = window.innerWidth/150;
pentool.position.y = 0;
}
if(carot) {
carot.position.x = -window.innerWidth/150;
carot.position.y = 0;
}
}
};
var animate = function () {
change_model_location();
if (carot)carot.rotation.x += Math.PI/1001;
if (carot)carot.rotation.z += Math.PI/1001;
if(pentool) pentool.rotation.z -= Math.PI/1001;
if(pentool) pentool.rotation.x -= Math.PI/1001;
requestAnimationFrame( animate );
renderer.render( scene, camera );
CameraLight.position.set(camera.position.x +10, camera.position.y +10, camera.position.z +10);
};
animate();