NodeBuilder.js 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997
  1. import NodeUniform from './NodeUniform.js';
  2. import NodeAttribute from './NodeAttribute.js';
  3. import NodeVarying from './NodeVarying.js';
  4. import NodeVar from './NodeVar.js';
  5. import NodeCode from './NodeCode.js';
  6. import NodeKeywords from './NodeKeywords.js';
  7. import NodeCache from './NodeCache.js';
  8. import { createNodeMaterialFromType } from '../materials/NodeMaterial.js';
  9. import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';
  10. import { REVISION, NoColorSpace, LinearEncoding, sRGBEncoding, SRGBColorSpace, Color, Vector2, Vector3, Vector4, Float16BufferAttribute } from 'three';
  11. import { stack } from './StackNode.js';
  12. import { maxMipLevel } from '../utils/MaxMipLevelNode.js';
  13. const typeFromLength = new Map( [
  14. [ 2, 'vec2' ],
  15. [ 3, 'vec3' ],
  16. [ 4, 'vec4' ],
  17. [ 9, 'mat3' ],
  18. [ 16, 'mat4' ]
  19. ] );
  20. const typeFromArray = new Map( [
  21. [ Int8Array, 'int' ],
  22. [ Int16Array, 'int' ],
  23. [ Int32Array, 'int' ],
  24. [ Uint8Array, 'uint' ],
  25. [ Uint16Array, 'uint' ],
  26. [ Uint32Array, 'uint' ],
  27. [ Float32Array, 'float' ]
  28. ] );
  29. const isNonPaddingElementArray = new Set( [ Int32Array, Uint32Array, Float32Array ] );
  30. const toFloat = ( value ) => {
  31. value = Number( value );
  32. return value + ( value % 1 ? '' : '.0' );
  33. };
  34. class NodeBuilder {
  35. constructor( object, renderer, parser ) {
  36. this.object = object;
  37. this.material = object && ( object.material || null );
  38. this.geometry = object && ( object.geometry || null );
  39. this.renderer = renderer;
  40. this.parser = parser;
  41. this.nodes = [];
  42. this.updateNodes = [];
  43. this.updateBeforeNodes = [];
  44. this.hashNodes = {};
  45. this.lightsNode = null;
  46. this.environmentNode = null;
  47. this.fogNode = null;
  48. this.toneMappingNode = null;
  49. this.vertexShader = null;
  50. this.fragmentShader = null;
  51. this.computeShader = null;
  52. this.flowNodes = { vertex: [], fragment: [], compute: [] };
  53. this.flowCode = { vertex: '', fragment: '', compute: [] };
  54. this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
  55. this.codes = { vertex: [], fragment: [], compute: [] };
  56. this.bindings = { vertex: [], fragment: [], compute: [] };
  57. this.bindingsOffset = { vertex: 0, fragment: 0, compute: 0 };
  58. this.bindingsArray = null;
  59. this.attributes = [];
  60. this.bufferAttributes = [];
  61. this.varyings = [];
  62. this.vars = { vertex: [], fragment: [], compute: [] };
  63. this.flow = { code: '' };
  64. this.chaining = [];
  65. this.stack = stack();
  66. this.tab = '\t';
  67. this.context = {
  68. keywords: new NodeKeywords(),
  69. material: this.material,
  70. getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode.mul( maxMipLevel( textureNode ) )
  71. };
  72. this.cache = new NodeCache();
  73. this.globalCache = this.cache;
  74. this.flowsData = new WeakMap();
  75. this.shaderStage = null;
  76. this.buildStage = null;
  77. }
  78. getBindings() {
  79. let bindingsArray = this.bindingsArray;
  80. if ( bindingsArray === null ) {
  81. const bindings = this.bindings;
  82. this.bindingsArray = bindingsArray = ( this.material !== null ) ? [ ...bindings.vertex, ...bindings.fragment ] : bindings.compute;
  83. }
  84. return bindingsArray;
  85. }
  86. setHashNode( node, hash ) {
  87. this.hashNodes[ hash ] = node;
  88. }
  89. addNode( node ) {
  90. if ( this.nodes.indexOf( node ) === - 1 ) {
  91. const updateType = node.getUpdateType();
  92. const updateBeforeType = node.getUpdateBeforeType();
  93. if ( updateType !== NodeUpdateType.NONE ) {
  94. this.updateNodes.push( node );
  95. }
  96. if ( updateBeforeType !== NodeUpdateType.NONE ) {
  97. this.updateBeforeNodes.push( node );
  98. }
  99. this.nodes.push( node );
  100. this.setHashNode( node, node.getHash( this ) );
  101. }
  102. }
  103. get currentNode() {
  104. return this.chaining[ this.chaining.length - 1 ];
  105. }
  106. addChain( node ) {
  107. /*
  108. if ( this.chaining.indexOf( node ) !== - 1 ) {
  109. console.warn( 'Recursive node: ', node );
  110. }
  111. */
  112. this.chaining.push( node );
  113. }
  114. removeChain( node ) {
  115. const lastChain = this.chaining.pop();
  116. if ( lastChain !== node ) {
  117. throw new Error( 'NodeBuilder: Invalid node chaining!' );
  118. }
  119. }
  120. getMethod( method ) {
  121. return method;
  122. }
  123. getNodeFromHash( hash ) {
  124. return this.hashNodes[ hash ];
  125. }
  126. addFlow( shaderStage, node ) {
  127. this.flowNodes[ shaderStage ].push( node );
  128. return node;
  129. }
  130. setContext( context ) {
  131. this.context = context;
  132. }
  133. getContext() {
  134. return this.context;
  135. }
  136. setCache( cache ) {
  137. this.cache = cache;
  138. }
  139. getCache() {
  140. return this.cache;
  141. }
  142. isAvailable( /*name*/ ) {
  143. return false;
  144. }
  145. getInstanceIndex() {
  146. console.warn( 'Abstract function.' );
  147. }
  148. getFrontFacing() {
  149. console.warn( 'Abstract function.' );
  150. }
  151. getFragCoord() {
  152. console.warn( 'Abstract function.' );
  153. }
  154. isFlipY() {
  155. return false;
  156. }
  157. getTexture( /* texture, textureProperty, uvSnippet */ ) {
  158. console.warn( 'Abstract function.' );
  159. }
  160. getTextureLevel( /* texture, textureProperty, uvSnippet, levelSnippet */ ) {
  161. console.warn( 'Abstract function.' );
  162. }
  163. // @TODO: rename to .generateConst()
  164. getConst( type, value = null ) {
  165. if ( value === null ) {
  166. if ( type === 'float' || type === 'int' || type === 'uint' ) value = 0;
  167. else if ( type === 'bool' ) value = false;
  168. else if ( type === 'color' ) value = new Color();
  169. else if ( type === 'vec2' ) value = new Vector2();
  170. else if ( type === 'vec3' ) value = new Vector3();
  171. else if ( type === 'vec4' ) value = new Vector4();
  172. }
  173. if ( type === 'float' ) return toFloat( value );
  174. if ( type === 'int' ) return `${ Math.round( value ) }`;
  175. if ( type === 'uint' ) return value >= 0 ? `${ Math.round( value ) }u` : '0u';
  176. if ( type === 'bool' ) return value ? 'true' : 'false';
  177. if ( type === 'color' ) return `${ this.getType( 'vec3' ) }( ${ toFloat( value.r ) }, ${ toFloat( value.g ) }, ${ toFloat( value.b ) } )`;
  178. const typeLength = this.getTypeLength( type );
  179. const componentType = this.getComponentType( type );
  180. const getConst = value => this.getConst( componentType, value );
  181. if ( typeLength === 2 ) {
  182. return `${ this.getType( type ) }( ${ getConst( value.x ) }, ${ getConst( value.y ) } )`;
  183. } else if ( typeLength === 3 ) {
  184. return `${ this.getType( type ) }( ${ getConst( value.x ) }, ${ getConst( value.y ) }, ${ getConst( value.z ) } )`;
  185. } else if ( typeLength === 4 ) {
  186. return `${ this.getType( type ) }( ${ getConst( value.x ) }, ${ getConst( value.y ) }, ${ getConst( value.z ) }, ${ getConst( value.w ) } )`;
  187. } else if ( typeLength > 4 && value && ( value.isMatrix3 || value.isMatrix4 ) ) {
  188. return `${ this.getType( type ) }( ${ value.elements.map( getConst ).join( ', ' ) } )`;
  189. } else if ( typeLength > 4 ) {
  190. return `${ this.getType( type ) }()`;
  191. }
  192. throw new Error( `NodeBuilder: Type '${type}' not found in generate constant attempt.` );
  193. }
  194. getType( type ) {
  195. return type;
  196. }
  197. generateMethod( method ) {
  198. return method;
  199. }
  200. hasGeometryAttribute( name ) {
  201. return this.geometry && this.geometry.getAttribute( name ) !== undefined;
  202. }
  203. getAttribute( name, type ) {
  204. const attributes = this.attributes;
  205. // find attribute
  206. for ( const attribute of attributes ) {
  207. if ( attribute.name === name ) {
  208. return attribute;
  209. }
  210. }
  211. // create a new if no exist
  212. const attribute = new NodeAttribute( name, type );
  213. attributes.push( attribute );
  214. return attribute;
  215. }
  216. getPropertyName( node/*, shaderStage*/ ) {
  217. return node.name;
  218. }
  219. isVector( type ) {
  220. return /vec\d/.test( type );
  221. }
  222. isMatrix( type ) {
  223. return /mat\d/.test( type );
  224. }
  225. isReference( type ) {
  226. return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture';
  227. }
  228. /** @deprecated, r152 */
  229. getTextureEncodingFromMap( map ) {
  230. console.warn( 'THREE.NodeBuilder: Method .getTextureEncodingFromMap replaced by .getTextureColorSpaceFromMap in r152+.' );
  231. return this.getTextureColorSpaceFromMap( map ) === SRGBColorSpace ? sRGBEncoding : LinearEncoding;
  232. }
  233. getTextureColorSpaceFromMap( map ) {
  234. let colorSpace;
  235. if ( map && map.isTexture ) {
  236. colorSpace = map.colorSpace;
  237. } else if ( map && map.isWebGLRenderTarget ) {
  238. colorSpace = map.texture.colorSpace;
  239. } else {
  240. colorSpace = NoColorSpace;
  241. }
  242. return colorSpace;
  243. }
  244. getComponentType( type ) {
  245. type = this.getVectorType( type );
  246. if ( type === 'float' || type === 'bool' || type === 'int' || type === 'uint' ) return type;
  247. const componentType = /(b|i|u|)(vec|mat)([2-4])/.exec( type );
  248. if ( componentType === null ) return null;
  249. if ( componentType[ 1 ] === 'b' ) return 'bool';
  250. if ( componentType[ 1 ] === 'i' ) return 'int';
  251. if ( componentType[ 1 ] === 'u' ) return 'uint';
  252. return 'float';
  253. }
  254. getVectorType( type ) {
  255. if ( type === 'color' ) return 'vec3';
  256. if ( type === 'texture' ) return 'vec4';
  257. return type;
  258. }
  259. getTypeFromLength( length, componentType = 'float' ) {
  260. if ( length === 1 ) return componentType;
  261. const baseType = typeFromLength.get( length );
  262. const prefix = componentType === 'float' ? '' : componentType[ 0 ];
  263. return prefix + baseType;
  264. }
  265. getTypeFromArray( array ) {
  266. return typeFromArray.get( array.constructor );
  267. }
  268. getTypeFromAttribute( attribute ) {
  269. let dataAttribute = attribute;
  270. if ( attribute.isInterleavedBufferAttribute ) dataAttribute = attribute.data;
  271. const array = dataAttribute.array;
  272. const itemSize = isNonPaddingElementArray.has( array.constructor ) ? attribute.itemSize : dataAttribute.stride || attribute.itemSize;
  273. const normalized = attribute.normalized;
  274. let arrayType;
  275. if ( ! ( attribute instanceof Float16BufferAttribute ) && normalized !== true ) {
  276. arrayType = this.getTypeFromArray( array );
  277. }
  278. return this.getTypeFromLength( itemSize, arrayType );
  279. }
  280. getTypeLength( type ) {
  281. const vecType = this.getVectorType( type );
  282. const vecNum = /vec([2-4])/.exec( vecType );
  283. if ( vecNum !== null ) return Number( vecNum[ 1 ] );
  284. if ( vecType === 'float' || vecType === 'bool' || vecType === 'int' || vecType === 'uint' ) return 1;
  285. if ( /mat3/.test( type ) === true ) return 9;
  286. if ( /mat4/.test( type ) === true ) return 16;
  287. return 0;
  288. }
  289. getVectorFromMatrix( type ) {
  290. return type.replace( 'mat', 'vec' );
  291. }
  292. changeComponentType( type, newComponentType ) {
  293. return this.getTypeFromLength( this.getTypeLength( type ), newComponentType );
  294. }
  295. getIntegerType( type ) {
  296. const componentType = this.getComponentType( type );
  297. if ( componentType === 'int' || componentType === 'uint' ) return type;
  298. return this.changeComponentType( type, 'int' );
  299. }
  300. addStack() {
  301. this.stack = stack( this.stack );
  302. return this.stack;
  303. }
  304. removeStack() {
  305. const currentStack = this.stack;
  306. this.stack = currentStack.parent;
  307. return currentStack;
  308. }
  309. getDataFromNode( node, shaderStage = this.shaderStage ) {
  310. const cache = node.isGlobal( this ) ? this.globalCache : this.cache;
  311. let nodeData = cache.getNodeData( node );
  312. if ( nodeData === undefined ) {
  313. nodeData = { vertex: {}, fragment: {}, compute: {} };
  314. cache.setNodeData( node, nodeData );
  315. }
  316. return shaderStage !== null ? nodeData[ shaderStage ] : nodeData;
  317. }
  318. getNodeProperties( node, shaderStage = this.shaderStage ) {
  319. const nodeData = this.getDataFromNode( node, shaderStage );
  320. return nodeData.properties || ( nodeData.properties = { outputNode: null } );
  321. }
  322. getBufferAttributeFromNode( node, type ) {
  323. const nodeData = this.getDataFromNode( node );
  324. let bufferAttribute = nodeData.bufferAttribute;
  325. if ( bufferAttribute === undefined ) {
  326. const index = this.uniforms.index ++;
  327. bufferAttribute = new NodeAttribute( 'nodeAttribute' + index, type, node );
  328. this.bufferAttributes.push( bufferAttribute );
  329. nodeData.bufferAttribute = bufferAttribute;
  330. }
  331. return bufferAttribute;
  332. }
  333. getUniformFromNode( node, type, shaderStage = this.shaderStage ) {
  334. const nodeData = this.getDataFromNode( node, shaderStage );
  335. let nodeUniform = nodeData.uniform;
  336. if ( nodeUniform === undefined ) {
  337. const index = this.uniforms.index ++;
  338. nodeUniform = new NodeUniform( 'nodeUniform' + index, type, node );
  339. this.uniforms[ shaderStage ].push( nodeUniform );
  340. nodeData.uniform = nodeUniform;
  341. }
  342. return nodeUniform;
  343. }
  344. getVarFromNode( node, type, shaderStage = this.shaderStage ) {
  345. const nodeData = this.getDataFromNode( node, shaderStage );
  346. let nodeVar = nodeData.variable;
  347. if ( nodeVar === undefined ) {
  348. const vars = this.vars[ shaderStage ];
  349. const index = vars.length;
  350. nodeVar = new NodeVar( 'nodeVar' + index, type );
  351. vars.push( nodeVar );
  352. nodeData.variable = nodeVar;
  353. }
  354. return nodeVar;
  355. }
  356. getVaryingFromNode( node, type ) {
  357. const nodeData = this.getDataFromNode( node, null );
  358. let nodeVarying = nodeData.varying;
  359. if ( nodeVarying === undefined ) {
  360. const varyings = this.varyings;
  361. const index = varyings.length;
  362. nodeVarying = new NodeVarying( 'nodeVarying' + index, type );
  363. varyings.push( nodeVarying );
  364. nodeData.varying = nodeVarying;
  365. }
  366. return nodeVarying;
  367. }
  368. getCodeFromNode( node, type, shaderStage = this.shaderStage ) {
  369. const nodeData = this.getDataFromNode( node );
  370. let nodeCode = nodeData.code;
  371. if ( nodeCode === undefined ) {
  372. const codes = this.codes[ shaderStage ];
  373. const index = codes.length;
  374. nodeCode = new NodeCode( 'nodeCode' + index, type );
  375. codes.push( nodeCode );
  376. nodeData.code = nodeCode;
  377. }
  378. return nodeCode;
  379. }
  380. addLineFlowCode( code ) {
  381. if ( code === '' ) return this;
  382. code = this.tab + code;
  383. if ( ! /;\s*$/.test( code ) ) {
  384. code = code + ';\n';
  385. }
  386. this.flow.code += code;
  387. return this;
  388. }
  389. addFlowCode( code ) {
  390. this.flow.code += code;
  391. return this;
  392. }
  393. addFlowTab() {
  394. this.tab += '\t';
  395. return this;
  396. }
  397. removeFlowTab() {
  398. this.tab = this.tab.slice( 0, - 1 );
  399. return this;
  400. }
  401. getFlowData( node/*, shaderStage*/ ) {
  402. return this.flowsData.get( node );
  403. }
  404. flowNode( node ) {
  405. const output = node.getNodeType( this );
  406. const flowData = this.flowChildNode( node, output );
  407. this.flowsData.set( node, flowData );
  408. return flowData;
  409. }
  410. flowChildNode( node, output = null ) {
  411. const previousFlow = this.flow;
  412. const flow = {
  413. code: '',
  414. };
  415. this.flow = flow;
  416. flow.result = node.build( this, output );
  417. this.flow = previousFlow;
  418. return flow;
  419. }
  420. flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
  421. const previousShaderStage = this.shaderStage;
  422. this.setShaderStage( shaderStage );
  423. const flowData = this.flowChildNode( node, output );
  424. if ( propertyName !== null ) {
  425. flowData.code += `${ this.tab + propertyName } = ${ flowData.result };\n`;
  426. }
  427. this.flowCode[ shaderStage ] = this.flowCode[ shaderStage ] + flowData.code;
  428. this.setShaderStage( previousShaderStage );
  429. return flowData;
  430. }
  431. getAttributesArray() {
  432. return this.attributes.concat( this.bufferAttributes );
  433. }
  434. getAttributes( /*shaderStage*/ ) {
  435. console.warn( 'Abstract function.' );
  436. }
  437. getVaryings( /*shaderStage*/ ) {
  438. console.warn( 'Abstract function.' );
  439. }
  440. getVar( type, name ) {
  441. return `${type} ${name}`;
  442. }
  443. getVars( shaderStage ) {
  444. let snippet = '';
  445. const vars = this.vars[ shaderStage ];
  446. for ( const variable of vars ) {
  447. snippet += `${ this.getVar( variable.type, variable.name ) }; `;
  448. }
  449. return snippet;
  450. }
  451. getUniforms( /*shaderStage*/ ) {
  452. console.warn( 'Abstract function.' );
  453. }
  454. getCodes( shaderStage ) {
  455. const codes = this.codes[ shaderStage ];
  456. let code = '';
  457. for ( const nodeCode of codes ) {
  458. code += nodeCode.code + '\n';
  459. }
  460. return code;
  461. }
  462. getHash() {
  463. return this.vertexShader + this.fragmentShader + this.computeShader;
  464. }
  465. setShaderStage( shaderStage ) {
  466. this.shaderStage = shaderStage;
  467. }
  468. getShaderStage() {
  469. return this.shaderStage;
  470. }
  471. setBuildStage( buildStage ) {
  472. this.buildStage = buildStage;
  473. }
  474. getBuildStage() {
  475. return this.buildStage;
  476. }
  477. buildCode() {
  478. console.warn( 'Abstract function.' );
  479. }
  480. build() {
  481. // construct() -> stage 1: create possible new nodes and returns an output reference node
  482. // analyze() -> stage 2: analyze nodes to possible optimization and validation
  483. // generate() -> stage 3: generate shader
  484. for ( const buildStage of defaultBuildStages ) {
  485. this.setBuildStage( buildStage );
  486. if ( this.context.vertex && this.context.vertex.isNode ) {
  487. this.flowNodeFromShaderStage( 'vertex', this.context.vertex );
  488. }
  489. for ( const shaderStage of shaderStages ) {
  490. this.setShaderStage( shaderStage );
  491. const flowNodes = this.flowNodes[ shaderStage ];
  492. for ( const node of flowNodes ) {
  493. if ( buildStage === 'generate' ) {
  494. this.flowNode( node );
  495. } else {
  496. node.build( this );
  497. }
  498. }
  499. }
  500. }
  501. this.setBuildStage( null );
  502. this.setShaderStage( null );
  503. // stage 4: build code for a specific output
  504. this.buildCode();
  505. return this;
  506. }
  507. createNodeMaterial( type ) {
  508. return createNodeMaterialFromType( type );
  509. }
  510. format( snippet, fromType, toType ) {
  511. fromType = this.getVectorType( fromType );
  512. toType = this.getVectorType( toType );
  513. if ( fromType === toType || toType === null || this.isReference( toType ) ) {
  514. return snippet;
  515. }
  516. const fromTypeLength = this.getTypeLength( fromType );
  517. const toTypeLength = this.getTypeLength( toType );
  518. if ( fromTypeLength > 4 ) { // fromType is matrix-like
  519. // @TODO: ignore for now
  520. return snippet;
  521. }
  522. if ( toTypeLength > 4 || toTypeLength === 0 ) { // toType is matrix-like or unknown
  523. // @TODO: ignore for now
  524. return snippet;
  525. }
  526. if ( fromTypeLength === toTypeLength ) {
  527. return `${ this.getType( toType ) }( ${ snippet } )`;
  528. }
  529. if ( fromTypeLength > toTypeLength ) {
  530. return this.format( `${ snippet }.${ 'xyz'.slice( 0, toTypeLength ) }`, this.getTypeFromLength( toTypeLength, this.getComponentType( fromType ) ), toType );
  531. }
  532. if ( toTypeLength === 4 ) { // toType is vec4-like
  533. return `${ this.getType( toType ) }( ${ this.format( snippet, fromType, 'vec3' ) }, 1.0 )`;
  534. }
  535. if ( fromTypeLength === 2 ) { // fromType is vec2-like and toType is vec3-like
  536. return `${ this.getType( toType ) }( ${ this.format( snippet, fromType, 'vec2' ) }, 0.0 )`;
  537. }
  538. return `${ this.getType( toType ) }( ${ snippet } )`; // fromType is float-like
  539. }
  540. getSignature() {
  541. return `// Three.js r${ REVISION } - NodeMaterial System\n`;
  542. }
  543. }
  544. export default NodeBuilder;