|
@@ -5,6 +5,7 @@ import { normalLocal } from './NormalNode.js';
|
|
import { positionLocal } from './PositionNode.js';
|
|
import { positionLocal } from './PositionNode.js';
|
|
import { nodeProxy, vec3, mat3, mat4 } from '../shadernode/ShaderNode.js';
|
|
import { nodeProxy, vec3, mat3, mat4 } from '../shadernode/ShaderNode.js';
|
|
import { DynamicDrawUsage, InstancedInterleavedBuffer, InstancedBufferAttribute } from 'three';
|
|
import { DynamicDrawUsage, InstancedInterleavedBuffer, InstancedBufferAttribute } from 'three';
|
|
|
|
+import { NodeUpdateType } from '../core/constants.js';
|
|
|
|
|
|
class InstanceNode extends Node {
|
|
class InstanceNode extends Node {
|
|
|
|
|
|
@@ -18,6 +19,11 @@ class InstanceNode extends Node {
|
|
|
|
|
|
this.instanceColorNode = null;
|
|
this.instanceColorNode = null;
|
|
|
|
|
|
|
|
+ this.updateType = NodeUpdateType.FRAME;
|
|
|
|
+
|
|
|
|
+ this.buffer = null;
|
|
|
|
+ this.bufferColor = null;
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
setup( /*builder*/ ) {
|
|
setup( /*builder*/ ) {
|
|
@@ -31,6 +37,7 @@ class InstanceNode extends Node {
|
|
const instanceAttribute = instanceMesh.instanceMatrix;
|
|
const instanceAttribute = instanceMesh.instanceMatrix;
|
|
const buffer = new InstancedInterleavedBuffer( instanceAttribute.array, 16, 1 );
|
|
const buffer = new InstancedInterleavedBuffer( instanceAttribute.array, 16, 1 );
|
|
|
|
|
|
|
|
+ this.buffer = buffer;
|
|
const bufferFn = instanceAttribute.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
|
|
const bufferFn = instanceAttribute.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
|
|
|
|
|
|
const instanceBuffers = [
|
|
const instanceBuffers = [
|
|
@@ -54,6 +61,7 @@ class InstanceNode extends Node {
|
|
const buffer = new InstancedBufferAttribute( instanceColorAttribute.array, 3 );
|
|
const buffer = new InstancedBufferAttribute( instanceColorAttribute.array, 3 );
|
|
const bufferFn = instanceColorAttribute.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
|
|
const bufferFn = instanceColorAttribute.usage === DynamicDrawUsage ? instancedDynamicBufferAttribute : instancedBufferAttribute;
|
|
|
|
|
|
|
|
+ this.bufferColor = buffer;
|
|
this.instanceColorNode = vec3( bufferFn( buffer, 'vec3', 3, 0 ) );
|
|
this.instanceColorNode = vec3( bufferFn( buffer, 'vec3', 3, 0 ) );
|
|
|
|
|
|
}
|
|
}
|
|
@@ -85,6 +93,22 @@ class InstanceNode extends Node {
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ update( /*frame*/ ) {
|
|
|
|
+
|
|
|
|
+ if ( this.instanceMesh.instanceMatrix.version !== this.buffer.version ) {
|
|
|
|
+
|
|
|
|
+ this.buffer.version = this.instanceMesh.instanceMatrix.version;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if ( this.instanceMesh.instanceColor && this.instanceMesh.instanceColor.version !== this.bufferColor.version ) {
|
|
|
|
+
|
|
|
|
+ this.bufferColor.version = this.instanceMesh.instanceColor.version;
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
export default InstanceNode;
|
|
export default InstanceNode;
|