@plastic-software/three 0.167.4 → 0.174.0
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/LICENSE +1 -1
- package/README.md +1 -1
- package/build/three.cjs +36217 -23964
- package/build/three.core.js +48830 -0
- package/build/three.core.min.js +6 -0
- package/build/three.module.js +10175 -46744
- package/build/three.module.min.js +2 -3
- package/build/three.tsl.js +550 -0
- package/build/three.tsl.min.js +6 -0
- package/build/three.webgpu.js +44348 -50671
- package/build/three.webgpu.min.js +2 -3
- package/build/three.webgpu.nodes.js +70301 -0
- package/build/three.webgpu.nodes.min.js +6 -0
- package/examples/jsm/Addons.js +3 -15
- package/examples/jsm/animation/AnimationClipCreator.js +1 -1
- package/examples/jsm/animation/CCDIKSolver.js +61 -11
- package/examples/jsm/capabilities/WebGL.js +27 -21
- package/examples/jsm/capabilities/WebGPU.js +1 -10
- package/examples/jsm/controls/ArcballControls.js +262 -231
- package/examples/jsm/controls/DragControls.js +1 -1
- package/examples/jsm/controls/FirstPersonControls.js +175 -163
- package/examples/jsm/controls/FlyControls.js +194 -188
- package/examples/jsm/controls/OrbitControls.js +801 -777
- package/examples/jsm/controls/PointerLockControls.js +26 -20
- package/examples/jsm/controls/TrackballControls.js +469 -448
- package/examples/jsm/controls/TransformControls.js +119 -68
- package/examples/jsm/csm/CSM.js +2 -2
- package/examples/jsm/csm/CSMFrustum.js +7 -4
- package/examples/jsm/csm/CSMHelper.js +2 -0
- package/examples/jsm/csm/CSMShadowNode.js +442 -0
- package/examples/jsm/curves/NURBSCurve.js +33 -2
- package/examples/jsm/curves/NURBSUtils.js +3 -0
- package/examples/jsm/effects/AnaglyphEffect.js +6 -13
- package/examples/jsm/effects/OutlineEffect.js +1 -1
- package/examples/jsm/effects/ParallaxBarrierEffect.js +17 -11
- package/examples/jsm/effects/StereoEffect.js +6 -1
- package/examples/jsm/exporters/DRACOExporter.js +4 -2
- package/examples/jsm/exporters/EXRExporter.js +19 -11
- package/examples/jsm/exporters/GLTFExporter.js +181 -109
- package/examples/jsm/exporters/KTX2Exporter.js +54 -23
- package/examples/jsm/exporters/OBJExporter.js +5 -1
- package/examples/jsm/exporters/PLYExporter.js +11 -9
- package/examples/jsm/exporters/USDZExporter.js +50 -11
- package/examples/jsm/geometries/DecalGeometry.js +73 -21
- package/examples/jsm/geometries/TextGeometry.js +1 -12
- package/examples/jsm/helpers/LightProbeHelper.js +43 -44
- package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
- package/examples/jsm/helpers/TextureHelperGPU.js +185 -0
- package/examples/jsm/helpers/VertexNormalsHelper.js +2 -0
- package/examples/jsm/interactive/HTMLMesh.js +1 -0
- package/examples/jsm/interactive/InteractiveGroup.js +108 -51
- package/examples/jsm/interactive/SelectionHelper.js +3 -1
- package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
- package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
- package/examples/jsm/libs/demuxer_mp4.js +109 -0
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/lighting/TiledLighting.js +18 -0
- package/examples/jsm/lights/LightProbeGenerator.js +26 -12
- package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
- package/examples/jsm/lines/LineGeometry.js +25 -0
- package/examples/jsm/lines/LineMaterial.js +0 -1
- package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
- package/examples/jsm/lines/webgpu/Line2.js +2 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +16 -21
- package/examples/jsm/lines/webgpu/Wireframe.js +57 -0
- package/examples/jsm/loaders/3DMLoader.js +1 -0
- package/examples/jsm/loaders/3MFLoader.js +104 -2
- package/examples/jsm/loaders/BVHLoader.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +15 -12
- package/examples/jsm/loaders/DDSLoader.js +42 -0
- package/examples/jsm/loaders/DRACOLoader.js +3 -1
- package/examples/jsm/loaders/FBXLoader.js +71 -22
- package/examples/jsm/loaders/GCodeLoader.js +4 -2
- package/examples/jsm/loaders/GLTFLoader.js +29 -14
- package/examples/jsm/loaders/KTX2Loader.js +160 -58
- package/examples/jsm/loaders/KTXLoader.js +4 -4
- package/examples/jsm/loaders/LDrawLoader.js +22 -136
- package/examples/jsm/loaders/LottieLoader.js +2 -1
- package/examples/jsm/loaders/MTLLoader.js +27 -7
- package/examples/jsm/loaders/MaterialXLoader.js +40 -14
- package/examples/jsm/loaders/NRRDLoader.js +1 -1
- package/examples/jsm/loaders/OBJLoader.js +5 -3
- package/examples/jsm/loaders/PCDLoader.js +14 -13
- package/examples/jsm/loaders/PDBLoader.js +3 -2
- package/examples/jsm/loaders/PLYLoader.js +15 -12
- package/examples/jsm/loaders/PVRLoader.js +1 -1
- package/examples/jsm/loaders/STLLoader.js +3 -2
- package/examples/jsm/loaders/SVGLoader.js +2 -2
- package/examples/jsm/loaders/TDSLoader.js +17 -18
- package/examples/jsm/loaders/VRMLLoader.js +17 -17
- package/examples/jsm/loaders/VTKLoader.js +4 -3
- package/examples/jsm/loaders/XYZLoader.js +3 -2
- package/examples/jsm/loaders/lwo/IFFParser.js +4 -4
- package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
- package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
- package/examples/jsm/math/ColorSpaces.js +76 -0
- package/examples/jsm/math/ConvexHull.js +1 -1
- package/examples/jsm/math/OBB.js +17 -0
- package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
- package/examples/jsm/misc/ProgressiveLightMap.js +54 -41
- package/examples/jsm/misc/ProgressiveLightMapGPU.js +294 -0
- package/examples/jsm/misc/Timer.js +27 -12
- package/examples/jsm/misc/Volume.js +28 -18
- package/examples/jsm/misc/VolumeSlice.js +19 -16
- package/examples/jsm/modifiers/CurveModifier.js +10 -8
- package/examples/jsm/modifiers/CurveModifierGPU.js +235 -0
- package/examples/jsm/modifiers/SimplifyModifier.js +2 -2
- package/examples/jsm/objects/GroundedSkybox.js +4 -4
- package/examples/jsm/objects/LensflareMesh.js +324 -0
- package/examples/jsm/objects/Reflector.js +5 -2
- package/examples/jsm/objects/Sky.js +2 -2
- package/examples/jsm/objects/SkyMesh.js +14 -14
- package/examples/jsm/objects/Water2.js +1 -1
- package/examples/jsm/objects/Water2Mesh.js +11 -9
- package/examples/jsm/objects/WaterMesh.js +38 -33
- package/examples/jsm/physics/JoltPhysics.js +8 -8
- package/examples/jsm/physics/RapierPhysics.js +5 -5
- package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
- package/examples/jsm/postprocessing/BloomPass.js +2 -2
- package/examples/jsm/postprocessing/EffectComposer.js +1 -2
- package/examples/jsm/postprocessing/OutlinePass.js +37 -51
- package/examples/jsm/postprocessing/OutputPass.js +2 -0
- package/examples/jsm/postprocessing/SAOPass.js +1 -2
- package/examples/jsm/postprocessing/SMAAPass.js +1 -3
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -1
- package/examples/jsm/postprocessing/SSAOPass.js +2 -4
- package/examples/jsm/postprocessing/SSRPass.js +8 -4
- package/examples/jsm/postprocessing/UnrealBloomPass.js +2 -2
- package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
- package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
- package/examples/jsm/renderers/SVGRenderer.js +6 -4
- package/examples/jsm/shaders/BokehShader2.js +1 -1
- package/examples/jsm/shaders/FXAAShader.js +225 -224
- package/examples/jsm/shaders/GodRaysShader.js +3 -3
- package/examples/jsm/shaders/OutputShader.js +6 -2
- package/examples/jsm/shaders/SobelOperatorShader.js +1 -1
- package/examples/jsm/transpiler/AST.js +12 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +77 -31
- package/examples/jsm/transpiler/ShaderToyDecoder.js +3 -3
- package/examples/jsm/transpiler/TSLEncoder.js +96 -21
- package/examples/jsm/tsl/display/AfterImageNode.js +243 -0
- package/examples/jsm/tsl/display/AnaglyphPassNode.js +106 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +257 -0
- package/{src/nodes/display/BleachBypassNode.js → examples/jsm/tsl/display/BleachBypass.js} +11 -6
- package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +252 -67
- package/examples/jsm/tsl/display/DenoiseNode.js +332 -0
- package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +92 -14
- package/examples/jsm/tsl/display/DotScreenNode.js +103 -0
- package/examples/jsm/tsl/display/FXAANode.js +364 -0
- package/examples/jsm/tsl/display/FilmNode.js +100 -0
- package/examples/jsm/tsl/display/GTAONode.js +521 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +393 -0
- package/examples/jsm/tsl/display/LensflareNode.js +278 -0
- package/examples/jsm/tsl/display/Lut3DNode.js +108 -0
- package/examples/jsm/tsl/display/MotionBlur.js +33 -0
- package/examples/jsm/tsl/display/OutlineNode.js +750 -0
- package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +88 -0
- package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +160 -28
- package/examples/jsm/tsl/display/RGBShiftNode.js +95 -0
- package/examples/jsm/tsl/display/SMAANode.js +767 -0
- package/examples/jsm/tsl/display/SSAAPassNode.js +357 -0
- package/examples/jsm/tsl/display/SSRNode.js +538 -0
- package/examples/jsm/tsl/display/Sepia.js +24 -0
- package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +66 -20
- package/examples/jsm/tsl/display/StereoCompositePassNode.js +184 -0
- package/examples/jsm/tsl/display/StereoPassNode.js +119 -0
- package/examples/jsm/tsl/display/TRAAPassNode.js +451 -0
- package/examples/jsm/tsl/display/TransitionNode.js +140 -0
- package/examples/jsm/tsl/display/hashBlur.js +34 -0
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +395 -0
- package/examples/jsm/tsl/math/Bayer.js +18 -0
- package/examples/jsm/tsl/utils/Raymarching.js +65 -0
- package/examples/jsm/utils/BufferGeometryUtils.js +2 -2
- package/examples/jsm/utils/CameraUtils.js +4 -1
- package/examples/jsm/utils/GeometryCompressionUtils.js +38 -123
- package/examples/jsm/utils/GeometryUtils.js +22 -19
- package/examples/jsm/utils/SceneOptimizer.js +410 -0
- package/examples/jsm/utils/SceneUtils.js +2 -2
- package/examples/jsm/utils/ShadowMapViewer.js +3 -8
- package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
- package/examples/jsm/utils/SkeletonUtils.js +84 -66
- package/examples/jsm/utils/UVsDebug.js +1 -1
- package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +1 -0
- package/examples/jsm/utils/WebGPUTextureUtils.js +64 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
- package/examples/jsm/webxr/Text2D.js +6 -6
- package/examples/jsm/webxr/XRControllerModelFactory.js +7 -2
- package/examples/jsm/webxr/XREstimatedLight.js +1 -1
- package/package.json +14 -9
- package/src/Three.Core.js +182 -0
- package/src/Three.Legacy.js +0 -21
- package/src/Three.TSL.js +543 -0
- package/src/Three.WebGPU.Nodes.js +23 -0
- package/src/Three.WebGPU.js +13 -184
- package/src/Three.js +1 -176
- package/src/animation/AnimationClip.js +2 -2
- package/src/animation/AnimationObjectGroup.js +2 -2
- package/src/animation/AnimationUtils.js +1 -1
- package/src/animation/PropertyBinding.js +2 -2
- package/src/audio/Audio.js +379 -2
- package/src/audio/AudioAnalyser.js +58 -1
- package/src/audio/AudioContext.js +15 -0
- package/src/audio/AudioListener.js +76 -0
- package/src/audio/PositionalAudio.js +107 -0
- package/src/cameras/ArrayCamera.js +29 -0
- package/src/cameras/Camera.js +47 -0
- package/src/cameras/CubeCamera.js +66 -0
- package/src/cameras/OrthographicCamera.js +109 -0
- package/src/cameras/PerspectiveCamera.js +173 -34
- package/src/cameras/StereoCamera.js +48 -2
- package/src/constants.js +6 -6
- package/src/core/BufferAttribute.js +4 -9
- package/src/core/BufferGeometry.js +48 -8
- package/src/core/Clock.js +1 -1
- package/src/core/EventDispatcher.js +52 -8
- package/src/core/InterleavedBuffer.js +4 -13
- package/src/core/Object3D.js +573 -3
- package/src/core/RenderTarget.js +22 -4
- package/src/core/RenderTarget3D.js +22 -0
- package/src/core/RenderTargetArray.js +22 -0
- package/src/extras/Controls.js +104 -0
- package/src/extras/DataUtils.js +48 -8
- package/src/extras/Earcut.js +18 -7
- package/src/extras/ImageUtils.js +18 -11
- package/src/extras/PMREMGenerator.js +40 -9
- package/src/extras/ShapeUtils.js +24 -2
- package/src/extras/TextureUtils.js +96 -10
- package/src/extras/core/Curve.js +153 -53
- package/src/extras/core/CurvePath.js +63 -22
- package/src/extras/core/Interpolations.js +29 -3
- package/src/extras/core/Path.js +134 -1
- package/src/extras/core/Shape.js +66 -3
- package/src/extras/core/ShapePath.js +76 -0
- package/src/extras/curves/ArcCurve.js +22 -0
- package/src/extras/curves/CatmullRomCurve3.js +89 -18
- package/src/extras/curves/CubicBezierCurve.js +67 -0
- package/src/extras/curves/CubicBezierCurve3.js +50 -0
- package/src/extras/curves/EllipseCurve.js +102 -0
- package/src/extras/curves/LineCurve.js +36 -0
- package/src/extras/curves/LineCurve3.js +36 -0
- package/src/extras/curves/QuadraticBezierCurve.js +59 -0
- package/src/extras/curves/QuadraticBezierCurve3.js +43 -0
- package/src/extras/curves/SplineCurve.js +48 -0
- package/src/geometries/BoxGeometry.js +38 -0
- package/src/geometries/CapsuleGeometry.js +34 -0
- package/src/geometries/CircleGeometry.js +40 -0
- package/src/geometries/ConeGeometry.js +38 -0
- package/src/geometries/CylinderGeometry.js +50 -4
- package/src/geometries/DodecahedronGeometry.js +32 -0
- package/src/geometries/EdgesGeometry.js +30 -2
- package/src/geometries/ExtrudeGeometry.js +52 -0
- package/src/geometries/IcosahedronGeometry.js +32 -0
- package/src/geometries/LatheGeometry.js +43 -3
- package/src/geometries/OctahedronGeometry.js +32 -0
- package/src/geometries/PlaneGeometry.js +34 -0
- package/src/geometries/PolyhedronGeometry.js +29 -0
- package/src/geometries/RingGeometry.js +36 -0
- package/src/geometries/ShapeGeometry.js +37 -0
- package/src/geometries/SphereGeometry.js +37 -0
- package/src/geometries/TetrahedronGeometry.js +32 -0
- package/src/geometries/TorusGeometry.js +35 -0
- package/src/geometries/TorusKnotGeometry.js +38 -0
- package/src/geometries/TubeGeometry.js +49 -0
- package/src/geometries/WireframeGeometry.js +32 -0
- package/src/helpers/ArrowHelper.js +60 -3
- package/src/helpers/AxesHelper.js +28 -0
- package/src/helpers/Box3Helper.js +28 -0
- package/src/helpers/BoxHelper.js +43 -7
- package/src/helpers/CameraHelper.js +61 -18
- package/src/helpers/DirectionalLightHelper.js +52 -0
- package/src/helpers/GridHelper.js +26 -0
- package/src/helpers/HemisphereLightHelper.js +39 -0
- package/src/helpers/PlaneHelper.js +33 -0
- package/src/helpers/PointLightHelper.js +43 -0
- package/src/helpers/PolarGridHelper.js +30 -0
- package/src/helpers/SkeletonHelper.js +39 -2
- package/src/helpers/SpotLightHelper.js +40 -0
- package/src/lights/AmbientLight.js +25 -0
- package/src/lights/DirectionalLight.js +57 -0
- package/src/lights/DirectionalLightShadow.js +15 -0
- package/src/lights/HemisphereLight.js +32 -0
- package/src/lights/Light.js +36 -0
- package/src/lights/LightProbe.js +43 -0
- package/src/lights/LightShadow.js +159 -0
- package/src/lights/PointLight.js +59 -0
- package/src/lights/PointLightShadow.js +21 -0
- package/src/lights/RectAreaLight.js +59 -0
- package/src/lights/SpotLight.js +102 -0
- package/src/lights/SpotLightShadow.js +24 -2
- package/src/lights/webgpu/IESSpotLight.js +21 -0
- package/src/loaders/Loader.js +132 -0
- package/src/loaders/MaterialLoader.js +7 -1
- package/src/loaders/nodes/NodeLoader.js +189 -0
- package/src/loaders/nodes/NodeMaterialLoader.js +108 -0
- package/src/loaders/nodes/NodeObjectLoader.js +151 -0
- package/src/materials/LineDashedMaterial.js +0 -1
- package/src/materials/Material.js +469 -7
- package/src/materials/MeshPhongMaterial.js +1 -1
- package/src/materials/MeshPhysicalMaterial.js +2 -2
- package/src/materials/MeshStandardMaterial.js +2 -2
- package/src/{nodes/materials → materials/nodes}/Line2NodeMaterial.js +192 -82
- package/src/materials/nodes/LineBasicNodeMaterial.js +46 -0
- package/src/materials/nodes/LineDashedNodeMaterial.js +132 -0
- package/src/materials/nodes/MeshBasicNodeMaterial.js +133 -0
- package/src/materials/nodes/MeshLambertNodeMaterial.js +82 -0
- package/src/materials/nodes/MeshMatcapNodeMaterial.js +77 -0
- package/src/materials/nodes/MeshNormalNodeMaterial.js +67 -0
- package/src/materials/nodes/MeshPhongNodeMaterial.js +141 -0
- package/src/materials/nodes/MeshPhysicalNodeMaterial.js +517 -0
- package/src/materials/nodes/MeshSSSNodeMaterial.js +175 -0
- package/src/materials/nodes/MeshStandardNodeMaterial.js +186 -0
- package/src/materials/nodes/MeshToonNodeMaterial.js +66 -0
- package/src/materials/nodes/NodeMaterial.js +1180 -0
- package/src/{nodes/materials/Materials.js → materials/nodes/NodeMaterials.js} +3 -2
- package/src/materials/nodes/PointsNodeMaterial.js +153 -0
- package/src/materials/nodes/ShadowNodeMaterial.js +67 -0
- package/src/materials/nodes/SpriteNodeMaterial.js +198 -0
- package/src/materials/nodes/VolumeNodeMaterial.js +72 -0
- package/src/materials/nodes/manager/NodeMaterialObserver.js +509 -0
- package/src/math/Box2.js +177 -0
- package/src/math/Box3.js +243 -0
- package/src/math/Color.js +343 -0
- package/src/math/ColorManagement.js +143 -102
- package/src/math/Cylindrical.js +65 -6
- package/src/math/Euler.js +137 -4
- package/src/math/Frustum.js +83 -0
- package/src/math/Interpolant.js +87 -8
- package/src/math/Line3.js +96 -2
- package/src/math/MathUtils.js +182 -19
- package/src/math/Matrix2.js +70 -0
- package/src/math/Matrix3.js +229 -4
- package/src/math/Matrix4.js +368 -3
- package/src/math/Plane.js +164 -2
- package/src/math/Quaternion.js +265 -9
- package/src/math/Ray.js +160 -0
- package/src/math/Sphere.js +147 -0
- package/src/math/Spherical.js +73 -11
- package/src/math/SphericalHarmonics3.js +112 -14
- package/src/math/Triangle.js +230 -2
- package/src/math/Vector2.js +396 -10
- package/src/math/Vector3.js +550 -13
- package/src/math/Vector4.js +415 -9
- package/src/math/interpolants/CubicInterpolant.js +10 -1
- package/src/math/interpolants/DiscreteInterpolant.js +10 -2
- package/src/math/interpolants/LinearInterpolant.js +13 -0
- package/src/math/interpolants/QuaternionLinearInterpolant.js +10 -1
- package/src/nodes/Nodes.js +84 -166
- package/src/nodes/TSL.js +167 -0
- package/src/nodes/accessors/AccessorsUtils.js +39 -10
- package/src/nodes/accessors/Arrays.js +68 -0
- package/src/nodes/accessors/BatchNode.js +93 -26
- package/src/nodes/accessors/Bitangent.js +54 -0
- package/src/nodes/accessors/BufferAttributeNode.js +189 -11
- package/src/nodes/accessors/BufferNode.js +70 -5
- package/src/nodes/accessors/BuiltinNode.js +63 -0
- package/src/nodes/accessors/Camera.js +129 -0
- package/src/nodes/accessors/ClippingNode.js +152 -43
- package/src/nodes/accessors/CubeTextureNode.js +76 -13
- package/src/nodes/accessors/InstanceNode.js +118 -35
- package/src/nodes/accessors/InstancedMeshNode.js +50 -0
- package/src/nodes/accessors/Lights.js +129 -0
- package/src/nodes/accessors/MaterialNode.js +394 -58
- package/src/nodes/accessors/MaterialProperties.js +57 -1
- package/src/nodes/accessors/MaterialReferenceNode.js +60 -18
- package/src/nodes/accessors/ModelNode.js +159 -12
- package/src/nodes/accessors/ModelViewProjectionNode.js +10 -36
- package/src/nodes/accessors/MorphNode.js +60 -13
- package/src/nodes/accessors/Normal.js +156 -0
- package/src/nodes/accessors/Object3DNode.js +154 -35
- package/src/nodes/accessors/PointUVNode.js +35 -6
- package/src/nodes/accessors/Position.js +64 -0
- package/src/nodes/accessors/ReferenceBaseNode.js +357 -0
- package/src/nodes/accessors/ReferenceNode.js +243 -6
- package/src/nodes/accessors/ReflectVector.js +36 -0
- package/src/nodes/accessors/RendererReferenceNode.js +57 -7
- package/src/nodes/accessors/SceneNode.js +98 -6
- package/src/nodes/accessors/SkinningNode.js +214 -21
- package/src/nodes/accessors/StorageBufferNode.js +288 -28
- package/src/nodes/accessors/StorageTextureNode.js +139 -12
- package/src/nodes/accessors/Tangent.js +62 -0
- package/src/nodes/accessors/Texture3DNode.js +98 -12
- package/src/nodes/accessors/{TextureBicubicNode.js → TextureBicubic.js} +14 -34
- package/src/nodes/accessors/TextureNode.js +347 -34
- package/src/nodes/accessors/TextureSizeNode.js +51 -9
- package/src/nodes/accessors/UV.js +11 -0
- package/src/nodes/accessors/UniformArrayNode.js +241 -32
- package/src/nodes/accessors/UserDataNode.js +55 -7
- package/src/nodes/accessors/VelocityNode.js +223 -0
- package/src/nodes/accessors/VertexColorNode.js +45 -6
- package/src/nodes/code/CodeNode.js +108 -8
- package/src/nodes/code/ExpressionNode.js +38 -7
- package/src/nodes/code/FunctionCallNode.js +62 -11
- package/src/nodes/code/FunctionNode.js +54 -24
- package/src/nodes/code/ScriptableNode.js +241 -17
- package/src/nodes/code/ScriptableValueNode.js +93 -8
- package/src/nodes/core/ArrayNode.js +142 -0
- package/src/nodes/core/AssignNode.js +60 -12
- package/src/nodes/core/AttributeNode.js +55 -22
- package/src/nodes/core/BypassNode.js +59 -11
- package/src/nodes/core/CacheNode.js +64 -10
- package/src/nodes/core/ConstNode.js +38 -3
- package/src/nodes/core/ContextNode.js +87 -12
- package/src/nodes/core/IndexNode.js +102 -10
- package/src/nodes/core/InputNode.js +55 -3
- package/src/nodes/core/LightingModel.js +65 -5
- package/src/nodes/core/MRTNode.js +81 -7
- package/src/nodes/core/Node.js +368 -50
- package/src/nodes/core/NodeAttribute.js +38 -0
- package/src/nodes/core/NodeBuilder.js +1317 -83
- package/src/nodes/core/NodeCache.js +41 -2
- package/src/nodes/core/NodeCode.js +31 -0
- package/src/nodes/core/NodeFrame.js +123 -2
- package/src/nodes/core/NodeFunction.js +46 -0
- package/src/nodes/core/NodeFunctionInput.js +44 -0
- package/src/nodes/core/NodeParser.js +11 -0
- package/src/nodes/core/NodeUniform.js +52 -0
- package/src/nodes/core/NodeUtils.js +226 -6
- package/src/nodes/core/NodeVar.js +47 -1
- package/src/nodes/core/NodeVarying.js +28 -0
- package/src/nodes/core/OutputStructNode.js +61 -17
- package/src/nodes/core/ParameterNode.js +34 -4
- package/src/nodes/core/PropertyNode.js +296 -32
- package/src/nodes/core/StackNode.js +108 -8
- package/src/nodes/core/StructNode.js +120 -0
- package/src/nodes/core/StructType.js +13 -0
- package/src/nodes/core/StructTypeNode.js +116 -9
- package/src/nodes/core/TempNode.js +37 -7
- package/src/nodes/core/UniformGroupNode.js +98 -17
- package/src/nodes/core/UniformNode.js +72 -4
- package/src/nodes/core/VarNode.js +170 -13
- package/src/nodes/core/VaryingNode.js +109 -8
- package/src/nodes/core/constants.js +40 -0
- package/src/nodes/display/BlendModes.js +193 -0
- package/src/nodes/display/BumpMapNode.js +47 -10
- package/src/nodes/display/ColorAdjustment.js +141 -0
- package/src/nodes/display/ColorSpaceFunctions.js +54 -0
- package/src/nodes/display/ColorSpaceNode.js +147 -68
- package/src/nodes/display/FrontFacingNode.js +39 -6
- package/src/nodes/display/NormalMapNode.js +55 -13
- package/src/nodes/display/PassNode.js +420 -19
- package/src/nodes/display/PosterizeNode.js +40 -7
- package/src/nodes/display/RenderOutputNode.js +81 -13
- package/src/nodes/display/ScreenNode.js +286 -0
- package/src/nodes/display/ToneMappingFunctions.js +242 -0
- package/src/nodes/display/ToneMappingNode.js +68 -175
- package/src/nodes/display/ToonOutlinePassNode.js +183 -0
- package/src/nodes/display/ViewportDepthNode.js +210 -36
- package/src/nodes/display/ViewportDepthTextureNode.js +32 -9
- package/src/nodes/display/ViewportSharedTextureNode.js +32 -9
- package/src/nodes/display/ViewportTextureNode.js +68 -11
- package/src/nodes/fog/Fog.js +113 -0
- package/src/nodes/functions/BSDF/BRDF_GGX.js +4 -4
- package/src/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/src/nodes/functions/BSDF/BRDF_Sheen.js +6 -6
- package/src/nodes/functions/BSDF/DFGApprox.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX.js +2 -2
- package/src/nodes/functions/BSDF/D_GGX_Anisotropic.js +3 -3
- package/src/nodes/functions/BSDF/EnvironmentBRDF.js +2 -2
- package/src/nodes/functions/BSDF/F_Schlick.js +2 -2
- package/src/nodes/functions/BSDF/LTC.js +50 -6
- package/src/nodes/functions/BSDF/Schlick_to_F0.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
- package/src/nodes/functions/BSDF/V_GGX_SmithCorrelated_Anisotropic.js +2 -2
- package/src/nodes/functions/BasicLightingModel.js +27 -6
- package/src/nodes/functions/PhongLightingModel.js +38 -8
- package/src/nodes/functions/PhysicalLightingModel.js +215 -51
- package/src/nodes/functions/ShadowMaskModel.js +24 -1
- package/src/nodes/functions/ToonLightingModel.js +24 -5
- package/src/nodes/functions/VolumetricLightingModel.js +183 -0
- package/src/nodes/functions/material/getAlphaHashThreshold.js +68 -0
- package/src/nodes/functions/material/getGeometryRoughness.js +10 -4
- package/src/nodes/functions/material/getParallaxCorrectNormal.js +37 -0
- package/src/nodes/functions/material/getRoughness.js +2 -2
- package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
- package/src/nodes/geometry/RangeNode.js +62 -7
- package/src/nodes/gpgpu/AtomicFunctionNode.js +280 -0
- package/src/nodes/gpgpu/BarrierNode.js +89 -0
- package/src/nodes/gpgpu/ComputeBuiltinNode.js +227 -0
- package/src/nodes/gpgpu/ComputeNode.js +124 -9
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +208 -0
- package/src/nodes/lighting/AONode.js +24 -3
- package/src/nodes/lighting/AmbientLightNode.js +16 -8
- package/src/nodes/lighting/AnalyticLightNode.js +151 -231
- package/src/nodes/lighting/BasicEnvironmentNode.js +25 -3
- package/src/nodes/lighting/BasicLightMapNode.js +25 -5
- package/src/nodes/lighting/DirectionalLightNode.js +19 -20
- package/src/nodes/lighting/EnvironmentNode.js +34 -17
- package/src/nodes/lighting/HemisphereLightNode.js +42 -11
- package/src/nodes/lighting/IESSpotLightNode.js +18 -9
- package/src/nodes/lighting/IrradianceNode.js +23 -3
- package/src/nodes/lighting/LightProbeNode.js +29 -36
- package/src/nodes/lighting/LightUtils.js +12 -4
- package/src/nodes/lighting/LightingContextNode.js +70 -21
- package/src/nodes/lighting/LightingNode.js +22 -9
- package/src/nodes/lighting/LightsNode.js +309 -86
- package/src/nodes/lighting/PointLightNode.js +66 -32
- package/src/nodes/lighting/PointShadowNode.js +306 -0
- package/src/nodes/lighting/RectAreaLightNode.js +61 -25
- package/src/nodes/lighting/ShadowBaseNode.js +92 -0
- package/src/nodes/lighting/ShadowNode.js +812 -0
- package/src/nodes/lighting/SpotLightNode.js +73 -31
- package/src/nodes/materialx/MaterialXNodes.js +2 -2
- package/src/nodes/materialx/lib/mx_hsv.js +27 -22
- package/src/nodes/materialx/lib/mx_noise.js +70 -70
- package/src/nodes/materialx/lib/mx_transform_color.js +2 -2
- package/src/nodes/math/ConditionalNode.js +230 -0
- package/src/nodes/math/Hash.js +21 -0
- package/src/nodes/math/MathNode.js +812 -131
- package/src/nodes/math/MathUtils.js +47 -8
- package/src/nodes/math/OperatorNode.js +410 -66
- package/src/nodes/math/TriNoise3D.js +32 -32
- package/src/nodes/parsers/GLSLNodeFunction.js +16 -0
- package/src/nodes/parsers/GLSLNodeParser.js +11 -0
- package/src/nodes/pmrem/PMREMNode.js +188 -28
- package/src/nodes/pmrem/PMREMUtils.js +24 -24
- package/src/nodes/procedural/Checker.js +22 -0
- package/src/nodes/shapes/Shapes.js +32 -0
- package/src/nodes/tsl/TSLBase.js +31 -0
- package/src/nodes/{shadernode/ShaderNode.js → tsl/TSLCore.js} +114 -98
- package/src/nodes/utils/ArrayElementNode.js +45 -5
- package/src/nodes/utils/ConvertNode.js +39 -4
- package/src/nodes/utils/CubeMapNode.js +88 -8
- package/src/nodes/utils/Discard.js +24 -0
- package/src/nodes/utils/EquirectUVNode.js +39 -7
- package/src/nodes/utils/FlipNode.js +106 -0
- package/src/nodes/utils/FunctionOverloadingNode.js +61 -6
- package/src/nodes/utils/JoinNode.js +31 -3
- package/src/nodes/utils/LoopNode.js +95 -9
- package/src/nodes/utils/MatcapUVNode.js +27 -8
- package/src/nodes/utils/MaxMipLevelNode.js +57 -6
- package/src/nodes/utils/MemberNode.js +68 -0
- package/src/nodes/utils/Oscillators.js +41 -0
- package/src/nodes/utils/Packing.js +21 -0
- package/src/nodes/utils/PostProcessingUtils.js +95 -0
- package/src/nodes/utils/RTTNode.js +141 -9
- package/src/nodes/utils/ReflectorNode.js +295 -21
- package/src/nodes/utils/RemapNode.js +93 -10
- package/src/nodes/utils/RotateNode.js +48 -13
- package/src/nodes/utils/SetNode.js +50 -4
- package/src/nodes/utils/SplitNode.js +62 -6
- package/src/nodes/utils/SpriteSheetUVNode.js +56 -7
- package/src/nodes/utils/SpriteUtils.js +21 -5
- package/src/nodes/utils/StorageArrayElementNode.js +64 -12
- package/src/nodes/utils/Timer.js +73 -0
- package/src/nodes/utils/TriplanarTexturesNode.js +96 -10
- package/src/nodes/utils/UVUtils.js +27 -9
- package/src/nodes/utils/ViewportUtils.js +16 -4
- package/src/objects/BatchedMesh.js +808 -281
- package/src/objects/Bone.js +24 -0
- package/src/objects/ClippingGroup.js +68 -0
- package/src/objects/Group.js +24 -0
- package/src/objects/InstancedMesh.js +120 -2
- package/src/objects/LOD.js +120 -5
- package/src/objects/Line.js +89 -6
- package/src/objects/LineLoop.js +20 -0
- package/src/objects/LineSegments.js +18 -0
- package/src/objects/Mesh.js +82 -23
- package/src/objects/Points.js +62 -0
- package/src/objects/Skeleton.js +107 -2
- package/src/objects/SkinnedMesh.js +99 -5
- package/src/objects/Sprite.js +54 -0
- package/src/renderers/WebGLRenderer.js +274 -157
- package/src/renderers/common/Animation.js +109 -12
- package/src/renderers/common/Attributes.js +40 -0
- package/src/renderers/common/Backend.js +504 -44
- package/src/renderers/common/Background.js +67 -9
- package/src/renderers/common/BindGroup.js +45 -1
- package/src/renderers/common/Binding.js +35 -0
- package/src/renderers/common/Bindings.js +136 -19
- package/src/renderers/common/Buffer.js +49 -0
- package/src/renderers/common/BufferUtils.js +25 -0
- package/src/renderers/common/BundleGroup.js +83 -0
- package/src/renderers/common/ChainMap.js +45 -6
- package/src/renderers/common/ClippingContext.js +175 -80
- package/src/renderers/common/Color4.js +40 -0
- package/src/renderers/common/ComputePipeline.js +24 -0
- package/src/renderers/common/Constants.js +2 -1
- package/src/renderers/common/CubeRenderTarget.js +22 -3
- package/src/renderers/common/DataMap.js +37 -1
- package/src/renderers/common/Geometries.js +111 -14
- package/src/renderers/common/IndirectStorageBufferAttribute.js +38 -0
- package/src/renderers/common/Info.js +78 -35
- package/src/renderers/common/Lighting.js +73 -0
- package/src/renderers/common/Pipeline.js +22 -0
- package/src/renderers/common/Pipelines.js +148 -5
- package/src/renderers/common/PostProcessing.js +112 -11
- package/src/renderers/common/ProgrammableStage.js +60 -2
- package/src/renderers/common/QuadMesh.js +56 -5
- package/src/renderers/common/RenderBundle.js +14 -8
- package/src/renderers/common/RenderBundles.js +39 -10
- package/src/renderers/common/RenderContext.js +205 -7
- package/src/renderers/common/RenderContexts.js +59 -6
- package/src/renderers/common/RenderList.js +230 -21
- package/src/renderers/common/RenderLists.js +45 -6
- package/src/renderers/common/RenderObject.js +552 -41
- package/src/renderers/common/RenderObjects.js +118 -9
- package/src/renderers/common/RenderPipeline.js +24 -0
- package/src/renderers/common/Renderer.js +1537 -239
- package/src/renderers/common/RendererUtils.js +191 -0
- package/src/renderers/common/SampledTexture.js +132 -3
- package/src/renderers/common/Sampler.js +30 -0
- package/src/renderers/common/StorageBuffer.js +24 -0
- package/src/renderers/common/StorageBufferAttribute.js +31 -2
- package/src/renderers/common/StorageInstancedBufferAttribute.js +31 -2
- package/src/renderers/common/StorageTexture.js +38 -0
- package/src/renderers/common/Textures.js +142 -32
- package/src/renderers/common/TimestampQueryPool.js +98 -0
- package/src/renderers/common/Uniform.js +225 -3
- package/src/renderers/common/UniformBuffer.js +19 -0
- package/src/renderers/common/UniformsGroup.js +157 -6
- package/src/renderers/common/XRManager.js +1185 -0
- package/src/renderers/common/XRRenderTarget.js +74 -0
- package/src/renderers/common/extras/PMREMGenerator.js +211 -53
- package/src/renderers/common/nodes/NodeBuilderState.js +100 -6
- package/src/renderers/common/nodes/NodeLibrary.js +194 -0
- package/src/renderers/common/nodes/NodeSampledTexture.js +92 -4
- package/src/renderers/common/nodes/NodeSampler.js +28 -0
- package/src/renderers/common/nodes/NodeStorageBuffer.js +37 -3
- package/src/renderers/common/nodes/NodeUniform.js +285 -2
- package/src/renderers/common/nodes/NodeUniformBuffer.js +29 -0
- package/src/renderers/common/nodes/NodeUniformsGroup.js +31 -18
- package/src/renderers/common/nodes/Nodes.js +390 -70
- package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
- package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +7 -7
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
- package/src/renderers/webgl/WebGLAttributes.js +45 -14
- package/src/renderers/webgl/WebGLBackground.js +24 -1
- package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLCapabilities.js +2 -0
- package/src/renderers/webgl/WebGLGeometries.js +0 -28
- package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
- package/src/renderers/webgl/WebGLProgram.js +27 -29
- package/src/renderers/webgl/WebGLPrograms.js +24 -16
- package/src/renderers/webgl/WebGLState.js +68 -11
- package/src/renderers/webgl/WebGLTextures.js +49 -10
- package/src/renderers/webgl-fallback/WebGLBackend.js +1055 -238
- package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +5 -10
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +425 -48
- package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +64 -1
- package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
- package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
- package/src/renderers/webgl-fallback/utils/WebGLState.js +419 -14
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +281 -59
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +367 -0
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
- package/src/renderers/webgpu/WebGPUBackend.js +816 -236
- package/src/renderers/webgpu/WebGPURenderer.Nodes.js +78 -0
- package/src/renderers/webgpu/WebGPURenderer.js +45 -6
- package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +63 -0
- package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +97 -0
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +954 -147
- package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +29 -4
- package/src/renderers/webgpu/nodes/WGSLNodeParser.js +11 -0
- package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +147 -31
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +213 -31
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +146 -28
- package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +161 -7
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +333 -50
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +287 -0
- package/src/renderers/webgpu/utils/WebGPUUtils.js +131 -3
- package/src/renderers/webxr/WebXRDepthSensing.js +1 -1
- package/src/renderers/webxr/WebXRManager.js +54 -32
- package/src/scenes/Fog.js +60 -0
- package/src/scenes/FogExp2.js +51 -0
- package/src/scenes/Scene.js +87 -0
- package/src/textures/Data3DTexture.js +2 -2
- package/src/textures/DepthTexture.js +2 -0
- package/src/textures/Source.js +2 -2
- package/src/textures/Texture.js +368 -5
- package/src/textures/VideoFrameTexture.js +35 -0
- package/src/utils.js +33 -1
- package/examples/jsm/animation/MMDAnimationHelper.js +0 -1207
- package/examples/jsm/animation/MMDPhysics.js +0 -1406
- package/examples/jsm/cameras/CinematicCamera.js +0 -208
- package/examples/jsm/controls/Controls.js +0 -32
- package/examples/jsm/exporters/MMDExporter.js +0 -217
- package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -174
- package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
- package/examples/jsm/libs/mmdparser.module.js +0 -11530
- package/examples/jsm/loaders/LogLuvLoader.js +0 -606
- package/examples/jsm/loaders/MMDLoader.js +0 -2295
- package/examples/jsm/loaders/TiltLoader.js +0 -520
- package/examples/jsm/objects/InstancedPoints.js +0 -21
- package/examples/jsm/shaders/MMDToonShader.js +0 -134
- package/examples/jsm/utils/GPUStatsPanel.js +0 -95
- package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
- package/src/nodes/accessors/BitangentNode.js +0 -13
- package/src/nodes/accessors/CameraNode.js +0 -19
- package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -21
- package/src/nodes/accessors/NormalNode.js +0 -14
- package/src/nodes/accessors/PositionNode.js +0 -10
- package/src/nodes/accessors/ReflectVectorNode.js +0 -10
- package/src/nodes/accessors/TangentNode.js +0 -23
- package/src/nodes/accessors/UVNode.js +0 -3
- package/src/nodes/core/NodeKeywords.js +0 -80
- package/src/nodes/core/UniformGroup.js +0 -13
- package/src/nodes/display/AfterImageNode.js +0 -152
- package/src/nodes/display/AnamorphicNode.js +0 -145
- package/src/nodes/display/BlendModeNode.js +0 -128
- package/src/nodes/display/ColorAdjustmentNode.js +0 -104
- package/src/nodes/display/DenoiseNode.js +0 -198
- package/src/nodes/display/DotScreenNode.js +0 -75
- package/src/nodes/display/FXAANode.js +0 -327
- package/src/nodes/display/FilmNode.js +0 -52
- package/src/nodes/display/GTAONode.js +0 -324
- package/src/nodes/display/GaussianBlurNode.js +0 -207
- package/src/nodes/display/Lut3DNode.js +0 -53
- package/src/nodes/display/RGBShiftNode.js +0 -49
- package/src/nodes/display/SepiaNode.js +0 -18
- package/src/nodes/display/TransitionNode.js +0 -76
- package/src/nodes/display/ViewportNode.js +0 -137
- package/src/nodes/fog/FogExp2Node.js +0 -34
- package/src/nodes/fog/FogNode.js +0 -48
- package/src/nodes/fog/FogRangeNode.js +0 -35
- package/src/nodes/lighting/LightNode.js +0 -57
- package/src/nodes/loaders/NodeLoader.js +0 -110
- package/src/nodes/loaders/NodeMaterialLoader.js +0 -60
- package/src/nodes/loaders/NodeObjectLoader.js +0 -71
- package/src/nodes/materials/InstancedPointsNodeMaterial.js +0 -162
- package/src/nodes/materials/LineBasicNodeMaterial.js +0 -28
- package/src/nodes/materials/LineDashedNodeMaterial.js +0 -55
- package/src/nodes/materials/MeshBasicNodeMaterial.js +0 -73
- package/src/nodes/materials/MeshLambertNodeMaterial.js +0 -43
- package/src/nodes/materials/MeshMatcapNodeMaterial.js +0 -53
- package/src/nodes/materials/MeshNormalNodeMaterial.js +0 -40
- package/src/nodes/materials/MeshPhongNodeMaterial.js +0 -74
- package/src/nodes/materials/MeshPhysicalNodeMaterial.js +0 -244
- package/src/nodes/materials/MeshSSSNodeMaterial.js +0 -84
- package/src/nodes/materials/MeshStandardNodeMaterial.js +0 -104
- package/src/nodes/materials/MeshToonNodeMaterial.js +0 -34
- package/src/nodes/materials/NodeMaterial.js +0 -680
- package/src/nodes/materials/PointsNodeMaterial.js +0 -39
- package/src/nodes/materials/ShadowNodeMaterial.js +0 -34
- package/src/nodes/materials/SpriteNodeMaterial.js +0 -90
- package/src/nodes/materials/VolumeNodeMaterial.js +0 -106
- package/src/nodes/math/CondNode.js +0 -139
- package/src/nodes/math/HashNode.js +0 -34
- package/src/nodes/procedural/CheckerNode.js +0 -42
- package/src/nodes/utils/DiscardNode.js +0 -28
- package/src/nodes/utils/OscNode.js +0 -81
- package/src/nodes/utils/PackingNode.js +0 -55
- package/src/nodes/utils/TimerNode.js +0 -94
|
@@ -3,47 +3,37 @@ import NodeAttribute from './NodeAttribute.js';
|
|
|
3
3
|
import NodeVarying from './NodeVarying.js';
|
|
4
4
|
import NodeVar from './NodeVar.js';
|
|
5
5
|
import NodeCode from './NodeCode.js';
|
|
6
|
-
import NodeKeywords from './NodeKeywords.js';
|
|
7
6
|
import NodeCache from './NodeCache.js';
|
|
8
7
|
import ParameterNode from './ParameterNode.js';
|
|
8
|
+
import StructType from './StructType.js';
|
|
9
9
|
import FunctionNode from '../code/FunctionNode.js';
|
|
10
|
-
import
|
|
10
|
+
import NodeMaterial from '../../materials/nodes/NodeMaterial.js';
|
|
11
|
+
import { getTypeFromLength } from './NodeUtils.js';
|
|
11
12
|
import { NodeUpdateType, defaultBuildStages, shaderStages } from './constants.js';
|
|
12
13
|
|
|
13
14
|
import {
|
|
14
15
|
NumberNodeUniform, Vector2NodeUniform, Vector3NodeUniform, Vector4NodeUniform,
|
|
15
|
-
ColorNodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
|
|
16
|
+
ColorNodeUniform, Matrix2NodeUniform, Matrix3NodeUniform, Matrix4NodeUniform
|
|
16
17
|
} from '../../renderers/common/nodes/NodeUniform.js';
|
|
17
18
|
|
|
18
19
|
import { stack } from './StackNode.js';
|
|
19
|
-
import { getCurrentStack, setCurrentStack } from '../
|
|
20
|
+
import { getCurrentStack, setCurrentStack } from '../tsl/TSLBase.js';
|
|
20
21
|
|
|
21
22
|
import CubeRenderTarget from '../../renderers/common/CubeRenderTarget.js';
|
|
22
23
|
import ChainMap from '../../renderers/common/ChainMap.js';
|
|
23
24
|
|
|
24
|
-
import PMREMGenerator from '../../renderers/common/extras/PMREMGenerator.js';
|
|
25
|
-
|
|
26
25
|
import BindGroup from '../../renderers/common/BindGroup.js';
|
|
27
26
|
|
|
28
|
-
import { REVISION } from '../../constants.js';
|
|
27
|
+
import { REVISION, IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
|
|
29
28
|
import { RenderTarget } from '../../core/RenderTarget.js';
|
|
30
29
|
import { Color } from '../../math/Color.js';
|
|
31
30
|
import { Vector2 } from '../../math/Vector2.js';
|
|
32
31
|
import { Vector3 } from '../../math/Vector3.js';
|
|
33
32
|
import { Vector4 } from '../../math/Vector4.js';
|
|
34
33
|
import { Float16BufferAttribute } from '../../core/BufferAttribute.js';
|
|
35
|
-
import { IntType, UnsignedIntType, LinearFilter, LinearMipmapNearestFilter, NearestMipmapLinearFilter, LinearMipmapLinearFilter } from '../../constants.js';
|
|
36
34
|
|
|
37
35
|
const rendererCache = new WeakMap();
|
|
38
36
|
|
|
39
|
-
const typeFromLength = new Map( [
|
|
40
|
-
[ 2, 'vec2' ],
|
|
41
|
-
[ 3, 'vec3' ],
|
|
42
|
-
[ 4, 'vec4' ],
|
|
43
|
-
[ 9, 'mat3' ],
|
|
44
|
-
[ 16, 'mat4' ]
|
|
45
|
-
] );
|
|
46
|
-
|
|
47
37
|
const typeFromArray = new Map( [
|
|
48
38
|
[ Int8Array, 'int' ],
|
|
49
39
|
[ Int16Array, 'int' ],
|
|
@@ -56,79 +46,385 @@ const typeFromArray = new Map( [
|
|
|
56
46
|
|
|
57
47
|
const toFloat = ( value ) => {
|
|
58
48
|
|
|
59
|
-
|
|
49
|
+
if ( /e/g.test( value ) ) {
|
|
50
|
+
|
|
51
|
+
return String( value ).replace( /\+/g, '' );
|
|
60
52
|
|
|
61
|
-
|
|
53
|
+
} else {
|
|
54
|
+
|
|
55
|
+
value = Number( value );
|
|
56
|
+
|
|
57
|
+
return value + ( value % 1 ? '' : '.0' );
|
|
58
|
+
|
|
59
|
+
}
|
|
62
60
|
|
|
63
61
|
};
|
|
64
62
|
|
|
63
|
+
/**
|
|
64
|
+
* Base class for builders which generate a shader program based
|
|
65
|
+
* on a 3D object and its node material definition.
|
|
66
|
+
*/
|
|
65
67
|
class NodeBuilder {
|
|
66
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Constructs a new node builder.
|
|
71
|
+
*
|
|
72
|
+
* @param {Object3D} object - The 3D object.
|
|
73
|
+
* @param {Renderer} renderer - The current renderer.
|
|
74
|
+
* @param {NodeParser} parser - A reference to a node parser.
|
|
75
|
+
*/
|
|
67
76
|
constructor( object, renderer, parser ) {
|
|
68
77
|
|
|
78
|
+
/**
|
|
79
|
+
* The 3D object.
|
|
80
|
+
*
|
|
81
|
+
* @type {Object3D}
|
|
82
|
+
*/
|
|
69
83
|
this.object = object;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* The material of the 3D object.
|
|
87
|
+
*
|
|
88
|
+
* @type {?Material}
|
|
89
|
+
*/
|
|
70
90
|
this.material = ( object && object.material ) || null;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* The geometry of the 3D object.
|
|
94
|
+
*
|
|
95
|
+
* @type {?BufferGeometry}
|
|
96
|
+
*/
|
|
71
97
|
this.geometry = ( object && object.geometry ) || null;
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The current renderer.
|
|
101
|
+
*
|
|
102
|
+
* @type {Renderer}
|
|
103
|
+
*/
|
|
72
104
|
this.renderer = renderer;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* A reference to a node parser.
|
|
108
|
+
*
|
|
109
|
+
* @type {NodeParser}
|
|
110
|
+
*/
|
|
73
111
|
this.parser = parser;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* The scene the 3D object belongs to.
|
|
115
|
+
*
|
|
116
|
+
* @type {?Scene}
|
|
117
|
+
* @default null
|
|
118
|
+
*/
|
|
74
119
|
this.scene = null;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* The camera the 3D object is rendered with.
|
|
123
|
+
*
|
|
124
|
+
* @type {?Camera}
|
|
125
|
+
* @default null
|
|
126
|
+
*/
|
|
75
127
|
this.camera = null;
|
|
76
128
|
|
|
129
|
+
/**
|
|
130
|
+
* A list of all nodes the builder is processing
|
|
131
|
+
* for this 3D object.
|
|
132
|
+
*
|
|
133
|
+
* @type {Array<Node>}
|
|
134
|
+
*/
|
|
77
135
|
this.nodes = [];
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A list of all sequential nodes.
|
|
139
|
+
*
|
|
140
|
+
* @type {Array<Node>}
|
|
141
|
+
*/
|
|
142
|
+
this.sequentialNodes = [];
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* A list of all nodes which {@link Node#update} method should be executed.
|
|
146
|
+
*
|
|
147
|
+
* @type {Array<Node>}
|
|
148
|
+
*/
|
|
78
149
|
this.updateNodes = [];
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* A list of all nodes which {@link Node#updateBefore} method should be executed.
|
|
153
|
+
*
|
|
154
|
+
* @type {Array<Node>}
|
|
155
|
+
*/
|
|
79
156
|
this.updateBeforeNodes = [];
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* A list of all nodes which {@link Node#updateAfter} method should be executed.
|
|
160
|
+
*
|
|
161
|
+
* @type {Array<Node>}
|
|
162
|
+
*/
|
|
80
163
|
this.updateAfterNodes = [];
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* A dictionary that assigns each node to a unique hash.
|
|
167
|
+
*
|
|
168
|
+
* @type {Object<number,Node>}
|
|
169
|
+
*/
|
|
81
170
|
this.hashNodes = {};
|
|
82
171
|
|
|
172
|
+
/**
|
|
173
|
+
* A reference to a node material observer.
|
|
174
|
+
*
|
|
175
|
+
* @type {?NodeMaterialObserver}
|
|
176
|
+
* @default null
|
|
177
|
+
*/
|
|
178
|
+
this.observer = null;
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* A reference to the current lights node.
|
|
182
|
+
*
|
|
183
|
+
* @type {?LightsNode}
|
|
184
|
+
* @default null
|
|
185
|
+
*/
|
|
83
186
|
this.lightsNode = null;
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* A reference to the current environment node.
|
|
190
|
+
*
|
|
191
|
+
* @type {?Node}
|
|
192
|
+
* @default null
|
|
193
|
+
*/
|
|
84
194
|
this.environmentNode = null;
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* A reference to the current fog node.
|
|
198
|
+
*
|
|
199
|
+
* @type {?FogNode}
|
|
200
|
+
* @default null
|
|
201
|
+
*/
|
|
85
202
|
this.fogNode = null;
|
|
86
203
|
|
|
204
|
+
/**
|
|
205
|
+
* The current clipping context.
|
|
206
|
+
*
|
|
207
|
+
* @type {?ClippingContext}
|
|
208
|
+
*/
|
|
87
209
|
this.clippingContext = null;
|
|
88
210
|
|
|
211
|
+
/**
|
|
212
|
+
* The generated vertex shader.
|
|
213
|
+
*
|
|
214
|
+
* @type {?string}
|
|
215
|
+
*/
|
|
89
216
|
this.vertexShader = null;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* The generated fragment shader.
|
|
220
|
+
*
|
|
221
|
+
* @type {?string}
|
|
222
|
+
*/
|
|
90
223
|
this.fragmentShader = null;
|
|
224
|
+
|
|
225
|
+
/**
|
|
226
|
+
* The generated compute shader.
|
|
227
|
+
*
|
|
228
|
+
* @type {?string}
|
|
229
|
+
*/
|
|
91
230
|
this.computeShader = null;
|
|
92
231
|
|
|
232
|
+
/**
|
|
233
|
+
* Nodes used in the primary flow of code generation.
|
|
234
|
+
*
|
|
235
|
+
* @type {Object<string,Array<Node>>}
|
|
236
|
+
*/
|
|
93
237
|
this.flowNodes = { vertex: [], fragment: [], compute: [] };
|
|
238
|
+
|
|
239
|
+
/**
|
|
240
|
+
* Nodes code from `.flowNodes`.
|
|
241
|
+
*
|
|
242
|
+
* @type {Object<string,string>}
|
|
243
|
+
*/
|
|
94
244
|
this.flowCode = { vertex: '', fragment: '', compute: '' };
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* This dictionary holds the node uniforms of the builder.
|
|
248
|
+
* The uniforms are maintained in an array for each shader stage.
|
|
249
|
+
*
|
|
250
|
+
* @type {Object}
|
|
251
|
+
*/
|
|
95
252
|
this.uniforms = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* This dictionary holds the output structs of the builder.
|
|
256
|
+
* The structs are maintained in an array for each shader stage.
|
|
257
|
+
*
|
|
258
|
+
* @type {Object}
|
|
259
|
+
*/
|
|
96
260
|
this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* This dictionary holds the bindings for each shader stage.
|
|
264
|
+
*
|
|
265
|
+
* @type {Object}
|
|
266
|
+
*/
|
|
97
267
|
this.bindings = { vertex: {}, fragment: {}, compute: {} };
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* This dictionary maintains the binding indices per bind group.
|
|
271
|
+
*
|
|
272
|
+
* @type {Object}
|
|
273
|
+
*/
|
|
98
274
|
this.bindingsIndexes = {};
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* Reference to the array of bind groups.
|
|
278
|
+
*
|
|
279
|
+
* @type {?Array<BindGroup>}
|
|
280
|
+
*/
|
|
99
281
|
this.bindGroups = null;
|
|
282
|
+
|
|
283
|
+
/**
|
|
284
|
+
* This array holds the node attributes of this builder
|
|
285
|
+
* created via {@link AttributeNode}.
|
|
286
|
+
*
|
|
287
|
+
* @type {Array<NodeAttribute>}
|
|
288
|
+
*/
|
|
100
289
|
this.attributes = [];
|
|
290
|
+
|
|
291
|
+
/**
|
|
292
|
+
* This array holds the node attributes of this builder
|
|
293
|
+
* created via {@link BufferAttributeNode}.
|
|
294
|
+
*
|
|
295
|
+
* @type {Array<NodeAttribute>}
|
|
296
|
+
*/
|
|
101
297
|
this.bufferAttributes = [];
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* This array holds the node varyings of this builder.
|
|
301
|
+
*
|
|
302
|
+
* @type {Array<NodeVarying>}
|
|
303
|
+
*/
|
|
102
304
|
this.varyings = [];
|
|
305
|
+
|
|
306
|
+
/**
|
|
307
|
+
* This dictionary holds the (native) node codes of this builder.
|
|
308
|
+
* The codes are maintained in an array for each shader stage.
|
|
309
|
+
*
|
|
310
|
+
* @type {Object<string,Array<NodeCode>>}
|
|
311
|
+
*/
|
|
103
312
|
this.codes = {};
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* This dictionary holds the node variables of this builder.
|
|
316
|
+
* The variables are maintained in an array for each shader stage.
|
|
317
|
+
*
|
|
318
|
+
* @type {Object<string,Array<NodeVar>>}
|
|
319
|
+
*/
|
|
104
320
|
this.vars = {};
|
|
321
|
+
|
|
322
|
+
/**
|
|
323
|
+
* Current code flow.
|
|
324
|
+
* All code generated in this stack will be stored in `.flow`.
|
|
325
|
+
*
|
|
326
|
+
* @type {{code: string}}
|
|
327
|
+
*/
|
|
105
328
|
this.flow = { code: '' };
|
|
329
|
+
|
|
330
|
+
/**
|
|
331
|
+
* A chain of nodes.
|
|
332
|
+
* Used to check recursive calls in node-graph.
|
|
333
|
+
*
|
|
334
|
+
* @type {Array<Node>}
|
|
335
|
+
*/
|
|
106
336
|
this.chaining = [];
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* The current stack.
|
|
340
|
+
* This reflects the current process in the code block hierarchy,
|
|
341
|
+
* it is useful to know if the current process is inside a conditional for example.
|
|
342
|
+
*
|
|
343
|
+
* @type {StackNode}
|
|
344
|
+
*/
|
|
107
345
|
this.stack = stack();
|
|
346
|
+
|
|
347
|
+
/**
|
|
348
|
+
* List of stack nodes.
|
|
349
|
+
* The current stack hierarchy is stored in an array.
|
|
350
|
+
*
|
|
351
|
+
* @type {Array<StackNode>}
|
|
352
|
+
*/
|
|
108
353
|
this.stacks = [];
|
|
109
|
-
this.tab = '\t';
|
|
110
354
|
|
|
111
|
-
|
|
355
|
+
/**
|
|
356
|
+
* A tab value. Used for shader string generation.
|
|
357
|
+
*
|
|
358
|
+
* @type {string}
|
|
359
|
+
* @default '\t'
|
|
360
|
+
*/
|
|
361
|
+
this.tab = '\t';
|
|
112
362
|
|
|
363
|
+
/**
|
|
364
|
+
* Reference to the current function node.
|
|
365
|
+
*
|
|
366
|
+
* @type {?FunctionNode}
|
|
367
|
+
* @default null
|
|
368
|
+
*/
|
|
113
369
|
this.currentFunctionNode = null;
|
|
114
370
|
|
|
371
|
+
/**
|
|
372
|
+
* The builder's context.
|
|
373
|
+
*
|
|
374
|
+
* @type {Object}
|
|
375
|
+
*/
|
|
115
376
|
this.context = {
|
|
116
|
-
keywords: new NodeKeywords(),
|
|
117
377
|
material: this.material
|
|
118
378
|
};
|
|
119
379
|
|
|
380
|
+
/**
|
|
381
|
+
* The builder's cache.
|
|
382
|
+
*
|
|
383
|
+
* @type {NodeCache}
|
|
384
|
+
*/
|
|
120
385
|
this.cache = new NodeCache();
|
|
386
|
+
|
|
387
|
+
/**
|
|
388
|
+
* Since the {@link NodeBuilder#cache} might be temporarily
|
|
389
|
+
* overwritten by other caches, this member retains the reference
|
|
390
|
+
* to the builder's own cache.
|
|
391
|
+
*
|
|
392
|
+
* @type {NodeCache}
|
|
393
|
+
* @default this.cache
|
|
394
|
+
*/
|
|
121
395
|
this.globalCache = this.cache;
|
|
122
396
|
|
|
123
397
|
this.flowsData = new WeakMap();
|
|
124
398
|
|
|
399
|
+
/**
|
|
400
|
+
* The current shader stage.
|
|
401
|
+
*
|
|
402
|
+
* @type {?('vertex'|'fragment'|'compute'|'any')}
|
|
403
|
+
*/
|
|
125
404
|
this.shaderStage = null;
|
|
405
|
+
|
|
406
|
+
/**
|
|
407
|
+
* The current build stage.
|
|
408
|
+
*
|
|
409
|
+
* @type {?('setup'|'analyze'|'generate')}
|
|
410
|
+
*/
|
|
126
411
|
this.buildStage = null;
|
|
127
412
|
|
|
413
|
+
/**
|
|
414
|
+
* Whether comparison in shader code are generated with methods or not.
|
|
415
|
+
*
|
|
416
|
+
* @type {boolean}
|
|
417
|
+
* @default false
|
|
418
|
+
*/
|
|
128
419
|
this.useComparisonMethod = false;
|
|
129
420
|
|
|
130
421
|
}
|
|
131
422
|
|
|
423
|
+
/**
|
|
424
|
+
* Returns the bind groups of the current renderer.
|
|
425
|
+
*
|
|
426
|
+
* @return {ChainMap} The cache.
|
|
427
|
+
*/
|
|
132
428
|
getBindGroupsCache() {
|
|
133
429
|
|
|
134
430
|
let bindGroupsCache = rendererCache.get( this.renderer );
|
|
@@ -145,32 +441,64 @@ class NodeBuilder {
|
|
|
145
441
|
|
|
146
442
|
}
|
|
147
443
|
|
|
444
|
+
/**
|
|
445
|
+
* Factory method for creating an instance of {@link RenderTarget} with the given
|
|
446
|
+
* dimensions and options.
|
|
447
|
+
*
|
|
448
|
+
* @param {number} width - The width of the render target.
|
|
449
|
+
* @param {number} height - The height of the render target.
|
|
450
|
+
* @param {Object} options - The options of the render target.
|
|
451
|
+
* @return {RenderTarget} The render target.
|
|
452
|
+
*/
|
|
148
453
|
createRenderTarget( width, height, options ) {
|
|
149
454
|
|
|
150
455
|
return new RenderTarget( width, height, options );
|
|
151
456
|
|
|
152
457
|
}
|
|
153
458
|
|
|
459
|
+
/**
|
|
460
|
+
* Factory method for creating an instance of {@link CubeRenderTarget} with the given
|
|
461
|
+
* dimensions and options.
|
|
462
|
+
*
|
|
463
|
+
* @param {number} size - The size of the cube render target.
|
|
464
|
+
* @param {Object} options - The options of the cube render target.
|
|
465
|
+
* @return {CubeRenderTarget} The cube render target.
|
|
466
|
+
*/
|
|
154
467
|
createCubeRenderTarget( size, options ) {
|
|
155
468
|
|
|
156
469
|
return new CubeRenderTarget( size, options );
|
|
157
470
|
|
|
158
471
|
}
|
|
159
472
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
}
|
|
167
|
-
|
|
473
|
+
/**
|
|
474
|
+
* Whether the given node is included in the internal array of nodes or not.
|
|
475
|
+
*
|
|
476
|
+
* @param {Node} node - The node to test.
|
|
477
|
+
* @return {boolean} Whether the given node is included in the internal array of nodes or not.
|
|
478
|
+
*/
|
|
168
479
|
includes( node ) {
|
|
169
480
|
|
|
170
481
|
return this.nodes.includes( node );
|
|
171
482
|
|
|
172
483
|
}
|
|
173
484
|
|
|
485
|
+
/**
|
|
486
|
+
* Returns the output struct name which is required by
|
|
487
|
+
* {@link OutputStructNode}.
|
|
488
|
+
*
|
|
489
|
+
* @abstract
|
|
490
|
+
* @return {string} The name of the output struct.
|
|
491
|
+
*/
|
|
492
|
+
getOutputStructName() {}
|
|
493
|
+
|
|
494
|
+
/**
|
|
495
|
+
* Returns a bind group for the given group name and binding.
|
|
496
|
+
*
|
|
497
|
+
* @private
|
|
498
|
+
* @param {string} groupName - The group name.
|
|
499
|
+
* @param {Array<NodeUniformsGroup>} bindings - List of bindings.
|
|
500
|
+
* @return {BindGroup} The bind group
|
|
501
|
+
*/
|
|
174
502
|
_getBindGroup( groupName, bindings ) {
|
|
175
503
|
|
|
176
504
|
const bindGroupsCache = this.getBindGroupsCache();
|
|
@@ -199,7 +527,7 @@ class NodeBuilder {
|
|
|
199
527
|
|
|
200
528
|
if ( bindGroup === undefined ) {
|
|
201
529
|
|
|
202
|
-
bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
|
|
530
|
+
bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray );
|
|
203
531
|
|
|
204
532
|
bindGroupsCache.set( bindingsArray, bindGroup );
|
|
205
533
|
|
|
@@ -207,7 +535,7 @@ class NodeBuilder {
|
|
|
207
535
|
|
|
208
536
|
} else {
|
|
209
537
|
|
|
210
|
-
bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group );
|
|
538
|
+
bindGroup = new BindGroup( groupName, bindingsArray, this.bindingsIndexes[ groupName ].group, bindingsArray );
|
|
211
539
|
|
|
212
540
|
}
|
|
213
541
|
|
|
@@ -215,6 +543,13 @@ class NodeBuilder {
|
|
|
215
543
|
|
|
216
544
|
}
|
|
217
545
|
|
|
546
|
+
/**
|
|
547
|
+
* Returns an array of node uniform groups for the given group name and shader stage.
|
|
548
|
+
*
|
|
549
|
+
* @param {string} groupName - The group name.
|
|
550
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
551
|
+
* @return {Array<NodeUniformsGroup>} The array of node uniform groups.
|
|
552
|
+
*/
|
|
218
553
|
getBindGroupArray( groupName, shaderStage ) {
|
|
219
554
|
|
|
220
555
|
const bindings = this.bindings[ shaderStage ];
|
|
@@ -237,6 +572,11 @@ class NodeBuilder {
|
|
|
237
572
|
|
|
238
573
|
}
|
|
239
574
|
|
|
575
|
+
/**
|
|
576
|
+
* Returns a list bindings of all shader stages separated by groups.
|
|
577
|
+
*
|
|
578
|
+
* @return {Array<BindGroup>} The list of bindings.
|
|
579
|
+
*/
|
|
240
580
|
getBindings() {
|
|
241
581
|
|
|
242
582
|
let bindingsGroups = this.bindGroups;
|
|
@@ -279,12 +619,44 @@ class NodeBuilder {
|
|
|
279
619
|
|
|
280
620
|
}
|
|
281
621
|
|
|
622
|
+
/**
|
|
623
|
+
* Sorts the bind groups and updates {@link NodeBuilder#bindingsIndexes}.
|
|
624
|
+
*/
|
|
625
|
+
sortBindingGroups() {
|
|
626
|
+
|
|
627
|
+
const bindingsGroups = this.getBindings();
|
|
628
|
+
|
|
629
|
+
bindingsGroups.sort( ( a, b ) => ( a.bindings[ 0 ].groupNode.order - b.bindings[ 0 ].groupNode.order ) );
|
|
630
|
+
|
|
631
|
+
for ( let i = 0; i < bindingsGroups.length; i ++ ) {
|
|
632
|
+
|
|
633
|
+
const bindingGroup = bindingsGroups[ i ];
|
|
634
|
+
this.bindingsIndexes[ bindingGroup.name ].group = i;
|
|
635
|
+
|
|
636
|
+
bindingGroup.index = i;
|
|
637
|
+
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
}
|
|
641
|
+
|
|
642
|
+
/**
|
|
643
|
+
* The builder maintains each node in a hash-based dictionary.
|
|
644
|
+
* This method sets the given node (value) with the given hash (key) into this dictionary.
|
|
645
|
+
*
|
|
646
|
+
* @param {Node} node - The node to add.
|
|
647
|
+
* @param {number} hash - The hash of the node.
|
|
648
|
+
*/
|
|
282
649
|
setHashNode( node, hash ) {
|
|
283
650
|
|
|
284
651
|
this.hashNodes[ hash ] = node;
|
|
285
652
|
|
|
286
653
|
}
|
|
287
654
|
|
|
655
|
+
/**
|
|
656
|
+
* Adds a node to this builder.
|
|
657
|
+
*
|
|
658
|
+
* @param {Node} node - The node to add.
|
|
659
|
+
*/
|
|
288
660
|
addNode( node ) {
|
|
289
661
|
|
|
290
662
|
if ( this.nodes.includes( node ) === false ) {
|
|
@@ -297,13 +669,31 @@ class NodeBuilder {
|
|
|
297
669
|
|
|
298
670
|
}
|
|
299
671
|
|
|
672
|
+
/**
|
|
673
|
+
* It is used to add Nodes that will be used as FRAME and RENDER events,
|
|
674
|
+
* and need to follow a certain sequence in the calls to work correctly.
|
|
675
|
+
* This function should be called after 'setup()' in the 'build()' process to ensure that the child nodes are processed first.
|
|
676
|
+
*
|
|
677
|
+
* @param {Node} node - The node to add.
|
|
678
|
+
*/
|
|
679
|
+
addSequentialNode( node ) {
|
|
680
|
+
|
|
681
|
+
if ( this.sequentialNodes.includes( node ) === false ) {
|
|
682
|
+
|
|
683
|
+
this.sequentialNodes.push( node );
|
|
684
|
+
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
/**
|
|
690
|
+
* Checks the update types of nodes
|
|
691
|
+
*/
|
|
300
692
|
buildUpdateNodes() {
|
|
301
693
|
|
|
302
694
|
for ( const node of this.nodes ) {
|
|
303
695
|
|
|
304
696
|
const updateType = node.getUpdateType();
|
|
305
|
-
const updateBeforeType = node.getUpdateBeforeType();
|
|
306
|
-
const updateAfterType = node.getUpdateAfterType();
|
|
307
697
|
|
|
308
698
|
if ( updateType !== NodeUpdateType.NONE ) {
|
|
309
699
|
|
|
@@ -311,15 +701,22 @@ class NodeBuilder {
|
|
|
311
701
|
|
|
312
702
|
}
|
|
313
703
|
|
|
704
|
+
}
|
|
705
|
+
|
|
706
|
+
for ( const node of this.sequentialNodes ) {
|
|
707
|
+
|
|
708
|
+
const updateBeforeType = node.getUpdateBeforeType();
|
|
709
|
+
const updateAfterType = node.getUpdateAfterType();
|
|
710
|
+
|
|
314
711
|
if ( updateBeforeType !== NodeUpdateType.NONE ) {
|
|
315
712
|
|
|
316
|
-
this.updateBeforeNodes.push( node );
|
|
713
|
+
this.updateBeforeNodes.push( node.getSelf() );
|
|
317
714
|
|
|
318
715
|
}
|
|
319
716
|
|
|
320
717
|
if ( updateAfterType !== NodeUpdateType.NONE ) {
|
|
321
718
|
|
|
322
|
-
this.updateAfterNodes.push( node );
|
|
719
|
+
this.updateAfterNodes.push( node.getSelf() );
|
|
323
720
|
|
|
324
721
|
}
|
|
325
722
|
|
|
@@ -327,12 +724,24 @@ class NodeBuilder {
|
|
|
327
724
|
|
|
328
725
|
}
|
|
329
726
|
|
|
727
|
+
/**
|
|
728
|
+
* A reference the current node which is the
|
|
729
|
+
* last node in the chain of nodes.
|
|
730
|
+
*
|
|
731
|
+
* @type {Node}
|
|
732
|
+
*/
|
|
330
733
|
get currentNode() {
|
|
331
734
|
|
|
332
735
|
return this.chaining[ this.chaining.length - 1 ];
|
|
333
736
|
|
|
334
737
|
}
|
|
335
738
|
|
|
739
|
+
/**
|
|
740
|
+
* Whether the given texture is filtered or not.
|
|
741
|
+
*
|
|
742
|
+
* @param {Texture} texture - The texture to check.
|
|
743
|
+
* @return {boolean} Whether the given texture is filtered or not.
|
|
744
|
+
*/
|
|
336
745
|
isFilteredTexture( texture ) {
|
|
337
746
|
|
|
338
747
|
return ( texture.magFilter === LinearFilter || texture.magFilter === LinearMipmapNearestFilter || texture.magFilter === NearestMipmapLinearFilter || texture.magFilter === LinearMipmapLinearFilter ||
|
|
@@ -340,6 +749,12 @@ class NodeBuilder {
|
|
|
340
749
|
|
|
341
750
|
}
|
|
342
751
|
|
|
752
|
+
/**
|
|
753
|
+
* Adds the given node to the internal node chain.
|
|
754
|
+
* This is used to check recursive calls in node-graph.
|
|
755
|
+
*
|
|
756
|
+
* @param {Node} node - The node to add.
|
|
757
|
+
*/
|
|
343
758
|
addChain( node ) {
|
|
344
759
|
|
|
345
760
|
/*
|
|
@@ -354,6 +769,11 @@ class NodeBuilder {
|
|
|
354
769
|
|
|
355
770
|
}
|
|
356
771
|
|
|
772
|
+
/**
|
|
773
|
+
* Removes the given node from the internal node chain.
|
|
774
|
+
*
|
|
775
|
+
* @param {Node} node - The node to remove.
|
|
776
|
+
*/
|
|
357
777
|
removeChain( node ) {
|
|
358
778
|
|
|
359
779
|
const lastChain = this.chaining.pop();
|
|
@@ -366,18 +786,40 @@ class NodeBuilder {
|
|
|
366
786
|
|
|
367
787
|
}
|
|
368
788
|
|
|
789
|
+
/**
|
|
790
|
+
* Returns the native shader method name for a given generic name. E.g.
|
|
791
|
+
* the method name `textureDimensions` matches the WGSL name but must be
|
|
792
|
+
* resolved to `textureSize` in GLSL.
|
|
793
|
+
*
|
|
794
|
+
* @abstract
|
|
795
|
+
* @param {string} method - The method name to resolve.
|
|
796
|
+
* @return {string} The resolved method name.
|
|
797
|
+
*/
|
|
369
798
|
getMethod( method ) {
|
|
370
799
|
|
|
371
800
|
return method;
|
|
372
801
|
|
|
373
802
|
}
|
|
374
803
|
|
|
804
|
+
/**
|
|
805
|
+
* Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
|
|
806
|
+
*
|
|
807
|
+
* @param {number} hash - The hash of the node.
|
|
808
|
+
* @return {Node} The found node.
|
|
809
|
+
*/
|
|
375
810
|
getNodeFromHash( hash ) {
|
|
376
811
|
|
|
377
812
|
return this.hashNodes[ hash ];
|
|
378
813
|
|
|
379
814
|
}
|
|
380
815
|
|
|
816
|
+
/**
|
|
817
|
+
* Adds the Node to a target flow so that it can generate code in the 'generate' process.
|
|
818
|
+
*
|
|
819
|
+
* @param {('vertex'|'fragment'|'compute')} shaderStage - The shader stage.
|
|
820
|
+
* @param {Node} node - The node to add.
|
|
821
|
+
* @return {Node} The node.
|
|
822
|
+
*/
|
|
381
823
|
addFlow( shaderStage, node ) {
|
|
382
824
|
|
|
383
825
|
this.flowNodes[ shaderStage ].push( node );
|
|
@@ -386,41 +828,73 @@ class NodeBuilder {
|
|
|
386
828
|
|
|
387
829
|
}
|
|
388
830
|
|
|
831
|
+
/**
|
|
832
|
+
* Sets builder's context.
|
|
833
|
+
*
|
|
834
|
+
* @param {Object} context - The context to set.
|
|
835
|
+
*/
|
|
389
836
|
setContext( context ) {
|
|
390
837
|
|
|
391
838
|
this.context = context;
|
|
392
839
|
|
|
393
840
|
}
|
|
394
841
|
|
|
842
|
+
/**
|
|
843
|
+
* Returns the builder's current context.
|
|
844
|
+
*
|
|
845
|
+
* @return {Object} The builder's current context.
|
|
846
|
+
*/
|
|
395
847
|
getContext() {
|
|
396
848
|
|
|
397
849
|
return this.context;
|
|
398
850
|
|
|
399
851
|
}
|
|
400
852
|
|
|
853
|
+
/**
|
|
854
|
+
* Gets a context used in shader construction that can be shared across different materials.
|
|
855
|
+
* This is necessary since the renderer cache can reuse shaders generated in one material and use them in another.
|
|
856
|
+
*
|
|
857
|
+
* @return {Object} The builder's current context without material.
|
|
858
|
+
*/
|
|
401
859
|
getSharedContext() {
|
|
402
860
|
|
|
403
861
|
const context = { ...this.context };
|
|
404
862
|
|
|
405
|
-
delete context.keywords;
|
|
406
863
|
delete context.material;
|
|
407
864
|
|
|
408
865
|
return this.context;
|
|
409
866
|
|
|
410
867
|
}
|
|
411
868
|
|
|
869
|
+
/**
|
|
870
|
+
* Sets builder's cache.
|
|
871
|
+
*
|
|
872
|
+
* @param {NodeCache} cache - The cache to set.
|
|
873
|
+
*/
|
|
412
874
|
setCache( cache ) {
|
|
413
875
|
|
|
414
876
|
this.cache = cache;
|
|
415
877
|
|
|
416
878
|
}
|
|
417
879
|
|
|
880
|
+
/**
|
|
881
|
+
* Returns the builder's current cache.
|
|
882
|
+
*
|
|
883
|
+
* @return {NodeCache} The builder's current cache.
|
|
884
|
+
*/
|
|
418
885
|
getCache() {
|
|
419
886
|
|
|
420
887
|
return this.cache;
|
|
421
888
|
|
|
422
889
|
}
|
|
423
890
|
|
|
891
|
+
/**
|
|
892
|
+
* Returns a cache for the given node.
|
|
893
|
+
*
|
|
894
|
+
* @param {Node} node - The node.
|
|
895
|
+
* @param {boolean} [parent=true] - Whether this node refers to a shared parent cache or not.
|
|
896
|
+
* @return {NodeCache} The cache.
|
|
897
|
+
*/
|
|
424
898
|
getCacheFromNode( node, parent = true ) {
|
|
425
899
|
|
|
426
900
|
const data = this.getDataFromNode( node );
|
|
@@ -430,60 +904,229 @@ class NodeBuilder {
|
|
|
430
904
|
|
|
431
905
|
}
|
|
432
906
|
|
|
907
|
+
/**
|
|
908
|
+
* Whether the requested feature is available or not.
|
|
909
|
+
*
|
|
910
|
+
* @abstract
|
|
911
|
+
* @param {string} name - The requested feature.
|
|
912
|
+
* @return {boolean} Whether the requested feature is supported or not.
|
|
913
|
+
*/
|
|
433
914
|
isAvailable( /*name*/ ) {
|
|
434
915
|
|
|
435
916
|
return false;
|
|
436
917
|
|
|
437
918
|
}
|
|
438
919
|
|
|
920
|
+
/**
|
|
921
|
+
* Returns the vertexIndex input variable as a native shader string.
|
|
922
|
+
*
|
|
923
|
+
* @abstract
|
|
924
|
+
* @return {string} The instanceIndex shader string.
|
|
925
|
+
*/
|
|
439
926
|
getVertexIndex() {
|
|
440
927
|
|
|
441
928
|
console.warn( 'Abstract function.' );
|
|
442
929
|
|
|
443
930
|
}
|
|
444
931
|
|
|
932
|
+
/**
|
|
933
|
+
* Returns the instanceIndex input variable as a native shader string.
|
|
934
|
+
*
|
|
935
|
+
* @abstract
|
|
936
|
+
* @return {string} The instanceIndex shader string.
|
|
937
|
+
*/
|
|
445
938
|
getInstanceIndex() {
|
|
446
939
|
|
|
447
940
|
console.warn( 'Abstract function.' );
|
|
448
941
|
|
|
449
942
|
}
|
|
450
943
|
|
|
944
|
+
/**
|
|
945
|
+
* Returns the drawIndex input variable as a native shader string.
|
|
946
|
+
* Only relevant for WebGL and its `WEBGL_multi_draw` extension.
|
|
947
|
+
*
|
|
948
|
+
* @abstract
|
|
949
|
+
* @return {string} The drawIndex shader string.
|
|
950
|
+
*/
|
|
451
951
|
getDrawIndex() {
|
|
452
952
|
|
|
453
953
|
console.warn( 'Abstract function.' );
|
|
454
954
|
|
|
455
955
|
}
|
|
456
956
|
|
|
957
|
+
/**
|
|
958
|
+
* Returns the frontFacing input variable as a native shader string.
|
|
959
|
+
*
|
|
960
|
+
* @abstract
|
|
961
|
+
* @return {string} The frontFacing shader string.
|
|
962
|
+
*/
|
|
457
963
|
getFrontFacing() {
|
|
458
964
|
|
|
459
965
|
console.warn( 'Abstract function.' );
|
|
460
966
|
|
|
461
967
|
}
|
|
462
968
|
|
|
969
|
+
/**
|
|
970
|
+
* Returns the fragCoord input variable as a native shader string.
|
|
971
|
+
*
|
|
972
|
+
* @abstract
|
|
973
|
+
* @return {string} The fragCoord shader string.
|
|
974
|
+
*/
|
|
463
975
|
getFragCoord() {
|
|
464
976
|
|
|
465
977
|
console.warn( 'Abstract function.' );
|
|
466
978
|
|
|
467
979
|
}
|
|
468
980
|
|
|
981
|
+
/**
|
|
982
|
+
* Whether to flip texture data along its vertical axis or not. WebGL needs
|
|
983
|
+
* this method evaluate to `true`, WebGPU to `false`.
|
|
984
|
+
*
|
|
985
|
+
* @abstract
|
|
986
|
+
* @return {boolean} Whether to flip texture data along its vertical axis or not.
|
|
987
|
+
*/
|
|
469
988
|
isFlipY() {
|
|
470
989
|
|
|
471
990
|
return false;
|
|
472
991
|
|
|
473
992
|
}
|
|
474
993
|
|
|
994
|
+
/**
|
|
995
|
+
* Calling this method increases the usage count for the given node by one.
|
|
996
|
+
*
|
|
997
|
+
* @param {Node} node - The node to increase the usage count for.
|
|
998
|
+
* @return {number} The updated usage count.
|
|
999
|
+
*/
|
|
1000
|
+
increaseUsage( node ) {
|
|
1001
|
+
|
|
1002
|
+
const nodeData = this.getDataFromNode( node );
|
|
1003
|
+
nodeData.usageCount = nodeData.usageCount === undefined ? 1 : nodeData.usageCount + 1;
|
|
1004
|
+
|
|
1005
|
+
return nodeData.usageCount;
|
|
1006
|
+
|
|
1007
|
+
}
|
|
1008
|
+
|
|
1009
|
+
/**
|
|
1010
|
+
* Generates a texture sample shader string for the given texture data.
|
|
1011
|
+
*
|
|
1012
|
+
* @abstract
|
|
1013
|
+
* @param {Texture} texture - The texture.
|
|
1014
|
+
* @param {string} textureProperty - The texture property name.
|
|
1015
|
+
* @param {string} uvSnippet - Snippet defining the texture coordinates.
|
|
1016
|
+
* @return {string} The generated shader string.
|
|
1017
|
+
*/
|
|
475
1018
|
generateTexture( /* texture, textureProperty, uvSnippet */ ) {
|
|
476
1019
|
|
|
477
1020
|
console.warn( 'Abstract function.' );
|
|
478
1021
|
|
|
479
1022
|
}
|
|
480
1023
|
|
|
481
|
-
|
|
1024
|
+
/**
|
|
1025
|
+
* Generates a texture LOD shader string for the given texture data.
|
|
1026
|
+
*
|
|
1027
|
+
* @abstract
|
|
1028
|
+
* @param {Texture} texture - The texture.
|
|
1029
|
+
* @param {string} textureProperty - The texture property name.
|
|
1030
|
+
* @param {string} uvSnippet - Snippet defining the texture coordinates.
|
|
1031
|
+
* @param {?string} depthSnippet - Snippet defining the 0-based texture array index to sample.
|
|
1032
|
+
* @param {string} levelSnippet - Snippet defining the mip level.
|
|
1033
|
+
* @return {string} The generated shader string.
|
|
1034
|
+
*/
|
|
1035
|
+
generateTextureLod( /* texture, textureProperty, uvSnippet, depthSnippet, levelSnippet */ ) {
|
|
482
1036
|
|
|
483
1037
|
console.warn( 'Abstract function.' );
|
|
484
1038
|
|
|
485
1039
|
}
|
|
486
1040
|
|
|
1041
|
+
/**
|
|
1042
|
+
* Generates the array declaration string.
|
|
1043
|
+
*
|
|
1044
|
+
* @param {string} type - The type.
|
|
1045
|
+
* @param {?number} [count] - The count.
|
|
1046
|
+
* @return {string} The generated value as a shader string.
|
|
1047
|
+
*/
|
|
1048
|
+
generateArrayDeclaration( type, count ) {
|
|
1049
|
+
|
|
1050
|
+
return this.getType( type ) + '[ ' + count + ' ]';
|
|
1051
|
+
|
|
1052
|
+
}
|
|
1053
|
+
|
|
1054
|
+
/**
|
|
1055
|
+
* Generates the array shader string for the given type and value.
|
|
1056
|
+
*
|
|
1057
|
+
* @param {string} type - The type.
|
|
1058
|
+
* @param {?number} [count] - The count.
|
|
1059
|
+
* @param {?Array<Node>} [values=null] - The default values.
|
|
1060
|
+
* @return {string} The generated value as a shader string.
|
|
1061
|
+
*/
|
|
1062
|
+
generateArray( type, count, values = null ) {
|
|
1063
|
+
|
|
1064
|
+
let snippet = this.generateArrayDeclaration( type, count ) + '( ';
|
|
1065
|
+
|
|
1066
|
+
for ( let i = 0; i < count; i ++ ) {
|
|
1067
|
+
|
|
1068
|
+
const value = values ? values[ i ] : null;
|
|
1069
|
+
|
|
1070
|
+
if ( value !== null ) {
|
|
1071
|
+
|
|
1072
|
+
snippet += value.build( this, type );
|
|
1073
|
+
|
|
1074
|
+
} else {
|
|
1075
|
+
|
|
1076
|
+
snippet += this.generateConst( type );
|
|
1077
|
+
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
if ( i < count - 1 ) snippet += ', ';
|
|
1081
|
+
|
|
1082
|
+
}
|
|
1083
|
+
|
|
1084
|
+
snippet += ' )';
|
|
1085
|
+
|
|
1086
|
+
return snippet;
|
|
1087
|
+
|
|
1088
|
+
}
|
|
1089
|
+
|
|
1090
|
+
/**
|
|
1091
|
+
* Generates the struct shader string.
|
|
1092
|
+
*
|
|
1093
|
+
* @param {string} type - The type.
|
|
1094
|
+
* @param {Array<Object>} [membersLayout] - The count.
|
|
1095
|
+
* @param {?Array<Node>} [values=null] - The default values.
|
|
1096
|
+
* @return {string} The generated value as a shader string.
|
|
1097
|
+
*/
|
|
1098
|
+
generateStruct( type, membersLayout, values = null ) {
|
|
1099
|
+
|
|
1100
|
+
const snippets = [];
|
|
1101
|
+
|
|
1102
|
+
for ( const member of membersLayout ) {
|
|
1103
|
+
|
|
1104
|
+
const { name, type } = member;
|
|
1105
|
+
|
|
1106
|
+
if ( values && values[ name ] && values[ name ].isNode ) {
|
|
1107
|
+
|
|
1108
|
+
snippets.push( values[ name ].build( this, type ) );
|
|
1109
|
+
|
|
1110
|
+
} else {
|
|
1111
|
+
|
|
1112
|
+
snippets.push( this.generateConst( type ) );
|
|
1113
|
+
|
|
1114
|
+
}
|
|
1115
|
+
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
return type + '( ' + snippets.join( ', ' ) + ' )';
|
|
1119
|
+
|
|
1120
|
+
}
|
|
1121
|
+
|
|
1122
|
+
|
|
1123
|
+
/**
|
|
1124
|
+
* Generates the shader string for the given type and value.
|
|
1125
|
+
*
|
|
1126
|
+
* @param {string} type - The type.
|
|
1127
|
+
* @param {?any} [value=null] - The value.
|
|
1128
|
+
* @return {string} The generated value as a shader string.
|
|
1129
|
+
*/
|
|
487
1130
|
generateConst( type, value = null ) {
|
|
488
1131
|
|
|
489
1132
|
if ( value === null ) {
|
|
@@ -517,11 +1160,11 @@ class NodeBuilder {
|
|
|
517
1160
|
|
|
518
1161
|
return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) } )`;
|
|
519
1162
|
|
|
520
|
-
} else if ( typeLength === 4 ) {
|
|
1163
|
+
} else if ( typeLength === 4 && type !== 'mat2' ) {
|
|
521
1164
|
|
|
522
1165
|
return `${ this.getType( type ) }( ${ generateConst( value.x ) }, ${ generateConst( value.y ) }, ${ generateConst( value.z ) }, ${ generateConst( value.w ) } )`;
|
|
523
1166
|
|
|
524
|
-
} else if ( typeLength
|
|
1167
|
+
} else if ( typeLength >= 4 && value && ( value.isMatrix2 || value.isMatrix3 || value.isMatrix4 ) ) {
|
|
525
1168
|
|
|
526
1169
|
return `${ this.getType( type ) }( ${ value.elements.map( generateConst ).join( ', ' ) } )`;
|
|
527
1170
|
|
|
@@ -535,6 +1178,13 @@ class NodeBuilder {
|
|
|
535
1178
|
|
|
536
1179
|
}
|
|
537
1180
|
|
|
1181
|
+
/**
|
|
1182
|
+
* It might be necessary to convert certain data types to different ones
|
|
1183
|
+
* so this method can be used to hide the conversion.
|
|
1184
|
+
*
|
|
1185
|
+
* @param {string} type - The type.
|
|
1186
|
+
* @return {string} The updated type.
|
|
1187
|
+
*/
|
|
538
1188
|
getType( type ) {
|
|
539
1189
|
|
|
540
1190
|
if ( type === 'color' ) return 'vec3';
|
|
@@ -543,12 +1193,25 @@ class NodeBuilder {
|
|
|
543
1193
|
|
|
544
1194
|
}
|
|
545
1195
|
|
|
1196
|
+
/**
|
|
1197
|
+
* Whether the given attribute name is defined in the geometry or not.
|
|
1198
|
+
*
|
|
1199
|
+
* @param {string} name - The attribute name.
|
|
1200
|
+
* @return {boolean} Whether the given attribute name is defined in the geometry.
|
|
1201
|
+
*/
|
|
546
1202
|
hasGeometryAttribute( name ) {
|
|
547
1203
|
|
|
548
1204
|
return this.geometry && this.geometry.getAttribute( name ) !== undefined;
|
|
549
1205
|
|
|
550
1206
|
}
|
|
551
1207
|
|
|
1208
|
+
/**
|
|
1209
|
+
* Returns a node attribute for the given name and type.
|
|
1210
|
+
*
|
|
1211
|
+
* @param {string} name - The attribute's name.
|
|
1212
|
+
* @param {string} type - The attribute's type.
|
|
1213
|
+
* @return {NodeAttribute} The node attribute.
|
|
1214
|
+
*/
|
|
552
1215
|
getAttribute( name, type ) {
|
|
553
1216
|
|
|
554
1217
|
const attributes = this.attributes;
|
|
@@ -575,36 +1238,74 @@ class NodeBuilder {
|
|
|
575
1238
|
|
|
576
1239
|
}
|
|
577
1240
|
|
|
1241
|
+
/**
|
|
1242
|
+
* Returns for the given node and shader stage the property name for the shader.
|
|
1243
|
+
*
|
|
1244
|
+
* @param {Node} node - The node.
|
|
1245
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
1246
|
+
* @return {string} The property name.
|
|
1247
|
+
*/
|
|
578
1248
|
getPropertyName( node/*, shaderStage*/ ) {
|
|
579
1249
|
|
|
580
1250
|
return node.name;
|
|
581
1251
|
|
|
582
1252
|
}
|
|
583
1253
|
|
|
1254
|
+
/**
|
|
1255
|
+
* Whether the given type is a vector type or not.
|
|
1256
|
+
*
|
|
1257
|
+
* @param {string} type - The type to check.
|
|
1258
|
+
* @return {boolean} Whether the given type is a vector type or not.
|
|
1259
|
+
*/
|
|
584
1260
|
isVector( type ) {
|
|
585
1261
|
|
|
586
1262
|
return /vec\d/.test( type );
|
|
587
1263
|
|
|
588
1264
|
}
|
|
589
1265
|
|
|
1266
|
+
/**
|
|
1267
|
+
* Whether the given type is a matrix type or not.
|
|
1268
|
+
*
|
|
1269
|
+
* @param {string} type - The type to check.
|
|
1270
|
+
* @return {boolean} Whether the given type is a matrix type or not.
|
|
1271
|
+
*/
|
|
590
1272
|
isMatrix( type ) {
|
|
591
1273
|
|
|
592
1274
|
return /mat\d/.test( type );
|
|
593
1275
|
|
|
594
1276
|
}
|
|
595
1277
|
|
|
1278
|
+
/**
|
|
1279
|
+
* Whether the given type is a reference type or not.
|
|
1280
|
+
*
|
|
1281
|
+
* @param {string} type - The type to check.
|
|
1282
|
+
* @return {boolean} Whether the given type is a reference type or not.
|
|
1283
|
+
*/
|
|
596
1284
|
isReference( type ) {
|
|
597
1285
|
|
|
598
1286
|
return type === 'void' || type === 'property' || type === 'sampler' || type === 'texture' || type === 'cubeTexture' || type === 'storageTexture' || type === 'depthTexture' || type === 'texture3D';
|
|
599
1287
|
|
|
600
1288
|
}
|
|
601
1289
|
|
|
602
|
-
|
|
1290
|
+
/**
|
|
1291
|
+
* Checks if the given texture requires a manual conversion to the working color space.
|
|
1292
|
+
*
|
|
1293
|
+
* @abstract
|
|
1294
|
+
* @param {Texture} texture - The texture to check.
|
|
1295
|
+
* @return {boolean} Whether the given texture requires a conversion to working color space or not.
|
|
1296
|
+
*/
|
|
1297
|
+
needsToWorkingColorSpace( /*texture*/ ) {
|
|
603
1298
|
|
|
604
1299
|
return false;
|
|
605
1300
|
|
|
606
1301
|
}
|
|
607
1302
|
|
|
1303
|
+
/**
|
|
1304
|
+
* Returns the component type of a given texture.
|
|
1305
|
+
*
|
|
1306
|
+
* @param {Texture} texture - The texture.
|
|
1307
|
+
* @return {string} The component type.
|
|
1308
|
+
*/
|
|
608
1309
|
getComponentTypeFromTexture( texture ) {
|
|
609
1310
|
|
|
610
1311
|
const type = texture.type;
|
|
@@ -620,6 +1321,12 @@ class NodeBuilder {
|
|
|
620
1321
|
|
|
621
1322
|
}
|
|
622
1323
|
|
|
1324
|
+
/**
|
|
1325
|
+
* Returns the element type for a given type.
|
|
1326
|
+
*
|
|
1327
|
+
* @param {string} type - The type.
|
|
1328
|
+
* @return {string} The element type.
|
|
1329
|
+
*/
|
|
623
1330
|
getElementType( type ) {
|
|
624
1331
|
|
|
625
1332
|
if ( type === 'mat2' ) return 'vec2';
|
|
@@ -630,6 +1337,12 @@ class NodeBuilder {
|
|
|
630
1337
|
|
|
631
1338
|
}
|
|
632
1339
|
|
|
1340
|
+
/**
|
|
1341
|
+
* Returns the component type for a given type.
|
|
1342
|
+
*
|
|
1343
|
+
* @param {string} type - The type.
|
|
1344
|
+
* @return {string} The component type.
|
|
1345
|
+
*/
|
|
633
1346
|
getComponentType( type ) {
|
|
634
1347
|
|
|
635
1348
|
type = this.getVectorType( type );
|
|
@@ -648,6 +1361,12 @@ class NodeBuilder {
|
|
|
648
1361
|
|
|
649
1362
|
}
|
|
650
1363
|
|
|
1364
|
+
/**
|
|
1365
|
+
* Returns the vector type for a given type.
|
|
1366
|
+
*
|
|
1367
|
+
* @param {string} type - The type.
|
|
1368
|
+
* @return {string} The vector type.
|
|
1369
|
+
*/
|
|
651
1370
|
getVectorType( type ) {
|
|
652
1371
|
|
|
653
1372
|
if ( type === 'color' ) return 'vec3';
|
|
@@ -657,23 +1376,49 @@ class NodeBuilder {
|
|
|
657
1376
|
|
|
658
1377
|
}
|
|
659
1378
|
|
|
1379
|
+
/**
|
|
1380
|
+
* Returns the data type for the given the length and component type.
|
|
1381
|
+
*
|
|
1382
|
+
* @param {number} length - The length.
|
|
1383
|
+
* @param {string} [componentType='float'] - The component type.
|
|
1384
|
+
* @return {string} The type.
|
|
1385
|
+
*/
|
|
660
1386
|
getTypeFromLength( length, componentType = 'float' ) {
|
|
661
1387
|
|
|
662
1388
|
if ( length === 1 ) return componentType;
|
|
663
1389
|
|
|
664
|
-
|
|
1390
|
+
let baseType = getTypeFromLength( length );
|
|
665
1391
|
const prefix = componentType === 'float' ? '' : componentType[ 0 ];
|
|
666
1392
|
|
|
1393
|
+
// fix edge case for mat2x2 being same size as vec4
|
|
1394
|
+
if ( /mat2/.test( componentType ) === true ) {
|
|
1395
|
+
|
|
1396
|
+
baseType = baseType.replace( 'vec', 'mat' );
|
|
1397
|
+
|
|
1398
|
+
}
|
|
1399
|
+
|
|
667
1400
|
return prefix + baseType;
|
|
668
1401
|
|
|
669
1402
|
}
|
|
670
1403
|
|
|
1404
|
+
/**
|
|
1405
|
+
* Returns the type for a given typed array.
|
|
1406
|
+
*
|
|
1407
|
+
* @param {TypedArray} array - The typed array.
|
|
1408
|
+
* @return {string} The type.
|
|
1409
|
+
*/
|
|
671
1410
|
getTypeFromArray( array ) {
|
|
672
1411
|
|
|
673
1412
|
return typeFromArray.get( array.constructor );
|
|
674
1413
|
|
|
675
1414
|
}
|
|
676
1415
|
|
|
1416
|
+
/**
|
|
1417
|
+
* Returns the type for a given buffer attribute.
|
|
1418
|
+
*
|
|
1419
|
+
* @param {BufferAttribute} attribute - The buffer attribute.
|
|
1420
|
+
* @return {string} The type.
|
|
1421
|
+
*/
|
|
677
1422
|
getTypeFromAttribute( attribute ) {
|
|
678
1423
|
|
|
679
1424
|
let dataAttribute = attribute;
|
|
@@ -696,6 +1441,12 @@ class NodeBuilder {
|
|
|
696
1441
|
|
|
697
1442
|
}
|
|
698
1443
|
|
|
1444
|
+
/**
|
|
1445
|
+
* Returns the length for the given data type.
|
|
1446
|
+
*
|
|
1447
|
+
* @param {string} type - The data type.
|
|
1448
|
+
* @return {number} The length.
|
|
1449
|
+
*/
|
|
699
1450
|
getTypeLength( type ) {
|
|
700
1451
|
|
|
701
1452
|
const vecType = this.getVectorType( type );
|
|
@@ -711,18 +1462,39 @@ class NodeBuilder {
|
|
|
711
1462
|
|
|
712
1463
|
}
|
|
713
1464
|
|
|
1465
|
+
/**
|
|
1466
|
+
* Returns the vector type for a given matrix type.
|
|
1467
|
+
*
|
|
1468
|
+
* @param {string} type - The matrix type.
|
|
1469
|
+
* @return {string} The vector type.
|
|
1470
|
+
*/
|
|
714
1471
|
getVectorFromMatrix( type ) {
|
|
715
1472
|
|
|
716
1473
|
return type.replace( 'mat', 'vec' );
|
|
717
1474
|
|
|
718
1475
|
}
|
|
719
1476
|
|
|
1477
|
+
/**
|
|
1478
|
+
* For a given type this method changes the component type to the
|
|
1479
|
+
* given value. E.g. `vec4` should be changed to the new component type
|
|
1480
|
+
* `uint` which results in `uvec4`.
|
|
1481
|
+
*
|
|
1482
|
+
* @param {string} type - The type.
|
|
1483
|
+
* @param {string} newComponentType - The new component type.
|
|
1484
|
+
* @return {string} The new type.
|
|
1485
|
+
*/
|
|
720
1486
|
changeComponentType( type, newComponentType ) {
|
|
721
1487
|
|
|
722
1488
|
return this.getTypeFromLength( this.getTypeLength( type ), newComponentType );
|
|
723
1489
|
|
|
724
1490
|
}
|
|
725
1491
|
|
|
1492
|
+
/**
|
|
1493
|
+
* Returns the integer type pendant for the given type.
|
|
1494
|
+
*
|
|
1495
|
+
* @param {string} type - The type.
|
|
1496
|
+
* @return {string} The integer type.
|
|
1497
|
+
*/
|
|
726
1498
|
getIntegerType( type ) {
|
|
727
1499
|
|
|
728
1500
|
const componentType = this.getComponentType( type );
|
|
@@ -733,6 +1505,11 @@ class NodeBuilder {
|
|
|
733
1505
|
|
|
734
1506
|
}
|
|
735
1507
|
|
|
1508
|
+
/**
|
|
1509
|
+
* Adds a stack node to the internal stack.
|
|
1510
|
+
*
|
|
1511
|
+
* @return {StackNode} The added stack node.
|
|
1512
|
+
*/
|
|
736
1513
|
addStack() {
|
|
737
1514
|
|
|
738
1515
|
this.stack = stack( this.stack );
|
|
@@ -744,6 +1521,11 @@ class NodeBuilder {
|
|
|
744
1521
|
|
|
745
1522
|
}
|
|
746
1523
|
|
|
1524
|
+
/**
|
|
1525
|
+
* Removes the last stack node from the internal stack.
|
|
1526
|
+
*
|
|
1527
|
+
* @return {StackNode} The removed stack node.
|
|
1528
|
+
*/
|
|
747
1529
|
removeStack() {
|
|
748
1530
|
|
|
749
1531
|
const lastStack = this.stack;
|
|
@@ -755,6 +1537,15 @@ class NodeBuilder {
|
|
|
755
1537
|
|
|
756
1538
|
}
|
|
757
1539
|
|
|
1540
|
+
/**
|
|
1541
|
+
* The builder maintains (cached) data for each node during the building process. This method
|
|
1542
|
+
* can be used to get these data for a specific shader stage and cache.
|
|
1543
|
+
*
|
|
1544
|
+
* @param {Node} node - The node to get the data for.
|
|
1545
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1546
|
+
* @param {?NodeCache} cache - An optional cache.
|
|
1547
|
+
* @return {Object} The node data.
|
|
1548
|
+
*/
|
|
758
1549
|
getDataFromNode( node, shaderStage = this.shaderStage, cache = null ) {
|
|
759
1550
|
|
|
760
1551
|
cache = cache === null ? ( node.isGlobal( this ) ? this.globalCache : this.cache ) : cache;
|
|
@@ -775,6 +1566,13 @@ class NodeBuilder {
|
|
|
775
1566
|
|
|
776
1567
|
}
|
|
777
1568
|
|
|
1569
|
+
/**
|
|
1570
|
+
* Returns the properties for the given node and shader stage.
|
|
1571
|
+
*
|
|
1572
|
+
* @param {Node} node - The node to get the properties for.
|
|
1573
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage='any'] - The shader stage.
|
|
1574
|
+
* @return {Object} The node properties.
|
|
1575
|
+
*/
|
|
778
1576
|
getNodeProperties( node, shaderStage = 'any' ) {
|
|
779
1577
|
|
|
780
1578
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
@@ -783,6 +1581,13 @@ class NodeBuilder {
|
|
|
783
1581
|
|
|
784
1582
|
}
|
|
785
1583
|
|
|
1584
|
+
/**
|
|
1585
|
+
* Returns an instance of {@link NodeAttribute} for the given buffer attribute node.
|
|
1586
|
+
*
|
|
1587
|
+
* @param {BufferAttributeNode} node - The buffer attribute node.
|
|
1588
|
+
* @param {string} type - The node type.
|
|
1589
|
+
* @return {NodeAttribute} The node attribute.
|
|
1590
|
+
*/
|
|
786
1591
|
getBufferAttributeFromNode( node, type ) {
|
|
787
1592
|
|
|
788
1593
|
const nodeData = this.getDataFromNode( node );
|
|
@@ -805,25 +1610,64 @@ class NodeBuilder {
|
|
|
805
1610
|
|
|
806
1611
|
}
|
|
807
1612
|
|
|
808
|
-
|
|
1613
|
+
/**
|
|
1614
|
+
* Returns an instance of {@link StructType} for the given output struct node.
|
|
1615
|
+
*
|
|
1616
|
+
* @param {OutputStructNode} node - The output struct node.
|
|
1617
|
+
* @param {Array<Object>} membersLayout - The output struct types.
|
|
1618
|
+
* @param {?string} [name=null] - The name of the struct.
|
|
1619
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1620
|
+
* @return {StructType} The struct type attribute.
|
|
1621
|
+
*/
|
|
1622
|
+
getStructTypeFromNode( node, membersLayout, name = null, shaderStage = this.shaderStage ) {
|
|
809
1623
|
|
|
810
|
-
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
1624
|
+
const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
|
|
1625
|
+
|
|
1626
|
+
let structType = nodeData.structType;
|
|
811
1627
|
|
|
812
|
-
if (
|
|
1628
|
+
if ( structType === undefined ) {
|
|
813
1629
|
|
|
814
1630
|
const index = this.structs.index ++;
|
|
815
1631
|
|
|
816
|
-
|
|
817
|
-
this.structs[ shaderStage ].push( node );
|
|
1632
|
+
if ( name === null ) name = 'StructType' + index;
|
|
818
1633
|
|
|
819
|
-
|
|
1634
|
+
structType = new StructType( name, membersLayout );
|
|
1635
|
+
|
|
1636
|
+
this.structs[ shaderStage ].push( structType );
|
|
1637
|
+
|
|
1638
|
+
nodeData.structType = structType;
|
|
820
1639
|
|
|
821
1640
|
}
|
|
822
1641
|
|
|
823
|
-
return
|
|
1642
|
+
return structType;
|
|
824
1643
|
|
|
825
1644
|
}
|
|
826
1645
|
|
|
1646
|
+
/**
|
|
1647
|
+
* Returns an instance of {@link StructType} for the given output struct node.
|
|
1648
|
+
*
|
|
1649
|
+
* @param {OutputStructNode} node - The output struct node.
|
|
1650
|
+
* @param {Array<Object>} membersLayout - The output struct types.
|
|
1651
|
+
* @return {StructType} The struct type attribute.
|
|
1652
|
+
*/
|
|
1653
|
+
getOutputStructTypeFromNode( node, membersLayout ) {
|
|
1654
|
+
|
|
1655
|
+
const structType = this.getStructTypeFromNode( node, membersLayout, 'OutputType', 'fragment' );
|
|
1656
|
+
structType.output = true;
|
|
1657
|
+
|
|
1658
|
+
return structType;
|
|
1659
|
+
|
|
1660
|
+
}
|
|
1661
|
+
|
|
1662
|
+
/**
|
|
1663
|
+
* Returns an instance of {@link NodeUniform} for the given uniform node.
|
|
1664
|
+
*
|
|
1665
|
+
* @param {UniformNode} node - The uniform node.
|
|
1666
|
+
* @param {string} type - The uniform type.
|
|
1667
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1668
|
+
* @param {?string} name - The name of the uniform.
|
|
1669
|
+
* @return {NodeUniform} The node uniform.
|
|
1670
|
+
*/
|
|
827
1671
|
getUniformFromNode( node, type, shaderStage = this.shaderStage, name = null ) {
|
|
828
1672
|
|
|
829
1673
|
const nodeData = this.getDataFromNode( node, shaderStage, this.globalCache );
|
|
@@ -846,7 +1690,35 @@ class NodeBuilder {
|
|
|
846
1690
|
|
|
847
1691
|
}
|
|
848
1692
|
|
|
849
|
-
|
|
1693
|
+
/**
|
|
1694
|
+
* Returns the array length.
|
|
1695
|
+
*
|
|
1696
|
+
* @param {Node} node - The node.
|
|
1697
|
+
* @return {?number} The array length.
|
|
1698
|
+
*/
|
|
1699
|
+
getArrayCount( node ) {
|
|
1700
|
+
|
|
1701
|
+
let count = null;
|
|
1702
|
+
|
|
1703
|
+
if ( node.isArrayNode ) count = node.count;
|
|
1704
|
+
else if ( node.isVarNode && node.node.isArrayNode ) count = node.node.count;
|
|
1705
|
+
|
|
1706
|
+
return count;
|
|
1707
|
+
|
|
1708
|
+
}
|
|
1709
|
+
|
|
1710
|
+
/**
|
|
1711
|
+
* Returns an instance of {@link NodeVar} for the given variable node.
|
|
1712
|
+
*
|
|
1713
|
+
* @param {VarNode} node - The variable node.
|
|
1714
|
+
* @param {?string} name - The variable's name.
|
|
1715
|
+
* @param {string} [type=node.getNodeType( this )] - The variable's type.
|
|
1716
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1717
|
+
* @param {boolean} [readOnly=false] - Whether the variable is read-only or not.
|
|
1718
|
+
*
|
|
1719
|
+
* @return {NodeVar} The node variable.
|
|
1720
|
+
*/
|
|
1721
|
+
getVarFromNode( node, name = null, type = node.getNodeType( this ), shaderStage = this.shaderStage, readOnly = false ) {
|
|
850
1722
|
|
|
851
1723
|
const nodeData = this.getDataFromNode( node, shaderStage );
|
|
852
1724
|
|
|
@@ -854,13 +1726,30 @@ class NodeBuilder {
|
|
|
854
1726
|
|
|
855
1727
|
if ( nodeVar === undefined ) {
|
|
856
1728
|
|
|
1729
|
+
const idNS = readOnly ? '_const' : '_var';
|
|
1730
|
+
|
|
857
1731
|
const vars = this.vars[ shaderStage ] || ( this.vars[ shaderStage ] = [] );
|
|
1732
|
+
const id = this.vars[ idNS ] || ( this.vars[ idNS ] = 0 );
|
|
858
1733
|
|
|
859
|
-
if ( name === null )
|
|
1734
|
+
if ( name === null ) {
|
|
1735
|
+
|
|
1736
|
+
name = ( readOnly ? 'nodeConst' : 'nodeVar' ) + id;
|
|
1737
|
+
|
|
1738
|
+
this.vars[ idNS ] ++;
|
|
1739
|
+
|
|
1740
|
+
}
|
|
860
1741
|
|
|
861
|
-
|
|
1742
|
+
//
|
|
862
1743
|
|
|
863
|
-
|
|
1744
|
+
const count = this.getArrayCount( node );
|
|
1745
|
+
|
|
1746
|
+
nodeVar = new NodeVar( name, type, readOnly, count );
|
|
1747
|
+
|
|
1748
|
+
if ( ! readOnly ) {
|
|
1749
|
+
|
|
1750
|
+
vars.push( nodeVar );
|
|
1751
|
+
|
|
1752
|
+
}
|
|
864
1753
|
|
|
865
1754
|
nodeData.variable = nodeVar;
|
|
866
1755
|
|
|
@@ -870,6 +1759,61 @@ class NodeBuilder {
|
|
|
870
1759
|
|
|
871
1760
|
}
|
|
872
1761
|
|
|
1762
|
+
/**
|
|
1763
|
+
* Returns whether a Node or its flow is deterministic, useful for use in `const`.
|
|
1764
|
+
*
|
|
1765
|
+
* @param {Node} node - The varying node.
|
|
1766
|
+
* @return {boolean} Returns true if deterministic.
|
|
1767
|
+
*/
|
|
1768
|
+
isDeterministic( node ) {
|
|
1769
|
+
|
|
1770
|
+
if ( node.isMathNode ) {
|
|
1771
|
+
|
|
1772
|
+
return this.isDeterministic( node.aNode ) &&
|
|
1773
|
+
( node.bNode ? this.isDeterministic( node.bNode ) : true ) &&
|
|
1774
|
+
( node.cNode ? this.isDeterministic( node.cNode ) : true );
|
|
1775
|
+
|
|
1776
|
+
} else if ( node.isOperatorNode ) {
|
|
1777
|
+
|
|
1778
|
+
return this.isDeterministic( node.aNode ) &&
|
|
1779
|
+
( node.bNode ? this.isDeterministic( node.bNode ) : true );
|
|
1780
|
+
|
|
1781
|
+
} else if ( node.isArrayNode ) {
|
|
1782
|
+
|
|
1783
|
+
if ( node.values !== null ) {
|
|
1784
|
+
|
|
1785
|
+
for ( const n of node.values ) {
|
|
1786
|
+
|
|
1787
|
+
if ( ! this.isDeterministic( n ) ) {
|
|
1788
|
+
|
|
1789
|
+
return false;
|
|
1790
|
+
|
|
1791
|
+
}
|
|
1792
|
+
|
|
1793
|
+
}
|
|
1794
|
+
|
|
1795
|
+
}
|
|
1796
|
+
|
|
1797
|
+
return true;
|
|
1798
|
+
|
|
1799
|
+
} else if ( node.isConstNode ) {
|
|
1800
|
+
|
|
1801
|
+
return true;
|
|
1802
|
+
|
|
1803
|
+
}
|
|
1804
|
+
|
|
1805
|
+
return false;
|
|
1806
|
+
|
|
1807
|
+
}
|
|
1808
|
+
|
|
1809
|
+
/**
|
|
1810
|
+
* Returns an instance of {@link NodeVarying} for the given varying node.
|
|
1811
|
+
*
|
|
1812
|
+
* @param {(VaryingNode|PropertyNode)} node - The varying node.
|
|
1813
|
+
* @param {?string} name - The varying's name.
|
|
1814
|
+
* @param {string} [type=node.getNodeType( this )] - The varying's type.
|
|
1815
|
+
* @return {NodeVar} The node varying.
|
|
1816
|
+
*/
|
|
873
1817
|
getVaryingFromNode( node, name = null, type = node.getNodeType( this ) ) {
|
|
874
1818
|
|
|
875
1819
|
const nodeData = this.getDataFromNode( node, 'any' );
|
|
@@ -895,6 +1839,14 @@ class NodeBuilder {
|
|
|
895
1839
|
|
|
896
1840
|
}
|
|
897
1841
|
|
|
1842
|
+
/**
|
|
1843
|
+
* Returns an instance of {@link NodeCode} for the given code node.
|
|
1844
|
+
*
|
|
1845
|
+
* @param {CodeNode} node - The code node.
|
|
1846
|
+
* @param {string} type - The node type.
|
|
1847
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1848
|
+
* @return {NodeCode} The node code.
|
|
1849
|
+
*/
|
|
898
1850
|
getCodeFromNode( node, type, shaderStage = this.shaderStage ) {
|
|
899
1851
|
|
|
900
1852
|
const nodeData = this.getDataFromNode( node );
|
|
@@ -918,10 +1870,82 @@ class NodeBuilder {
|
|
|
918
1870
|
|
|
919
1871
|
}
|
|
920
1872
|
|
|
921
|
-
|
|
1873
|
+
/**
|
|
1874
|
+
* Adds a code flow based on the code-block hierarchy.
|
|
1875
|
+
|
|
1876
|
+
* This is used so that code-blocks like If,Else create their variables locally if the Node
|
|
1877
|
+
* is only used inside one of these conditionals in the current shader stage.
|
|
1878
|
+
*
|
|
1879
|
+
* @param {Node} node - The node to add.
|
|
1880
|
+
* @param {Node} nodeBlock - Node-based code-block. Usually 'ConditionalNode'.
|
|
1881
|
+
*/
|
|
1882
|
+
addFlowCodeHierarchy( node, nodeBlock ) {
|
|
1883
|
+
|
|
1884
|
+
const { flowCodes, flowCodeBlock } = this.getDataFromNode( node );
|
|
1885
|
+
|
|
1886
|
+
let needsFlowCode = true;
|
|
1887
|
+
let nodeBlockHierarchy = nodeBlock;
|
|
1888
|
+
|
|
1889
|
+
while ( nodeBlockHierarchy ) {
|
|
1890
|
+
|
|
1891
|
+
if ( flowCodeBlock.get( nodeBlockHierarchy ) === true ) {
|
|
1892
|
+
|
|
1893
|
+
needsFlowCode = false;
|
|
1894
|
+
break;
|
|
1895
|
+
|
|
1896
|
+
}
|
|
1897
|
+
|
|
1898
|
+
nodeBlockHierarchy = this.getDataFromNode( nodeBlockHierarchy ).parentNodeBlock;
|
|
1899
|
+
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
if ( needsFlowCode ) {
|
|
1903
|
+
|
|
1904
|
+
for ( const flowCode of flowCodes ) {
|
|
1905
|
+
|
|
1906
|
+
this.addLineFlowCode( flowCode );
|
|
1907
|
+
|
|
1908
|
+
}
|
|
1909
|
+
|
|
1910
|
+
}
|
|
1911
|
+
|
|
1912
|
+
}
|
|
1913
|
+
|
|
1914
|
+
/**
|
|
1915
|
+
* Add a inline-code to the current flow code-block.
|
|
1916
|
+
*
|
|
1917
|
+
* @param {Node} node - The node to add.
|
|
1918
|
+
* @param {string} code - The code to add.
|
|
1919
|
+
* @param {Node} nodeBlock - Current ConditionalNode
|
|
1920
|
+
*/
|
|
1921
|
+
addLineFlowCodeBlock( node, code, nodeBlock ) {
|
|
1922
|
+
|
|
1923
|
+
const nodeData = this.getDataFromNode( node );
|
|
1924
|
+
const flowCodes = nodeData.flowCodes || ( nodeData.flowCodes = [] );
|
|
1925
|
+
const codeBlock = nodeData.flowCodeBlock || ( nodeData.flowCodeBlock = new WeakMap() );
|
|
1926
|
+
|
|
1927
|
+
flowCodes.push( code );
|
|
1928
|
+
codeBlock.set( nodeBlock, true );
|
|
1929
|
+
|
|
1930
|
+
}
|
|
1931
|
+
|
|
1932
|
+
/**
|
|
1933
|
+
* Add a inline-code to the current flow.
|
|
1934
|
+
*
|
|
1935
|
+
* @param {string} code - The code to add.
|
|
1936
|
+
* @param {?Node} [node= null] - Optional Node, can help the system understand if the Node is part of a code-block.
|
|
1937
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
1938
|
+
*/
|
|
1939
|
+
addLineFlowCode( code, node = null ) {
|
|
922
1940
|
|
|
923
1941
|
if ( code === '' ) return this;
|
|
924
1942
|
|
|
1943
|
+
if ( node !== null && this.context.nodeBlock ) {
|
|
1944
|
+
|
|
1945
|
+
this.addLineFlowCodeBlock( node, code, this.context.nodeBlock );
|
|
1946
|
+
|
|
1947
|
+
}
|
|
1948
|
+
|
|
925
1949
|
code = this.tab + code;
|
|
926
1950
|
|
|
927
1951
|
if ( ! /;\s*$/.test( code ) ) {
|
|
@@ -936,6 +1960,12 @@ class NodeBuilder {
|
|
|
936
1960
|
|
|
937
1961
|
}
|
|
938
1962
|
|
|
1963
|
+
/**
|
|
1964
|
+
* Adds a code to the current code flow.
|
|
1965
|
+
*
|
|
1966
|
+
* @param {string} code - Shader code.
|
|
1967
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
1968
|
+
*/
|
|
939
1969
|
addFlowCode( code ) {
|
|
940
1970
|
|
|
941
1971
|
this.flow.code += code;
|
|
@@ -944,6 +1974,12 @@ class NodeBuilder {
|
|
|
944
1974
|
|
|
945
1975
|
}
|
|
946
1976
|
|
|
1977
|
+
/**
|
|
1978
|
+
* Add tab in the code that will be generated so that other snippets respect the current tabulation.
|
|
1979
|
+
* Typically used in codes with If,Else.
|
|
1980
|
+
*
|
|
1981
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
1982
|
+
*/
|
|
947
1983
|
addFlowTab() {
|
|
948
1984
|
|
|
949
1985
|
this.tab += '\t';
|
|
@@ -952,6 +1988,11 @@ class NodeBuilder {
|
|
|
952
1988
|
|
|
953
1989
|
}
|
|
954
1990
|
|
|
1991
|
+
/**
|
|
1992
|
+
* Removes a tab.
|
|
1993
|
+
*
|
|
1994
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
1995
|
+
*/
|
|
955
1996
|
removeFlowTab() {
|
|
956
1997
|
|
|
957
1998
|
this.tab = this.tab.slice( 0, - 1 );
|
|
@@ -960,12 +2001,25 @@ class NodeBuilder {
|
|
|
960
2001
|
|
|
961
2002
|
}
|
|
962
2003
|
|
|
2004
|
+
/**
|
|
2005
|
+
* Gets the current flow data based on a Node.
|
|
2006
|
+
*
|
|
2007
|
+
* @param {Node} node - Node that the flow was started.
|
|
2008
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2009
|
+
* @return {Object} The flow data.
|
|
2010
|
+
*/
|
|
963
2011
|
getFlowData( node/*, shaderStage*/ ) {
|
|
964
2012
|
|
|
965
2013
|
return this.flowsData.get( node );
|
|
966
2014
|
|
|
967
2015
|
}
|
|
968
2016
|
|
|
2017
|
+
/**
|
|
2018
|
+
* Executes the node flow based on a root node to generate the final shader code.
|
|
2019
|
+
*
|
|
2020
|
+
* @param {Node} node - The node to execute.
|
|
2021
|
+
* @return {Object} The code flow.
|
|
2022
|
+
*/
|
|
969
2023
|
flowNode( node ) {
|
|
970
2024
|
|
|
971
2025
|
const output = node.getNodeType( this );
|
|
@@ -978,6 +2032,29 @@ class NodeBuilder {
|
|
|
978
2032
|
|
|
979
2033
|
}
|
|
980
2034
|
|
|
2035
|
+
/**
|
|
2036
|
+
* Includes a node in the current function node.
|
|
2037
|
+
*
|
|
2038
|
+
* @param {Node} node - The node to include.
|
|
2039
|
+
* @returns {void}
|
|
2040
|
+
*/
|
|
2041
|
+
addInclude( node ) {
|
|
2042
|
+
|
|
2043
|
+
if ( this.currentFunctionNode !== null ) {
|
|
2044
|
+
|
|
2045
|
+
this.currentFunctionNode.includes.push( node );
|
|
2046
|
+
|
|
2047
|
+
}
|
|
2048
|
+
|
|
2049
|
+
}
|
|
2050
|
+
|
|
2051
|
+
/**
|
|
2052
|
+
* Returns the native shader operator name for a given generic name.
|
|
2053
|
+
* It is a similar type of method like {@link NodeBuilder#getMethod}.
|
|
2054
|
+
*
|
|
2055
|
+
* @param {ShaderNodeInternal} shaderNode - The shader node to build the function node with.
|
|
2056
|
+
* @return {FunctionNode} The build function node.
|
|
2057
|
+
*/
|
|
981
2058
|
buildFunctionNode( shaderNode ) {
|
|
982
2059
|
|
|
983
2060
|
const fn = new FunctionNode();
|
|
@@ -994,31 +2071,34 @@ class NodeBuilder {
|
|
|
994
2071
|
|
|
995
2072
|
}
|
|
996
2073
|
|
|
2074
|
+
/**
|
|
2075
|
+
* Generates a code flow based on a TSL function: Fn().
|
|
2076
|
+
*
|
|
2077
|
+
* @param {ShaderNodeInternal} shaderNode - A function code will be generated based on the input.
|
|
2078
|
+
* @return {Object}
|
|
2079
|
+
*/
|
|
997
2080
|
flowShaderNode( shaderNode ) {
|
|
998
2081
|
|
|
999
2082
|
const layout = shaderNode.layout;
|
|
1000
2083
|
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
if ( shaderNode.isArrayInput ) {
|
|
2084
|
+
const inputs = {
|
|
2085
|
+
[ Symbol.iterator ]() {
|
|
1004
2086
|
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
2087
|
+
let index = 0;
|
|
2088
|
+
const values = Object.values( this );
|
|
2089
|
+
return {
|
|
2090
|
+
next: () => ( {
|
|
2091
|
+
value: values[ index ],
|
|
2092
|
+
done: index ++ >= values.length
|
|
2093
|
+
} )
|
|
2094
|
+
};
|
|
1010
2095
|
|
|
1011
2096
|
}
|
|
2097
|
+
};
|
|
1012
2098
|
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
inputs = {};
|
|
1016
|
-
|
|
1017
|
-
for ( const input of layout.inputs ) {
|
|
1018
|
-
|
|
1019
|
-
inputs[ input.name ] = new ParameterNode( input.type, input.name );
|
|
2099
|
+
for ( const input of layout.inputs ) {
|
|
1020
2100
|
|
|
1021
|
-
|
|
2101
|
+
inputs[ input.name ] = new ParameterNode( input.type, input.name );
|
|
1022
2102
|
|
|
1023
2103
|
}
|
|
1024
2104
|
|
|
@@ -1035,6 +2115,13 @@ class NodeBuilder {
|
|
|
1035
2115
|
|
|
1036
2116
|
}
|
|
1037
2117
|
|
|
2118
|
+
/**
|
|
2119
|
+
* Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
|
|
2120
|
+
*
|
|
2121
|
+
* @param {Node} node - The node to execute.
|
|
2122
|
+
* @param {?string} output - Expected output type. For example 'vec3'.
|
|
2123
|
+
* @return {Object}
|
|
2124
|
+
*/
|
|
1038
2125
|
flowStagesNode( node, output = null ) {
|
|
1039
2126
|
|
|
1040
2127
|
const previousFlow = this.flow;
|
|
@@ -1073,12 +2160,27 @@ class NodeBuilder {
|
|
|
1073
2160
|
|
|
1074
2161
|
}
|
|
1075
2162
|
|
|
1076
|
-
|
|
2163
|
+
/**
|
|
2164
|
+
* Returns the native shader operator name for a given generic name.
|
|
2165
|
+
* It is a similar type of method like {@link NodeBuilder#getMethod}.
|
|
2166
|
+
*
|
|
2167
|
+
* @abstract
|
|
2168
|
+
* @param {string} op - The operator name to resolve.
|
|
2169
|
+
* @return {string} The resolved operator name.
|
|
2170
|
+
*/
|
|
2171
|
+
getFunctionOperator( /* op */ ) {
|
|
1077
2172
|
|
|
1078
2173
|
return null;
|
|
1079
2174
|
|
|
1080
2175
|
}
|
|
1081
2176
|
|
|
2177
|
+
/**
|
|
2178
|
+
* Generates a code flow based on a child Node.
|
|
2179
|
+
*
|
|
2180
|
+
* @param {Node} node - The node to execute.
|
|
2181
|
+
* @param {?string} output - Expected output type. For example 'vec3'.
|
|
2182
|
+
* @return {Object} The code flow.
|
|
2183
|
+
*/
|
|
1082
2184
|
flowChildNode( node, output = null ) {
|
|
1083
2185
|
|
|
1084
2186
|
const previousFlow = this.flow;
|
|
@@ -1097,6 +2199,18 @@ class NodeBuilder {
|
|
|
1097
2199
|
|
|
1098
2200
|
}
|
|
1099
2201
|
|
|
2202
|
+
/**
|
|
2203
|
+
* Executes a flow of code in a different stage.
|
|
2204
|
+
*
|
|
2205
|
+
* Some nodes like `varying()` have the ability to compute code in vertex-stage and
|
|
2206
|
+
* return the value in fragment-stage even if it is being executed in an input fragment.
|
|
2207
|
+
*
|
|
2208
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2209
|
+
* @param {Node} node - The node to execute.
|
|
2210
|
+
* @param {?string} output - Expected output type. For example 'vec3'.
|
|
2211
|
+
* @param {?string} propertyName - The property name to assign the result.
|
|
2212
|
+
* @return {Object}
|
|
2213
|
+
*/
|
|
1100
2214
|
flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
|
|
1101
2215
|
|
|
1102
2216
|
const previousShaderStage = this.shaderStage;
|
|
@@ -1119,30 +2233,63 @@ class NodeBuilder {
|
|
|
1119
2233
|
|
|
1120
2234
|
}
|
|
1121
2235
|
|
|
2236
|
+
/**
|
|
2237
|
+
* Returns an array holding all node attributes of this node builder.
|
|
2238
|
+
*
|
|
2239
|
+
* @return {Array<NodeAttribute>} The node attributes of this builder.
|
|
2240
|
+
*/
|
|
1122
2241
|
getAttributesArray() {
|
|
1123
2242
|
|
|
1124
2243
|
return this.attributes.concat( this.bufferAttributes );
|
|
1125
2244
|
|
|
1126
2245
|
}
|
|
1127
2246
|
|
|
2247
|
+
/**
|
|
2248
|
+
* Returns the attribute definitions as a shader string for the given shader stage.
|
|
2249
|
+
*
|
|
2250
|
+
* @abstract
|
|
2251
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2252
|
+
* @return {string} The attribute code section.
|
|
2253
|
+
*/
|
|
1128
2254
|
getAttributes( /*shaderStage*/ ) {
|
|
1129
2255
|
|
|
1130
2256
|
console.warn( 'Abstract function.' );
|
|
1131
2257
|
|
|
1132
2258
|
}
|
|
1133
2259
|
|
|
2260
|
+
/**
|
|
2261
|
+
* Returns the varying definitions as a shader string for the given shader stage.
|
|
2262
|
+
*
|
|
2263
|
+
* @abstract
|
|
2264
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2265
|
+
* @return {string} The varying code section.
|
|
2266
|
+
*/
|
|
1134
2267
|
getVaryings( /*shaderStage*/ ) {
|
|
1135
2268
|
|
|
1136
2269
|
console.warn( 'Abstract function.' );
|
|
1137
2270
|
|
|
1138
2271
|
}
|
|
1139
2272
|
|
|
1140
|
-
|
|
2273
|
+
/**
|
|
2274
|
+
* Returns a single variable definition as a shader string for the given variable type and name.
|
|
2275
|
+
*
|
|
2276
|
+
* @param {string} type - The variable's type.
|
|
2277
|
+
* @param {string} name - The variable's name.
|
|
2278
|
+
* @param {?number} [count=null] - The array length.
|
|
2279
|
+
* @return {string} The shader string.
|
|
2280
|
+
*/
|
|
2281
|
+
getVar( type, name, count = null ) {
|
|
1141
2282
|
|
|
1142
|
-
return `${ this.getType( type ) } ${ name }`;
|
|
2283
|
+
return `${ count !== null ? this.generateArrayDeclaration( type, count ) : this.getType( type ) } ${ name }`;
|
|
1143
2284
|
|
|
1144
2285
|
}
|
|
1145
2286
|
|
|
2287
|
+
/**
|
|
2288
|
+
* Returns the variable definitions as a shader string for the given shader stage.
|
|
2289
|
+
*
|
|
2290
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2291
|
+
* @return {string} The variable code section.
|
|
2292
|
+
*/
|
|
1146
2293
|
getVars( shaderStage ) {
|
|
1147
2294
|
|
|
1148
2295
|
let snippet = '';
|
|
@@ -1163,12 +2310,25 @@ class NodeBuilder {
|
|
|
1163
2310
|
|
|
1164
2311
|
}
|
|
1165
2312
|
|
|
2313
|
+
/**
|
|
2314
|
+
* Returns the uniform definitions as a shader string for the given shader stage.
|
|
2315
|
+
*
|
|
2316
|
+
* @abstract
|
|
2317
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2318
|
+
* @return {string} The uniform code section.
|
|
2319
|
+
*/
|
|
1166
2320
|
getUniforms( /*shaderStage*/ ) {
|
|
1167
2321
|
|
|
1168
2322
|
console.warn( 'Abstract function.' );
|
|
1169
2323
|
|
|
1170
2324
|
}
|
|
1171
2325
|
|
|
2326
|
+
/**
|
|
2327
|
+
* Returns the native code definitions as a shader string for the given shader stage.
|
|
2328
|
+
*
|
|
2329
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage.
|
|
2330
|
+
* @return {string} The native code section.
|
|
2331
|
+
*/
|
|
1172
2332
|
getCodes( shaderStage ) {
|
|
1173
2333
|
|
|
1174
2334
|
const codes = this.codes[ shaderStage ];
|
|
@@ -1189,50 +2349,94 @@ class NodeBuilder {
|
|
|
1189
2349
|
|
|
1190
2350
|
}
|
|
1191
2351
|
|
|
2352
|
+
/**
|
|
2353
|
+
* Returns the hash of this node builder.
|
|
2354
|
+
*
|
|
2355
|
+
* @return {string} The hash.
|
|
2356
|
+
*/
|
|
1192
2357
|
getHash() {
|
|
1193
2358
|
|
|
1194
2359
|
return this.vertexShader + this.fragmentShader + this.computeShader;
|
|
1195
2360
|
|
|
1196
2361
|
}
|
|
1197
2362
|
|
|
2363
|
+
/**
|
|
2364
|
+
* Sets the current shader stage.
|
|
2365
|
+
*
|
|
2366
|
+
* @param {?('vertex'|'fragment'|'compute'|'any')} shaderStage - The shader stage to set.
|
|
2367
|
+
*/
|
|
1198
2368
|
setShaderStage( shaderStage ) {
|
|
1199
2369
|
|
|
1200
2370
|
this.shaderStage = shaderStage;
|
|
1201
2371
|
|
|
1202
2372
|
}
|
|
1203
2373
|
|
|
2374
|
+
/**
|
|
2375
|
+
* Returns the current shader stage.
|
|
2376
|
+
*
|
|
2377
|
+
* @return {?('vertex'|'fragment'|'compute'|'any')} The current shader stage.
|
|
2378
|
+
*/
|
|
1204
2379
|
getShaderStage() {
|
|
1205
2380
|
|
|
1206
2381
|
return this.shaderStage;
|
|
1207
2382
|
|
|
1208
2383
|
}
|
|
1209
2384
|
|
|
2385
|
+
/**
|
|
2386
|
+
* Sets the current build stage.
|
|
2387
|
+
*
|
|
2388
|
+
* @param {?('setup'|'analyze'|'generate')} buildStage - The build stage to set.
|
|
2389
|
+
*/
|
|
1210
2390
|
setBuildStage( buildStage ) {
|
|
1211
2391
|
|
|
1212
2392
|
this.buildStage = buildStage;
|
|
1213
2393
|
|
|
1214
2394
|
}
|
|
1215
2395
|
|
|
2396
|
+
/**
|
|
2397
|
+
* Returns the current build stage.
|
|
2398
|
+
*
|
|
2399
|
+
* @return {?('setup'|'analyze'|'generate')} The current build stage.
|
|
2400
|
+
*/
|
|
1216
2401
|
getBuildStage() {
|
|
1217
2402
|
|
|
1218
2403
|
return this.buildStage;
|
|
1219
2404
|
|
|
1220
2405
|
}
|
|
1221
2406
|
|
|
2407
|
+
/**
|
|
2408
|
+
* Controls the code build of the shader stages.
|
|
2409
|
+
*
|
|
2410
|
+
* @abstract
|
|
2411
|
+
*/
|
|
1222
2412
|
buildCode() {
|
|
1223
2413
|
|
|
1224
2414
|
console.warn( 'Abstract function.' );
|
|
1225
2415
|
|
|
1226
2416
|
}
|
|
1227
2417
|
|
|
2418
|
+
/**
|
|
2419
|
+
* Central build method which controls the build for the given object.
|
|
2420
|
+
*
|
|
2421
|
+
* @return {NodeBuilder} A reference to this node builder.
|
|
2422
|
+
*/
|
|
1228
2423
|
build() {
|
|
1229
2424
|
|
|
1230
|
-
const { object, material } = this;
|
|
1231
|
-
|
|
2425
|
+
const { object, material, renderer } = this;
|
|
1232
2426
|
|
|
1233
2427
|
if ( material !== null ) {
|
|
1234
2428
|
|
|
1235
|
-
|
|
2429
|
+
let nodeMaterial = renderer.library.fromMaterial( material );
|
|
2430
|
+
|
|
2431
|
+
if ( nodeMaterial === null ) {
|
|
2432
|
+
|
|
2433
|
+
console.error( `NodeMaterial: Material "${ material.type }" is not compatible.` );
|
|
2434
|
+
|
|
2435
|
+
nodeMaterial = new NodeMaterial();
|
|
2436
|
+
|
|
2437
|
+
}
|
|
2438
|
+
|
|
2439
|
+
nodeMaterial.build( this );
|
|
1236
2440
|
|
|
1237
2441
|
} else {
|
|
1238
2442
|
|
|
@@ -1290,6 +2494,13 @@ class NodeBuilder {
|
|
|
1290
2494
|
|
|
1291
2495
|
}
|
|
1292
2496
|
|
|
2497
|
+
/**
|
|
2498
|
+
* Returns a uniform representation which is later used for UBO generation and rendering.
|
|
2499
|
+
*
|
|
2500
|
+
* @param {NodeUniform} uniformNode - The uniform node.
|
|
2501
|
+
* @param {string} type - The requested type.
|
|
2502
|
+
* @return {Uniform} The uniform.
|
|
2503
|
+
*/
|
|
1293
2504
|
getNodeUniform( uniformNode, type ) {
|
|
1294
2505
|
|
|
1295
2506
|
if ( type === 'float' || type === 'int' || type === 'uint' ) return new NumberNodeUniform( uniformNode );
|
|
@@ -1297,6 +2508,7 @@ class NodeBuilder {
|
|
|
1297
2508
|
if ( type === 'vec3' || type === 'ivec3' || type === 'uvec3' ) return new Vector3NodeUniform( uniformNode );
|
|
1298
2509
|
if ( type === 'vec4' || type === 'ivec4' || type === 'uvec4' ) return new Vector4NodeUniform( uniformNode );
|
|
1299
2510
|
if ( type === 'color' ) return new ColorNodeUniform( uniformNode );
|
|
2511
|
+
if ( type === 'mat2' ) return new Matrix2NodeUniform( uniformNode );
|
|
1300
2512
|
if ( type === 'mat3' ) return new Matrix3NodeUniform( uniformNode );
|
|
1301
2513
|
if ( type === 'mat4' ) return new Matrix4NodeUniform( uniformNode );
|
|
1302
2514
|
|
|
@@ -1304,14 +2516,16 @@ class NodeBuilder {
|
|
|
1304
2516
|
|
|
1305
2517
|
}
|
|
1306
2518
|
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
2519
|
+
/**
|
|
2520
|
+
* Formats the given shader snippet from a given type into another one. E.g.
|
|
2521
|
+
* this method might be used to convert a simple float string `"1.0"` into a
|
|
2522
|
+
* `vec3` representation: `"vec3<f32>( 1.0 )"`.
|
|
2523
|
+
*
|
|
2524
|
+
* @param {string} snippet - The shader snippet.
|
|
2525
|
+
* @param {string} fromType - The source type.
|
|
2526
|
+
* @param {string} toType - The target type.
|
|
2527
|
+
* @return {string} The updated shader string.
|
|
2528
|
+
*/
|
|
1315
2529
|
format( snippet, fromType, toType ) {
|
|
1316
2530
|
|
|
1317
2531
|
fromType = this.getVectorType( fromType );
|
|
@@ -1392,12 +2606,32 @@ class NodeBuilder {
|
|
|
1392
2606
|
|
|
1393
2607
|
}
|
|
1394
2608
|
|
|
2609
|
+
/**
|
|
2610
|
+
* Returns a signature with the engine's current revision.
|
|
2611
|
+
*
|
|
2612
|
+
* @return {string} The signature.
|
|
2613
|
+
*/
|
|
1395
2614
|
getSignature() {
|
|
1396
2615
|
|
|
1397
2616
|
return `// Three.js r${ REVISION } - Node System\n`;
|
|
1398
2617
|
|
|
1399
2618
|
}
|
|
1400
2619
|
|
|
2620
|
+
// Deprecated
|
|
2621
|
+
|
|
2622
|
+
/**
|
|
2623
|
+
* @function
|
|
2624
|
+
* @deprecated since r168. Use `new NodeMaterial()` instead, with targeted node material name.
|
|
2625
|
+
*
|
|
2626
|
+
* @param {string} [type='NodeMaterial'] - The node material type.
|
|
2627
|
+
* @throws {Error}
|
|
2628
|
+
*/
|
|
2629
|
+
createNodeMaterial( type = 'NodeMaterial' ) { // @deprecated, r168
|
|
2630
|
+
|
|
2631
|
+
throw new Error( `THREE.NodeBuilder: createNodeMaterial() was deprecated. Use new ${ type }() instead.` );
|
|
2632
|
+
|
|
2633
|
+
}
|
|
2634
|
+
|
|
1401
2635
|
}
|
|
1402
2636
|
|
|
1403
2637
|
export default NodeBuilder;
|