1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980 |
- import Node from './Node.js';
- class CodeNode extends Node {
- constructor( code = '', type = 'code' ) {
- super( type );
- this.code = code;
- this.useKeywords = false;
- this._includes = [];
- Object.defineProperty( this, 'isCodeNode', { value: true } );
- }
- setIncludes( includes ) {
- this._includes = includes;
- return this;
- }
- getIncludes( /*builder*/ ) {
- return this._includes;
- }
- generate( builder, output ) {
- if ( this.useKeywords === true ) {
- const contextKeywords = builder.getContextValue( 'keywords' );
- if ( contextKeywords !== undefined ) {
- const nodeData = builder.getDataFromNode( this, builder.shaderStage );
- if ( nodeData.keywords === undefined ) {
- nodeData.keywords = [];
- }
- if ( nodeData.keywords.indexOf( contextKeywords ) === - 1 ) {
- contextKeywords.include( builder, this.code );
- nodeData.keywords.push( contextKeywords );
- }
- }
- }
- const includes = this.getIncludes( builder );
- for ( const include of includes ) {
- include.build( builder );
- }
- const type = this.getType( builder );
- const nodeCode = builder.getCodeFromNode( this, type );
- nodeCode.code = this.code;
- return nodeCode.code;
- }
- }
- export default CodeNode;
|