-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3dcube.html
57 lines (48 loc) · 1.25 KB
/
3dcube.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial- scale=1.0" />
<title>Codedamn Blog Three.js</title>
</head>
<body style="margin: 0; padding: 0">
<!-- CDN url to import three.js library -->
<script
src="https://cdnjs.cloudflare.com/ajax/libs/three.js/r125/three.js"
></script>
<script>
//create a scene
const scene = new THREE.Scene();
//create a camera
const camera = new THREE.PerspectiveCamera(
40,
window.innerWidth / window.innerHeight,
0.1,
500
);
camera.position.z = 5;
//create an object
const geometry = new THREE.BoxGeometry(1, 1, 1);
var material = new THREE.MeshBasicMaterial({
color: 0xfffff,
wireframe: false,
});
var cube = new THREE.Mesh(geometry, material);
//add the object to scene
scene.add(cube);
//create renderer
const renderer = new THREE.WebGLRenderer({ antialias: true });
renderer.setSize(window.innerWidth, window.innerHeight);
renderer.render(scene, camera);
//animation loop
const animate = () => {
requestAnimationFrame(animate);
cube.rotation.y += 0.01;
cube.rotation.x += 0.02;
renderer.render(scene, camera);
};
animate();
document.body.appendChild(renderer.domElement);
</script>
</body>
</html>