super-three 0.157.1 → 0.158.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.
Files changed (178) hide show
  1. package/README.md +6 -4
  2. package/build/three.cjs +1013 -790
  3. package/build/three.js +1013 -790
  4. package/build/three.min.js +1 -1
  5. package/build/three.module.js +1008 -791
  6. package/build/three.module.min.js +1 -1
  7. package/examples/jsm/Addons.js +290 -0
  8. package/examples/jsm/controls/FlyControls.js +26 -0
  9. package/examples/jsm/controls/OrbitControls.js +12 -1
  10. package/examples/jsm/controls/TransformControls.js +27 -11
  11. package/examples/jsm/csm/CSMShader.js +1 -1
  12. package/examples/jsm/exporters/GLTFExporter.js +72 -2
  13. package/examples/jsm/geometries/InstancedPointsGeometry.js +174 -0
  14. package/examples/jsm/geometries/SDFGeometryGenerator.js +144 -0
  15. package/examples/jsm/libs/lottie_canvas.module.js +6 -1
  16. package/examples/jsm/libs/opentype.module.js +13 -75
  17. package/examples/jsm/libs/surfaceNet.js +201 -0
  18. package/examples/jsm/loaders/GLTFLoader.js +12 -3
  19. package/examples/jsm/loaders/LUTImageLoader.js +162 -0
  20. package/examples/jsm/loaders/lwo/IFFParser.js +89 -93
  21. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  22. package/examples/jsm/math/Capsule.js +0 -55
  23. package/examples/jsm/math/Octree.js +70 -3
  24. package/examples/jsm/modifiers/SimplifyModifier.js +103 -11
  25. package/examples/jsm/modifiers/TessellateModifier.js +3 -3
  26. package/examples/jsm/nodes/Nodes.js +6 -6
  27. package/examples/jsm/nodes/accessors/CubeTextureNode.js +3 -3
  28. package/examples/jsm/nodes/accessors/InstanceNode.js +3 -3
  29. package/examples/jsm/nodes/accessors/InstancedPointsMaterialNode.js +21 -0
  30. package/examples/jsm/nodes/accessors/MaterialNode.js +68 -31
  31. package/examples/jsm/nodes/accessors/ModelNode.js +1 -2
  32. package/examples/jsm/nodes/accessors/MorphNode.js +5 -5
  33. package/examples/jsm/nodes/accessors/NormalNode.js +1 -1
  34. package/examples/jsm/nodes/accessors/PositionNode.js +1 -1
  35. package/examples/jsm/nodes/accessors/SkinningNode.js +13 -3
  36. package/examples/jsm/nodes/accessors/TextureNode.js +3 -3
  37. package/examples/jsm/nodes/code/FunctionNode.js +1 -1
  38. package/examples/jsm/nodes/core/AssignNode.js +72 -0
  39. package/examples/jsm/nodes/core/LightingModel.js +3 -1
  40. package/examples/jsm/nodes/core/Node.js +7 -12
  41. package/examples/jsm/nodes/core/NodeBuilder.js +126 -16
  42. package/examples/jsm/nodes/core/NodeUtils.js +4 -2
  43. package/examples/jsm/nodes/core/OutputStructNode.js +1 -1
  44. package/examples/jsm/nodes/core/ParameterNode.js +33 -0
  45. package/examples/jsm/nodes/core/PropertyNode.js +4 -10
  46. package/examples/jsm/nodes/core/StackNode.js +7 -17
  47. package/examples/jsm/nodes/core/TempNode.js +1 -1
  48. package/examples/jsm/nodes/core/VarNode.js +6 -35
  49. package/examples/jsm/nodes/core/VaryingNode.js +2 -0
  50. package/examples/jsm/nodes/display/BumpMapNode.js +35 -13
  51. package/examples/jsm/nodes/display/NormalMapNode.js +3 -1
  52. package/examples/jsm/nodes/display/ViewportNode.js +14 -4
  53. package/examples/jsm/nodes/functions/BSDF/BRDF_Sheen.js +20 -6
  54. package/examples/jsm/nodes/functions/BSDF/DFGApprox.js +8 -7
  55. package/examples/jsm/nodes/functions/BSDF/D_GGX.js +8 -3
  56. package/examples/jsm/nodes/functions/BSDF/Schlick_to_F0.js +8 -0
  57. package/examples/jsm/nodes/functions/BSDF/V_GGX_SmithCorrelated.js +8 -0
  58. package/examples/jsm/nodes/functions/PhysicalLightingModel.js +93 -43
  59. package/examples/jsm/nodes/gpgpu/ComputeNode.js +2 -2
  60. package/examples/jsm/nodes/lighting/AmbientLightNode.js +1 -1
  61. package/examples/jsm/nodes/lighting/AnalyticLightNode.js +19 -5
  62. package/examples/jsm/nodes/lighting/DirectionalLightNode.js +1 -1
  63. package/examples/jsm/nodes/lighting/EnvironmentNode.js +0 -6
  64. package/examples/jsm/nodes/lighting/LightingContextNode.js +21 -57
  65. package/examples/jsm/nodes/lighting/LightsNode.js +62 -4
  66. package/examples/jsm/nodes/lighting/PointLightNode.js +1 -1
  67. package/examples/jsm/nodes/lighting/SpotLightNode.js +1 -1
  68. package/examples/jsm/nodes/materials/InstancedPointsNodeMaterial.js +162 -0
  69. package/examples/jsm/nodes/materials/Line2NodeMaterial.js +70 -71
  70. package/examples/jsm/nodes/materials/LineDashedNodeMaterial.js +5 -5
  71. package/examples/jsm/nodes/materials/Materials.js +1 -0
  72. package/examples/jsm/nodes/materials/MeshNormalNodeMaterial.js +2 -2
  73. package/examples/jsm/nodes/materials/MeshPhongNodeMaterial.js +3 -3
  74. package/examples/jsm/nodes/materials/MeshPhysicalNodeMaterial.js +47 -20
  75. package/examples/jsm/nodes/materials/MeshStandardNodeMaterial.js +6 -6
  76. package/examples/jsm/nodes/materials/NodeMaterial.js +17 -20
  77. package/examples/jsm/nodes/materialx/lib/mx_noise.js +5 -5
  78. package/examples/jsm/nodes/math/OperatorNode.js +5 -21
  79. package/examples/jsm/nodes/shadernode/ShaderNode.js +128 -9
  80. package/examples/jsm/nodes/utils/ArrayElementNode.js +2 -0
  81. package/examples/jsm/nodes/utils/DiscardNode.js +3 -2
  82. package/examples/jsm/nodes/utils/JoinNode.js +11 -1
  83. package/examples/jsm/nodes/utils/LoopNode.js +36 -24
  84. package/examples/jsm/nodes/utils/SplitNode.js +2 -0
  85. package/examples/jsm/objects/BatchedMesh.js +586 -0
  86. package/examples/jsm/objects/InstancedPoints.js +21 -0
  87. package/examples/jsm/objects/Lensflare.js +20 -0
  88. package/examples/jsm/objects/ReflectorForSSRPass.js +3 -0
  89. package/examples/jsm/objects/Refractor.js +3 -0
  90. package/examples/jsm/objects/Sky.js +5 -3
  91. package/examples/jsm/objects/Water.js +5 -2
  92. package/examples/jsm/objects/Water2.js +3 -0
  93. package/examples/jsm/physics/AmmoPhysics.js +21 -0
  94. package/examples/jsm/physics/RapierPhysics.js +21 -0
  95. package/examples/jsm/postprocessing/BokehPass.js +3 -2
  96. package/examples/jsm/postprocessing/LUTPass.js +2 -1
  97. package/examples/jsm/postprocessing/OutputPass.js +1 -0
  98. package/examples/jsm/postprocessing/Pass.js +14 -3
  99. package/examples/jsm/postprocessing/SAOPass.js +0 -1
  100. package/examples/jsm/postprocessing/SMAAPass.js +0 -2
  101. package/examples/jsm/postprocessing/TAARenderPass.js +1 -2
  102. package/examples/jsm/renderers/CSS3DRenderer.js +3 -9
  103. package/examples/jsm/renderers/SVGRenderer.js +9 -6
  104. package/examples/jsm/renderers/common/Bindings.js +1 -1
  105. package/examples/jsm/renderers/common/RenderObject.js +8 -1
  106. package/examples/jsm/renderers/common/RenderObjects.js +1 -1
  107. package/examples/jsm/renderers/common/Textures.js +4 -36
  108. package/examples/jsm/renderers/common/nodes/Nodes.js +53 -18
  109. package/examples/jsm/renderers/webgl/WebGLBackend.js +291 -50
  110. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +88 -12
  111. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +40 -5
  112. package/examples/jsm/renderers/webgl/utils/WebGLState.js +14 -2
  113. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +2 -0
  114. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +36 -4
  115. package/examples/jsm/shaders/ACESFilmicToneMappingShader.js +2 -0
  116. package/examples/jsm/shaders/AfterimageShader.js +2 -0
  117. package/examples/jsm/shaders/BasicShader.js +2 -0
  118. package/examples/jsm/shaders/BlendShader.js +2 -0
  119. package/examples/jsm/shaders/BokehShader.js +2 -0
  120. package/examples/jsm/shaders/BokehShader2.js +4 -0
  121. package/examples/jsm/shaders/BrightnessContrastShader.js +2 -0
  122. package/examples/jsm/shaders/ColorCorrectionShader.js +2 -0
  123. package/examples/jsm/shaders/DOFMipMapShader.js +2 -0
  124. package/examples/jsm/shaders/DepthLimitedBlurShader.js +5 -0
  125. package/examples/jsm/shaders/FXAAShader.js +2 -0
  126. package/examples/jsm/shaders/FilmShader.js +1 -1
  127. package/examples/jsm/shaders/FocusShader.js +2 -0
  128. package/examples/jsm/shaders/FreiChenShader.js +2 -0
  129. package/examples/jsm/shaders/GodRaysShader.js +8 -0
  130. package/examples/jsm/shaders/HalftoneShader.js +2 -0
  131. package/examples/jsm/shaders/HorizontalTiltShiftShader.js +2 -0
  132. package/examples/jsm/shaders/HueSaturationShader.js +2 -0
  133. package/examples/jsm/shaders/KaleidoShader.js +2 -0
  134. package/examples/jsm/shaders/LuminosityHighPassShader.js +2 -0
  135. package/examples/jsm/shaders/LuminosityShader.js +2 -0
  136. package/examples/jsm/shaders/MMDToonShader.js +2 -0
  137. package/examples/jsm/shaders/MirrorShader.js +2 -0
  138. package/examples/jsm/shaders/NormalMapShader.js +2 -0
  139. package/examples/jsm/shaders/OutputShader.js +4 -5
  140. package/examples/jsm/shaders/SAOShader.js +5 -0
  141. package/examples/jsm/shaders/SMAAShader.js +6 -0
  142. package/examples/jsm/shaders/SSAOShader.js +6 -0
  143. package/examples/jsm/shaders/SSRShader.js +6 -0
  144. package/examples/jsm/shaders/SobelOperatorShader.js +2 -0
  145. package/examples/jsm/shaders/SubsurfaceScatteringShader.js +2 -0
  146. package/examples/jsm/shaders/TechnicolorShader.js +2 -0
  147. package/examples/jsm/shaders/TriangleBlurShader.js +2 -0
  148. package/examples/jsm/shaders/UnpackDepthRGBAShader.js +2 -0
  149. package/examples/jsm/shaders/VelocityShader.js +2 -0
  150. package/examples/jsm/shaders/VerticalTiltShiftShader.js +2 -0
  151. package/examples/jsm/shaders/WaterRefractionShader.js +2 -0
  152. package/examples/jsm/transpiler/AST.js +231 -0
  153. package/examples/jsm/transpiler/GLSLDecoder.js +899 -0
  154. package/examples/jsm/transpiler/ShaderToyDecoder.js +49 -0
  155. package/examples/jsm/transpiler/TSLEncoder.js +611 -0
  156. package/examples/jsm/transpiler/Transpiler.js +18 -0
  157. package/examples/jsm/webxr/VRButton.js +1 -1
  158. package/examples/jsm/webxr/XRButton.js +7 -5
  159. package/examples/jsm/webxr/XREstimatedLight.js +1 -1
  160. package/package.json +4 -1
  161. package/src/constants.js +7 -1
  162. package/src/extras/PMREMGenerator.js +7 -1
  163. package/src/loaders/MaterialLoader.js +10 -2
  164. package/src/materials/Material.js +27 -13
  165. package/src/math/Box3.js +35 -18
  166. package/src/math/Vector3.js +11 -12
  167. package/src/objects/SkinnedMesh.js +6 -7
  168. package/src/renderers/WebGLRenderer.js +142 -25
  169. package/src/renderers/shaders/ShaderChunk/aomap_fragment.glsl.js +8 -0
  170. package/src/renderers/shaders/ShaderChunk/bumpmap_pars_fragment.glsl.js +3 -2
  171. package/src/renderers/shaders/ShaderChunk/lights_fragment_begin.glsl.js +1 -1
  172. package/src/renderers/shaders/ShaderChunk/lights_physical_pars_fragment.glsl.js +8 -6
  173. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +2 -2
  174. package/src/renderers/webgl/WebGLProgram.js +80 -50
  175. package/src/renderers/webgl/WebGLPrograms.js +3 -0
  176. package/src/renderers/webgl/WebGLState.js +25 -4
  177. package/examples/jsm/nodes/accessors/ExtendedMaterialNode.js +0 -76
  178. package/examples/jsm/nodes/accessors/LineMaterialNode.js +0 -29
