@gnsx/three 0.185.16 → 0.186.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (417) hide show
  1. package/build/three.cjs +10 -82600
  2. package/build/three.core.js +1303 -728
  3. package/build/three.module.js +439 -338
  4. package/build/three.tsl.js +74 -44
  5. package/build/three.webgpu.js +6036 -2184
  6. package/build/three.webgpu.nodes.js +6020 -2184
  7. package/examples/jsm/Addons.js +6 -6
  8. package/examples/jsm/controls/ArcballControls.js +1 -1
  9. package/examples/jsm/controls/FirstPersonControls.js +44 -20
  10. package/examples/jsm/controls/OrbitControls.js +9 -0
  11. package/examples/jsm/controls/TrackballControls.js +109 -4
  12. package/examples/jsm/csm/CSMShadowNode.js +13 -0
  13. package/examples/jsm/exporters/GLTFExporter.js +23 -7
  14. package/examples/jsm/exporters/USDZExporter.js +2 -2
  15. package/examples/jsm/generators/CityGenerator.js +377 -45
  16. package/examples/jsm/generators/ForestGenerator.js +12 -12
  17. package/examples/jsm/generators/TerrainGenerator.js +49 -37
  18. package/examples/jsm/generators/TreeGenerator.js +70 -76
  19. package/examples/jsm/generators/city/BenchGenerator.js +127 -0
  20. package/examples/jsm/generators/city/CarGenerator.js +479 -0
  21. package/examples/jsm/generators/city/CityGeneratorUtils.js +31 -0
  22. package/examples/jsm/generators/city/HydrantGenerator.js +106 -0
  23. package/examples/jsm/generators/city/InstancedMeshGenerator.js +86 -0
  24. package/examples/jsm/generators/city/PersonGenerator.js +447 -0
  25. package/examples/jsm/generators/city/SidewalkGenerator.js +33 -38
  26. package/examples/jsm/generators/city/SkyscraperGenerator.js +448 -48
  27. package/examples/jsm/generators/city/StreetTreeGenerator.js +231 -0
  28. package/examples/jsm/generators/city/StreetlightGenerator.js +100 -0
  29. package/examples/jsm/generators/city/TrafficlightGenerator.js +106 -0
  30. package/examples/jsm/generators/city/TrashcanGenerator.js +100 -0
  31. package/examples/jsm/geometries/BoxLineGeometry.js +1 -1
  32. package/examples/jsm/geometries/ParametricGeometry.js +1 -1
  33. package/examples/jsm/geometries/RoundedBoxGeometry.js +1 -1
  34. package/examples/jsm/gpgpu/CountingSort.js +271 -0
  35. package/examples/jsm/helpers/LightProbeGridHelper.js +60 -239
  36. package/examples/jsm/helpers/LightProbeGridHelperWebGL.js +221 -0
  37. package/examples/jsm/inspector/Extension.js +94 -0
  38. package/examples/jsm/inspector/Inspector.js +145 -41
  39. package/examples/jsm/inspector/RendererInspector.js +100 -52
  40. package/examples/jsm/inspector/extensions/color-grading/ColorGrading.js +2609 -0
  41. package/examples/jsm/inspector/extensions/color-grading/ColorWheel.js +352 -0
  42. package/examples/jsm/inspector/extensions/color-grading/CurveEditor.js +599 -0
  43. package/examples/jsm/inspector/extensions/color-grading/LUT3DStyle.js +1201 -0
  44. package/examples/jsm/inspector/extensions/color-grading/LUTMath.js +788 -0
  45. package/examples/jsm/inspector/extensions/color-grading/modules/BrightnessModule.js +72 -0
  46. package/examples/jsm/inspector/extensions/color-grading/modules/ColorWheelModule.js +112 -0
  47. package/examples/jsm/inspector/extensions/color-grading/modules/ContrastModule.js +82 -0
  48. package/examples/jsm/inspector/extensions/color-grading/modules/CurvesModule.js +109 -0
  49. package/examples/jsm/inspector/extensions/color-grading/modules/ExposureHueModule.js +110 -0
  50. package/examples/jsm/inspector/extensions/color-grading/modules/ExposureModule.js +73 -0
  51. package/examples/jsm/inspector/extensions/color-grading/modules/HueModule.js +78 -0
  52. package/examples/jsm/inspector/extensions/color-grading/modules/ImportedCubeModule.js +89 -0
  53. package/examples/jsm/inspector/extensions/color-grading/modules/Module.js +285 -0
  54. package/examples/jsm/inspector/extensions/color-grading/modules/OutputModule.js +101 -0
  55. package/examples/jsm/inspector/extensions/color-grading/modules/RendererModule.js +225 -0
  56. package/examples/jsm/inspector/extensions/color-grading/modules/SatVibranceModule.js +102 -0
  57. package/examples/jsm/inspector/extensions/color-grading/modules/SaturationModule.js +76 -0
  58. package/examples/jsm/inspector/extensions/color-grading/modules/VibranceModule.js +76 -0
  59. package/examples/jsm/inspector/extensions/color-grading/modules/WhiteBalanceModule.js +86 -0
  60. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +26 -31
  61. package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -0
  62. package/examples/jsm/inspector/tabs/Memory.js +0 -2
  63. package/examples/jsm/inspector/tabs/Settings.js +4 -0
  64. package/examples/jsm/inspector/tabs/Timeline.js +223 -171
  65. package/examples/jsm/inspector/tabs/Viewer.js +515 -21
  66. package/examples/jsm/inspector/ui/List.js +15 -9
  67. package/examples/jsm/inspector/ui/Profiler.js +170 -14
  68. package/examples/jsm/inspector/ui/Style.js +269 -23
  69. package/examples/jsm/inspector/ui/Tab.js +2 -0
  70. package/examples/jsm/inspector/ui/Values.js +14 -2
  71. package/examples/jsm/interactive/HTMLMesh.js +19 -3
  72. package/examples/jsm/lighting/LightProbeGrid.js +484 -889
  73. package/examples/jsm/lighting/LightProbeGridUtils.js +107 -0
  74. package/examples/jsm/lighting/LightProbeGridWebGL.js +841 -0
  75. package/examples/jsm/lighting/vxgi/VXGIConeTracer.js +194 -0
  76. package/examples/jsm/lighting/vxgi/VXGINode.js +660 -0
  77. package/examples/jsm/lighting/vxgi/VXGISceneCollector.js +478 -0
  78. package/examples/jsm/lighting/vxgi/VXGIVolume.js +1430 -0
  79. package/examples/jsm/lights/SunLight.js +95 -0
  80. package/examples/jsm/lights/SunLightNode.js +56 -0
  81. package/examples/jsm/lights/SunLightShadow.js +319 -0
  82. package/examples/jsm/lights/SunShadowNode.js +312 -0
  83. package/examples/jsm/loaders/3DMLoader.js +150 -49
  84. package/examples/jsm/loaders/3MFLoader.js +202 -1
  85. package/examples/jsm/loaders/FBXLoader.js +81 -5
  86. package/examples/jsm/loaders/GLTFGaussianSplatLoaderExtension.js +330 -0
  87. package/examples/jsm/loaders/GLTFLoader.js +79 -14
  88. package/examples/jsm/loaders/GaussianSplatPLYLoader.js +386 -0
  89. package/examples/jsm/loaders/KSPLATLoader.js +463 -0
  90. package/examples/jsm/loaders/MaterialXLoader.js +111 -1010
  91. package/examples/jsm/loaders/PCDLoader.js +1 -1
  92. package/examples/jsm/loaders/SPLATLoader.js +139 -0
  93. package/examples/jsm/loaders/SPZLoader.js +561 -0
  94. package/examples/jsm/loaders/materialx/MaterialXArchive.js +108 -0
  95. package/examples/jsm/loaders/materialx/MaterialXDocument.js +878 -0
  96. package/examples/jsm/loaders/materialx/MaterialXHextile.js +183 -0
  97. package/examples/jsm/loaders/materialx/MaterialXInterfaceValidation.js +376 -0
  98. package/examples/jsm/loaders/materialx/MaterialXLog.js +75 -0
  99. package/examples/jsm/loaders/materialx/MaterialXNodeInterfaceRegistry.js +4 -0
  100. package/examples/jsm/loaders/materialx/MaterialXNodeLibrary.js +1021 -0
  101. package/examples/jsm/loaders/materialx/MaterialXSurfaceMappings.js +661 -0
  102. package/examples/jsm/loaders/materialx/MaterialXUtils.js +57 -0
  103. package/examples/jsm/loaders/materialx/compile/MaterialXCompileRegistry.js +997 -0
  104. package/examples/jsm/loaders/materialx/parse/MaterialXParser.js +28 -0
  105. package/examples/jsm/loaders/usd/USDAParser.js +15 -2
  106. package/examples/jsm/loaders/usd/USDCParser.js +1 -4
  107. package/examples/jsm/loaders/usd/USDComposer.js +80 -42
  108. package/examples/jsm/materials/WoodNodeMaterial.js +6 -108
  109. package/examples/jsm/misc/RollerCoaster.js +2 -2
  110. package/examples/jsm/misc/SculptGL.LICENSE.txt +21 -0
  111. package/examples/jsm/misc/Sculptor.js +1679 -0
  112. package/examples/jsm/misc/SculptorMesh.js +1504 -0
  113. package/examples/jsm/misc/SculptorTools.js +1180 -0
  114. package/examples/jsm/misc/SculptorUtils.js +345 -0
  115. package/examples/jsm/misc/TubePainter.js +28 -16
  116. package/examples/jsm/misc/VolumeSlice.js +24 -24
  117. package/examples/jsm/modifiers/SimplifyModifier.js +63 -556
  118. package/examples/jsm/objects/GaussianSplat.js +1039 -0
  119. package/examples/jsm/objects/Sky.js +66 -45
  120. package/examples/jsm/objects/SkyMesh.js +70 -51
  121. package/examples/jsm/physics/JoltPhysics.js +1 -1
  122. package/examples/jsm/postprocessing/AfterimagePass.js +4 -2
  123. package/examples/jsm/postprocessing/BloomPass.js +2 -2
  124. package/examples/jsm/postprocessing/GTAOPass.js +1 -1
  125. package/examples/jsm/postprocessing/OutlinePass.js +5 -5
  126. package/examples/jsm/postprocessing/SAOPass.js +1 -1
  127. package/examples/jsm/postprocessing/SSAOPass.js +1 -1
  128. package/examples/jsm/postprocessing/SSRPass.js +4 -2
  129. package/examples/jsm/postprocessing/SavePass.js +1 -1
  130. package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
  131. package/examples/jsm/postprocessing/UnrealBloomPass.js +30 -13
  132. package/examples/jsm/renderers/CSS2DRenderer.js +29 -5
  133. package/examples/jsm/shaders/DepthLimitedBlurShader.js +4 -1
  134. package/examples/jsm/shaders/ExposureShader.js +1 -1
  135. package/examples/jsm/shaders/FilmShader.js +2 -1
  136. package/examples/jsm/transpiler/AST.js +21 -2
  137. package/examples/jsm/transpiler/GLSLDecoder.js +498 -8
  138. package/examples/jsm/transpiler/TSLEncoder.js +82 -10
  139. package/examples/jsm/transpiler/WGSLEncoder.js +33 -4
  140. package/examples/jsm/tsl/WebGLNodesHandler.js +29 -39
  141. package/examples/jsm/tsl/display/AfterImageNode.js +2 -0
  142. package/examples/jsm/tsl/display/AnaglyphPassNode.js +3 -2
  143. package/examples/jsm/tsl/display/BilateralBlurNode.js +5 -2
  144. package/examples/jsm/tsl/display/BloomNode.js +55 -30
  145. package/examples/jsm/tsl/display/DenoiseNode.js +21 -1
  146. package/examples/jsm/tsl/display/DepthOfFieldNode.js +24 -6
  147. package/examples/jsm/tsl/display/DotScreenNode.js +11 -11
  148. package/examples/jsm/tsl/display/FSR1Node.js +8 -4
  149. package/examples/jsm/tsl/display/GTAONode.js +199 -86
  150. package/examples/jsm/tsl/display/GaussianBlurNode.js +65 -52
  151. package/examples/jsm/tsl/display/GodraysNode.js +5 -2
  152. package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +2 -2
  153. package/examples/jsm/tsl/display/LensflareNode.js +5 -2
  154. package/examples/jsm/tsl/display/OITPassNode.js +352 -0
  155. package/examples/jsm/tsl/display/OutlineNode.js +2 -0
  156. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +3 -2
  157. package/examples/jsm/tsl/display/RGBShiftNode.js +9 -9
  158. package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +7 -4
  159. package/examples/jsm/tsl/display/RetroPassNode.js +1 -1
  160. package/examples/jsm/tsl/display/SMAANode.js +22 -61
  161. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -4
  162. package/examples/jsm/tsl/display/SSAONode.js +436 -0
  163. package/examples/jsm/tsl/display/SSGINode.js +5 -2
  164. package/examples/jsm/tsl/display/SSRNode.js +7 -2
  165. package/examples/jsm/tsl/display/SSSNode.js +5 -2
  166. package/examples/jsm/tsl/display/SharpenNode.js +5 -4
  167. package/examples/jsm/tsl/display/StereoCompositePassNode.js +1 -3
  168. package/examples/jsm/tsl/display/StereoPassNode.js +1 -3
  169. package/examples/jsm/tsl/display/TAAUNode.js +22 -125
  170. package/examples/jsm/tsl/display/TRAANode.js +16 -142
  171. package/examples/jsm/tsl/display/TemporalReprojectNode.js +21 -15
  172. package/examples/jsm/tsl/display/depthAwareBlur.js +63 -0
  173. package/examples/jsm/tsl/display/hashBlur.js +3 -2
  174. package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +38 -27
  175. package/examples/jsm/tsl/lighting/LightProbeGridNode.js +136 -0
  176. package/examples/jsm/tsl/math/voronoiNoise.js +112 -0
  177. package/examples/jsm/tsl/shadows/TileShadowNode.js +4 -6
  178. package/examples/jsm/tsl/utils/Raymarching.js +5 -5
  179. package/examples/jsm/tsl/utils/SoftParticles.js +60 -0
  180. package/examples/jsm/tsl/utils/TAAUtils.js +195 -0
  181. package/examples/jsm/utils/BufferGeometryUtils.js +14 -14
  182. package/examples/jsm/utils/GaussianSplatUtils.js +229 -0
  183. package/examples/jsm/utils/WebGLTextureUtils.js +1 -1
  184. package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
  185. package/examples/jsm/webxr/WebGLXRFallback.js +2 -16
  186. package/examples/jsm/webxr/XRControllerModelFactory.js +16 -4
  187. package/package.json +9 -16
  188. package/src/Three.Core.js +2 -1
  189. package/src/Three.TSL.js +73 -43
  190. package/src/Three.WebGPU.Nodes.js +1 -0
  191. package/src/Three.WebGPU.js +1 -0
  192. package/src/animation/AnimationClip.js +15 -2
  193. package/src/animation/AnimationObjectGroup.js +18 -6
  194. package/src/animation/AnimationUtils.js +26 -0
  195. package/src/animation/KeyframeTrack.js +37 -0
  196. package/src/constants.js +23 -1
  197. package/src/core/BufferAttribute.js +3 -2
  198. package/src/core/BufferGeometry.js +1 -1
  199. package/src/core/InterleavedBuffer.js +5 -1
  200. package/src/core/Object3D.js +40 -12
  201. package/src/core/Raycaster.js +4 -0
  202. package/src/core/RenderTarget.js +99 -9
  203. package/src/core/RenderTarget3D.js +12 -8
  204. package/src/extras/Controls.js +0 -8
  205. package/src/extras/PMREMGenerator.js +99 -205
  206. package/src/geometries/TorusGeometry.js +1 -1
  207. package/src/helpers/ArrowHelper.js +2 -0
  208. package/src/helpers/AxesHelper.js +2 -0
  209. package/src/helpers/Box3Helper.js +2 -0
  210. package/src/helpers/BoxHelper.js +2 -0
  211. package/src/helpers/CameraHelper.js +2 -0
  212. package/src/helpers/DirectionalLightHelper.js +2 -0
  213. package/src/helpers/GridHelper.js +2 -0
  214. package/src/helpers/HemisphereLightHelper.js +2 -0
  215. package/src/helpers/PlaneHelper.js +2 -0
  216. package/src/helpers/PointLightHelper.js +2 -0
  217. package/src/helpers/PolarGridHelper.js +2 -0
  218. package/src/helpers/SkeletonHelper.js +2 -0
  219. package/src/helpers/SpotLightHelper.js +2 -0
  220. package/src/lights/Light.js +0 -10
  221. package/src/lights/LightShadow.js +43 -12
  222. package/src/lights/SpotLightShadow.js +18 -0
  223. package/src/loaders/BufferGeometryLoader.js +5 -0
  224. package/src/loaders/ImageBitmapLoader.js +3 -1
  225. package/src/loaders/ObjectLoader.js +8 -5
  226. package/src/materials/Material.js +80 -57
  227. package/src/materials/MeshPhysicalMaterial.js +32 -0
  228. package/src/materials/nodes/Line2NodeMaterial.js +17 -8
  229. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +42 -5
  230. package/src/materials/nodes/NodeMaterial.js +19 -13
  231. package/src/materials/nodes/PointsNodeMaterial.js +2 -1
  232. package/src/materials/nodes/manager/NodeMaterialObserver.js +282 -55
  233. package/src/math/Frustum.js +9 -0
  234. package/src/math/FrustumArray.js +1 -1
  235. package/src/math/MathUtils.js +5 -3
  236. package/src/math/Matrix4.js +2 -9
  237. package/src/math/Plane.js +30 -1
  238. package/src/math/Quaternion.js +0 -10
  239. package/src/math/Ray.js +95 -45
  240. package/src/math/Triangle.js +0 -2
  241. package/src/math/Vector3.js +2 -2
  242. package/src/math/Vector4.js +0 -4
  243. package/src/math/interpolants/BezierInterpolant.js +36 -23
  244. package/src/nodes/Nodes.js +2 -0
  245. package/src/nodes/TSL.js +11 -3
  246. package/src/nodes/accessors/Batch.js +85 -13
  247. package/src/nodes/accessors/BufferAttributeNode.js +1 -1
  248. package/src/nodes/accessors/BuiltinNode.js +1 -1
  249. package/src/nodes/accessors/Instance.js +19 -18
  250. package/src/nodes/accessors/MaterialNode.js +9 -0
  251. package/src/nodes/accessors/ModelNode.js +85 -9
  252. package/src/nodes/accessors/ReferenceBaseNode.js +1 -70
  253. package/src/nodes/accessors/ReferenceElementNode.js +72 -0
  254. package/src/nodes/accessors/ReferenceNode.js +1 -70
  255. package/src/nodes/accessors/Skinning.js +124 -12
  256. package/src/nodes/accessors/StorageTextureNode.js +7 -3
  257. package/src/nodes/accessors/Texture3DNode.js +1 -1
  258. package/src/nodes/accessors/TextureNode.js +51 -21
  259. package/src/nodes/accessors/TextureSizeNode.js +4 -2
  260. package/src/nodes/accessors/UniformArrayNode.js +30 -5
  261. package/src/nodes/code/CodeNode.js +1 -1
  262. package/src/nodes/code/FunctionNode.js +12 -2
  263. package/src/nodes/core/ArrayNode.js +2 -2
  264. package/src/nodes/core/ContextNode.js +57 -4
  265. package/src/nodes/core/IndexNode.js +69 -4
  266. package/src/nodes/core/InspectorNode.js +2 -2
  267. package/src/nodes/core/MRTNode.js +44 -2
  268. package/src/nodes/core/Node.js +6 -3
  269. package/src/nodes/core/NodeBuilder.js +65 -50
  270. package/src/nodes/core/NodeFrame.js +11 -3
  271. package/src/nodes/core/NodeUtils.js +88 -0
  272. package/src/nodes/core/PropertyNode.js +8 -0
  273. package/src/nodes/core/StackNode.js +0 -1
  274. package/src/nodes/core/StructNode.js +4 -3
  275. package/src/nodes/core/UniformGroupNode.js +3 -2
  276. package/src/nodes/core/UniformNode.js +26 -12
  277. package/src/nodes/core/VarNode.js +0 -1
  278. package/src/nodes/display/BumpMapNode.js +2 -2
  279. package/src/nodes/display/ColorAdjustment.js +1 -1
  280. package/src/nodes/display/PassNode.js +76 -15
  281. package/src/nodes/display/ScreenNode.js +22 -65
  282. package/src/nodes/fog/Fog.js +4 -4
  283. package/src/nodes/functions/BSDF/BRDF_GGX.js +6 -6
  284. package/src/nodes/functions/BSDF/BRDF_Sheen.js +1 -1
  285. package/src/nodes/functions/BSDF/DFGLUT.js +2 -1
  286. package/src/nodes/functions/BSDF/LTC.js +1 -1
  287. package/src/nodes/functions/PhongLightingModel.js +1 -1
  288. package/src/nodes/functions/PhysicalLightingModel.js +83 -25
  289. package/src/nodes/functions/ToonLightingModel.js +2 -2
  290. package/src/nodes/functions/material/getParallaxCorrectNormal.js +3 -3
  291. package/src/nodes/gpgpu/AtomicFunctionNode.js +64 -13
  292. package/src/nodes/gpgpu/BarrierNode.js +13 -4
  293. package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
  294. package/src/nodes/gpgpu/ComputeNode.js +20 -17
  295. package/src/nodes/gpgpu/SubgroupFunctionNode.js +165 -37
  296. package/src/nodes/gpgpu/WorkgroupInfoNode.js +44 -6
  297. package/src/nodes/lighting/EnvironmentNode.js +40 -4
  298. package/src/nodes/lighting/LightsNode.js +20 -4
  299. package/src/nodes/lighting/ShadowBaseNode.js +158 -1
  300. package/src/nodes/lighting/ShadowFilterNode.js +2 -106
  301. package/src/nodes/lighting/ShadowNode.js +22 -91
  302. package/src/nodes/materialx/{lib/mx_hsv.js → MaterialXColor.js} +3 -6
  303. package/src/nodes/materialx/{lib/mx_transform_color.js → MaterialXColorTransform.js} +3 -6
  304. package/src/nodes/materialx/MaterialXCore.js +37 -0
  305. package/src/nodes/materialx/MaterialXNodes.js +64 -72
  306. package/src/nodes/materialx/{lib/mx_noise.js → MaterialXNoise.js} +426 -197
  307. package/src/nodes/math/BitcountNode.js +24 -4
  308. package/src/nodes/math/MathNode.js +4 -4
  309. package/src/nodes/math/MathUtils.js +15 -4
  310. package/src/nodes/math/OperatorNode.js +2 -2
  311. package/src/nodes/math/PackFloatNode.js +29 -1
  312. package/src/nodes/math/Packed4x8IntegerNode.js +433 -0
  313. package/src/nodes/math/UnpackFloatNode.js +30 -2
  314. package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
  315. package/src/nodes/pmrem/PMREMNode.js +1 -1
  316. package/src/nodes/pmrem/PMREMUtils.js +31 -74
  317. package/src/nodes/shapes/Shapes.js +1 -1
  318. package/src/nodes/tsl/TSLCore.js +1 -31
  319. package/src/nodes/utils/EventNode.js +75 -0
  320. package/src/nodes/utils/LoopNode.js +54 -13
  321. package/src/nodes/utils/PostProcessingUtils.js +23 -2
  322. package/src/nodes/utils/RTTNode.js +97 -32
  323. package/src/nodes/utils/ReflectorNode.js +8 -4
  324. package/src/nodes/utils/RotateNode.js +85 -8
  325. package/src/nodes/utils/SpriteUtils.js +58 -23
  326. package/src/objects/BatchedMesh.js +6 -0
  327. package/src/objects/InstancedMesh.js +1 -1
  328. package/src/objects/LOD.js +1 -1
  329. package/src/objects/Line.js +12 -0
  330. package/src/objects/Mesh.js +12 -0
  331. package/src/objects/Points.js +12 -0
  332. package/src/objects/Sprite.js +12 -0
  333. package/src/renderers/WebGLRenderer.js +93 -27
  334. package/src/renderers/common/Animation.js +12 -2
  335. package/src/renderers/common/Backend.js +38 -10
  336. package/src/renderers/common/BindGroup.js +0 -1
  337. package/src/renderers/common/Bindings.js +50 -4
  338. package/src/renderers/common/BundleGroup.js +4 -0
  339. package/src/renderers/common/ClippingContext.js +11 -1
  340. package/src/renderers/common/Color4.js +9 -0
  341. package/src/renderers/common/Constants.js +0 -5
  342. package/src/renderers/common/DirectRenderPipeline.js +233 -0
  343. package/src/renderers/common/Geometries.js +24 -3
  344. package/src/renderers/common/Info.js +3 -3
  345. package/src/renderers/common/InspectorBase.js +37 -8
  346. package/src/renderers/common/Lighting.js +11 -4
  347. package/src/renderers/common/Pipelines.js +6 -4
  348. package/src/renderers/common/QuadMesh.js +16 -2
  349. package/src/renderers/common/RenderContext.js +8 -0
  350. package/src/renderers/common/RenderList.js +53 -19
  351. package/src/renderers/common/RenderLists.js +58 -11
  352. package/src/renderers/common/RenderObject.js +14 -0
  353. package/src/renderers/common/RenderObjects.js +14 -9
  354. package/src/renderers/common/RenderPipeline.js +52 -44
  355. package/src/renderers/common/Renderer.js +226 -55
  356. package/src/renderers/common/Storage3DTexture.js +16 -0
  357. package/src/renderers/common/Textures.js +3 -3
  358. package/src/renderers/common/XRManager.js +79 -72
  359. package/src/renderers/common/extras/PMREMGenerator.js +76 -144
  360. package/src/renderers/common/nodes/NodeManager.js +144 -6
  361. package/src/renderers/common/nodes/NodeStorageBuffer.js +3 -1
  362. package/src/renderers/common/nodes/NodeUniformBuffer.js +3 -1
  363. package/src/renderers/shaders/DFGLUTData.js +2 -1
  364. package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +4 -2
  365. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +48 -0
  366. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +53 -4
  367. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +20 -2
  368. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +20 -0
  369. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
  370. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +61 -57
  371. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +82 -0
  372. package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +9 -0
  373. package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +8 -1
  374. package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +15 -0
  375. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
  376. package/src/renderers/shaders/ShaderLib.js +1 -0
  377. package/src/renderers/shaders/UniformsLib.js +16 -0
  378. package/src/renderers/webgl/WebGLAnimation.js +2 -2
  379. package/src/renderers/webgl/WebGLCapabilities.js +2 -2
  380. package/src/renderers/webgl/WebGLLights.js +74 -4
  381. package/src/renderers/webgl/WebGLMaterials.js +6 -0
  382. package/src/renderers/webgl/WebGLOutput.js +36 -24
  383. package/src/renderers/webgl/WebGLProgram.js +3 -0
  384. package/src/renderers/webgl/WebGLPrograms.js +8 -0
  385. package/src/renderers/webgl/WebGLRenderLists.js +6 -10
  386. package/src/renderers/webgl/WebGLShadowMap.js +47 -44
  387. package/src/renderers/webgl/WebGLTextures.js +7 -7
  388. package/src/renderers/webgl-fallback/WebGLBackend.js +153 -45
  389. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +83 -29
  390. package/src/renderers/webgl-fallback/utils/WebGLState.js +163 -17
  391. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +32 -5
  392. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +11 -4
  393. package/src/renderers/webgpu/WebGPUBackend.js +513 -145
  394. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +99 -20
  395. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -1
  396. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +3 -12
  397. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +24 -14
  398. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +80 -14
  399. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +62 -7
  400. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +9 -3
  401. package/src/renderers/webgpu/utils/WebGPUUtils.js +16 -4
  402. package/src/renderers/webxr/WebXRManager.js +25 -2
  403. package/src/scenes/Scene.js +3 -3
  404. package/src/textures/CompressedArrayTexture.js +16 -0
  405. package/src/textures/Data3DTexture.js +16 -0
  406. package/src/textures/DataArrayTexture.js +16 -0
  407. package/src/textures/DepthTexture.js +3 -3
  408. package/src/textures/Texture.js +3 -3
  409. package/src/textures/{Source.js → TextureSource.js} +39 -8
  410. package/build/three.core.min.js +0 -6
  411. package/build/three.module.min.js +0 -6
  412. package/build/three.tsl.min.js +0 -6
  413. package/build/three.webgpu.min.js +0 -6
  414. package/build/three.webgpu.nodes.min.js +0 -6
  415. package/examples/jsm/libs/ecsy.module.js +0 -1792
  416. package/examples/jsm/loaders/LottieLoader.js +0 -130
  417. package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +0 -52
