@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.
- package/build/three.cjs +10 -82600
- package/build/three.core.js +1303 -728
- package/build/three.module.js +439 -338
- package/build/three.tsl.js +74 -44
- package/build/three.webgpu.js +6036 -2184
- package/build/three.webgpu.nodes.js +6020 -2184
- package/examples/jsm/Addons.js +6 -6
- package/examples/jsm/controls/ArcballControls.js +1 -1
- package/examples/jsm/controls/FirstPersonControls.js +44 -20
- package/examples/jsm/controls/OrbitControls.js +9 -0
- package/examples/jsm/controls/TrackballControls.js +109 -4
- package/examples/jsm/csm/CSMShadowNode.js +13 -0
- package/examples/jsm/exporters/GLTFExporter.js +23 -7
- package/examples/jsm/exporters/USDZExporter.js +2 -2
- package/examples/jsm/generators/CityGenerator.js +377 -45
- package/examples/jsm/generators/ForestGenerator.js +12 -12
- package/examples/jsm/generators/TerrainGenerator.js +49 -37
- package/examples/jsm/generators/TreeGenerator.js +70 -76
- package/examples/jsm/generators/city/BenchGenerator.js +127 -0
- package/examples/jsm/generators/city/CarGenerator.js +479 -0
- package/examples/jsm/generators/city/CityGeneratorUtils.js +31 -0
- package/examples/jsm/generators/city/HydrantGenerator.js +106 -0
- package/examples/jsm/generators/city/InstancedMeshGenerator.js +86 -0
- package/examples/jsm/generators/city/PersonGenerator.js +447 -0
- package/examples/jsm/generators/city/SidewalkGenerator.js +33 -38
- package/examples/jsm/generators/city/SkyscraperGenerator.js +448 -48
- package/examples/jsm/generators/city/StreetTreeGenerator.js +231 -0
- package/examples/jsm/generators/city/StreetlightGenerator.js +100 -0
- package/examples/jsm/generators/city/TrafficlightGenerator.js +106 -0
- package/examples/jsm/generators/city/TrashcanGenerator.js +100 -0
- package/examples/jsm/geometries/BoxLineGeometry.js +1 -1
- package/examples/jsm/geometries/ParametricGeometry.js +1 -1
- package/examples/jsm/geometries/RoundedBoxGeometry.js +1 -1
- package/examples/jsm/gpgpu/CountingSort.js +271 -0
- package/examples/jsm/helpers/LightProbeGridHelper.js +60 -239
- package/examples/jsm/helpers/LightProbeGridHelperWebGL.js +221 -0
- package/examples/jsm/inspector/Extension.js +94 -0
- package/examples/jsm/inspector/Inspector.js +145 -41
- package/examples/jsm/inspector/RendererInspector.js +100 -52
- package/examples/jsm/inspector/extensions/color-grading/ColorGrading.js +2609 -0
- package/examples/jsm/inspector/extensions/color-grading/ColorWheel.js +352 -0
- package/examples/jsm/inspector/extensions/color-grading/CurveEditor.js +599 -0
- package/examples/jsm/inspector/extensions/color-grading/LUT3DStyle.js +1201 -0
- package/examples/jsm/inspector/extensions/color-grading/LUTMath.js +788 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/BrightnessModule.js +72 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ColorWheelModule.js +112 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ContrastModule.js +82 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/CurvesModule.js +109 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ExposureHueModule.js +110 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ExposureModule.js +73 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/HueModule.js +78 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/ImportedCubeModule.js +89 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/Module.js +285 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/OutputModule.js +101 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/RendererModule.js +225 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/SatVibranceModule.js +102 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/SaturationModule.js +76 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/VibranceModule.js +76 -0
- package/examples/jsm/inspector/extensions/color-grading/modules/WhiteBalanceModule.js +86 -0
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphEditor.js +26 -31
- package/examples/jsm/inspector/extensions/tsl-graph/TSLGraphLoader.js +1 -0
- package/examples/jsm/inspector/tabs/Memory.js +0 -2
- package/examples/jsm/inspector/tabs/Settings.js +4 -0
- package/examples/jsm/inspector/tabs/Timeline.js +223 -171
- package/examples/jsm/inspector/tabs/Viewer.js +515 -21
- package/examples/jsm/inspector/ui/List.js +15 -9
- package/examples/jsm/inspector/ui/Profiler.js +170 -14
- package/examples/jsm/inspector/ui/Style.js +269 -23
- package/examples/jsm/inspector/ui/Tab.js +2 -0
- package/examples/jsm/inspector/ui/Values.js +14 -2
- package/examples/jsm/interactive/HTMLMesh.js +19 -3
- package/examples/jsm/lighting/LightProbeGrid.js +484 -889
- package/examples/jsm/lighting/LightProbeGridUtils.js +107 -0
- package/examples/jsm/lighting/LightProbeGridWebGL.js +841 -0
- package/examples/jsm/lighting/vxgi/VXGIConeTracer.js +194 -0
- package/examples/jsm/lighting/vxgi/VXGINode.js +660 -0
- package/examples/jsm/lighting/vxgi/VXGISceneCollector.js +478 -0
- package/examples/jsm/lighting/vxgi/VXGIVolume.js +1430 -0
- package/examples/jsm/lights/SunLight.js +95 -0
- package/examples/jsm/lights/SunLightNode.js +56 -0
- package/examples/jsm/lights/SunLightShadow.js +319 -0
- package/examples/jsm/lights/SunShadowNode.js +312 -0
- package/examples/jsm/loaders/3DMLoader.js +150 -49
- package/examples/jsm/loaders/3MFLoader.js +202 -1
- package/examples/jsm/loaders/FBXLoader.js +81 -5
- package/examples/jsm/loaders/GLTFGaussianSplatLoaderExtension.js +330 -0
- package/examples/jsm/loaders/GLTFLoader.js +79 -14
- package/examples/jsm/loaders/GaussianSplatPLYLoader.js +386 -0
- package/examples/jsm/loaders/KSPLATLoader.js +463 -0
- package/examples/jsm/loaders/MaterialXLoader.js +111 -1010
- package/examples/jsm/loaders/PCDLoader.js +1 -1
- package/examples/jsm/loaders/SPLATLoader.js +139 -0
- package/examples/jsm/loaders/SPZLoader.js +561 -0
- package/examples/jsm/loaders/materialx/MaterialXArchive.js +108 -0
- package/examples/jsm/loaders/materialx/MaterialXDocument.js +878 -0
- package/examples/jsm/loaders/materialx/MaterialXHextile.js +183 -0
- package/examples/jsm/loaders/materialx/MaterialXInterfaceValidation.js +376 -0
- package/examples/jsm/loaders/materialx/MaterialXLog.js +75 -0
- package/examples/jsm/loaders/materialx/MaterialXNodeInterfaceRegistry.js +4 -0
- package/examples/jsm/loaders/materialx/MaterialXNodeLibrary.js +1021 -0
- package/examples/jsm/loaders/materialx/MaterialXSurfaceMappings.js +661 -0
- package/examples/jsm/loaders/materialx/MaterialXUtils.js +57 -0
- package/examples/jsm/loaders/materialx/compile/MaterialXCompileRegistry.js +997 -0
- package/examples/jsm/loaders/materialx/parse/MaterialXParser.js +28 -0
- package/examples/jsm/loaders/usd/USDAParser.js +15 -2
- package/examples/jsm/loaders/usd/USDCParser.js +1 -4
- package/examples/jsm/loaders/usd/USDComposer.js +80 -42
- package/examples/jsm/materials/WoodNodeMaterial.js +6 -108
- package/examples/jsm/misc/RollerCoaster.js +2 -2
- package/examples/jsm/misc/SculptGL.LICENSE.txt +21 -0
- package/examples/jsm/misc/Sculptor.js +1679 -0
- package/examples/jsm/misc/SculptorMesh.js +1504 -0
- package/examples/jsm/misc/SculptorTools.js +1180 -0
- package/examples/jsm/misc/SculptorUtils.js +345 -0
- package/examples/jsm/misc/TubePainter.js +28 -16
- package/examples/jsm/misc/VolumeSlice.js +24 -24
- package/examples/jsm/modifiers/SimplifyModifier.js +63 -556
- package/examples/jsm/objects/GaussianSplat.js +1039 -0
- package/examples/jsm/objects/Sky.js +66 -45
- package/examples/jsm/objects/SkyMesh.js +70 -51
- package/examples/jsm/physics/JoltPhysics.js +1 -1
- package/examples/jsm/postprocessing/AfterimagePass.js +4 -2
- package/examples/jsm/postprocessing/BloomPass.js +2 -2
- package/examples/jsm/postprocessing/GTAOPass.js +1 -1
- package/examples/jsm/postprocessing/OutlinePass.js +5 -5
- package/examples/jsm/postprocessing/SAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSRPass.js +4 -2
- package/examples/jsm/postprocessing/SavePass.js +1 -1
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +30 -13
- package/examples/jsm/renderers/CSS2DRenderer.js +29 -5
- package/examples/jsm/shaders/DepthLimitedBlurShader.js +4 -1
- package/examples/jsm/shaders/ExposureShader.js +1 -1
- package/examples/jsm/shaders/FilmShader.js +2 -1
- package/examples/jsm/transpiler/AST.js +21 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +498 -8
- package/examples/jsm/transpiler/TSLEncoder.js +82 -10
- package/examples/jsm/transpiler/WGSLEncoder.js +33 -4
- package/examples/jsm/tsl/WebGLNodesHandler.js +29 -39
- package/examples/jsm/tsl/display/AfterImageNode.js +2 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +3 -2
- package/examples/jsm/tsl/display/BilateralBlurNode.js +5 -2
- package/examples/jsm/tsl/display/BloomNode.js +55 -30
- package/examples/jsm/tsl/display/DenoiseNode.js +21 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +24 -6
- package/examples/jsm/tsl/display/DotScreenNode.js +11 -11
- package/examples/jsm/tsl/display/FSR1Node.js +8 -4
- package/examples/jsm/tsl/display/GTAONode.js +199 -86
- package/examples/jsm/tsl/display/GaussianBlurNode.js +65 -52
- package/examples/jsm/tsl/display/GodraysNode.js +5 -2
- package/examples/jsm/tsl/display/ImportanceSampledEnvironment.js +2 -2
- package/examples/jsm/tsl/display/LensflareNode.js +5 -2
- package/examples/jsm/tsl/display/OITPassNode.js +352 -0
- package/examples/jsm/tsl/display/OutlineNode.js +2 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +3 -2
- package/examples/jsm/tsl/display/RGBShiftNode.js +9 -9
- package/examples/jsm/tsl/display/RecurrentDenoiseNode.js +7 -4
- package/examples/jsm/tsl/display/RetroPassNode.js +1 -1
- package/examples/jsm/tsl/display/SMAANode.js +22 -61
- package/examples/jsm/tsl/display/SSAAPassNode.js +2 -4
- package/examples/jsm/tsl/display/SSAONode.js +436 -0
- package/examples/jsm/tsl/display/SSGINode.js +5 -2
- package/examples/jsm/tsl/display/SSRNode.js +7 -2
- package/examples/jsm/tsl/display/SSSNode.js +5 -2
- package/examples/jsm/tsl/display/SharpenNode.js +5 -4
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +1 -3
- package/examples/jsm/tsl/display/StereoPassNode.js +1 -3
- package/examples/jsm/tsl/display/TAAUNode.js +22 -125
- package/examples/jsm/tsl/display/TRAANode.js +16 -142
- package/examples/jsm/tsl/display/TemporalReprojectNode.js +21 -15
- package/examples/jsm/tsl/display/depthAwareBlur.js +63 -0
- package/examples/jsm/tsl/display/hashBlur.js +3 -2
- package/examples/jsm/tsl/lighting/ClusteredLightsNode.js +38 -27
- package/examples/jsm/tsl/lighting/LightProbeGridNode.js +136 -0
- package/examples/jsm/tsl/math/voronoiNoise.js +112 -0
- package/examples/jsm/tsl/shadows/TileShadowNode.js +4 -6
- package/examples/jsm/tsl/utils/Raymarching.js +5 -5
- package/examples/jsm/tsl/utils/SoftParticles.js +60 -0
- package/examples/jsm/tsl/utils/TAAUtils.js +195 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +14 -14
- package/examples/jsm/utils/GaussianSplatUtils.js +229 -0
- package/examples/jsm/utils/WebGLTextureUtils.js +1 -1
- package/examples/jsm/utils/WebGPUTextureUtils.js +1 -1
- package/examples/jsm/webxr/WebGLXRFallback.js +2 -16
- package/examples/jsm/webxr/XRControllerModelFactory.js +16 -4
- package/package.json +9 -16
- package/src/Three.Core.js +2 -1
- package/src/Three.TSL.js +73 -43
- package/src/Three.WebGPU.Nodes.js +1 -0
- package/src/Three.WebGPU.js +1 -0
- package/src/animation/AnimationClip.js +15 -2
- package/src/animation/AnimationObjectGroup.js +18 -6
- package/src/animation/AnimationUtils.js +26 -0
- package/src/animation/KeyframeTrack.js +37 -0
- package/src/constants.js +23 -1
- package/src/core/BufferAttribute.js +3 -2
- package/src/core/BufferGeometry.js +1 -1
- package/src/core/InterleavedBuffer.js +5 -1
- package/src/core/Object3D.js +40 -12
- package/src/core/Raycaster.js +4 -0
- package/src/core/RenderTarget.js +99 -9
- package/src/core/RenderTarget3D.js +12 -8
- package/src/extras/Controls.js +0 -8
- package/src/extras/PMREMGenerator.js +99 -205
- package/src/geometries/TorusGeometry.js +1 -1
- package/src/helpers/ArrowHelper.js +2 -0
- package/src/helpers/AxesHelper.js +2 -0
- package/src/helpers/Box3Helper.js +2 -0
- package/src/helpers/BoxHelper.js +2 -0
- package/src/helpers/CameraHelper.js +2 -0
- package/src/helpers/DirectionalLightHelper.js +2 -0
- package/src/helpers/GridHelper.js +2 -0
- package/src/helpers/HemisphereLightHelper.js +2 -0
- package/src/helpers/PlaneHelper.js +2 -0
- package/src/helpers/PointLightHelper.js +2 -0
- package/src/helpers/PolarGridHelper.js +2 -0
- package/src/helpers/SkeletonHelper.js +2 -0
- package/src/helpers/SpotLightHelper.js +2 -0
- package/src/lights/Light.js +0 -10
- package/src/lights/LightShadow.js +43 -12
- package/src/lights/SpotLightShadow.js +18 -0
- package/src/loaders/BufferGeometryLoader.js +5 -0
- package/src/loaders/ImageBitmapLoader.js +3 -1
- package/src/loaders/ObjectLoader.js +8 -5
- package/src/materials/Material.js +80 -57
- package/src/materials/MeshPhysicalMaterial.js +32 -0
- package/src/materials/nodes/Line2NodeMaterial.js +17 -8
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +42 -5
- package/src/materials/nodes/NodeMaterial.js +19 -13
- package/src/materials/nodes/PointsNodeMaterial.js +2 -1
- package/src/materials/nodes/manager/NodeMaterialObserver.js +282 -55
- package/src/math/Frustum.js +9 -0
- package/src/math/FrustumArray.js +1 -1
- package/src/math/MathUtils.js +5 -3
- package/src/math/Matrix4.js +2 -9
- package/src/math/Plane.js +30 -1
- package/src/math/Quaternion.js +0 -10
- package/src/math/Ray.js +95 -45
- package/src/math/Triangle.js +0 -2
- package/src/math/Vector3.js +2 -2
- package/src/math/Vector4.js +0 -4
- package/src/math/interpolants/BezierInterpolant.js +36 -23
- package/src/nodes/Nodes.js +2 -0
- package/src/nodes/TSL.js +11 -3
- package/src/nodes/accessors/Batch.js +85 -13
- package/src/nodes/accessors/BufferAttributeNode.js +1 -1
- package/src/nodes/accessors/BuiltinNode.js +1 -1
- package/src/nodes/accessors/Instance.js +19 -18
- package/src/nodes/accessors/MaterialNode.js +9 -0
- package/src/nodes/accessors/ModelNode.js +85 -9
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -70
- package/src/nodes/accessors/ReferenceElementNode.js +72 -0
- package/src/nodes/accessors/ReferenceNode.js +1 -70
- package/src/nodes/accessors/Skinning.js +124 -12
- package/src/nodes/accessors/StorageTextureNode.js +7 -3
- package/src/nodes/accessors/Texture3DNode.js +1 -1
- package/src/nodes/accessors/TextureNode.js +51 -21
- package/src/nodes/accessors/TextureSizeNode.js +4 -2
- package/src/nodes/accessors/UniformArrayNode.js +30 -5
- package/src/nodes/code/CodeNode.js +1 -1
- package/src/nodes/code/FunctionNode.js +12 -2
- package/src/nodes/core/ArrayNode.js +2 -2
- package/src/nodes/core/ContextNode.js +57 -4
- package/src/nodes/core/IndexNode.js +69 -4
- package/src/nodes/core/InspectorNode.js +2 -2
- package/src/nodes/core/MRTNode.js +44 -2
- package/src/nodes/core/Node.js +6 -3
- package/src/nodes/core/NodeBuilder.js +65 -50
- package/src/nodes/core/NodeFrame.js +11 -3
- package/src/nodes/core/NodeUtils.js +88 -0
- package/src/nodes/core/PropertyNode.js +8 -0
- package/src/nodes/core/StackNode.js +0 -1
- package/src/nodes/core/StructNode.js +4 -3
- package/src/nodes/core/UniformGroupNode.js +3 -2
- package/src/nodes/core/UniformNode.js +26 -12
- package/src/nodes/core/VarNode.js +0 -1
- package/src/nodes/display/BumpMapNode.js +2 -2
- package/src/nodes/display/ColorAdjustment.js +1 -1
- package/src/nodes/display/PassNode.js +76 -15
- package/src/nodes/display/ScreenNode.js +22 -65
- package/src/nodes/fog/Fog.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_GGX.js +6 -6
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +1 -1
- package/src/nodes/functions/BSDF/DFGLUT.js +2 -1
- package/src/nodes/functions/BSDF/LTC.js +1 -1
- package/src/nodes/functions/PhongLightingModel.js +1 -1
- package/src/nodes/functions/PhysicalLightingModel.js +83 -25
- package/src/nodes/functions/ToonLightingModel.js +2 -2
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +3 -3
- package/src/nodes/gpgpu/AtomicFunctionNode.js +64 -13
- package/src/nodes/gpgpu/BarrierNode.js +13 -4
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +20 -17
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +165 -37
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +44 -6
- package/src/nodes/lighting/EnvironmentNode.js +40 -4
- package/src/nodes/lighting/LightsNode.js +20 -4
- package/src/nodes/lighting/ShadowBaseNode.js +158 -1
- package/src/nodes/lighting/ShadowFilterNode.js +2 -106
- package/src/nodes/lighting/ShadowNode.js +22 -91
- package/src/nodes/materialx/{lib/mx_hsv.js → MaterialXColor.js} +3 -6
- package/src/nodes/materialx/{lib/mx_transform_color.js → MaterialXColorTransform.js} +3 -6
- package/src/nodes/materialx/MaterialXCore.js +37 -0
- package/src/nodes/materialx/MaterialXNodes.js +64 -72
- package/src/nodes/materialx/{lib/mx_noise.js → MaterialXNoise.js} +426 -197
- package/src/nodes/math/BitcountNode.js +24 -4
- package/src/nodes/math/MathNode.js +4 -4
- package/src/nodes/math/MathUtils.js +15 -4
- package/src/nodes/math/OperatorNode.js +2 -2
- package/src/nodes/math/PackFloatNode.js +29 -1
- package/src/nodes/math/Packed4x8IntegerNode.js +433 -0
- package/src/nodes/math/UnpackFloatNode.js +30 -2
- package/src/nodes/parsers/GLSLNodeFunction.js +1 -1
- package/src/nodes/pmrem/PMREMNode.js +1 -1
- package/src/nodes/pmrem/PMREMUtils.js +31 -74
- package/src/nodes/shapes/Shapes.js +1 -1
- package/src/nodes/tsl/TSLCore.js +1 -31
- package/src/nodes/utils/EventNode.js +75 -0
- package/src/nodes/utils/LoopNode.js +54 -13
- package/src/nodes/utils/PostProcessingUtils.js +23 -2
- package/src/nodes/utils/RTTNode.js +97 -32
- package/src/nodes/utils/ReflectorNode.js +8 -4
- package/src/nodes/utils/RotateNode.js +85 -8
- package/src/nodes/utils/SpriteUtils.js +58 -23
- package/src/objects/BatchedMesh.js +6 -0
- package/src/objects/InstancedMesh.js +1 -1
- package/src/objects/LOD.js +1 -1
- package/src/objects/Line.js +12 -0
- package/src/objects/Mesh.js +12 -0
- package/src/objects/Points.js +12 -0
- package/src/objects/Sprite.js +12 -0
- package/src/renderers/WebGLRenderer.js +93 -27
- package/src/renderers/common/Animation.js +12 -2
- package/src/renderers/common/Backend.js +38 -10
- package/src/renderers/common/BindGroup.js +0 -1
- package/src/renderers/common/Bindings.js +50 -4
- package/src/renderers/common/BundleGroup.js +4 -0
- package/src/renderers/common/ClippingContext.js +11 -1
- package/src/renderers/common/Color4.js +9 -0
- package/src/renderers/common/Constants.js +0 -5
- package/src/renderers/common/DirectRenderPipeline.js +233 -0
- package/src/renderers/common/Geometries.js +24 -3
- package/src/renderers/common/Info.js +3 -3
- package/src/renderers/common/InspectorBase.js +37 -8
- package/src/renderers/common/Lighting.js +11 -4
- package/src/renderers/common/Pipelines.js +6 -4
- package/src/renderers/common/QuadMesh.js +16 -2
- package/src/renderers/common/RenderContext.js +8 -0
- package/src/renderers/common/RenderList.js +53 -19
- package/src/renderers/common/RenderLists.js +58 -11
- package/src/renderers/common/RenderObject.js +14 -0
- package/src/renderers/common/RenderObjects.js +14 -9
- package/src/renderers/common/RenderPipeline.js +52 -44
- package/src/renderers/common/Renderer.js +226 -55
- package/src/renderers/common/Storage3DTexture.js +16 -0
- package/src/renderers/common/Textures.js +3 -3
- package/src/renderers/common/XRManager.js +79 -72
- package/src/renderers/common/extras/PMREMGenerator.js +76 -144
- package/src/renderers/common/nodes/NodeManager.js +144 -6
- package/src/renderers/common/nodes/NodeStorageBuffer.js +3 -1
- package/src/renderers/common/nodes/NodeUniformBuffer.js +3 -1
- package/src/renderers/shaders/DFGLUTData.js +2 -1
- package/src/renderers/shaders/ShaderChunk/defaultnormal_vertex.glsl.js +4 -2
- package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +48 -0
- package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +53 -4
- package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +20 -2
- package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +20 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +61 -57
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +82 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_vertex.glsl.js +9 -0
- package/src/renderers/shaders/ShaderChunk/shadowmap_vertex.glsl.js +8 -1
- package/src/renderers/shaders/ShaderChunk/shadowmask_pars_fragment.glsl.js +15 -0
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -0
- package/src/renderers/shaders/ShaderLib.js +1 -0
- package/src/renderers/shaders/UniformsLib.js +16 -0
- package/src/renderers/webgl/WebGLAnimation.js +2 -2
- package/src/renderers/webgl/WebGLCapabilities.js +2 -2
- package/src/renderers/webgl/WebGLLights.js +74 -4
- package/src/renderers/webgl/WebGLMaterials.js +6 -0
- package/src/renderers/webgl/WebGLOutput.js +36 -24
- package/src/renderers/webgl/WebGLProgram.js +3 -0
- package/src/renderers/webgl/WebGLPrograms.js +8 -0
- package/src/renderers/webgl/WebGLRenderLists.js +6 -10
- package/src/renderers/webgl/WebGLShadowMap.js +47 -44
- package/src/renderers/webgl/WebGLTextures.js +7 -7
- package/src/renderers/webgl-fallback/WebGLBackend.js +153 -45
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +83 -29
- package/src/renderers/webgl-fallback/utils/WebGLState.js +163 -17
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +32 -5
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +11 -4
- package/src/renderers/webgpu/WebGPUBackend.js +513 -145
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +99 -20
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +2 -1
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +3 -12
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +24 -14
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +80 -14
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +62 -7
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +9 -3
- package/src/renderers/webgpu/utils/WebGPUUtils.js +16 -4
- package/src/renderers/webxr/WebXRManager.js +25 -2
- package/src/scenes/Scene.js +3 -3
- package/src/textures/CompressedArrayTexture.js +16 -0
- package/src/textures/Data3DTexture.js +16 -0
- package/src/textures/DataArrayTexture.js +16 -0
- package/src/textures/DepthTexture.js +3 -3
- package/src/textures/Texture.js +3 -3
- package/src/textures/{Source.js → TextureSource.js} +39 -8
- package/build/three.core.min.js +0 -6
- package/build/three.module.min.js +0 -6
- package/build/three.tsl.min.js +0 -6
- package/build/three.webgpu.min.js +0 -6
- package/build/three.webgpu.nodes.min.js +0 -6
- package/examples/jsm/libs/ecsy.module.js +0 -1792
- package/examples/jsm/loaders/LottieLoader.js +0 -130
- package/src/nodes/functions/BSDF/BRDF_GGX_Multiscatter.js +0 -52
|
@@ -0,0 +1,878 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Texture,
|
|
3
|
+
RepeatWrapping,
|
|
4
|
+
ClampToEdgeWrapping,
|
|
5
|
+
MirroredRepeatWrapping,
|
|
6
|
+
ImageLoader,
|
|
7
|
+
ImageBitmapLoader,
|
|
8
|
+
Matrix3,
|
|
9
|
+
Matrix4,
|
|
10
|
+
MeshBasicNodeMaterial,
|
|
11
|
+
MeshPhysicalNodeMaterial,
|
|
12
|
+
} from '@gnsx/three/webgpu';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
float,
|
|
16
|
+
int,
|
|
17
|
+
bool,
|
|
18
|
+
sub,
|
|
19
|
+
vec2,
|
|
20
|
+
vec3,
|
|
21
|
+
vec4,
|
|
22
|
+
color,
|
|
23
|
+
uv,
|
|
24
|
+
mat3,
|
|
25
|
+
mat4,
|
|
26
|
+
element,
|
|
27
|
+
mx_transform_uv,
|
|
28
|
+
mx_srgb_texture_to_lin_rec709,
|
|
29
|
+
} from '@gnsx/three/tsl';
|
|
30
|
+
|
|
31
|
+
import { MaterialXLogCodes } from './MaterialXLog.js';
|
|
32
|
+
import { createMaterialXCompileRegistry, compileNodeFromRegistry } from './compile/MaterialXCompileRegistry.js';
|
|
33
|
+
import { parseMaterialXNodeTree, parseMaterialXText } from './parse/MaterialXParser.js';
|
|
34
|
+
import { getSurfaceMapper } from './MaterialXSurfaceMappings.js';
|
|
35
|
+
import { MtlXLibrary } from './MaterialXNodeLibrary.js';
|
|
36
|
+
import { mxHextileCoord, mxHextileComputeBlendWeights } from './MaterialXHextile.js';
|
|
37
|
+
import { toBooleanNode } from './MaterialXUtils.js';
|
|
38
|
+
|
|
39
|
+
const colorSpaceLib = {
|
|
40
|
+
mx_srgb_texture_to_lin_rec709,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const DEFAULT_DOCUMENT_COLOR_SPACE = 'lin_rec709';
|
|
44
|
+
const IDENTITY_MAT3_VALUES = [ 1, 0, 0, 0, 1, 0, 0, 0, 1 ];
|
|
45
|
+
const IDENTITY_MAT4_VALUES = [ 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 ];
|
|
46
|
+
const MATRIX_INVERSE_EPSILON = 1e-8;
|
|
47
|
+
const COMPILE_REGISTRY = createMaterialXCompileRegistry();
|
|
48
|
+
const TEXTURE_ADDRESS_MODE_WRAPPING = {
|
|
49
|
+
constant: ClampToEdgeWrapping,
|
|
50
|
+
clamp: ClampToEdgeWrapping,
|
|
51
|
+
periodic: RepeatWrapping,
|
|
52
|
+
mirror: MirroredRepeatWrapping,
|
|
53
|
+
};
|
|
54
|
+
const NODE_CLASS_BY_TYPE = {
|
|
55
|
+
integer: int,
|
|
56
|
+
float,
|
|
57
|
+
vector2: vec2,
|
|
58
|
+
vector3: vec3,
|
|
59
|
+
vector4: vec4,
|
|
60
|
+
color4: vec4,
|
|
61
|
+
color3: color,
|
|
62
|
+
boolean: null,
|
|
63
|
+
matrix33: mat3,
|
|
64
|
+
matrix44: mat4,
|
|
65
|
+
};
|
|
66
|
+
const OUTPUT_CHANNELS = {
|
|
67
|
+
outx: 0,
|
|
68
|
+
outr: 0,
|
|
69
|
+
outy: 1,
|
|
70
|
+
outg: 1,
|
|
71
|
+
outz: 2,
|
|
72
|
+
outb: 2,
|
|
73
|
+
outw: 3,
|
|
74
|
+
outa: 3,
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
function mxFlipUvY( uvNode ) {
|
|
78
|
+
|
|
79
|
+
return vec2( element( uvNode, 0 ), sub( 1, element( uvNode, 1 ) ) );
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function mxIdentityUv( uvNode ) {
|
|
84
|
+
|
|
85
|
+
return uvNode;
|
|
86
|
+
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
function getBottomLeftUvSpaceHelpers( uvSpace ) {
|
|
90
|
+
|
|
91
|
+
const helper = uvSpace === 'top-left' ? mxFlipUvY : mxIdentityUv;
|
|
92
|
+
return {
|
|
93
|
+
mxToBottomLeftUvSpace: helper,
|
|
94
|
+
mxFromBottomLeftUvSpace: helper,
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function normalizeUvSpace( uvSpace ) {
|
|
100
|
+
|
|
101
|
+
if ( uvSpace === undefined || uvSpace === null ) return 'bottom-left';
|
|
102
|
+
if ( uvSpace === 'bottom-left' || uvSpace === 'top-left' ) return uvSpace;
|
|
103
|
+
throw new Error( `Unsupported MaterialX uvSpace "${uvSpace}". Expected "bottom-left" or "top-left".` );
|
|
104
|
+
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function isSvgUri( uri ) {
|
|
108
|
+
|
|
109
|
+
if ( typeof uri !== 'string' ) return false;
|
|
110
|
+
return /\.svg(?:$|[?#])/i.test( uri );
|
|
111
|
+
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
function normalizeTextureAddressMode( value ) {
|
|
115
|
+
|
|
116
|
+
if ( value === null || value === undefined || value === '' ) return 'periodic';
|
|
117
|
+
|
|
118
|
+
const mode = value.trim().toLowerCase();
|
|
119
|
+
return mode in TEXTURE_ADDRESS_MODE_WRAPPING ? mode : null;
|
|
120
|
+
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function invertConstantMatrixValues( values, size ) {
|
|
124
|
+
|
|
125
|
+
if ( ! Array.isArray( values ) || values.length !== size * size ) return null;
|
|
126
|
+
|
|
127
|
+
if ( size === 3 ) {
|
|
128
|
+
|
|
129
|
+
const matrix = new Matrix3().setFromArray( values );
|
|
130
|
+
if ( Math.abs( matrix.determinant() ) < MATRIX_INVERSE_EPSILON ) return null;
|
|
131
|
+
matrix.invert();
|
|
132
|
+
// Convert Three.js internal column-major storage back to row-major literal order.
|
|
133
|
+
return matrix.transpose().elements;
|
|
134
|
+
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
if ( size === 4 ) {
|
|
138
|
+
|
|
139
|
+
const matrix = new Matrix4().setFromArray( values );
|
|
140
|
+
if ( Math.abs( matrix.determinant() ) < MATRIX_INVERSE_EPSILON ) return null;
|
|
141
|
+
matrix.invert();
|
|
142
|
+
// Convert Three.js internal column-major storage back to row-major literal order.
|
|
143
|
+
return matrix.transpose().elements;
|
|
144
|
+
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
return null;
|
|
148
|
+
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
function getOutputChannel( outputName ) {
|
|
152
|
+
|
|
153
|
+
return OUTPUT_CHANNELS[ outputName ] || 0;
|
|
154
|
+
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function isChannelOutput( outputName ) {
|
|
158
|
+
|
|
159
|
+
return outputName in OUTPUT_CHANNELS;
|
|
160
|
+
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
class MaterialXNode {
|
|
164
|
+
|
|
165
|
+
constructor( materialX, nodeXML, nodePath = '' ) {
|
|
166
|
+
|
|
167
|
+
this.materialX = materialX;
|
|
168
|
+
this.nodeXML = nodeXML;
|
|
169
|
+
this.nodePath = nodePath ? nodePath + '/' + this.name : this.name;
|
|
170
|
+
this.parent = null;
|
|
171
|
+
this.node = null;
|
|
172
|
+
this.children = [];
|
|
173
|
+
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
get element() {
|
|
177
|
+
|
|
178
|
+
return this.nodeXML.nodeName;
|
|
179
|
+
|
|
180
|
+
}
|
|
181
|
+
get nodeGraph() {
|
|
182
|
+
|
|
183
|
+
return this.getAttribute( 'nodegraph' );
|
|
184
|
+
|
|
185
|
+
}
|
|
186
|
+
get nodeName() {
|
|
187
|
+
|
|
188
|
+
return this.getAttribute( 'nodename' );
|
|
189
|
+
|
|
190
|
+
}
|
|
191
|
+
get interfaceName() {
|
|
192
|
+
|
|
193
|
+
return this.getAttribute( 'interfacename' );
|
|
194
|
+
|
|
195
|
+
}
|
|
196
|
+
get output() {
|
|
197
|
+
|
|
198
|
+
return this.getAttribute( 'output' );
|
|
199
|
+
|
|
200
|
+
}
|
|
201
|
+
get name() {
|
|
202
|
+
|
|
203
|
+
return this.getAttribute( 'name' );
|
|
204
|
+
|
|
205
|
+
}
|
|
206
|
+
get type() {
|
|
207
|
+
|
|
208
|
+
return this.getAttribute( 'type' );
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
get value() {
|
|
212
|
+
|
|
213
|
+
return this.getAttribute( 'value' );
|
|
214
|
+
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
getNodeGraph() {
|
|
218
|
+
|
|
219
|
+
let nodeX = this;
|
|
220
|
+
while ( nodeX !== null ) {
|
|
221
|
+
|
|
222
|
+
if ( nodeX.element === 'nodegraph' ) break;
|
|
223
|
+
nodeX = nodeX.parent;
|
|
224
|
+
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return nodeX;
|
|
228
|
+
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
getRoot() {
|
|
232
|
+
|
|
233
|
+
let nodeX = this;
|
|
234
|
+
while ( nodeX.parent !== null ) {
|
|
235
|
+
|
|
236
|
+
nodeX = nodeX.parent;
|
|
237
|
+
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
return nodeX;
|
|
241
|
+
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
get referencePath() {
|
|
245
|
+
|
|
246
|
+
let referencePath = null;
|
|
247
|
+
if ( this.nodeGraph !== null && this.output !== null ) {
|
|
248
|
+
|
|
249
|
+
referencePath = this.nodeGraph + '/' + this.output;
|
|
250
|
+
|
|
251
|
+
} else if ( this.nodeName !== null || this.interfaceName !== null ) {
|
|
252
|
+
|
|
253
|
+
const graphNode = this.getNodeGraph();
|
|
254
|
+
const scopedReference = this.nodeName || this.interfaceName;
|
|
255
|
+
if ( graphNode && scopedReference ) {
|
|
256
|
+
|
|
257
|
+
referencePath = graphNode.nodePath + '/' + scopedReference;
|
|
258
|
+
|
|
259
|
+
} else if ( this.nodeName !== null ) {
|
|
260
|
+
|
|
261
|
+
// Surface-level nodename links can legitimately target top-level siblings.
|
|
262
|
+
referencePath = this.nodeName;
|
|
263
|
+
|
|
264
|
+
}
|
|
265
|
+
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
return referencePath;
|
|
269
|
+
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
get hasReference() {
|
|
273
|
+
|
|
274
|
+
return this.referencePath !== null;
|
|
275
|
+
|
|
276
|
+
}
|
|
277
|
+
get isConst() {
|
|
278
|
+
|
|
279
|
+
return this.element === 'input' && this.value !== null && this.type !== 'filename';
|
|
280
|
+
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
getColorSpaceNode() {
|
|
284
|
+
|
|
285
|
+
const csSource = this.getAttribute( 'colorspace' );
|
|
286
|
+
const csTarget = this.getRoot().getAttribute( 'colorspace' );
|
|
287
|
+
if ( ! csSource || ! csTarget ) return null;
|
|
288
|
+
const nodeName = `mx_${csSource}_to_${csTarget}`;
|
|
289
|
+
return colorSpaceLib[ nodeName ] || null;
|
|
290
|
+
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
getTextureAddressMode( inputName ) {
|
|
294
|
+
|
|
295
|
+
const rawMode = this.getInputValueByName( inputName );
|
|
296
|
+
const mode = normalizeTextureAddressMode( rawMode );
|
|
297
|
+
if ( mode ) return mode;
|
|
298
|
+
|
|
299
|
+
this.materialX.log.add(
|
|
300
|
+
MaterialXLogCodes.INVALID_VALUE,
|
|
301
|
+
`Unsupported texture address mode "${rawMode}" on input "${inputName}". Expected constant, clamp, periodic, or mirror.`,
|
|
302
|
+
this.name,
|
|
303
|
+
);
|
|
304
|
+
return 'periodic';
|
|
305
|
+
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
getTextureAddressModes() {
|
|
309
|
+
|
|
310
|
+
return {
|
|
311
|
+
u: this.getTextureAddressMode( 'uaddressmode' ),
|
|
312
|
+
v: this.getTextureAddressMode( 'vaddressmode' ),
|
|
313
|
+
};
|
|
314
|
+
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
getTexture() {
|
|
318
|
+
|
|
319
|
+
const filePrefix = this.getRecursiveAttribute( 'fileprefix' ) || '';
|
|
320
|
+
const sourceURI = filePrefix + this.value;
|
|
321
|
+
const resolvedURI = this.materialX.resolveTextureURI( sourceURI );
|
|
322
|
+
const svgTexture = isSvgUri( resolvedURI );
|
|
323
|
+
const textureSourceNode = this.parent && typeof this.parent.getTextureAddressModes === 'function' ? this.parent : this;
|
|
324
|
+
const addressModes = textureSourceNode.getTextureAddressModes();
|
|
325
|
+
const textureCacheKey = `${resolvedURI}|${addressModes.u}|${addressModes.v}`;
|
|
326
|
+
|
|
327
|
+
if ( this.materialX.textureCache.has( textureCacheKey ) ) {
|
|
328
|
+
|
|
329
|
+
return this.materialX.textureCache.get( textureCacheKey );
|
|
330
|
+
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
let loader = svgTexture ? this.materialX.imageLoader : this.materialX.textureLoader;
|
|
334
|
+
if ( resolvedURI && ! svgTexture ) {
|
|
335
|
+
|
|
336
|
+
const handler = this.materialX.manager.getHandler( resolvedURI );
|
|
337
|
+
if ( handler !== null ) loader = handler;
|
|
338
|
+
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
const textureNode = new Texture();
|
|
342
|
+
textureNode.wrapS = TEXTURE_ADDRESS_MODE_WRAPPING[ addressModes.u ];
|
|
343
|
+
textureNode.wrapT = TEXTURE_ADDRESS_MODE_WRAPPING[ addressModes.v ];
|
|
344
|
+
textureNode.flipY = false;
|
|
345
|
+
this.materialX.textureCache.set( textureCacheKey, textureNode );
|
|
346
|
+
|
|
347
|
+
loader.load( resolvedURI, ( imageData ) => {
|
|
348
|
+
|
|
349
|
+
textureNode.image = imageData;
|
|
350
|
+
textureNode.needsUpdate = true;
|
|
351
|
+
|
|
352
|
+
}, undefined, () => {
|
|
353
|
+
|
|
354
|
+
throw new Error( `Failed to load texture "${resolvedURI}".` );
|
|
355
|
+
|
|
356
|
+
} );
|
|
357
|
+
|
|
358
|
+
return textureNode;
|
|
359
|
+
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
getClassFromType( type ) {
|
|
363
|
+
|
|
364
|
+
return NODE_CLASS_BY_TYPE[ type ] || null;
|
|
365
|
+
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
toBooleanNode( node ) {
|
|
369
|
+
|
|
370
|
+
return toBooleanNode( node );
|
|
371
|
+
|
|
372
|
+
}
|
|
373
|
+
|
|
374
|
+
getNode( out = null ) {
|
|
375
|
+
|
|
376
|
+
if ( this.node !== null && out === null ) return this.node;
|
|
377
|
+
|
|
378
|
+
let node;
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
if ( ( this.element === 'separate2' || this.element === 'separate3' || this.element === 'separate4' ) && out ) {
|
|
382
|
+
|
|
383
|
+
const inNode = this.getNodeByName( 'in' );
|
|
384
|
+
return element( inNode, getOutputChannel( out ) );
|
|
385
|
+
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
const type = this.type;
|
|
389
|
+
const channelRequested = this.element !== 'input' && this.element !== 'gltf_colorimage' && isChannelOutput( out );
|
|
390
|
+
|
|
391
|
+
if ( this.isConst ) {
|
|
392
|
+
|
|
393
|
+
if ( type === 'boolean' ) {
|
|
394
|
+
|
|
395
|
+
const normalized = this.getValue().trim().toLowerCase();
|
|
396
|
+
node = bool( normalized === 'true' || normalized === '1' );
|
|
397
|
+
|
|
398
|
+
} else if ( type === 'matrix33' ) {
|
|
399
|
+
|
|
400
|
+
node = this.getMatrix( 3 ) || mat3( 1, 0, 0, 0, 1, 0, 0, 0, 1 );
|
|
401
|
+
|
|
402
|
+
} else if ( type === 'matrix44' ) {
|
|
403
|
+
|
|
404
|
+
node = this.getMatrix( 4 ) || mat4( 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1 );
|
|
405
|
+
|
|
406
|
+
} else if ( type === 'string' ) {
|
|
407
|
+
|
|
408
|
+
node = this.getValue();
|
|
409
|
+
|
|
410
|
+
} else {
|
|
411
|
+
|
|
412
|
+
const nodeClass = this.getClassFromType( type );
|
|
413
|
+
node = nodeClass ? nodeClass( ...this.getVector() ) : float( 0 );
|
|
414
|
+
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
} else if ( this.hasReference ) {
|
|
418
|
+
|
|
419
|
+
if ( this.element === 'output' && this.output && out === null ) out = this.output;
|
|
420
|
+
let requestedOutput = out;
|
|
421
|
+
// For nodegraph references, this input's `output` attribute selects the graph output
|
|
422
|
+
// itself and should not be forwarded as an output selector on the resolved node.
|
|
423
|
+
if ( this.element === 'input' && this.nodeGraph !== null && this.output !== null ) {
|
|
424
|
+
|
|
425
|
+
requestedOutput = null;
|
|
426
|
+
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
const referenceNode = this.materialX.getMaterialXNode( this.referencePath );
|
|
430
|
+
|
|
431
|
+
if ( referenceNode ) {
|
|
432
|
+
|
|
433
|
+
node = referenceNode.getNode( requestedOutput );
|
|
434
|
+
|
|
435
|
+
} else {
|
|
436
|
+
|
|
437
|
+
this.materialX.log.add(
|
|
438
|
+
MaterialXLogCodes.MISSING_REFERENCE,
|
|
439
|
+
`Missing MaterialX reference "${this.referencePath}" from "${this.name}".`,
|
|
440
|
+
this.name,
|
|
441
|
+
);
|
|
442
|
+
node = float( 0 );
|
|
443
|
+
|
|
444
|
+
}
|
|
445
|
+
|
|
446
|
+
} else if ( this.element === 'input' && this.name === 'texcoord' && this.type === 'vector2' ) {
|
|
447
|
+
|
|
448
|
+
let index = 0;
|
|
449
|
+
const defaultGeomProp = this.getAttribute( 'defaultgeomprop' );
|
|
450
|
+
if ( defaultGeomProp && /^UV(\d+)$/.test( defaultGeomProp ) ) {
|
|
451
|
+
|
|
452
|
+
index = parseInt( defaultGeomProp.match( /^UV(\d+)$/ )[ 1 ], 10 );
|
|
453
|
+
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
node = this.materialX.compileContext.mxToBottomLeftUvSpace( uv( index ) );
|
|
457
|
+
|
|
458
|
+
} else {
|
|
459
|
+
|
|
460
|
+
node = compileNodeFromRegistry( this, out, this.materialX.compileContext );
|
|
461
|
+
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if ( node === null || node === undefined ) {
|
|
465
|
+
|
|
466
|
+
this.materialX.log.add(
|
|
467
|
+
MaterialXLogCodes.UNSUPPORTED_NODE,
|
|
468
|
+
`Unsupported MaterialX node category "${this.element}" on "${this.name}".`,
|
|
469
|
+
this.name,
|
|
470
|
+
);
|
|
471
|
+
node = float( 0 );
|
|
472
|
+
|
|
473
|
+
}
|
|
474
|
+
|
|
475
|
+
if ( channelRequested ) {
|
|
476
|
+
|
|
477
|
+
node = element( node, getOutputChannel( out ) );
|
|
478
|
+
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
const resolvedType = channelRequested ? 'float' : type;
|
|
482
|
+
if ( resolvedType === 'boolean' ) {
|
|
483
|
+
|
|
484
|
+
node = this.toBooleanNode( node );
|
|
485
|
+
|
|
486
|
+
} else if ( resolvedType === 'string' ) {
|
|
487
|
+
|
|
488
|
+
// String-typed inputs (for example transform* fromspace/tospace) are
|
|
489
|
+
// valid scalar parameters and should pass through without numeric casting.
|
|
490
|
+
node = typeof node === 'string' ? node : this.getValue();
|
|
491
|
+
|
|
492
|
+
} else {
|
|
493
|
+
|
|
494
|
+
const nodeToTypeClass = this.getClassFromType( resolvedType );
|
|
495
|
+
if ( nodeToTypeClass !== null ) {
|
|
496
|
+
|
|
497
|
+
node = nodeToTypeClass( node );
|
|
498
|
+
|
|
499
|
+
} else if ( resolvedType !== null && resolvedType !== undefined && resolvedType !== 'multioutput' ) {
|
|
500
|
+
|
|
501
|
+
this.materialX.log.add(
|
|
502
|
+
MaterialXLogCodes.INVALID_VALUE,
|
|
503
|
+
`Unexpected type "${resolvedType}" on node "${this.name}".`,
|
|
504
|
+
this.name,
|
|
505
|
+
);
|
|
506
|
+
node = float( 0 );
|
|
507
|
+
|
|
508
|
+
}
|
|
509
|
+
|
|
510
|
+
}
|
|
511
|
+
|
|
512
|
+
if ( node && typeof node === 'object' ) {
|
|
513
|
+
|
|
514
|
+
node.name = this.name;
|
|
515
|
+
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
this.node = node;
|
|
519
|
+
return node;
|
|
520
|
+
|
|
521
|
+
}
|
|
522
|
+
|
|
523
|
+
getChildByName( name ) {
|
|
524
|
+
|
|
525
|
+
for ( const input of this.children ) {
|
|
526
|
+
|
|
527
|
+
if ( input.name === name ) return input;
|
|
528
|
+
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
}
|
|
532
|
+
|
|
533
|
+
getNodes() {
|
|
534
|
+
|
|
535
|
+
const nodes = {};
|
|
536
|
+
for ( const input of this.children ) {
|
|
537
|
+
|
|
538
|
+
const value = input.getNode( input.output );
|
|
539
|
+
nodes[ input.name ] = value;
|
|
540
|
+
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
return nodes;
|
|
544
|
+
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
getNodeByName( name ) {
|
|
548
|
+
|
|
549
|
+
const child = this.getChildByName( name );
|
|
550
|
+
return child ? child.getNode( child.output ) : undefined;
|
|
551
|
+
|
|
552
|
+
}
|
|
553
|
+
|
|
554
|
+
getInputValueByName( name ) {
|
|
555
|
+
|
|
556
|
+
const child = this.getChildByName( name );
|
|
557
|
+
return child ? child.value : null;
|
|
558
|
+
|
|
559
|
+
}
|
|
560
|
+
|
|
561
|
+
getNodesByNames( ...names ) {
|
|
562
|
+
|
|
563
|
+
const nodes = [];
|
|
564
|
+
for ( const name of names ) {
|
|
565
|
+
|
|
566
|
+
const nodeValue = this.getNodeByName( name );
|
|
567
|
+
nodes.push( nodeValue );
|
|
568
|
+
|
|
569
|
+
}
|
|
570
|
+
|
|
571
|
+
return nodes;
|
|
572
|
+
|
|
573
|
+
}
|
|
574
|
+
|
|
575
|
+
getValue() {
|
|
576
|
+
|
|
577
|
+
return this.value ? this.value.trim() : '';
|
|
578
|
+
|
|
579
|
+
}
|
|
580
|
+
|
|
581
|
+
getVector() {
|
|
582
|
+
|
|
583
|
+
const vector = [];
|
|
584
|
+
for ( const val of this.getValue().split( /[,|\s]/ ) ) {
|
|
585
|
+
|
|
586
|
+
if ( val !== '' ) vector.push( Number( val.trim() ) );
|
|
587
|
+
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
return vector;
|
|
591
|
+
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
getMatrix( size ) {
|
|
595
|
+
|
|
596
|
+
const vector = this.getVector();
|
|
597
|
+
const expectedLength = size * size;
|
|
598
|
+
if ( vector.length !== expectedLength ) return null;
|
|
599
|
+
// MaterialX matrix values are serialized in column-major order.
|
|
600
|
+
// Reorder to row-major before constructing TSL matrix nodes so
|
|
601
|
+
// transformmatrix semantics match MaterialXJS and MaterialXView.
|
|
602
|
+
const reordered = [];
|
|
603
|
+
for ( let row = 0; row < size; row += 1 ) {
|
|
604
|
+
|
|
605
|
+
for ( let column = 0; column < size; column += 1 ) {
|
|
606
|
+
|
|
607
|
+
reordered.push( vector[ column * size + row ] );
|
|
608
|
+
|
|
609
|
+
}
|
|
610
|
+
|
|
611
|
+
}
|
|
612
|
+
|
|
613
|
+
return size === 3 ? mat3( ...reordered ) : mat4( ...reordered );
|
|
614
|
+
|
|
615
|
+
}
|
|
616
|
+
|
|
617
|
+
getAttribute( name ) {
|
|
618
|
+
|
|
619
|
+
const value = this.nodeXML.getAttribute( name );
|
|
620
|
+
if ( value === null && this.element === 'materialx' && name === 'colorspace' ) {
|
|
621
|
+
|
|
622
|
+
return DEFAULT_DOCUMENT_COLOR_SPACE;
|
|
623
|
+
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
return value;
|
|
627
|
+
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
getRecursiveAttribute( name ) {
|
|
631
|
+
|
|
632
|
+
let attribute = this.nodeXML.getAttribute( name );
|
|
633
|
+
if ( attribute === null && this.parent !== null ) {
|
|
634
|
+
|
|
635
|
+
attribute = this.parent.getRecursiveAttribute( name );
|
|
636
|
+
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
return attribute;
|
|
640
|
+
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
setMaterial( material ) {
|
|
644
|
+
|
|
645
|
+
const mapper = getSurfaceMapper( this.element );
|
|
646
|
+
if ( mapper ) {
|
|
647
|
+
|
|
648
|
+
mapper.apply( material, this.getNodes(), this.materialX.log, this.name );
|
|
649
|
+
|
|
650
|
+
} else {
|
|
651
|
+
|
|
652
|
+
this.materialX.log.add(
|
|
653
|
+
MaterialXLogCodes.UNSUPPORTED_NODE,
|
|
654
|
+
`Unsupported MaterialX node category "${this.element}" on "${this.name}".`,
|
|
655
|
+
this.name,
|
|
656
|
+
);
|
|
657
|
+
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
}
|
|
661
|
+
|
|
662
|
+
toBasicMaterial() {
|
|
663
|
+
|
|
664
|
+
const material = new MeshBasicNodeMaterial();
|
|
665
|
+
material.name = this.name;
|
|
666
|
+
|
|
667
|
+
for ( const nodeX of this.children.toReversed() ) {
|
|
668
|
+
|
|
669
|
+
if ( nodeX.name === 'out' ) {
|
|
670
|
+
|
|
671
|
+
material.colorNode = nodeX.getNode();
|
|
672
|
+
break;
|
|
673
|
+
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
return material;
|
|
679
|
+
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
resolveSurfaceShaderNode( nodeX ) {
|
|
683
|
+
|
|
684
|
+
if ( nodeX.hasReference ) {
|
|
685
|
+
|
|
686
|
+
return this.materialX.getMaterialXNode( nodeX.referencePath ) || null;
|
|
687
|
+
|
|
688
|
+
}
|
|
689
|
+
|
|
690
|
+
if ( nodeX.nodeName ) {
|
|
691
|
+
|
|
692
|
+
return this.materialX.getMaterialXNode( nodeX.nodeName ) || null;
|
|
693
|
+
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
return null;
|
|
697
|
+
|
|
698
|
+
}
|
|
699
|
+
|
|
700
|
+
toPhysicalMaterial() {
|
|
701
|
+
|
|
702
|
+
const material = new MeshPhysicalNodeMaterial();
|
|
703
|
+
material.name = this.name;
|
|
704
|
+
|
|
705
|
+
for ( const nodeX of this.children ) {
|
|
706
|
+
|
|
707
|
+
const shaderProperties = this.resolveSurfaceShaderNode( nodeX );
|
|
708
|
+
if ( shaderProperties === null ) {
|
|
709
|
+
|
|
710
|
+
this.materialX.log.add(
|
|
711
|
+
MaterialXLogCodes.MISSING_REFERENCE,
|
|
712
|
+
`Missing MaterialX reference "${nodeX.referencePath || nodeX.nodeName || '(unknown)'}" from "${nodeX.name}".`,
|
|
713
|
+
nodeX.name,
|
|
714
|
+
);
|
|
715
|
+
continue;
|
|
716
|
+
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
shaderProperties.setMaterial( material );
|
|
720
|
+
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
return material;
|
|
724
|
+
|
|
725
|
+
}
|
|
726
|
+
|
|
727
|
+
toMaterials( materialName = null ) {
|
|
728
|
+
|
|
729
|
+
const materials = {};
|
|
730
|
+
const surfaceMaterials = this.children.filter( ( nodeX ) => nodeX.element === 'surfacematerial' );
|
|
731
|
+
|
|
732
|
+
let selectedSurfaceMaterials = surfaceMaterials;
|
|
733
|
+
if ( materialName ) {
|
|
734
|
+
|
|
735
|
+
selectedSurfaceMaterials = surfaceMaterials.filter( ( nodeX ) => nodeX.name === materialName );
|
|
736
|
+
|
|
737
|
+
if ( selectedSurfaceMaterials.length === 0 ) {
|
|
738
|
+
|
|
739
|
+
this.materialX.log.add(
|
|
740
|
+
MaterialXLogCodes.MISSING_MATERIAL,
|
|
741
|
+
`Could not find surfacematerial named "${materialName}".`,
|
|
742
|
+
);
|
|
743
|
+
|
|
744
|
+
}
|
|
745
|
+
|
|
746
|
+
}
|
|
747
|
+
|
|
748
|
+
for ( const nodeX of selectedSurfaceMaterials ) {
|
|
749
|
+
|
|
750
|
+
const material = nodeX.toPhysicalMaterial();
|
|
751
|
+
materials[ material.name ] = material;
|
|
752
|
+
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
if ( Object.keys( materials ).length === 0 ) {
|
|
756
|
+
|
|
757
|
+
for ( const nodeX of this.children ) {
|
|
758
|
+
|
|
759
|
+
if ( nodeX.element === 'nodegraph' ) {
|
|
760
|
+
|
|
761
|
+
const material = nodeX.toBasicMaterial();
|
|
762
|
+
materials[ material.name ] = material;
|
|
763
|
+
|
|
764
|
+
}
|
|
765
|
+
|
|
766
|
+
}
|
|
767
|
+
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
return materials;
|
|
771
|
+
|
|
772
|
+
}
|
|
773
|
+
|
|
774
|
+
add( materialXNode ) {
|
|
775
|
+
|
|
776
|
+
materialXNode.parent = this;
|
|
777
|
+
this.children.push( materialXNode );
|
|
778
|
+
|
|
779
|
+
}
|
|
780
|
+
|
|
781
|
+
}
|
|
782
|
+
|
|
783
|
+
class MaterialXDocument {
|
|
784
|
+
|
|
785
|
+
constructor( manager, path, log, archiveResolver = null, uvSpace = 'bottom-left' ) {
|
|
786
|
+
|
|
787
|
+
this.manager = manager;
|
|
788
|
+
this.path = path;
|
|
789
|
+
this.log = log;
|
|
790
|
+
this.archiveResolver = archiveResolver;
|
|
791
|
+
this.uvSpace = normalizeUvSpace( uvSpace );
|
|
792
|
+
|
|
793
|
+
this.nodesXLib = new Map();
|
|
794
|
+
this.imageLoader = new ImageLoader( manager );
|
|
795
|
+
this.imageLoader.setPath( path );
|
|
796
|
+
this.textureLoader = new ImageBitmapLoader( manager );
|
|
797
|
+
this.textureLoader.setOptions( { imageOrientation: 'none' } );
|
|
798
|
+
this.textureLoader.setPath( path );
|
|
799
|
+
this.textureCache = new Map();
|
|
800
|
+
const bottomLeftUvSpaceHelpers = getBottomLeftUvSpaceHelpers( this.uvSpace );
|
|
801
|
+
|
|
802
|
+
this.compileContext = {
|
|
803
|
+
compileRegistry: COMPILE_REGISTRY,
|
|
804
|
+
nodeLibrary: MtlXLibrary,
|
|
805
|
+
...bottomLeftUvSpaceHelpers,
|
|
806
|
+
mxTransformUv: mx_transform_uv,
|
|
807
|
+
mxHextileCoord,
|
|
808
|
+
mxHextileComputeBlendWeights,
|
|
809
|
+
invertConstantMatrixValues,
|
|
810
|
+
IDENTITY_MAT3_VALUES,
|
|
811
|
+
IDENTITY_MAT4_VALUES,
|
|
812
|
+
};
|
|
813
|
+
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
resolveTextureURI( uri ) {
|
|
817
|
+
|
|
818
|
+
if ( this.archiveResolver ) {
|
|
819
|
+
|
|
820
|
+
const archiveURI = this.archiveResolver( uri );
|
|
821
|
+
if ( archiveURI ) return archiveURI;
|
|
822
|
+
|
|
823
|
+
}
|
|
824
|
+
|
|
825
|
+
return uri;
|
|
826
|
+
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
addMaterialXNode( materialXNode ) {
|
|
830
|
+
|
|
831
|
+
this.nodesXLib.set( materialXNode.nodePath, materialXNode );
|
|
832
|
+
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
getMaterialXNode( ...names ) {
|
|
836
|
+
|
|
837
|
+
return this.nodesXLib.get( names.join( '/' ) );
|
|
838
|
+
|
|
839
|
+
}
|
|
840
|
+
|
|
841
|
+
parseNode( nodeXML, nodePath = '' ) {
|
|
842
|
+
|
|
843
|
+
return parseMaterialXNodeTree(
|
|
844
|
+
nodeXML,
|
|
845
|
+
( childNodeXML, childNodePath ) => new MaterialXNode( this, childNodeXML, childNodePath ),
|
|
846
|
+
( materialXNode ) => this.addMaterialXNode( materialXNode ),
|
|
847
|
+
nodePath,
|
|
848
|
+
);
|
|
849
|
+
|
|
850
|
+
}
|
|
851
|
+
|
|
852
|
+
parse( text, materialName = null, options = {} ) {
|
|
853
|
+
|
|
854
|
+
const rootNode = parseMaterialXText(
|
|
855
|
+
text,
|
|
856
|
+
( childNodeXML, childNodePath ) => new MaterialXNode( this, childNodeXML, childNodePath ),
|
|
857
|
+
( materialXNode ) => this.addMaterialXNode( materialXNode ),
|
|
858
|
+
);
|
|
859
|
+
|
|
860
|
+
if ( options.interfaceValidator ) {
|
|
861
|
+
|
|
862
|
+
options.interfaceValidator( rootNode, this.log );
|
|
863
|
+
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
const materials = rootNode.toMaterials( materialName );
|
|
867
|
+
return {
|
|
868
|
+
materials,
|
|
869
|
+
log: this.log.entries,
|
|
870
|
+
errors: this.log.errors,
|
|
871
|
+
warnings: this.log.warnings,
|
|
872
|
+
};
|
|
873
|
+
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
}
|
|
877
|
+
|
|
878
|
+
export { MaterialXDocument };
|