-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
63 lines (48 loc) · 1.7 KB
/
index.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Three.js Cube demo</title>
<style>
body {
margin: 0;
overflow: hidden;
}
</style>
</head>
<body>
<script src="http://static.ciweishixi.com/three@0.131.2/three.min.js"></script>
<script>
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000);
camera.position.z = 500;
const renderer = new THREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
const cubeSize = 100; //大正方体尺寸
const innerCubeSize = 50; //小正方体尺寸
const cubeMaterial = new THREE.MeshBasicMaterial({ color: 0xffffff, wireframe: true });
const innerCubeMaterial = new THREE.MeshBasicMaterial({ color: 0x00ff00, wireframe: true });
const cubeGeometry = new THREE.BoxGeometry(cubeSize, cubeSize, cubeSize);
const innerCubeGeometry = new THREE.BoxGeometry(innerCubeSize, innerCubeSize, innerCubeSize);
const cubeGroup = new THREE.Group();
const cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
const innerCube = new THREE.Mesh(innerCubeGeometry, innerCubeMaterial);
cubeGroup.add(cube);
cubeGroup.add(innerCube);
scene.add(cubeGroup);
function animate() {
requestAnimationFrame(animate);
const time = Date.now() * 0.001;
// 旋转大正方体
cubeGroup.rotation.x = time;
cubeGroup.rotation.y = time;
// 旋转小正方体
innerCube.rotation.x = time * 2;
innerCube.rotation.y = time * 2;
renderer.render(scene, camera);
}
animate();
</script>
</body>
</html>