123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475 |
- import Node from './Node.js';
- import FloatNode from '../inputs/FloatNode.js';
- const zeroValue = new FloatNode( 0 ).setConst( true );
- class StructVarNode extends Node {
- constructor( struct, inputs = {} ) {
- super();
- this.struct = struct;
- this.inputs = inputs;
- }
- getType( builder ) {
- return this.struct.getType( builder );
- }
- generate( builder, output ) {
- const type = this.getType( builder );
- const struct = this.struct;
- const inputs = this.inputs;
- const structInputs = this.struct.inputs;
- const nodeData = builder.getDataFromNode( this );
- let property = nodeData.property;
- if ( property === undefined ) {
- property = struct.build( builder, 'var' );
- const inputsSnippets = [];
- for ( const inputName in structInputs ) {
- const inputType = structInputs[ inputName ];
- const input = inputs[ inputName ];
- let inputSnippet = null;
- if ( input !== undefined ) {
- inputSnippet = input.build( builder, inputType );
- } else {
- inputSnippet = zeroValue.build( builder, inputType );
- }
- inputsSnippets.push( inputSnippet );
- }
- builder.addFlowCode( `${type} ${property} = ${type}( ${inputsSnippets.join( ', ' )} )` );
- nodeData.property = property;
- }
- return builder.format( property, type, output );
- }
- }
- export default StructVarNode;
|