You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.0 KiB

2 years ago
import Node from '../core/Node.js';
import UniformNode from '../core/UniformNode.js';
import { NodeUpdateType } from '../core/constants.js';
class ReferenceNode extends Node {
constructor( property, uniformType, object = null ) {
super();
this.property = property;
this.uniformType = uniformType;
this.object = object;
this.node = null;
this.updateType = NodeUpdateType.OBJECT;
this.setNodeType( uniformType );
}
setNodeType( uniformType ) {
this.node = new UniformNode( null, uniformType );
this.nodeType = uniformType;
if ( uniformType === 'color' ) {
this.nodeType = 'vec3';
} else if ( uniformType === 'texture' ) {
this.nodeType = 'vec4';
}
}
getNodeType() {
return this.uniformType;
}
update( frame ) {
const object = this.object !== null ? this.object : frame.object;
const value = object[ this.property ];
this.node.value = value;
}
generate( builder ) {
return this.node.build( builder, this.getNodeType( builder ) );
}
}
export default ReferenceNode;