-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtorusknot.js
62 lines (53 loc) · 1.9 KB
/
torusknot.js
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
// var shaders = {
// Gouraud:new THREE.ShaderMaterial ({
// vertexColors: THREE.VertexColors,
// vertexShader: document.getElementById('gouraud.vert').text,
// fragmentShader: document.getElementById('gouraud.frag').text,
// uniforms: {
// light_position: { type: 'v3', value: light.position }
// }
// }),
// Phong:new THREE.ShaderMaterial ({
// vertexColors: THREE.VertexColors,
// vertexShader: document.getElementById('phong.vert').text,
// fragmentShader: document.getElementById('phong.frag').text,
// uniforms: {
// light_position: { type: 'v3', value: light.position }
// }
// })
// };
function torusknot() {
var width = window.innerWidth *7/15 ;
var height = window.innerHeight *7/15 ;
// var width = 400;
// var height =400;
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera( 45, width / height, 1, 1000 );
camera.position.set( 0, 0, 5 );
scene.add( camera );
var light = new THREE.PointLight();
light.position.set( 5, 5, 5 );
scene.add( light );
var renderer = new THREE.WebGLRenderer( );
// renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( width, height );
document.body.appendChild( renderer.domElement );
var geometry = new THREE.TorusKnotGeometry( 1, 0.3, 100, 20 );
var material = new THREE.ShaderMaterial ({
vertexColors: THREE.VertexColors,
vertexShader: document.getElementById('phong.vert').text,
fragmentShader: document.getElementById('phong.frag').text,
uniforms: {
light_position: { type: 'v3', value: light.position }
}
});
var torus_knot = new THREE.Mesh( geometry, material );
scene.add( torus_knot );
loop();
function loop() {
requestAnimationFrame( loop );
torus_knot.rotation.x += 0.01;
torus_knot.rotation.y += 0.01;
renderer.render( scene, camera );
}
}