-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathscript.js
57 lines (45 loc) · 1.36 KB
/
script.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
var currentDemo;
slideshow.on('afterShowSlide', function(slide) {
console.log(slide.properties);
switch (slide.properties.demo) {
case 'rotate-cube':
currentDemo = rotateCube();
break;
}
});
slideshow.on('hideSlide', function(slide) {
currentDemo && currentDemo.stop();
});
function rotateCube() {
var renderer = new THREE.WebGLRenderer({ antialias : true });
var container = document.querySelector('#rotate-cube');
console.log(container.offsetWidth);
renderer.setSize(container.offsetWidth, container.offsetHeight);
container.appendChild(renderer.domElement);
var camera = new THREE.PerspectiveCamera(75, container.offsetWidth / container.offsetHeight, 1, 1000);
camera.position.z = 300;
var scene = new THREE.Scene();
var geometry = new THREE.CubeGeometry(200, 200, 200);
var material = new THREE.MeshLambertMaterial({
color: 0xff0000
});
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
var light = new THREE.PointLight(0xffffff);
light.position = new THREE.Vector3(0,100,400);
scene.add(light);
var pause = false;
function animate() {
!pause && requestAnimationFrame(animate);
mesh.rotation.x += .005;
mesh.rotation.y += .005;
renderer.render(scene, camera);
}
animate();
return {
stop: function() {
pause = true;
container.innerHTML = "";
}
};
}