@@ -1,173 +1,30 @@
1
- import {
2
- FileLoader, Loader, ImageBitmapLoader, Texture, RepeatWrapping, MeshBasicNodeMaterial,
3
- MeshPhysicalNodeMaterial, DoubleSide,
4
- } from '@gnsx/three/webgpu';
5
-
6
- import {
7
- float, bool, int, vec2, vec3, vec4, color, texture,
8
- positionLocal, positionWorld, uv, vertexColor,
9
- normalLocal, normalWorld, tangentLocal, tangentWorld,
10
- mul, abs, sign, floor, ceil, round, sin, cos, tan,
11
- asin, acos, sqrt, exp, clamp, min, max, normalize, length, dot, cross, normalMap,
12
- remap, smoothstep, luminance, mx_rgbtohsv, mx_hsvtorgb,
13
- mix, saturation, transpose, determinant, inverse, log, reflect, refract, element,
14
- mx_ramplr, mx_ramptb, mx_splitlr, mx_splittb,
15
- mx_fractal_noise_float, mx_noise_float, mx_cell_noise_float, mx_worley_noise_float,
16
- mx_transform_uv,
17
- mx_safepower, mx_contrast,
18
- mx_srgb_texture_to_lin_rec709,
19
- mx_add, mx_atan2, mx_divide, mx_modulo, mx_multiply, mx_power, mx_subtract,
20
- mx_timer, mx_frame, mat3, mx_ramp4,
21
- mx_invert, mx_ifgreater, mx_ifgreatereq, mx_ifequal, distance,
22
- mx_separate, mx_place2d, mx_rotate2d, mx_rotate3d, mx_heighttonormal,
23
- mx_unifiednoise2d, mx_unifiednoise3d
24
- } from '@gnsx/three/tsl';
25
-
26
- const colorSpaceLib = {
27
- mx_srgb_texture_to_lin_rec709
28
- };
29
-
30
- class MXElement {
31
-
32
- constructor( name, nodeFunc, params = [] ) {
33
-
34
- this.name = name;
35
- this.nodeFunc = nodeFunc;
36
- this.params = params;
1
+ import { FileLoader, Loader } from '@gnsx/three/webgpu';
37
2
 
38
- }
3
+ import { MaterialXDocument } from './materialx/MaterialXDocument.js';
4
+ import { MaterialXLog } from './materialx/MaterialXLog.js';
5
+ import { isZipBuffer, readMtlxArchive, createArchiveResolver } from './materialx/MaterialXArchive.js';
39
6
 
40
- }
7
+ const _textDecoder = new TextDecoder();
8
+
9
+ function getResourcePath( loaderPath, url ) {
10
+
11
+ if ( loaderPath ) return loaderPath;
41
12
 
42
- // Ref: https://github.com/mrdoob/three.js/issues/24674
43
-
44
- // Enhanced separate node to support multi-output referencing (outx, outy, outz, outw)
45
-
46
- // Type/arity-aware MaterialX node wrappers
47
-
48
- const MXElements = [
49
-
50
- // << Math >>
51
- new MXElement( 'add', mx_add, [ 'in1', 'in2' ] ),
52
- new MXElement( 'subtract', mx_subtract, [ 'in1', 'in2' ] ),
53
- new MXElement( 'multiply', mx_multiply, [ 'in1', 'in2' ] ),
54
- new MXElement( 'divide', mx_divide, [ 'in1', 'in2' ] ),
55
- new MXElement( 'modulo', mx_modulo, [ 'in1', 'in2' ] ),
56
- new MXElement( 'absval', abs, [ 'in1', 'in2' ] ),
57
- new MXElement( 'sign', sign, [ 'in1', 'in2' ] ),
58
- new MXElement( 'floor', floor, [ 'in1', 'in2' ] ),
59
- new MXElement( 'ceil', ceil, [ 'in1', 'in2' ] ),
60
- new MXElement( 'round', round, [ 'in1', 'in2' ] ),
61
- new MXElement( 'power', mx_power, [ 'in1', 'in2' ] ),
62
- new MXElement( 'sin', sin, [ 'in' ] ),
63
- new MXElement( 'cos', cos, [ 'in' ] ),
64
- new MXElement( 'tan', tan, [ 'in' ] ),
65
- new MXElement( 'asin', asin, [ 'in' ] ),
66
- new MXElement( 'acos', acos, [ 'in' ] ),
67
- new MXElement( 'atan2', mx_atan2, [ 'in1', 'in2' ] ),
68
- new MXElement( 'sqrt', sqrt, [ 'in' ] ),
69
- new MXElement( 'ln', log, [ 'in' ] ),
70
- new MXElement( 'exp', exp, [ 'in' ] ),
71
- new MXElement( 'clamp', clamp, [ 'in', 'low', 'high' ] ),
72
- new MXElement( 'min', min, [ 'in1', 'in2' ] ),
73
- new MXElement( 'max', max, [ 'in1', 'in2' ] ),
74
- new MXElement( 'normalize', normalize, [ 'in' ] ),
75
- new MXElement( 'magnitude', length, [ 'in1', 'in2' ] ),
76
- new MXElement( 'dotproduct', dot, [ 'in1', 'in2' ] ),
77
- new MXElement( 'crossproduct', cross, [ 'in' ] ),
78
- new MXElement( 'distance', distance, [ 'in1', 'in2' ] ),
79
- new MXElement( 'invert', mx_invert, [ 'in', 'amount' ] ),
80
- //new MtlXElement( 'transformpoint', ... ),
81
- //new MtlXElement( 'transformvector', ... ),
82
- //new MtlXElement( 'transformnormal', ... ),
83
- new MXElement( 'transformmatrix', mul, [ 'in1', 'in2' ] ),
84
- new MXElement( 'normalmap', normalMap, [ 'in', 'scale' ] ),
85
- new MXElement( 'transpose', transpose, [ 'in' ] ),
86
- new MXElement( 'determinant', determinant, [ 'in' ] ),
87
- new MXElement( 'invertmatrix', inverse, [ 'in' ] ),
88
- new MXElement( 'creatematrix', mat3, [ 'in1', 'in2', 'in3' ] ),
89
- //new MtlXElement( 'rotate2d', rotateUV, [ 'in', radians( 'amount' )** ] ),
90
- //new MtlXElement( 'rotate3d', ... ),
91
- //new MtlXElement( 'arrayappend', ... ),
92
- //new MtlXElement( 'dot', ... ),
93
-
94
- new MXElement( 'length', length, [ 'in' ] ),
95
- new MXElement( 'crossproduct', cross, [ 'in1', 'in2' ] ),
96
- new MXElement( 'floor', floor, [ 'in' ] ),
97
- new MXElement( 'ceil', ceil, [ 'in' ] ),
98
-
99
- // << Adjustment >>
100
- new MXElement( 'remap', remap, [ 'in', 'inlow', 'inhigh', 'outlow', 'outhigh' ] ),
101
- new MXElement( 'smoothstep', smoothstep, [ 'in', 'low', 'high' ] ),
102
- //new MtlXElement( 'curveadjust', ... ),
103
- //new MtlXElement( 'curvelookup', ... ),
104
- new MXElement( 'luminance', luminance, [ 'in', 'lumacoeffs' ] ),
105
- new MXElement( 'rgbtohsv', mx_rgbtohsv, [ 'in' ] ),
106
- new MXElement( 'hsvtorgb', mx_hsvtorgb, [ 'in' ] ),
107
-
108
- // << Mix >>
109
- new MXElement( 'mix', mix, [ 'bg', 'fg', 'mix' ] ),
110
-
111
- // << Channel >>
112
- new MXElement( 'combine2', vec2, [ 'in1', 'in2' ] ),
113
- new MXElement( 'combine3', vec3, [ 'in1', 'in2', 'in3' ] ),
114
- new MXElement( 'combine4', vec4, [ 'in1', 'in2', 'in3', 'in4' ] ),
115
-
116
- // << Procedural >>
117
- new MXElement( 'ramplr', mx_ramplr, [ 'valuel', 'valuer', 'texcoord' ] ),
118
- new MXElement( 'ramptb', mx_ramptb, [ 'valuet', 'valueb', 'texcoord' ] ),
119
- new MXElement( 'ramp4', mx_ramp4, [ 'valuetl', 'valuetr', 'valuebl', 'valuebr', 'texcoord' ] ),
120
- new MXElement( 'splitlr', mx_splitlr, [ 'valuel', 'valuer', 'texcoord' ] ),
121
- new MXElement( 'splittb', mx_splittb, [ 'valuet', 'valueb', 'texcoord' ] ),
122
- new MXElement( 'noise2d', mx_noise_float, [ 'texcoord', 'amplitude', 'pivot' ] ),
123
- new MXElement( 'noise3d', mx_noise_float, [ 'texcoord', 'amplitude', 'pivot' ] ),
124
- new MXElement( 'fractal3d', mx_fractal_noise_float, [ 'position', 'octaves', 'lacunarity', 'diminish', 'amplitude' ] ),
125
- new MXElement( 'cellnoise2d', mx_cell_noise_float, [ 'texcoord' ] ),
126
- new MXElement( 'cellnoise3d', mx_cell_noise_float, [ 'texcoord' ] ),
127
- new MXElement( 'worleynoise2d', mx_worley_noise_float, [ 'texcoord', 'jitter' ] ),
128
- new MXElement( 'worleynoise3d', mx_worley_noise_float, [ 'texcoord', 'jitter' ] ),
129
- new MXElement( 'unifiednoise2d', mx_unifiednoise2d, [ 'type', 'texcoord', 'freq', 'offset', 'jitter', 'outmin', 'outmax', 'clampoutput', 'octaves', 'lacunarity', 'diminish' ] ),
130
- new MXElement( 'unifiednoise3d', mx_unifiednoise3d, [ 'type', 'texcoord', 'freq', 'offset', 'jitter', 'outmin', 'outmax', 'clampoutput', 'octaves', 'lacunarity', 'diminish' ] ),
131
- // << Supplemental >>
132
- //new MtlXElement( 'tiledimage', ... ),
133
- //new MtlXElement( 'triplanarprojection', triplanarTextures, [ 'filex', 'filey', 'filez' ] ),
134
- //new MtlXElement( 'ramp4', ... ),
135
- new MXElement( 'place2d', mx_place2d, [ 'texcoord', 'pivot', 'scale', 'rotate', 'offset', 'operationorder' ] ),
136
- new MXElement( 'safepower', mx_safepower, [ 'in1', 'in2' ] ),
137
- new MXElement( 'contrast', mx_contrast, [ 'in', 'amount', 'pivot' ] ),
138
- //new MtlXElement( 'hsvadjust', ... ),
139
- new MXElement( 'saturate', saturation, [ 'in', 'amount' ] ),
140
- new MXElement( 'extract', element, [ 'in', 'index' ] ),
141
- new MXElement( 'separate2', mx_separate, [ 'in' ] ),
142
- new MXElement( 'separate3', mx_separate, [ 'in' ] ),
143
- new MXElement( 'separate4', mx_separate, [ 'in' ] ),
144
- new MXElement( 'reflect', reflect, [ 'in', 'normal' ] ),
145
- new MXElement( 'refract', refract, [ 'in', 'normal', 'ior' ] ),
146
-
147
- new MXElement( 'time', mx_timer ),
148
- new MXElement( 'frame', mx_frame ),
149
- new MXElement( 'ifgreater', mx_ifgreater, [ 'value1', 'value2', 'in1', 'in2' ] ),
150
- new MXElement( 'ifgreatereq', mx_ifgreatereq, [ 'value1', 'value2', 'in1', 'in2' ] ),
151
- new MXElement( 'ifequal', mx_ifequal, [ 'value1', 'value2', 'in1', 'in2' ] ),
152
-
153
- // Placeholder implementations for unsupported nodes
154
- new MXElement( 'rotate2d', mx_rotate2d, [ 'in', 'amount' ] ),
155
- new MXElement( 'rotate3d', mx_rotate3d, [ 'in', 'amount', 'axis' ] ),
156
- new MXElement( 'heighttonormal', mx_heighttonormal, [ 'in', 'scale', 'texcoord' ] ),
157
-
158
- ];
159
-
160
- const MtlXLibrary = {};
161
- MXElements.forEach( element => MtlXLibrary[ element.name ] = element );
13
+ const index = url.lastIndexOf( '/' );
14
+ return index === - 1 ? '' : url.slice( 0, index + 1 );
15
+
16
+ }
162
17
 
