MaterialXLoader.js 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852
  1. import {
  2. FileLoader,
  3. Loader,
  4. TextureLoader,
  5. RepeatWrapping
  6. } from 'three';
  7. import {
  8. MeshBasicNodeMaterial, MeshPhysicalNodeMaterial,
  9. float, bool, int, vec2, vec3, vec4, color, texture,
  10. positionLocal, positionWorld, uv, vertexColor,
  11. normalLocal, normalWorld, tangentLocal, tangentWorld,
  12. add, sub, mul, div, mod, abs, sign, floor, ceil, round, pow, sin, cos, tan,
  13. asin, acos, atan2, sqrt, exp, clamp, min, max, normalize, length, dot, cross, normalMap,
  14. remap, smoothstep, luminance, mx_rgbtohsv, mx_hsvtorgb,
  15. mix,
  16. mx_ramplr, mx_ramptb, mx_splitlr, mx_splittb,
  17. mx_fractal_noise_float, mx_noise_float, mx_cell_noise_float, mx_worley_noise_float,
  18. mx_transform_uv,
  19. mx_safepower, mx_contrast,
  20. mx_srgb_texture_to_lin_rec709,
  21. saturation
  22. } from '../nodes/Nodes.js';
  23. const colorSpaceLib = {
  24. mx_srgb_texture_to_lin_rec709
  25. };
  26. class MXElement {
  27. constructor( name, nodeFunc, params = null ) {
  28. this.name = name;
  29. this.nodeFunc = nodeFunc;
  30. this.params = params;
  31. }
  32. }
  33. // Ref: https://github.com/mrdoob/three.js/issues/24674
  34. const mx_add = ( in1, in2 = float( 0 ) ) => add( in1, in2 );
  35. const mx_subtract = ( in1, in2 = float( 0 ) ) => sub( in1, in2 );
  36. const mx_multiply = ( in1, in2 = float( 1 ) ) => mul( in1, in2 );
  37. const mx_divide = ( in1, in2 = float( 1 ) ) => div( in1, in2 );
  38. const mx_modulo = ( in1, in2 = float( 1 ) ) => mod( in1, in2 );
  39. const mx_power = ( in1, in2 = float( 1 ) ) => pow( in1, in2 );
  40. const mx_atan2 = ( in1 = float( 0 ), in2 = float( 1 ) ) => atan2( in1, in2 );
  41. const MXElements = [
  42. // << Math >>
  43. new MXElement( 'add', mx_add, [ 'in1', 'in2' ] ),
  44. new MXElement( 'subtract', mx_subtract, [ 'in1', 'in2' ] ),
  45. new MXElement( 'multiply', mx_multiply, [ 'in1', 'in2' ] ),
  46. new MXElement( 'divide', mx_divide, [ 'in1', 'in2' ] ),
  47. new MXElement( 'modulo', mx_modulo, [ 'in1', 'in2' ] ),
  48. new MXElement( 'absval', abs, [ 'in1', 'in2' ] ),
  49. new MXElement( 'sign', sign, [ 'in1', 'in2' ] ),
  50. new MXElement( 'floor', floor, [ 'in1', 'in2' ] ),
  51. new MXElement( 'ceil', ceil, [ 'in1', 'in2' ] ),
  52. new MXElement( 'round', round, [ 'in1', 'in2' ] ),
  53. new MXElement( 'power', mx_power, [ 'in1', 'in2' ] ),
  54. new MXElement( 'sin', sin, [ 'in' ] ),
  55. new MXElement( 'cos', cos, [ 'in' ] ),
  56. new MXElement( 'tan', tan, [ 'in' ] ),
  57. new MXElement( 'asin', asin, [ 'in' ] ),
  58. new MXElement( 'acos', acos, [ 'in' ] ),
  59. new MXElement( 'atan2', mx_atan2, [ 'in1', 'in2' ] ),
  60. new MXElement( 'sqrt', sqrt, [ 'in' ] ),
  61. //new MtlXElement( 'ln', ... ),
  62. new MXElement( 'exp', exp, [ 'in' ] ),
  63. new MXElement( 'clamp', clamp, [ 'in', 'low', 'high' ] ),
  64. new MXElement( 'min', min, [ 'in1', 'in2' ] ),
  65. new MXElement( 'max', max, [ 'in1', 'in2' ] ),
  66. new MXElement( 'normalize', normalize, [ 'in' ] ),
  67. new MXElement( 'magnitude', length, [ 'in1', 'in2' ] ),
  68. new MXElement( 'dotproduct', dot, [ 'in1', 'in2' ] ),
  69. new MXElement( 'crossproduct', cross, [ 'in' ] ),
  70. //new MtlXElement( 'transformpoint', ... ),
  71. //new MtlXElement( 'transformvector', ... ),
  72. //new MtlXElement( 'transformnormal', ... ),
  73. //new MtlXElement( 'transformmatrix', ... ),
  74. new MXElement( 'normalmap', normalMap, [ 'in', 'scale' ] ),
  75. //new MtlXElement( 'transpose', ... ),
  76. //new MtlXElement( 'determinant', ... ),
  77. //new MtlXElement( 'invertmatrix', ... ),
  78. //new MtlXElement( 'rotate2d', rotateUV, [ 'in', radians( 'amount' )** ] ),
  79. //new MtlXElement( 'rotate3d', ... ),
  80. //new MtlXElement( 'arrayappend', ... ),
  81. //new MtlXElement( 'dot', ... ),
  82. // << Adjustment >>
  83. new MXElement( 'remap', remap, [ 'in', 'inlow', 'inhigh', 'outlow', 'outhigh' ] ),
  84. new MXElement( 'smoothstep', smoothstep, [ 'in', 'low', 'high' ] ),
  85. //new MtlXElement( 'curveadjust', ... ),
  86. //new MtlXElement( 'curvelookup', ... ),
  87. new MXElement( 'luminance', luminance, [ 'in', 'lumacoeffs' ] ),
  88. new MXElement( 'rgbtohsv', mx_rgbtohsv, [ 'in' ] ),
  89. new MXElement( 'hsvtorgb', mx_hsvtorgb, [ 'in' ] ),
  90. // << Mix >>
  91. new MXElement( 'mix', mix, [ 'bg', 'fg', 'mix' ] ),
  92. // << Channel >>
  93. new MXElement( 'combine2', vec2, [ 'in1', 'in2' ] ),
  94. new MXElement( 'combine3', vec3, [ 'in1', 'in2', 'in3' ] ),
  95. new MXElement( 'combine4', vec4, [ 'in1', 'in2', 'in3', 'in4' ] ),
  96. // << Procedural >>
  97. new MXElement( 'ramplr', mx_ramplr, [ 'valuel', 'valuer', 'texcoord' ] ),
  98. new MXElement( 'ramptb', mx_ramptb, [ 'valuet', 'valueb', 'texcoord' ] ),
  99. new MXElement( 'splitlr', mx_splitlr, [ 'valuel', 'valuer', 'texcoord' ] ),
  100. new MXElement( 'splittb', mx_splittb, [ 'valuet', 'valueb', 'texcoord' ] ),
  101. new MXElement( 'noise2d', mx_noise_float, [ 'texcoord', 'amplitude', 'pivot' ] ),
  102. new MXElement( 'noise3d', mx_noise_float, [ 'texcoord', 'amplitude', 'pivot' ] ),
  103. new MXElement( 'fractal3d', mx_fractal_noise_float, [ 'position', 'octaves', 'lacunarity', 'diminish', 'amplitude' ] ),
  104. new MXElement( 'cellnoise2d', mx_cell_noise_float, [ 'texcoord' ] ),
  105. new MXElement( 'cellnoise3d', mx_cell_noise_float, [ 'texcoord' ] ),
  106. new MXElement( 'worleynoise2d', mx_worley_noise_float, [ 'texcoord', 'jitter' ] ),
  107. new MXElement( 'worleynoise3d', mx_worley_noise_float, [ 'texcoord', 'jitter' ] ),
  108. // << Supplemental >>
  109. //new MtlXElement( 'tiledimage', ... ),
  110. //new MtlXElement( 'triplanarprojection', triplanarTextures, [ 'filex', 'filey', 'filez' ] ),
  111. //new MtlXElement( 'ramp4', ... ),
  112. //new MtlXElement( 'place2d', mx_place2d, [ 'texcoord', 'pivot', 'scale', 'rotate', 'offset' ] ),
  113. new MXElement( 'safepower', mx_safepower, [ 'in1', 'in2' ] ),
  114. new MXElement( 'contrast', mx_contrast, [ 'in', 'amount', 'pivot' ] ),
  115. //new MtlXElement( 'hsvadjust', ... ),
  116. new MXElement( 'saturate', saturation, [ 'in', 'amount' ] ),
  117. //new MtlXElement( 'extract', ... ),
  118. //new MtlXElement( 'separate2', ... ),
  119. //new MtlXElement( 'separate3', ... ),
  120. //new MtlXElement( 'separate4', ... )
  121. ];
  122. const MtlXLibrary = {};
  123. MXElements.forEach( element => MtlXLibrary[ element.name ] = element );
  124. class MaterialXLoader extends Loader {
  125. constructor( manager ) {
  126. super( manager );
  127. }
  128. load( url, onLoad, onProgress, onError ) {
  129. const _onError = function ( e ) {
  130. if ( onError ) {
  131. onError( e );
  132. } else {
  133. console.error( e );
  134. }
  135. };
  136. new FileLoader( this.manager )
  137. .setPath( this.path )
  138. .load( url, async ( text ) => {
  139. try {
  140. onLoad( this.parse( text ) );
  141. } catch ( e ) {
  142. _onError( e );
  143. }
  144. }, onProgress, _onError );
  145. return this;
  146. }
  147. parse( text ) {
  148. return new MaterialX( this.manager, this.path ).parse( text );
  149. }
  150. }
  151. class MaterialXNode {
  152. constructor( materialX, nodeXML, nodePath = '' ) {
  153. this.materialX = materialX;
  154. this.nodeXML = nodeXML;
  155. this.nodePath = nodePath ? nodePath + '/' + this.name : this.name;
  156. this.parent = null;
  157. this.node = null;
  158. this.children = [];
  159. }
  160. get element() {
  161. return this.nodeXML.nodeName;
  162. }
  163. get nodeGraph() {
  164. return this.getAttribute( 'nodegraph' );
  165. }
  166. get nodeName() {
  167. return this.getAttribute( 'nodename' );
  168. }
  169. get interfaceName() {
  170. return this.getAttribute( 'interfacename' );
  171. }
  172. get output() {
  173. return this.getAttribute( 'output' );
  174. }
  175. get name() {
  176. return this.getAttribute( 'name' );
  177. }
  178. get type() {
  179. return this.getAttribute( 'type' );
  180. }
  181. get value() {
  182. return this.getAttribute( 'value' );
  183. }
  184. getNodeGraph() {
  185. let nodeX = this;
  186. while ( nodeX !== null ) {
  187. if ( nodeX.element === 'nodegraph' ) {
  188. break;
  189. }
  190. nodeX = nodeX.parent;
  191. }
  192. return nodeX;
  193. }
  194. getRoot() {
  195. let nodeX = this;
  196. while ( nodeX.parent !== null ) {
  197. nodeX = nodeX.parent;
  198. }
  199. return nodeX;
  200. }
  201. get referencePath() {
  202. let referencePath = null;
  203. if ( this.nodeGraph !== null && this.output !== null ) {
  204. referencePath = this.nodeGraph + '/' + this.output;
  205. } else if ( this.nodeName !== null || this.interfaceName !== null ) {
  206. referencePath = this.getNodeGraph().nodePath + '/' + ( this.nodeName || this.interfaceName );
  207. }
  208. return referencePath;
  209. }
  210. get hasReference() {
  211. return this.referencePath !== null;
  212. }
  213. get isConst() {
  214. return this.element === 'input' && this.value !== null && this.type !== 'filename';
  215. }
  216. getColorSpaceNode() {
  217. const csSource = this.getAttribute( 'colorspace' );
  218. const csTarget = this.getRoot().getAttribute( 'colorspace' );
  219. const nodeName = `mx_${ csSource }_to_${ csTarget }`;
  220. return colorSpaceLib[ nodeName ];
  221. }
  222. getTexture() {
  223. const filePrefix = this.getRecursiveAttribute( 'fileprefix' ) || '';
  224. let loader = this.materialX.textureLoader;
  225. const uri = filePrefix + this.value;
  226. if ( uri ) {
  227. const handler = this.materialX.manager.getHandler( uri );
  228. if ( handler !== null ) loader = handler;
  229. }
  230. const texture = loader.load( uri );
  231. texture.wrapS = texture.wrapT = RepeatWrapping;
  232. texture.flipY = false;
  233. return texture;
  234. }
  235. getClassFromType( type ) {
  236. let nodeClass = null;
  237. if ( type === 'integer' ) nodeClass = int;
  238. else if ( type === 'float' ) nodeClass = float;
  239. else if ( type === 'vector2' ) nodeClass = vec2;
  240. else if ( type === 'vector3' ) nodeClass = vec3;
  241. else if ( type === 'vector4' || type === 'color4' ) nodeClass = vec4;
  242. else if ( type === 'color3' ) nodeClass = color;
  243. else if ( type === 'boolean' ) nodeClass = bool;
  244. return nodeClass;
  245. }
  246. getNode() {
  247. let node = this.node;
  248. if ( node !== null ) {
  249. return node;
  250. }
  251. //
  252. const type = this.type;
  253. if ( this.isConst ) {
  254. const nodeClass = this.getClassFromType( type );
  255. node = nodeClass( ...this.getVector() );
  256. } else if ( this.hasReference ) {
  257. node = this.materialX.getMaterialXNode( this.referencePath ).getNode();
  258. } else {
  259. const element = this.element;
  260. if ( element === 'convert' ) {
  261. const nodeClass = this.getClassFromType( type );
  262. node = nodeClass( this.getNodeByName( 'in' ) );
  263. } else if ( element === 'constant' ) {
  264. node = this.getNodeByName( 'value' );
  265. } else if ( element === 'position' ) {
  266. const space = this.getAttribute( 'space' );
  267. node = space === 'world' ? positionWorld : positionLocal;
  268. } else if ( element === 'normal' ) {
  269. const space = this.getAttribute( 'space' );
  270. node = space === 'world' ? normalWorld : normalLocal;
  271. } else if ( element === 'tangent' ) {
  272. const space = this.getAttribute( 'space' );
  273. node = space === 'world' ? tangentWorld : tangentLocal;
  274. } else if ( element === 'texcoord' ) {
  275. const indexNode = this.getChildByName( 'index' );
  276. const index = indexNode ? parseInt( indexNode.value ) : 0;
  277. node = uv( index );
  278. } else if ( element === 'geomcolor' ) {
  279. const indexNode = this.getChildByName( 'index' );
  280. const index = indexNode ? parseInt( indexNode.value ) : 0;
  281. node = vertexColor( index );
  282. } else if ( element === 'tiledimage' ) {
  283. const file = this.getChildByName( 'file' );
  284. const textureFile = file.getTexture();
  285. const uvTiling = mx_transform_uv( ...this.getNodesByNames( [ 'uvtiling', 'uvoffset' ] ) );
  286. node = texture( textureFile, uvTiling );
  287. const colorSpaceNode = file.getColorSpaceNode();
  288. if ( colorSpaceNode ) {
  289. node = colorSpaceNode( node );
  290. }
  291. } else if ( element === 'image' ) {
  292. const file = this.getChildByName( 'file' );
  293. const uvNode = this.getNodeByName( 'texcoord' );
  294. const textureFile = file.getTexture();
  295. node = texture( textureFile, uvNode );
  296. const colorSpaceNode = file.getColorSpaceNode();
  297. if ( colorSpaceNode ) {
  298. node = colorSpaceNode( node );
  299. }
  300. } else if ( MtlXLibrary[ element ] !== undefined ) {
  301. const nodeElement = MtlXLibrary[ element ];
  302. node = nodeElement.nodeFunc( ...this.getNodesByNames( ...nodeElement.params ) );
  303. }
  304. }
  305. //
  306. if ( node === null ) {
  307. console.warn( `THREE.MaterialXLoader: Unexpected node ${ new XMLSerializer().serializeToString( this.nodeXML ) }.` );
  308. node = float( 0 );
  309. }
  310. //
  311. const nodeToTypeClass = this.getClassFromType( type );
  312. if ( nodeToTypeClass !== null ) {
  313. node = nodeToTypeClass( node );
  314. }
  315. node.name = this.name;
  316. this.node = node;
  317. return node;
  318. }
  319. getChildByName( name ) {
  320. for ( const input of this.children ) {
  321. if ( input.name === name ) {
  322. return input;
  323. }
  324. }
  325. }
  326. getNodes() {
  327. const nodes = {};
  328. for ( const input of this.children ) {
  329. const node = input.getNode();
  330. nodes[ node.name ] = node;
  331. }
  332. return nodes;
  333. }
  334. getNodeByName( name ) {
  335. const child = this.getChildByName( name );
  336. return child ? child.getNode() : undefined;
  337. }
  338. getNodesByNames( ...names ) {
  339. const nodes = [];
  340. for ( const name of names ) {
  341. const node = this.getNodeByName( name );
  342. if ( node ) nodes.push( node );
  343. }
  344. return nodes;
  345. }
  346. getValue() {
  347. return this.value.trim();
  348. }
  349. getVector() {
  350. const vector = [];
  351. for ( const val of this.getValue().split( /[,|\s]/ ) ) {
  352. if ( val !== '' ) {
  353. vector.push( Number( val.trim() ) );
  354. }
  355. }
  356. return vector;
  357. }
  358. getAttribute( name ) {
  359. return this.nodeXML.getAttribute( name );
  360. }
  361. getRecursiveAttribute( name ) {
  362. let attribute = this.nodeXML.getAttribute( name );
  363. if ( attribute === null && this.parent !== null ) {
  364. attribute = this.parent.getRecursiveAttribute( name );
  365. }
  366. return attribute;
  367. }
  368. setStandardSurfaceToGltfPBR( material ) {
  369. const inputs = this.getNodes();
  370. //
  371. let colorNode = null;
  372. if ( inputs.base && inputs.base_color ) colorNode = mul( inputs.base, inputs.base_color );
  373. else if ( inputs.base ) colorNode = inputs.base;
  374. else if ( inputs.base_color ) colorNode = inputs.base_color;
  375. //
  376. let roughnessNode = null;
  377. if ( inputs.specular_roughness ) roughnessNode = inputs.specular_roughness;
  378. //
  379. let metalnessNode = null;
  380. if ( inputs.metalness ) metalnessNode = inputs.metalness;
  381. //
  382. let clearcoatNode = null;
  383. let clearcoatRoughnessNode = null;
  384. if ( inputs.coat ) clearcoatNode = inputs.coat;
  385. if ( inputs.coat_roughness ) clearcoatRoughnessNode = inputs.coat_roughness;
  386. if ( inputs.coat_color ) {
  387. colorNode = colorNode ? mul( colorNode, inputs.coat_color ) : colorNode;
  388. }
  389. //
  390. let normalNode = null;
  391. if ( inputs.normal ) normalNode = inputs.normal;
  392. //
  393. let emissiveNode = null;
  394. if ( inputs.emission ) emissiveNode = inputs.emission;
  395. if ( inputs.emissionColor ) {
  396. emissiveNode = emissiveNode ? mul( emissiveNode, inputs.emissionColor ) : emissiveNode;
  397. }
  398. //
  399. material.colorNode = colorNode || color( 0.8, 0.8, 0.8 );
  400. material.roughnessNode = roughnessNode || float( 0.2 );
  401. material.metalnessNode = metalnessNode || float( 0 );
  402. material.clearcoatNode = clearcoatNode || float( 0 );
  403. material.clearcoatRoughnessNode = clearcoatRoughnessNode || float( 0 );
  404. if ( normalNode ) material.normalNode = normalNode;
  405. if ( emissiveNode ) material.emissiveNode = emissiveNode;
  406. }
  407. /*setGltfPBR( material ) {
  408. const inputs = this.getNodes();
  409. console.log( inputs );
  410. }*/
  411. setMaterial( material ) {
  412. const element = this.element;
  413. if ( element === 'gltf_pbr' ) {
  414. //this.setGltfPBR( material );
  415. } else if ( element === 'standard_surface' ) {
  416. this.setStandardSurfaceToGltfPBR( material );
  417. }
  418. }
  419. toBasicMaterial() {
  420. const material = new MeshBasicNodeMaterial();
  421. material.name = this.name;
  422. for ( const nodeX of this.children.toReversed() ) {
  423. if ( nodeX.name === 'out' ) {
  424. material.colorNode = nodeX.getNode();
  425. break;
  426. }
  427. }
  428. return material;
  429. }
  430. toPhysicalMaterial() {
  431. const material = new MeshPhysicalNodeMaterial();
  432. material.name = this.name;
  433. for ( const nodeX of this.children ) {
  434. const shaderProperties = this.materialX.getMaterialXNode( nodeX.nodeName );
  435. shaderProperties.setMaterial( material );
  436. }
  437. return material;
  438. }
  439. toMaterials() {
  440. const materials = {};
  441. let isUnlit = true;
  442. for ( const nodeX of this.children ) {
  443. if ( nodeX.element === 'surfacematerial' ) {
  444. const material = nodeX.toPhysicalMaterial();
  445. materials[ material.name ] = material;
  446. isUnlit = false;
  447. }
  448. }
  449. if ( isUnlit ) {
  450. for ( const nodeX of this.children ) {
  451. if ( nodeX.element === 'nodegraph' ) {
  452. const material = nodeX.toBasicMaterial();
  453. materials[ material.name ] = material;
  454. }
  455. }
  456. }
  457. return materials;
  458. }
  459. add( materialXNode ) {
  460. materialXNode.parent = this;
  461. this.children.push( materialXNode );
  462. }
  463. }
  464. class MaterialX {
  465. constructor( manager, path ) {
  466. this.manager = manager;
  467. this.path = path;
  468. this.resourcePath = '';
  469. this.nodesXLib = new Map();
  470. //this.nodesXRefLib = new WeakMap();
  471. this.textureLoader = new TextureLoader( manager );
  472. }
  473. addMaterialXNode( materialXNode ) {
  474. this.nodesXLib.set( materialXNode.nodePath, materialXNode );
  475. }
  476. /*getMaterialXNodeFromXML( xmlNode ) {
  477. return this.nodesXRefLib.get( xmlNode );
  478. }*/
  479. getMaterialXNode( ...names ) {
  480. return this.nodesXLib.get( names.join( '/' ) );
  481. }
  482. parseNode( nodeXML, nodePath = '' ) {
  483. const materialXNode = new MaterialXNode( this, nodeXML, nodePath );
  484. if ( materialXNode.nodePath ) this.addMaterialXNode( materialXNode );
  485. for ( const childNodeXML of nodeXML.children ) {
  486. const childMXNode = this.parseNode( childNodeXML, materialXNode.nodePath );
  487. materialXNode.add( childMXNode );
  488. }
  489. return materialXNode;
  490. }
  491. parse( text ) {
  492. const rootXML = new DOMParser().parseFromString( text, 'application/xml' ).documentElement;
  493. this.textureLoader.setPath( this.path );
  494. //
  495. const materials = this.parseNode( rootXML ).toMaterials();
  496. return { materials };
  497. }
  498. }
  499. export { MaterialXLoader };