|
@@ -70,11 +70,8 @@
|
|
const _stemMesh = gltf.scene.getObjectByName( 'Stem' );
|
|
const _stemMesh = gltf.scene.getObjectByName( 'Stem' );
|
|
const _blossomMesh = gltf.scene.getObjectByName( 'Blossom' );
|
|
const _blossomMesh = gltf.scene.getObjectByName( 'Blossom' );
|
|
|
|
|
|
- stemGeometry = new THREE.InstancedBufferGeometry();
|
|
|
|
- blossomGeometry = new THREE.InstancedBufferGeometry();
|
|
|
|
-
|
|
|
|
- THREE.BufferGeometry.prototype.copy.call( stemGeometry, _stemMesh.geometry );
|
|
|
|
- THREE.BufferGeometry.prototype.copy.call( blossomGeometry, _blossomMesh.geometry );
|
|
|
|
|
|
+ stemGeometry = _stemMesh.geometry.clone();
|
|
|
|
+ blossomGeometry = _blossomMesh.geometry.clone();
|
|
|
|
|
|
const defaultTransform = new THREE.Matrix4()
|
|
const defaultTransform = new THREE.Matrix4()
|
|
.makeRotationX( Math.PI )
|
|
.makeRotationX( Math.PI )
|
|
@@ -86,24 +83,20 @@
|
|
stemMaterial = _stemMesh.material;
|
|
stemMaterial = _stemMesh.material;
|
|
blossomMaterial = _blossomMesh.material;
|
|
blossomMaterial = _blossomMesh.material;
|
|
|
|
|
|
|
|
+ stemMesh = new THREE.InstancedMesh( stemGeometry, stemMaterial, count );
|
|
|
|
+ blossomMesh = new THREE.InstancedMesh( blossomGeometry, blossomMaterial, count );
|
|
|
|
+
|
|
// Assign random colors to the blossoms.
|
|
// Assign random colors to the blossoms.
|
|
- const _color = new THREE.Color();
|
|
|
|
- const color = new Float32Array( count * 3 );
|
|
|
|
|
|
+ const color = new THREE.Color();
|
|
const blossomPalette = [ 0xF20587, 0xF2D479, 0xF2C879, 0xF2B077, 0xF24405 ];
|
|
const blossomPalette = [ 0xF20587, 0xF2D479, 0xF2C879, 0xF2B077, 0xF24405 ];
|
|
|
|
|
|
for ( let i = 0; i < count; i ++ ) {
|
|
for ( let i = 0; i < count; i ++ ) {
|
|
|
|
|
|
- _color.setHex( blossomPalette[ Math.floor( Math.random() * blossomPalette.length ) ] );
|
|
|
|
- _color.toArray( color, i * 3 );
|
|
|
|
|
|
+ color.setHex( blossomPalette[ Math.floor( Math.random() * blossomPalette.length ) ] );
|
|
|
|
+ blossomMesh.setColorAt( i, color );
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- blossomGeometry.setAttribute( 'color', new THREE.InstancedBufferAttribute( color, 3 ) );
|
|
|
|
- blossomMaterial.vertexColors = true;
|
|
|
|
-
|
|
|
|
- stemMesh = new THREE.InstancedMesh( stemGeometry, stemMaterial, count );
|
|
|
|
- blossomMesh = new THREE.InstancedMesh( blossomGeometry, blossomMaterial, count );
|
|
|
|
-
|
|
|
|
// Instance matrices will be updated every frame.
|
|
// Instance matrices will be updated every frame.
|
|
stemMesh.instanceMatrix.setUsage( THREE.DynamicDrawUsage );
|
|
stemMesh.instanceMatrix.setUsage( THREE.DynamicDrawUsage );
|
|
blossomMesh.instanceMatrix.setUsage( THREE.DynamicDrawUsage );
|
|
blossomMesh.instanceMatrix.setUsage( THREE.DynamicDrawUsage );
|