three-stdlib 2.8.7 → 2.8.10
Sign up to get free protection for your applications and to get access to all the features.
- package/Nodes-607e9ed8.js +471 -0
- package/Nodes-627a8bdf.js +1 -0
- package/index.cjs.js +1 -1
- package/index.d.ts +0 -75
- package/index.js +70 -76
- package/loaders/NodeMaterialLoader.cjs.js +1 -1
- package/loaders/NodeMaterialLoader.js +2 -136
- package/loaders/RGBELoader.cjs.js +1 -1
- package/loaders/RGBELoader.js +3 -3
- package/loaders/RGBMLoader.cjs.js +1 -1
- package/loaders/RGBMLoader.js +190 -268
- package/nodes/Nodes.cjs.js +1 -1
- package/nodes/Nodes.js +203 -76
- package/nodes/ShaderNode.cjs.js +1 -0
- package/nodes/ShaderNode.js +308 -0
- package/nodes/accessors/BufferNode.cjs.js +1 -0
- package/nodes/accessors/BufferNode.js +18 -0
- package/nodes/accessors/CameraNode.cjs.js +1 -1
- package/nodes/accessors/CameraNode.js +32 -138
- package/nodes/accessors/CubeTextureNode.cjs.js +1 -0
- package/nodes/accessors/CubeTextureNode.js +53 -0
- package/nodes/accessors/MaterialNode.cjs.js +1 -0
- package/nodes/accessors/MaterialNode.js +80 -0
- package/nodes/accessors/MaterialReferenceNode.cjs.js +1 -0
- package/nodes/accessors/MaterialReferenceNode.js +16 -0
- package/nodes/accessors/ModelNode.cjs.js +1 -0
- package/nodes/accessors/ModelNode.js +10 -0
- package/nodes/accessors/ModelViewProjectionNode.cjs.js +1 -0
- package/nodes/accessors/ModelViewProjectionNode.js +22 -0
- package/nodes/accessors/NormalNode.cjs.js +1 -1
- package/nodes/accessors/NormalNode.js +48 -78
- package/nodes/accessors/Object3DNode.cjs.js +1 -0
- package/nodes/accessors/Object3DNode.js +85 -0
- package/nodes/accessors/PointUVNode.cjs.js +1 -0
- package/nodes/accessors/PointUVNode.js +16 -0
- package/nodes/accessors/PositionNode.cjs.js +1 -1
- package/nodes/accessors/PositionNode.js +49 -87
- package/nodes/accessors/ReferenceNode.cjs.js +1 -0
- package/nodes/accessors/ReferenceNode.js +43 -0
- package/nodes/accessors/ReflectNode.cjs.js +1 -1
- package/nodes/accessors/ReflectNode.js +35 -98
- package/nodes/accessors/SkinningNode.cjs.js +1 -0
- package/nodes/accessors/SkinningNode.js +59 -0
- package/nodes/accessors/TextureNode.cjs.js +1 -0
- package/nodes/accessors/TextureNode.js +68 -0
- package/nodes/accessors/UVNode.cjs.js +1 -1
- package/nodes/accessors/UVNode.js +20 -38
- package/nodes/core/ArrayUniformNode.cjs.js +1 -0
- package/nodes/core/ArrayUniformNode.js +17 -0
- package/nodes/core/AttributeNode.cjs.js +1 -1
- package/nodes/core/AttributeNode.js +31 -40
- package/nodes/core/BypassNode.cjs.js +1 -0
- package/nodes/core/BypassNode.js +28 -0
- package/nodes/core/CodeNode.cjs.js +1 -0
- package/nodes/core/CodeNode.js +35 -0
- package/nodes/core/ConstNode.cjs.js +1 -1
- package/nodes/core/ConstNode.js +10 -78
- package/nodes/core/ContextNode.cjs.js +1 -0
- package/nodes/core/ContextNode.js +26 -0
- package/nodes/core/ExpressionNode.cjs.js +1 -1
- package/nodes/core/ExpressionNode.js +19 -8
- package/nodes/core/FunctionCallNode.cjs.js +1 -1
- package/nodes/core/FunctionCallNode.js +31 -60
- package/nodes/core/FunctionNode.cjs.js +1 -1
- package/nodes/core/FunctionNode.js +45 -166
- package/nodes/core/InputNode.cjs.js +1 -1
- package/nodes/core/InputNode.js +43 -57
- package/nodes/core/Node.cjs.js +1 -1
- package/nodes/core/Node.js +155 -113
- package/nodes/core/NodeAttribute.cjs.js +1 -0
- package/nodes/core/NodeAttribute.js +11 -0
- package/nodes/core/NodeBuilder.cjs.js +1 -1
- package/nodes/core/NodeBuilder.js +422 -548
- package/nodes/core/NodeCode.cjs.js +1 -0
- package/nodes/core/NodeCode.js +13 -0
- package/nodes/core/NodeFrame.cjs.js +1 -1
- package/nodes/core/NodeFrame.js +34 -27
- package/nodes/core/NodeFunction.cjs.js +1 -0
- package/nodes/core/NodeFunction.js +17 -0
- package/nodes/core/NodeFunctionInput.cjs.js +1 -0
- package/nodes/core/NodeFunctionInput.js +14 -0
- package/nodes/core/NodeKeywords.cjs.js +1 -0
- package/nodes/core/NodeKeywords.js +54 -0
- package/nodes/core/NodeParser.cjs.js +1 -0
- package/nodes/core/NodeParser.js +8 -0
- package/nodes/core/NodeUniform.cjs.js +1 -1
- package/nodes/core/NodeUniform.js +18 -17
- package/nodes/core/NodeUtils.cjs.js +1 -1
- package/nodes/core/NodeUtils.js +55 -35
- package/nodes/core/NodeVar.cjs.js +1 -0
- package/nodes/core/NodeVar.js +11 -0
- package/nodes/core/NodeVary.cjs.js +1 -0
- package/nodes/core/NodeVary.js +11 -0
- package/nodes/core/PropertyNode.cjs.js +1 -0
- package/nodes/core/PropertyNode.js +26 -0
- package/nodes/core/TempNode.cjs.js +1 -1
- package/nodes/core/TempNode.js +21 -88
- package/nodes/core/UniformNode.cjs.js +1 -0
- package/nodes/core/UniformNode.js +28 -0
- package/nodes/core/VarNode.cjs.js +1 -1
- package/nodes/core/VarNode.js +28 -35
- package/nodes/core/VaryNode.cjs.js +1 -0
- package/nodes/core/VaryNode.js +38 -0
- package/nodes/core/constants.cjs.js +1 -0
- package/nodes/core/constants.js +11 -0
- package/nodes/display/ColorSpaceNode.cjs.js +1 -0
- package/nodes/display/ColorSpaceNode.js +67 -0
- package/nodes/display/NormalMapNode.cjs.js +1 -0
- package/nodes/display/NormalMapNode.js +71 -0
- package/nodes/fog/FogNode.cjs.js +1 -0
- package/nodes/fog/FogNode.js +18 -0
- package/nodes/fog/FogRangeNode.cjs.js +1 -0
- package/nodes/fog/FogRangeNode.js +20 -0
- package/nodes/functions/BSDFs.cjs.js +1 -0
- package/nodes/functions/BSDFs.js +121 -0
- package/nodes/functions/PhysicalMaterialFunctions.cjs.js +1 -0
- package/nodes/functions/PhysicalMaterialFunctions.js +57 -0
- package/nodes/lights/LightContextNode.cjs.js +1 -0
- package/nodes/lights/LightContextNode.js +43 -0
- package/nodes/lights/LightNode.cjs.js +1 -0
- package/nodes/lights/LightNode.js +61 -0
- package/nodes/lights/LightsNode.cjs.js +1 -0
- package/nodes/lights/LightsNode.js +77 -0
- package/nodes/loaders/NodeLoader.cjs.js +1 -0
- package/nodes/loaders/NodeLoader.js +80 -0
- package/nodes/loaders/NodeMaterialLoader.cjs.js +1 -0
- package/nodes/loaders/NodeMaterialLoader.js +29 -0
- package/nodes/loaders/NodeObjectLoader.cjs.js +1 -0
- package/nodes/loaders/NodeObjectLoader.js +49 -0
- package/nodes/materials/LineBasicNodeMaterial.cjs.js +1 -0
- package/nodes/materials/LineBasicNodeMaterial.js +31 -0
- package/nodes/materials/Materials.cjs.js +1 -0
- package/nodes/materials/Materials.js +27 -0
- package/nodes/materials/MeshBasicNodeMaterial.cjs.js +1 -0
- package/nodes/materials/MeshBasicNodeMaterial.js +32 -0
- package/nodes/materials/MeshStandardNodeMaterial.cjs.js +1 -1
- package/nodes/materials/MeshStandardNodeMaterial.js +41 -13
- package/nodes/materials/NodeMaterial.cjs.js +1 -1
- package/nodes/materials/NodeMaterial.js +67 -140
- package/nodes/materials/PointsNodeMaterial.cjs.js +1 -0
- package/nodes/materials/PointsNodeMaterial.js +34 -0
- package/nodes/math/CondNode.cjs.js +1 -1
- package/nodes/math/CondNode.js +33 -74
- package/nodes/math/MathNode.cjs.js +1 -1
- package/nodes/math/MathNode.js +193 -193
- package/nodes/math/OperatorNode.cjs.js +1 -1
- package/nodes/math/OperatorNode.js +116 -52
- package/nodes/parsers/GLSLNodeFunction.cjs.js +1 -0
- package/nodes/parsers/GLSLNodeFunction.js +101 -0
- package/nodes/parsers/GLSLNodeParser.cjs.js +1 -0
- package/nodes/parsers/GLSLNodeParser.js +13 -0
- package/nodes/parsers/WGSLNodeFunction.cjs.js +1 -0
- package/nodes/parsers/WGSLNodeFunction.js +71 -0
- package/nodes/parsers/WGSLNodeParser.cjs.js +1 -0
- package/nodes/parsers/WGSLNodeParser.js +13 -0
- package/nodes/procedural/CheckerNode.cjs.js +1 -1
- package/nodes/procedural/CheckerNode.js +22 -40
- package/nodes/utils/ArrayElementNode.cjs.js +1 -0
- package/nodes/utils/ArrayElementNode.js +22 -0
- package/nodes/utils/ConvertNode.cjs.js +1 -0
- package/nodes/utils/ConvertNode.js +29 -0
- package/nodes/utils/JoinNode.cjs.js +1 -1
- package/nodes/utils/JoinNode.js +19 -69
- package/nodes/utils/MatcapUVNode.cjs.js +1 -0
- package/nodes/utils/MatcapUVNode.js +18 -0
- package/nodes/utils/OscNode.cjs.js +1 -0
- package/nodes/utils/OscNode.js +55 -0
- package/nodes/utils/SplitNode.cjs.js +1 -0
- package/nodes/utils/SplitNode.js +58 -0
- package/nodes/utils/SpriteSheetUVNode.cjs.js +1 -0
- package/nodes/utils/SpriteSheetUVNode.js +39 -0
- package/nodes/utils/TimerNode.cjs.js +1 -1
- package/nodes/utils/TimerNode.js +38 -56
- package/package.json +2 -2
- package/Nodes-894ac9dc.js +0 -1
- package/Nodes-af575af7.js +0 -157
- package/nodes/accessors/ColorsNode.cjs.js +0 -1
- package/nodes/accessors/ColorsNode.d.ts +0 -10
- package/nodes/accessors/ColorsNode.js +0 -40
- package/nodes/accessors/LightNode.cjs.js +0 -1
- package/nodes/accessors/LightNode.d.ts +0 -12
- package/nodes/accessors/LightNode.js +0 -41
- package/nodes/accessors/ResolutionNode.cjs.js +0 -1
- package/nodes/accessors/ResolutionNode.d.ts +0 -14
- package/nodes/accessors/ResolutionNode.js +0 -41
- package/nodes/accessors/ScreenUVNode.cjs.js +0 -1
- package/nodes/accessors/ScreenUVNode.d.ts +0 -11
- package/nodes/accessors/ScreenUVNode.js +0 -43
- package/nodes/core/NodeLib.cjs.js +0 -1
- package/nodes/core/NodeLib.d.ts +0 -22
- package/nodes/core/NodeLib.js +0 -37
- package/nodes/core/StructNode.cjs.js +0 -1
- package/nodes/core/StructNode.d.ts +0 -19
- package/nodes/core/StructNode.js +0 -72
- package/nodes/effects/BlurNode.cjs.js +0 -1
- package/nodes/effects/BlurNode.d.ts +0 -31
- package/nodes/effects/BlurNode.js +0 -100
- package/nodes/effects/ColorAdjustmentNode.cjs.js +0 -1
- package/nodes/effects/ColorAdjustmentNode.d.ts +0 -27
- package/nodes/effects/ColorAdjustmentNode.js +0 -73
- package/nodes/effects/LuminanceNode.cjs.js +0 -1
- package/nodes/effects/LuminanceNode.d.ts +0 -18
- package/nodes/effects/LuminanceNode.js +0 -46
- package/nodes/inputs/BoolNode.cjs.js +0 -1
- package/nodes/inputs/BoolNode.d.ts +0 -19
- package/nodes/inputs/BoolNode.js +0 -36
- package/nodes/inputs/ColorNode.cjs.js +0 -1
- package/nodes/inputs/ColorNode.d.ts +0 -21
- package/nodes/inputs/ColorNode.js +0 -41
- package/nodes/inputs/CubeTextureNode.cjs.js +0 -1
- package/nodes/inputs/CubeTextureNode.d.ts +0 -17
- package/nodes/inputs/CubeTextureNode.js +0 -79
- package/nodes/inputs/FloatNode.cjs.js +0 -1
- package/nodes/inputs/FloatNode.d.ts +0 -19
- package/nodes/inputs/FloatNode.js +0 -36
- package/nodes/inputs/IntNode.cjs.js +0 -1
- package/nodes/inputs/IntNode.d.ts +0 -19
- package/nodes/inputs/IntNode.js +0 -36
- package/nodes/inputs/Matrix3Node.cjs.js +0 -1
- package/nodes/inputs/Matrix3Node.d.ts +0 -22
- package/nodes/inputs/Matrix3Node.js +0 -46
- package/nodes/inputs/Matrix4Node.cjs.js +0 -1
- package/nodes/inputs/Matrix4Node.d.ts +0 -22
- package/nodes/inputs/Matrix4Node.js +0 -46
- package/nodes/inputs/PropertyNode.cjs.js +0 -1
- package/nodes/inputs/PropertyNode.d.ts +0 -10
- package/nodes/inputs/PropertyNode.js +0 -35
- package/nodes/inputs/RTTNode.cjs.js +0 -1
- package/nodes/inputs/RTTNode.d.ts +0 -27
- package/nodes/inputs/RTTNode.js +0 -103
- package/nodes/inputs/ReflectorNode.cjs.js +0 -1
- package/nodes/inputs/ReflectorNode.d.ts +0 -21
- package/nodes/inputs/ReflectorNode.js +0 -60
- package/nodes/inputs/ScreenNode.cjs.js +0 -1
- package/nodes/inputs/ScreenNode.d.ts +0 -11
- package/nodes/inputs/ScreenNode.js +0 -20
- package/nodes/inputs/TextureNode.cjs.js +0 -1
- package/nodes/inputs/TextureNode.d.ts +0 -20
- package/nodes/inputs/TextureNode.js +0 -83
- package/nodes/inputs/Vector2Node.cjs.js +0 -1
- package/nodes/inputs/Vector2Node.d.ts +0 -21
- package/nodes/inputs/Vector2Node.js +0 -40
- package/nodes/inputs/Vector3Node.cjs.js +0 -1
- package/nodes/inputs/Vector3Node.d.ts +0 -21
- package/nodes/inputs/Vector3Node.js +0 -41
- package/nodes/inputs/Vector4Node.cjs.js +0 -1
- package/nodes/inputs/Vector4Node.d.ts +0 -21
- package/nodes/inputs/Vector4Node.js +0 -42
- package/nodes/materials/BasicNodeMaterial.cjs.js +0 -1
- package/nodes/materials/BasicNodeMaterial.d.ts +0 -11
- package/nodes/materials/BasicNodeMaterial.js +0 -15
- package/nodes/materials/PhongNodeMaterial.cjs.js +0 -1
- package/nodes/materials/PhongNodeMaterial.d.ts +0 -21
- package/nodes/materials/PhongNodeMaterial.js +0 -15
- package/nodes/materials/SpriteNodeMaterial.cjs.js +0 -1
- package/nodes/materials/SpriteNodeMaterial.d.ts +0 -12
- package/nodes/materials/SpriteNodeMaterial.js +0 -15
- package/nodes/materials/StandardNodeMaterial.cjs.js +0 -1
- package/nodes/materials/StandardNodeMaterial.d.ts +0 -25
- package/nodes/materials/StandardNodeMaterial.js +0 -15
- package/nodes/materials/nodes/BasicNode.cjs.js +0 -1
- package/nodes/materials/nodes/BasicNode.d.ts +0 -15
- package/nodes/materials/nodes/BasicNode.js +0 -91
- package/nodes/materials/nodes/MeshStandardNode.cjs.js +0 -1
- package/nodes/materials/nodes/MeshStandardNode.d.ts +0 -25
- package/nodes/materials/nodes/MeshStandardNode.js +0 -81
- package/nodes/materials/nodes/PhongNode.cjs.js +0 -1
- package/nodes/materials/nodes/PhongNode.d.ts +0 -14
- package/nodes/materials/nodes/PhongNode.js +0 -212
- package/nodes/materials/nodes/RawNode.cjs.js +0 -1
- package/nodes/materials/nodes/RawNode.d.ts +0 -10
- package/nodes/materials/nodes/RawNode.js +0 -42
- package/nodes/materials/nodes/SpriteNode.cjs.js +0 -1
- package/nodes/materials/nodes/SpriteNode.d.ts +0 -13
- package/nodes/materials/nodes/SpriteNode.js +0 -113
- package/nodes/materials/nodes/StandardNode.cjs.js +0 -1
- package/nodes/materials/nodes/StandardNode.d.ts +0 -15
- package/nodes/materials/nodes/StandardNode.js +0 -336
- package/nodes/misc/BumpMapNode.cjs.js +0 -1
- package/nodes/misc/BumpMapNode.d.ts +0 -21
- package/nodes/misc/BumpMapNode.js +0 -80
- package/nodes/misc/NormalMapNode.cjs.js +0 -1
- package/nodes/misc/NormalMapNode.d.ts +0 -19
- package/nodes/misc/NormalMapNode.js +0 -102
- package/nodes/misc/TextureCubeNode.cjs.js +0 -1
- package/nodes/misc/TextureCubeNode.d.ts +0 -21
- package/nodes/misc/TextureCubeNode.js +0 -52
- package/nodes/misc/TextureCubeUVNode.cjs.js +0 -1
- package/nodes/misc/TextureCubeUVNode.d.ts +0 -18
- package/nodes/misc/TextureCubeUVNode.js +0 -229
- package/nodes/postprocessing/NodePass.cjs.js +0 -1
- package/nodes/postprocessing/NodePass.d.ts +0 -15
- package/nodes/postprocessing/NodePass.js +0 -61
- package/nodes/postprocessing/NodePostProcessing.cjs.js +0 -1
- package/nodes/postprocessing/NodePostProcessing.d.ts +0 -26
- package/nodes/postprocessing/NodePostProcessing.js +0 -91
- package/nodes/procedural/NoiseNode.cjs.js +0 -1
- package/nodes/procedural/NoiseNode.d.ts +0 -17
- package/nodes/procedural/NoiseNode.js +0 -43
- package/nodes/utils/BypassNode.cjs.js +0 -1
- package/nodes/utils/BypassNode.d.ts +0 -11
- package/nodes/utils/BypassNode.js +0 -55
- package/nodes/utils/ColorSpaceNode.cjs.js +0 -1
- package/nodes/utils/ColorSpaceNode.d.ts +0 -55
- package/nodes/utils/ColorSpaceNode.js +0 -106
- package/nodes/utils/MaxMIPLevelNode.cjs.js +0 -1
- package/nodes/utils/MaxMIPLevelNode.d.ts +0 -11
- package/nodes/utils/MaxMIPLevelNode.js +0 -38
- package/nodes/utils/SpecularMIPLevelNode.cjs.js +0 -1
- package/nodes/utils/SpecularMIPLevelNode.d.ts +0 -17
- package/nodes/utils/SpecularMIPLevelNode.js +0 -61
- package/nodes/utils/SubSlotNode.cjs.js +0 -1
- package/nodes/utils/SubSlotNode.js +0 -53
- package/nodes/utils/SwitchNode.cjs.js +0 -1
- package/nodes/utils/SwitchNode.d.ts +0 -11
- package/nodes/utils/SwitchNode.js +0 -69
- package/nodes/utils/UVTransformNode.cjs.js +0 -1
- package/nodes/utils/UVTransformNode.d.ts +0 -15
- package/nodes/utils/UVTransformNode.js +0 -46
- package/nodes/utils/VelocityNode.cjs.js +0 -1
- package/nodes/utils/VelocityNode.d.ts +0 -28
- package/nodes/utils/VelocityNode.js +0 -115
@@ -1,631 +1,505 @@
|
|
1
|
-
import
|
2
|
-
import
|
3
|
-
import
|
4
|
-
import
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import {
|
8
|
-
import {
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
constructors = ['float', 'vec2', 'vec3', 'vec4'],
|
17
|
-
convertFormatToType = {
|
18
|
-
float: 'f',
|
19
|
-
vec2: 'v2',
|
20
|
-
vec3: 'v3',
|
21
|
-
vec4: 'v4',
|
22
|
-
mat4: 'v4',
|
23
|
-
int: 'i',
|
24
|
-
bool: 'b'
|
25
|
-
},
|
26
|
-
convertTypeToFormat = {
|
27
|
-
t: 'sampler2D',
|
28
|
-
tc: 'samplerCube',
|
29
|
-
b: 'bool',
|
30
|
-
i: 'int',
|
31
|
-
f: 'float',
|
32
|
-
c: 'vec3',
|
33
|
-
v2: 'vec2',
|
34
|
-
v3: 'vec3',
|
35
|
-
v4: 'vec4',
|
36
|
-
m3: 'mat3',
|
37
|
-
m4: 'mat4'
|
1
|
+
import NodeUniform from './NodeUniform.js';
|
2
|
+
import NodeAttribute from './NodeAttribute.js';
|
3
|
+
import NodeVary from './NodeVary.js';
|
4
|
+
import NodeVar from './NodeVar.js';
|
5
|
+
import NodeCode from './NodeCode.js';
|
6
|
+
import NodeKeywords from './NodeKeywords.js';
|
7
|
+
import { NodeUpdateType } from './constants.js';
|
8
|
+
import { REVISION, LinearEncoding } from 'three';
|
9
|
+
|
10
|
+
const shaderStages = ['fragment', 'vertex'];
|
11
|
+
const vector = ['x', 'y', 'z', 'w'];
|
12
|
+
|
13
|
+
const toFloat = value => {
|
14
|
+
value = Number(value);
|
15
|
+
return value + (value % 1 ? '' : '.0');
|
38
16
|
};
|
39
17
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
this.code = {
|
66
|
-
vertex: '',
|
67
|
-
fragment: ''
|
68
|
-
};
|
69
|
-
this.nodeCode = {
|
70
|
-
vertex: '',
|
71
|
-
fragment: ''
|
72
|
-
};
|
73
|
-
this.resultCode = {
|
74
|
-
vertex: '',
|
75
|
-
fragment: ''
|
76
|
-
};
|
77
|
-
this.finalCode = {
|
78
|
-
vertex: '',
|
79
|
-
fragment: ''
|
80
|
-
};
|
81
|
-
this.inputs = {
|
82
|
-
uniforms: {
|
83
|
-
list: [],
|
18
|
+
class NodeBuilder {
|
19
|
+
constructor(object, renderer, parser) {
|
20
|
+
this.object = object;
|
21
|
+
this.material = object.material;
|
22
|
+
this.renderer = renderer;
|
23
|
+
this.parser = parser;
|
24
|
+
this.nodes = [];
|
25
|
+
this.updateNodes = [];
|
26
|
+
this.hashNodes = {};
|
27
|
+
this.vertexShader = null;
|
28
|
+
this.fragmentShader = null;
|
29
|
+
this.flowNodes = {
|
30
|
+
vertex: [],
|
31
|
+
fragment: []
|
32
|
+
};
|
33
|
+
this.flowCode = {
|
34
|
+
vertex: '',
|
35
|
+
fragment: ''
|
36
|
+
};
|
37
|
+
this.uniforms = {
|
38
|
+
vertex: [],
|
39
|
+
fragment: [],
|
40
|
+
index: 0
|
41
|
+
};
|
42
|
+
this.codes = {
|
84
43
|
vertex: [],
|
85
44
|
fragment: []
|
86
|
-
}
|
87
|
-
|
88
|
-
|
45
|
+
};
|
46
|
+
this.attributes = [];
|
47
|
+
this.varys = [];
|
48
|
+
this.vars = {
|
89
49
|
vertex: [],
|
90
50
|
fragment: []
|
91
|
-
}
|
92
|
-
|
51
|
+
};
|
52
|
+
this.flow = {
|
53
|
+
code: ''
|
54
|
+
};
|
55
|
+
this.stack = [];
|
56
|
+
this.context = {
|
57
|
+
keywords: new NodeKeywords(),
|
58
|
+
material: object.material
|
59
|
+
};
|
60
|
+
this.nodesData = new WeakMap();
|
61
|
+
this.flowsData = new WeakMap();
|
62
|
+
this.shaderStage = null;
|
63
|
+
this.node = null;
|
64
|
+
}
|
93
65
|
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
66
|
+
addStack(node) {
|
67
|
+
/*
|
68
|
+
if ( this.stack.indexOf( node ) !== - 1 ) {
|
69
|
+
console.warn( 'Recursive node: ', node );
|
70
|
+
}
|
71
|
+
*/
|
72
|
+
this.stack.push(node);
|
73
|
+
}
|
99
74
|
|
100
|
-
|
101
|
-
|
75
|
+
removeStack(node) {
|
76
|
+
const lastStack = this.stack.pop();
|
102
77
|
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
this.buildShader('fragment', fragment);
|
78
|
+
if (lastStack !== node) {
|
79
|
+
throw new Error('NodeBuilder: Invalid node stack!');
|
80
|
+
}
|
81
|
+
}
|
108
82
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
this.addVaryCode('varying vec2 vUv' + uvIndex + ';');
|
83
|
+
setHashNode(node, hash) {
|
84
|
+
this.hashNodes[hash] = node;
|
85
|
+
}
|
113
86
|
|
114
|
-
|
115
|
-
|
116
|
-
|
87
|
+
addNode(node) {
|
88
|
+
if (this.nodes.indexOf(node) === -1) {
|
89
|
+
const updateType = node.getUpdateType(this);
|
117
90
|
|
118
|
-
|
91
|
+
if (updateType !== NodeUpdateType.None) {
|
92
|
+
this.updateNodes.push(node);
|
119
93
|
}
|
120
|
-
}
|
121
94
|
|
122
|
-
|
123
|
-
this.
|
124
|
-
this.addVertexParsCode('attribute vec4 color;');
|
125
|
-
this.addVertexFinalCode('vColor = color;');
|
95
|
+
this.nodes.push(node);
|
96
|
+
this.setHashNode(node, node.getHash(this));
|
126
97
|
}
|
98
|
+
}
|
127
99
|
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
this.addVertexFinalCode('vColor2 = color2;');
|
132
|
-
}
|
100
|
+
getMethod(method) {
|
101
|
+
return method;
|
102
|
+
}
|
133
103
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
}
|
104
|
+
getNodeFromHash(hash) {
|
105
|
+
return this.hashNodes[hash];
|
106
|
+
}
|
138
107
|
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
108
|
+
addFlow(shaderStage, node) {
|
109
|
+
this.flowNodes[shaderStage].push(node);
|
110
|
+
return node;
|
111
|
+
}
|
143
112
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
}
|
113
|
+
setContext(context) {
|
114
|
+
this.context = context;
|
115
|
+
}
|
148
116
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
}
|
117
|
+
getContext() {
|
118
|
+
return this.context;
|
119
|
+
}
|
153
120
|
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
this.resultCode[shader] = node.build(this.setShader(shader), 'v4');
|
158
|
-
},
|
159
|
-
setMaterial: function (material, renderer) {
|
160
|
-
this.material = material;
|
161
|
-
this.renderer = renderer;
|
162
|
-
this.requires.lights = material.lights;
|
163
|
-
this.requires.fog = material.fog;
|
164
|
-
this.mergeDefines(material.defines);
|
165
|
-
return this;
|
166
|
-
},
|
167
|
-
addFlow: function (slot, cache, context) {
|
168
|
-
return this.addSlot(slot).addCache(cache).addContext(context);
|
169
|
-
},
|
170
|
-
removeFlow: function () {
|
171
|
-
return this.removeSlot().removeCache().removeContext();
|
172
|
-
},
|
173
|
-
addCache: function (name) {
|
174
|
-
this.cache = name || '';
|
175
|
-
this.caches.push(this.cache);
|
176
|
-
return this;
|
177
|
-
},
|
178
|
-
removeCache: function () {
|
179
|
-
this.caches.pop();
|
180
|
-
this.cache = this.caches[this.caches.length - 1] || '';
|
181
|
-
return this;
|
182
|
-
},
|
183
|
-
addContext: function (context) {
|
184
|
-
this.context = Object.assign({}, this.context, context);
|
185
|
-
this.context.extra = this.context.extra || {};
|
186
|
-
this.contexts.push(this.context);
|
187
|
-
return this;
|
188
|
-
},
|
189
|
-
removeContext: function () {
|
190
|
-
this.contexts.pop();
|
191
|
-
this.context = this.contexts[this.contexts.length - 1] || {};
|
192
|
-
return this;
|
193
|
-
},
|
194
|
-
addSlot: function (name) {
|
195
|
-
this.slot = name || '';
|
196
|
-
this.slots.push(this.slot);
|
197
|
-
return this;
|
198
|
-
},
|
199
|
-
removeSlot: function () {
|
200
|
-
this.slots.pop();
|
201
|
-
this.slot = this.slots[this.slots.length - 1] || '';
|
202
|
-
return this;
|
203
|
-
},
|
204
|
-
addVertexCode: function (code) {
|
205
|
-
this.addCode(code, 'vertex');
|
206
|
-
},
|
207
|
-
addFragmentCode: function (code) {
|
208
|
-
this.addCode(code, 'fragment');
|
209
|
-
},
|
210
|
-
addCode: function (code, shader) {
|
211
|
-
this.code[shader || this.shader] += code + '\n';
|
212
|
-
},
|
213
|
-
addVertexNodeCode: function (code) {
|
214
|
-
this.addNodeCode(code, 'vertex');
|
215
|
-
},
|
216
|
-
addFragmentNodeCode: function (code) {
|
217
|
-
this.addNodeCode(code, 'fragment');
|
218
|
-
},
|
219
|
-
addNodeCode: function (code, shader) {
|
220
|
-
this.nodeCode[shader || this.shader] += code + '\n';
|
221
|
-
},
|
222
|
-
clearNodeCode: function (shader) {
|
223
|
-
shader = shader || this.shader;
|
224
|
-
var code = this.nodeCode[shader];
|
225
|
-
this.nodeCode[shader] = '';
|
226
|
-
return code;
|
227
|
-
},
|
228
|
-
clearVertexNodeCode: function () {
|
229
|
-
return this.clearNodeCode('vertex');
|
230
|
-
},
|
231
|
-
clearFragmentNodeCode: function () {
|
232
|
-
return this.clearNodeCode('fragment');
|
233
|
-
},
|
234
|
-
addVertexFinalCode: function (code) {
|
235
|
-
this.addFinalCode(code, 'vertex');
|
236
|
-
},
|
237
|
-
addFragmentFinalCode: function (code) {
|
238
|
-
this.addFinalCode(code, 'fragment');
|
239
|
-
},
|
240
|
-
addFinalCode: function (code, shader) {
|
241
|
-
this.finalCode[shader || this.shader] += code + '\n';
|
242
|
-
},
|
243
|
-
addVertexParsCode: function (code) {
|
244
|
-
this.addParsCode(code, 'vertex');
|
245
|
-
},
|
246
|
-
addFragmentParsCode: function (code) {
|
247
|
-
this.addParsCode(code, 'fragment');
|
248
|
-
},
|
249
|
-
addParsCode: function (code, shader) {
|
250
|
-
this.parsCode[shader || this.shader] += code + '\n';
|
251
|
-
},
|
252
|
-
addVaryCode: function (code) {
|
253
|
-
this.addVertexParsCode(code);
|
254
|
-
this.addFragmentParsCode(code);
|
255
|
-
},
|
256
|
-
isCache: function (name) {
|
257
|
-
return this.caches.indexOf(name) !== -1;
|
258
|
-
},
|
259
|
-
isSlot: function (name) {
|
260
|
-
return this.slots.indexOf(name) !== -1;
|
261
|
-
},
|
262
|
-
define: function (name, value) {
|
263
|
-
this.defines[name] = value === undefined ? 1 : value;
|
264
|
-
},
|
265
|
-
require: function (name) {
|
266
|
-
this.requires[name] = true;
|
267
|
-
},
|
268
|
-
isDefined: function (name) {
|
269
|
-
return this.defines[name] !== undefined;
|
270
|
-
},
|
271
|
-
getVar: function (uuid, type, ns, shader = 'varying', prefix = 'V', label = '') {
|
272
|
-
var vars = this.getVars(shader),
|
273
|
-
data = vars[uuid];
|
274
|
-
|
275
|
-
if (!data) {
|
276
|
-
var index = vars.length,
|
277
|
-
name = ns ? ns : 'node' + prefix + index + (label ? '_' + label : '');
|
278
|
-
data = {
|
279
|
-
name: name,
|
280
|
-
type: type
|
281
|
-
};
|
282
|
-
vars.push(data);
|
283
|
-
vars[uuid] = data;
|
284
|
-
}
|
121
|
+
getTexture() {
|
122
|
+
console.warn('Abstract function.');
|
123
|
+
}
|
285
124
|
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
return this.getVar(uuid, type, ns, this.shader, 'T', label);
|
290
|
-
},
|
291
|
-
getAttribute: function (name, type) {
|
292
|
-
if (!this.attributes[name]) {
|
293
|
-
var varying = this.getVar(name, type);
|
294
|
-
this.addVertexParsCode('attribute ' + type + ' ' + name + ';');
|
295
|
-
this.addVertexFinalCode(varying.name + ' = ' + name + ';');
|
296
|
-
this.attributes[name] = {
|
297
|
-
varying: varying,
|
298
|
-
name: name,
|
299
|
-
type: type
|
300
|
-
};
|
301
|
-
}
|
125
|
+
getTextureBias() {
|
126
|
+
console.warn('Abstract function.');
|
127
|
+
}
|
302
128
|
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
return [this.prefixCode, this.parsCode[shader], this.getVarListCode(this.getVars('varying'), 'varying'), this.getVarListCode(this.inputs.uniforms[shader], 'uniform'), this.getIncludesCode('consts', shader), this.getIncludesCode('structs', shader), this.getIncludesCode('functions', shader), 'void main() {', this.getVarListCode(this.getVars(shader)), this.code[shader], this.resultCode[shader], this.finalCode[shader], '}'].join('\n');
|
307
|
-
},
|
308
|
-
getVarListCode: function (vars, prefix) {
|
309
|
-
prefix = prefix || '';
|
310
|
-
var code = '';
|
311
|
-
|
312
|
-
for (let i = 0, l = vars.length; i < l; ++i) {
|
313
|
-
var nVar = vars[i],
|
314
|
-
type = nVar.type,
|
315
|
-
name = nVar.name;
|
316
|
-
var formatType = this.getFormatByType(type);
|
317
|
-
|
318
|
-
if (formatType === undefined) {
|
319
|
-
throw new Error('Node pars ' + formatType + ' not found.');
|
320
|
-
}
|
129
|
+
getCubeTexture() {
|
130
|
+
console.warn('Abstract function.');
|
131
|
+
}
|
321
132
|
|
322
|
-
|
323
|
-
|
133
|
+
getCubeTextureBias() {
|
134
|
+
console.warn('Abstract function.');
|
135
|
+
} // @TODO: rename to .generateConst()
|
324
136
|
|
325
|
-
return code;
|
326
|
-
},
|
327
|
-
getVars: function (shader) {
|
328
|
-
return this.inputs.vars[shader || this.shader];
|
329
|
-
},
|
330
|
-
getNodeData: function (node) {
|
331
|
-
var uuid = node.isNode ? node.uuid : node;
|
332
|
-
return this.nodeData[uuid] = this.nodeData[uuid] || {};
|
333
|
-
},
|
334
|
-
createUniform: function (shader, type, node, ns, needsUpdate, label) {
|
335
|
-
var uniforms = this.inputs.uniforms,
|
336
|
-
index = uniforms.list.length;
|
337
|
-
var uniform = new NodeUniform({
|
338
|
-
type: type,
|
339
|
-
name: ns ? ns : 'nodeU' + index + (label ? '_' + label : ''),
|
340
|
-
node: node,
|
341
|
-
needsUpdate: needsUpdate
|
342
|
-
});
|
343
|
-
uniforms.list.push(uniform);
|
344
|
-
uniforms[shader].push(uniform);
|
345
|
-
uniforms[shader][uniform.name] = uniform;
|
346
|
-
this.uniforms[uniform.name] = uniform;
|
347
|
-
return uniform;
|
348
|
-
},
|
349
|
-
createVertexUniform: function (type, node, ns, needsUpdate, label) {
|
350
|
-
return this.createUniform('vertex', type, node, ns, needsUpdate, label);
|
351
|
-
},
|
352
|
-
createFragmentUniform: function (type, node, ns, needsUpdate, label) {
|
353
|
-
return this.createUniform('fragment', type, node, ns, needsUpdate, label);
|
354
|
-
},
|
355
|
-
include: function (node, parent, source) {
|
356
|
-
var includesStruct;
|
357
|
-
node = typeof node === 'string' ? NodeLib.get(node) : node;
|
358
|
-
|
359
|
-
if (this.context.include === false) {
|
360
|
-
return node.name;
|
361
|
-
}
|
362
137
|
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
138
|
+
getConst(type, value) {
|
139
|
+
if (type === 'float') return toFloat(value);
|
140
|
+
if (type === 'int') return `${Math.round(value)}`;
|
141
|
+
if (type === 'uint') return value >= 0 ? `${Math.round(value)}u` : '0u';
|
142
|
+
if (type === 'bool') return value ? 'true' : 'false';
|
143
|
+
if (type === 'color') return `${this.getType('vec3')}( ${toFloat(value.r)}, ${toFloat(value.g)}, ${toFloat(value.b)} )`;
|
144
|
+
const typeLength = this.getTypeLength(type);
|
145
|
+
const componentType = this.getComponentType(type);
|
146
|
+
|
147
|
+
const getConst = value => this.getConst(componentType, value);
|
148
|
+
|
149
|
+
if (typeLength === 2) {
|
150
|
+
return `${this.getType(type)}( ${getConst(value.x)}, ${getConst(value.y)} )`;
|
151
|
+
} else if (typeLength === 3) {
|
152
|
+
return `${this.getType(type)}( ${getConst(value.x)}, ${getConst(value.y)}, ${getConst(value.z)} )`;
|
153
|
+
} else if (typeLength === 4) {
|
154
|
+
return `${this.getType(type)}( ${getConst(value.x)}, ${getConst(value.y)}, ${getConst(value.z)}, ${getConst(value.w)} )`;
|
369
155
|
}
|
370
156
|
|
371
|
-
|
157
|
+
throw new Error(`NodeBuilder: Type '${type}' not found in generate constant attempt.`);
|
158
|
+
}
|
159
|
+
|
160
|
+
getType(type) {
|
161
|
+
return type;
|
162
|
+
}
|
163
|
+
|
164
|
+
generateMethod(method) {
|
165
|
+
return method;
|
166
|
+
}
|
372
167
|
|
373
|
-
|
374
|
-
|
168
|
+
getAttribute(name, type) {
|
169
|
+
const attributes = this.attributes; // find attribute
|
375
170
|
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
deps: []
|
380
|
-
};
|
381
|
-
includes.push(included);
|
382
|
-
included.src = node.build(this, 'source');
|
171
|
+
for (const attribute of attributes) {
|
172
|
+
if (attribute.name === name) {
|
173
|
+
return attribute;
|
383
174
|
}
|
175
|
+
} // create a new if no exist
|
384
176
|
|
385
|
-
if (node instanceof FunctionNode && parent && includes[parent.name] && includes[parent.name].deps.indexOf(node) == -1) {
|
386
|
-
includes[parent.name].deps.push(node);
|
387
177
|
|
388
|
-
|
389
|
-
|
178
|
+
const attribute = new NodeAttribute(name, type);
|
179
|
+
attributes.push(attribute);
|
180
|
+
return attribute;
|
181
|
+
}
|
390
182
|
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
183
|
+
getPropertyName(node
|
184
|
+
/*, shaderStage*/
|
185
|
+
) {
|
186
|
+
return node.name;
|
187
|
+
}
|
396
188
|
|
397
|
-
|
398
|
-
|
399
|
-
|
189
|
+
isVector(type) {
|
190
|
+
return /vec\d/.test(type);
|
191
|
+
}
|
192
|
+
|
193
|
+
isMatrix(type) {
|
194
|
+
return /mat\d/.test(type);
|
195
|
+
}
|
196
|
+
|
197
|
+
isReference(type) {
|
198
|
+
return type === 'void' || type === 'property' || type === 'sampler';
|
199
|
+
}
|
400
200
|
|
401
|
-
|
201
|
+
isShaderStage(shaderStage) {
|
202
|
+
return this.shaderStage === shaderStage;
|
203
|
+
}
|
204
|
+
|
205
|
+
getTextureEncodingFromMap(map) {
|
206
|
+
let encoding;
|
207
|
+
|
208
|
+
if (map && map.isTexture) {
|
209
|
+
encoding = map.encoding;
|
210
|
+
} else if (map && map.isWebGLRenderTarget) {
|
211
|
+
encoding = map.texture.encoding;
|
402
212
|
} else {
|
403
|
-
|
404
|
-
}
|
405
|
-
},
|
406
|
-
colorToVectorProperties: function (color) {
|
407
|
-
return color.replace('r', 'x').replace('g', 'y').replace('b', 'z').replace('a', 'w');
|
408
|
-
},
|
409
|
-
colorToVector: function (color) {
|
410
|
-
return color.replace(/c/g, 'v3');
|
411
|
-
},
|
412
|
-
getIncludes: function (type, shader) {
|
413
|
-
return this.includes[type][shader || this.shader];
|
414
|
-
},
|
415
|
-
getIncludesCode: function () {
|
416
|
-
function sortByPosition(a, b) {
|
417
|
-
return a.deps.length - b.deps.length;
|
213
|
+
encoding = LinearEncoding;
|
418
214
|
}
|
419
215
|
|
420
|
-
return
|
421
|
-
|
422
|
-
|
423
|
-
|
424
|
-
|
216
|
+
return encoding;
|
217
|
+
}
|
218
|
+
|
219
|
+
getComponentType(type) {
|
220
|
+
type = this.getVectorType(type);
|
221
|
+
const componentType = /(b|i|u|)(vec|mat)([2-4])/.exec(type);
|
222
|
+
if (componentType === null) return null;
|
223
|
+
if (componentType[1] === 'b') return 'bool';
|
224
|
+
if (componentType[1] === 'i') return 'int';
|
225
|
+
if (componentType[1] === 'u') return 'uint';
|
226
|
+
return 'float';
|
227
|
+
}
|
425
228
|
|
426
|
-
|
427
|
-
|
428
|
-
|
229
|
+
getVectorType(type) {
|
230
|
+
if (type === 'color') return 'vec3';
|
231
|
+
if (type === 'texture') return 'vec4';
|
232
|
+
return type;
|
233
|
+
}
|
429
234
|
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
438
|
-
|
439
|
-
|
440
|
-
|
441
|
-
|
442
|
-
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
447
|
-
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
|
235
|
+
getTypeFromLength(type) {
|
236
|
+
if (type === 1) return 'float';
|
237
|
+
if (type === 2) return 'vec2';
|
238
|
+
if (type === 3) return 'vec3';
|
239
|
+
if (type === 4) return 'vec4';
|
240
|
+
return 0;
|
241
|
+
}
|
242
|
+
|
243
|
+
getTypeLength(type) {
|
244
|
+
const vecType = this.getVectorType(type);
|
245
|
+
const vecNum = /vec([2-4])/.exec(vecType);
|
246
|
+
if (vecNum !== null) return Number(vecNum[1]);
|
247
|
+
if (vecType === 'float' || vecType === 'bool' || vecType === 'int' || vecType === 'uint') return 1;
|
248
|
+
return 0;
|
249
|
+
}
|
250
|
+
|
251
|
+
getVectorFromMatrix(type) {
|
252
|
+
return type.replace('mat', 'vec');
|
253
|
+
}
|
254
|
+
|
255
|
+
getDataFromNode(node, shaderStage = this.shaderStage) {
|
256
|
+
let nodeData = this.nodesData.get(node);
|
257
|
+
|
258
|
+
if (nodeData === undefined) {
|
259
|
+
nodeData = {
|
260
|
+
vertex: {},
|
261
|
+
fragment: {}
|
262
|
+
};
|
263
|
+
this.nodesData.set(node, nodeData);
|
454
264
|
}
|
455
|
-
|
456
|
-
|
457
|
-
|
458
|
-
|
459
|
-
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
|
468
|
-
|
469
|
-
case CubeUVReflectionMapping:
|
470
|
-
case CubeUVRefractionMapping:
|
471
|
-
return new TextureCubeNode(new TextureNode(nodeCandidate));
|
472
|
-
|
473
|
-
default:
|
474
|
-
return new TextureNode(nodeCandidate);
|
475
|
-
}
|
476
|
-
} else if (nodeCandidate.isVector2) {
|
477
|
-
return new Vector2Node(nodeCandidate);
|
478
|
-
} else if (nodeCandidate.isVector3) {
|
479
|
-
return new Vector3Node(nodeCandidate);
|
480
|
-
} else if (nodeCandidate.isVector4) {
|
481
|
-
return new Vector4Node(nodeCandidate);
|
482
|
-
}
|
483
|
-
}
|
265
|
+
|
266
|
+
return shaderStage !== null ? nodeData[shaderStage] : nodeData;
|
267
|
+
}
|
268
|
+
|
269
|
+
getUniformFromNode(node, shaderStage, type) {
|
270
|
+
const nodeData = this.getDataFromNode(node, shaderStage);
|
271
|
+
let nodeUniform = nodeData.uniform;
|
272
|
+
|
273
|
+
if (nodeUniform === undefined) {
|
274
|
+
const index = this.uniforms.index++;
|
275
|
+
nodeUniform = new NodeUniform('nodeUniform' + index, type, node);
|
276
|
+
this.uniforms[shaderStage].push(nodeUniform);
|
277
|
+
nodeData.uniform = nodeUniform;
|
484
278
|
}
|
485
|
-
},
|
486
|
-
format: function (code, from, to) {
|
487
|
-
var typeToType = this.colorToVector(to + ' <- ' + from);
|
488
279
|
|
489
|
-
|
490
|
-
|
491
|
-
return code + '.x';
|
280
|
+
return nodeUniform;
|
281
|
+
}
|
492
282
|
|
493
|
-
|
494
|
-
|
283
|
+
getVarFromNode(node, type, shaderStage = this.shaderStage) {
|
284
|
+
const nodeData = this.getDataFromNode(node, shaderStage);
|
285
|
+
let nodeVar = nodeData.variable;
|
495
286
|
|
496
|
-
|
497
|
-
|
287
|
+
if (nodeVar === undefined) {
|
288
|
+
const vars = this.vars[shaderStage];
|
289
|
+
const index = vars.length;
|
290
|
+
nodeVar = new NodeVar('nodeVar' + index, type);
|
291
|
+
vars.push(nodeVar);
|
292
|
+
nodeData.variable = nodeVar;
|
293
|
+
}
|
498
294
|
|
499
|
-
|
500
|
-
|
501
|
-
return 'float( ' + code + ' )';
|
295
|
+
return nodeVar;
|
296
|
+
}
|
502
297
|
|
503
|
-
|
504
|
-
|
298
|
+
getVaryFromNode(node, type) {
|
299
|
+
const nodeData = this.getDataFromNode(node, null);
|
300
|
+
let nodeVary = nodeData.vary;
|
505
301
|
|
506
|
-
|
507
|
-
|
302
|
+
if (nodeVary === undefined) {
|
303
|
+
const varys = this.varys;
|
304
|
+
const index = varys.length;
|
305
|
+
nodeVary = new NodeVary('nodeVary' + index, type);
|
306
|
+
varys.push(nodeVary);
|
307
|
+
nodeData.vary = nodeVary;
|
308
|
+
}
|
508
309
|
|
509
|
-
|
510
|
-
|
310
|
+
return nodeVary;
|
311
|
+
}
|
511
312
|
|
512
|
-
|
513
|
-
|
514
|
-
|
313
|
+
getCodeFromNode(node, type, shaderStage = this.shaderStage) {
|
314
|
+
const nodeData = this.getDataFromNode(node);
|
315
|
+
let nodeCode = nodeData.code;
|
515
316
|
|
516
|
-
|
517
|
-
|
317
|
+
if (nodeCode === undefined) {
|
318
|
+
const codes = this.codes[shaderStage];
|
319
|
+
const index = codes.length;
|
320
|
+
nodeCode = new NodeCode('nodeCode' + index, type);
|
321
|
+
codes.push(nodeCode);
|
322
|
+
nodeData.code = nodeCode;
|
323
|
+
}
|
518
324
|
|
519
|
-
|
520
|
-
|
325
|
+
return nodeCode;
|
326
|
+
}
|
521
327
|
|
522
|
-
|
523
|
-
|
328
|
+
addFlowCode(code) {
|
329
|
+
this.flow.code += code;
|
330
|
+
}
|
524
331
|
|
525
|
-
|
526
|
-
|
527
|
-
|
332
|
+
getFlowData(shaderStage, node) {
|
333
|
+
return this.flowsData.get(node);
|
334
|
+
}
|
528
335
|
|
529
|
-
|
530
|
-
|
336
|
+
flowNode(node) {
|
337
|
+
this.node = node;
|
338
|
+
const output = node.getNodeType(this);
|
339
|
+
const flowData = this.flowChildNode(node, output);
|
340
|
+
this.flowsData.set(node, flowData);
|
341
|
+
this.node = null;
|
342
|
+
return flowData;
|
343
|
+
}
|
531
344
|
|
532
|
-
|
533
|
-
|
345
|
+
flowChildNode(node, output = null) {
|
346
|
+
const previousFlow = this.flow;
|
347
|
+
const flow = {
|
348
|
+
code: ''
|
349
|
+
};
|
350
|
+
this.flow = flow;
|
351
|
+
flow.result = node.build(this, output);
|
352
|
+
this.flow = previousFlow;
|
353
|
+
return flow;
|
354
|
+
}
|
534
355
|
|
535
|
-
|
536
|
-
|
356
|
+
flowNodeFromShaderStage(shaderStage, node, output = null, propertyName = null) {
|
357
|
+
const previousShaderStage = this.shaderStage;
|
358
|
+
this.setShaderStage(shaderStage);
|
359
|
+
const flowData = this.flowChildNode(node, output);
|
537
360
|
|
538
|
-
|
539
|
-
|
540
|
-
|
361
|
+
if (propertyName !== null) {
|
362
|
+
flowData.code += `${propertyName} = ${flowData.result};\n\t`;
|
363
|
+
}
|
541
364
|
|
542
|
-
|
543
|
-
|
544
|
-
|
365
|
+
this.flowCode[shaderStage] = this.flowCode[shaderStage] + flowData.code;
|
366
|
+
this.setShaderStage(previousShaderStage);
|
367
|
+
return flowData;
|
368
|
+
}
|
545
369
|
|
546
|
-
|
547
|
-
|
370
|
+
getAttributes() {
|
371
|
+
console.warn('Abstract function.');
|
372
|
+
}
|
548
373
|
|
549
|
-
|
550
|
-
|
374
|
+
getVarys() {
|
375
|
+
console.warn('Abstract function.');
|
376
|
+
}
|
551
377
|
|
552
|
-
|
553
|
-
|
378
|
+
getVars(shaderStage) {
|
379
|
+
let snippet = '';
|
380
|
+
const vars = this.vars[shaderStage];
|
554
381
|
|
555
|
-
|
556
|
-
|
382
|
+
for (let index = 0; index < vars.length; index++) {
|
383
|
+
const variable = vars[index];
|
384
|
+
snippet += `${variable.type} ${variable.name}; `;
|
385
|
+
}
|
557
386
|
|
558
|
-
|
559
|
-
|
387
|
+
return snippet;
|
388
|
+
}
|
560
389
|
|
561
|
-
|
562
|
-
|
390
|
+
getUniforms() {
|
391
|
+
console.warn('Abstract function.');
|
392
|
+
}
|
563
393
|
|
564
|
-
|
565
|
-
|
394
|
+
getCodes(shaderStage) {
|
395
|
+
const codes = this.codes[shaderStage];
|
396
|
+
let code = '';
|
566
397
|
|
567
|
-
|
568
|
-
|
398
|
+
for (const nodeCode of codes) {
|
399
|
+
code += nodeCode.code + '\n';
|
569
400
|
}
|
570
401
|
|
571
402
|
return code;
|
572
|
-
}
|
573
|
-
|
574
|
-
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
403
|
+
}
|
404
|
+
|
405
|
+
getHash() {
|
406
|
+
return this.vertexShader + this.fragmentShader;
|
407
|
+
}
|
408
|
+
|
409
|
+
getShaderStage() {
|
410
|
+
return this.shaderStage;
|
411
|
+
}
|
412
|
+
|
413
|
+
setShaderStage(shaderStage) {
|
414
|
+
this.shaderStage = shaderStage;
|
415
|
+
}
|
416
|
+
|
417
|
+
buildCode() {
|
418
|
+
console.warn('Abstract function.');
|
419
|
+
}
|
420
|
+
|
421
|
+
build() {
|
422
|
+
// stage 1: analyze nodes to possible optimization and validation
|
423
|
+
for (const shaderStage of shaderStages) {
|
424
|
+
this.setShaderStage(shaderStage);
|
425
|
+
const flowNodes = this.flowNodes[shaderStage];
|
426
|
+
|
427
|
+
for (const node of flowNodes) {
|
428
|
+
node.analyze(this);
|
429
|
+
}
|
430
|
+
} // stage 2: pre-build vertex code used in fragment shader
|
431
|
+
|
432
|
+
|
433
|
+
if (this.context.vertex && this.context.vertex.isNode) {
|
434
|
+
this.flowNodeFromShaderStage('vertex', this.context.vertex);
|
435
|
+
} // stage 3: generate shader
|
436
|
+
|
437
|
+
|
438
|
+
for (const shaderStage of shaderStages) {
|
439
|
+
this.setShaderStage(shaderStage);
|
440
|
+
const flowNodes = this.flowNodes[shaderStage];
|
441
|
+
|
442
|
+
for (const node of flowNodes) {
|
443
|
+
this.flowNode(node, shaderStage);
|
444
|
+
}
|
445
|
+
}
|
446
|
+
|
447
|
+
this.setShaderStage(null); // stage 4: build code for a specific output
|
448
|
+
|
449
|
+
this.buildCode();
|
595
450
|
return this;
|
596
|
-
}
|
597
|
-
|
598
|
-
|
599
|
-
|
451
|
+
}
|
452
|
+
|
453
|
+
format(snippet, fromType, toType) {
|
454
|
+
fromType = this.getVectorType(fromType);
|
455
|
+
toType = this.getVectorType(toType);
|
456
|
+
|
457
|
+
if (fromType === toType || toType === null || this.isReference(toType)) {
|
458
|
+
return snippet;
|
600
459
|
}
|
601
460
|
|
602
|
-
|
603
|
-
|
604
|
-
|
605
|
-
|
606
|
-
|
461
|
+
const fromTypeLength = this.getTypeLength(fromType);
|
462
|
+
const toTypeLength = this.getTypeLength(toType);
|
463
|
+
|
464
|
+
if (fromTypeLength === 0) {
|
465
|
+
// fromType is matrix-like
|
466
|
+
const vectorType = this.getVectorFromMatrix(fromType);
|
467
|
+
return this.format(`( ${snippet} * ${this.getType(vectorType)}( 1.0 ) )`, vectorType, toType);
|
607
468
|
}
|
608
469
|
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
470
|
+
if (toTypeLength === 0) {
|
471
|
+
// toType is matrix-like
|
472
|
+
// ignore for now
|
473
|
+
//return `${ this.getType( toType ) }( ${ snippet } )`;
|
474
|
+
return snippet;
|
475
|
+
}
|
613
476
|
|
614
|
-
if (
|
615
|
-
|
616
|
-
} else if (map.isTexture) {
|
617
|
-
encoding = map.encoding;
|
618
|
-
} else if (map.isWebGLRenderTarget) {
|
619
|
-
console.warn("THREE.WebGLPrograms.getTextureEncodingFromMap: don't use render targets as textures. Use their .texture property instead.");
|
620
|
-
encoding = map.texture.encoding;
|
477
|
+
if (fromTypeLength === toTypeLength) {
|
478
|
+
return `${this.getType(toType)}( ${snippet} )`;
|
621
479
|
}
|
622
480
|
|
623
|
-
if (
|
624
|
-
|
481
|
+
if (fromTypeLength > toTypeLength) {
|
482
|
+
return this.format(`${snippet}.${'xyz'.slice(0, toTypeLength)}`, this.getTypeFromLength(toTypeLength), toType);
|
625
483
|
}
|
626
484
|
|
627
|
-
|
485
|
+
if (toTypeLength === 4) {
|
486
|
+
// toType is vec4-like
|
487
|
+
return `${this.getType(toType)}( ${this.format(snippet, fromType, 'vec3')}, 1.0 )`;
|
488
|
+
}
|
489
|
+
|
490
|
+
if (fromTypeLength === 2) {
|
491
|
+
// fromType is vec2-like and toType is vec3-like
|
492
|
+
return `${this.getType(toType)}( ${this.format(snippet, fromType, 'vec2')}, 0.0 )`;
|
493
|
+
}
|
494
|
+
|
495
|
+
return `${this.getType(toType)}( ${snippet} )`; // fromType is float-like
|
628
496
|
}
|
629
|
-
};
|
630
497
|
|
631
|
-
|
498
|
+
getSignature() {
|
499
|
+
return `// Three.js r${REVISION} - NodeMaterial System\n`;
|
500
|
+
}
|
501
|
+
|
502
|
+
}
|
503
|
+
|
504
|
+
export default NodeBuilder;
|
505
|
+
export { shaderStages, vector };
|