|
@@ -2,36 +2,63 @@ import Node, { addNodeClass } from '../core/Node.js';
|
|
|
import { NodeUpdateType } from '../core/constants.js';
|
|
|
import { uniform } from '../core/UniformNode.js';
|
|
|
import { texture } from './TextureNode.js';
|
|
|
+import { buffer } from './BufferNode.js';
|
|
|
import { nodeObject } from '../shadernode/ShaderNode.js';
|
|
|
import { uniforms } from './UniformsNode.js';
|
|
|
+import ArrayElementNode from '../utils/ArrayElementNode.js';
|
|
|
+
|
|
|
+class ReferenceElementNode extends ArrayElementNode {
|
|
|
+
|
|
|
+ constructor( referenceNode, indexNode ) {
|
|
|
+
|
|
|
+ super( referenceNode, indexNode );
|
|
|
+
|
|
|
+ this.referenceNode = referenceNode;
|
|
|
+
|
|
|
+ this.isReferenceElementNode = true;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ getNodeType() {
|
|
|
+
|
|
|
+ return this.referenceNode.uniformType;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ generate( builder ) {
|
|
|
+
|
|
|
+ const snippet = super.generate( builder );
|
|
|
+ const arrayType = this.referenceNode.getNodeType();
|
|
|
+ const elementType = this.getNodeType();
|
|
|
+
|
|
|
+ return builder.format( snippet, arrayType, elementType );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
|
|
|
class ReferenceNode extends Node {
|
|
|
|
|
|
- constructor( property, uniformType, object = null, indexNode = null ) {
|
|
|
+ constructor( property, uniformType, object = null, count = null ) {
|
|
|
|
|
|
super();
|
|
|
|
|
|
this.property = property;
|
|
|
- this.indexNode = indexNode;
|
|
|
-
|
|
|
this.uniformType = uniformType;
|
|
|
-
|
|
|
this.object = object;
|
|
|
- this.reference = null;
|
|
|
+ this.count = count;
|
|
|
|
|
|
+ this.properties = property.split( '.' );
|
|
|
+ this.reference = null;
|
|
|
this.node = null;
|
|
|
|
|
|
this.updateType = NodeUpdateType.OBJECT;
|
|
|
|
|
|
- this.setNodeType( uniformType );
|
|
|
-
|
|
|
}
|
|
|
|
|
|
- updateReference( frame ) {
|
|
|
+ element( indexNode ) {
|
|
|
|
|
|
- this.reference = this.object !== null ? this.object : frame.object;
|
|
|
-
|
|
|
- return this.reference;
|
|
|
+ return nodeObject( new ReferenceElementNode( this, nodeObject( indexNode ) ) );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -39,17 +66,21 @@ class ReferenceNode extends Node {
|
|
|
|
|
|
let node = null;
|
|
|
|
|
|
- if ( uniformType === 'texture' ) {
|
|
|
+ if ( this.count !== null ) {
|
|
|
|
|
|
- node = texture( null );
|
|
|
+ node = buffer( null, uniformType, this.count );
|
|
|
+
|
|
|
+ } else if ( Array.isArray( this.getValueFromReference() ) ) {
|
|
|
+
|
|
|
+ node = uniforms( null, uniformType );
|
|
|
|
|
|
- } else if ( this.indexNode !== null ) {
|
|
|
+ } else if ( uniformType === 'texture' ) {
|
|
|
|
|
|
- node = uniforms( null, uniformType ).element( this.indexNode );
|
|
|
+ node = texture( null );
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- node = uniform( uniformType );
|
|
|
+ node = uniform( null, uniformType );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -63,40 +94,67 @@ class ReferenceNode extends Node {
|
|
|
|
|
|
}
|
|
|
|
|
|
- update( /*frame*/ ) {
|
|
|
+ getValueFromReference( object = this.reference ) {
|
|
|
|
|
|
- const value = this.reference[ this.property ];
|
|
|
+ const { properties } = this;
|
|
|
|
|
|
- if ( this.indexNode !== null ) {
|
|
|
+ let value = object[ properties[ 0 ] ];
|
|
|
|
|
|
- this.node.node.array = value;
|
|
|
+ for ( let i = 1; i < properties.length; i ++ ) {
|
|
|
|
|
|
- } else {
|
|
|
-
|
|
|
- this.node.value = value;
|
|
|
+ value = value[ properties[ i ] ];
|
|
|
|
|
|
}
|
|
|
|
|
|
+ return value;
|
|
|
|
|
|
}
|
|
|
|
|
|
- setup( builder ) {
|
|
|
+ setReference( state ) {
|
|
|
|
|
|
- if ( this.indexNode !== null ) {
|
|
|
+ this.reference = this.object !== null ? this.object : state.object;
|
|
|
|
|
|
- this.node.node.array = ( this.object !== null ? this.object : builder.object )[ this.property ];
|
|
|
+ return this.reference;
|
|
|
|
|
|
- }
|
|
|
+ }
|
|
|
+
|
|
|
+ setup() {
|
|
|
+
|
|
|
+ this.updateValue();
|
|
|
|
|
|
return this.node;
|
|
|
|
|
|
}
|
|
|
|
|
|
+ update( /*frame*/ ) {
|
|
|
+
|
|
|
+ this.updateValue();
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ updateValue() {
|
|
|
+
|
|
|
+ if ( this.node === null ) this.setNodeType( this.uniformType );
|
|
|
+
|
|
|
+ const value = this.getValueFromReference();
|
|
|
+
|
|
|
+ if ( Array.isArray( value ) ) {
|
|
|
+
|
|
|
+ this.node.array = value;
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ this.node.value = value;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
export default ReferenceNode;
|
|
|
|
|
|
export const reference = ( name, type, object ) => nodeObject( new ReferenceNode( name, type, object ) );
|
|
|
-export const referenceIndex = ( name, index, type, object ) => nodeObject( new ReferenceNode( name, type, object, index ) );
|
|
|
+export const referenceBuffer = ( name, type, count, object ) => nodeObject( new ReferenceNode( name, type, object, count ) );
|
|
|
|
|
|
addNodeClass( 'ReferenceNode', ReferenceNode );
|