@@ -147,7 +147,7 @@ export class XREstimatedLight extends Group {
147
147
  this.directionalLight.intensity = 0;
148
148
  this.add( this.directionalLight );
149
149
 
150
- // Will be set to a cube map in the SessionLightProbe is environment estimation is
150
+ // Will be set to a cube map in the SessionLightProbe if environment estimation is
151
151
  // available and requested.
152
152
  this.environment = null;
153
153
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "super-three",
3
- "version": "0.157.1",
3
+ "version": "0.158.0",
4
4
  "description": "JavaScript 3D library",
5
5
  "type": "module",
6
6
  "main": "./build/three.js",
@@ -12,6 +12,7 @@
12
12
  },
13
13
  "./examples/fonts/*": "./examples/fonts/*",
14
14
  "./examples/jsm/*": "./examples/jsm/*",
15
+ "./addons": "./examples/jsm/Addons.js",
15
16
  "./addons/*": "./examples/jsm/*",
16
17
  "./src/*": "./src/*",
17
18
  "./nodes": "./examples/jsm/nodes/Nodes.js"
@@ -59,6 +60,7 @@
59
60
  "test-e2e": "node test/e2e/puppeteer.js",
60
61
  "test-e2e-cov": "node test/e2e/check-coverage.js",
61
62
  "test-treeshake": "rollup -c test/rollup.treeshake.config.js",
