NodeBuilder.js 18 KB

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