163
18
  /**
164
19
  * A loader for the MaterialX format.
165
20
  *
166
21
  * The node materials loaded with this loader can only be used with {@link WebGPURenderer}.
22
+ * Besides plain `.mtlx` documents, the loader accepts `.mtlx.zip` archives that bundle a
23
+ * document with its textures.
167
24
  *
168
25
  * ```js
169
26
  * const loader = new MaterialXLoader().setPath( SAMPLE_PATH );
170
- * const materials = await loader.loadAsync( 'standard_surface_brass_tiled.mtlx' );
27
+ * const { materials } = await loader.loadAsync( 'standard_surface_brass_tiled.mtlx' );
171
28
  * ```
172
29
  *
173
30
  * @augments Loader
@@ -184,6 +41,32 @@ class MaterialXLoader extends Loader {
184
41
 
185
42
  super( manager );
186
43
 
44
+ /**
45
+ * Releases the resources of the last loaded archive, if any.
46
+ *
47
+ * @private
48
+ * @type {?Function}
49
+ */
50
+ this.archiveDisposer = null;
51
+
52
+ }
53
+
54
+ /**
55
+ * Frees the resources of the last loaded archive.
56
+ *
57
+ * @return {MaterialXLoader} A reference to this loader.
58
+ */
59
+ dispose() {
60
+
61
+ if ( this.archiveDisposer ) {
62
+
63
+ this.archiveDisposer();
64
+ this.archiveDisposer = null;
65
+
66
+ }
67
+
68
+ return this;
69
+
187
70
  }
