super-three 0.156.0 → 0.157.1

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.
Files changed (223) hide show
  1. package/build/three.cjs +753 -277
  2. package/build/three.js +753 -277
  3. package/build/three.min.js +2 -2
  4. package/build/three.module.js +750 -276
  5. package/build/three.module.min.js +1 -1
  6. package/examples/jsm/capabilities/WebGL.js +17 -0
  7. package/examples/jsm/controls/DragControls.js +3 -2
  8. package/examples/jsm/csm/CSMShader.js +25 -21
  9. package/examples/jsm/exporters/EXRExporter.js +102 -24
  10. package/examples/jsm/exporters/GLTFExporter.js +1 -1
  11. package/examples/jsm/libs/rhino3dm/rhino3dm.js +8726 -4
  12. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +8737 -4
  13. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  14. package/examples/jsm/lights/LightProbeGenerator.js +37 -3
  15. package/examples/jsm/lines/LineMaterial.js +90 -156
  16. package/examples/jsm/loaders/3DMLoader.js +378 -104
  17. package/examples/jsm/loaders/GLTFLoader.js +1 -1
  18. package/examples/jsm/loaders/LDrawLoader.js +22 -16
  19. package/examples/jsm/loaders/RGBELoader.js +1 -1
  20. package/examples/jsm/loaders/USDZLoader.js +215 -12
  21. package/examples/jsm/materials/MeshGouraudMaterial.js +22 -18
  22. package/examples/jsm/nodes/Nodes.js +5 -1
  23. package/examples/jsm/nodes/accessors/BitangentNode.js +1 -1
  24. package/examples/jsm/nodes/accessors/BufferAttributeNode.js +2 -2
  25. package/examples/jsm/nodes/accessors/BufferNode.js +1 -1
  26. package/examples/jsm/nodes/accessors/CameraNode.js +1 -1
  27. package/examples/jsm/nodes/accessors/CubeTextureNode.js +2 -2
  28. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +6 -5
  29. package/examples/jsm/nodes/accessors/InstanceNode.js +2 -2
  30. package/examples/jsm/nodes/accessors/LineMaterialNode.js +7 -9
  31. package/examples/jsm/nodes/accessors/MaterialNode.js +34 -46
  32. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +9 -9
  33. package/examples/jsm/nodes/accessors/ModelNode.js +1 -1
  34. package/examples/jsm/nodes/accessors/ModelViewProjectionNode.js +5 -4
  35. package/examples/jsm/nodes/accessors/MorphNode.js +4 -4
  36. package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
  37. package/examples/jsm/nodes/accessors/Object3DNode.js +1 -1
  38. package/examples/jsm/nodes/accessors/PointUVNode.js +1 -1
  39. package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
  40. package/examples/jsm/nodes/accessors/ReferenceNode.js +13 -7
  41. package/examples/jsm/nodes/accessors/ReflectVectorNode.js +2 -2
  42. package/examples/jsm/nodes/accessors/SceneNode.js +2 -2
  43. package/examples/jsm/nodes/accessors/SkinningNode.js +2 -2
  44. package/examples/jsm/nodes/accessors/StorageBufferNode.js +1 -1
  45. package/examples/jsm/nodes/accessors/TangentNode.js +1 -1
  46. package/examples/jsm/nodes/accessors/TextureBicubicNode.js +2 -2
  47. package/examples/jsm/nodes/accessors/TextureNode.js +12 -6
  48. package/examples/jsm/nodes/accessors/TextureSizeNode.js +2 -2
  49. package/examples/jsm/nodes/accessors/TextureStoreNode.js +1 -1
  50. package/examples/jsm/nodes/accessors/UVNode.js +1 -1
  51. package/examples/jsm/nodes/accessors/UserDataNode.js +2 -2
  52. package/examples/jsm/nodes/code/CodeNode.js +1 -1
  53. package/examples/jsm/nodes/code/ExpressionNode.js +1 -1
  54. package/examples/jsm/nodes/code/FunctionCallNode.js +1 -1
  55. package/examples/jsm/nodes/code/FunctionNode.js +18 -7
  56. package/examples/jsm/nodes/code/ScriptableNode.js +2 -2
  57. package/examples/jsm/nodes/code/ScriptableValueNode.js +2 -2
  58. package/examples/jsm/nodes/core/ArrayUniformNode.js +1 -1
  59. package/examples/jsm/nodes/core/AttributeNode.js +1 -1
  60. package/examples/jsm/nodes/core/BypassNode.js +1 -1
  61. package/examples/jsm/nodes/core/CacheNode.js +1 -1
  62. package/examples/jsm/nodes/core/ConstNode.js +1 -1
  63. package/examples/jsm/nodes/core/ContextNode.js +2 -2
  64. package/examples/jsm/nodes/core/IndexNode.js +1 -1
  65. package/examples/jsm/nodes/core/InputNode.js +1 -1
  66. package/examples/jsm/nodes/core/Node.js +28 -13
  67. package/examples/jsm/nodes/core/NodeBuilder.js +3 -17
  68. package/examples/jsm/nodes/core/NodeFrame.js +37 -14
  69. package/examples/jsm/nodes/core/OutputStructNode.js +8 -4
  70. package/examples/jsm/nodes/core/PropertyNode.js +3 -3
  71. package/examples/jsm/nodes/core/StackNode.js +1 -1
  72. package/examples/jsm/nodes/core/StructTypeNode.js +1 -1
  73. package/examples/jsm/nodes/core/TempNode.js +1 -1
  74. package/examples/jsm/nodes/core/UniformNode.js +3 -1
  75. package/examples/jsm/nodes/core/VarNode.js +1 -1
  76. package/examples/jsm/nodes/core/VaryingNode.js +1 -1
  77. package/examples/jsm/nodes/core/constants.js +1 -1
  78. package/examples/jsm/nodes/display/BlendModeNode.js +2 -2
  79. package/examples/jsm/nodes/display/BumpMapNode.js +2 -2
  80. package/examples/jsm/nodes/display/ColorAdjustmentNode.js +2 -2
  81. package/examples/jsm/nodes/display/ColorSpaceNode.js +2 -2
  82. package/examples/jsm/nodes/display/FrontFacingNode.js +1 -1
  83. package/examples/jsm/nodes/display/NormalMapNode.js +2 -2
  84. package/examples/jsm/nodes/display/PosterizeNode.js +2 -2
  85. package/examples/jsm/nodes/display/ToneMappingNode.js +2 -2
  86. package/examples/jsm/nodes/display/ViewportDepthNode.js +2 -2
  87. package/examples/jsm/nodes/display/ViewportDepthTextureNode.js +1 -1
  88. package/examples/jsm/nodes/display/ViewportNode.js +2 -2
  89. package/examples/jsm/nodes/display/ViewportSharedTextureNode.js +1 -1
  90. package/examples/jsm/nodes/display/ViewportTextureNode.js +1 -1
  91. package/examples/jsm/nodes/fog/FogExp2Node.js +2 -2
  92. package/examples/jsm/nodes/fog/FogNode.js +2 -2
  93. package/examples/jsm/nodes/fog/FogRangeNode.js +2 -2
  94. package/examples/jsm/nodes/geometry/RangeNode.js +2 -2
  95. package/examples/jsm/nodes/gpgpu/ComputeNode.js +1 -1
  96. package/examples/jsm/nodes/lighting/AONode.js +2 -2
  97. package/examples/jsm/nodes/lighting/AmbientLightNode.js +3 -3
  98. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +4 -4
  99. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +4 -4
  100. package/examples/jsm/nodes/lighting/EnvironmentNode.js +2 -2
  101. package/examples/jsm/nodes/lighting/HemisphereLightNode.js +3 -3
  102. package/examples/jsm/nodes/lighting/IESSpotLightNode.js +2 -2
  103. package/examples/jsm/nodes/lighting/LightNode.js +2 -2
  104. package/examples/jsm/nodes/lighting/LightingContextNode.js +3 -3
  105. package/examples/jsm/nodes/lighting/LightingNode.js +1 -1
  106. package/examples/jsm/nodes/lighting/LightsNode.js +4 -4
  107. package/examples/jsm/nodes/lighting/PointLightNode.js +3 -3
  108. package/examples/jsm/nodes/lighting/SpotLightNode.js +4 -4
  109. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +449 -0
  110. package/examples/jsm/nodes/materials/LineBasicNodeMaterial.js +1 -1
  111. package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +2 -2
  112. package/examples/jsm/nodes/materials/Materials.js +1 -0
  113. package/examples/jsm/nodes/materials/MeshBasicNodeMaterial.js +1 -1
  114. package/examples/jsm/nodes/materials/MeshLambertNodeMaterial.js +2 -2
  115. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -2
  116. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +3 -3
  117. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +6 -6
  118. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +3 -3
  119. package/examples/jsm/nodes/materials/NodeMaterial.js +27 -26
  120. package/examples/jsm/nodes/materials/PointsNodeMaterial.js +1 -1
  121. package/examples/jsm/nodes/materials/SpriteNodeMaterial.js +2 -2
  122. package/examples/jsm/nodes/math/CondNode.js +1 -1
  123. package/examples/jsm/nodes/math/HashNode.js +8 -9
  124. package/examples/jsm/nodes/math/MathNode.js +2 -2
  125. package/examples/jsm/nodes/math/OperatorNode.js +1 -1
  126. package/examples/jsm/nodes/procedural/CheckerNode.js +3 -3
  127. package/examples/jsm/nodes/shadernode/ShaderNode.js +81 -28
  128. package/examples/jsm/nodes/utils/ArrayElementNode.js +1 -1
  129. package/examples/jsm/nodes/utils/ConvertNode.js +1 -1
  130. package/examples/jsm/nodes/utils/DiscardNode.js +1 -1
  131. package/examples/jsm/nodes/utils/EquirectUVNode.js +2 -2
  132. package/examples/jsm/nodes/utils/JoinNode.js +1 -1
  133. package/examples/jsm/nodes/utils/LoopNode.js +11 -11
  134. package/examples/jsm/nodes/utils/MatcapUVNode.js +2 -2
  135. package/examples/jsm/nodes/utils/MaxMipLevelNode.js +1 -1
  136. package/examples/jsm/nodes/utils/OscNode.js +2 -2
  137. package/examples/jsm/nodes/utils/PackingNode.js +2 -2
  138. package/examples/jsm/nodes/utils/RemapNode.js +2 -2
  139. package/examples/jsm/nodes/utils/RotateUVNode.js +2 -2
  140. package/examples/jsm/nodes/utils/SetNode.js +62 -0
  141. package/examples/jsm/nodes/utils/SpecularMIPLevelNode.js +2 -2
  142. package/examples/jsm/nodes/utils/SplitNode.js +1 -1
  143. package/examples/jsm/nodes/utils/SpriteSheetUVNode.js +2 -2
  144. package/examples/jsm/nodes/utils/TimerNode.js +2 -2
  145. package/examples/jsm/nodes/utils/TriplanarTexturesNode.js +2 -2
  146. package/examples/jsm/objects/Sky.js +1 -3
  147. package/examples/jsm/postprocessing/OutputPass.js +3 -2
  148. package/examples/jsm/renderers/common/Background.js +2 -2
  149. package/examples/jsm/renderers/common/Bindings.js +3 -5
  150. package/examples/jsm/renderers/common/Pipelines.js +7 -7
  151. package/examples/jsm/renderers/common/RenderContext.js +3 -0
  152. package/examples/jsm/renderers/common/RenderObject.js +40 -16
  153. package/examples/jsm/renderers/common/RenderObjects.js +8 -14
  154. package/examples/jsm/renderers/common/Renderer.js +40 -13
  155. package/examples/jsm/renderers/common/SampledTexture.js +4 -2
  156. package/examples/jsm/renderers/common/StorageTexture.js +19 -0
  157. package/examples/jsm/renderers/common/Textures.js +14 -9
  158. package/examples/jsm/renderers/common/nodes/NodeBuilderState.js +35 -0
  159. package/examples/jsm/renderers/common/nodes/NodeSampledTexture.js +20 -10
  160. package/examples/jsm/renderers/common/nodes/NodeSampler.js +0 -6
  161. package/examples/jsm/renderers/common/nodes/Nodes.js +51 -24
  162. package/examples/jsm/renderers/webgl/WebGLBackend.js +100 -5
  163. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +92 -6
  164. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +13 -0
  165. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodeBuilder.js +3 -3
  166. package/examples/jsm/renderers/webgl-legacy/nodes/WebGLNodes.js +14 -2
  167. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +5 -5
  168. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +6 -3
  169. package/examples/jsm/renderers/webgpu/utils/WebGPUPipelineUtils.js +5 -5
  170. package/examples/jsm/renderers/webgpu/utils/WebGPUTexturePassUtils.js +285 -0
  171. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +197 -167
  172. package/examples/jsm/shaders/GammaCorrectionShader.js +1 -1
  173. package/examples/jsm/shaders/MMDToonShader.js +4 -4
  174. package/examples/jsm/shaders/OutputShader.js +2 -2
  175. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +6 -6
  176. package/examples/jsm/utils/BufferGeometryUtils.js +6 -4
  177. package/package.json +1 -1
  178. package/src/Three.js +0 -2
  179. package/src/animation/AnimationUtils.js +3 -20
  180. package/src/animation/KeyframeTrack.js +8 -8
  181. package/src/cameras/Camera.js +1 -5
  182. package/src/cameras/CubeCamera.js +14 -8
  183. package/src/constants.js +7 -1
  184. package/src/core/RenderTarget.js +16 -7
  185. package/src/extras/core/CurvePath.js +4 -1
  186. package/src/loaders/MaterialLoader.js +1 -1
  187. package/src/loaders/ObjectLoader.js +6 -0
  188. package/src/materials/Material.js +8 -8
  189. package/src/math/Color.js +1 -5
  190. package/src/math/ColorManagement.js +82 -60
  191. package/src/objects/Sprite.js +2 -2
  192. package/src/renderers/WebGLMultiviewRenderTarget.js +35 -0
  193. package/src/renderers/WebGLRenderer.js +78 -22
  194. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +1 -1
  195. package/src/renderers/shaders/ShaderChunk/clearcoat_normal_fragment_begin.glsl.js +1 -1
  196. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +35 -2
  197. package/src/renderers/shaders/ShaderChunk/common.glsl.js +0 -9
  198. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +19 -15
  199. package/src/renderers/shaders/ShaderChunk/lights_fragment_end.glsl.js +2 -2
  200. package/src/renderers/shaders/ShaderChunk/lights_fragment_maps.glsl.js +4 -4
  201. package/src/renderers/shaders/ShaderChunk/lights_lambert_pars_fragment.glsl.js +3 -3
  202. package/src/renderers/shaders/ShaderChunk/lights_pars_begin.glsl.js +11 -6
  203. package/src/renderers/shaders/ShaderChunk/lights_phong_pars_fragment.glsl.js +4 -4
  204. package/src/renderers/shaders/ShaderChunk/lights_physical_fragment.glsl.js +1 -1
  205. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +16 -16
  206. package/src/renderers/shaders/ShaderChunk/lights_toon_pars_fragment.glsl.js +3 -3
  207. package/src/renderers/shaders/ShaderChunk/normal_fragment_begin.glsl.js +1 -1
  208. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +1 -1
  209. package/src/renderers/shaders/UniformsUtils.js +2 -2
  210. package/src/renderers/webgl/WebGLBackground.js +5 -4
  211. package/src/renderers/webgl/WebGLLights.js +14 -3
  212. package/src/renderers/webgl/WebGLMultiview.js +100 -0
  213. package/src/renderers/webgl/WebGLProgram.js +84 -5
  214. package/src/renderers/webgl/WebGLPrograms.js +11 -2
  215. package/src/renderers/webgl/WebGLTextures.js +214 -26
  216. package/src/renderers/webgl/WebGLUtils.js +21 -23
  217. package/src/renderers/webxr/WebXRManager.js +36 -12
  218. package/src/scenes/Fog.js +1 -0
  219. package/src/scenes/FogExp2.js +1 -0
  220. package/src/textures/Source.js +2 -2
  221. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureMipmapUtils.js +0 -163
  222. package/src/lights/AmbientLightProbe.js +0 -21
  223. package/src/lights/HemisphereLightProbe.js +0 -30
