|
312 | 312 | const BIRDS = WIDTH * WIDTH; |
313 | 313 |
|
314 | 314 | // Custom Geometry - using 3 triangles each. No UVs, no normals currently. |
315 | | - function BirdGeometry() { |
| 315 | + class BirdGeometry extends THREE.BufferGeometry { |
316 | 316 |
|
317 | | - const triangles = BIRDS * 3; |
318 | | - const points = triangles * 3; |
| 317 | + constructor() { |
319 | 318 |
|
320 | | - THREE.BufferGeometry.call( this ); |
| 319 | + super(); |
321 | 320 |
|
322 | | - const vertices = new THREE.BufferAttribute( new Float32Array( points * 3 ), 3 ); |
323 | | - const birdColors = new THREE.BufferAttribute( new Float32Array( points * 3 ), 3 ); |
324 | | - const references = new THREE.BufferAttribute( new Float32Array( points * 2 ), 2 ); |
325 | | - const birdVertex = new THREE.BufferAttribute( new Float32Array( points ), 1 ); |
| 321 | + const triangles = BIRDS * 3; |
| 322 | + const points = triangles * 3; |
326 | 323 |
|
327 | | - this.setAttribute( 'position', vertices ); |
328 | | - this.setAttribute( 'birdColor', birdColors ); |
329 | | - this.setAttribute( 'reference', references ); |
330 | | - this.setAttribute( 'birdVertex', birdVertex ); |
| 324 | + const vertices = new THREE.BufferAttribute( new Float32Array( points * 3 ), 3 ); |
| 325 | + const birdColors = new THREE.BufferAttribute( new Float32Array( points * 3 ), 3 ); |
| 326 | + const references = new THREE.BufferAttribute( new Float32Array( points * 2 ), 2 ); |
| 327 | + const birdVertex = new THREE.BufferAttribute( new Float32Array( points ), 1 ); |
331 | 328 |
|
332 | | - // this.setAttribute( 'normal', new Float32Array( points * 3 ), 3 ); |
| 329 | + this.setAttribute( 'position', vertices ); |
| 330 | + this.setAttribute( 'birdColor', birdColors ); |
| 331 | + this.setAttribute( 'reference', references ); |
| 332 | + this.setAttribute( 'birdVertex', birdVertex ); |
333 | 333 |
|
| 334 | + // this.setAttribute( 'normal', new Float32Array( points * 3 ), 3 ); |
334 | 335 |
|
335 | | - let v = 0; |
336 | 336 |
|
337 | | - function verts_push() { |
| 337 | + let v = 0; |
338 | 338 |
|
339 | | - for ( let i = 0; i < arguments.length; i ++ ) { |
| 339 | + function verts_push() { |
340 | 340 |
|
341 | | - vertices.array[ v ++ ] = arguments[ i ]; |
| 341 | + for ( let i = 0; i < arguments.length; i ++ ) { |
| 342 | + |
| 343 | + vertices.array[ v ++ ] = arguments[ i ]; |
| 344 | + |
| 345 | + } |
342 | 346 |
|
343 | 347 | } |
344 | 348 |
|
345 | | - } |
| 349 | + const wingsSpan = 20; |
346 | 350 |
|
347 | | - const wingsSpan = 20; |
| 351 | + for ( let f = 0; f < BIRDS; f ++ ) { |
348 | 352 |
|
349 | | - for ( let f = 0; f < BIRDS; f ++ ) { |
| 353 | + // Body |
| 354 | + verts_push( |
| 355 | + 0, - 0, - 20, |
| 356 | + 0, 4, - 20, |
| 357 | + 0, 0, 30 |
| 358 | + ); |
350 | 359 |
|
351 | | - // Body |
352 | | - verts_push( |
353 | | - 0, - 0, - 20, |
354 | | - 0, 4, - 20, |
355 | | - 0, 0, 30 |
356 | | - ); |
| 360 | + // Left Wing |
| 361 | + verts_push( |
| 362 | + 0, 0, - 15, |
| 363 | + - wingsSpan, 0, 0, |
| 364 | + 0, 0, 15 |
| 365 | + ); |
357 | 366 |
|
358 | | - // Left Wing |
359 | | - verts_push( |
360 | | - 0, 0, - 15, |
361 | | - - wingsSpan, 0, 0, |
362 | | - 0, 0, 15 |
363 | | - ); |
| 367 | + // Right Wing |
| 368 | + verts_push( |
| 369 | + 0, 0, 15, |
| 370 | + wingsSpan, 0, 0, |
| 371 | + 0, 0, - 15 |
| 372 | + ); |
364 | 373 |
|
365 | | - // Right Wing |
366 | | - verts_push( |
367 | | - 0, 0, 15, |
368 | | - wingsSpan, 0, 0, |
369 | | - 0, 0, - 15 |
370 | | - ); |
| 374 | + } |
371 | 375 |
|
372 | | - } |
| 376 | + for ( let v = 0; v < triangles * 3; v ++ ) { |
373 | 377 |
|
374 | | - for ( let v = 0; v < triangles * 3; v ++ ) { |
| 378 | + const i = ~ ~ ( v / 3 ); |
| 379 | + const x = ( i % WIDTH ) / WIDTH; |
| 380 | + const y = ~ ~ ( i / WIDTH ) / WIDTH; |
375 | 381 |
|
376 | | - const i = ~ ~ ( v / 3 ); |
377 | | - const x = ( i % WIDTH ) / WIDTH; |
378 | | - const y = ~ ~ ( i / WIDTH ) / WIDTH; |
| 382 | + const c = new THREE.Color( |
| 383 | + 0x444444 + |
| 384 | + ~ ~ ( v / 9 ) / BIRDS * 0x666666 |
| 385 | + ); |
379 | 386 |
|
380 | | - const c = new THREE.Color( |
381 | | - 0x444444 + |
382 | | - ~ ~ ( v / 9 ) / BIRDS * 0x666666 |
383 | | - ); |
| 387 | + birdColors.array[ v * 3 + 0 ] = c.r; |
| 388 | + birdColors.array[ v * 3 + 1 ] = c.g; |
| 389 | + birdColors.array[ v * 3 + 2 ] = c.b; |
384 | 390 |
|
385 | | - birdColors.array[ v * 3 + 0 ] = c.r; |
386 | | - birdColors.array[ v * 3 + 1 ] = c.g; |
387 | | - birdColors.array[ v * 3 + 2 ] = c.b; |
| 391 | + references.array[ v * 2 ] = x; |
| 392 | + references.array[ v * 2 + 1 ] = y; |
388 | 393 |
|
389 | | - references.array[ v * 2 ] = x; |
390 | | - references.array[ v * 2 + 1 ] = y; |
| 394 | + birdVertex.array[ v ] = v % 9; |
391 | 395 |
|
392 | | - birdVertex.array[ v ] = v % 9; |
| 396 | + } |
393 | 397 |
|
394 | | - } |
| 398 | + this.scale( 0.2, 0.2, 0.2 ); |
395 | 399 |
|
396 | | - this.scale( 0.2, 0.2, 0.2 ); |
| 400 | + } |
397 | 401 |
|
398 | 402 | } |
399 | 403 |
|
400 | | - BirdGeometry.prototype = Object.create( THREE.BufferGeometry.prototype ); |
401 | | - |
| 404 | + // |
402 | 405 |
|
403 | 406 | let container, stats; |
404 | 407 | let camera, scene, renderer; |
|
0 commit comments