-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
49 lines (33 loc) · 1.04 KB
/
script.js
File metadata and controls
49 lines (33 loc) · 1.04 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
// Scene Mesh Camera Renderer
// Scene
const scene = new THREE.Scene();
// Mesh
const geometry = new THREE.BoxGeometry(1, 1, 1);
const material = new THREE.MeshBasicMaterial({color: "pink"});
const mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
// Camera
const aspect = {
width: window.innerWidth,
height: window.innerHeight,
};
const camera = new THREE.PerspectiveCamera( 75, aspect.width / aspect.height);
camera.position.z = 3;
scene.add(camera);
// Renderer
const canvas = document.querySelector(".draw"); // Select the canvas
const renderer = new THREE.WebGLRenderer({ canvas }); // add WebGL Renderer
renderer.setSize( aspect.width, aspect.height); // Renderer Size
// Clock Class
const clock = new THREE.Clock();
// Animation
const animate = () => {
// GetElapsedTime
const elapsedTime = clock.getElapsedTime();
// Update Rotation On X Axis
mesh.rotation.y = elapsedTime * Math.PI * 0.20;
// Renderer
renderer.render(scene, camera);
window.requestAnimationFrame(animate);
};
animate();