@@ -0,0 +1,449 @@
1
+ import NodeMaterial, { addNodeMaterial } from './NodeMaterial.js';
2
+ import { temp } from '../core/VarNode.js';
3
+ import { varying } from '../core/VaryingNode.js';
4
+ import { property } from '../core/PropertyNode.js';
5
+ import { attribute } from '../core/AttributeNode.js';
6
+ import { cameraProjectionMatrix } from '../accessors/CameraNode.js';
7
+ import { materialColor } from '../accessors/MaterialNode.js';
8
+ import { modelViewMatrix } from '../accessors/ModelNode.js';
9
+ import { positionGeometry } from '../accessors/PositionNode.js';
10
+ import { abs, mix, mod, dot, clamp, smoothstep } from '../math/MathNode.js';
11
+ import { tslFn, ShaderNode, float, vec2, vec3, vec4 } from '../shadernode/ShaderNode.js';
12
+ import { uv } from '../accessors/UVNode.js';
13
+ import { materialLineScale, materialLineDashSize, materialLineGapSize, materialLineDashOffset, materialLineWidth } from '../accessors/LineMaterialNode.js';
14
+ import { viewport } from '../display/ViewportNode.js';
15
+ import { dashSize, gapSize } from '../core/PropertyNode.js';
16
+
17
+ import { LineDashedMaterial } from 'three';
18
+
19
+ const defaultValues = new LineDashedMaterial();
20
+
21
+ class Line2NodeMaterial extends NodeMaterial {
22
+
23
+ constructor( params = {} ) {
24
+
25
+ super();
26
+
27
+ this.normals = false;
28
+ this.lights = false;
29
+
30
+ this.setDefaultValues( defaultValues );
31
+
32
+ this.useAlphaToCoverage = true;
33
+ this.useColor = params.vertexColors;
34
+ this.useDash = params.dashed;
35
+ this.useWorldUnits = false;
36
+
37
+ this.dashOffset = 0;
38
+ this.lineWidth = 1;
39
+
40
+ this.lineColorNode = null;
41
+
42
+ this.offsetNode = null;
43
+ this.dashScaleNode = null;
44
+ this.dashSizeNode = null;
45
+ this.gapSizeNode = null;
46
+
47
+ this.setupShaders();
48
+
49
+ this.setValues( params );
50
+
51
+ }
52
+
53
+ setupShaders() {
54
+
55
+ const useAlphaToCoverage = this.alphaToCoverage;
56
+ const useColor = this.useColor;
57
+ const useDash = this.dashed;
58
+ const useWorldUnits = this.worldUnits;
59
+
60
+ const trimSegment = tslFn( ( { start, end } ) => {
61
+
62
+ const a = cameraProjectionMatrix.element( 2 ).element( 2 ); // 3nd entry in 3th column
63
+ const b = cameraProjectionMatrix.element( 3 ).element( 2 ); // 3nd entry in 4th column
64
+ const nearEstimate = b.mul( -0.5 ).div( a );
65
+
66
+ const alpha = nearEstimate.sub( start.z ).div( end.z.sub( start.z ) );
67
+
68
+ return vec4( mix( start.xyz, end.xyz, alpha ), end.w );
69
+
70
+ } );
71
+
72
+ this.vertexNode = new ShaderNode( ( stack ) => {
73
+
74
+ stack.assign( varying( vec2(), 'vUv' ), uv() );
75
+
76
+ const instanceStart = attribute( 'instanceStart' );
77
+ const instanceEnd = attribute( 'instanceEnd' );
78
+
79
+ // camera space
80
+
81
+ const start = property( 'vec4', 'start' );
82
+ const end = property( 'vec4', 'end' );
83
+
84
+ stack.assign( start, modelViewMatrix.mul( vec4( instanceStart, 1.0 ) ) ); // force assignment into correct place in flow
85
+ stack.assign( end, modelViewMatrix.mul( vec4( instanceEnd, 1.0 ) ) );
86
+
87
+
88
+ if ( useWorldUnits ) {
89
+
90
+ stack.assign( varying( vec3(), 'worldStart' ), start.xyz );
91
+ stack.assign( varying( vec3(), 'worldEnd' ), end.xyz );
92
+
93
+ }
94
+
95
+ const aspect = viewport.z.div( viewport.w );
96
+
97
+ // special case for perspective projection, and segments that terminate either in, or behind, the camera plane
98
+ // clearly the gpu firmware has a way of addressing this issue when projecting into ndc space
99
+ // but we need to perform ndc-space calculations in the shader, so we must address this issue directly
100
+ // perhaps there is a more elegant solution -- WestLangley
101
+
102
+ const perspective = cameraProjectionMatrix.element( 2 ).element( 3 ).equal( -1.0 ); // 4th entry in the 3rd column
103
+
104
+ stack.if( perspective, ( stack ) => {
105
+
106
+ stack.if( start.z.lessThan( 0.0 ).and( end.z.greaterThan( 0.0 ) ), ( stack ) => {
107
+
108
+ stack.assign( end, trimSegment( { start: start, end: end } ) );
109
+
110
+ } ).elseif( end.z.lessThan( 0.0 ).and( start.z.greaterThanEqual( 0.0 ) ), ( stack ) => {
111
+
112
+ stack.assign( start, trimSegment( { start: end, end: start } ) );
113
+
114
+ } );
115
+
116
+ } );
117
+
118
+ // clip space
119
+ const clipStart = cameraProjectionMatrix.mul( start );
120
+ const clipEnd = cameraProjectionMatrix.mul( end );
121
+
122
+ // ndc space
123
+ const ndcStart = clipStart.xyz.div( clipStart.w );
124
+ const ndcEnd = clipEnd.xyz.div( clipEnd.w );
125
+
126
+ // direction
127
+ const dir = ndcEnd.xy.sub( ndcStart.xy );
128
+
129
+ // account for clip-space aspect ratio
130
+ stack.assign( dir.x, dir.x.mul( aspect ) );
131
+ stack.assign( dir, dir.normalize() );
132
+
133
+ const clip = temp( vec4() );
134
+
135
+ if ( useWorldUnits ) {
136
+
137
+ // get the offset direction as perpendicular to the view vector
138
+ const worldDir = end.xyz.sub( start.xyz ).normalize();
139
+
140
+ const offset = positionGeometry.y.lessThan( 0.5 ).cond(
141
+ start.xyz.cross( worldDir ).normalize(),
142
+ end.xyz.cross( worldDir ).normalize()
143
+
144
+ );
145
+
146
+ // sign flip
147
+ stack.assign( offset, positionGeometry.x.lessThan( 0.0 ).cond( offset.negate(), offset ) );
148
+
149
+ const forwardOffset = worldDir.dot( vec3( 0.0, 0.0, 1.0 ) );
150
+
151
+ // don't extend the line if we're rendering dashes because we
152
+ // won't be rendering the endcaps
153
+ if ( ! useDash ) {
154
+
155
+ // extend the line bounds to encompass endcaps
156
+ stack.assign( start, start.sub( vec4( worldDir.mul( materialLineWidth ).mul( 0.5 ), 0 ) ) );
157
+ stack.assign( end, end.add( vec4( worldDir.mul( materialLineWidth ).mul( 0.5 ), 0 ) ) );
158
+
159
+ // shift the position of the quad so it hugs the forward edge of the line
160
+ stack.assign( offset, offset.sub( vec3( dir.mul( forwardOffset ), 0 ) ) );
161
+ stack.assign( offset.z, offset.z.add( 0.5 ) );
162
+
163
+ }
164
+
165
+ // endcaps
166
+
167
+ stack.if( positionGeometry.y.greaterThan( 1.0 ).or( positionGeometry.y.lessThan( 0.0 ) ), ( stack ) => {
168
+
169
+ stack.assign( offset, offset.add( vec3( dir.mul( 2.0 ).mul( forwardOffset ), 0 ) ) );
170
+
171
+ } );
172
+
173
+ // adjust for linewidth
174
+ stack.assign( offset, offset.mul( materialLineWidth ).mul( 0.5 ) );
175
+
176
+ // set the world position
177
+
178
+ const worldPos = varying( vec4(), 'worldPos' );
179
+
180
+ stack.assign( worldPos, positionGeometry.y.lessThan( 0.5 ).cond( start, end ) );
181
+ stack.assign( worldPos, worldPos.add( vec4( offset, 0 ) ) );
182
+
183
+ // project the worldpos
184
+ stack.assign( clip, cameraProjectionMatrix.mul( worldPos ) );
185
+
186
+ // shift the depth of the projected points so the line
187
+ // segments overlap neatly
188
+ const clipPose = temp( vec3() );
189
+
190
+ stack.assign( clipPose, positionGeometry.y.lessThan( 0.5 ).cond( ndcStart, ndcEnd ) );
191
+ stack.assign( clip.z, clipPose.z.mul( clip.w ) );
192
+
193
+ } else {
194
+
195
+ const offset = property( 'vec2', 'offset' );
196
+
197
+ stack.assign( offset, vec2( dir.y, dir.x.negate() ) );
198
+
199
+ // undo aspect ratio adjustment
200
+ stack.assign( dir.x, dir.x.div( aspect ) );
201
+ stack.assign( offset.x, offset.x.div( aspect ) );
202
+
203
+ // sign flip
204
+ stack.assign( offset, positionGeometry.x.lessThan( 0.0 ).cond( offset.negate(), offset ) );
205
+
206
+ // endcaps
207
+ stack.if( positionGeometry.y.lessThan( 0.0 ), ( stack ) => {
208
+
209
+ stack.assign( offset, offset.sub( dir ) );
210
+
211
+ } ).elseif( positionGeometry.y.greaterThan( 1.0 ), ( stack ) => {
212
+
213
+ stack.assign( offset, offset.add( dir ) );
214
+
215
+ } );
216
+
217
+ // adjust for linewidth
218
+ stack.assign( offset, offset.mul( materialLineWidth ) );
219
+
220
+ // adjust for clip-space to screen-space conversion // maybe resolution should be based on viewport ...
221
+ stack.assign( offset, offset.div( viewport.w ) );
222
+
223
+ // select end
224
+ stack.assign( clip, positionGeometry.y.lessThan( 0.5 ).cond( clipStart, clipEnd ) );
225
+
226
+ // back to clip space
227
+ stack.assign( offset, offset.mul( clip.w ) );
228
+
229
+ stack.assign( clip, clip.add( vec4( offset, 0, 0 ) ) );
230
+
231
+ }
232
+
233
+ return clip;
234
+
235
+ } );
236
+
237
+ const closestLineToLine = tslFn( ( { p1, p2, p3, p4 } ) => {
238
+
239
+ const p13 = p1.sub( p3 );
240
+ const p43 = p4.sub( p3 );
241
+
242
+ const p21 = p2.sub( p1 );
243
+
244
+ const d1343 = dot( p13, p43 );
245
+ const d4321 = dot( p43, p21 );
246
+ const d1321 = dot( p13, p21 );
247
+ const d4343 = dot( p43, p43 );
248
+ const d2121 = dot( p21, p21 );
249
+
250
+ const denom = d2121.mul( d4343 ).sub( d4321.mul( d4321 ) );
251
+ const numer = d1343.mul( d4321 ).sub( d1321.mul( d4343 ) );
252
+
253
+ const mua = clamp( numer.div( denom ), 0, 1 );
254
+ const mub = clamp( d1343.add( d4321.mul( mua ) ).div( d4343 ), 0, 1 );
255
+
256
+ return vec2( mua, mub );
257
+
258
+ } );
259
+
260
+ this.colorNode = new ShaderNode( ( stack ) => {
261
+
262
+ const vUv = varying( vec2(), 'vUv' );
263
+
264
+ if ( useDash ) {
265
+
266
+ const offsetNode = this.offsetNode ? float( this.offsetNodeNode ) : materialLineDashOffset;
267
+ const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale;
268
+ const dashSizeNode = this.dashSizeNode ? float( this.dashSizeNode ) : materialLineDashSize;
269
+ const gapSizeNode = this.dashSizeNode ? float( this.dashGapNode ) : materialLineGapSize;
270
+
271
+ stack.assign( dashSize, dashSizeNode );
272
+ stack.assign( gapSize, gapSizeNode );
273
+
274
+ const instanceDistanceStart = attribute( 'instanceDistanceStart' );
275
+ const instanceDistanceEnd = attribute( 'instanceDistanceEnd' );
276
+
277
+ const lineDistance = positionGeometry.y.lessThan( 0.5 ).cond( dashScaleNode.mul( instanceDistanceStart ), materialLineScale.mul( instanceDistanceEnd ) );
278
+
279
+ const vLineDistance = varying( lineDistance.add( materialLineDashOffset ) );
280
+ const vLineDistanceOffset = offsetNode ? vLineDistance.add( offsetNode ) : vLineDistance;
281
+
282
+ stack.add( vUv.y.lessThan( - 1.0 ).or( vUv.y.greaterThan( 1.0 ) ).discard() ); // discard endcaps
283
+ stack.add( mod( vLineDistanceOffset, dashSize.add( gapSize ) ).greaterThan( dashSize ).discard() ); // todo - FIX
284
+
285
+ }
286
+
287
+ // force assignment into correct place in flow
288
+ const alpha = property( 'float', 'alpha' );
289
+ stack.assign( alpha, 1 );
290
+
291
+ if ( useWorldUnits ) {
292
+
293
+
294
+ let worldStart = varying( vec3(), 'worldStart' );
295
+ let worldEnd = varying( vec3(), 'worldEnd' );
296
+
297
+ // Find the closest points on the view ray and the line segment
298
+ const rayEnd = varying( vec4(), 'worldPos' ).xyz.normalize().mul( 1e5 );
299
+ const lineDir = worldEnd.sub( worldStart );
300
+ const params = closestLineToLine( { p1: worldStart, p2: worldEnd, p3: vec3( 0.0, 0.0, 0.0 ), p4: rayEnd } );
301
+
302
+ const p1 = worldStart.add( lineDir.mul( params.x ) );
303
+ const p2 = rayEnd.mul( params.y );
304
+ const delta = p1.sub( p2 );
305
+ const len = delta.length();
306
+ const norm = len.div( materialLineWidth );
307
+
308
+ if ( ! useDash ) {
309
+
310
+ if ( useAlphaToCoverage ) {
311
+
312
+ const dnorm = norm.fwidth();
313
+ stack.assign( alpha, smoothstep( dnorm.negate().add( 0.5 ), dnorm.add( 0.5 ), norm ).oneMinus() );
314
+
315
+ } else {
316
+
317
+ stack.add( norm.greaterThan( 0.5 ).discard() );
318
+
319
+ }
320
+
321
+ }
322
+
323
+ } else {
324
+
325
+ // round endcaps
326
+
327
+ if ( useAlphaToCoverage ) {
328
+
329
+ const a = vUv.x;
330
+ const b = vUv.y.greaterThan( 0.0 ).cond( vUv.y.sub( 1.0 ), vUv.y.add( 1.0 ) );
331
+
332
+ const len2 = a.mul( a ).add( b.mul( b ) );
333
+
334
+ // force assignment out of following 'if' statement - to avoid uniform control flow errors
335
+ const dlen = property( 'float', 'dlen' );
336
+ stack.assign( dlen, len2.fwidth() );
337
+
338
+ stack.if( abs( vUv.y ).greaterThan( 1.0 ), ( stack ) => {
339
+
340
+ stack.assign( alpha, smoothstep( dlen.oneMinus(), dlen.add( 1 ), len2 ).oneMinus() );
341
+
342
+ } );
343
+
344
+ } else {
345
+
346
+ stack.if( abs( vUv.y ).greaterThan( 1.0 ), ( stack ) => {
347
+
348
+ const a = vUv.x;
349
+ const b = vUv.y.greaterThan( 0.0 ).cond( vUv.y.sub( 1.0 ), vUv.y.add( 1.0 ) );
350
+ const len2 = a.mul( a ).add( b.mul( b ) );
351
+
352
+ stack.add( len2.greaterThan( 1.0 ).discard() );
353
+
354
+ } );
355
+
356
+ }
357
+
358
+ }
359
+
360
+ let lineColorNode;
361
+
362
+ if ( this.lineColorNode ) {
363
+
364
+ lineColorNode = this.lineColorNode;
365
+
366
+ } else {
367
+
368
+ if ( useColor ) {
369
+
370
+ const instanceColorStart = attribute( 'instanceColorStart' );
371
+ const instanceColorEnd = attribute( 'instanceColorEnd' );
372
+
373
+ lineColorNode = varying( positionGeometry.y.lessThan( 0.5 ).cond( instanceColorStart, instanceColorEnd ) );
374
+
375
+ } else {
376
+
377
+ lineColorNode = materialColor;
378
+
379
+ }
380
+
381
+ }
382
+
383
+ return vec4( lineColorNode, alpha );
384
+
385
+ } );
386
+
387
+ this.needsUpdate = true;
388
+
389
+ }
390
+
391
+
392
+ get worldUnits() {
393
+
394
+ return this.useWorldUnits;
395
+
396
+ }
397
+
398
+ set worldUnits( value ) {
399
+
400
+ if ( this.useWorldUnits !== value ) {
401
+
402
+ this.useWorldUnits = value;
403
+ this.setupShaders();
404
+
405
+ }
406
+
407
+ }
408
+
409
+
410
+ get dashed() {
411
+
412
+ return this.useDash;
413
+
414
+ }
415
+
416
+ set dashed( value ) {
417
+
418
+ if ( this.useDash !== value ) {
419
+
420
+ this.useDash = value;
421
+ this.setupShaders();
422
+
423
+ }
424
+
425
+ }
426
+
427
+
428
+ get alphaToCoverage() {
429
+
430
+ return this.useAlphaToCoverage;
431
+
432
+ }
433
+
434
+ set alphaToCoverage( value ) {
435
+
436
+ if ( this.useAlphaToCoverage !== value ) {
437
+
438
+ this.useAlphaToCoverage = value;
439
+ this.setupShaders();
440
+
441
+ }
442
+
443
+ }
444
+
445
+ }
446
+
447
+ export default Line2NodeMaterial;
448
+
449
+ addNodeMaterial( 'Line2NodeMaterial', Line2NodeMaterial );
@@ -25,4 +25,4 @@ class LineBasicNodeMaterial extends NodeMaterial {
25
25
 
26
26
  export default LineBasicNodeMaterial;
27
27
 
28
- addNodeMaterial( LineBasicNodeMaterial );
28
+ addNodeMaterial( 'LineBasicNodeMaterial', LineBasicNodeMaterial );
@@ -30,7 +30,7 @@ class LineDashedNodeMaterial extends NodeMaterial {
30
30
 
31
31
  }
32
32
 
33
- constructVariants( { stack } ) {
33
+ setupVariants( { stack } ) {
34
34
 
35
35
  const offsetNode = this.offsetNode;
36
36
  const dashScaleNode = this.dashScaleNode ? float( this.dashScaleNode ) : materialLineScale;
@@ -51,4 +51,4 @@ class LineDashedNodeMaterial extends NodeMaterial {
51
51
 
52
52
  export default LineDashedNodeMaterial;
53
53
 
54
- addNodeMaterial( LineDashedNodeMaterial );
54
+ addNodeMaterial( 'LineDashedNodeMaterial', LineDashedNodeMaterial );
@@ -3,6 +3,7 @@
3
3
  export { default as NodeMaterial, addNodeMaterial, createNodeMaterialFromType } from './NodeMaterial.js';
4
4
  export { default as LineBasicNodeMaterial } from './LineBasicNodeMaterial.js';
5
5
  export { default as LineDashedNodeMaterial } from './LineDashedNodeMaterial.js';
6
+ export { default as Line2NodeMaterial } from './Line2NodeMaterial.js';
6
7
  export { default as MeshNormalNodeMaterial } from './MeshNormalNodeMaterial.js';
7
8
  export { default as MeshBasicNodeMaterial } from './MeshBasicNodeMaterial.js';
8
9
  export { default as MeshLambertNodeMaterial } from './MeshLambertNodeMaterial.js';
@@ -24,4 +24,4 @@ class MeshBasicNodeMaterial extends NodeMaterial {
24
24
 
25
25
  export default MeshBasicNodeMaterial;
26
26
 
27
- addNodeMaterial( MeshBasicNodeMaterial );
27
+ addNodeMaterial( 'MeshBasicNodeMaterial', MeshBasicNodeMaterial );
@@ -21,7 +21,7 @@ class MeshLambertNodeMaterial extends NodeMaterial {
21
21
 
22
22
  }
23
23
 
24
- constructLightingModel( /*builder*/ ) {
24
+ setupLightingModel( /*builder*/ ) {
25
25
 
26
26
  return new PhongLightingModel( false ); // ( specular ) -> force lambert
27
27
 
@@ -31,4 +31,4 @@ class MeshLambertNodeMaterial extends NodeMaterial {
31
31
 
32
32
  export default MeshLambertNodeMaterial;
33
33
 
34
- addNodeMaterial( MeshLambertNodeMaterial );
34
+ addNodeMaterial( 'MeshLambertNodeMaterial', MeshLambertNodeMaterial );
@@ -25,7 +25,7 @@ class MeshNormalNodeMaterial extends NodeMaterial {
25
25
 
26
26
  }
27
27
 
28
- constructDiffuseColor( { stack } ) {
28
+ setupDiffuseColor( { stack } ) {
29
29
 
30
30
  const opacityNode = this.opacityNode ? float( this.opacityNode ) : materialOpacity;
31
31
 
@@ -37,4 +37,4 @@ class MeshNormalNodeMaterial extends NodeMaterial {
37
37
 
38
38
  export default MeshNormalNodeMaterial;
39
39
 
40
- addNodeMaterial( MeshNormalNodeMaterial );
40
+ addNodeMaterial( 'MeshNormalNodeMaterial', MeshNormalNodeMaterial );
@@ -27,13 +27,13 @@ class MeshPhongNodeMaterial extends NodeMaterial {
27
27
 
28
28
  }
29
29
 
30
- constructLightingModel( /*builder*/ ) {
30
+ setupLightingModel( /*builder*/ ) {
31
31
 
32
32
  return new PhongLightingModel();
33
33
 
34
34
  }
35
35
 
36
- constructVariants( { stack } ) {
36
+ setupVariants( { stack } ) {
37
37
 
38
38
  // SHININESS
39
39
 
@@ -62,4 +62,4 @@ class MeshPhongNodeMaterial extends NodeMaterial {
62
62
 
63
63
  export default MeshPhongNodeMaterial;
64
64
 
65
- addNodeMaterial( MeshPhongNodeMaterial );
65
+ addNodeMaterial( 'MeshPhongNodeMaterial', MeshPhongNodeMaterial );
@@ -44,15 +44,15 @@ class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial {
44
44
 
45
45
  }
46
46
 
47
- constructLightingModel( /*builder*/ ) {
47
+ setupLightingModel( /*builder*/ ) {
48
48
 
49
49
  return new PhysicalLightingModel(); // @TODO: Optimize shader using parameters.
50
50
 
51
51
  }
52
52
 
53
- constructVariants( builder ) {
53
+ setupVariants( builder ) {
54
54
 
55
- super.constructVariants( builder );
55
+ super.setupVariants( builder );
56
56
 
57
57
  const { stack } = builder;
58
58
 
@@ -84,9 +84,9 @@ class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial {
84
84
 
85
85
  }
86
86
 
87
- constructNormal( builder ) {
87
+ setupNormal( builder ) {
88
88
 
89
- super.constructNormal( builder );
89
+ super.setupNormal( builder );
90
90
 
91
91
  // CLEARCOAT NORMAL
92
92
 
@@ -125,4 +125,4 @@ class MeshPhysicalNodeMaterial extends MeshStandardNodeMaterial {
125
125
 
126
126
  export default MeshPhysicalNodeMaterial;
127
127
 
128
- addNodeMaterial( MeshPhysicalNodeMaterial );
128
+ addNodeMaterial( 'MeshPhysicalNodeMaterial', MeshPhysicalNodeMaterial );
@@ -29,13 +29,13 @@ class MeshStandardNodeMaterial extends NodeMaterial {
29
29
 
30
30
  }
31
31
 
32
- constructLightingModel( /*builder*/ ) {
32
+ setupLightingModel( /*builder*/ ) {
33
33
 
34
34
  return new PhysicalLightingModel( false, false ); // ( clearcoat, sheen ) -> standard
35
35
 
36
36
  }
37
37
 
38
- constructVariants( { stack } ) {
38
+ setupVariants( { stack } ) {
39
39
 
40
40
  // METALNESS
41
41
 
@@ -77,4 +77,4 @@ class MeshStandardNodeMaterial extends NodeMaterial {
77
77
 
78
78
  export default MeshStandardNodeMaterial;
79
79
 
80
- addNodeMaterial( MeshStandardNodeMaterial );
80
+ addNodeMaterial( 'MeshStandardNodeMaterial', MeshStandardNodeMaterial );