@needle-tools/three 0.153.1 → 0.154.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/three.cjs +1260 -1517
- package/build/three.js +1267 -1524
- package/build/three.min.js +7 -8
- package/build/three.module.js +859 -1097
- package/build/three.module.min.js +6 -7
- package/examples/jsm/controls/ArcballControls.js +2 -1
- package/examples/jsm/controls/FlyControls.js +25 -9
- package/examples/jsm/controls/OrbitControls.js +7 -1
- package/examples/jsm/csm/CSM.js +1 -1
- package/examples/jsm/effects/AnaglyphEffect.js +1 -1
- package/examples/jsm/effects/OutlineEffect.js +1 -1
- package/examples/jsm/effects/ParallaxBarrierEffect.js +1 -1
- package/examples/jsm/environments/RoomEnvironment.js +6 -2
- package/examples/jsm/lines/LineMaterial.js +1 -1
- package/examples/jsm/loaders/3DMLoader.js +1 -1
- package/examples/jsm/loaders/3MFLoader.js +5 -1
- package/examples/jsm/loaders/AMFLoader.js +5 -1
- package/examples/jsm/loaders/ColladaLoader.js +4 -1
- package/examples/jsm/loaders/FBXLoader.js +9 -2
- package/examples/jsm/loaders/GLTFLoader.js +8 -2
- package/examples/jsm/loaders/GLTFLoaderAnimationPointer.js +2 -2
- package/examples/jsm/loaders/LDrawLoader.js +4 -7
- package/examples/jsm/loaders/PLYLoader.js +16 -6
- package/examples/jsm/loaders/VRMLLoader.js +16 -4
- package/examples/jsm/materials/MeshGouraudMaterial.js +2 -2
- package/examples/jsm/math/MeshSurfaceSampler.js +76 -35
- package/examples/jsm/nodes/Nodes.js +20 -15
- package/examples/jsm/nodes/accessors/BufferAttributeNode.js +21 -8
- package/examples/jsm/nodes/accessors/CameraNode.js +25 -4
- package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +7 -1
- package/examples/jsm/nodes/accessors/InstanceNode.js +2 -4
- package/examples/jsm/nodes/accessors/MaterialNode.js +55 -47
- package/examples/jsm/nodes/accessors/ModelNode.js +3 -1
- package/examples/jsm/nodes/accessors/MorphNode.js +70 -0
- package/examples/jsm/nodes/accessors/NormalNode.js +3 -2
- package/examples/jsm/nodes/accessors/Object3DNode.js +10 -2
- package/examples/jsm/nodes/accessors/SceneNode.js +46 -0
- package/examples/jsm/nodes/accessors/SkinningNode.js +43 -62
- package/examples/jsm/nodes/accessors/TangentNode.js +2 -2
- package/examples/jsm/nodes/accessors/TextureBicubicNode.js +94 -0
- package/examples/jsm/nodes/accessors/TextureNode.js +68 -6
- package/examples/jsm/nodes/accessors/TextureSizeNode.js +35 -0
- package/examples/jsm/nodes/accessors/UVNode.js +1 -1
- package/examples/jsm/nodes/code/CodeNode.js +3 -0
- package/examples/jsm/nodes/code/FunctionNode.js +25 -4
- package/examples/jsm/nodes/core/BypassNode.js +2 -2
- package/examples/jsm/nodes/core/ContextNode.js +2 -0
- package/examples/jsm/nodes/core/IndexNode.js +66 -0
- package/examples/jsm/nodes/core/LightingModel.js +2 -1
- package/examples/jsm/nodes/core/Node.js +12 -15
- package/examples/jsm/nodes/core/NodeBuilder.js +24 -5
- package/examples/jsm/nodes/core/PropertyNode.js +4 -0
- package/examples/jsm/nodes/core/StackNode.js +1 -1
- package/examples/jsm/nodes/core/UniformNode.js +1 -1
- package/examples/jsm/nodes/core/VarNode.js +1 -3
- package/examples/jsm/nodes/display/BlendModeNode.js +9 -9
- package/examples/jsm/nodes/display/ColorAdjustmentNode.js +7 -7
- package/examples/jsm/nodes/display/ColorSpaceNode.js +50 -49
- package/examples/jsm/nodes/display/NormalMapNode.js +3 -3
- package/examples/jsm/nodes/display/ToneMappingNode.js +8 -8
- package/examples/jsm/nodes/display/ViewportDepthNode.js +69 -0
- package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +34 -0
- package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +6 -5
- package/examples/jsm/nodes/display/ViewportTextureNode.js +23 -15
- package/examples/jsm/nodes/functions/BSDF/BRDF_BlinnPhong.js +5 -5
- package/examples/jsm/nodes/functions/BSDF/BRDF_GGX.js +10 -8
- package/examples/jsm/nodes/functions/BSDF/BRDF_Lambert.js +2 -2
- package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +43 -0
- package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +4 -4
- package/examples/jsm/nodes/functions/BSDF/D_GGX.js +2 -2
- package/examples/jsm/nodes/functions/BSDF/EnvironmentBRDF.js +13 -0
- package/examples/jsm/nodes/functions/BSDF/F_Schlick.js +2 -4
- package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +2 -2
- package/examples/jsm/nodes/functions/PhongLightingModel.js +7 -7
- package/examples/jsm/nodes/functions/PhysicalLightingModel.js +129 -18
- package/examples/jsm/nodes/functions/material/getGeometryRoughness.js +2 -2
- package/examples/jsm/nodes/functions/material/getRoughness.js +3 -3
- package/examples/jsm/nodes/geometry/RangeNode.js +1 -1
- package/examples/jsm/nodes/lighting/DirectionalLightNode.js +2 -2
- package/examples/jsm/nodes/lighting/EnvironmentNode.js +91 -62
- package/examples/jsm/nodes/lighting/LightUtils.js +2 -2
- package/examples/jsm/nodes/lighting/LightingContextNode.js +17 -15
- package/examples/jsm/nodes/lighting/PointLightNode.js +3 -3
- package/examples/jsm/nodes/lighting/SpotLightNode.js +3 -3
- package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +0 -15
- package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +0 -15
- package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +0 -10
- package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +0 -9
- package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +41 -0
- package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +1 -14
- package/examples/jsm/nodes/materials/NodeMaterial.js +79 -28
- package/examples/jsm/nodes/materials/PointsNodeMaterial.js +0 -9
- package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +0 -7
- package/examples/jsm/nodes/materialx/lib/mx_hsv.js +3 -3
- package/examples/jsm/nodes/materialx/lib/mx_noise.js +14 -14
- package/examples/jsm/nodes/materialx/lib/mx_transform_color.js +4 -4
- package/examples/jsm/nodes/math/MathNode.js +6 -0
- package/examples/jsm/nodes/math/OperatorNode.js +1 -1
- package/examples/jsm/nodes/procedural/CheckerNode.js +3 -3
- package/examples/jsm/nodes/shadernode/ShaderNode.js +24 -4
- package/examples/jsm/nodes/utils/LoopNode.js +1 -1
- package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +1 -1
- package/examples/jsm/objects/GroundProjectedSkybox.js +1 -1
- package/examples/jsm/objects/Reflector.js +1 -1
- package/examples/jsm/objects/Refractor.js +1 -1
- package/examples/jsm/objects/Sky.js +1 -1
- package/examples/jsm/objects/Water.js +1 -1
- package/examples/jsm/objects/Water2.js +1 -1
- package/examples/jsm/offscreen/scene.js +1 -0
- package/examples/jsm/postprocessing/EffectComposer.js +2 -0
- package/examples/jsm/postprocessing/OutlinePass.js +1 -3
- package/examples/jsm/postprocessing/SSAARenderPass.js +3 -12
- package/examples/jsm/postprocessing/SavePass.js +3 -1
- package/examples/jsm/postprocessing/TAARenderPass.js +14 -2
- package/examples/jsm/postprocessing/TexturePass.js +2 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +9 -10
- package/examples/jsm/renderers/common/Backend.js +2 -0
- package/examples/jsm/renderers/common/Background.js +7 -6
- package/examples/jsm/renderers/common/Pipelines.js +26 -14
- package/examples/jsm/renderers/common/RenderObject.js +18 -0
- package/examples/jsm/renderers/common/RenderObjects.js +29 -29
- package/examples/jsm/renderers/common/Renderer.js +48 -6
- package/examples/jsm/renderers/common/nodes/Nodes.js +1 -1
- package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +340 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +23 -19
- package/examples/jsm/renderers/webgpu/WebGPUBackend.js +123 -41
- package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +29 -9
- package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +4 -0
- package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +8 -13
- package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +85 -3
- package/examples/jsm/renderers/webgpu/utils/WebGPUUtils.js +5 -1
- package/examples/jsm/shaders/BlendShader.js +1 -2
- package/examples/jsm/shaders/BokehShader2.js +1 -1
- package/examples/jsm/shaders/CopyShader.js +2 -2
- package/examples/jsm/shaders/ToonShader.js +4 -4
- package/examples/jsm/shaders/WaterRefractionShader.js +1 -1
- package/examples/jsm/webxr/OculusHandPointerModel.js +34 -13
- package/package.json +2 -1
- package/src/Three.Legacy.js +0 -228
- package/src/animation/PropertyBinding.js +1 -1
- package/src/constants.js +1 -1
- package/src/core/BufferAttribute.js +0 -24
- package/src/core/BufferGeometry.js +0 -7
- package/src/loaders/Loader.js +2 -0
- package/src/loaders/MaterialLoader.js +1 -0
- package/src/materials/Material.js +3 -0
- package/src/objects/Skeleton.js +0 -2
- package/src/renderers/WebGLRenderer.js +9 -21
- package/src/renderers/shaders/ShaderChunk/alphahash_fragment.glsl.js +7 -0
- package/src/renderers/shaders/ShaderChunk/alphahash_pars_fragment.glsl.js +68 -0
- package/src/renderers/shaders/ShaderChunk/begin_vertex.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/common.glsl.js +6 -0
- package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +9 -1
- package/src/renderers/shaders/ShaderChunk/uv_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/uv_pars_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/uv_vertex.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk.js +10 -6
- package/src/renderers/shaders/ShaderLib/background.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/cube.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
- package/src/renderers/shaders/ShaderLib/equirect.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +2 -2
- package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/points.glsl.js +4 -2
- package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/sprite.glsl.js +4 -2
- package/src/renderers/webgl/WebGLObjects.js +23 -3
- package/src/renderers/webgl/WebGLProgram.js +24 -5
- package/src/renderers/webgl/WebGLPrograms.js +3 -0
- package/src/renderers/webxr/WebXRManager.js +11 -33
- package/src/scenes/Scene.js +0 -14
- package/examples/jsm/nodes/core/InstanceIndexNode.js +0 -45
- /package/src/renderers/shaders/ShaderChunk/{encodings_fragment.glsl.js → colorspace_fragment.glsl.js} +0 -0
- /package/src/renderers/shaders/ShaderChunk/{encodings_pars_fragment.glsl.js → colorspace_pars_fragment.glsl.js} +0 -0
- /package/src/renderers/shaders/ShaderChunk/{output_fragment.glsl.js → opaque_fragment.glsl.js} +0 -0
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import Object3DNode from './Object3DNode.js';
|
|
2
2
|
import { addNodeClass } from '../core/Node.js';
|
|
3
|
+
import { label } from '../core/ContextNode.js';
|
|
3
4
|
import { nodeImmutable } from '../shadernode/ShaderNode.js';
|
|
4
5
|
|
|
5
6
|
class ModelNode extends Object3DNode {
|
|
@@ -23,10 +24,11 @@ class ModelNode extends Object3DNode {
|
|
|
23
24
|
export default ModelNode;
|
|
24
25
|
|
|
25
26
|
export const modelDirection = nodeImmutable( ModelNode, ModelNode.DIRECTION );
|
|
26
|
-
export const modelViewMatrix = nodeImmutable( ModelNode, ModelNode.VIEW_MATRIX );
|
|
27
|
+
export const modelViewMatrix = label( nodeImmutable( ModelNode, ModelNode.VIEW_MATRIX ), 'modelViewMatrix' );
|
|
27
28
|
export const modelNormalMatrix = nodeImmutable( ModelNode, ModelNode.NORMAL_MATRIX );
|
|
28
29
|
export const modelWorldMatrix = nodeImmutable( ModelNode, ModelNode.WORLD_MATRIX );
|
|
29
30
|
export const modelPosition = nodeImmutable( ModelNode, ModelNode.POSITION );
|
|
31
|
+
export const modelScale = nodeImmutable( ModelNode, ModelNode.SCALE );
|
|
30
32
|
export const modelViewPosition = nodeImmutable( ModelNode, ModelNode.VIEW_POSITION );
|
|
31
33
|
|
|
32
34
|
addNodeClass( ModelNode );
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import Node, { addNodeClass } from '../core/Node.js';
|
|
2
|
+
import { NodeUpdateType } from '../core/constants.js';
|
|
3
|
+
import { nodeProxy } from '../shadernode/ShaderNode.js';
|
|
4
|
+
import { uniform } from '../core/UniformNode.js';
|
|
5
|
+
import { reference } from './ReferenceNode.js';
|
|
6
|
+
import { bufferAttribute } from './BufferAttributeNode.js';
|
|
7
|
+
import { positionLocal } from './PositionNode.js';
|
|
8
|
+
|
|
9
|
+
class MorphNode extends Node {
|
|
10
|
+
|
|
11
|
+
constructor( mesh ) {
|
|
12
|
+
|
|
13
|
+
super( 'void' );
|
|
14
|
+
|
|
15
|
+
this.mesh = mesh;
|
|
16
|
+
this.morphBaseInfluence = uniform( 1 );
|
|
17
|
+
|
|
18
|
+
this.updateType = NodeUpdateType.OBJECT;
|
|
19
|
+
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
constructAttribute( builder, name, assignNode = positionLocal ) {
|
|
23
|
+
|
|
24
|
+
const mesh = this.mesh;
|
|
25
|
+
const attributes = mesh.geometry.morphAttributes[ name ];
|
|
26
|
+
|
|
27
|
+
builder.stack.assign( assignNode, assignNode.mul( this.morphBaseInfluence ) );
|
|
28
|
+
|
|
29
|
+
for ( let i = 0; i < attributes.length; i ++ ) {
|
|
30
|
+
|
|
31
|
+
const attribute = attributes[ i ];
|
|
32
|
+
|
|
33
|
+
const bufferAttrib = bufferAttribute( attribute.array, 'vec3' );
|
|
34
|
+
const influence = reference( i, 'float', mesh.morphTargetInfluences );
|
|
35
|
+
|
|
36
|
+
builder.stack.assign( assignNode, assignNode.add( bufferAttrib.mul( influence ) ) );
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
construct( builder ) {
|
|
43
|
+
|
|
44
|
+
this.constructAttribute( builder, 'position' );
|
|
45
|
+
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
update() {
|
|
49
|
+
|
|
50
|
+
const morphBaseInfluence = this.morphBaseInfluence;
|
|
51
|
+
|
|
52
|
+
if ( this.mesh.geometry.morphTargetsRelative ) {
|
|
53
|
+
|
|
54
|
+
morphBaseInfluence.value = 1;
|
|
55
|
+
|
|
56
|
+
} else {
|
|
57
|
+
|
|
58
|
+
morphBaseInfluence.value = 1 - this.mesh.morphTargetInfluences.reduce( ( a, b ) => a + b, 0 );
|
|
59
|
+
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export default MorphNode;
|
|
67
|
+
|
|
68
|
+
export const morph = nodeProxy( MorphNode );
|
|
69
|
+
|
|
70
|
+
addNodeClass( MorphNode );
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import Node, { addNodeClass } from '../core/Node.js';
|
|
2
2
|
import { attribute } from '../core/AttributeNode.js';
|
|
3
|
-
import { label } from '../core/VarNode.js';
|
|
4
3
|
import { varying } from '../core/VaryingNode.js';
|
|
4
|
+
import { property } from '../core/PropertyNode.js';
|
|
5
5
|
import { normalize } from '../math/MathNode.js';
|
|
6
6
|
import { cameraViewMatrix } from './CameraNode.js';
|
|
7
7
|
import { modelNormalMatrix } from './ModelNode.js';
|
|
@@ -89,7 +89,8 @@ export const normalGeometry = nodeImmutable( NormalNode, NormalNode.GEOMETRY );
|
|
|
89
89
|
export const normalLocal = nodeImmutable( NormalNode, NormalNode.LOCAL );
|
|
90
90
|
export const normalView = nodeImmutable( NormalNode, NormalNode.VIEW );
|
|
91
91
|
export const normalWorld = nodeImmutable( NormalNode, NormalNode.WORLD );
|
|
92
|
-
export const transformedNormalView =
|
|
92
|
+
export const transformedNormalView = property( 'vec3', 'TransformedNormalView' );
|
|
93
93
|
export const transformedNormalWorld = transformedNormalView.transformDirection( cameraViewMatrix ).normalize();
|
|
94
|
+
export const transformedClearcoatNormalView = property( 'vec3', 'TransformedClearcoatNormalView' );
|
|
94
95
|
|
|
95
96
|
addNodeClass( NormalNode );
|
|
@@ -32,7 +32,7 @@ class Object3DNode extends Node {
|
|
|
32
32
|
|
|
33
33
|
return 'mat3';
|
|
34
34
|
|
|
35
|
-
} else if ( scope === Object3DNode.POSITION || scope === Object3DNode.VIEW_POSITION || scope === Object3DNode.DIRECTION ) {
|
|
35
|
+
} else if ( scope === Object3DNode.POSITION || scope === Object3DNode.VIEW_POSITION || scope === Object3DNode.DIRECTION || scope === Object3DNode.SCALE ) {
|
|
36
36
|
|
|
37
37
|
return 'vec3';
|
|
38
38
|
|
|
@@ -64,6 +64,12 @@ class Object3DNode extends Node {
|
|
|
64
64
|
|
|
65
65
|
uniformNode.value.setFromMatrixPosition( object.matrixWorld );
|
|
66
66
|
|
|
67
|
+
} else if ( scope === Object3DNode.SCALE ) {
|
|
68
|
+
|
|
69
|
+
uniformNode.value = uniformNode.value || new Vector3();
|
|
70
|
+
|
|
71
|
+
uniformNode.value.setFromMatrixScale( object.matrixWorld );
|
|
72
|
+
|
|
67
73
|
} else if ( scope === Object3DNode.DIRECTION ) {
|
|
68
74
|
|
|
69
75
|
uniformNode.value = uniformNode.value || new Vector3();
|
|
@@ -95,7 +101,7 @@ class Object3DNode extends Node {
|
|
|
95
101
|
|
|
96
102
|
this._uniformNode.nodeType = 'mat3';
|
|
97
103
|
|
|
98
|
-
} else if ( scope === Object3DNode.POSITION || scope === Object3DNode.VIEW_POSITION || scope === Object3DNode.DIRECTION ) {
|
|
104
|
+
} else if ( scope === Object3DNode.POSITION || scope === Object3DNode.VIEW_POSITION || scope === Object3DNode.DIRECTION || scope === Object3DNode.SCALE ) {
|
|
99
105
|
|
|
100
106
|
this._uniformNode.nodeType = 'vec3';
|
|
101
107
|
|
|
@@ -127,6 +133,7 @@ Object3DNode.VIEW_MATRIX = 'viewMatrix';
|
|
|
127
133
|
Object3DNode.NORMAL_MATRIX = 'normalMatrix';
|
|
128
134
|
Object3DNode.WORLD_MATRIX = 'worldMatrix';
|
|
129
135
|
Object3DNode.POSITION = 'position';
|
|
136
|
+
Object3DNode.SCALE = 'scale';
|
|
130
137
|
Object3DNode.VIEW_POSITION = 'viewPosition';
|
|
131
138
|
Object3DNode.DIRECTION = 'direction';
|
|
132
139
|
|
|
@@ -137,6 +144,7 @@ export const objectViewMatrix = nodeProxy( Object3DNode, Object3DNode.VIEW_MATRI
|
|
|
137
144
|
export const objectNormalMatrix = nodeProxy( Object3DNode, Object3DNode.NORMAL_MATRIX );
|
|
138
145
|
export const objectWorldMatrix = nodeProxy( Object3DNode, Object3DNode.WORLD_MATRIX );
|
|
139
146
|
export const objectPosition = nodeProxy( Object3DNode, Object3DNode.POSITION );
|
|
147
|
+
export const objectScale = nodeProxy( Object3DNode, Object3DNode.SCALE );
|
|
140
148
|
export const objectViewPosition = nodeProxy( Object3DNode, Object3DNode.VIEW_POSITION );
|
|
141
149
|
|
|
142
150
|
addNodeClass( Object3DNode );
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import Node from '../core/Node.js';
|
|
2
|
+
import { addNodeClass } from '../core/Node.js';
|
|
3
|
+
import { nodeImmutable } from '../shadernode/ShaderNode.js';
|
|
4
|
+
import { reference } from './ReferenceNode.js';
|
|
5
|
+
|
|
6
|
+
class SceneNode extends Node {
|
|
7
|
+
|
|
8
|
+
constructor( scope = SceneNode.BACKGROUND_BLURRINESS, scene = null ) {
|
|
9
|
+
|
|
10
|
+
super();
|
|
11
|
+
|
|
12
|
+
this.scope = scope;
|
|
13
|
+
this.scene = scene;
|
|
14
|
+
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
construct( builder ) {
|
|
18
|
+
|
|
19
|
+
const scope = this.scope;
|
|
20
|
+
const scene = this.scene !== null ? this.scene : builder.scene;
|
|
21
|
+
|
|
22
|
+
let output;
|
|
23
|
+
|
|
24
|
+
if ( scope === SceneNode.BACKGROUND_BLURRINESS ) {
|
|
25
|
+
|
|
26
|
+
output = reference( 'backgroundBlurriness', 'float', scene );
|
|
27
|
+
|
|
28
|
+
} else {
|
|
29
|
+
|
|
30
|
+
console.error( 'THREE.SceneNode: Unknown scope:', scope );
|
|
31
|
+
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return output;
|
|
35
|
+
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
SceneNode.BACKGROUND_BLURRINESS = 'backgroundBlurriness';
|
|
41
|
+
|
|
42
|
+
export default SceneNode;
|
|
43
|
+
|
|
44
|
+
export const backgroundBlurriness = nodeImmutable( SceneNode, SceneNode.BACKGROUND_BLURRINESS );
|
|
45
|
+
|
|
46
|
+
addNodeClass( SceneNode );
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Node, { addNodeClass } from '../core/Node.js';
|
|
2
2
|
import { NodeUpdateType } from '../core/constants.js';
|
|
3
|
-
import {
|
|
3
|
+
import { nodeProxy } from '../shadernode/ShaderNode.js';
|
|
4
4
|
import { attribute } from '../core/AttributeNode.js';
|
|
5
5
|
import { uniform } from '../core/UniformNode.js';
|
|
6
6
|
import { add } from '../math/OperatorNode.js';
|
|
@@ -9,91 +9,72 @@ import { normalLocal } from './NormalNode.js';
|
|
|
9
9
|
import { positionLocal } from './PositionNode.js';
|
|
10
10
|
import { tangentLocal } from './TangentNode.js';
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
class SkinningNode extends Node {
|
|
13
13
|
|
|
14
|
-
|
|
14
|
+
constructor( skinnedMesh ) {
|
|
15
15
|
|
|
16
|
-
|
|
17
|
-
const boneMatY = boneMatrices.element( index.y );
|
|
18
|
-
const boneMatZ = boneMatrices.element( index.z );
|
|
19
|
-
const boneMatW = boneMatrices.element( index.w );
|
|
16
|
+
super( 'void' );
|
|
20
17
|
|
|
21
|
-
|
|
18
|
+
this.skinnedMesh = skinnedMesh;
|
|
22
19
|
|
|
23
|
-
|
|
20
|
+
this.updateType = NodeUpdateType.OBJECT;
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
boneMatX.mul( weight.x ).mul( skinVertex ),
|
|
27
|
-
boneMatY.mul( weight.y ).mul( skinVertex ),
|
|
28
|
-
boneMatZ.mul( weight.z ).mul( skinVertex ),
|
|
29
|
-
boneMatW.mul( weight.w ).mul( skinVertex )
|
|
30
|
-
);
|
|
22
|
+
//
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
this.skinIndexNode = attribute( 'skinIndex', 'uvec4' );
|
|
25
|
+
this.skinWeightNode = attribute( 'skinWeight', 'vec4' );
|
|
33
26
|
|
|
34
|
-
|
|
27
|
+
this.bindMatrixNode = uniform( skinnedMesh.bindMatrix, 'mat4' );
|
|
28
|
+
this.bindMatrixInverseNode = uniform( skinnedMesh.bindMatrixInverse, 'mat4' );
|
|
29
|
+
this.boneMatricesNode = buffer( skinnedMesh.skeleton.boneMatrices, 'mat4', skinnedMesh.skeleton.bones.length );
|
|
35
30
|
|
|
36
|
-
|
|
37
|
-
weight.x.mul( boneMatX ),
|
|
38
|
-
weight.y.mul( boneMatY ),
|
|
39
|
-
weight.z.mul( boneMatZ ),
|
|
40
|
-
weight.w.mul( boneMatW )
|
|
41
|
-
);
|
|
31
|
+
}
|
|
42
32
|
|
|
43
|
-
|
|
33
|
+
construct( builder ) {
|
|
44
34
|
|
|
45
|
-
|
|
35
|
+
const { skinIndexNode, skinWeightNode, bindMatrixNode, bindMatrixInverseNode, boneMatricesNode } = this;
|
|
46
36
|
|
|
47
|
-
|
|
37
|
+
const boneMatX = boneMatricesNode.element( skinIndexNode.x );
|
|
38
|
+
const boneMatY = boneMatricesNode.element( skinIndexNode.y );
|
|
39
|
+
const boneMatZ = boneMatricesNode.element( skinIndexNode.z );
|
|
40
|
+
const boneMatW = boneMatricesNode.element( skinIndexNode.w );
|
|
48
41
|
|
|
49
|
-
|
|
50
|
-
normalLocal.assign( skinNormal ).build( builder );
|
|
42
|
+
// POSITION
|
|
51
43
|
|
|
52
|
-
|
|
44
|
+
const skinVertex = bindMatrixNode.mul( positionLocal );
|
|
53
45
|
|
|
54
|
-
|
|
46
|
+
const skinned = add(
|
|
47
|
+
boneMatX.mul( skinWeightNode.x ).mul( skinVertex ),
|
|
48
|
+
boneMatY.mul( skinWeightNode.y ).mul( skinVertex ),
|
|
49
|
+
boneMatZ.mul( skinWeightNode.z ).mul( skinVertex ),
|
|
50
|
+
boneMatW.mul( skinWeightNode.w ).mul( skinVertex )
|
|
51
|
+
);
|
|
55
52
|
|
|
56
|
-
|
|
53
|
+
const skinPosition = bindMatrixInverseNode.mul( skinned ).xyz;
|
|
57
54
|
|
|
58
|
-
|
|
55
|
+
// NORMAL
|
|
59
56
|
|
|
60
|
-
|
|
57
|
+
let skinMatrix = add(
|
|
58
|
+
skinWeightNode.x.mul( boneMatX ),
|
|
59
|
+
skinWeightNode.y.mul( boneMatY ),
|
|
60
|
+
skinWeightNode.z.mul( boneMatZ ),
|
|
61
|
+
skinWeightNode.w.mul( boneMatW )
|
|
62
|
+
);
|
|
61
63
|
|
|
62
|
-
|
|
64
|
+
skinMatrix = bindMatrixInverseNode.mul( skinMatrix ).mul( bindMatrixNode );
|
|
63
65
|
|
|
64
|
-
|
|
66
|
+
const skinNormal = skinMatrix.transformDirection( normalLocal ).xyz;
|
|
65
67
|
|
|
66
|
-
|
|
68
|
+
// ASSIGNS
|
|
67
69
|
|
|
68
|
-
|
|
70
|
+
builder.stack.assign( positionLocal, skinPosition );
|
|
71
|
+
builder.stack.assign( normalLocal, skinNormal );
|
|
69
72
|
|
|
70
|
-
|
|
73
|
+
if ( builder.hasGeometryAttribute( 'tangent' ) ) {
|
|
71
74
|
|
|
72
|
-
|
|
73
|
-
this.skinWeightNode = attribute( 'skinWeight', 'vec4' );
|
|
74
|
-
|
|
75
|
-
this.bindMatrixNode = uniform( skinnedMesh.bindMatrix, 'mat4' );
|
|
76
|
-
this.bindMatrixInverseNode = uniform( skinnedMesh.bindMatrixInverse, 'mat4' );
|
|
77
|
-
this.boneMatricesNode = buffer( skinnedMesh.skeleton.boneMatrices, 'mat4', skinnedMesh.skeleton.bones.length );
|
|
78
|
-
|
|
79
|
-
}
|
|
75
|
+
builder.stack.assign( tangentLocal, skinNormal );
|
|
80
76
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
/*return new ShaderNode( ( {}, stack, builder ) => Skinning.call( {
|
|
84
|
-
index: this.skinIndexNode,
|
|
85
|
-
weight: this.skinWeightNode,
|
|
86
|
-
bindMatrix: this.bindMatrixNode,
|
|
87
|
-
bindMatrixInverse: this.bindMatrixInverseNode,
|
|
88
|
-
boneMatrices: this.boneMatricesNode
|
|
89
|
-
}, stack, builder ) ).build( builder );*/
|
|
90
|
-
Skinning.call( {
|
|
91
|
-
index: this.skinIndexNode,
|
|
92
|
-
weight: this.skinWeightNode,
|
|
93
|
-
bindMatrix: this.bindMatrixNode,
|
|
94
|
-
bindMatrixInverse: this.bindMatrixInverseNode,
|
|
95
|
-
boneMatrices: this.boneMatricesNode
|
|
96
|
-
}, {}, builder );
|
|
77
|
+
}
|
|
97
78
|
|
|
98
79
|
}
|
|
99
80
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import Node, { addNodeClass } from '../core/Node.js';
|
|
2
2
|
import { attribute } from '../core/AttributeNode.js';
|
|
3
|
-
import {
|
|
3
|
+
import { temp } from '../core/VarNode.js';
|
|
4
4
|
import { varying } from '../core/VaryingNode.js';
|
|
5
5
|
import { normalize } from '../math/MathNode.js';
|
|
6
6
|
import { cameraViewMatrix } from './CameraNode.js';
|
|
@@ -97,7 +97,7 @@ export const tangentGeometry = nodeImmutable( TangentNode, TangentNode.GEOMETRY
|
|
|
97
97
|
export const tangentLocal = nodeImmutable( TangentNode, TangentNode.LOCAL );
|
|
98
98
|
export const tangentView = nodeImmutable( TangentNode, TangentNode.VIEW );
|
|
99
99
|
export const tangentWorld = nodeImmutable( TangentNode, TangentNode.WORLD );
|
|
100
|
-
export const transformedTangentView =
|
|
100
|
+
export const transformedTangentView = temp( tangentView, 'TransformedTangentView' );
|
|
101
101
|
export const transformedTangentWorld = normalize( transformedTangentView.transformDirection( cameraViewMatrix ) );
|
|
102
102
|
|
|
103
103
|
addNodeClass( TangentNode );
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import TempNode from '../core/TempNode.js';
|
|
2
|
+
import { addNodeClass } from '../core/Node.js';
|
|
3
|
+
import { add, mul, div } from '../math/OperatorNode.js';
|
|
4
|
+
import { floor, ceil, fract, pow } from '../math/MathNode.js';
|
|
5
|
+
import { nodeProxy, addNodeElement, float, vec2, vec4, int } from '../shadernode/ShaderNode.js';
|
|
6
|
+
|
|
7
|
+
// Mipped Bicubic Texture Filtering by N8
|
|
8
|
+
// https://www.shadertoy.com/view/Dl2SDW
|
|
9
|
+
|
|
10
|
+
const bC = 1.0 / 6.0;
|
|
11
|
+
|
|
12
|
+
const w0 = ( a ) => mul( bC, mul( a, mul( a, a.negate().add( 3.0 ) ).sub( 3.0 ) ).add( 1.0 ) );
|
|
13
|
+
|
|
14
|
+
const w1 = ( a ) => mul( bC, mul( a, mul( a, mul( 3.0, a ).sub( 6.0 ) ) ).add( 4.0 ) );
|
|
15
|
+
|
|
16
|
+
const w2 = ( a ) => mul( bC, mul( a, mul( a, mul( - 3.0, a ).add( 3.0 ) ).add( 3.0 ) ).add( 1.0 ) );
|
|
17
|
+
|
|
18
|
+
const w3 = ( a ) => mul( bC, pow( a, 3 ) );
|
|
19
|
+
|
|
20
|
+
const g0 = ( a ) => w0( a ).add( w1( a ) );
|
|
21
|
+
|
|
22
|
+
const g1 = ( a ) => w2( a ).add( w3( a ) );
|
|
23
|
+
|
|
24
|
+
// h0 and h1 are the two offset functions
|
|
25
|
+
const h0 = ( a ) => add( - 1.0, w1( a ).div( w0( a ).add( w1( a ) ) ) );
|
|
26
|
+
|
|
27
|
+
const h1 = ( a ) => add( 1.0, w3( a ).div( w2( a ).add( w3( a ) ) ) );
|
|
28
|
+
|
|
29
|
+
const bicubic = ( textureNode, texelSize, lod ) => {
|
|
30
|
+
|
|
31
|
+
const uv = textureNode.uvNode;
|
|
32
|
+
const uvScaled = mul( uv, texelSize.zw ).add( 0.5 );
|
|
33
|
+
|
|
34
|
+
const iuv = floor( uvScaled );
|
|
35
|
+
const fuv = fract( uvScaled );
|
|
36
|
+
|
|
37
|
+
const g0x = g0( fuv.x );
|
|
38
|
+
const g1x = g1( fuv.x );
|
|
39
|
+
const h0x = h0( fuv.x );
|
|
40
|
+
const h1x = h1( fuv.x );
|
|
41
|
+
const h0y = h0( fuv.y );
|
|
42
|
+
const h1y = h1( fuv.y );
|
|
43
|
+
|
|
44
|
+
const p0 = vec2( iuv.x.add( h0x ), iuv.y.add( h0y ) ).sub( 0.5 ).mul( texelSize.xy );
|
|
45
|
+
const p1 = vec2( iuv.x.add( h1x ), iuv.y.add( h0y ) ).sub( 0.5 ).mul( texelSize.xy );
|
|
46
|
+
const p2 = vec2( iuv.x.add( h0x ), iuv.y.add( h1y ) ).sub( 0.5 ).mul( texelSize.xy );
|
|
47
|
+
const p3 = vec2( iuv.x.add( h1x ), iuv.y.add( h1y ) ).sub( 0.5 ).mul( texelSize.xy );
|
|
48
|
+
|
|
49
|
+
const a = g0( fuv.y ).mul( add( g0x.mul( textureNode.uv( p0 ).level( lod ) ), g1x.mul( textureNode.uv( p1 ).level( lod ) ) ) );
|
|
50
|
+
const b = g1( fuv.y ).mul( add( g0x.mul( textureNode.uv( p2 ).level( lod ) ), g1x.mul( textureNode.uv( p3 ).level( lod ) ) ) );
|
|
51
|
+
|
|
52
|
+
return a.add( b );
|
|
53
|
+
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const textureBicubicMethod = ( textureNode, lodNode ) => {
|
|
57
|
+
|
|
58
|
+
const fLodSize = vec2( textureNode.size( int( lodNode ) ) );
|
|
59
|
+
const cLodSize = vec2( textureNode.size( int( lodNode.add( 1.0 ) ) ) );
|
|
60
|
+
const fLodSizeInv = div( 1.0, fLodSize );
|
|
61
|
+
const cLodSizeInv = div( 1.0, cLodSize );
|
|
62
|
+
const fSample = bicubic( textureNode, vec4( fLodSizeInv, fLodSize ), floor( lodNode ) );
|
|
63
|
+
const cSample = bicubic( textureNode, vec4( cLodSizeInv, cLodSize ), ceil( lodNode ) );
|
|
64
|
+
|
|
65
|
+
return fract( lodNode ).mix( fSample, cSample );
|
|
66
|
+
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
class TextureBicubicNode extends TempNode {
|
|
70
|
+
|
|
71
|
+
constructor( textureNode, blurNode = float( 3 ) ) {
|
|
72
|
+
|
|
73
|
+
super( 'vec4' );
|
|
74
|
+
|
|
75
|
+
this.textureNode = textureNode;
|
|
76
|
+
this.blurNode = blurNode;
|
|
77
|
+
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
construct() {
|
|
81
|
+
|
|
82
|
+
return textureBicubicMethod( this.textureNode, this.blurNode );
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
export default TextureBicubicNode;
|
|
89
|
+
|
|
90
|
+
export const textureBicubic = nodeProxy( TextureBicubicNode );
|
|
91
|
+
|
|
92
|
+
addNodeElement( 'bicubic', textureBicubic );
|
|
93
|
+
|
|
94
|
+
addNodeClass( TextureBicubicNode );
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import UniformNode from '../core/UniformNode.js';
|
|
1
|
+
import UniformNode, { uniform } from '../core/UniformNode.js';
|
|
2
2
|
import { uv } from './UVNode.js';
|
|
3
|
+
import { textureSize } from './TextureSizeNode.js';
|
|
4
|
+
import { colorSpaceToLinear } from '../display/ColorSpaceNode.js';
|
|
5
|
+
import { context } from '../core/ContextNode.js';
|
|
6
|
+
import { expression } from '../code/ExpressionNode.js';
|
|
3
7
|
import { addNodeClass } from '../core/Node.js';
|
|
4
|
-
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
|
|
5
|
-
|
|
6
|
-
let defaultUV;
|
|
8
|
+
import { addNodeElement, nodeProxy, vec3 } from '../shadernode/ShaderNode.js';
|
|
9
|
+
import { NodeUpdateType } from '../core/constants.js';
|
|
7
10
|
|
|
8
11
|
class TextureNode extends UniformNode {
|
|
9
12
|
|
|
@@ -16,6 +19,8 @@ class TextureNode extends UniformNode {
|
|
|
16
19
|
this.uvNode = uvNode;
|
|
17
20
|
this.levelNode = levelNode;
|
|
18
21
|
|
|
22
|
+
this.updateType = NodeUpdateType.FRAME;
|
|
23
|
+
|
|
19
24
|
}
|
|
20
25
|
|
|
21
26
|
getUniformHash( /*builder*/ ) {
|
|
@@ -40,7 +45,9 @@ class TextureNode extends UniformNode {
|
|
|
40
45
|
|
|
41
46
|
getDefaultUV() {
|
|
42
47
|
|
|
43
|
-
|
|
48
|
+
const texture = this.value;
|
|
49
|
+
|
|
50
|
+
return uniform( texture.matrix ).mul( vec3( uv( texture.channel ), 1 ) );
|
|
44
51
|
|
|
45
52
|
}
|
|
46
53
|
|
|
@@ -134,12 +141,46 @@ class TextureNode extends UniformNode {
|
|
|
134
141
|
|
|
135
142
|
}
|
|
136
143
|
|
|
137
|
-
|
|
144
|
+
let snippet = propertyName;
|
|
145
|
+
|
|
146
|
+
if ( builder.needsColorSpaceToLinear( this.value ) ) {
|
|
147
|
+
|
|
148
|
+
snippet = colorSpaceToLinear( expression( snippet, nodeType ), this.value.colorSpace ).construct( builder ).build( builder, nodeType );
|
|
149
|
+
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return builder.format( snippet, nodeType, output );
|
|
138
153
|
|
|
139
154
|
}
|
|
140
155
|
|
|
141
156
|
}
|
|
142
157
|
|
|
158
|
+
uv( uvNode ) {
|
|
159
|
+
|
|
160
|
+
const textureNode = this.clone();
|
|
161
|
+
textureNode.uvNode = uvNode;
|
|
162
|
+
|
|
163
|
+
return textureNode;
|
|
164
|
+
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
level( levelNode ) {
|
|
168
|
+
|
|
169
|
+
const textureNode = this.clone();
|
|
170
|
+
textureNode.levelNode = levelNode;
|
|
171
|
+
|
|
172
|
+
return context( textureNode, {
|
|
173
|
+
getMIPLevelAlgorithmNode: ( textureNode, levelNode ) => levelNode
|
|
174
|
+
} );
|
|
175
|
+
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
size( levelNode ) {
|
|
179
|
+
|
|
180
|
+
return textureSize( this, levelNode );
|
|
181
|
+
|
|
182
|
+
}
|
|
183
|
+
|
|
143
184
|
serialize( data ) {
|
|
144
185
|
|
|
145
186
|
super.serialize( data );
|
|
@@ -156,13 +197,34 @@ class TextureNode extends UniformNode {
|
|
|
156
197
|
|
|
157
198
|
}
|
|
158
199
|
|
|
200
|
+
update() {
|
|
201
|
+
|
|
202
|
+
const texture = this.value;
|
|
203
|
+
|
|
204
|
+
if ( texture.matrixAutoUpdate === true ) {
|
|
205
|
+
|
|
206
|
+
texture.updateMatrix();
|
|
207
|
+
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
clone() {
|
|
213
|
+
|
|
214
|
+
return new this.constructor( this.value, this.uvNode, this.levelNode );
|
|
215
|
+
|
|
216
|
+
}
|
|
217
|
+
|
|
159
218
|
}
|
|
160
219
|
|
|
161
220
|
export default TextureNode;
|
|
162
221
|
|
|
163
222
|
export const texture = nodeProxy( TextureNode );
|
|
223
|
+
//export const textureLevel = ( value, uv, level ) => texture( value, uv ).level( level );
|
|
224
|
+
|
|
164
225
|
export const sampler = ( aTexture ) => ( aTexture.isNode === true ? aTexture : texture( aTexture ) ).convert( 'sampler' );
|
|
165
226
|
|
|
166
227
|
addNodeElement( 'texture', texture );
|
|
228
|
+
//addNodeElement( 'textureLevel', textureLevel );
|
|
167
229
|
|
|
168
230
|
addNodeClass( TextureNode );
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import Node from '../core/Node.js';
|
|
2
|
+
import { addNodeClass } from '../core/Node.js';
|
|
3
|
+
import { addNodeElement, nodeProxy } from '../shadernode/ShaderNode.js';
|
|
4
|
+
|
|
5
|
+
class TextureSizeNode extends Node {
|
|
6
|
+
|
|
7
|
+
constructor( textureNode, levelNode = null ) {
|
|
8
|
+
|
|
9
|
+
super( 'uvec2' );
|
|
10
|
+
|
|
11
|
+
this.isTextureSizeNode = true;
|
|
12
|
+
|
|
13
|
+
this.textureNode = textureNode;
|
|
14
|
+
this.levelNode = levelNode;
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
generate( builder, output ) {
|
|
19
|
+
|
|
20
|
+
const textureProperty = this.textureNode.build( builder, 'property' );
|
|
21
|
+
const levelNode = this.levelNode.build( builder, 'int' );
|
|
22
|
+
|
|
23
|
+
return builder.format( `textureDimensions( ${textureProperty}, ${levelNode} )`, this.getNodeType( builder ), output );
|
|
24
|
+
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
export default TextureSizeNode;
|
|
30
|
+
|
|
31
|
+
export const textureSize = nodeProxy( TextureSizeNode );
|
|
32
|
+
|
|
33
|
+
addNodeElement( 'textureSize', textureSize );
|
|
34
|
+
|
|
35
|
+
addNodeClass( TextureSizeNode );
|
|
@@ -70,6 +70,9 @@ class CodeNode extends Node {
|
|
|
70
70
|
export default CodeNode;
|
|
71
71
|
|
|
72
72
|
export const code = nodeProxy( CodeNode );
|
|
73
|
+
|
|
73
74
|
export const js = ( src, includes ) => code( src, includes, 'js' );
|
|
75
|
+
export const wgsl = ( src, includes ) => code( src, includes, 'wgsl' );
|
|
76
|
+
export const glsl = ( src, includes ) => code( src, includes, 'glsl' );
|
|
74
77
|
|
|
75
78
|
addNodeClass( CodeNode );
|
|
@@ -4,9 +4,9 @@ import { nodeObject } from '../shadernode/ShaderNode.js';
|
|
|
4
4
|
|
|
5
5
|
class FunctionNode extends CodeNode {
|
|
6
6
|
|
|
7
|
-
constructor( code = '', includes = [] ) {
|
|
7
|
+
constructor( code = '', includes = [], language = '' ) {
|
|
8
8
|
|
|
9
|
-
super( code, includes );
|
|
9
|
+
super( code, includes, language );
|
|
10
10
|
|
|
11
11
|
this.keywords = {};
|
|
12
12
|
|
|
@@ -99,8 +99,29 @@ class FunctionNode extends CodeNode {
|
|
|
99
99
|
|
|
100
100
|
export default FunctionNode;
|
|
101
101
|
|
|
102
|
-
|
|
102
|
+
const nativeFn = ( code, includes, language = '' ) => {
|
|
103
103
|
|
|
104
|
-
|
|
104
|
+
let functionNode = null;
|
|
105
|
+
|
|
106
|
+
return ( ...params ) => {
|
|
107
|
+
|
|
108
|
+
if ( functionNode === null ) functionNode = nodeObject( new FunctionNode( code, includes, language ) );
|
|
109
|
+
|
|
110
|
+
return functionNode.call( ...params );
|
|
111
|
+
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
export const glslFn = ( code, includes ) => nativeFn( code, includes, 'glsl' );
|
|
117
|
+
export const wgslFn = ( code, includes ) => nativeFn( code, includes, 'wgsl' );
|
|
118
|
+
|
|
119
|
+
export const func = ( code, includes ) => { // @deprecated, r154
|
|
120
|
+
|
|
121
|
+
console.warn( 'TSL: func() is deprecated. Use nativeFn(), wgslFn() or glslFn() instead.' );
|
|
122
|
+
|
|
123
|
+
return nodeObject( new FunctionNode( code, includes ) );
|
|
124
|
+
|
|
125
|
+
};
|
|
105
126
|
|
|
106
127
|
addNodeClass( FunctionNode );
|