NodeBuilder.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988
  1. /**
  2. * @author sunag / http://www.sunag.com.br/
  3. */
  4. import {
  5. CubeReflectionMapping,
  6. CubeRefractionMapping,
  7. CubeUVReflectionMapping,
  8. CubeUVRefractionMapping,
  9. LinearEncoding,
  10. GammaEncoding
  11. } from '../../../../build/three.module.js';
  12. import { NodeUniform } from './NodeUniform.js';
  13. import { NodeUtils } from './NodeUtils.js';
  14. import { NodeLib } from './NodeLib.js';
  15. import { FunctionNode } from './FunctionNode.js';
  16. import { ConstNode } from './ConstNode.js';
  17. import { StructNode } from './StructNode.js';
  18. import { Vector2Node } from '../inputs/Vector2Node.js';
  19. import { Vector3Node } from '../inputs/Vector3Node.js';
  20. import { Vector4Node } from '../inputs/Vector4Node.js';
  21. import { TextureNode } from '../inputs/TextureNode.js';
  22. import { CubeTextureNode } from '../inputs/CubeTextureNode.js';
  23. import { TextureCubeNode } from '../misc/TextureCubeNode.js';
  24. var elements = NodeUtils.elements,
  25. constructors = [ 'float', 'vec2', 'vec3', 'vec4' ],
  26. convertFormatToType = {
  27. float: 'f',
  28. vec2: 'v2',
  29. vec3: 'v3',
  30. vec4: 'v4',
  31. mat4: 'v4',
  32. int: 'i',
  33. bool: 'b'
  34. },
  35. convertTypeToFormat = {
  36. t: 'sampler2D',
  37. tc: 'samplerCube',
  38. b: 'bool',
  39. i: 'int',
  40. f: 'float',
  41. c: 'vec3',
  42. v2: 'vec2',
  43. v3: 'vec3',
  44. v4: 'vec4',
  45. m3: 'mat3',
  46. m4: 'mat4'
  47. };
  48. function NodeBuilder() {
  49. this.slots = [];
  50. this.caches = [];
  51. this.contexts = [];
  52. this.keywords = {};
  53. this.nodeData = {};
  54. this.requires = {
  55. uv: [],
  56. color: [],
  57. lights: false,
  58. fog: false,
  59. transparent: false,
  60. irradiance: false
  61. };
  62. this.includes = {
  63. consts: [],
  64. functions: [],
  65. structs: []
  66. };
  67. this.attributes = {};
  68. this.prefixCode = [
  69. "#ifdef TEXTURE_LOD_EXT",
  70. " #define texCube(a, b) textureCube(a, b)",
  71. " #define texCubeBias(a, b, c) textureCubeLodEXT(a, b, c)",
  72. " #define tex2D(a, b) texture2D(a, b)",
  73. " #define tex2DBias(a, b, c) texture2DLodEXT(a, b, c)",
  74. "#else",
  75. " #define texCube(a, b) textureCube(a, b)",
  76. " #define texCubeBias(a, b, c) textureCube(a, b, c)",
  77. " #define tex2D(a, b) texture2D(a, b)",
  78. " #define tex2DBias(a, b, c) texture2D(a, b, c)",
  79. "#endif",
  80. "#include <packing>",
  81. "#include <common>"
  82. ].join( "\n" );
  83. this.parsCode = {
  84. vertex: '',
  85. fragment: ''
  86. };
  87. this.code = {
  88. vertex: '',
  89. fragment: ''
  90. };
  91. this.nodeCode = {
  92. vertex: '',
  93. fragment: ''
  94. };
  95. this.resultCode = {
  96. vertex: '',
  97. fragment: ''
  98. };
  99. this.finalCode = {
  100. vertex: '',
  101. fragment: ''
  102. };
  103. this.inputs = {
  104. uniforms: {
  105. list: [],
  106. vertex: [],
  107. fragment: []
  108. },
  109. vars: {
  110. varying: [],
  111. vertex: [],
  112. fragment: []
  113. }
  114. };
  115. // send to material
  116. this.defines = {};
  117. this.uniforms = {};
  118. this.extensions = {};
  119. this.updaters = [];
  120. this.nodes = [];
  121. // --
  122. this.analyzing = false;
  123. }
  124. NodeBuilder.prototype = {
  125. constructor: NodeBuilder,
  126. build: function ( vertex, fragment ) {
  127. this.buildShader( 'vertex', vertex );
  128. this.buildShader( 'fragment', fragment );
  129. for ( var i = 0; i < this.requires.uv.length; i ++ ) {
  130. if ( this.requires.uv[ i ] ) {
  131. var uvIndex = i > 0 ? i + 1 : '';
  132. this.addVaryCode( 'varying vec2 vUv' + uvIndex + ';' );
  133. if ( i > 0 ) {
  134. this.addVertexParsCode( 'attribute vec2 uv' + uvIndex + ';' );
  135. }
  136. this.addVertexFinalCode( 'vUv' + uvIndex + ' = uv' + uvIndex + ';' );
  137. }
  138. }
  139. if ( this.requires.color[ 0 ] ) {
  140. this.addVaryCode( 'varying vec4 vColor;' );
  141. this.addVertexParsCode( 'attribute vec4 color;' );
  142. this.addVertexFinalCode( 'vColor = color;' );
  143. }
  144. if ( this.requires.color[ 1 ] ) {
  145. this.addVaryCode( 'varying vec4 vColor2;' );
  146. this.addVertexParsCode( 'attribute vec4 color2;' );
  147. this.addVertexFinalCode( 'vColor2 = color2;' );
  148. }
  149. if ( this.requires.position ) {
  150. this.addVaryCode( 'varying vec3 vPosition;' );
  151. this.addVertexFinalCode( 'vPosition = transformed;' );
  152. }
  153. if ( this.requires.worldPosition ) {
  154. this.addVaryCode( 'varying vec3 vWPosition;' );
  155. this.addVertexFinalCode( 'vWPosition = ( modelMatrix * vec4( transformed, 1.0 ) ).xyz;' );
  156. }
  157. if ( this.requires.normal ) {
  158. this.addVaryCode( 'varying vec3 vObjectNormal;' );
  159. this.addVertexFinalCode( 'vObjectNormal = normal;' );
  160. }
  161. if ( this.requires.worldNormal ) {
  162. this.addVaryCode( 'varying vec3 vWNormal;' );
  163. this.addVertexFinalCode( 'vWNormal = inverseTransformDirection( transformedNormal, viewMatrix ).xyz;' );
  164. }
  165. return this;
  166. },
  167. buildShader: function ( shader, node ) {
  168. this.resultCode[ shader ] = node.build( this.setShader( shader ), 'v4' );
  169. },
  170. setMaterial: function ( material, renderer ) {
  171. this.material = material;
  172. this.renderer = renderer;
  173. this.requires.lights = material.lights;
  174. this.requires.fog = material.fog;
  175. this.mergeDefines( material.defines );
  176. return this;
  177. },
  178. addFlow: function ( slot, cache, context ) {
  179. return this.addSlot( slot ).addCache( cache ).addContext( context );
  180. },
  181. removeFlow: function () {
  182. return this.removeSlot().removeCache().removeContext();
  183. },
  184. addCache: function ( name ) {
  185. this.cache = name || '';
  186. this.caches.push( this.cache );
  187. return this;
  188. },
  189. removeCache: function () {
  190. this.caches.pop();
  191. this.cache = this.caches[ this.caches.length - 1 ] || '';
  192. return this;
  193. },
  194. addContext: function ( context ) {
  195. this.context = Object.assign( {}, this.context, context );
  196. this.context.extra = this.context.extra || {};
  197. this.contexts.push( this.context );
  198. return this;
  199. },
  200. removeContext: function () {
  201. this.contexts.pop();
  202. this.context = this.contexts[ this.contexts.length - 1 ] || {};
  203. return this;
  204. },
  205. addSlot: function ( name ) {
  206. this.slot = name || '';
  207. this.slots.push( this.slot );
  208. return this;
  209. },
  210. removeSlot: function () {
  211. this.slots.pop();
  212. this.slot = this.slots[ this.slots.length - 1 ] || '';
  213. return this;
  214. },
  215. addVertexCode: function ( code ) {
  216. this.addCode( code, 'vertex' );
  217. },
  218. addFragmentCode: function ( code ) {
  219. this.addCode( code, 'fragment' );
  220. },
  221. addCode: function ( code, shader ) {
  222. this.code[ shader || this.shader ] += code + '\n';
  223. },
  224. addVertexNodeCode: function ( code ) {
  225. this.addNodeCode( code, 'vertex' );
  226. },
  227. addFragmentNodeCode: function ( code ) {
  228. this.addNodeCode( code, 'fragment' );
  229. },
  230. addNodeCode: function ( code, shader ) {
  231. this.nodeCode[ shader || this.shader ] += code + '\n';
  232. },
  233. clearNodeCode: function ( shader ) {
  234. shader = shader || this.shader;
  235. var code = this.nodeCode[ shader ];
  236. this.nodeCode[ shader ] = '';
  237. return code;
  238. },
  239. clearVertexNodeCode: function ( ) {
  240. return this.clearNodeCode( 'vertex' );
  241. },
  242. clearFragmentNodeCode: function ( ) {
  243. return this.clearNodeCode( 'fragment' );
  244. },
  245. addVertexFinalCode: function ( code ) {
  246. this.addFinalCode( code, 'vertex' );
  247. },
  248. addFragmentFinalCode: function ( code ) {
  249. this.addFinalCode( code, 'fragment' );
  250. },
  251. addFinalCode: function ( code, shader ) {
  252. this.finalCode[ shader || this.shader ] += code + '\n';
  253. },
  254. addVertexParsCode: function ( code ) {
  255. this.addParsCode( code, 'vertex' );
  256. },
  257. addFragmentParsCode: function ( code ) {
  258. this.addParsCode( code, 'fragment' );
  259. },
  260. addParsCode: function ( code, shader ) {
  261. this.parsCode[ shader || this.shader ] += code + '\n';
  262. },
  263. addVaryCode: function ( code ) {
  264. this.addVertexParsCode( code );
  265. this.addFragmentParsCode( code );
  266. },
  267. isCache: function ( name ) {
  268. return this.caches.indexOf( name ) !== - 1;
  269. },
  270. isSlot: function ( name ) {
  271. return this.slots.indexOf( name ) !== - 1;
  272. },
  273. define: function ( name, value ) {
  274. this.defines[ name ] = value === undefined ? 1 : value;
  275. },
  276. require: function ( name ) {
  277. this.requires[ name ] = true;
  278. },
  279. isDefined: function ( name ) {
  280. return this.defines[ name ] !== undefined;
  281. },
  282. getVar: function ( uuid, type, ns, shader = 'varying', prefix = 'V', label = '' ) {
  283. var vars = this.getVars( shader ),
  284. data = vars[ uuid ];
  285. if ( ! data ) {
  286. var index = vars.length,
  287. name = ns ? ns : 'node' + prefix + index + ( label ? '_' + label : '' );
  288. data = { name: name, type: type };
  289. vars.push( data );
  290. vars[ uuid ] = data;
  291. }
  292. return data;
  293. },
  294. getTempVar: function ( uuid, type, ns, label ) {
  295. return this.getVar( uuid, type, ns, this.shader, 'T', label );
  296. },
  297. getAttribute: function ( name, type ) {
  298. if ( ! this.attributes[ name ] ) {
  299. var varying = this.getVar( name, type );
  300. this.addVertexParsCode( 'attribute ' + type + ' ' + name + ';' );
  301. this.addVertexFinalCode( varying.name + ' = ' + name + ';' );
  302. this.attributes[ name ] = { varying: varying, name: name, type: type };
  303. }
  304. return this.attributes[ name ];
  305. },
  306. getCode: function ( shader ) {
  307. return [
  308. this.prefixCode,
  309. this.parsCode[ shader ],
  310. this.getVarListCode( this.getVars( 'varying' ), 'varying' ),
  311. this.getVarListCode( this.inputs.uniforms[ shader ], 'uniform' ),
  312. this.getIncludesCode( 'consts', shader ),
  313. this.getIncludesCode( 'structs', shader ),
  314. this.getIncludesCode( 'functions', shader ),
  315. 'void main() {',
  316. this.getVarListCode( this.getVars( shader ) ),
  317. this.code[ shader ],
  318. this.resultCode[ shader ],
  319. this.finalCode[ shader ],
  320. '}'
  321. ].join( "\n" );
  322. },
  323. getVarListCode: function ( vars, prefix ) {
  324. prefix = prefix || '';
  325. var code = '';
  326. for ( var i = 0, l = vars.length; i < l; ++ i ) {
  327. var nVar = vars[ i ],
  328. type = nVar.type,
  329. name = nVar.name;
  330. var formatType = this.getFormatByType( type );
  331. if ( formatType === undefined ) {
  332. throw new Error( "Node pars " + formatType + " not found." );
  333. }
  334. code += prefix + ' ' + formatType + ' ' + name + ';\n';
  335. }
  336. return code;
  337. },
  338. getVars: function ( shader ) {
  339. return this.inputs.vars[ shader || this.shader ];
  340. },
  341. getNodeData: function ( node ) {
  342. var uuid = node.isNode ? node.uuid : node;
  343. return this.nodeData[ uuid ] = this.nodeData[ uuid ] || {};
  344. },
  345. createUniform: function ( shader, type, node, ns, needsUpdate, label ) {
  346. var uniforms = this.inputs.uniforms,
  347. index = uniforms.list.length;
  348. var uniform = new NodeUniform( {
  349. type: type,
  350. name: ns ? ns : 'nodeU' + index + ( label ? '_' + label : '' ),
  351. node: node,
  352. needsUpdate: needsUpdate
  353. } );
  354. uniforms.list.push( uniform );
  355. uniforms[ shader ].push( uniform );
  356. uniforms[ shader ][ uniform.name ] = uniform;
  357. this.uniforms[ uniform.name ] = uniform;
  358. return uniform;
  359. },
  360. createVertexUniform: function ( type, node, ns, needsUpdate, label ) {
  361. return this.createUniform( 'vertex', type, node, ns, needsUpdate, label );
  362. },
  363. createFragmentUniform: function ( type, node, ns, needsUpdate, label ) {
  364. return this.createUniform( 'fragment', type, node, ns, needsUpdate, label );
  365. },
  366. include: function ( node, parent, source ) {
  367. var includesStruct;
  368. node = typeof node === 'string' ? NodeLib.get( node ) : node;
  369. if ( this.context.include === false ) {
  370. return node.name;
  371. }
  372. if ( node instanceof FunctionNode ) {
  373. includesStruct = this.includes.functions;
  374. } else if ( node instanceof ConstNode ) {
  375. includesStruct = this.includes.consts;
  376. } else if ( node instanceof StructNode ) {
  377. includesStruct = this.includes.structs;
  378. }
  379. var includes = includesStruct[ this.shader ] = includesStruct[ this.shader ] || [];
  380. if ( node ) {
  381. var included = includes[ node.name ];
  382. if ( ! included ) {
  383. included = includes[ node.name ] = {
  384. node: node,
  385. deps: []
  386. };
  387. includes.push( included );
  388. included.src = node.build( this, 'source' );
  389. }
  390. if ( node instanceof FunctionNode && parent && includes[ parent.name ] && includes[ parent.name ].deps.indexOf( node ) == - 1 ) {
  391. includes[ parent.name ].deps.push( node );
  392. if ( node.includes && node.includes.length ) {
  393. var i = 0;
  394. do {
  395. this.include( node.includes[ i ++ ], parent );
  396. } while ( i < node.includes.length );
  397. }
  398. }
  399. if ( source ) {
  400. included.src = source;
  401. }
  402. return node.name;
  403. } else {
  404. throw new Error( "Include not found." );
  405. }
  406. },
  407. colorToVectorProperties: function ( color ) {
  408. return color.replace( 'r', 'x' ).replace( 'g', 'y' ).replace( 'b', 'z' ).replace( 'a', 'w' );
  409. },
  410. colorToVector: function ( color ) {
  411. return color.replace( /c/g, 'v3' );
  412. },
  413. getIncludes: function ( type, shader ) {
  414. return this.includes[ type ][ shader || this.shader ];
  415. },
  416. getIncludesCode: function () {
  417. function sortByPosition( a, b ) {
  418. return a.deps.length - b.deps.length;
  419. }
  420. return function getIncludesCode( type, shader ) {
  421. var includes = this.getIncludes( type, shader );
  422. if ( ! includes ) return '';
  423. var code = '',
  424. includes = includes.sort( sortByPosition );
  425. for ( var i = 0; i < includes.length; i ++ ) {
  426. if ( includes[ i ].src ) code += includes[ i ].src + '\n';
  427. }
  428. return code;
  429. };
  430. }(),
  431. getConstructorFromLength: function ( len ) {
  432. return constructors[ len - 1 ];
  433. },
  434. isTypeMatrix: function ( format ) {
  435. return /^m/.test( format );
  436. },
  437. getTypeLength: function ( type ) {
  438. if ( type === 'f' ) return 1;
  439. return parseInt( this.colorToVector( type ).substr( 1 ) );
  440. },
  441. getTypeFromLength: function ( len ) {
  442. if ( len === 1 ) return 'f';
  443. return 'v' + len;
  444. },
  445. findNode: function () {
  446. for ( var i = 0; i < arguments.length; i ++ ) {
  447. var nodeCandidate = arguments[ i ];
  448. if ( nodeCandidate !== undefined && nodeCandidate.isNode ) {
  449. return nodeCandidate;
  450. }
  451. }
  452. },
  453. resolve: function () {
  454. for ( var i = 0; i < arguments.length; i ++ ) {
  455. var nodeCandidate = arguments[ i ];
  456. if ( nodeCandidate !== undefined ) {
  457. if ( nodeCandidate.isNode ) {
  458. return nodeCandidate;
  459. } else if ( nodeCandidate.isTexture ) {
  460. switch ( nodeCandidate.mapping ) {
  461. case CubeReflectionMapping:
  462. case CubeRefractionMapping:
  463. return new CubeTextureNode( nodeCandidate );
  464. break;
  465. case CubeUVReflectionMapping:
  466. case CubeUVRefractionMapping:
  467. return new TextureCubeNode( new TextureNode( nodeCandidate ) );
  468. break;
  469. default:
  470. return new TextureNode( nodeCandidate );
  471. }
  472. } else if ( nodeCandidate.isVector2 ) {
  473. return new Vector2Node( nodeCandidate );
  474. } else if ( nodeCandidate.isVector3 ) {
  475. return new Vector3Node( nodeCandidate );
  476. } else if ( nodeCandidate.isVector4 ) {
  477. return new Vector4Node( nodeCandidate );
  478. }
  479. }
  480. }
  481. },
  482. format: function ( code, from, to ) {
  483. var typeToType = this.colorToVector( to + ' <- ' + from );
  484. switch ( typeToType ) {
  485. case 'f <- v2' : return code + '.x';
  486. case 'f <- v3' : return code + '.x';
  487. case 'f <- v4' : return code + '.x';
  488. case 'f <- i' :
  489. case 'f <- b' : return 'float( ' + code + ' )';
  490. case 'v2 <- f' : return 'vec2( ' + code + ' )';
  491. case 'v2 <- v3': return code + '.xy';
  492. case 'v2 <- v4': return code + '.xy';
  493. case 'v2 <- i' :
  494. case 'v2 <- b' : return 'vec2( float( ' + code + ' ) )';
  495. case 'v3 <- f' : return 'vec3( ' + code + ' )';
  496. case 'v3 <- v2': return 'vec3( ' + code + ', 0.0 )';
  497. case 'v3 <- v4': return code + '.xyz';
  498. case 'v3 <- i' :
  499. case 'v3 <- b' : return 'vec2( float( ' + code + ' ) )';
  500. case 'v4 <- f' : return 'vec4( ' + code + ' )';
  501. case 'v4 <- v2': return 'vec4( ' + code + ', 0.0, 1.0 )';
  502. case 'v4 <- v3': return 'vec4( ' + code + ', 1.0 )';
  503. case 'v4 <- i' :
  504. case 'v4 <- b' : return 'vec4( float( ' + code + ' ) )';
  505. case 'i <- f' :
  506. case 'i <- b' : return 'int( ' + code + ' )';
  507. case 'i <- v2' : return 'int( ' + code + '.x )';
  508. case 'i <- v3' : return 'int( ' + code + '.x )';
  509. case 'i <- v4' : return 'int( ' + code + '.x )';
  510. case 'b <- f' : return '( ' + code + ' != 0.0 )';
  511. case 'b <- v2' : return '( ' + code + ' != vec2( 0.0 ) )';
  512. case 'b <- v3' : return '( ' + code + ' != vec3( 0.0 ) )';
  513. case 'b <- v4' : return '( ' + code + ' != vec4( 0.0 ) )';
  514. case 'b <- i' : return '( ' + code + ' != 0 )';
  515. }
  516. return code;
  517. },
  518. getTypeByFormat: function ( format ) {
  519. return convertFormatToType[ format ] || format;
  520. },
  521. getFormatByType: function ( type ) {
  522. return convertTypeToFormat[ type ] || type;
  523. },
  524. getUuid: function ( uuid, useCache ) {
  525. useCache = useCache !== undefined ? useCache : true;
  526. if ( useCache && this.cache ) uuid = this.cache + '-' + uuid;
  527. return uuid;
  528. },
  529. getElementByIndex: function ( index ) {
  530. return elements[ index ];
  531. },
  532. getIndexByElement: function ( elm ) {
  533. return elements.indexOf( elm );
  534. },
  535. isShader: function ( shader ) {
  536. return this.shader === shader;
  537. },
  538. setShader: function ( shader ) {
  539. this.shader = shader;
  540. return this;
  541. },
  542. mergeDefines: function ( defines ) {
  543. for ( var name in defines ) {
  544. this.defines[ name ] = defines[ name ];
  545. }
  546. return this.defines;
  547. },
  548. mergeUniform: function ( uniforms ) {
  549. for ( var name in uniforms ) {
  550. this.uniforms[ name ] = uniforms[ name ];
  551. }
  552. return this.uniforms;
  553. },
  554. getTextureEncodingFromMap: function ( map ) {
  555. var encoding;
  556. if ( ! map ) {
  557. encoding = LinearEncoding;
  558. } else if ( map.isTexture ) {
  559. encoding = map.encoding;
  560. } else if ( map.isWebGLRenderTarget ) {
  561. console.warn( "THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead." );
  562. encoding = map.texture.encoding;
  563. }
  564. if ( encoding === LinearEncoding && this.context.gamma ) {
  565. encoding = GammaEncoding;
  566. }
  567. return encoding;
  568. }
  569. };
  570. export { NodeBuilder };