@plastic-software/three 0.178.0 → 0.180.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/README.md +1 -1
- package/build/three.cjs +950 -230
- package/build/three.core.js +754 -138
- package/build/three.core.min.js +1 -1
- package/build/three.module.js +197 -96
- package/build/three.module.min.js +1 -1
- package/build/three.tsl.js +99 -25
- package/build/three.tsl.min.js +1 -1
- package/build/three.webgpu.js +4586 -1499
- package/build/three.webgpu.min.js +1 -1
- package/build/three.webgpu.nodes.js +4544 -1499
- package/build/three.webgpu.nodes.min.js +1 -1
- package/examples/jsm/Addons.js +2 -3
- package/examples/jsm/capabilities/WebGPU.js +1 -1
- package/examples/jsm/controls/ArcballControls.js +7 -7
- package/examples/jsm/controls/DragControls.js +6 -56
- package/examples/jsm/controls/FirstPersonControls.js +2 -2
- package/examples/jsm/controls/PointerLockControls.js +0 -8
- package/examples/jsm/csm/CSMShadowNode.js +4 -4
- package/examples/jsm/environments/RoomEnvironment.js +8 -3
- package/examples/jsm/exporters/GLTFExporter.js +30 -22
- package/examples/jsm/exporters/KTX2Exporter.js +4 -2
- package/examples/jsm/exporters/PLYExporter.js +1 -1
- package/examples/jsm/exporters/USDZExporter.js +676 -299
- package/examples/jsm/geometries/RoundedBoxGeometry.js +47 -8
- package/examples/jsm/interactive/HTMLMesh.js +5 -3
- package/examples/jsm/libs/ktx-parse.module.js +1 -1
- package/examples/jsm/libs/meshopt_decoder.module.js +75 -58
- package/examples/jsm/lights/LightProbeGenerator.js +14 -3
- package/examples/jsm/lines/Line2.js +3 -3
- package/examples/jsm/lines/LineGeometry.js +1 -1
- package/examples/jsm/lines/LineSegments2.js +2 -2
- package/examples/jsm/lines/Wireframe.js +2 -2
- package/examples/jsm/lines/WireframeGeometry2.js +1 -1
- package/examples/jsm/lines/webgpu/LineSegments2.js +1 -1
- package/examples/jsm/lines/webgpu/Wireframe.js +1 -1
- package/examples/jsm/loaders/ColladaLoader.js +1 -1
- package/examples/jsm/loaders/EXRLoader.js +210 -22
- package/examples/jsm/loaders/FBXLoader.js +1 -1
- package/examples/jsm/loaders/GLTFLoader.js +9 -5
- package/examples/jsm/loaders/HDRCubeTextureLoader.js +5 -5
- package/examples/jsm/loaders/HDRLoader.js +486 -0
- package/examples/jsm/loaders/KTX2Loader.js +112 -32
- package/examples/jsm/loaders/MaterialXLoader.js +212 -30
- package/examples/jsm/loaders/RGBELoader.js +7 -473
- package/examples/jsm/loaders/TTFLoader.js +13 -1
- package/examples/jsm/loaders/USDLoader.js +219 -0
- package/examples/jsm/loaders/USDZLoader.js +4 -892
- package/examples/jsm/loaders/UltraHDRLoader.js +1 -1
- package/examples/jsm/loaders/lwo/IFFParser.js +1 -1
- package/examples/jsm/loaders/usd/USDAParser.js +741 -0
- package/examples/jsm/loaders/usd/USDCParser.js +17 -0
- package/examples/jsm/materials/WoodNodeMaterial.js +533 -0
- package/examples/jsm/math/ColorSpaces.js +19 -1
- package/examples/jsm/math/ConvexHull.js +2 -2
- package/examples/jsm/math/Lut.js +2 -2
- package/examples/jsm/misc/MD2CharacterComplex.js +1 -1
- package/examples/jsm/misc/ProgressiveLightMap.js +1 -1
- package/examples/jsm/misc/Volume.js +1 -1
- package/examples/jsm/objects/LensflareMesh.js +3 -3
- package/examples/jsm/objects/SkyMesh.js +2 -2
- package/examples/jsm/physics/RapierPhysics.js +14 -5
- package/examples/jsm/postprocessing/GTAOPass.js +10 -9
- package/examples/jsm/postprocessing/OutlinePass.js +17 -17
- package/examples/jsm/postprocessing/SSAOPass.js +10 -9
- package/examples/jsm/postprocessing/SSRPass.js +37 -8
- package/examples/jsm/shaders/UnpackDepthRGBAShader.js +11 -2
- package/examples/jsm/transpiler/GLSLDecoder.js +23 -20
- package/examples/jsm/transpiler/TSLEncoder.js +2 -10
- package/examples/jsm/transpiler/WGSLEncoder.js +24 -0
- package/examples/jsm/tsl/display/AnamorphicNode.js +27 -4
- package/examples/jsm/tsl/display/BloomNode.js +7 -6
- package/examples/jsm/tsl/display/ChromaticAberrationNode.js +2 -1
- package/examples/jsm/tsl/display/DepthOfFieldNode.js +439 -90
- package/examples/jsm/tsl/display/GTAONode.js +8 -0
- package/examples/jsm/tsl/display/GaussianBlurNode.js +51 -41
- package/examples/jsm/tsl/display/OutlineNode.js +2 -2
- package/examples/jsm/tsl/display/SSRNode.js +180 -65
- package/examples/jsm/tsl/display/{TRAAPassNode.js → TRAANode.js} +181 -172
- package/examples/jsm/tsl/display/boxBlur.js +64 -0
- package/examples/jsm/tsl/display/hashBlur.js +15 -18
- package/examples/jsm/tsl/lighting/TiledLightsNode.js +1 -1
- package/examples/jsm/utils/BufferGeometryUtils.js +1 -1
- package/examples/jsm/utils/ShadowMapViewerGPU.js +12 -5
- package/examples/jsm/webxr/OculusHandModel.js +1 -1
- package/package.json +1 -1
- package/src/Three.Core.js +2 -0
- package/src/Three.TSL.js +98 -24
- package/src/animation/AnimationClip.js +17 -2
- package/src/animation/KeyframeTrack.js +1 -1
- package/src/animation/tracks/BooleanKeyframeTrack.js +1 -1
- package/src/animation/tracks/StringKeyframeTrack.js +1 -1
- package/src/cameras/Camera.js +14 -0
- package/src/cameras/OrthographicCamera.js +1 -1
- package/src/cameras/PerspectiveCamera.js +1 -1
- package/src/constants.js +11 -3
- package/src/core/BufferGeometry.js +2 -2
- package/{examples/jsm/misc → src/core}/Timer.js +4 -42
- package/src/extras/PMREMGenerator.js +11 -0
- package/src/extras/TextureUtils.js +2 -1
- package/src/extras/lib/earcut.js +1 -1
- package/src/helpers/CameraHelper.js +41 -11
- package/src/helpers/SkeletonHelper.js +35 -6
- package/src/lights/LightShadow.js +21 -8
- package/src/lights/PointLightShadow.js +1 -1
- package/src/lights/webgpu/ProjectorLight.js +1 -1
- package/src/loaders/FileLoader.js +25 -2
- package/src/loaders/ImageBitmapLoader.js +23 -0
- package/src/loaders/Loader.js +14 -0
- package/src/loaders/LoadingManager.js +23 -0
- package/src/materials/Material.js +12 -0
- package/src/materials/MeshBasicMaterial.js +1 -1
- package/src/materials/MeshDistanceMaterial.js +1 -1
- package/src/materials/nodes/Line2NodeMaterial.js +0 -8
- package/src/materials/nodes/NodeMaterial.js +1 -1
- package/src/materials/nodes/PointsNodeMaterial.js +86 -28
- package/src/materials/nodes/SpriteNodeMaterial.js +3 -15
- package/src/materials/nodes/manager/NodeMaterialObserver.js +87 -2
- package/src/math/ColorManagement.js +7 -1
- package/src/math/Frustum.js +19 -8
- package/src/math/FrustumArray.js +10 -5
- package/src/math/Line3.js +129 -2
- package/src/math/Matrix4.js +48 -27
- package/src/math/Spherical.js +2 -2
- package/src/nodes/Nodes.js +4 -0
- package/src/nodes/TSL.js +4 -0
- package/src/nodes/accessors/BufferNode.js +1 -1
- package/src/nodes/accessors/Camera.js +142 -16
- package/src/nodes/accessors/ClippingNode.js +6 -5
- package/src/nodes/accessors/CubeTextureNode.js +2 -2
- package/src/nodes/accessors/InstanceNode.js +3 -1
- package/src/nodes/accessors/Normal.js +11 -11
- package/src/nodes/accessors/Object3DNode.js +1 -1
- package/src/nodes/accessors/ReferenceBaseNode.js +1 -1
- package/src/nodes/accessors/ReferenceNode.js +19 -4
- package/src/nodes/accessors/SceneNode.js +1 -1
- package/src/nodes/accessors/StorageTextureNode.js +1 -1
- package/src/nodes/accessors/Texture3DNode.js +13 -0
- package/src/nodes/accessors/TextureNode.js +83 -19
- package/src/nodes/code/FunctionCallNode.js +19 -0
- package/src/nodes/code/FunctionNode.js +23 -0
- package/src/nodes/core/ArrayNode.js +12 -0
- package/src/nodes/core/AssignNode.js +6 -2
- package/src/nodes/core/ContextNode.js +44 -1
- package/src/nodes/core/Node.js +30 -22
- package/src/nodes/core/NodeBuilder.js +71 -32
- package/src/nodes/core/NodeFrame.js +1 -1
- package/src/nodes/core/NodeUniform.js +1 -1
- package/src/nodes/core/NodeUtils.js +5 -3
- package/src/nodes/core/StackNode.js +71 -4
- package/src/nodes/core/StructNode.js +5 -5
- package/src/nodes/core/StructTypeNode.js +1 -0
- package/src/nodes/core/SubBuildNode.js +2 -2
- package/src/nodes/core/UniformNode.js +79 -14
- package/src/nodes/core/VarNode.js +83 -15
- package/src/nodes/display/FrontFacingNode.js +4 -8
- package/src/nodes/display/PassNode.js +148 -2
- package/src/nodes/display/ScreenNode.js +42 -13
- package/src/nodes/display/ViewportDepthTextureNode.js +16 -4
- package/src/nodes/display/ViewportSharedTextureNode.js +12 -0
- package/src/nodes/display/ViewportTextureNode.js +94 -4
- package/src/nodes/functions/PhysicalLightingModel.js +2 -2
- package/src/nodes/gpgpu/AtomicFunctionNode.js +1 -1
- package/src/nodes/gpgpu/ComputeNode.js +67 -23
- package/src/nodes/gpgpu/SubgroupFunctionNode.js +430 -0
- package/src/nodes/gpgpu/WorkgroupInfoNode.js +28 -3
- package/src/nodes/lighting/LightsNode.js +1 -1
- package/src/nodes/lighting/ProjectorLightNode.js +19 -6
- package/src/nodes/lighting/ShadowFilterNode.js +1 -1
- package/src/nodes/materialx/MaterialXNodes.js +131 -2
- package/src/nodes/materialx/lib/mx_noise.js +165 -1
- package/src/nodes/math/BitcastNode.js +156 -0
- package/src/nodes/math/ConditionalNode.js +19 -3
- package/src/nodes/math/MathNode.js +72 -60
- package/src/nodes/math/OperatorNode.js +26 -25
- package/src/nodes/tsl/TSLCore.js +477 -142
- package/src/nodes/utils/DebugNode.js +1 -1
- package/src/nodes/utils/EventNode.js +83 -0
- package/src/nodes/utils/JoinNode.js +3 -1
- package/src/nodes/utils/MemberNode.js +58 -7
- package/src/nodes/utils/RTTNode.js +10 -1
- package/src/nodes/utils/ReflectorNode.js +51 -7
- package/src/nodes/utils/SampleNode.js +12 -2
- package/src/nodes/utils/SplitNode.js +11 -0
- package/src/nodes/utils/Timer.js +0 -47
- package/src/objects/BatchedMesh.js +6 -4
- package/src/objects/LOD.js +1 -1
- package/src/objects/Sprite.js +2 -2
- package/src/renderers/WebGLRenderer.js +21 -31
- package/src/renderers/common/Attributes.js +1 -1
- package/src/renderers/common/Backend.js +19 -1
- package/src/renderers/common/Bindings.js +21 -18
- package/src/renderers/common/ChainMap.js +1 -1
- package/src/renderers/common/Color4.js +2 -2
- package/src/renderers/common/DataMap.js +1 -1
- package/src/renderers/common/Pipelines.js +1 -1
- package/src/renderers/common/PostProcessing.js +60 -5
- package/src/renderers/common/RenderContext.js +2 -2
- package/src/renderers/common/RenderObject.js +14 -2
- package/src/renderers/common/Renderer.js +55 -32
- package/src/renderers/common/SampledTexture.js +4 -72
- package/src/renderers/common/Sampler.js +91 -0
- package/src/renderers/common/Storage3DTexture.js +21 -0
- package/src/renderers/common/StorageArrayTexture.js +21 -0
- package/src/renderers/common/StorageTexture.js +19 -0
- package/src/renderers/common/Textures.js +52 -14
- package/src/renderers/common/TimestampQueryPool.js +3 -3
- package/src/renderers/common/XRManager.js +51 -17
- package/src/renderers/common/nodes/NodeBuilderState.js +1 -1
- package/src/renderers/common/nodes/NodeLibrary.js +5 -5
- package/src/renderers/common/nodes/NodeSampledTexture.js +0 -12
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/logdepthbuf_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/shadowmap_pars_fragment.glsl.js +21 -11
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +11 -2
- package/src/renderers/webgl/WebGLCapabilities.js +2 -2
- package/src/renderers/webgl/WebGLMaterials.js +6 -6
- package/src/renderers/webgl/WebGLProgram.js +24 -18
- package/src/renderers/webgl/WebGLPrograms.js +4 -4
- package/src/renderers/webgl/WebGLShadowMap.js +11 -1
- package/src/renderers/webgl/WebGLTextures.js +20 -7
- package/src/renderers/webgl/WebGLUtils.js +3 -2
- package/src/renderers/webgl-fallback/WebGLBackend.js +207 -146
- package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +112 -19
- package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -1
- package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +52 -3
- package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +9 -10
- package/src/renderers/webgl-fallback/utils/WebGLUtils.js +3 -2
- package/src/renderers/webgpu/WebGPUBackend.js +87 -44
- package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +169 -99
- package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +35 -31
- package/src/renderers/webgpu/utils/WebGPUConstants.js +2 -2
- package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +10 -19
- package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +120 -84
- package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +3 -3
- package/src/renderers/webgpu/utils/WebGPUUtils.js +2 -17
- package/src/renderers/webxr/WebXRDepthSensing.js +6 -10
- package/src/renderers/webxr/WebXRManager.js +86 -11
- package/src/textures/ExternalTexture.js +56 -0
- package/src/textures/FramebufferTexture.js +2 -2
- package/src/textures/Source.js +12 -2
- package/src/textures/VideoTexture.js +27 -2
- package/examples/jsm/loaders/RGBMLoader.js +0 -1148
|
@@ -196,7 +196,7 @@ class NodeBuilder {
|
|
|
196
196
|
/**
|
|
197
197
|
* A reference to the current fog node.
|
|
198
198
|
*
|
|
199
|
-
* @type {?
|
|
199
|
+
* @type {?Node}
|
|
200
200
|
* @default null
|
|
201
201
|
*/
|
|
202
202
|
this.fogNode = null;
|
|
@@ -259,6 +259,13 @@ class NodeBuilder {
|
|
|
259
259
|
*/
|
|
260
260
|
this.structs = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
261
261
|
|
|
262
|
+
/**
|
|
263
|
+
* This dictionary holds the types of the builder.
|
|
264
|
+
*
|
|
265
|
+
* @type {Object}
|
|
266
|
+
*/
|
|
267
|
+
this.types = { vertex: [], fragment: [], compute: [], index: 0 };
|
|
268
|
+
|
|
262
269
|
/**
|
|
263
270
|
* This dictionary holds the bindings for each shader stage.
|
|
264
271
|
*
|
|
@@ -722,7 +729,7 @@ class NodeBuilder {
|
|
|
722
729
|
|
|
723
730
|
if ( updateType !== NodeUpdateType.NONE ) {
|
|
724
731
|
|
|
725
|
-
this.updateNodes.push( node
|
|
732
|
+
this.updateNodes.push( node );
|
|
726
733
|
|
|
727
734
|
}
|
|
728
735
|
|
|
@@ -735,13 +742,13 @@ class NodeBuilder {
|
|
|
735
742
|
|
|
736
743
|
if ( updateBeforeType !== NodeUpdateType.NONE ) {
|
|
737
744
|
|
|
738
|
-
this.updateBeforeNodes.push( node
|
|
745
|
+
this.updateBeforeNodes.push( node );
|
|
739
746
|
|
|
740
747
|
}
|
|
741
748
|
|
|
742
749
|
if ( updateAfterType !== NodeUpdateType.NONE ) {
|
|
743
750
|
|
|
744
|
-
this.updateAfterNodes.push( node
|
|
751
|
+
this.updateAfterNodes.push( node );
|
|
745
752
|
|
|
746
753
|
}
|
|
747
754
|
|
|
@@ -826,6 +833,22 @@ class NodeBuilder {
|
|
|
826
833
|
|
|
827
834
|
}
|
|
828
835
|
|
|
836
|
+
/**
|
|
837
|
+
* Returns the native snippet for a ternary operation. E.g. GLSL would output
|
|
838
|
+
* a ternary op as `cond ? x : y` whereas WGSL would output it as `select(y, x, cond)`
|
|
839
|
+
*
|
|
840
|
+
* @abstract
|
|
841
|
+
* @param {string} condSnippet - The condition determining which expression gets resolved.
|
|
842
|
+
* @param {string} ifSnippet - The expression to resolve to if the condition is true.
|
|
843
|
+
* @param {string} elseSnippet - The expression to resolve to if the condition is false.
|
|
844
|
+
* @return {string} The resolved method name.
|
|
845
|
+
*/
|
|
846
|
+
getTernary( /* condSnippet, ifSnippet, elseSnippet*/ ) {
|
|
847
|
+
|
|
848
|
+
return null;
|
|
849
|
+
|
|
850
|
+
}
|
|
851
|
+
|
|
829
852
|
/**
|
|
830
853
|
* Returns a node for the given hash, see {@link NodeBuilder#setHashNode}.
|
|
831
854
|
*
|
|
@@ -1144,7 +1167,6 @@ class NodeBuilder {
|
|
|
1144
1167
|
|
|
1145
1168
|
}
|
|
1146
1169
|
|
|
1147
|
-
|
|
1148
1170
|
/**
|
|
1149
1171
|
* Generates the shader string for the given type and value.
|
|
1150
1172
|
*
|
|
@@ -1553,7 +1575,9 @@ class NodeBuilder {
|
|
|
1553
1575
|
|
|
1554
1576
|
this.stack = stack( this.stack );
|
|
1555
1577
|
|
|
1556
|
-
|
|
1578
|
+
const previousStack = getCurrentStack();
|
|
1579
|
+
|
|
1580
|
+
this.stacks.push( previousStack );
|
|
1557
1581
|
setCurrentStack( this.stack );
|
|
1558
1582
|
|
|
1559
1583
|
return this.stack;
|
|
@@ -1665,6 +1689,20 @@ class NodeBuilder {
|
|
|
1665
1689
|
|
|
1666
1690
|
}
|
|
1667
1691
|
|
|
1692
|
+
/**
|
|
1693
|
+
* Returns an instance of {@link StructType} for the given struct name and shader stage
|
|
1694
|
+
* or null if not found.
|
|
1695
|
+
*
|
|
1696
|
+
* @param {string} name - The name of the struct.
|
|
1697
|
+
* @param {('vertex'|'fragment'|'compute'|'any')} [shaderStage=this.shaderStage] - The shader stage.
|
|
1698
|
+
* @return {?StructType} The struct type or null if not found.
|
|
1699
|
+
*/
|
|
1700
|
+
getStructTypeNode( name, shaderStage = this.shaderStage ) {
|
|
1701
|
+
|
|
1702
|
+
return this.types[ shaderStage ][ name ] || null;
|
|
1703
|
+
|
|
1704
|
+
}
|
|
1705
|
+
|
|
1668
1706
|
/**
|
|
1669
1707
|
* Returns an instance of {@link StructType} for the given output struct node.
|
|
1670
1708
|
*
|
|
@@ -1689,6 +1727,7 @@ class NodeBuilder {
|
|
|
1689
1727
|
structType = new StructType( name, membersLayout );
|
|
1690
1728
|
|
|
1691
1729
|
this.structs[ shaderStage ].push( structType );
|
|
1730
|
+
this.types[ shaderStage ][ name ] = node;
|
|
1692
1731
|
|
|
1693
1732
|
nodeData.structType = structType;
|
|
1694
1733
|
|
|
@@ -1747,23 +1786,6 @@ class NodeBuilder {
|
|
|
1747
1786
|
|
|
1748
1787
|
}
|
|
1749
1788
|
|
|
1750
|
-
/**
|
|
1751
|
-
* Returns the array length.
|
|
1752
|
-
*
|
|
1753
|
-
* @param {Node} node - The node.
|
|
1754
|
-
* @return {?number} The array length.
|
|
1755
|
-
*/
|
|
1756
|
-
getArrayCount( node ) {
|
|
1757
|
-
|
|
1758
|
-
let count = null;
|
|
1759
|
-
|
|
1760
|
-
if ( node.isArrayNode ) count = node.count;
|
|
1761
|
-
else if ( node.isVarNode && node.node.isArrayNode ) count = node.node.count;
|
|
1762
|
-
|
|
1763
|
-
return count;
|
|
1764
|
-
|
|
1765
|
-
}
|
|
1766
|
-
|
|
1767
1789
|
/**
|
|
1768
1790
|
* Returns an instance of {@link NodeVar} for the given variable node.
|
|
1769
1791
|
*
|
|
@@ -1807,7 +1829,7 @@ class NodeBuilder {
|
|
|
1807
1829
|
|
|
1808
1830
|
//
|
|
1809
1831
|
|
|
1810
|
-
const count =
|
|
1832
|
+
const count = node.getArrayCount( this );
|
|
1811
1833
|
|
|
1812
1834
|
nodeVar = new NodeVar( name, type, readOnly, count );
|
|
1813
1835
|
|
|
@@ -2233,6 +2255,28 @@ class NodeBuilder {
|
|
|
2233
2255
|
|
|
2234
2256
|
}
|
|
2235
2257
|
|
|
2258
|
+
/**
|
|
2259
|
+
* Executes the node in a specific build stage.
|
|
2260
|
+
*
|
|
2261
|
+
* @param {Node} node - The node to execute.
|
|
2262
|
+
* @param {string} buildStage - The build stage to execute the node in.
|
|
2263
|
+
* @param {?(Node|string)} [output=null] - Expected output type. For example 'vec3'.
|
|
2264
|
+
* @return {?(Node|string)} The result of the node build.
|
|
2265
|
+
*/
|
|
2266
|
+
flowBuildStage( node, buildStage, output = null ) {
|
|
2267
|
+
|
|
2268
|
+
const previousBuildStage = this.getBuildStage();
|
|
2269
|
+
|
|
2270
|
+
this.setBuildStage( buildStage );
|
|
2271
|
+
|
|
2272
|
+
const result = node.build( this, output );
|
|
2273
|
+
|
|
2274
|
+
this.setBuildStage( previousBuildStage );
|
|
2275
|
+
|
|
2276
|
+
return result;
|
|
2277
|
+
|
|
2278
|
+
}
|
|
2279
|
+
|
|
2236
2280
|
/**
|
|
2237
2281
|
* Runs the node flow through all the steps of creation, 'setup', 'analyze', 'generate'.
|
|
2238
2282
|
*
|
|
@@ -2343,7 +2387,7 @@ class NodeBuilder {
|
|
|
2343
2387
|
* @param {Node} node - The node to execute.
|
|
2344
2388
|
* @param {?string} output - Expected output type. For example 'vec3'.
|
|
2345
2389
|
* @param {?string} propertyName - The property name to assign the result.
|
|
2346
|
-
* @return {Object|Node
|
|
2390
|
+
* @return {?(Object|Node)} The code flow or node.build() result.
|
|
2347
2391
|
*/
|
|
2348
2392
|
flowNodeFromShaderStage( shaderStage, node, output = null, propertyName = null ) {
|
|
2349
2393
|
|
|
@@ -2611,7 +2655,7 @@ class NodeBuilder {
|
|
|
2611
2655
|
/**
|
|
2612
2656
|
* Returns the closest sub-build layer for the given data.
|
|
2613
2657
|
*
|
|
2614
|
-
* @param {Node|Set
|
|
2658
|
+
* @param {Node|Set<string>|Array<string>} data - The data to get the closest sub-build layer from.
|
|
2615
2659
|
* @return {?string} The closest sub-build name or null if none found.
|
|
2616
2660
|
*/
|
|
2617
2661
|
getClosestSubBuild( data ) {
|
|
@@ -2743,7 +2787,7 @@ class NodeBuilder {
|
|
|
2743
2787
|
|
|
2744
2788
|
}
|
|
2745
2789
|
|
|
2746
|
-
// setup() -> stage 1: create possible new nodes and
|
|
2790
|
+
// setup() -> stage 1: create possible new nodes and/or return an output reference node
|
|
2747
2791
|
// analyze() -> stage 2: analyze nodes to possible optimization and validation
|
|
2748
2792
|
// generate() -> stage 3: generate shader
|
|
2749
2793
|
|
|
@@ -2918,11 +2962,6 @@ class NodeBuilder {
|
|
|
2918
2962
|
|
|
2919
2963
|
}
|
|
2920
2964
|
|
|
2921
|
-
/**
|
|
2922
|
-
* Prevents the node builder from being used as an iterable in TSL.Fn(), avoiding potential runtime errors.
|
|
2923
|
-
*/
|
|
2924
|
-
*[ Symbol.iterator ]() { }
|
|
2925
|
-
|
|
2926
2965
|
}
|
|
2927
2966
|
|
|
2928
2967
|
export default NodeBuilder;
|
|
@@ -115,7 +115,7 @@ class NodeFrame {
|
|
|
115
115
|
* @private
|
|
116
116
|
* @param {WeakMap<Node, Object>} referenceMap - The reference weak map.
|
|
117
117
|
* @param {Node} nodeRef - The reference to the current node.
|
|
118
|
-
* @return {Object<string,WeakMap
|
|
118
|
+
* @return {Object<string,WeakMap<Object, number>>} The dictionary.
|
|
119
119
|
*/
|
|
120
120
|
_getMaps( referenceMap, nodeRef ) {
|
|
121
121
|
|
|
@@ -88,7 +88,6 @@ export function getCacheKey( object, force = false ) {
|
|
|
88
88
|
if ( object.isNode === true ) {
|
|
89
89
|
|
|
90
90
|
values.push( object.id );
|
|
91
|
-
object = object.getSelf();
|
|
92
91
|
|
|
93
92
|
}
|
|
94
93
|
|
|
@@ -113,7 +112,7 @@ export function getCacheKey( object, force = false ) {
|
|
|
113
112
|
*/
|
|
114
113
|
export function* getNodeChildren( node, toJSON = false ) {
|
|
115
114
|
|
|
116
|
-
for ( const property
|
|
115
|
+
for ( const property of Object.getOwnPropertyNames( node ) ) {
|
|
117
116
|
|
|
118
117
|
// Ignore private properties.
|
|
119
118
|
if ( property.startsWith( '_' ) === true ) continue;
|
|
@@ -138,10 +137,13 @@ export function* getNodeChildren( node, toJSON = false ) {
|
|
|
138
137
|
|
|
139
138
|
yield { property, childNode: object };
|
|
140
139
|
|
|
141
|
-
} else if (
|
|
140
|
+
} else if ( object && Object.getPrototypeOf( object ) === Object.prototype ) {
|
|
142
141
|
|
|
143
142
|
for ( const subProperty in object ) {
|
|
144
143
|
|
|
144
|
+
// Ignore private properties.
|
|
145
|
+
if ( subProperty.startsWith( '_' ) === true ) continue;
|
|
146
|
+
|
|
145
147
|
const child = object[ subProperty ];
|
|
146
148
|
|
|
147
149
|
if ( child && ( child.isNode === true || toJSON && typeof child.toJSON === 'function' ) ) {
|
|
@@ -80,13 +80,13 @@ class StackNode extends Node {
|
|
|
80
80
|
|
|
81
81
|
getNodeType( builder ) {
|
|
82
82
|
|
|
83
|
-
return this.
|
|
83
|
+
return this.hasOutput ? this.outputNode.getNodeType( builder ) : 'void';
|
|
84
84
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
getMemberType( builder, name ) {
|
|
88
88
|
|
|
89
|
-
return this.
|
|
89
|
+
return this.hasOutput ? this.outputNode.getMemberType( builder, name ) : 'void';
|
|
90
90
|
|
|
91
91
|
}
|
|
92
92
|
|
|
@@ -98,6 +98,13 @@ class StackNode extends Node {
|
|
|
98
98
|
*/
|
|
99
99
|
add( node ) {
|
|
100
100
|
|
|
101
|
+
if ( node.isNode !== true ) {
|
|
102
|
+
|
|
103
|
+
console.error( 'THREE.TSL: Invalid node added to stack.' );
|
|
104
|
+
return this;
|
|
105
|
+
|
|
106
|
+
}
|
|
107
|
+
|
|
101
108
|
this.nodes.push( node );
|
|
102
109
|
|
|
103
110
|
return this;
|
|
@@ -191,7 +198,7 @@ class StackNode extends Node {
|
|
|
191
198
|
|
|
192
199
|
} else {
|
|
193
200
|
|
|
194
|
-
|
|
201
|
+
console.error( 'THREE.TSL: Invalid parameter length. Case() requires at least two parameters.' );
|
|
195
202
|
|
|
196
203
|
}
|
|
197
204
|
|
|
@@ -245,6 +252,42 @@ class StackNode extends Node {
|
|
|
245
252
|
|
|
246
253
|
}
|
|
247
254
|
|
|
255
|
+
setup( builder ) {
|
|
256
|
+
|
|
257
|
+
const nodeProperties = builder.getNodeProperties( this );
|
|
258
|
+
|
|
259
|
+
let index = 0;
|
|
260
|
+
|
|
261
|
+
for ( const childNode of this.getChildren() ) {
|
|
262
|
+
|
|
263
|
+
if ( childNode.isVarNode && childNode.intent === true ) {
|
|
264
|
+
|
|
265
|
+
const properties = builder.getNodeProperties( childNode );
|
|
266
|
+
|
|
267
|
+
if ( properties.assign !== true ) {
|
|
268
|
+
|
|
269
|
+
continue;
|
|
270
|
+
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
nodeProperties[ 'node' + index ++ ] = childNode;
|
|
276
|
+
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// return a outputNode if exists or null
|
|
280
|
+
|
|
281
|
+
return nodeProperties.outputNode || null;
|
|
282
|
+
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
get hasOutput() {
|
|
286
|
+
|
|
287
|
+
return this.outputNode && this.outputNode.isNode;
|
|
288
|
+
|
|
289
|
+
}
|
|
290
|
+
|
|
248
291
|
build( builder, ...params ) {
|
|
249
292
|
|
|
250
293
|
const previousBuildStack = builder.currentStack;
|
|
@@ -258,6 +301,18 @@ class StackNode extends Node {
|
|
|
258
301
|
|
|
259
302
|
for ( const node of this.nodes ) {
|
|
260
303
|
|
|
304
|
+
if ( node.isVarNode && node.intent === true ) {
|
|
305
|
+
|
|
306
|
+
const properties = builder.getNodeProperties( node );
|
|
307
|
+
|
|
308
|
+
if ( properties.assign !== true ) {
|
|
309
|
+
|
|
310
|
+
continue;
|
|
311
|
+
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
}
|
|
315
|
+
|
|
261
316
|
if ( buildStage === 'setup' ) {
|
|
262
317
|
|
|
263
318
|
node.build( builder );
|
|
@@ -283,7 +338,19 @@ class StackNode extends Node {
|
|
|
283
338
|
|
|
284
339
|
}
|
|
285
340
|
|
|
286
|
-
|
|
341
|
+
//
|
|
342
|
+
|
|
343
|
+
let result;
|
|
344
|
+
|
|
345
|
+
if ( this.hasOutput ) {
|
|
346
|
+
|
|
347
|
+
result = this.outputNode.build( builder, ...params );
|
|
348
|
+
|
|
349
|
+
} else {
|
|
350
|
+
|
|
351
|
+
result = super.build( builder, ...params );
|
|
352
|
+
|
|
353
|
+
}
|
|
287
354
|
|
|
288
355
|
setCurrentStack( previousStack );
|
|
289
356
|
|
|
@@ -30,11 +30,11 @@ class StructNode extends Node {
|
|
|
30
30
|
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
constructor(
|
|
33
|
+
constructor( structTypeNode, values ) {
|
|
34
34
|
|
|
35
35
|
super( 'vec3' );
|
|
36
36
|
|
|
37
|
-
this.
|
|
37
|
+
this.structTypeNode = structTypeNode;
|
|
38
38
|
this.values = values;
|
|
39
39
|
|
|
40
40
|
this.isStructNode = true;
|
|
@@ -43,13 +43,13 @@ class StructNode extends Node {
|
|
|
43
43
|
|
|
44
44
|
getNodeType( builder ) {
|
|
45
45
|
|
|
46
|
-
return this.
|
|
46
|
+
return this.structTypeNode.getNodeType( builder );
|
|
47
47
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
getMemberType( builder, name ) {
|
|
51
51
|
|
|
52
|
-
return this.
|
|
52
|
+
return this.structTypeNode.getMemberType( builder, name );
|
|
53
53
|
|
|
54
54
|
}
|
|
55
55
|
|
|
@@ -59,7 +59,7 @@ class StructNode extends Node {
|
|
|
59
59
|
const structType = nodeVar.type;
|
|
60
60
|
const propertyName = builder.getPropertyName( nodeVar );
|
|
61
61
|
|
|
62
|
-
builder.addLineFlowCode( `${ propertyName } = ${ builder.generateStruct( structType, this.
|
|
62
|
+
builder.addLineFlowCode( `${ propertyName } = ${ builder.generateStruct( structType, this.structTypeNode.membersLayout, this.values ) }`, this );
|
|
63
63
|
|
|
64
64
|
return nodeVar.name;
|
|
65
65
|
|
|
@@ -7,7 +7,7 @@ import { nodeObject } from '../tsl/TSLCore.js';
|
|
|
7
7
|
* @augments Node
|
|
8
8
|
* @param {Node} node - The node to be built in the sub-build.
|
|
9
9
|
* @param {string} name - The name of the sub-build.
|
|
10
|
-
* @param {string
|
|
10
|
+
* @param {?string} [nodeType=null] - The type of the node, if known.
|
|
11
11
|
*/
|
|
12
12
|
class SubBuildNode extends Node {
|
|
13
13
|
|
|
@@ -83,7 +83,7 @@ export default SubBuildNode;
|
|
|
83
83
|
* @function
|
|
84
84
|
* @param {Node} node - The node to be built in the sub-build.
|
|
85
85
|
* @param {string} name - The name of the sub-build.
|
|
86
|
-
* @param {string
|
|
86
|
+
* @param {?string} [type=null] - The type of the node, if known.
|
|
87
87
|
* @returns {Node} A node object wrapping the SubBuildNode instance.
|
|
88
88
|
*/
|
|
89
89
|
export const subBuild = ( node, name, type = null ) => nodeObject( new SubBuildNode( nodeObject( node ), name, type ) );
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import InputNode from './InputNode.js';
|
|
2
2
|
import { objectGroup } from './UniformGroupNode.js';
|
|
3
3
|
import { nodeObject, getConstNodeType } from '../tsl/TSLCore.js';
|
|
4
|
+
import { getValueFromType } from './NodeUtils.js';
|
|
4
5
|
|
|
5
6
|
/**
|
|
6
7
|
* Class for representing a uniform.
|
|
@@ -59,7 +60,7 @@ class UniformNode extends InputNode {
|
|
|
59
60
|
* @param {string} name - The name of the uniform.
|
|
60
61
|
* @return {UniformNode} A reference to this node.
|
|
61
62
|
*/
|
|
62
|
-
|
|
63
|
+
setName( name ) {
|
|
63
64
|
|
|
64
65
|
this.name = name;
|
|
65
66
|
|
|
@@ -67,6 +68,21 @@ class UniformNode extends InputNode {
|
|
|
67
68
|
|
|
68
69
|
}
|
|
69
70
|
|
|
71
|
+
/**
|
|
72
|
+
* Sets the {@link UniformNode#name} property.
|
|
73
|
+
*
|
|
74
|
+
* @deprecated
|
|
75
|
+
* @param {string} name - The name of the uniform.
|
|
76
|
+
* @return {UniformNode} A reference to this node.
|
|
77
|
+
*/
|
|
78
|
+
label( name ) {
|
|
79
|
+
|
|
80
|
+
console.warn( 'THREE.TSL: "label()" has been deprecated. Use "setName()" instead.' ); // @deprecated r179
|
|
81
|
+
|
|
82
|
+
return this.setName( name );
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
70
86
|
/**
|
|
71
87
|
* Sets the {@link UniformNode#groupNode} property.
|
|
72
88
|
*
|
|
@@ -107,13 +123,11 @@ class UniformNode extends InputNode {
|
|
|
107
123
|
|
|
108
124
|
onUpdate( callback, updateType ) {
|
|
109
125
|
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
callback = callback.bind( self );
|
|
126
|
+
callback = callback.bind( this );
|
|
113
127
|
|
|
114
128
|
return super.onUpdate( ( frame ) => {
|
|
115
129
|
|
|
116
|
-
const value = callback( frame,
|
|
130
|
+
const value = callback( frame, this );
|
|
117
131
|
|
|
118
132
|
if ( value !== undefined ) {
|
|
119
133
|
|
|
@@ -125,6 +139,20 @@ class UniformNode extends InputNode {
|
|
|
125
139
|
|
|
126
140
|
}
|
|
127
141
|
|
|
142
|
+
getInputType( builder ) {
|
|
143
|
+
|
|
144
|
+
let type = super.getInputType( builder );
|
|
145
|
+
|
|
146
|
+
if ( type === 'bool' ) {
|
|
147
|
+
|
|
148
|
+
type = 'uint';
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return type;
|
|
153
|
+
|
|
154
|
+
}
|
|
155
|
+
|
|
128
156
|
generate( builder, output ) {
|
|
129
157
|
|
|
130
158
|
const type = this.getNodeType( builder );
|
|
@@ -143,12 +171,41 @@ class UniformNode extends InputNode {
|
|
|
143
171
|
|
|
144
172
|
const sharedNodeType = sharedNode.getInputType( builder );
|
|
145
173
|
|
|
146
|
-
const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.
|
|
147
|
-
const
|
|
174
|
+
const nodeUniform = builder.getUniformFromNode( sharedNode, sharedNodeType, builder.shaderStage, this.name || builder.context.nodeName );
|
|
175
|
+
const uniformName = builder.getPropertyName( nodeUniform );
|
|
176
|
+
|
|
177
|
+
if ( builder.context.nodeName !== undefined ) delete builder.context.nodeName;
|
|
178
|
+
|
|
179
|
+
//
|
|
180
|
+
|
|
181
|
+
let snippet = uniformName;
|
|
182
|
+
|
|
183
|
+
if ( type === 'bool' ) {
|
|
184
|
+
|
|
185
|
+
// cache to variable
|
|
186
|
+
|
|
187
|
+
const nodeData = builder.getDataFromNode( this );
|
|
188
|
+
|
|
189
|
+
let propertyName = nodeData.propertyName;
|
|
190
|
+
|
|
191
|
+
if ( propertyName === undefined ) {
|
|
192
|
+
|
|
193
|
+
const nodeVar = builder.getVarFromNode( this, null, 'bool' );
|
|
194
|
+
propertyName = builder.getPropertyName( nodeVar );
|
|
195
|
+
|
|
196
|
+
nodeData.propertyName = propertyName;
|
|
148
197
|
|
|
149
|
-
|
|
198
|
+
snippet = builder.format( uniformName, sharedNodeType, type );
|
|
150
199
|
|
|
151
|
-
|
|
200
|
+
builder.addLineFlowCode( `${ propertyName } = ${ snippet }`, this );
|
|
201
|
+
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
snippet = propertyName;
|
|
205
|
+
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
return builder.format( snippet, type, output );
|
|
152
209
|
|
|
153
210
|
}
|
|
154
211
|
|
|
@@ -161,16 +218,24 @@ export default UniformNode;
|
|
|
161
218
|
*
|
|
162
219
|
* @tsl
|
|
163
220
|
* @function
|
|
164
|
-
* @param {any}
|
|
165
|
-
* @param {string} [
|
|
221
|
+
* @param {any|string} value - The value of this uniform or your type. Usually a JS primitive or three.js object (vector, matrix, color, texture).
|
|
222
|
+
* @param {string} [type] - The node type. If no explicit type is defined, the node tries to derive the type from its value.
|
|
166
223
|
* @returns {UniformNode}
|
|
167
224
|
*/
|
|
168
|
-
export const uniform = (
|
|
225
|
+
export const uniform = ( value, type ) => {
|
|
169
226
|
|
|
170
|
-
const nodeType = getConstNodeType(
|
|
227
|
+
const nodeType = getConstNodeType( type || value );
|
|
228
|
+
|
|
229
|
+
if ( nodeType === value ) {
|
|
230
|
+
|
|
231
|
+
// if the value is a type but no having a value
|
|
232
|
+
|
|
233
|
+
value = getValueFromType( nodeType );
|
|
234
|
+
|
|
235
|
+
}
|
|
171
236
|
|
|
172
237
|
// @TODO: get ConstNode from .traverse() in the future
|
|
173
|
-
|
|
238
|
+
value = ( value && value.isNode === true ) ? ( value.node && value.node.value ) || value.value : value;
|
|
174
239
|
|
|
175
240
|
return nodeObject( new UniformNode( value, nodeType ) );
|
|
176
241
|
|