-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
/
scene.js
82 lines (52 loc) · 1.94 KB
/
scene.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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
var camera, scene, renderer, group;
function init( canvas, width, height, pixelRatio, path ) {
camera = new THREE.PerspectiveCamera( 40, width / height, 1, 1000 );
camera.position.z = 200;
scene = new THREE.Scene();
scene.fog = new THREE.Fog( 0x444466, 100, 400 );
scene.background = new THREE.Color( 0x444466 );
group = new THREE.Group();
scene.add( group );
// we don't use ImageLoader since it has a DOM dependency (HTML5 image element)
var loader = new THREE.ImageBitmapLoader().setPath( path );
loader.setOptions( { imageOrientation: 'flipY' } );
loader.load( 'textures/matcaps/matcap-porcelain-white.jpg', function ( imageBitmap ) {
var texture = new THREE.CanvasTexture( imageBitmap );
var geometry = new THREE.IcosahedronBufferGeometry( 5, 3 );
var materials = [
new THREE.MeshMatcapMaterial( { color: 0xaa24df, matcap: texture } ),
new THREE.MeshMatcapMaterial( { color: 0x605d90, matcap: texture } ),
new THREE.MeshMatcapMaterial( { color: 0xe04a3f, matcap: texture } ),
new THREE.MeshMatcapMaterial( { color: 0xe30456, matcap: texture } )
];
for ( var i = 0; i < 100; i ++ ) {
var material = materials[ i % materials.length ];
var mesh = new THREE.Mesh( geometry, material );
mesh.position.x = random() * 200 - 100;
mesh.position.y = random() * 200 - 100;
mesh.position.z = random() * 200 - 100;
mesh.scale.setScalar( random() + 1 );
group.add( mesh );
}
renderer = new THREE.WebGLRenderer( { antialias: true, canvas: canvas } );
renderer.setPixelRatio( pixelRatio );
renderer.setSize( width, height, false );
animate();
} );
}
function animate() {
// group.rotation.x = Date.now() / 4000;
group.rotation.y = - Date.now() / 4000;
renderer.render( scene, camera );
if ( self.requestAnimationFrame ) {
self.requestAnimationFrame( animate );
} else {
// Firefox
}
}
// PRNG
var seed = 1;
function random() {
var x = Math.sin( seed ++ ) * 10000;
return x - Math.floor( x );
}