-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
159 lines (123 loc) · 3.75 KB
/
Copy pathscript.js
File metadata and controls
159 lines (123 loc) · 3.75 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
let camera, scene, renderer;
init();
animate();
var clock = new THREE.Clock();
var mixer;
var AnimationValue = 0
var animationAction;
var animation
function init() {
camera = new THREE.PerspectiveCamera(45,window.innerWidth / window.innerHeight,1,20000);
camera.position.z = 5;
camera.position.x = 0;
camera.position.y = 0;
scene = new THREE.Scene();
scene.background = new THREE.Color(0xffffff);
const loader = new THREE.TextureLoader();
//loader.load('stars.jpg' , function(texture)
// {
// scene.background = texture;
// });
const loadingManager = new THREE.LoadingManager( () => {
const loadingScreen = document.getElementById( 'loading-screen' );
loadingScreen.classList.add( 'fade-out' );
// optional: remove loader from DOM via event listener
loadingScreen.addEventListener( 'transitionend', onTransitionEnd );
} );
// gltf
const gltfLoader = new THREE.GLTFLoader(loadingManager);
gltfLoader.load('Med_animation.glb', (gltf) => {
const model = gltf.scene;
mixer= new THREE.AnimationMixer(model);
animation = gltf.animations
animationAction = mixer.clipAction(animation[AnimationValue])
animationAction.play()
// gltf.animations.forEach((clip) => {mixer.clipAction(clip).play(); });
console.log(gltf.animations[0])
model.position.set(0,-0.8,0)
scene.add( model );
});
// Galaxy
let galaxyGeometry = new THREE.SphereGeometry(1000,32,32);
let galaxyMaterial = new THREE.MeshBasicMaterial({
side: THREE.BackSide
});
let galaxy = new THREE.Mesh(galaxyGeometry, galaxyMaterial);
// Load Galaxy Textures
loader.crossOrigin = true;
loader.load(
'bg.png',
function(texture) {
galaxyMaterial.map = texture;
scene.add(galaxy);
}
);
let hemiLight = new THREE.HemisphereLight(0xffffff, 0xffffff, 0.61);
hemiLight.position.set(0, 50, 0);
// Add hemisphere light to scene
scene.add(hemiLight);
let d = 8.25;
let dirLight = new THREE.DirectionalLight(0xffffff, 0.54);
dirLight.position.set(-8, 12, 8);
dirLight.shadow.mapSize = new THREE.Vector2(1024, 1024);
dirLight.shadow.camera.near = 0.1;
dirLight.shadow.camera.far = 1500;
dirLight.shadow.camera.left = d * -1;
dirLight.shadow.camera.right = d;
dirLight.shadow.camera.top = d;
dirLight.shadow.camera.bottom = d * -1;
// Add directional Light to scene
scene.add(dirLight);
//
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//
const controls = new THREE.OrbitControls( camera, renderer.domElement );
controls.update();
//
window.addEventListener( 'resize', onWindowResize, false );
}
var options = {
anim1: function() {
AnimationValue = 0
mixer.stopAllAction()
animationAction = mixer.clipAction(animation[AnimationValue])
animationAction.play()
console.log("clicked")
},
anim2: function() {
AnimationValue = 1
mixer.stopAllAction()
animationAction = mixer.clipAction(animation[AnimationValue])
animationAction.play()
},
anim3: function() {
AnimationValue = 2
mixer.stopAllAction()
animationAction = mixer.clipAction(animation[AnimationValue])
animationAction.play()
}
};
var gui = new dat.GUI();
gui.add(options, 'anim1');
gui.add(options, 'anim2');
gui.add(options, 'anim3');
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
// clock.getDelta();
if ( mixer ) mixer.update( clock.getDelta() );
requestAnimationFrame( animate );
render();
}
function render() {
renderer.render( scene, camera );
}
function onTransitionEnd( event ) {
event.target.remove();
}