188
71
 
189
72
  /**
@@ -191,12 +74,13 @@ class MaterialXLoader extends Loader {
191
74
  * to the `onLoad()` callback.
192
75
  *
193
76
  * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
194
- * @param {function(Object<string,NodeMaterial>)} onLoad - Executed when the loading process has been finished.
77
+ * @param {function(Object)} onLoad - Executed when the loading process has been finished. Receives the parse result, see {@link MaterialXLoader#parse}.
195
78
  * @param {onProgressCallback} onProgress - Executed while the loading is in progress.
196
79
  * @param {onErrorCallback} onError - Executed when errors occur.
80
+ * @param {Object} [options] - Parse options, see {@link MaterialXLoader#parse}.
197
81
  * @return {MaterialXLoader} A reference to this loader.
198
82
  */
199
- load( url, onLoad, onProgress, onError ) {
83
+ load( url, onLoad, onProgress, onError, options = {} ) {
200
84
 
201
85
  const _onError = function ( e ) {
202
86
 
@@ -214,11 +98,12 @@ class MaterialXLoader extends Loader {
214
98
 
215
99
  new FileLoader( this.manager )
216
100
  .setPath( this.path )
217
- .load( url, async ( text ) => {
101
+ .setResponseType( 'arraybuffer' )
102
+ .load( url, ( data ) => {
218
103
 
219
104
  try {
220
105
 
221
- onLoad( this.parse( text ) );
106
+ onLoad( this.parseBuffer( data, url, options ) );
222
107
 
223
108
  } catch ( e ) {
224
109
 
@@ -233,891 +118,107 @@ class MaterialXLoader extends Loader {
233
118
  }
234
119
 
235
120
  /**
236
- * Parses the given MaterialX data and returns the resulting materials.
121
+ * Async version of {@link MaterialXLoader#load}. The progress callback can be
122
+ * omitted and the parse options passed as the second argument instead.
237
123
  *
238
- * Supported standard_surface inputs:
239
- * - base, base_color: Base color/albedo
240
- * - opacity: Alpha/transparency
241
- * - specular_roughness: Surface roughness
242
- * - metalness: Metallic property
243
- * - specular: Specular reflection intensity
244
- * - specular_color: Specular reflection color
245
- * - ior: Index of refraction
246
- * - specular_anisotropy, specular_rotation: Anisotropic reflection
247
- * - transmission, transmission_color: Transmission properties
248
- * - thin_film_thickness, thin_film_ior: Thin film interference
249
- * - sheen, sheen_color, sheen_roughness: Sheen properties
250
- * - normal: Normal map
251
- * - coat, coat_roughness, coat_color: Clearcoat properties
252
- * - emission, emissionColor: Emission properties
253
- *
254
- * @param {string} text - The raw MaterialX data as a string.
255
- * @return {Object<string,NodeMaterial>} A dictionary holding the parse node materials.
124
+ * @param {string} url - The path/URL of the file to be loaded. This can also be a data URI.
125
+ * @param {onProgressCallback|Object} [onProgress] - Executed while the loading is in progress, or the parse options.
126
+ * @param {Object} [options] - Parse options, see {@link MaterialXLoader#parse}.
127
+ * @return {Promise<Object>} A Promise that resolves with the parse result.
256
128
  */
257
- parse( text ) {
258
-
259
- return new MaterialX( this.manager, this.path ).parse( text );
260
-
261
- }
262
-
263
- }
264
-
265
- class MaterialXNode {
266
-
267
- constructor( materialX, nodeXML, nodePath = '' ) {
268
-
269
- if ( ! materialX || typeof materialX !== 'object' ) {
270
-
271
- console.warn( 'MaterialXNode: materialX argument is not an object!', { materialX, nodeXML, nodePath } );
272
-
273
- }
274
-
275
- this.materialX = materialX;
276
- this.nodeXML = nodeXML;
277
- this.nodePath = nodePath ? nodePath + '/' + this.name : this.name;
278
-
279
- this.parent = null;
280
-
281
- this.node = null;
282
-
283
- this.children = [];
284
-
285
- }
286
-
287
- get element() {
288
-
289
- return this.nodeXML.nodeName;
290
-
291
- }
292
-
293
- get nodeGraph() {
294
-
295
- return this.getAttribute( 'nodegraph' );
296
-
297
- }
298
-
299
- get nodeName() {
300
-
301
- return this.getAttribute( 'nodename' );
302
-
303
- }
304
-
305
- get interfaceName() {
306
-
307
- return this.getAttribute( 'interfacename' );
308
-
309
- }
310
-
311
- get output() {
312
-
313
- return this.getAttribute( 'output' );
314
-
315
- }
316
-
317
- get name() {
318
-
319
- return this.getAttribute( 'name' );
320
-
321
- }
322
-
323
- get type() {
324
-
325
- return this.getAttribute( 'type' );
326
-
327
- }
328
-
329
- get value() {
330
-
331
- return this.getAttribute( 'value' );
332
-
333
- }
334
-
335
- getNodeGraph() {
336
-
337
- let nodeX = this;
338
-
339
- while ( nodeX !== null ) {
340
-
341
- if ( nodeX.element === 'nodegraph' ) {
342
-
343
- break;
344
-
345
- }
346
-
347
- nodeX = nodeX.parent;
348
-
349
- }
350
-
351
- return nodeX;
352
-
353
- }
354
-
355
- getRoot() {
356
-
357
- let nodeX = this;
358
-
359
- while ( nodeX.parent !== null ) {
360
-
361
- nodeX = nodeX.parent;
362
-
363
- }
364
-
365
- return nodeX;
366
-
367
- }
368
-
369
- get referencePath() {
370
-
371
- let referencePath = null;
372
-
373
- if ( this.nodeGraph !== null && this.output !== null ) {
374
-
375
- referencePath = this.nodeGraph + '/' + this.output;
376
-
377
- } else if ( this.nodeName !== null || this.interfaceName !== null ) {
378
-
379
- referencePath = this.getNodeGraph().nodePath + '/' + ( this.nodeName || this.interfaceName );
380
-
381
- }
382
-
383
- return referencePath;
384
-
385
- }
386
-
387
- get hasReference() {
388
-
389
- return this.referencePath !== null;
390
-
391
- }
392
-
393
- get isConst() {
394
-
395
- return this.element === 'input' && this.value !== null && this.type !== 'filename';
396
-
397
- }
398
-
399
- getColorSpaceNode() {
400
-
401
- const csSource = this.getAttribute( 'colorspace' );
402
- const csTarget = this.getRoot().getAttribute( 'colorspace' );
403
-
404
- const nodeName = `mx_${ csSource }_to_${ csTarget }`;
405
-
406
- return colorSpaceLib[ nodeName ];
407
-
408
- }
409
-
410
- getTexture() {
411
-
412
- const filePrefix = this.getRecursiveAttribute( 'fileprefix' ) || '';
413
- const uri = filePrefix + this.value;
129
+ loadAsync( url, onProgress, options = {} ) {
414
130
 
415
- if ( this.materialX.textureCache.has( uri ) ) {
131
+ if ( onProgress && typeof onProgress === 'object' ) {
416
132
 
417
- return this.materialX.textureCache.get( uri );
133
+ options = onProgress;
134
+ onProgress = undefined;
418
135
 
419
136
  }
420
137
 
421
- let loader = this.materialX.textureLoader;
138
+ return new Promise( ( resolve, reject ) => {
422
139
 
423
- if ( uri ) {
424
-
425
- const handler = this.materialX.manager.getHandler( uri );
426
- if ( handler !== null ) loader = handler;
427
-
428
- }
429
-
430
- const texture = new Texture();
431
- texture.wrapS = texture.wrapT = RepeatWrapping;
432
-
433
- this.materialX.textureCache.set( uri, texture );
434
-
435
- loader.load( uri, function ( imageBitmap ) {
436
-
437
- texture.image = imageBitmap;
438
- texture.needsUpdate = true;
140
+ this.load( url, resolve, onProgress, reject, options );
439
141
 
440
142
  } );
441
143
 
442
- return texture;
443
-
444
144
  }
445
145
 
446
- getClassFromType( type ) {
447
-
448
- let nodeClass = null;
449
-
450
- if ( type === 'integer' ) nodeClass = int;
451
- else if ( type === 'float' ) nodeClass = float;
452
- else if ( type === 'vector2' ) nodeClass = vec2;
453
- else if ( type === 'vector3' ) nodeClass = vec3;
454
- else if ( type === 'vector4' || type === 'color4' ) nodeClass = vec4;
455
- else if ( type === 'color3' ) nodeClass = color;
456
- else if ( type === 'boolean' ) nodeClass = bool;
457
-
458
- return nodeClass;
459
-
460
- }
461
-
462
- getNode( out = null ) {
463
-
464
- let node = this.node;
465
-
466
- if ( node !== null && out === null ) {
467
-
468
- return node;
469
-
470
- }
471
-
472
- // Handle <input name="texcoord" type="vector2" ... />
473
- if (
474
- this.element === 'input' &&
475
- this.name === 'texcoord' &&
476
- this.type === 'vector2'
477
- ) {
478
-
479
- // Try to get index from defaultgeomprop (e.g., "UV0" => 0)
480
- let index = 0;
481
- const defaultGeomProp = this.getAttribute( 'defaultgeomprop' );
482
- if ( defaultGeomProp && /^UV(\d+)$/.test( defaultGeomProp ) ) {
483
-
484
- index = parseInt( defaultGeomProp.match( /^UV(\d+)$/ )[ 1 ], 10 );
485
-
486
- }
487
-
488
- node = uv( index );
489
-
490
- }
491
-
492
- // Multi-output support for separate/separate3
493
- if (
494
- ( this.element === 'separate3' || this.element === 'separate2' || this.element === 'separate4' ) &&
495
- out && typeof out === 'string' && out.startsWith( 'out' )
496
- ) {
497
-
498
- const inNode = this.getNodeByName( 'in' );
499
- return mx_separate( inNode, out );
500
-
501
- }
502
-
503
- //
504
-
505
- const type = this.type;
506
-
507
- if ( this.isConst ) {
508
-
509
- const nodeClass = this.getClassFromType( type );
510
-
511
- node = nodeClass( ...this.getVector() );
512
-
513
- } else if ( this.hasReference ) {
514
-
515
- if ( this.element === 'output' && this.output && out === null ) {
516
-
517
- out = this.output;
518
-
519
- }
520
-
521
- node = this.materialX.getMaterialXNode( this.referencePath ).getNode( out );
522
-
523
- } else {
524
-
525
- const element = this.element;
526
-
527
- if ( element === 'convert' ) {
528
-
529
- const nodeClass = this.getClassFromType( type );
530
-
531
- node = nodeClass( this.getNodeByName( 'in' ) );
532
-
533
- } else if ( element === 'constant' ) {
534
-
535
- node = this.getNodeByName( 'value' );
536
-
537
- } else if ( element === 'position' ) {
538
-
539
- const space = this.getAttribute( 'space' );
540
- node = space === 'world' ? positionWorld : positionLocal;
541
-
542
- } else if ( element === 'normal' ) {
543
-
544
- const space = this.getAttribute( 'space' );
545
- node = space === 'world' ? normalWorld : normalLocal;
546
-
547
- } else if ( element === 'tangent' ) {
548
-
549
- const space = this.getAttribute( 'space' );
550
- node = space === 'world' ? tangentWorld : tangentLocal;
551
-
552
- } else if ( element === 'texcoord' ) {
553
-
554
- const indexNode = this.getChildByName( 'index' );
555
- const index = indexNode ? parseInt( indexNode.value ) : 0;
556
-
557
- node = uv( index );
558
-
559
- } else if ( element === 'geomcolor' ) {
560
-
561
- const indexNode = this.getChildByName( 'index' );
562
- const index = indexNode ? parseInt( indexNode.value ) : 0;
563
-
564
- node = vertexColor( index );
565
-
566
- } else if ( element === 'tiledimage' ) {
567
-
568
- const file = this.getChildByName( 'file' );
569
-
570
- const textureFile = file.getTexture();
571
- const uvTiling = mx_transform_uv( ...this.getNodesByNames( [ 'uvtiling', 'uvoffset' ] ) );
572
-
573
- node = texture( textureFile, uvTiling );
574
-
575
- const colorSpaceNode = file.getColorSpaceNode();
576
-
577
- if ( colorSpaceNode ) {
578
-
579
- node = colorSpaceNode( node );
580
-
581
- }
582
-
583
- } else if ( element === 'image' ) {
584
-
585
- const file = this.getChildByName( 'file' );
586
- const uvNode = this.getNodeByName( 'texcoord' );
587
-
588
- const textureFile = file.getTexture();
589
-
590
- node = texture( textureFile, uvNode );
591
-
592
- const colorSpaceNode = file.getColorSpaceNode();
593
-
594
- if ( colorSpaceNode ) {
595
-
596
- node = colorSpaceNode( node );
597
-
598
- }
599
-
600
- } else if ( MtlXLibrary[ element ] !== undefined ) {
601
-
602
- const nodeElement = MtlXLibrary[ element ];
603
-
604
- if ( ! nodeElement ) {
605
-
606
- throw new Error( `THREE.MaterialXLoader: Unexpected node ${ new XMLSerializer().serializeToString( this.nodeXML ) }.` );
607
-
608
- }
609
-
610
- if ( ! nodeElement.nodeFunc ) {
611
-
612
- throw new Error( `THREE.MaterialXLoader: Unexpected node 2 ${ new XMLSerializer().serializeToString( this.nodeXML ) }.` );
613
-
614
- }
615
-
616
- if ( out !== null ) {
617
-
618
- node = nodeElement.nodeFunc( ...this.getNodesByNames( ...nodeElement.params ), out );
619
-
620
- } else {
621
-
622
- node = nodeElement.nodeFunc( ...this.getNodesByNames( ...nodeElement.params ) );
623
-
624
- }
625
-
626
- }
627
-
628
- }
146
+ /**
147
+ * Parses a raw MaterialX document or a `.mtlx.zip` archive and returns the resulting materials.
148
+ *
149
+ * @param {ArrayBuffer|Uint8Array|string} data - The MaterialX document or archive.
150
+ * @param {string} [url=''] - The URL the data was loaded from, used to resolve relative resource paths.
151
+ * @param {Object} [options] - Parse options, see {@link MaterialXLoader#parse}.
152
+ * @return {Object} The parse result, see {@link MaterialXLoader#parse}.
153
+ */
154
+ parseBuffer( data, url = '', options = {} ) {
629
155
 
630
- //
156
+ this.dispose();
631
157
 
632
- if ( node === null ) {
158
+ let text;
159
+ let archiveResolver = null;
633
160
 
634
- console.warn( `THREE.MaterialXLoader: Unexpected node ${ new XMLSerializer().serializeToString( this.nodeXML ) }.` );
161
+ if ( data && ( isZipBuffer( data ) || /\.mtlx\.zip$/i.test( url ) ) ) {
635
162
 
636
- node = float( 0 );
163
+ const archive = readMtlxArchive( data );
164
+ text = archive.text;
637
165
 
638
- }
166
+ const resolver = createArchiveResolver( archive.files );
167
+ archiveResolver = resolver.resolve;
168
+ this.archiveDisposer = resolver.dispose;
639
169
 
640
- //
170
+ } else if ( typeof data === 'string' ) {
641
171
 
642
- const nodeToTypeClass = this.getClassFromType( type );
172
+ text = data;
643
173
 
644
- if ( nodeToTypeClass !== null ) {
174
+ } else if ( data instanceof Uint8Array ) {
645
175
 
646
- node = nodeToTypeClass( node );
176
+ text = _textDecoder.decode( data );
647
177
 
648
178
  } else {
649
179
 
650
- console.warn( `THREE.MaterialXLoader: Unexpected node ${ new XMLSerializer().serializeToString( this.nodeXML ) }.` );
651
- node = float( 0 );
652
-
653
- }
654
-
655
- node.name = this.name;
656
-
657
- this.node = node;
658
-
659
- return node;
660
-
661
- }
662
-
663
- getChildByName( name ) {
664
-
665
- for ( const input of this.children ) {
666
-
667
- if ( input.name === name ) {
668
-
669
- return input;
670
-
671
- }
180
+ text = _textDecoder.decode( new Uint8Array( data ) );
672
181
 
673
182
  }
674
183
 
675
- }
676
-
677
- getNodes() {
678
-
679
- const nodes = {};
680
-
681
- for ( const input of this.children ) {
682
-
683
- const node = input.getNode();
684
-
685
- nodes[ node.name ] = node;
686
-
687
- }
688
-
689
- return nodes;
690
-
691
- }
692
-
693
- getNodeByName( name ) {
694
-
695
- const child = this.getChildByName( name );
696
-
697
- return child ? child.getNode( child.output ) : undefined;
698
-
699
- }
700
-
701
- getNodesByNames( ...names ) {
702
-
703
- const nodes = [];
704
-
705
- for ( const name of names ) {
706
-
707
- const node = this.getNodeByName( name );
708
-
709
- if ( node ) nodes.push( node );
710
-
711
- }
712
-
713
- return nodes;
714
-
715
- }
716
-
717
- getValue() {
718
-
719
- return this.value.trim();
720
-
721
- }
722
-
723
- getVector() {
724
-
725
- const vector = [];
726
-
727
- for ( const val of this.getValue().split( /[,|\s]/ ) ) {
728
-
729
- if ( val !== '' ) {
730
-
731
- vector.push( Number( val.trim() ) );
732
-
733
- }
734
-
735
- }
736
-
737
- return vector;
738
-
739
- }
740
-
741
- getAttribute( name ) {
742
-
743
- return this.nodeXML.getAttribute( name );
744
-
745
- }
746
-
747
- getRecursiveAttribute( name ) {
748
-
749
- let attribute = this.nodeXML.getAttribute( name );
750
-
751
- if ( attribute === null && this.parent !== null ) {
752
-
753
- attribute = this.parent.getRecursiveAttribute( name );
754
-
755
- }
756
-
757
- return attribute;
758
-
759
- }
760
-
761
- setStandardSurfaceToGltfPBR( material ) {
762
-
763
- const inputs = this.getNodes();
764
-
765
- //
766
-
767
- let colorNode = null;
768
-
769
- if ( inputs.base && inputs.base_color ) colorNode = mul( inputs.base, inputs.base_color );
770
- else if ( inputs.base ) colorNode = inputs.base;
771
- else if ( inputs.base_color ) colorNode = inputs.base_color;
772
-
773
- //
774
-
775
- let opacityNode = null;
776
-
777
- if ( inputs.opacity ) opacityNode = inputs.opacity;
778
-
779
- //
780
-
781
- let roughnessNode = null;
782
-
783
- if ( inputs.specular_roughness ) roughnessNode = inputs.specular_roughness;
784
-
785
- //
786
-
787
- let metalnessNode = null;
788
-
789
- if ( inputs.metalness ) metalnessNode = inputs.metalness;
790
-
791
- //
792
-
793
- let specularIntensityNode = null;
794
-
795
- if ( inputs.specular ) specularIntensityNode = inputs.specular;
796
-
797
- //
798
-
799
- let specularColorNode = null;
800
-
801
- if ( inputs.specular_color ) specularColorNode = inputs.specular_color;
802
-
803
- //
804
-
805
- let iorNode = null;
806
-
807
- if ( inputs.ior ) iorNode = inputs.ior;
808
-
809
- //
810
-
811
- let anisotropyNode = null;
812
- let anisotropyRotationNode = null;
813
-
814
- if ( inputs.specular_anisotropy ) anisotropyNode = inputs.specular_anisotropy;
815
- if ( inputs.specular_rotation ) anisotropyRotationNode = inputs.specular_rotation;
816
-
817
- //
818
-
819
- let transmissionNode = null;
820
- let transmissionColorNode = null;
821
-
822
- if ( inputs.transmission ) transmissionNode = inputs.transmission;
823
- if ( inputs.transmission_color ) transmissionColorNode = inputs.transmission_color;
824
-
825
- //
826
-
827
- let thinFilmThicknessNode = null;
828
- let thinFilmIorNode = null;
829
-
830
- if ( inputs.thin_film_thickness ) thinFilmThicknessNode = inputs.thin_film_thickness;
831
-
832
- if ( inputs.thin_film_ior ) {
833
-
834
- // Clamp IOR to valid range for Three.js (1.0 to 2.333)
835
- thinFilmIorNode = clamp( inputs.thin_film_ior, float( 1.0 ), float( 2.333 ) );
836
-
837
- }
838
-
839
- //
840
-
841
- let sheenNode = null;
842
- let sheenColorNode = null;
843
- let sheenRoughnessNode = null;
844
-
845
- if ( inputs.sheen ) sheenNode = inputs.sheen;
846
- if ( inputs.sheen_color ) sheenColorNode = inputs.sheen_color;
847
- if ( inputs.sheen_roughness ) sheenRoughnessNode = inputs.sheen_roughness;
848
-
849
- //
850
-
851
- let clearcoatNode = null;
852
- let clearcoatRoughnessNode = null;
853
-
854
- if ( inputs.coat ) clearcoatNode = inputs.coat;
855
- if ( inputs.coat_roughness ) clearcoatRoughnessNode = inputs.coat_roughness;
856
-
857
- if ( inputs.coat_color ) {
858
-
859
- colorNode = colorNode ? mul( colorNode, inputs.coat_color ) : colorNode;
860
-
861
- }
862
-
863
- //
864
-
865
- let normalNode = null;
866
-
867
- if ( inputs.normal ) normalNode = inputs.normal;
868
-
869
- //
870
-
871
- let emissiveNode = null;
872
-
873
- if ( inputs.emission ) emissiveNode = inputs.emission;
874
- if ( inputs.emissionColor ) {
875
-
876
- emissiveNode = emissiveNode ? mul( emissiveNode, inputs.emissionColor ) : emissiveNode;
877
-
878
- }
879
-
880
- //
881
-
882
- material.colorNode = colorNode || color( 0.8, 0.8, 0.8 );
883
- material.opacityNode = opacityNode || float( 1.0 );
884
- material.roughnessNode = roughnessNode || float( 0.2 );
885
- material.metalnessNode = metalnessNode || float( 0 );
886
- material.specularIntensityNode = specularIntensityNode || float( 0.5 );
887
- material.specularColorNode = specularColorNode || color( 1.0, 1.0, 1.0 );
888
- material.iorNode = iorNode || float( 1.5 );
889
-
890
- if ( anisotropyNode !== null ) {
891
-
892
- material.anisotropyNode = anisotropyNode;
893
- material.anisotropyRotationNode = anisotropyRotationNode || float( 0 );
894
-
895
- }
896
-
897
- if ( transmissionNode !== null ) {
898
-
899
- material.transmissionNode = transmissionNode;
900
- material.transmissionColorNode = transmissionColorNode || color( 1.0, 1.0, 1.0 );
901
-
902
- }
903
-
904
- material.thinFilmThicknessNode = thinFilmThicknessNode || float( 0 );
905
- material.thinFilmIorNode = thinFilmIorNode || float( 1.5 );
906
-
907
- if ( sheenNode !== null ) {
908
-
909
- material.sheenNode = sheenNode;
910
- material.sheenColorNode = sheenColorNode || color( 1.0, 1.0, 1.0 );
911
- material.sheenRoughnessNode = sheenRoughnessNode || float( 0.5 );
912
-
913
- }
914
-
915
- if ( clearcoatNode !== null ) {
916
-
917
- material.clearcoatNode = clearcoatNode;
918
- material.clearcoatRoughnessNode = clearcoatRoughnessNode || float( 0 );
919
-
920
- }
921
-
922
- if ( normalNode ) material.normalNode = normalNode;
923
- if ( emissiveNode ) material.emissiveNode = emissiveNode;
924
-
925
- // Auto-enable iridescence when thin film parameters are present
926
- if ( thinFilmThicknessNode && thinFilmThicknessNode.value !== undefined && thinFilmThicknessNode.value > 0 ) {
927
-
928
- material.iridescence = 1.0;
929
-
930
- }
931
-
932
- if ( opacityNode !== null ) {
933
-
934
- material.transparent = true;
935
-
936
- }
937
-
938
- if ( transmissionNode !== null ) {
939
-
940
- material.side = DoubleSide;
941
- material.transparent = true;
942
-
943
- }
944
-
945
- }
946
-
947
- /*setGltfPBR( material ) {
948
-
949
- const inputs = this.getNodes();
950
-
951
- console.log( inputs );
952
-
953
- }*/
954
-
955
- setMaterial( material ) {
956
-
957
- const element = this.element;
958
-
959
- if ( element === 'gltf_pbr' ) {
960
-
961
- //this.setGltfPBR( material );
962
-
963
- } else if ( element === 'standard_surface' ) {
964
-
965
- this.setStandardSurfaceToGltfPBR( material );
966
-
967
- }
968
-
969
- }
970
-
971
- toBasicMaterial() {
972
-
973
- const material = new MeshBasicNodeMaterial();
974
- material.name = this.name;
975
-
976
- for ( const nodeX of this.children.toReversed() ) {
977
-
978
- if ( nodeX.name === 'out' ) {
979
-
980
- material.colorNode = nodeX.getNode();
981
-
982
- break;
983
-
984
- }
985
-
986
- }
987
-
988
- return material;
989
-
990
- }
991
-
992
- toPhysicalMaterial() {
993
-
994
- const material = new MeshPhysicalNodeMaterial();
995
- material.name = this.name;
996
-
997
- for ( const nodeX of this.children ) {
998
-
999
- const shaderProperties = this.materialX.getMaterialXNode( nodeX.nodeName );
1000
- shaderProperties.setMaterial( material );
1001
-
1002
- }
1003
-
1004
- return material;
1005
-
1006
- }
1007
-
1008
- toMaterials() {
1009
-
1010
- const materials = {};
1011
-
1012
- let isUnlit = true;
1013
-
1014
- for ( const nodeX of this.children ) {
1015
-
1016
- if ( nodeX.element === 'surfacematerial' ) {
1017
-
1018
- const material = nodeX.toPhysicalMaterial();
1019
-
1020
- materials[ material.name ] = material;
1021
-
1022
- isUnlit = false;
1023
-
1024
- }
1025
-
1026
- }
1027
-
1028
- if ( isUnlit ) {
1029
-
1030
- for ( const nodeX of this.children ) {
1031
-
1032
- if ( nodeX.element === 'nodegraph' ) {
1033
-
1034
- const material = nodeX.toBasicMaterial();
1035
-
1036
- materials[ material.name ] = material;
1037
-
1038
- }
1039
-
1040
- }
1041
-
1042
- }
1043
-
1044
- return materials;
1045
-
1046
- }
1047
-
1048
- add( materialXNode ) {
1049
-
1050
- materialXNode.parent = this;
1051
-
1052
- this.children.push( materialXNode );
1053
-
1054
- }
1055
-
1056
- }
1057
-
1058
- class MaterialX {
1059
-
1060
- constructor( manager, path ) {
1061
-
1062
- this.manager = manager;
1063
- this.path = path;
1064
- this.resourcePath = '';
1065
-
1066
- this.nodesXLib = new Map();
1067
- //this.nodesXRefLib = new WeakMap();
1068
-
1069
- this.textureLoader = new ImageBitmapLoader( manager );
1070
- this.textureLoader.setOptions( { imageOrientation: 'flipY' } );
1071
-
1072
- this.textureCache = new Map();
1073
-
1074
- }
1075
-
1076
- addMaterialXNode( materialXNode ) {
1077
-
1078
- this.nodesXLib.set( materialXNode.nodePath, materialXNode );
184
+ return this.parse( text, {
185
+ ...options,
186
+ archiveResolver,
187
+ path: options.path || getResourcePath( this.path, url )
188
+ } );
1079
189
 
1080
190
  }
1081
191
 
1082
- /*getMaterialXNodeFromXML( xmlNode ) {
1083
-
1084
- return this.nodesXRefLib.get( xmlNode );
1085
-
1086
- }*/
1087
-
1088
- getMaterialXNode( ...names ) {
1089
-
1090
- return this.nodesXLib.get( names.join( '/' ) );
1091
-
1092
- }
192
+ /**
193
+ * Parses the given MaterialX document and returns the resulting materials
194
+ * together with the translation log.
195
+ *
196
+ * @param {string} text - The raw MaterialX data as a string.
197
+ * @param {Object} [options] - Parse options.
198
+ * @param {string} [options.path] - The base path for resolving resources like textures. Defaults to the loader's path.
199
+ * @param {string} [options.materialName] - Only translate the material with this name. Defaults to all materials.
200
+ * @param {string} [options.uvSpace='bottom-left'] - The UV space of the document's textures, `'bottom-left'` or `'top-left'`.
201
+ * @param {Function} [options.interfaceValidator] - Validates node interfaces, see `createStrictInterfaceValidator()` in `MaterialXInterfaceValidation.js`.
202
+ * @param {boolean} [options.throwOnErrors=true] - Whether translation errors throw or are only reported in the log.
203
+ * @return {{materials: Object<string,NodeMaterial>, log: Array<Object>, errors: Array<Object>, warnings: Array<Object>}} The materials keyed by name and the translation log.
204
+ */
205
+ parse( text, options = {} ) {
1093
206
 
1094
- parseNode( nodeXML, nodePath = '' ) {
207
+ const log = new MaterialXLog();
1095
208
 
1096
- const materialXNode = new MaterialXNode( this, nodeXML, nodePath );
1097
- if ( materialXNode.nodePath ) this.addMaterialXNode( materialXNode );
209
+ const document = new MaterialXDocument( this.manager, options.path || this.path, log, options.archiveResolver || null, options.uvSpace );
210
+ const result = document.parse( text, options.materialName || null, {
211
+ interfaceValidator: options.interfaceValidator,
212
+ } );
1098
213
 
1099
- for ( const childNodeXML of nodeXML.children ) {
214
+ if ( options.throwOnErrors !== false && log.errors.length > 0 ) {
1100
215
 
1101
- const childMXNode = this.parseNode( childNodeXML, materialXNode.nodePath );
1102
- materialXNode.add( childMXNode );
216
+ const details = log.errors.map( ( error ) => error.message ).join( ' ' );
217
+ throw new Error( `THREE.MaterialXLoader: MaterialX translation failed with ${log.errors.length} error(s). ${details}` );
1103
218
 
1104
219
  }
1105
220
 
1106
- return materialXNode;
1107
-
1108
- }
1109
-
1110
- parse( text ) {
1111
-
1112
- const rootXML = new DOMParser().parseFromString( text, 'application/xml' ).documentElement;
1113
-
1114
- this.textureLoader.setPath( this.path );
1115
-
1116
- //
1117
-
1118
- const materials = this.parseNode( rootXML ).toMaterials();
1119
-
1120
- return { materials };
221
+ return result;
1121
222
 
1122
223
  }
1123
224