-
Notifications
You must be signed in to change notification settings - Fork 0
/
cube-rotating-result.html
60 lines (50 loc) · 2.05 KB
/
cube-rotating-result.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>cube-rotating-result</title>
<style>
body { margin: 0; }
</style>
</head>
<body>
<script type="module">
import * as THREE from "./three.js-dev/build/three.module.js";
let scene, camera, renderer, cube; //global variables
function initialise(){
// Init scene
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( // value in documentation, by default, almost always
75, //field of view in degrees
window.innerWidth / window.innerHeight, //aspect ratio - соотношение сторон
0.01, // near clip frame - the coordinate of starting point to view on Z axe for frame, z=-n
1000 //far clip frame, z=-f, z=x=y=0 - view/eye point, frustum view - truncated pyramid - усеченная пирамида
);
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
const geometry = new THREE.BoxGeometry();
const material = new THREE.MeshBasicMaterial( { color: 0x00ff00 } );
cube = new THREE.Mesh( geometry, material );
scene.add( cube );
camera.position.z = 5; // by default x=y=z=0; z is a camera position on z axis, for visualising
// the scene
}
function AnimateCube (){
requestAnimationFrame( AnimateCube ); // Request to the browser for animating something. We should define the function, which should be recalled - animate_cube
// In every new shot due to the loop, the scene would be drawn again.
cube.rotation.x += 0.01; // rotation speed
cube.rotation.y += 0.01;
renderer.render( scene, camera ); // render( scene, camera ) - to visualize the scene and camera
}
function WindowResize(){
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
window.addEventListener('resize', WindowResize, false);
initialise();
AnimateCube();
</script>
</body>
</html>