-
Notifications
You must be signed in to change notification settings - Fork 0
/
webgl-three2.html
53 lines (40 loc) · 1.11 KB
/
webgl-three2.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
<!DOCTYPE html>
<html>
<head>
<title>Three.js Example</title>
</head>
<body>
<canvas id="mycanvas" width="600" height="400"></canvas>
</body>
<script src="three.js"></script>
<script>
var init = function() {
// init renderer
var canvas = document.getElementById("mycanvas");
var renderer = new THREE.WebGLRenderer({ canvas: canvas });
renderer.setSize(canvas.width, canvas.height);
// scene
var scene = new THREE.Scene();
// camera
var camera = new THREE.PerspectiveCamera(45, canvas.width / canvas.height, 0.1, 1000);
camera.position.z = 50;
// light
var directionalLight = new THREE.DirectionalLight(0xffffff, 1.0);
directionalLight.position.set(1, 1, 1);
scene.add(directionalLight);
// mesh
var geometry = new THREE.TorusKnotGeometry(10, 2, 256, 16, 2, 7);
var material = new THREE.MeshPhongMaterial({ color: 0x88aaff });
var mesh = new THREE.Mesh(geometry, material);
scene.add(mesh);
// update loop
var update = function() {
requestAnimationFrame(update);
mesh.rotation.y += 0.03;
renderer.render( scene, camera );
};
update();
};
init();
</script>
</html>