super-three 0.133.2 → 0.135.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/build/three.js +619 -538
- package/build/three.min.js +1 -1
- package/build/three.module.js +763 -616
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff +0 -0
- package/examples/fonts/open-sans/open-sans-v15-cyrillic-ext_greek_greek-ext_cyrillic_latin_latin-ext_vietnamese-regular.woff2 +0 -0
- package/examples/fonts/open-sans/open-sans.css +9 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.eot +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.ttf +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff +0 -0
- package/examples/fonts/tabler-icons/fonts/tabler-icons.woff2 +0 -0
- package/examples/fonts/tabler-icons/tabler-icons.min.css +4 -0
- package/examples/js/controls/ArcballControls.js +68 -27
- package/examples/js/controls/DragControls.js +7 -0
- package/examples/js/controls/OrbitControls.js +5 -36
- package/examples/js/controls/TrackballControls.js +3 -2
- package/examples/js/csm/CSM.js +2 -2
- package/examples/js/csm/CSMFrustum.js +133 -0
- package/examples/js/exporters/GLTFExporter.js +147 -63
- package/examples/js/exporters/USDZExporter.js +45 -26
- package/examples/js/lines/LineMaterial.js +58 -20
- package/examples/js/lines/LineSegments2.js +29 -24
- package/examples/js/loaders/3DMLoader.js +24 -11
- package/examples/js/loaders/3MFLoader.js +2 -2
- package/examples/js/loaders/ColladaLoader.js +61 -3
- package/examples/js/loaders/FBXLoader.js +1 -1
- package/examples/js/loaders/GLTFLoader.js +94 -31
- package/examples/js/loaders/KTX2Loader.js +12 -0
- package/examples/js/loaders/LWOLoader.js +8 -6
- package/examples/js/loaders/LogLuvLoader.js +766 -0
- package/examples/js/loaders/PLYLoader.js +32 -7
- package/examples/js/loaders/RGBELoader.js +2 -1
- package/examples/js/loaders/SVGLoader.js +7 -3
- package/examples/js/loaders/TDSLoader.js +237 -271
- package/examples/js/loaders/lwo/LWO2Parser.js +1 -0
- package/examples/js/loaders/lwo/LWO3Parser.js +4 -2
- package/examples/js/objects/MarchingCubes.js +42 -128
- package/examples/js/renderers/CSS2DRenderer.js +4 -4
- package/examples/js/renderers/CSS3DRenderer.js +4 -4
- package/examples/js/utils/RoughnessMipmapper.js +1 -0
- package/examples/jsm/controls/ArcballControls.js +61 -29
- package/examples/jsm/controls/DragControls.js +7 -0
- package/examples/jsm/controls/OrbitControls.js +9 -51
- package/examples/jsm/controls/TrackballControls.js +1 -1
- package/examples/jsm/csm/CSM.js +3 -3
- package/examples/jsm/csm/{Frustum.js → CSMFrustum.js} +3 -3
- package/examples/jsm/exporters/GLTFExporter.js +160 -74
- package/examples/jsm/exporters/USDZExporter.js +47 -26
- package/examples/jsm/libs/flow.module.js +3218 -0
- package/examples/jsm/libs/lil-gui.module.min.js +8 -0
- package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
- package/examples/jsm/lines/LineMaterial.js +59 -23
- package/examples/jsm/lines/LineSegments2.js +22 -18
- package/examples/jsm/loaders/3DMLoader.js +18 -12
- package/examples/jsm/loaders/3MFLoader.js +2 -2
- package/examples/jsm/loaders/ColladaLoader.js +61 -3
- package/examples/jsm/loaders/FBXLoader.js +1 -1
- package/examples/jsm/loaders/GLTFLoader.js +99 -35
- package/examples/jsm/loaders/KTX2Loader.js +19 -0
- package/examples/jsm/loaders/LWOLoader.js +8 -6
- package/examples/jsm/loaders/LogLuvLoader.js +606 -0
- package/examples/jsm/loaders/PLYLoader.js +33 -7
- package/examples/jsm/loaders/SVGLoader.js +7 -4
- package/examples/jsm/loaders/TDSLoader.js +225 -285
- package/examples/jsm/loaders/lwo/LWO2Parser.js +1 -0
- package/examples/jsm/loaders/lwo/LWO3Parser.js +2 -2
- package/examples/jsm/node-editor/NodeEditor.js +455 -0
- package/examples/jsm/node-editor/accessors/NormalEditor.js +30 -0
- package/examples/jsm/node-editor/accessors/PositionEditor.js +30 -0
- package/examples/jsm/node-editor/accessors/UVEditor.js +26 -0
- package/examples/jsm/node-editor/display/BlendEditor.js +43 -0
- package/examples/jsm/node-editor/examples/animate-uv.json +1 -0
- package/examples/jsm/node-editor/examples/fake-top-light.json +1 -0
- package/examples/jsm/node-editor/examples/oscillator-color.json +1 -0
- package/examples/jsm/node-editor/examples/rim.json +1 -0
- package/examples/jsm/node-editor/inputs/ColorEditor.js +91 -0
- package/examples/jsm/node-editor/inputs/FloatEditor.js +24 -0
- package/examples/jsm/node-editor/inputs/SliderEditor.js +68 -0
- package/examples/jsm/node-editor/inputs/Vector2Editor.js +28 -0
- package/examples/jsm/node-editor/inputs/Vector3Editor.js +30 -0
- package/examples/jsm/node-editor/inputs/Vector4Editor.js +37 -0
- package/examples/jsm/node-editor/materials/StandardMaterialEditor.js +69 -0
- package/examples/jsm/node-editor/math/DotEditor.js +36 -0
- package/examples/jsm/node-editor/math/InvertEditor.js +38 -0
- package/examples/jsm/node-editor/math/LimiterEditor.js +48 -0
- package/examples/jsm/node-editor/math/NormalizeEditor.js +26 -0
- package/examples/jsm/node-editor/math/OperatorEditor.js +50 -0
- package/examples/jsm/node-editor/math/PowerEditor.js +34 -0
- package/examples/jsm/node-editor/math/TrigonometryEditor.js +39 -0
- package/examples/jsm/node-editor/procedural/CheckerEditor.js +26 -0
- package/examples/jsm/node-editor/utils/OscillatorEditor.js +42 -0
- package/examples/jsm/node-editor/utils/TimerEditor.js +57 -0
- package/examples/jsm/nodes/materials/StandardNodeMaterial.js +1 -1
- package/examples/jsm/nodes/materials/nodes/StandardNode.js +6 -6
- package/examples/jsm/nodes/utils/ColorSpaceNode.js +1 -49
- package/examples/jsm/objects/MarchingCubes.js +46 -152
- package/examples/jsm/postprocessing/AdaptiveToneMappingPass.js +1 -1
- package/examples/jsm/postprocessing/AfterimagePass.js +1 -1
- package/examples/jsm/postprocessing/BloomPass.js +1 -1
- package/examples/jsm/postprocessing/BokehPass.js +1 -1
- package/examples/jsm/postprocessing/ClearPass.js +1 -1
- package/examples/jsm/postprocessing/CubeTexturePass.js +1 -1
- package/examples/jsm/postprocessing/DotScreenPass.js +1 -1
- package/examples/jsm/postprocessing/EffectComposer.js +3 -3
- package/examples/jsm/postprocessing/FilmPass.js +1 -1
- package/examples/jsm/postprocessing/GlitchPass.js +1 -1
- package/examples/jsm/postprocessing/HalftonePass.js +1 -1
- package/examples/jsm/postprocessing/MaskPass.js +1 -1
- package/examples/jsm/postprocessing/OutlinePass.js +1 -1
- package/examples/jsm/postprocessing/RenderPass.js +1 -1
- package/examples/jsm/postprocessing/SAOPass.js +1 -1
- package/examples/jsm/postprocessing/SMAAPass.js +1 -1
- package/examples/jsm/postprocessing/SSAARenderPass.js +1 -1
- package/examples/jsm/postprocessing/SSAOPass.js +1 -1
- package/examples/jsm/postprocessing/SSRPass.js +1 -1
- package/examples/jsm/postprocessing/SSRrPass.js +1 -1
- package/examples/jsm/postprocessing/SavePass.js +1 -1
- package/examples/jsm/postprocessing/ShaderPass.js +1 -1
- package/examples/jsm/postprocessing/TAARenderPass.js +1 -1
- package/examples/jsm/postprocessing/TexturePass.js +1 -1
- package/examples/jsm/postprocessing/UnrealBloomPass.js +1 -1
- package/examples/jsm/renderers/CSS2DRenderer.js +5 -4
- package/examples/jsm/renderers/CSS3DRenderer.js +5 -4
- package/examples/jsm/renderers/nodes/Nodes.js +14 -13
- package/examples/jsm/renderers/nodes/ShaderNode.js +193 -41
- package/examples/jsm/renderers/nodes/accessors/MaterialNode.js +6 -6
- package/examples/jsm/renderers/nodes/accessors/ModelViewProjectionNode.js +5 -5
- package/examples/jsm/renderers/nodes/accessors/NormalNode.js +14 -3
- package/examples/jsm/renderers/nodes/accessors/PointUVNode.js +3 -3
- package/examples/jsm/renderers/nodes/accessors/PositionNode.js +15 -5
- package/examples/jsm/renderers/nodes/accessors/SkinningNode.js +107 -0
- package/examples/jsm/renderers/nodes/accessors/UVNode.js +7 -5
- package/examples/jsm/renderers/nodes/core/ArrayInputNode.js +3 -3
- package/examples/jsm/renderers/nodes/core/AttributeNode.js +6 -0
- package/examples/jsm/renderers/nodes/core/BypassNode.js +38 -0
- package/examples/jsm/renderers/nodes/core/CodeNode.js +3 -3
- package/examples/jsm/renderers/nodes/core/ContextNode.js +4 -19
- package/examples/jsm/renderers/nodes/core/ExpressionNode.js +13 -2
- package/examples/jsm/renderers/nodes/core/FunctionNode.js +19 -132
- package/examples/jsm/renderers/nodes/core/InputNode.js +13 -3
- package/examples/jsm/renderers/nodes/core/Node.js +32 -10
- package/examples/jsm/renderers/nodes/core/NodeBuilder.js +146 -128
- package/examples/jsm/renderers/nodes/core/NodeFunction.js +22 -0
- package/examples/jsm/renderers/nodes/core/NodeFunctionInput.js +4 -4
- package/examples/jsm/renderers/nodes/core/NodeKeywords.js +18 -179
- package/examples/jsm/renderers/nodes/core/NodeParser.js +11 -0
- package/examples/jsm/renderers/nodes/core/NodeVar.js +2 -2
- package/examples/jsm/renderers/nodes/core/PropertyNode.js +14 -2
- package/examples/jsm/renderers/nodes/core/TempNode.js +10 -13
- package/examples/jsm/renderers/nodes/core/VarNode.js +12 -7
- package/examples/jsm/renderers/nodes/core/VaryNode.js +23 -8
- package/examples/jsm/renderers/nodes/core/constants.js +2 -0
- package/examples/jsm/renderers/nodes/display/ColorSpaceNode.js +47 -25
- package/examples/jsm/renderers/nodes/display/NormalMapNode.js +21 -22
- package/examples/jsm/renderers/nodes/functions/BSDFs.js +64 -101
- package/examples/jsm/renderers/nodes/inputs/BufferNode.js +25 -0
- package/examples/jsm/renderers/nodes/inputs/IntNode.js +17 -0
- package/examples/jsm/renderers/nodes/inputs/TextureNode.js +10 -2
- package/examples/jsm/renderers/nodes/lights/LightContextNode.js +20 -14
- package/examples/jsm/renderers/nodes/lights/LightNode.js +32 -36
- package/examples/jsm/renderers/nodes/math/CondNode.js +60 -0
- package/examples/jsm/renderers/nodes/math/MathNode.js +87 -36
- package/examples/jsm/renderers/nodes/math/OperatorNode.js +124 -31
- package/examples/jsm/renderers/nodes/parsers/GLSLNodeFunction.js +137 -0
- package/examples/jsm/renderers/nodes/parsers/GLSLNodeParser.js +14 -0
- package/examples/jsm/renderers/nodes/parsers/WGSLNodeFunction.js +89 -0
- package/examples/jsm/renderers/nodes/parsers/WGSLNodeParser.js +14 -0
- package/examples/jsm/renderers/nodes/procedural/CheckerNode.js +7 -9
- package/examples/jsm/renderers/nodes/utils/ArrayElementNode.js +31 -0
- package/examples/jsm/renderers/nodes/utils/ConvertNode.js +33 -0
- package/examples/jsm/renderers/nodes/utils/JoinNode.js +7 -7
- package/examples/jsm/renderers/nodes/utils/OscNode.js +58 -0
- package/examples/jsm/renderers/nodes/utils/SplitNode.js +18 -8
- package/examples/jsm/renderers/nodes/utils/SpriteSheetUVNode.js +7 -7
- package/examples/jsm/renderers/webgl/nodes/SlotNode.js +22 -0
- package/examples/jsm/renderers/webgl/nodes/WebGLNodeBuilder.js +191 -94
- package/examples/jsm/renderers/webgl/nodes/WebGLNodes.js +2 -2
- package/examples/jsm/renderers/webgl/nodes/WebGLPhysicalContextNode.js +2 -2
- package/examples/jsm/renderers/webgpu/WebGPUBackground.js +1 -1
- package/examples/jsm/renderers/webgpu/WebGPUBindings.js +3 -3
- package/examples/jsm/renderers/webgpu/WebGPUComputePipelines.js +2 -4
- package/examples/jsm/renderers/webgpu/WebGPUProgrammableStage.js +2 -4
- package/examples/jsm/renderers/webgpu/WebGPURenderPipeline.js +15 -23
- package/examples/jsm/renderers/webgpu/WebGPURenderPipelines.js +3 -5
- package/examples/jsm/renderers/webgpu/WebGPURenderer.js +11 -27
- package/examples/jsm/renderers/webgpu/WebGPUTextureUtils.js +62 -28
- package/examples/jsm/renderers/webgpu/WebGPUTextures.js +34 -27
- package/examples/jsm/renderers/webgpu/constants.js +2 -2
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodeBuilder.js +430 -98
- package/examples/jsm/renderers/webgpu/nodes/WebGPUNodes.js +1 -1
- package/examples/jsm/utils/RoughnessMipmapper.js +1 -0
- package/examples/jsm/webxr/OculusHandPointerModel.js +6 -6
- package/package.json +10 -10
- package/src/Three.Legacy.js +6 -0
- package/src/Three.js +0 -1
- package/src/cameras/StereoCamera.js +8 -7
- package/src/constants.js +1 -2
- package/src/core/Layers.js +7 -1
- package/src/core/Object3D.js +2 -0
- package/src/extras/PMREMGenerator.js +11 -6
- package/src/loaders/FileLoader.js +89 -152
- package/src/loaders/ImageLoader.js +9 -4
- package/src/loaders/LoaderUtils.js +26 -0
- package/src/loaders/MaterialLoader.js +7 -4
- package/src/loaders/ObjectLoader.js +2 -0
- package/src/materials/Material.js +4 -4
- package/src/materials/MeshPhysicalMaterial.js +20 -14
- package/src/math/MathUtils.js +5 -16
- package/src/renderers/WebGLMultisampleRenderTarget.js +7 -1
- package/src/renderers/WebGLRenderer.js +83 -117
- package/src/renderers/shaders/ShaderChunk/bsdfs.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/encodings_pars_fragment.glsl.js +0 -27
- package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +0 -1
- package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +19 -6
- package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +2 -2
- package/src/renderers/shaders/ShaderChunk/transmission_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderChunk/transmission_pars_fragment.glsl.js +1 -1
- package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +13 -5
- package/src/renderers/shaders/ShaderLib/vsm.glsl.js +2 -1
- package/src/renderers/shaders/ShaderLib.js +6 -4
- package/src/renderers/shaders/UniformsLib.js +1 -2
- package/src/renderers/webgl/WebGLExtensions.js +1 -0
- package/src/renderers/webgl/WebGLMaterials.js +27 -15
- package/src/renderers/webgl/WebGLProgram.js +10 -6
- package/src/renderers/webgl/WebGLPrograms.js +17 -12
- package/src/renderers/webgl/WebGLShadowMap.js +14 -5
- package/src/renderers/webgl/WebGLState.js +31 -17
- package/src/renderers/webgl/WebGLTextures.js +188 -51
- package/src/renderers/webgl/WebGLUniforms.js +45 -1
- package/src/renderers/webxr/WebXRManager.js +71 -110
- package/src/textures/Texture.js +6 -0
- package/src/utils.js +37 -1
- package/examples/js/controls/DeviceOrientationControls.js +0 -147
- package/examples/js/libs/dat.gui.min.js +0 -14
- package/examples/jsm/controls/DeviceOrientationControls.js +0 -153
- package/examples/jsm/libs/dat.gui.module.js +0 -3575
- package/examples/jsm/libs/glslang.js +0 -78
- package/examples/jsm/libs/glslang.wasm +0 -0
- package/examples/jsm/renderers/nodes/consts/MathConsts.js +0 -7
- package/examples/jsm/renderers/nodes/core/ConstNode.js +0 -39
- package/examples/jsm/renderers/nodes/core/NodeSlot.js +0 -13
- package/examples/jsm/renderers/nodes/core/StructNode.js +0 -80
- package/examples/jsm/renderers/nodes/core/StructVarNode.js +0 -75
- package/examples/jsm/renderers/nodes/functions/EncodingFunctions.js +0 -99
- package/examples/jsm/renderers/nodes/functions/MathFunctions.js +0 -47
- package/examples/jsm/renderers/webgpu/nodes/ShaderLib.js +0 -152
- package/src/extras/objects/ImmediateRenderObject.js +0 -31
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { NodeUpdateType } from './constants.js';
|
|
2
2
|
|
|
3
|
+
import { MathUtils } from 'three';
|
|
4
|
+
|
|
3
5
|
class Node {
|
|
4
6
|
|
|
5
7
|
constructor( nodeType = null ) {
|
|
@@ -8,6 +10,8 @@ class Node {
|
|
|
8
10
|
|
|
9
11
|
this.updateType = NodeUpdateType.None;
|
|
10
12
|
|
|
13
|
+
this.uuid = MathUtils.generateUUID();
|
|
14
|
+
|
|
11
15
|
}
|
|
12
16
|
|
|
13
17
|
get type() {
|
|
@@ -16,21 +20,21 @@ class Node {
|
|
|
16
20
|
|
|
17
21
|
}
|
|
18
22
|
|
|
19
|
-
|
|
23
|
+
getHash( /*builder*/ ) {
|
|
20
24
|
|
|
21
|
-
return this.
|
|
25
|
+
return this.uuid;
|
|
22
26
|
|
|
23
27
|
}
|
|
24
28
|
|
|
25
|
-
|
|
29
|
+
getUpdateType( /*builder*/ ) {
|
|
26
30
|
|
|
27
|
-
return this.
|
|
31
|
+
return this.updateType;
|
|
28
32
|
|
|
29
33
|
}
|
|
30
34
|
|
|
31
|
-
|
|
35
|
+
getNodeType( /*builder*/ ) {
|
|
32
36
|
|
|
33
|
-
return
|
|
37
|
+
return this.nodeType;
|
|
34
38
|
|
|
35
39
|
}
|
|
36
40
|
|
|
@@ -48,30 +52,48 @@ class Node {
|
|
|
48
52
|
|
|
49
53
|
build( builder, output = null ) {
|
|
50
54
|
|
|
55
|
+
const hash = this.getHash( builder );
|
|
56
|
+
const sharedNode = builder.getNodeFromHash( hash );
|
|
57
|
+
|
|
58
|
+
if ( sharedNode !== undefined && this !== sharedNode ) {
|
|
59
|
+
|
|
60
|
+
return sharedNode.build( builder, output );
|
|
61
|
+
|
|
62
|
+
}
|
|
63
|
+
|
|
51
64
|
builder.addNode( this );
|
|
65
|
+
builder.addStack( this );
|
|
52
66
|
|
|
53
67
|
const isGenerateOnce = this.generate.length === 1;
|
|
54
68
|
|
|
69
|
+
let snippet = null;
|
|
70
|
+
|
|
55
71
|
if ( isGenerateOnce ) {
|
|
56
72
|
|
|
57
73
|
const type = this.getNodeType( builder );
|
|
58
74
|
const nodeData = builder.getDataFromNode( this );
|
|
59
75
|
|
|
60
|
-
|
|
76
|
+
snippet = nodeData.snippet;
|
|
61
77
|
|
|
62
78
|
if ( snippet === undefined ) {
|
|
63
79
|
|
|
64
|
-
snippet = this.generate( builder );
|
|
80
|
+
snippet = this.generate( builder ) || '';
|
|
65
81
|
|
|
66
82
|
nodeData.snippet = snippet;
|
|
67
83
|
|
|
68
84
|
}
|
|
69
85
|
|
|
70
|
-
|
|
86
|
+
snippet = builder.format( snippet, type, output );
|
|
87
|
+
|
|
88
|
+
} else {
|
|
89
|
+
|
|
90
|
+
snippet = this.generate( builder, output ) || '';
|
|
71
91
|
|
|
72
92
|
}
|
|
73
93
|
|
|
74
|
-
|
|
94
|
+
builder.removeStack( this );
|
|
95
|
+
|
|
96
|
+
return snippet;
|
|
75
97
|
|
|
76
98
|
}
|
|
77
99
|
|
|
@@ -6,39 +6,71 @@ import NodeCode from './NodeCode.js';
|
|
|
6
6
|
import NodeKeywords from './NodeKeywords.js';
|
|
7
7
|
import { NodeUpdateType } from './constants.js';
|
|
8
8
|
|
|
9
|
-
import { LinearEncoding } from 'three';
|
|
9
|
+
import { REVISION, LinearEncoding } from 'three';
|
|
10
|
+
|
|
11
|
+
const shaderStages = [ 'fragment', 'vertex' ];
|
|
10
12
|
|
|
11
13
|
class NodeBuilder {
|
|
12
14
|
|
|
13
|
-
constructor(
|
|
15
|
+
constructor( object, renderer, parser ) {
|
|
14
16
|
|
|
15
|
-
this.
|
|
17
|
+
this.object = object;
|
|
18
|
+
this.material = object.material;
|
|
16
19
|
this.renderer = renderer;
|
|
20
|
+
this.parser = parser;
|
|
17
21
|
|
|
18
22
|
this.nodes = [];
|
|
19
23
|
this.updateNodes = [];
|
|
24
|
+
this.hashNodes = {};
|
|
20
25
|
|
|
21
26
|
this.vertexShader = null;
|
|
22
27
|
this.fragmentShader = null;
|
|
23
28
|
|
|
24
|
-
this.
|
|
25
|
-
this.
|
|
29
|
+
this.flowNodes = { vertex: [], fragment: [] };
|
|
30
|
+
this.flowCode = { vertex: '', fragment: '' };
|
|
26
31
|
this.uniforms = { vertex: [], fragment: [], index: 0 };
|
|
27
32
|
this.codes = { vertex: [], fragment: [] };
|
|
28
33
|
this.attributes = [];
|
|
29
34
|
this.varys = [];
|
|
30
35
|
this.vars = { vertex: [], fragment: [] };
|
|
31
36
|
this.flow = { code: '' };
|
|
37
|
+
this.stack = [];
|
|
32
38
|
|
|
33
39
|
this.context = {
|
|
34
40
|
keywords: new NodeKeywords(),
|
|
35
|
-
material: material
|
|
41
|
+
material: object.material
|
|
36
42
|
};
|
|
37
43
|
|
|
38
44
|
this.nodesData = new WeakMap();
|
|
45
|
+
this.flowsData = new WeakMap();
|
|
39
46
|
|
|
40
47
|
this.shaderStage = null;
|
|
41
|
-
this.
|
|
48
|
+
this.node = null;
|
|
49
|
+
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
addStack( node ) {
|
|
53
|
+
|
|
54
|
+
/*
|
|
55
|
+
if ( this.stack.indexOf( node ) !== - 1 ) {
|
|
56
|
+
|
|
57
|
+
console.warn( 'Recursive node: ', node );
|
|
58
|
+
|
|
59
|
+
}
|
|
60
|
+
*/
|
|
61
|
+
this.stack.push( node );
|
|
62
|
+
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
removeStack( node ) {
|
|
66
|
+
|
|
67
|
+
const lastStack = this.stack.pop();
|
|
68
|
+
|
|
69
|
+
if ( lastStack !== node ) {
|
|
70
|
+
|
|
71
|
+
throw new Error( 'NodeBuilder: Invalid node stack!' );
|
|
72
|
+
|
|
73
|
+
}
|
|
42
74
|
|
|
43
75
|
}
|
|
44
76
|
|
|
@@ -56,37 +88,41 @@ class NodeBuilder {
|
|
|
56
88
|
|
|
57
89
|
this.nodes.push( node );
|
|
58
90
|
|
|
91
|
+
this.hashNodes[ node.getHash( this ) ] = node;
|
|
92
|
+
|
|
59
93
|
}
|
|
60
94
|
|
|
61
95
|
}
|
|
62
96
|
|
|
63
|
-
|
|
97
|
+
getMethod( method ) {
|
|
64
98
|
|
|
65
|
-
|
|
99
|
+
return method;
|
|
66
100
|
|
|
67
101
|
}
|
|
68
102
|
|
|
69
|
-
|
|
103
|
+
getNodeFromHash( hash ) {
|
|
70
104
|
|
|
71
|
-
this.
|
|
105
|
+
return this.hashNodes[ hash ];
|
|
72
106
|
|
|
73
107
|
}
|
|
74
108
|
|
|
75
|
-
|
|
109
|
+
addFlow( shaderStage, node ) {
|
|
76
110
|
|
|
77
|
-
this.
|
|
111
|
+
this.flowNodes[ shaderStage ].push( node );
|
|
112
|
+
|
|
113
|
+
return node;
|
|
78
114
|
|
|
79
115
|
}
|
|
80
116
|
|
|
81
|
-
|
|
117
|
+
setContext( context ) {
|
|
82
118
|
|
|
83
|
-
|
|
119
|
+
this.context = context;
|
|
84
120
|
|
|
85
121
|
}
|
|
86
122
|
|
|
87
|
-
|
|
123
|
+
getContext() {
|
|
88
124
|
|
|
89
|
-
return this.context
|
|
125
|
+
return this.context;
|
|
90
126
|
|
|
91
127
|
}
|
|
92
128
|
|
|
@@ -102,18 +138,31 @@ class NodeBuilder {
|
|
|
102
138
|
|
|
103
139
|
}
|
|
104
140
|
|
|
141
|
+
// rename to generate
|
|
105
142
|
getConst( type, value ) {
|
|
106
143
|
|
|
107
144
|
if ( type === 'float' ) return value + ( value % 1 ? '' : '.0' );
|
|
108
|
-
if ( type === 'vec2' ) return
|
|
109
|
-
if ( type === 'vec3' ) return
|
|
110
|
-
if ( type === 'vec4' ) return
|
|
111
|
-
if ( type === 'color' ) return
|
|
145
|
+
if ( type === 'vec2' ) return `${ this.getType( 'vec2' ) }( ${value.x}, ${value.y} )`;
|
|
146
|
+
if ( type === 'vec3' ) return `${ this.getType( 'vec3' ) }( ${value.x}, ${value.y}, ${value.z} )`;
|
|
147
|
+
if ( type === 'vec4' ) return `${ this.getType( 'vec4' ) }( ${value.x}, ${value.y}, ${value.z}, ${value.w} )`;
|
|
148
|
+
if ( type === 'color' ) return `${ this.getType( 'vec3' ) }( ${value.r}, ${value.g}, ${value.b} )`;
|
|
112
149
|
|
|
113
150
|
throw new Error( `NodeBuilder: Type '${type}' not found in generate constant attempt.` );
|
|
114
151
|
|
|
115
152
|
}
|
|
116
153
|
|
|
154
|
+
getType( type ) {
|
|
155
|
+
|
|
156
|
+
return type;
|
|
157
|
+
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
generateMethod( method ) {
|
|
161
|
+
|
|
162
|
+
return method;
|
|
163
|
+
|
|
164
|
+
}
|
|
165
|
+
|
|
117
166
|
getAttribute( name, type ) {
|
|
118
167
|
|
|
119
168
|
const attributes = this.attributes;
|
|
@@ -140,7 +189,7 @@ class NodeBuilder {
|
|
|
140
189
|
|
|
141
190
|
}
|
|
142
191
|
|
|
143
|
-
getPropertyName( node ) {
|
|
192
|
+
getPropertyName( node/*, shaderStage*/ ) {
|
|
144
193
|
|
|
145
194
|
return node.name;
|
|
146
195
|
|
|
@@ -209,11 +258,10 @@ class NodeBuilder {
|
|
|
209
258
|
getTypeLength( type ) {
|
|
210
259
|
|
|
211
260
|
const vecType = this.getVectorType( type );
|
|
261
|
+
const vecNum = /vec([2-4])/.exec( vecType );
|
|
212
262
|
|
|
213
|
-
if (
|
|
214
|
-
if ( vecType === '
|
|
215
|
-
if ( vecType === 'vec3' ) return 3;
|
|
216
|
-
if ( vecType === 'vec4' ) return 4;
|
|
263
|
+
if ( vecNum !== null ) return Number( vecNum[ 1 ] );
|
|
264
|
+
if ( vecType === 'float' || vecType === 'bool' ) return 1;
|
|
217
265
|
|
|
218
266
|
return 0;
|
|
219
267
|
|
|
@@ -334,30 +382,33 @@ class NodeBuilder {
|
|
|
334
382
|
|
|
335
383
|
addFlowCode( code ) {
|
|
336
384
|
|
|
337
|
-
|
|
385
|
+
this.flow.code += code;
|
|
338
386
|
|
|
339
|
-
|
|
387
|
+
}
|
|
340
388
|
|
|
341
|
-
|
|
389
|
+
getFlowData( shaderStage, node ) {
|
|
342
390
|
|
|
343
|
-
this.
|
|
391
|
+
return this.flowsData.get( node );
|
|
344
392
|
|
|
345
393
|
}
|
|
346
394
|
|
|
347
|
-
|
|
395
|
+
flowNode( node ) {
|
|
396
|
+
|
|
397
|
+
this.node = node;
|
|
348
398
|
|
|
349
|
-
|
|
399
|
+
const output = node.getNodeType( this );
|
|
350
400
|
|
|
351
|
-
const flowData = this.
|
|
401
|
+
const flowData = this.flowChildNode( node, output );
|
|
352
402
|
|
|
353
|
-
this.
|
|
354
|
-
this.define( shaderStage, `NODE_${slot.name}`, flowData.result );
|
|
403
|
+
this.flowsData.set( node, flowData );
|
|
355
404
|
|
|
356
|
-
this.
|
|
405
|
+
this.node = null;
|
|
406
|
+
|
|
407
|
+
return flowData;
|
|
357
408
|
|
|
358
409
|
}
|
|
359
410
|
|
|
360
|
-
|
|
411
|
+
flowChildNode( node, output = null ) {
|
|
361
412
|
|
|
362
413
|
const previousFlow = this.flow;
|
|
363
414
|
|
|
@@ -381,17 +432,15 @@ class NodeBuilder {
|
|
|
381
432
|
|
|
382
433
|
this.setShaderStage( shaderStage );
|
|
383
434
|
|
|
384
|
-
const flowData = this.
|
|
435
|
+
const flowData = this.flowChildNode( node, output );
|
|
385
436
|
|
|
386
437
|
if ( propertyName !== null ) {
|
|
387
438
|
|
|
388
|
-
flowData.code += `${propertyName} = ${flowData.result}
|
|
439
|
+
flowData.code += `${propertyName} = ${flowData.result};\n\t`;
|
|
389
440
|
|
|
390
441
|
}
|
|
391
442
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
this.define( shaderStage, 'NODE_CODE', shaderStageCode );
|
|
443
|
+
this.flowCode[ shaderStage ] = this.flowCode[ shaderStage ] + flowData.code;
|
|
395
444
|
|
|
396
445
|
this.setShaderStage( previousShaderStage );
|
|
397
446
|
|
|
@@ -399,22 +448,6 @@ class NodeBuilder {
|
|
|
399
448
|
|
|
400
449
|
}
|
|
401
450
|
|
|
402
|
-
getDefines( shaderStage ) {
|
|
403
|
-
|
|
404
|
-
const defines = this.defines[ shaderStage ];
|
|
405
|
-
|
|
406
|
-
let code = '';
|
|
407
|
-
|
|
408
|
-
for ( const name in defines ) {
|
|
409
|
-
|
|
410
|
-
code += `#define ${name} ${defines[ name ]}\n`;
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
return code;
|
|
415
|
-
|
|
416
|
-
}
|
|
417
|
-
|
|
418
451
|
getAttributes( shaderStage ) {
|
|
419
452
|
|
|
420
453
|
let snippet = '';
|
|
@@ -501,68 +534,37 @@ class NodeBuilder {
|
|
|
501
534
|
|
|
502
535
|
}
|
|
503
536
|
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
const shaderStages = [ 'vertex', 'fragment' ];
|
|
507
|
-
const shaderData = {};
|
|
508
|
-
|
|
509
|
-
for ( const shaderStage of shaderStages ) {
|
|
537
|
+
buildCode() {
|
|
510
538
|
|
|
511
|
-
|
|
539
|
+
console.warn( 'Abstract function.' );
|
|
512
540
|
|
|
513
|
-
|
|
541
|
+
}
|
|
514
542
|
|
|
515
|
-
|
|
543
|
+
build() {
|
|
516
544
|
|
|
517
|
-
|
|
545
|
+
if ( this.context.vertex && this.context.vertex.isNode ) {
|
|
518
546
|
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
}
|
|
547
|
+
this.flowNodeFromShaderStage( 'vertex', this.context.vertex );
|
|
522
548
|
|
|
523
549
|
}
|
|
524
550
|
|
|
525
|
-
this.setShaderStage( null );
|
|
526
|
-
|
|
527
551
|
for ( const shaderStage of shaderStages ) {
|
|
528
552
|
|
|
529
|
-
|
|
530
|
-
const uniforms = this.getUniforms( shaderStage );
|
|
531
|
-
const attributes = this.getAttributes( shaderStage );
|
|
532
|
-
const varys = this.getVarys( shaderStage );
|
|
533
|
-
const vars = this.getVars( shaderStage );
|
|
534
|
-
const codes = this.getCodes( shaderStage );
|
|
535
|
-
|
|
536
|
-
shaderData[ shaderStage ] = `
|
|
537
|
-
// <node_builder>
|
|
538
|
-
|
|
539
|
-
#define NODE_MATERIAL
|
|
540
|
-
|
|
541
|
-
// defines
|
|
542
|
-
${defines}
|
|
543
|
-
|
|
544
|
-
// uniforms
|
|
545
|
-
${uniforms}
|
|
546
|
-
|
|
547
|
-
// attributes
|
|
548
|
-
${attributes}
|
|
553
|
+
this.setShaderStage( shaderStage );
|
|
549
554
|
|
|
550
|
-
|
|
551
|
-
${varys}
|
|
555
|
+
const flowNodes = this.flowNodes[ shaderStage ];
|
|
552
556
|
|
|
553
|
-
|
|
554
|
-
${vars}
|
|
557
|
+
for ( const node of flowNodes ) {
|
|
555
558
|
|
|
556
|
-
|
|
557
|
-
${codes}
|
|
559
|
+
this.flowNode( node, shaderStage );
|
|
558
560
|
|
|
559
|
-
|
|
560
|
-
`;
|
|
561
|
+
}
|
|
561
562
|
|
|
562
563
|
}
|
|
563
564
|
|
|
564
|
-
this.
|
|
565
|
-
|
|
565
|
+
this.setShaderStage( null );
|
|
566
|
+
|
|
567
|
+
this.buildCode();
|
|
566
568
|
|
|
567
569
|
return this;
|
|
568
570
|
|
|
@@ -577,31 +579,42 @@ class NodeBuilder {
|
|
|
577
579
|
|
|
578
580
|
switch ( typeToType ) {
|
|
579
581
|
|
|
580
|
-
case '
|
|
581
|
-
case '
|
|
582
|
-
case '
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
case '
|
|
586
|
-
case '
|
|
587
|
-
|
|
588
|
-
case '
|
|
589
|
-
|
|
590
|
-
case '
|
|
591
|
-
|
|
592
|
-
case '
|
|
593
|
-
case '
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
case '
|
|
597
|
-
case '
|
|
598
|
-
case '
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
case '
|
|
602
|
-
case '
|
|
603
|
-
case '
|
|
604
|
-
|
|
582
|
+
case 'int to float' : return `${ this.getType( 'float' ) }( ${ snippet } )`;
|
|
583
|
+
case 'int to vec2' : return `${ this.getType( 'vec2' ) }( ${ this.getType( 'float' ) }( ${ snippet } ) )`;
|
|
584
|
+
case 'int to vec3' : return `${ this.getType( 'vec3' ) }( ${ this.getType( 'float' ) }( ${ snippet } ) )`;
|
|
585
|
+
case 'int to vec4' : return `${ this.getType( 'vec4' ) }( ${ this.getType( 'vec3' ) }( ${ this.getType( 'float' ) }( ${ snippet } ) ), 1.0 )`;
|
|
586
|
+
|
|
587
|
+
case 'float to int' : return `${ this.getType( 'int' ) }( ${ snippet } )`;
|
|
588
|
+
case 'float to vec2' : return `${ this.getType( 'vec2' ) }( ${ snippet } )`;
|
|
589
|
+
case 'float to vec3' : return `${ this.getType( 'vec3' ) }( ${ snippet } )`;
|
|
590
|
+
case 'float to vec4' : return `${ this.getType( 'vec4' ) }( ${ this.getType( 'vec3' ) }( ${ snippet } ), 1.0 )`;
|
|
591
|
+
|
|
592
|
+
case 'vec2 to int' : return `${ this.getType( 'int' ) }( ${ snippet }.x )`;
|
|
593
|
+
case 'vec2 to float' : return `${ snippet }.x`;
|
|
594
|
+
case 'vec2 to vec3' : return `${ this.getType( 'vec3' ) }( ${ snippet }, 0.0 )`;
|
|
595
|
+
case 'vec2 to vec4' : return `${ this.getType( 'vec4' ) }( ${ snippet }.xy, 0.0, 1.0 )`;
|
|
596
|
+
|
|
597
|
+
case 'vec3 to int' : return `${ this.getType( 'int' ) }( ${ snippet }.x )`;
|
|
598
|
+
case 'vec3 to float' : return `${ snippet }.x`;
|
|
599
|
+
case 'vec3 to vec2' : return `${ snippet }.xy`;
|
|
600
|
+
case 'vec3 to vec4' : return `${ this.getType( 'vec4' ) }( ${ snippet }, 1.0 )`;
|
|
601
|
+
|
|
602
|
+
case 'vec4 to int' : return `${ this.getType( 'int' ) }( ${ snippet }.x )`;
|
|
603
|
+
case 'vec4 to float' : return `${ snippet }.x`;
|
|
604
|
+
case 'vec4 to vec2' : return `${ snippet }.xy`;
|
|
605
|
+
case 'vec4 to vec3' : return `${ snippet }.xyz`;
|
|
606
|
+
|
|
607
|
+
case 'mat3 to int' : return `${ this.getType( 'int' ) }( ${ snippet } * ${ this.getType( 'vec3' ) }( 1.0 ) ).x`;
|
|
608
|
+
case 'mat3 to float' : return `( ${ snippet } * ${ this.getType( 'vec3' ) }( 1.0 ) ).x`;
|
|
609
|
+
case 'mat3 to vec2' : return `( ${ snippet } * ${ this.getType( 'vec3' ) }( 1.0 ) ).xy`;
|
|
610
|
+
case 'mat3 to vec3' : return `( ${ snippet } * ${ this.getType( 'vec3' ) }( 1.0 ) ).xyz`;
|
|
611
|
+
case 'mat3 to vec4' : return `${ this.getType( 'vec4' ) }( ${ snippet } * ${ this.getType( 'vec3' ) }( 1.0 ), 1.0 )`;
|
|
612
|
+
|
|
613
|
+
case 'mat4 to int' : return `${ this.getType( 'int' ) }( ${ snippet } * ${ this.getType( 'vec4' ) }( 1.0 ) ).x`;
|
|
614
|
+
case 'mat4 to float' : return `( ${ snippet } * ${ this.getType( 'vec4' ) }( 1.0 ) ).x`;
|
|
615
|
+
case 'mat4 to vec2' : return `( ${ snippet } * ${ this.getType( 'vec4' ) }( 1.0 ) ).xy`;
|
|
616
|
+
case 'mat4 to vec3' : return `( ${ snippet } * ${ this.getType( 'vec4' ) }( 1.0 ) ).xyz`;
|
|
617
|
+
case 'mat4 to vec4' : return `( ${ snippet } * ${ this.getType( 'vec4' ) }( 1.0 ) )`;
|
|
605
618
|
|
|
606
619
|
}
|
|
607
620
|
|
|
@@ -609,6 +622,11 @@ class NodeBuilder {
|
|
|
609
622
|
|
|
610
623
|
}
|
|
611
624
|
|
|
625
|
+
getSignature() {
|
|
626
|
+
|
|
627
|
+
return `// Three.js r${ REVISION } • NodeMaterial System\n`;
|
|
628
|
+
|
|
629
|
+
}
|
|
612
630
|
|
|
613
631
|
}
|
|
614
632
|
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
class NodeFunction {
|
|
2
|
+
|
|
3
|
+
constructor( type, inputs, name = '', presicion = '' ) {
|
|
4
|
+
|
|
5
|
+
this.type = type;
|
|
6
|
+
this.inputs = inputs;
|
|
7
|
+
this.name = name;
|
|
8
|
+
this.presicion = presicion;
|
|
9
|
+
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
getCode( /*name = this.name*/ ) {
|
|
13
|
+
|
|
14
|
+
console.warn( 'Abstract function.' );
|
|
15
|
+
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
NodeFunction.isNodeFunction = true;
|
|
21
|
+
|
|
22
|
+
export default NodeFunction;
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
class NodeFunctionInput {
|
|
2
2
|
|
|
3
|
-
constructor( type, name, qualifier = '', isConst = false
|
|
3
|
+
constructor( type, name, count = null, qualifier = '', isConst = false ) {
|
|
4
4
|
|
|
5
5
|
this.type = type;
|
|
6
6
|
this.name = name;
|
|
7
|
+
this.count = count;
|
|
7
8
|
this.qualifier = qualifier;
|
|
8
9
|
this.isConst = isConst;
|
|
9
|
-
this.count = count;
|
|
10
|
-
|
|
11
|
-
Object.defineProperty( this, 'isNodeFunction', { value: true } );
|
|
12
10
|
|
|
13
11
|
}
|
|
14
12
|
|
|
15
13
|
}
|
|
16
14
|
|
|
15
|
+
NodeFunctionInput.isNodeFunctionInput = true;
|
|
16
|
+
|
|
17
17
|
export default NodeFunctionInput;
|