-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhints.txt
210 lines (124 loc) · 5.09 KB
/
hints.txt
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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
// https://threejs.org/docs/#api/en/materials/PointsMaterial
const vertices = [];
for ( let i = 0; i < 10000; i ++ ) {
const x = THREE.MathUtils.randFloatSpread( 2000 );
const y = THREE.MathUtils.randFloatSpread( 2000 );
const z = THREE.MathUtils.randFloatSpread( 2000 );
vertices.push( x, y, z );
}
const geometry = new THREE.BufferGeometry();
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
const material = new THREE.PointsMaterial( { color: 0x888888 , size: 1, map: texture, alphaMap: texture, sizeAttenuation:true} );
const points = new THREE.Points( geometry, material );
scene.add( points );
// https://github.com/mrdoob/three.js/blob/master/examples/webgl_points_sprites.html
import * as THREE from '../build/three.module.js';
import Stats from './jsm/libs/stats.module.js';
import { GUI } from './jsm/libs/lil-gui.module.min.js';
let camera, scene, renderer, stats, parameters;
let mouseX = 0, mouseY = 0;
let windowHalfX = window.innerWidth / 2;
let windowHalfY = window.innerHeight / 2;
const materials = [];
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 1, 2000 );
camera.position.z = 1000;
scene = new THREE.Scene();
scene.fog = new THREE.FogExp2( 0x000000, 0.0008 );
const geometry = new THREE.BufferGeometry();
const vertices = [];
const textureLoader = new THREE.TextureLoader();
const sprite1 = textureLoader.load( 'textures/sprites/snowflake1.png' );
const sprite2 = textureLoader.load( 'textures/sprites/snowflake2.png' );
const sprite3 = textureLoader.load( 'textures/sprites/snowflake3.png' );
const sprite4 = textureLoader.load( 'textures/sprites/snowflake4.png' );
const sprite5 = textureLoader.load( 'textures/sprites/snowflake5.png' );
for ( let i = 0; i < 10000; i ++ ) {
const x = Math.random() * 2000 - 1000;
const y = Math.random() * 2000 - 1000;
const z = Math.random() * 2000 - 1000;
vertices.push( x, y, z );
}
geometry.setAttribute( 'position', new THREE.Float32BufferAttribute( vertices, 3 ) );
parameters = [
[[ 1.0, 0.2, 0.5 ], sprite2, 20 ],
[[ 0.95, 0.1, 0.5 ], sprite3, 15 ],
[[ 0.90, 0.05, 0.5 ], sprite1, 10 ],
[[ 0.85, 0, 0.5 ], sprite5, 8 ],
[[ 0.80, 0, 0.5 ], sprite4, 5 ]
];
for ( let i = 0; i < parameters.length; i ++ ) {
const color = parameters[ i ][ 0 ];
const sprite = parameters[ i ][ 1 ];
const size = parameters[ i ][ 2 ];
materials[ i ] = new THREE.PointsMaterial( { size: size, map: sprite, blending: THREE.AdditiveBlending, depthTest: false, transparent: true } );
materials[ i ].color.setHSL( color[ 0 ], color[ 1 ], color[ 2 ] );
const particles = new THREE.Points( geometry, materials[ i ] );
particles.rotation.x = Math.random() * 6;
particles.rotation.y = Math.random() * 6;
particles.rotation.z = Math.random() * 6;
scene.add( particles );
}
//
renderer = new THREE.WebGLRenderer();
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
//
stats = new Stats();
document.body.appendChild( stats.dom );
//
const gui = new GUI();
const params = {
texture: true
};
gui.add( params, 'texture' ).onChange( function ( value ) {
for ( let i = 0; i < materials.length; i ++ ) {
materials[ i ].map = ( value === true ) ? parameters[ i ][ 1 ] : null;
materials[ i ].needsUpdate = true;
}
} );
gui.open();
document.body.style.touchAction = 'none';
document.body.addEventListener( 'pointermove', onPointerMove );
//
window.addEventListener( 'resize', onWindowResize );
}
function onWindowResize() {
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function onPointerMove( event ) {
if ( event.isPrimary === false ) return;
mouseX = event.clientX - windowHalfX;
mouseY = event.clientY - windowHalfY;
}
//
function animate() {
requestAnimationFrame( animate );
render();
stats.update();
}
function render() {
const time = Date.now() * 0.00005;
camera.position.x += ( mouseX - camera.position.x ) * 0.05;
camera.position.y += ( - mouseY - camera.position.y ) * 0.05;
camera.lookAt( scene.position );
for ( let i = 0; i < scene.children.length; i ++ ) {
const object = scene.children[ i ];
if ( object instanceof THREE.Points ) {
object.rotation.y = time * ( i < 4 ? i + 1 : - ( i + 1 ) );
}
}
for ( let i = 0; i < materials.length; i ++ ) {
const color = parameters[ i ][ 0 ];
const h = ( 360 * ( color[ 0 ] + time ) % 360 ) / 360;
materials[ i ].color.setHSL( h, color[ 1 ], color[ 2 ] );
}
renderer.render( scene, camera );
}