63
+ "test-circular-deps": "dpdm --no-warning --no-tree --exit-code circular:1 examples/jsm/nodes/Nodes.js",
62
64
  "make-screenshot": "node test/e2e/puppeteer.js --make"
63
65
  },
64
66
  "keywords": [
@@ -89,6 +91,7 @@
89
91
  "@rollup/plugin-terser": "^0.4.0",
90
92
  "chalk": "^5.2.0",
91
93
  "concurrently": "^8.0.1",
94
+ "dpdm": "^3.14.0",
92
95
  "eslint": "^8.37.0",
93
96
  "eslint-config-mdcs": "^5.0.0",
94
97
  "eslint-plugin-compat": "^4.1.2",
package/src/constants.js CHANGED
@@ -1,4 +1,4 @@
1
- export const REVISION = '157';
1
+ export const REVISION = '158';
2
2
 
3
3
  export const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
4
4
  export const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
@@ -36,6 +36,10 @@ export const OneMinusDstAlphaFactor = 207;
36
36
  export const DstColorFactor = 208;
37
37
  export const OneMinusDstColorFactor = 209;
38
38
  export const SrcAlphaSaturateFactor = 210;
39
+ export const ConstantColorFactor = 211;
40
+ export const OneMinusConstantColorFactor = 212;
41
+ export const ConstantAlphaFactor = 213;
42
+ export const OneMinusConstantAlphaFactor = 214;
39
43
  export const NeverDepth = 0;
40
44
  export const AlwaysDepth = 1;
41
45
  export const LessDepth = 2;
@@ -53,6 +57,8 @@ export const ReinhardToneMapping = 2;
53
57
  export const CineonToneMapping = 3;
54
58
  export const ACESFilmicToneMapping = 4;
55
59
  export const CustomToneMapping = 5;
60
+ export const AttachedBindMode = 'attached';
61
+ export const DetachedBindMode = 'detached';
56
62
 
57
63
  export const UVMapping = 300;
58
64
  export const CubeReflectionMapping = 301;
@@ -38,6 +38,8 @@ const MAX_SAMPLES = 20;
38
38
  const _flatCamera = /*@__PURE__*/ new OrthographicCamera();
39
39
  const _clearColor = /*@__PURE__*/ new Color();
40
40
  let _oldTarget = null;
41
+ let _oldActiveCubeFace = 0;
42
+ let _oldActiveMipmapLevel = 0;
41
43
 
42
44
  // Golden Ratio
43
45
  const PHI = ( 1 + Math.sqrt( 5 ) ) / 2;
@@ -103,6 +105,8 @@ class PMREMGenerator {
103
105
  fromScene( scene, sigma = 0, near = 0.1, far = 100 ) {
104
106
 
105
107
  _oldTarget = this._renderer.getRenderTarget();
108
+ _oldActiveCubeFace = this._renderer.getActiveCubeFace();
109
+ _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
106
110
 
107
111
  this._setSize( 256 );
108
112
 
@@ -215,7 +219,7 @@ class PMREMGenerator {
215
219
 
216
220
  _cleanup( outputTarget ) {
217
221
 
218
- this._renderer.setRenderTarget( _oldTarget );
222
+ this._renderer.setRenderTarget( _oldTarget, _oldActiveCubeFace, _oldActiveMipmapLevel );
219
223
  outputTarget.scissorTest = false;
220
224
  _setViewport( outputTarget, 0, 0, outputTarget.width, outputTarget.height );
221
225
 
@@ -234,6 +238,8 @@ class PMREMGenerator {
234
238
  }
235
239
 
236
240
  _oldTarget = this._renderer.getRenderTarget();
241
+ _oldActiveCubeFace = this._renderer.getActiveCubeFace();
242
+ _oldActiveMipmapLevel = this._renderer.getActiveMipmapLevel();
237
243
 
238
244
  const cubeUVRenderTarget = renderTarget || this._allocateTargets();
239
245
  this._textureToCubeUV( texture, cubeUVRenderTarget );
@@ -122,11 +122,18 @@ class MaterialLoader extends Loader {
122
122
  if ( json.transparent !== undefined ) material.transparent = json.transparent;
123
123
  if ( json.alphaTest !== undefined ) material.alphaTest = json.alphaTest;
124
124
  if ( json.alphaHash !== undefined ) material.alphaHash = json.alphaHash;
125
+ if ( json.depthFunc !== undefined ) material.depthFunc = json.depthFunc;
125
126
  if ( json.depthTest !== undefined ) material.depthTest = json.depthTest;
126
127
  if ( json.depthWrite !== undefined ) material.depthWrite = json.depthWrite;
127
128
  if ( json.colorWrite !== undefined ) material.colorWrite = json.colorWrite;
128
-
129
- if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
129
+ if ( json.blendSrc !== undefined ) material.blendSrc = json.blendSrc;
130
+ if ( json.blendDst !== undefined ) material.blendDst = json.blendDst;
131
+ if ( json.blendEquation !== undefined ) material.blendEquation = json.blendEquation;
132
+ if ( json.blendSrcAlpha !== undefined ) material.blendSrcAlpha = json.blendSrcAlpha;
133
+ if ( json.blendDstAlpha !== undefined ) material.blendDstAlpha = json.blendDstAlpha;
134
+ if ( json.blendEquationAlpha !== undefined ) material.blendEquationAlpha = json.blendEquationAlpha;
135
+ if ( json.blendColor !== undefined && material.blendColor !== undefined ) material.blendColor.setHex( json.blendColor );
136
+ if ( json.blendAlpha !== undefined ) material.blendAlpha = json.blendAlpha;
130
137
  if ( json.stencilWriteMask !== undefined ) material.stencilWriteMask = json.stencilWriteMask;
131
138
  if ( json.stencilFunc !== undefined ) material.stencilFunc = json.stencilFunc;
132
139
  if ( json.stencilRef !== undefined ) material.stencilRef = json.stencilRef;
@@ -134,6 +141,7 @@ class MaterialLoader extends Loader {
134
141
  if ( json.stencilFail !== undefined ) material.stencilFail = json.stencilFail;
135
142
  if ( json.stencilZFail !== undefined ) material.stencilZFail = json.stencilZFail;
136
143
  if ( json.stencilZPass !== undefined ) material.stencilZPass = json.stencilZPass;
144
+ if ( json.stencilWrite !== undefined ) material.stencilWrite = json.stencilWrite;
137
145
 
138
146
  if ( json.wireframe !== undefined ) material.wireframe = json.wireframe;
139
147
  if ( json.wireframeLinewidth !== undefined ) material.wireframeLinewidth = json.wireframeLinewidth;
@@ -1,3 +1,4 @@
1
+ import { Color } from '../math/Color.js';
1
2
  import { EventDispatcher } from '../core/EventDispatcher.js';
2
3
  import { FrontSide, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp } from '../constants.js';
3
4
  import * as MathUtils from '../math/MathUtils.js';
@@ -33,6 +34,8 @@ class Material extends EventDispatcher {
33
34
  this.blendSrcAlpha = null;
34
35
  this.blendDstAlpha = null;
35
36
  this.blendEquationAlpha = null;
37
+ this.blendColor = new Color( 0, 0, 0 );
38
+ this.blendAlpha = 0;
36
39
 
37
40
  this.depthFunc = LessEqualDepth;
38
41
  this.depthTest = true;
@@ -325,19 +328,28 @@ class Material extends EventDispatcher {
325
328
  if ( this.opacity < 1 ) data.opacity = this.opacity;
326
329
  if ( this.transparent === true ) data.transparent = true;
327
330
 
328
- data.depthFunc = this.depthFunc;
329
- data.depthTest = this.depthTest;
330
- data.depthWrite = this.depthWrite;
331
- data.colorWrite = this.colorWrite;
332
-
333
- data.stencilWrite = this.stencilWrite;
334
- data.stencilWriteMask = this.stencilWriteMask;
335
- data.stencilFunc = this.stencilFunc;
336
- data.stencilRef = this.stencilRef;
337
- data.stencilFuncMask = this.stencilFuncMask;
338
- data.stencilFail = this.stencilFail;
339
- data.stencilZFail = this.stencilZFail;
340
- data.stencilZPass = this.stencilZPass;
331
+ if ( this.blendSrc !== SrcAlphaFactor ) data.blendSrc = this.blendSrc;
332
+ if ( this.blendDst !== OneMinusSrcAlphaFactor ) data.blendDst = this.blendDst;
333
+ if ( this.blendEquation !== AddEquation ) data.blendEquation = this.blendEquation;
334
+ if ( this.blendSrcAlpha !== null ) data.blendSrcAlpha = this.blendSrcAlpha;
335
+ if ( this.blendDstAlpha !== null ) data.blendDstAlpha = this.blendDstAlpha;
336
+ if ( this.blendEquationAlpha !== null ) data.blendEquationAlpha = this.blendEquationAlpha;
337
+ if ( this.blendColor && this.blendColor.isColor ) data.blendColor = this.blendColor.getHex();
338
+ if ( this.blendAlpha !== 0 ) data.blendAlpha = this.blendAlpha;
339
+
340
+ if ( this.depthFunc !== LessEqualDepth ) data.depthFunc = this.depthFunc;
341
+ if ( this.depthTest === false ) data.depthTest = this.depthTest;
342
+ if ( this.depthWrite === false ) data.depthWrite = this.depthWrite;
343
+ if ( this.colorWrite === false ) data.colorWrite = this.colorWrite;
344
+
345
+ if ( this.stencilWriteMask !== 0xff ) data.stencilWriteMask = this.stencilWriteMask;
346
+ if ( this.stencilFunc !== AlwaysStencilFunc ) data.stencilFunc = this.stencilFunc;
347
+ if ( this.stencilRef !== 0 ) data.stencilRef = this.stencilRef;
348
+ if ( this.stencilFuncMask !== 0xff ) data.stencilFuncMask = this.stencilFuncMask;
349
+ if ( this.stencilFail !== KeepStencilOp ) data.stencilFail = this.stencilFail;
350
+ if ( this.stencilZFail !== KeepStencilOp ) data.stencilZFail = this.stencilZFail;
351
+ if ( this.stencilZPass !== KeepStencilOp ) data.stencilZPass = this.stencilZPass;
352
+ if ( this.stencilWrite === true ) data.stencilWrite = this.stencilWrite;
341
353
 
342
354
  // rotation (SpriteMaterial)
343
355
  if ( this.rotation !== undefined && this.rotation !== 0 ) data.rotation = this.rotation;
@@ -429,6 +441,8 @@ class Material extends EventDispatcher {
429
441
  this.blendSrcAlpha = source.blendSrcAlpha;
430
442
  this.blendDstAlpha = source.blendDstAlpha;
431
443
  this.blendEquationAlpha = source.blendEquationAlpha;
444
+ this.blendColor.copy( source.blendColor );
445
+ this.blendAlpha = source.blendAlpha;
432
446
 
433
447
  this.depthFunc = source.depthFunc;
434
448
  this.depthTest = source.depthTest;
package/src/math/Box3.js CHANGED
@@ -159,37 +159,53 @@ class Box3 {
159
159
 
160
160
  object.updateWorldMatrix( false, false );
161
161
 
162
- if ( object.boundingBox !== undefined ) {
162
+ const geometry = object.geometry;
163
163
 
164
- if ( object.boundingBox === null ) {
164
+ if ( geometry !== undefined ) {
165
165
 
166
- object.computeBoundingBox();
166
+ const positionAttribute = geometry.getAttribute( 'position' );
167
167
 
168
- }
168
+ // precise AABB computation based on vertex data requires at least a position attribute.
169
+ // instancing isn't supported so far and uses the normal (conservative) code path.
169
170
 
170
- _box.copy( object.boundingBox );
171
- _box.applyMatrix4( object.matrixWorld );
171
+ if ( precise === true && positionAttribute !== undefined && object.isInstancedMesh !== true ) {
172
172
 
173
- this.union( _box );
173
+ for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
174
174
 
175
- } else {
175
+ if ( object.isMesh === true ) {
176
+
177
+ object.getVertexPosition( i, _vector );
178
+
179
+ } else {
180
+
181
+ _vector.fromBufferAttribute( positionAttribute, i );
182
+
183
+ }
184
+
185
+ _vector.applyMatrix4( object.matrixWorld );
186
+ this.expandByPoint( _vector );
176
187
 
177
- const geometry = object.geometry;
188
+ }
189
+
190
+ } else {
178
191
 
179
- if ( geometry !== undefined ) {
192
+ if ( object.boundingBox !== undefined ) {
180
193
 
181
- if ( precise && geometry.attributes !== undefined && geometry.attributes.position !== undefined ) {
194
+ // object-level bounding box
182
195
 
183
- const position = geometry.attributes.position;
184
- for ( let i = 0, l = position.count; i < l; i ++ ) {
196
+ if ( object.boundingBox === null ) {
185
197
 
186
- _vector.fromBufferAttribute( position, i ).applyMatrix4( object.matrixWorld );
187
- this.expandByPoint( _vector );
198
+ object.computeBoundingBox();
188
199
 
189
200
  }
190
201
 
202
+ _box.copy( object.boundingBox );
203
+
204
+
191
205
  } else {
192
206
 
207
+ // geometry-level bounding box
208
+
193
209
  if ( geometry.boundingBox === null ) {
194
210
 
195
211
  geometry.computeBoundingBox();
@@ -197,12 +213,13 @@ class Box3 {
197
213
  }
198
214
 
199
215
  _box.copy( geometry.boundingBox );
200
- _box.applyMatrix4( object.matrixWorld );
201
-
202
- this.union( _box );
203
216
 
204
217
  }
205
218
 
219
+ _box.applyMatrix4( object.matrixWorld );
220
+
221
+ this.union( _box );
222
+
206
223
  }
207
224
 
208
225
  }
@@ -251,21 +251,20 @@ class Vector3 {
251
251
 
252
252
  applyQuaternion( q ) {
253
253
 
254
- const x = this.x, y = this.y, z = this.z;
255
- const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
254
+ // quaternion q is assumed to have unit length
256
255
 
257
- // calculate quat * vector
258
-
259
- const ix = qw * x + qy * z - qz * y;
260
- const iy = qw * y + qz * x - qx * z;
261
- const iz = qw * z + qx * y - qy * x;
262
- const iw = - qx * x - qy * y - qz * z;
256
+ const vx = this.x, vy = this.y, vz = this.z;
257
+ const qx = q.x, qy = q.y, qz = q.z, qw = q.w;
263
258
 
264
- // calculate result * inverse quat
259
+ // t = 2 * cross( q.xyz, v );
260
+ const tx = 2 * ( qy * vz - qz * vy );
261
+ const ty = 2 * ( qz * vx - qx * vz );
262
+ const tz = 2 * ( qx * vy - qy * vx );
265
263
 
266
- this.x = ix * qw + iw * - qx + iy * - qz - iz * - qy;
267
- this.y = iy * qw + iw * - qy + iz * - qx - ix * - qz;
268
- this.z = iz * qw + iw * - qz + ix * - qy - iy * - qx;
264
+ // v + q.w * t + cross( q.xyz, t );
265
+ this.x = vx + qw * tx + qy * tz - qz * ty;
266
+ this.y = vy + qw * ty + qz * tx - qx * tz;
267
+ this.z = vz + qw * tz + qx * ty - qy * tx;
269
268
 
270
269
  return this;
271
270
 
@@ -5,6 +5,7 @@ import { Sphere } from '../math/Sphere.js';
5
5
  import { Vector3 } from '../math/Vector3.js';
6
6
  import { Vector4 } from '../math/Vector4.js';
7
7
  import { Ray } from '../math/Ray.js';
8
+ import { AttachedBindMode, DetachedBindMode } from '../constants.js';
8
9
 
9
10
  const _basePosition = /*@__PURE__*/ new Vector3();
10
11
 
@@ -29,7 +30,7 @@ class SkinnedMesh extends Mesh {
29
30
 
30
31
  this.type = 'SkinnedMesh';
31
32
 
32
- this.bindMode = 'attached';
33
+ this.bindMode = AttachedBindMode;
33
34
  this.bindMatrix = new Matrix4();
34
35
  this.bindMatrixInverse = new Matrix4();
35
36
 
@@ -54,8 +55,7 @@ class SkinnedMesh extends Mesh {
54
55
 
55
56
  for ( let i = 0; i < positionAttribute.count; i ++ ) {
56
57
 
57
- _vertex.fromBufferAttribute( positionAttribute, i );
58
- this.applyBoneTransform( i, _vertex );
58
+ this.getVertexPosition( i, _vertex );
59
59
  this.boundingBox.expandByPoint( _vertex );
60
60
 
61
61
  }
@@ -78,8 +78,7 @@ class SkinnedMesh extends Mesh {
78
78
 
79
79
  for ( let i = 0; i < positionAttribute.count; i ++ ) {
80
80
 
81
- _vertex.fromBufferAttribute( positionAttribute, i );
82
- this.applyBoneTransform( i, _vertex );
81
+ this.getVertexPosition( i, _vertex );
83
82
  this.boundingSphere.expandByPoint( _vertex );
84
83
 
85
84
  }
@@ -205,11 +204,11 @@ class SkinnedMesh extends Mesh {
205
204
 
206
205
  super.updateMatrixWorld( force );
207
206
 
208
- if ( this.bindMode === 'attached' ) {
207
+ if ( this.bindMode === AttachedBindMode ) {
209
208
 
210
209
  this.bindMatrixInverse.copy( this.matrixWorld ).invert();
211
210
 
212
- } else if ( this.bindMode === 'detached' ) {
211
+ } else if ( this.bindMode === DetachedBindMode ) {
213
212
 
214
213
  this.bindMatrixInverse.copy( this.bindMatrix ).invert();
215
214
 
@@ -634,7 +634,12 @@ class WebGLRenderer {
634
634
  }
635
635
 
636
636
  if ( depth ) bits |= _gl.DEPTH_BUFFER_BIT;
637
- if ( stencil ) bits |= _gl.STENCIL_BUFFER_BIT;
637
+ if ( stencil ) {
638
+
639
+ bits |= _gl.STENCIL_BUFFER_BIT;
640
+ this.state.buffers.stencil.setMask( 0xffffffff );
641
+
642
+ }
638
643
 
639
644
  _gl.clear( bits );
640
645
 
@@ -917,36 +922,40 @@ class WebGLRenderer {
917
922
 
918
923
  // Compile
919
924
 
920
- this.compile = function ( scene, camera ) {
925
+ function prepareMaterial( material, scene, object ) {
921
926
 
922
- function prepare( material, scene, object ) {
927
+ if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
923
928
 
924
- if ( material.transparent === true && material.side === DoubleSide && material.forceSinglePass === false ) {
929
+ material.side = BackSide;
930
+ material.needsUpdate = true;
931
+ getProgram( material, scene, object );
925
932
 
926
- material.side = BackSide;
927
- material.needsUpdate = true;
928
- getProgram( material, scene, object );
933
+ material.side = FrontSide;
934
+ material.needsUpdate = true;
935
+ getProgram( material, scene, object );
929
936
 
930
- material.side = FrontSide;
931
- material.needsUpdate = true;
932
- getProgram( material, scene, object );
937
+ material.side = DoubleSide;
933
938
 
934
- material.side = DoubleSide;
939
+ } else {
935
940
 
936
- } else {
941
+ getProgram( material, scene, object );
937
942
 
938
- getProgram( material, scene, object );
943
+ }
939
944
 
940
- }
945
+ }
941
946
 
942
- }
947
+ this.compile = function ( scene, camera, targetScene = null ) {
943
948
 
944
- currentRenderState = renderStates.get( scene );
949
+ if ( targetScene === null ) targetScene = scene;
950
+
951
+ currentRenderState = renderStates.get( targetScene );
945
952
  currentRenderState.init();
946
953
 
947
954
  renderStateStack.push( currentRenderState );
948
955
 
949
- scene.traverseVisible( function ( object ) {
956
+ // gather lights from both the target scene and the new object that will be added to the scene.
957
+
958
+ targetScene.traverseVisible( function ( object ) {
950
959
 
951
960
  if ( object.isLight && object.layers.test( camera.layers ) ) {
952
961
 
@@ -962,8 +971,32 @@ class WebGLRenderer {
962
971
 
963
972
  } );
964
973
 
974
+ if ( scene !== targetScene ) {
975
+
976
+ scene.traverseVisible( function ( object ) {
977
+
978
+ if ( object.isLight && object.layers.test( camera.layers ) ) {
979
+
980
+ currentRenderState.pushLight( object );
981
+
982
+ if ( object.castShadow ) {
983
+
984
+ currentRenderState.pushShadow( object );
985
+
986
+ }
987
+
988
+ }
989
+
990
+ } );
991
+
992
+ }
993
+
965
994
  currentRenderState.setupLights( _this._useLegacyLights );
966
995
 
996
+ // Only initialize materials in the new scene, not the targetScene.
997
+
998
+ const materials = new Set();
999
+
967
1000
  scene.traverse( function ( object ) {
968
1001
 
969
1002
  const material = object.material;
@@ -976,13 +1009,15 @@ class WebGLRenderer {
976
1009
 
977
1010
  const material2 = material[ i ];
978
1011
 
979
- prepare( material2, scene, object );
1012
+ prepareMaterial( material2, targetScene, object );
1013
+ materials.add( material2 );
980
1014
 
981
1015
  }
982
1016
 
983
1017
  } else {
984
1018
 
985
- prepare( material, scene, object );
1019
+ prepareMaterial( material, targetScene, object );
1020
+ materials.add( material );
986
1021
 
987
1022
  }
988
1023
 
@@ -993,6 +1028,70 @@ class WebGLRenderer {
993
1028
  renderStateStack.pop();
994
1029
  currentRenderState = null;
995
1030
 
1031
+ return materials;
1032
+
1033
+ };
1034
+
1035
+ // compileAsync
1036
+
1037
+ this.compileAsync = function ( scene, camera, targetScene = null ) {
1038
+
1039
+ const materials = this.compile( scene, camera, targetScene );
1040
+
1041
+ // Wait for all the materials in the new object to indicate that they're
1042
+ // ready to be used before resolving the promise.
1043
+
1044
+ return new Promise( ( resolve ) => {
1045
+
1046
+ function checkMaterialsReady() {
1047
+
1048
+ materials.forEach( function ( material ) {
1049
+
1050
+ const materialProperties = properties.get( material );
1051
+ const program = materialProperties.currentProgram;
1052
+
1053
+ if ( program.isReady() ) {
1054
+
1055
+ // remove any programs that report they're ready to use from the list
1056
+ materials.delete( material );
1057
+
1058
+ }
1059
+
1060
+ } );
1061
+
1062
+ // once the list of compiling materials is empty, call the callback
1063
+
1064
+ if ( materials.size === 0 ) {
1065
+
1066
+ resolve( scene );
1067
+ return;
1068
+
1069
+ }
1070
+
1071
+ // if some materials are still not ready, wait a bit and check again
1072
+
1073
+ setTimeout( checkMaterialsReady, 10 );
1074
+
1075
+ }
1076
+
1077
+ if ( extensions.get( 'KHR_parallel_shader_compile' ) !== null ) {
1078
+
1079
+ // If we can check the compilation status of the materials without
1080
+ // blocking then do so right away.
1081
+
1082
+ checkMaterialsReady();
1083
+
1084
+ } else {
1085
+
1086
+ // Otherwise start by waiting a bit to give the materials we just
1087
+ // initialized a chance to finish.
1088
+
1089
+ setTimeout( checkMaterialsReady, 10 );
1090
+
1091
+ }
1092
+
1093
+ } );
1094
+
996
1095
  };
997
1096
 
998
1097
  // Animation Loop
@@ -1346,6 +1445,14 @@ class WebGLRenderer {
1346
1445
 
1347
1446
  function renderTransmissionPass( opaqueObjects, transmissiveObjects, scene, camera ) {
1348
1447
 
1448
+ const overrideMaterial = scene.isScene === true ? scene.overrideMaterial : null;
1449
+
1450
+ if ( overrideMaterial !== null ) {
1451
+
1452
+ return;
1453
+
1454
+ }
1455
+
1349
1456
  const isWebGL2 = capabilities.isWebGL2;
1350
1457
 
1351
1458
  if ( _transmissionRenderTarget === null ) {
@@ -1605,16 +1712,26 @@ class WebGLRenderer {
1605
1712
 
1606
1713
  }
1607
1714
 
1608
- const progUniforms = program.getUniforms();
1609
- const uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, uniforms );
1610
-
1611
1715
  materialProperties.currentProgram = program;
1612
- materialProperties.uniformsList = uniformsList;
1716
+ materialProperties.uniformsList = null;
1613
1717
 
1614
1718
  return program;
1615
1719
 
1616
1720
  }
1617
1721
 
1722
+ function getUniformList( materialProperties ) {
1723
+
1724
+ if ( materialProperties.uniformsList === null ) {
1725
+
1726
+ const progUniforms = materialProperties.currentProgram.getUniforms();
1727
+ materialProperties.uniformsList = WebGLUniforms.seqWithValue( progUniforms.seq, materialProperties.uniforms );
1728
+
1729
+ }
1730
+
1731
+ return materialProperties.uniformsList;
1732
+
1733
+ }
1734
+
1618
1735
  function updateCommonMaterialProperties( material, parameters ) {
1619
1736
 
1620
1737
  const materialProperties = properties.get( material );
@@ -1958,13 +2075,13 @@ class WebGLRenderer {
1958
2075
 
1959
2076
  materials.refreshMaterialUniforms( m_uniforms, material, _pixelRatio, _height, _transmissionRenderTarget );
1960
2077
 
1961
- WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
2078
+ WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );
1962
2079
 
1963
2080
  }
1964
2081
 
1965
2082
  if ( material.isShaderMaterial && material.uniformsNeedUpdate === true ) {
1966
2083
 
1967
- WebGLUniforms.upload( _gl, materialProperties.uniformsList, m_uniforms, textures );
2084
+ WebGLUniforms.upload( _gl, getUniformList( materialProperties ), m_uniforms, textures );
1968
2085
  material.uniformsNeedUpdate = false;
1969
2086
 
1970
2087
  }
@@ -6,6 +6,14 @@ export default /* glsl */`
6
6
 
7
7
  reflectedLight.indirectDiffuse *= ambientOcclusion;
8
8
 
9
+ #if defined( USE_CLEARCOAT )
10
+ clearcoatSpecularIndirect *= ambientOcclusion;
11
+ #endif
12
+
13
+ #if defined( USE_SHEEN )
14
+ sheenSpecularIndirect *= ambientOcclusion;
15
+ #endif
16
+
9
17
  #if defined( USE_ENVMAP ) && defined( STANDARD )
10
18
 
11
19
  float dotNV = saturate( dot( geometryNormal, geometryViewDir ) );
@@ -24,8 +24,9 @@ export default /* glsl */`
24
24
 
25
25
  vec3 perturbNormalArb( vec3 surf_pos, vec3 surf_norm, vec2 dHdxy, float faceDirection ) {
26
26
 
27
- vec3 vSigmaX = dFdx( surf_pos.xyz );
28
- vec3 vSigmaY = dFdy( surf_pos.xyz );
27
+ // normalize is done to ensure that the bump map looks the same regardless of the texture's scale
28
+ vec3 vSigmaX = normalize( dFdx( surf_pos.xyz ) );
29
+ vec3 vSigmaY = normalize( dFdy( surf_pos.xyz ) );
29
30
  vec3 vN = surf_norm; // normalized
30
31
 
31
32
  vec3 R1 = cross( vSigmaY, vN );
@@ -17,7 +17,7 @@ vec3 geometryPosition = - vViewPosition;
17
17
  vec3 geometryNormal = normal;
18
18
  vec3 geometryViewDir = ( isOrthographic ) ? vec3( 0, 0, 1 ) : normalize( vViewPosition );
19
19
 
20
- vec3 geometryClearcoatNormal;
20
+ vec3 geometryClearcoatNormal = vec3( 0.0 );
21
21
 
22
22
  #ifdef USE_CLEARCOAT
23
23