super-three 0.168.0 → 0.169.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 (286) hide show
  1. package/build/three.cjs +369 -131
  2. package/build/three.module.js +369 -131
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +24644 -22406
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +79941 -0
  7. package/build/three.webgpu.nodes.min.js +6 -0
  8. package/examples/jsm/Addons.js +0 -6
  9. package/examples/jsm/controls/TrackballControls.js +32 -12
  10. package/examples/jsm/controls/TransformControls.js +97 -62
  11. package/examples/jsm/exporters/DRACOExporter.js +4 -2
  12. package/examples/jsm/exporters/EXRExporter.js +19 -11
  13. package/examples/jsm/exporters/KTX2Exporter.js +21 -13
  14. package/examples/jsm/exporters/OBJExporter.js +5 -1
  15. package/examples/jsm/exporters/PLYExporter.js +9 -7
  16. package/examples/jsm/geometries/DecalGeometry.js +4 -1
  17. package/examples/jsm/geometries/InstancedPointsGeometry.js +1 -1
  18. package/examples/jsm/helpers/LightProbeHelper.js +1 -1
  19. package/examples/jsm/helpers/LightProbeHelperGPU.js +65 -0
  20. package/examples/jsm/libs/basis/basis_transcoder.js +8 -10
  21. package/examples/jsm/libs/basis/basis_transcoder.wasm +0 -0
  22. package/examples/jsm/libs/ktx-parse.module.js +1 -1
  23. package/examples/jsm/lights/LightProbeGenerator.js +24 -10
  24. package/examples/jsm/loaders/ColladaLoader.js +9 -6
  25. package/examples/jsm/loaders/DRACOLoader.js +3 -1
  26. package/examples/jsm/loaders/FBXLoader.js +30 -20
  27. package/examples/jsm/loaders/GLTFLoader.js +5 -10
  28. package/examples/jsm/loaders/KTX2Loader.js +10 -7
  29. package/examples/jsm/loaders/MTLLoader.js +4 -3
  30. package/examples/jsm/loaders/MaterialXLoader.js +29 -10
  31. package/examples/jsm/loaders/OBJLoader.js +5 -3
  32. package/examples/jsm/loaders/PCDLoader.js +5 -4
  33. package/examples/jsm/loaders/PDBLoader.js +3 -2
  34. package/examples/jsm/loaders/PLYLoader.js +8 -5
  35. package/examples/jsm/loaders/STLLoader.js +3 -2
  36. package/examples/jsm/loaders/VRMLLoader.js +10 -10
  37. package/examples/jsm/loaders/VTKLoader.js +4 -3
  38. package/examples/jsm/loaders/XYZLoader.js +3 -2
  39. package/examples/jsm/misc/Timer.js +1 -1
  40. package/examples/jsm/modifiers/CurveModifierGPU.js +233 -0
  41. package/examples/jsm/objects/LensflareMesh.js +322 -0
  42. package/examples/jsm/objects/SkyMesh.js +1 -2
  43. package/examples/jsm/objects/Water2Mesh.js +2 -3
  44. package/examples/jsm/objects/WaterMesh.js +1 -2
  45. package/examples/jsm/physics/JoltPhysics.js +1 -1
  46. package/examples/jsm/physics/RapierPhysics.js +1 -1
  47. package/examples/jsm/transpiler/GLSLDecoder.js +1 -1
  48. package/examples/jsm/transpiler/ShaderToyDecoder.js +2 -2
  49. package/examples/jsm/utils/GeometryCompressionUtils.js +37 -122
  50. package/examples/jsm/utils/ShadowMapViewer.js +3 -8
  51. package/examples/jsm/utils/ShadowMapViewerGPU.js +201 -0
  52. package/examples/jsm/utils/SkeletonUtils.js +84 -66
  53. package/examples/jsm/utils/TextureUtils.js +1 -0
  54. package/examples/jsm/utils/TextureUtilsGPU.js +63 -0
  55. package/examples/jsm/webxr/XRControllerModelFactory.js +1 -1
  56. package/package.json +2 -2
  57. package/src/Three.WebGPU.Nodes.js +200 -0
  58. package/src/Three.WebGPU.js +2 -1
  59. package/src/audio/Audio.js +2 -2
  60. package/src/constants.js +1 -1
  61. package/src/core/BufferAttribute.js +0 -9
  62. package/src/core/Clock.js +1 -1
  63. package/src/core/InterleavedBuffer.js +0 -9
  64. package/src/extras/Controls.js +1 -1
  65. package/src/geometries/CylinderGeometry.js +11 -4
  66. package/src/loaders/MaterialLoader.js +7 -1
  67. package/src/loaders/nodes/NodeLoader.js +24 -4
  68. package/src/loaders/nodes/NodeMaterialLoader.js +21 -17
  69. package/src/loaders/nodes/NodeObjectLoader.js +19 -0
  70. package/src/materials/nodes/InstancedPointsNodeMaterial.js +19 -34
  71. package/src/materials/nodes/Line2NodeMaterial.js +26 -26
  72. package/src/materials/nodes/LineBasicNodeMaterial.js +7 -3
  73. package/src/materials/nodes/LineDashedNodeMaterial.js +7 -3
  74. package/src/materials/nodes/MeshBasicNodeMaterial.js +7 -3
  75. package/src/materials/nodes/MeshLambertNodeMaterial.js +7 -3
  76. package/src/materials/nodes/MeshMatcapNodeMaterial.js +7 -3
  77. package/src/materials/nodes/MeshNormalNodeMaterial.js +7 -3
  78. package/src/materials/nodes/MeshPhongNodeMaterial.js +7 -3
  79. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +6 -3
  80. package/src/materials/nodes/MeshSSSNodeMaterial.js +6 -3
  81. package/src/materials/nodes/MeshStandardNodeMaterial.js +7 -3
  82. package/src/materials/nodes/MeshToonNodeMaterial.js +7 -3
  83. package/src/materials/nodes/NodeMaterial.js +20 -45
  84. package/src/materials/nodes/NodeMaterials.js +2 -0
  85. package/src/materials/nodes/PointsNodeMaterial.js +7 -3
  86. package/src/materials/nodes/ShadowNodeMaterial.js +7 -3
  87. package/src/materials/nodes/SpriteNodeMaterial.js +39 -6
  88. package/src/materials/nodes/VolumeNodeMaterial.js +13 -9
  89. package/src/materials/nodes/manager/NodeMaterialObserver.js +302 -0
  90. package/src/math/Triangle.js +24 -0
  91. package/src/nodes/Nodes.js +3 -3
  92. package/src/nodes/TSL.js +96 -93
  93. package/src/nodes/accessors/BatchNode.js +7 -3
  94. package/src/nodes/accessors/BufferAttributeNode.js +6 -3
  95. package/src/nodes/accessors/BufferNode.js +6 -3
  96. package/src/nodes/accessors/Camera.js +10 -16
  97. package/src/nodes/accessors/ClippingNode.js +7 -3
  98. package/src/nodes/accessors/CubeTextureNode.js +6 -3
  99. package/src/nodes/accessors/InstanceNode.js +11 -11
  100. package/src/nodes/accessors/InstancedPointsMaterialNode.js +6 -3
  101. package/src/nodes/accessors/Lights.js +51 -0
  102. package/src/nodes/accessors/MaterialNode.js +8 -4
  103. package/src/nodes/accessors/MaterialReferenceNode.js +6 -3
  104. package/src/nodes/accessors/ModelNode.js +42 -7
  105. package/src/nodes/accessors/ModelViewProjectionNode.js +9 -5
  106. package/src/nodes/accessors/MorphNode.js +7 -3
  107. package/src/nodes/accessors/Normal.js +32 -6
  108. package/src/nodes/accessors/Object3DNode.js +11 -27
  109. package/src/nodes/accessors/PointUVNode.js +7 -3
  110. package/src/nodes/accessors/ReferenceBaseNode.js +32 -4
  111. package/src/nodes/accessors/ReferenceNode.js +40 -3
  112. package/src/nodes/accessors/RendererReferenceNode.js +9 -3
  113. package/src/nodes/accessors/SceneNode.js +7 -3
  114. package/src/nodes/accessors/SkinningNode.js +7 -3
  115. package/src/nodes/accessors/StorageBufferNode.js +21 -3
  116. package/src/nodes/accessors/StorageTextureNode.js +7 -4
  117. package/src/nodes/accessors/Texture3DNode.js +7 -4
  118. package/src/nodes/accessors/TextureNode.js +19 -8
  119. package/src/nodes/accessors/TextureSizeNode.js +8 -5
  120. package/src/nodes/accessors/UniformArrayNode.js +12 -9
  121. package/src/nodes/accessors/UserDataNode.js +9 -6
  122. package/src/nodes/accessors/VelocityNode.js +74 -23
  123. package/src/nodes/accessors/VertexColorNode.js +6 -3
  124. package/src/nodes/code/CodeNode.js +7 -3
  125. package/src/nodes/code/ExpressionNode.js +8 -4
  126. package/src/nodes/code/FunctionCallNode.js +6 -3
  127. package/src/nodes/code/FunctionNode.js +6 -3
  128. package/src/nodes/code/ScriptableNode.js +11 -6
  129. package/src/nodes/code/ScriptableValueNode.js +7 -3
  130. package/src/nodes/core/AssignNode.js +9 -6
  131. package/src/nodes/core/AttributeNode.js +7 -3
  132. package/src/nodes/core/BypassNode.js +8 -4
  133. package/src/nodes/core/CacheNode.js +8 -4
  134. package/src/nodes/core/ConstNode.js +6 -3
  135. package/src/nodes/core/ContextNode.js +7 -3
  136. package/src/nodes/core/IndexNode.js +25 -3
  137. package/src/nodes/core/InputNode.js +7 -3
  138. package/src/nodes/core/MRTNode.js +6 -3
  139. package/src/nodes/core/Node.js +10 -51
  140. package/src/nodes/core/NodeBuilder.js +71 -5
  141. package/src/nodes/core/NodeUtils.js +48 -6
  142. package/src/nodes/core/OutputStructNode.js +8 -4
  143. package/src/nodes/core/ParameterNode.js +6 -3
  144. package/src/nodes/core/PropertyNode.js +7 -3
  145. package/src/nodes/core/StackNode.js +7 -3
  146. package/src/nodes/core/StructTypeNode.js +7 -3
  147. package/src/nodes/core/TempNode.js +8 -4
  148. package/src/nodes/core/UniformGroupNode.js +10 -6
  149. package/src/nodes/core/UniformNode.js +6 -3
  150. package/src/nodes/core/VarNode.js +8 -4
  151. package/src/nodes/core/VaryingNode.js +7 -3
  152. package/src/nodes/display/AfterImageNode.js +6 -0
  153. package/src/nodes/display/AnaglyphPassNode.js +6 -0
  154. package/src/nodes/display/AnamorphicNode.js +6 -0
  155. package/src/nodes/display/BloomNode.js +6 -0
  156. package/src/nodes/display/BumpMapNode.js +6 -0
  157. package/src/nodes/display/ColorSpaceFunctions.js +4 -4
  158. package/src/nodes/display/ColorSpaceNode.js +43 -14
  159. package/src/nodes/display/DenoiseNode.js +6 -3
  160. package/src/nodes/display/DepthOfFieldNode.js +6 -3
  161. package/src/nodes/display/DotScreenNode.js +8 -5
  162. package/src/nodes/display/FXAANode.js +6 -3
  163. package/src/nodes/display/FilmNode.js +6 -3
  164. package/src/nodes/display/FrontFacingNode.js +7 -3
  165. package/src/nodes/display/GTAONode.js +6 -3
  166. package/src/nodes/display/GaussianBlurNode.js +6 -3
  167. package/src/nodes/display/Lut3DNode.js +6 -3
  168. package/src/nodes/display/NormalMapNode.js +8 -6
  169. package/src/nodes/display/ParallaxBarrierPassNode.js +8 -5
  170. package/src/nodes/display/PassNode.js +18 -7
  171. package/src/nodes/display/PixelationPassNode.js +12 -5
  172. package/src/nodes/display/PosterizeNode.js +6 -3
  173. package/src/nodes/display/RGBShiftNode.js +6 -3
  174. package/src/nodes/display/RenderOutputNode.js +12 -8
  175. package/src/nodes/display/SSAAPassNode.js +6 -3
  176. package/src/nodes/display/ScreenNode.js +181 -0
  177. package/src/nodes/display/SobelOperatorNode.js +6 -3
  178. package/src/nodes/display/StereoCompositePassNode.js +6 -3
  179. package/src/nodes/display/StereoPassNode.js +6 -3
  180. package/src/nodes/display/ToneMappingFunctions.js +12 -12
  181. package/src/nodes/display/ToneMappingNode.js +8 -7
  182. package/src/nodes/display/ToonOutlinePassNode.js +111 -0
  183. package/src/nodes/display/TransitionNode.js +6 -3
  184. package/src/nodes/display/ViewportDepthNode.js +7 -3
  185. package/src/nodes/display/ViewportDepthTextureNode.js +8 -5
  186. package/src/nodes/display/ViewportSharedTextureNode.js +8 -5
  187. package/src/nodes/display/ViewportTextureNode.js +8 -5
  188. package/src/nodes/fog/FogExp2Node.js +6 -3
  189. package/src/nodes/fog/FogNode.js +7 -3
  190. package/src/nodes/fog/FogRangeNode.js +6 -3
  191. package/src/nodes/functions/PhysicalLightingModel.js +2 -2
  192. package/src/nodes/functions/material/getShIrradianceAt.js +28 -0
  193. package/src/nodes/geometry/RangeNode.js +7 -3
  194. package/src/nodes/gpgpu/AtomicFunctionNode.js +99 -0
  195. package/src/nodes/gpgpu/BarrierNode.js +40 -0
  196. package/src/nodes/gpgpu/ComputeBuiltinNode.js +98 -0
  197. package/src/nodes/gpgpu/ComputeNode.js +8 -4
  198. package/src/nodes/gpgpu/WorkgroupInfoNode.js +100 -0
  199. package/src/nodes/lighting/AONode.js +6 -3
  200. package/src/nodes/lighting/AmbientLightNode.js +6 -3
  201. package/src/nodes/lighting/AnalyticLightNode.js +198 -30
  202. package/src/nodes/lighting/BasicEnvironmentNode.js +6 -3
  203. package/src/nodes/lighting/BasicLightMapNode.js +6 -3
  204. package/src/nodes/lighting/DirectionalLightNode.js +7 -4
  205. package/src/nodes/lighting/EnvironmentNode.js +6 -3
  206. package/src/nodes/lighting/HemisphereLightNode.js +10 -6
  207. package/src/nodes/lighting/IESSpotLightNode.js +6 -3
  208. package/src/nodes/lighting/IrradianceNode.js +6 -3
  209. package/src/nodes/lighting/LightProbeNode.js +8 -31
  210. package/src/nodes/lighting/LightingContextNode.js +6 -3
  211. package/src/nodes/lighting/LightingNode.js +7 -3
  212. package/src/nodes/lighting/LightsNode.js +24 -5
  213. package/src/nodes/lighting/PointLightNode.js +11 -7
  214. package/src/nodes/lighting/RectAreaLightNode.js +11 -7
  215. package/src/nodes/lighting/SpotLightNode.js +13 -10
  216. package/src/nodes/math/ConditionalNode.js +23 -6
  217. package/src/nodes/math/MathNode.js +6 -3
  218. package/src/nodes/math/OperatorNode.js +6 -3
  219. package/src/nodes/pmrem/PMREMNode.js +6 -3
  220. package/src/nodes/utils/ArrayElementNode.js +8 -4
  221. package/src/nodes/utils/ConvertNode.js +7 -3
  222. package/src/nodes/utils/CubeMapNode.js +6 -3
  223. package/src/nodes/utils/EquirectUVNode.js +6 -3
  224. package/src/nodes/utils/FlipNode.js +7 -4
  225. package/src/nodes/utils/FunctionOverloadingNode.js +7 -3
  226. package/src/nodes/utils/JoinNode.js +6 -3
  227. package/src/nodes/utils/LoopNode.js +7 -3
  228. package/src/nodes/utils/MatcapUVNode.js +6 -3
  229. package/src/nodes/utils/MaxMipLevelNode.js +6 -3
  230. package/src/nodes/utils/OscNode.js +7 -3
  231. package/src/nodes/utils/RTTNode.js +6 -3
  232. package/src/nodes/utils/ReflectorNode.js +8 -5
  233. package/src/nodes/utils/RemapNode.js +7 -3
  234. package/src/nodes/utils/RotateNode.js +6 -3
  235. package/src/nodes/utils/SetNode.js +7 -4
  236. package/src/nodes/utils/SplitNode.js +7 -3
  237. package/src/nodes/utils/SpriteSheetUVNode.js +7 -3
  238. package/src/nodes/utils/StorageArrayElementNode.js +9 -8
  239. package/src/nodes/utils/TimerNode.js +6 -3
  240. package/src/nodes/utils/TriplanarTexturesNode.js +7 -3
  241. package/src/nodes/utils/ViewportUtils.js +2 -2
  242. package/src/objects/BatchedMesh.js +76 -10
  243. package/src/objects/LOD.js +21 -0
  244. package/src/objects/Line.js +1 -0
  245. package/src/objects/Mesh.js +7 -23
  246. package/src/objects/Points.js +2 -0
  247. package/src/renderers/WebGLRenderer.js +64 -41
  248. package/src/renderers/common/BundleGroup.js +26 -0
  249. package/src/renderers/common/ClippingContext.js +4 -3
  250. package/src/renderers/common/RenderContext.js +4 -5
  251. package/src/renderers/common/RenderObject.js +116 -5
  252. package/src/renderers/common/RenderObjects.js +8 -1
  253. package/src/renderers/common/Renderer.js +57 -49
  254. package/src/renderers/common/extras/PMREMGenerator.js +7 -9
  255. package/src/renderers/common/nodes/NodeBuilderState.js +3 -3
  256. package/src/renderers/common/nodes/Nodes.js +33 -14
  257. package/src/renderers/shaders/ShaderLib/sprite.glsl.js +2 -4
  258. package/src/renderers/webgl/WebGLAttributes.js +45 -14
  259. package/src/renderers/webgl/WebGLCapabilities.js +9 -0
  260. package/src/renderers/webgl/WebGLProgram.js +2 -0
  261. package/src/renderers/webgl/WebGLPrograms.js +21 -17
  262. package/src/renderers/webgl/WebGLState.js +21 -0
  263. package/src/renderers/webgl/WebGLTextures.js +22 -0
  264. package/src/renderers/webgl-fallback/WebGLBackend.js +50 -45
  265. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +4 -4
  266. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +6 -0
  267. package/src/renderers/webgl-fallback/utils/WebGLState.js +1 -4
  268. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +61 -16
  269. package/src/renderers/webgpu/WebGPUBackend.js +33 -25
  270. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +42 -0
  271. package/src/renderers/webgpu/WebGPURenderer.js +5 -2
  272. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +59 -0
  273. package/src/renderers/{common → webgpu}/nodes/StandardNodeLibrary.js +11 -11
  274. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +91 -11
  275. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +6 -16
  276. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +1 -1
  277. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +7 -5
  278. package/src/renderers/webgpu/utils/WebGPUUtils.js +1 -1
  279. package/src/utils.js +33 -1
  280. package/examples/jsm/geometries/SDFGeometryGenerator.js +0 -144
  281. package/examples/jsm/loaders/TiltLoader.js +0 -520
  282. package/examples/jsm/utils/GPUStatsPanel.js +0 -95
  283. package/examples/jsm/utils/PackedPhongMaterial.js +0 -178
  284. package/src/nodes/display/ViewportNode.js +0 -138
  285. package/src/nodes/lighting/LightNode.js +0 -57
  286. package/src/renderers/common/StandardRenderer.js +0 -18
@@ -3,7 +3,7 @@
3
3
  * Copyright 2010-2024 Three.js Authors
4
4
  * SPDX-License-Identifier: MIT
5
5
  */
6
- const REVISION = '168';
6
+ const REVISION = '169';
7
7
 
8
8
  const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
9
9
  const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
@@ -1592,6 +1592,38 @@ function probeAsync( gl, sync, interval ) {
1592
1592
 
1593
1593
  }
1594
1594
 
1595
+ function toNormalizedProjectionMatrix( projectionMatrix ) {
1596
+
1597
+ const m = projectionMatrix.elements;
1598
+
1599
+ // Convert [-1, 1] to [0, 1] projection matrix
1600
+ m[ 2 ] = 0.5 * m[ 2 ] + 0.5 * m[ 3 ];
1601
+ m[ 6 ] = 0.5 * m[ 6 ] + 0.5 * m[ 7 ];
1602
+ m[ 10 ] = 0.5 * m[ 10 ] + 0.5 * m[ 11 ];
1603
+ m[ 14 ] = 0.5 * m[ 14 ] + 0.5 * m[ 15 ];
1604
+
1605
+ }
1606
+
1607
+ function toReversedProjectionMatrix( projectionMatrix ) {
1608
+
1609
+ const m = projectionMatrix.elements;
1610
+ const isPerspectiveMatrix = m[ 11 ] === - 1;
1611
+
1612
+ // Reverse [0, 1] projection matrix
1613
+ if ( isPerspectiveMatrix ) {
1614
+
1615
+ m[ 10 ] = - m[ 10 ] - 1;
1616
+ m[ 14 ] = - m[ 14 ];
1617
+
1618
+ } else {
1619
+
1620
+ m[ 10 ] = - m[ 10 ];
1621
+ m[ 14 ] = - m[ 14 ] + 1;
1622
+
1623
+ }
1624
+
1625
+ }
1626
+
1595
1627
  /**
1596
1628
  * Matrices converting P3 <-> Rec. 709 primaries, without gamut mapping
1597
1629
  * or clipping. Based on W3C specifications for sRGB and Display P3,
@@ -8187,6 +8219,10 @@ const _vap = /*@__PURE__*/ new Vector3();
8187
8219
  const _vbp = /*@__PURE__*/ new Vector3();
8188
8220
  const _vcp = /*@__PURE__*/ new Vector3();
8189
8221
 
8222
+ const _v40 = /*@__PURE__*/ new Vector4();
8223
+ const _v41 = /*@__PURE__*/ new Vector4();
8224
+ const _v42 = /*@__PURE__*/ new Vector4();
8225
+
8190
8226
  class Triangle {
8191
8227
 
8192
8228
  constructor( a = new Vector3(), b = new Vector3(), c = new Vector3() ) {
@@ -8281,6 +8317,25 @@ class Triangle {
8281
8317
 
8282
8318
  }
8283
8319
 
8320
+ static getInterpolatedAttribute( attr, i1, i2, i3, barycoord, target ) {
8321
+
8322
+ _v40.setScalar( 0 );
8323
+ _v41.setScalar( 0 );
8324
+ _v42.setScalar( 0 );
8325
+
8326
+ _v40.fromBufferAttribute( attr, i1 );
8327
+ _v41.fromBufferAttribute( attr, i2 );
8328
+ _v42.fromBufferAttribute( attr, i3 );
8329
+
8330
+ target.setScalar( 0 );
8331
+ target.addScaledVector( _v40, barycoord.x );
8332
+ target.addScaledVector( _v41, barycoord.y );
8333
+ target.addScaledVector( _v42, barycoord.z );
8334
+
8335
+ return target;
8336
+
8337
+ }
8338
+
8284
8339
  static isFrontFacing( a, b, c, direction ) {
8285
8340
 
8286
8341
  _v0$2.subVectors( c, b );
@@ -9896,7 +9951,6 @@ class BufferAttribute {
9896
9951
  this.normalized = normalized;
9897
9952
 
9898
9953
  this.usage = StaticDrawUsage;
9899
- this._updateRange = { offset: 0, count: - 1 };
9900
9954
  this.updateRanges = [];
9901
9955
  this.gpuType = FloatType;
9902
9956
 
@@ -9912,13 +9966,6 @@ class BufferAttribute {
9912
9966
 
9913
9967
  }
9914
9968
 
9915
- get updateRange() {
9916
-
9917
- warnOnce( 'THREE.BufferAttribute: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead.' ); // @deprecated, r159
9918
- return this._updateRange;
9919
-
9920
- }
9921
-
9922
9969
  setUsage( value ) {
9923
9970
 
9924
9971
  this.usage = value;
@@ -11563,14 +11610,6 @@ const _vC$1 = /*@__PURE__*/ new Vector3();
11563
11610
  const _tempA = /*@__PURE__*/ new Vector3();
11564
11611
  const _morphA = /*@__PURE__*/ new Vector3();
11565
11612
 
11566
- const _uvA$1 = /*@__PURE__*/ new Vector2();
11567
- const _uvB$1 = /*@__PURE__*/ new Vector2();
11568
- const _uvC$1 = /*@__PURE__*/ new Vector2();
11569
-
11570
- const _normalA = /*@__PURE__*/ new Vector3();
11571
- const _normalB = /*@__PURE__*/ new Vector3();
11572
- const _normalC = /*@__PURE__*/ new Vector3();
11573
-
11574
11613
  const _intersectionPoint = /*@__PURE__*/ new Vector3();
11575
11614
  const _intersectionPointWorld = /*@__PURE__*/ new Vector3();
11576
11615
 
@@ -11913,33 +11952,24 @@ function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, n
11913
11952
 
11914
11953
  if ( intersection ) {
11915
11954
 
11916
- if ( uv ) {
11955
+ const barycoord = new Vector3();
11956
+ Triangle.getBarycoord( _intersectionPoint, _vA$1, _vB$1, _vC$1, barycoord );
11917
11957
 
11918
- _uvA$1.fromBufferAttribute( uv, a );
11919
- _uvB$1.fromBufferAttribute( uv, b );
11920
- _uvC$1.fromBufferAttribute( uv, c );
11958
+ if ( uv ) {
11921
11959
 
11922
- intersection.uv = Triangle.getInterpolation( _intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() );
11960
+ intersection.uv = Triangle.getInterpolatedAttribute( uv, a, b, c, barycoord, new Vector2() );
11923
11961
 
11924
11962
  }
11925
11963
 
11926
11964
  if ( uv1 ) {
11927
11965
 
11928
- _uvA$1.fromBufferAttribute( uv1, a );
11929
- _uvB$1.fromBufferAttribute( uv1, b );
11930
- _uvC$1.fromBufferAttribute( uv1, c );
11931
-
11932
- intersection.uv1 = Triangle.getInterpolation( _intersectionPoint, _vA$1, _vB$1, _vC$1, _uvA$1, _uvB$1, _uvC$1, new Vector2() );
11966
+ intersection.uv1 = Triangle.getInterpolatedAttribute( uv1, a, b, c, barycoord, new Vector2() );
11933
11967
 
11934
11968
  }
11935
11969
 
11936
11970
  if ( normal ) {
11937
11971
 
11938
- _normalA.fromBufferAttribute( normal, a );
11939
- _normalB.fromBufferAttribute( normal, b );
11940
- _normalC.fromBufferAttribute( normal, c );
11941
-
11942
- intersection.normal = Triangle.getInterpolation( _intersectionPoint, _vA$1, _vB$1, _vC$1, _normalA, _normalB, _normalC, new Vector3() );
11972
+ intersection.normal = Triangle.getInterpolatedAttribute( normal, a, b, c, barycoord, new Vector3() );
11943
11973
 
11944
11974
  if ( intersection.normal.dot( ray.direction ) > 0 ) {
11945
11975
 
@@ -11960,6 +11990,7 @@ function checkGeometryIntersection( object, material, raycaster, ray, uv, uv1, n
11960
11990
  Triangle.getNormal( _vA$1, _vB$1, _vC$1, face.normal );
11961
11991
 
11962
11992
  intersection.face = face;
11993
+ intersection.barycoord = barycoord;
11963
11994
 
11964
11995
  }
11965
11996
 
@@ -13603,40 +13634,71 @@ function WebGLAttributes( gl ) {
13603
13634
  function updateBuffer( buffer, attribute, bufferType ) {
13604
13635
 
13605
13636
  const array = attribute.array;
13606
- const updateRange = attribute._updateRange; // @deprecated, r159
13607
13637
  const updateRanges = attribute.updateRanges;
13608
13638
 
13609
13639
  gl.bindBuffer( bufferType, buffer );
13610
13640
 
13611
- if ( updateRange.count === - 1 && updateRanges.length === 0 ) {
13641
+ if ( updateRanges.length === 0 ) {
13612
13642
 
13613
13643
  // Not using update ranges
13614
13644
  gl.bufferSubData( bufferType, 0, array );
13615
13645
 
13616
- }
13646
+ } else {
13617
13647
 
13618
- if ( updateRanges.length !== 0 ) {
13648
+ // Before applying update ranges, we merge any adjacent / overlapping
13649
+ // ranges to reduce load on `gl.bufferSubData`. Empirically, this has led
13650
+ // to performance improvements for applications which make heavy use of
13651
+ // update ranges. Likely due to GPU command overhead.
13652
+ //
13653
+ // Note that to reduce garbage collection between frames, we merge the
13654
+ // update ranges in-place. This is safe because this method will clear the
13655
+ // update ranges once updated.
13619
13656
 
13620
- for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {
13657
+ updateRanges.sort( ( a, b ) => a.start - b.start );
13621
13658
 
13659
+ // To merge the update ranges in-place, we work from left to right in the
13660
+ // existing updateRanges array, merging ranges. This may result in a final
13661
+ // array which is smaller than the original. This index tracks the last
13662
+ // index representing a merged range, any data after this index can be
13663
+ // trimmed once the merge algorithm is completed.
13664
+ let mergeIndex = 0;
13665
+
13666
+ for ( let i = 1; i < updateRanges.length; i ++ ) {
13667
+
13668
+ const previousRange = updateRanges[ mergeIndex ];
13622
13669
  const range = updateRanges[ i ];
13623
13670
 
13624
- gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT,
13625
- array, range.start, range.count );
13671
+ // We add one here to merge adjacent ranges. This is safe because ranges
13672
+ // operate over positive integers.
13673
+ if ( range.start <= previousRange.start + previousRange.count + 1 ) {
13674
+
13675
+ previousRange.count = Math.max(
13676
+ previousRange.count,
13677
+ range.start + range.count - previousRange.start
13678
+ );
13679
+
13680
+ } else {
13681
+
13682
+ ++ mergeIndex;
13683
+ updateRanges[ mergeIndex ] = range;
13684
+
13685
+ }
13626
13686
 
13627
13687
  }
13628
13688
 
13629
- attribute.clearUpdateRanges();
13689
+ // Trim the array to only contain the merged ranges.
13690
+ updateRanges.length = mergeIndex + 1;
13630
13691
 
13631
- }
13692
+ for ( let i = 0, l = updateRanges.length; i < l; i ++ ) {
13632
13693
 
13633
- // @deprecated, r159
13634
- if ( updateRange.count !== - 1 ) {
13694
+ const range = updateRanges[ i ];
13635
13695
 
13636
- gl.bufferSubData( bufferType, updateRange.offset * array.BYTES_PER_ELEMENT,
13637
- array, updateRange.offset, updateRange.count );
13696
+ gl.bufferSubData( bufferType, range.start * array.BYTES_PER_ELEMENT,
13697
+ array, range.start, range.count );
13698
+
13699
+ }
13638
13700
 
13639
- updateRange.count = - 1; // reset range
13701
+ attribute.clearUpdateRanges();
13640
13702
 
13641
13703
  }
13642
13704
 
@@ -14097,7 +14159,7 @@ const vertex$2 = "#include <common>\n#include <batching_pars_vertex>\n#include <
14097
14159
 
14098
14160
  const fragment$2 = "uniform vec3 color;\nuniform float opacity;\n#include <common>\n#include <packing>\n#include <fog_pars_fragment>\n#include <bsdfs>\n#include <lights_pars_begin>\n#include <logdepthbuf_pars_fragment>\n#include <shadowmap_pars_fragment>\n#include <shadowmask_pars_fragment>\nvoid main() {\n\t#include <logdepthbuf_fragment>\n\tgl_FragColor = vec4( color, opacity * ( 1.0 - getShadowMask() ) );\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}";
14099
14161
 
14100
- const vertex$1 = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix * vec4( 0.0, 0.0, 0.0, 1.0 );\n\tvec2 scale;\n\tscale.x = length( vec3( modelMatrix[ 0 ].x, modelMatrix[ 0 ].y, modelMatrix[ 0 ].z ) );\n\tscale.y = length( vec3( modelMatrix[ 1 ].x, modelMatrix[ 1 ].y, modelMatrix[ 1 ].z ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
14162
+ const vertex$1 = "uniform float rotation;\nuniform vec2 center;\n#include <common>\n#include <uv_pars_vertex>\n#include <fog_pars_vertex>\n#include <logdepthbuf_pars_vertex>\n#include <clipping_planes_pars_vertex>\nvoid main() {\n\t#include <uv_vertex>\n\tvec4 mvPosition = modelViewMatrix[ 3 ];\n\tvec2 scale = vec2( length( modelMatrix[ 0 ].xyz ), length( modelMatrix[ 1 ].xyz ) );\n\t#ifndef USE_SIZEATTENUATION\n\t\tbool isPerspective = isPerspectiveMatrix( projectionMatrix );\n\t\tif ( isPerspective ) scale *= - mvPosition.z;\n\t#endif\n\tvec2 alignedPosition = ( position.xy - ( center - vec2( 0.5 ) ) ) * scale;\n\tvec2 rotatedPosition;\n\trotatedPosition.x = cos( rotation ) * alignedPosition.x - sin( rotation ) * alignedPosition.y;\n\trotatedPosition.y = sin( rotation ) * alignedPosition.x + cos( rotation ) * alignedPosition.y;\n\tmvPosition.xy += rotatedPosition;\n\tgl_Position = projectionMatrix * mvPosition;\n\t#include <logdepthbuf_vertex>\n\t#include <clipping_planes_vertex>\n\t#include <fog_vertex>\n}";
14101
14163
 
14102
14164
  const fragment$1 = "uniform vec3 diffuse;\nuniform float opacity;\n#include <common>\n#include <uv_pars_fragment>\n#include <map_pars_fragment>\n#include <alphamap_pars_fragment>\n#include <alphatest_pars_fragment>\n#include <alphahash_pars_fragment>\n#include <fog_pars_fragment>\n#include <logdepthbuf_pars_fragment>\n#include <clipping_planes_pars_fragment>\nvoid main() {\n\tvec4 diffuseColor = vec4( diffuse, opacity );\n\t#include <clipping_planes_fragment>\n\tvec3 outgoingLight = vec3( 0.0 );\n\t#include <logdepthbuf_fragment>\n\t#include <map_fragment>\n\t#include <alphamap_fragment>\n\t#include <alphatest_fragment>\n\t#include <alphahash_fragment>\n\toutgoingLight = diffuseColor.rgb;\n\t#include <opaque_fragment>\n\t#include <tonemapping_fragment>\n\t#include <colorspace_fragment>\n\t#include <fog_fragment>\n}";
14103
14165
 
@@ -15863,6 +15925,14 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
15863
15925
  }
15864
15926
 
15865
15927
  const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
15928
+ const reverseDepthBuffer = parameters.reverseDepthBuffer === true && extensions.has( 'EXT_clip_control' );
15929
+
15930
+ if ( reverseDepthBuffer === true ) {
15931
+
15932
+ const ext = extensions.get( 'EXT_clip_control' );
15933
+ ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT );
15934
+
15935
+ }
15866
15936
 
15867
15937
  const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
15868
15938
  const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
@@ -15890,6 +15960,7 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
15890
15960
 
15891
15961
  precision: precision,
15892
15962
  logarithmicDepthBuffer: logarithmicDepthBuffer,
15963
+ reverseDepthBuffer: reverseDepthBuffer,
15893
15964
 
15894
15965
  maxTextures: maxTextures,
15895
15966
  maxVertexTextures: maxVertexTextures,
@@ -20006,6 +20077,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
20006
20077
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
20007
20078
 
20008
20079
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
20080
+ parameters.reverseDepthBuffer ? '#define USE_REVERSEDEPTHBUF' : '',
20009
20081
 
20010
20082
  'uniform mat4 modelMatrix;',
20011
20083
  'uniform mat4 modelViewMatrix;',
@@ -20171,6 +20243,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
20171
20243
  parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
20172
20244
 
20173
20245
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
20246
+ parameters.reverseDepthBuffer ? '#define USE_REVERSEDEPTHBUF' : '',
20174
20247
 
20175
20248
  'uniform mat4 viewMatrix;',
20176
20249
  'uniform vec3 cameraPosition;',
@@ -20611,6 +20684,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20611
20684
  const programs = [];
20612
20685
 
20613
20686
  const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
20687
+ const reverseDepthBuffer = capabilities.reverseDepthBuffer;
20614
20688
  const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures;
20615
20689
 
20616
20690
  let precision = capabilities.precision;
@@ -20905,6 +20979,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20905
20979
 
20906
20980
  sizeAttenuation: material.sizeAttenuation === true,
20907
20981
  logarithmicDepthBuffer: logarithmicDepthBuffer,
20982
+ reverseDepthBuffer: reverseDepthBuffer,
20908
20983
 
20909
20984
  skinning: object.isSkinnedMesh === true,
20910
20985
 
@@ -21124,40 +21199,42 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
21124
21199
  _programLayers.enable( 2 );
21125
21200
  if ( parameters.logarithmicDepthBuffer )
21126
21201
  _programLayers.enable( 3 );
21127
- if ( parameters.skinning )
21202
+ if ( parameters.reverseDepthBuffer )
21128
21203
  _programLayers.enable( 4 );
21129
- if ( parameters.morphTargets )
21204
+ if ( parameters.skinning )
21130
21205
  _programLayers.enable( 5 );
21131
- if ( parameters.morphNormals )
21206
+ if ( parameters.morphTargets )
21132
21207
  _programLayers.enable( 6 );
21133
- if ( parameters.morphColors )
21208
+ if ( parameters.morphNormals )
21134
21209
  _programLayers.enable( 7 );
21135
- if ( parameters.premultipliedAlpha )
21210
+ if ( parameters.morphColors )
21136
21211
  _programLayers.enable( 8 );
21137
- if ( parameters.shadowMapEnabled )
21212
+ if ( parameters.premultipliedAlpha )
21138
21213
  _programLayers.enable( 9 );
21139
- if ( parameters.doubleSided )
21214
+ if ( parameters.shadowMapEnabled )
21140
21215
  _programLayers.enable( 10 );
21141
- if ( parameters.flipSided )
21216
+ if ( parameters.doubleSided )
21142
21217
  _programLayers.enable( 11 );
21143
- if ( parameters.useDepthPacking )
21218
+ if ( parameters.flipSided )
21144
21219
  _programLayers.enable( 12 );
21145
- if ( parameters.dithering )
21220
+ if ( parameters.useDepthPacking )
21146
21221
  _programLayers.enable( 13 );
21147
- if ( parameters.transmission )
21222
+ if ( parameters.dithering )
21148
21223
  _programLayers.enable( 14 );
21149
- if ( parameters.sheen )
21224
+ if ( parameters.transmission )
21150
21225
  _programLayers.enable( 15 );
21151
- if ( parameters.opaque )
21226
+ if ( parameters.sheen )
21152
21227
  _programLayers.enable( 16 );
21153
- if ( parameters.pointsUvs )
21228
+ if ( parameters.opaque )
21154
21229
  _programLayers.enable( 17 );
21155
- if ( parameters.decodeVideoTexture )
21230
+ if ( parameters.pointsUvs )
21156
21231
  _programLayers.enable( 18 );
21157
- if ( parameters.alphaToCoverage )
21232
+ if ( parameters.decodeVideoTexture )
21158
21233
  _programLayers.enable( 19 );
21159
- if ( parameters.numMultiviewViews )
21234
+ if ( parameters.alphaToCoverage )
21160
21235
  _programLayers.enable( 20 );
21236
+ if ( parameters.numMultiviewViews )
21237
+ _programLayers.enable( 21 );
21161
21238
 
21162
21239
  array.push( _programLayers.mask );
21163
21240
 
@@ -22715,6 +22792,18 @@ function WebGLShadowMap( renderer, objects, capabilities ) {
22715
22792
 
22716
22793
  }
22717
22794
 
22795
+ const reversedFuncs = {
22796
+ [ NeverDepth ]: AlwaysDepth,
22797
+ [ LessDepth ]: GreaterDepth,
22798
+ [ EqualDepth ]: NotEqualDepth,
22799
+ [ LessEqualDepth ]: GreaterEqualDepth,
22800
+
22801
+ [ AlwaysDepth ]: NeverDepth,
22802
+ [ GreaterDepth ]: LessDepth,
22803
+ [ NotEqualDepth ]: EqualDepth,
22804
+ [ GreaterEqualDepth ]: LessEqualDepth,
22805
+ };
22806
+
22718
22807
  function WebGLState( gl ) {
22719
22808
 
22720
22809
  function ColorBuffer() {
@@ -22779,6 +22868,7 @@ function WebGLState( gl ) {
22779
22868
  function DepthBuffer() {
22780
22869
 
22781
22870
  let locked = false;
22871
+ let reversed = false;
22782
22872
 
22783
22873
  let currentDepthMask = null;
22784
22874
  let currentDepthFunc = null;
@@ -22786,6 +22876,12 @@ function WebGLState( gl ) {
22786
22876
 
22787
22877
  return {
22788
22878
 
22879
+ setReversed: function ( value ) {
22880
+
22881
+ reversed = value;
22882
+
22883
+ },
22884
+
22789
22885
  setTest: function ( depthTest ) {
22790
22886
 
22791
22887
  if ( depthTest ) {
@@ -22813,6 +22909,8 @@ function WebGLState( gl ) {
22813
22909
 
22814
22910
  setFunc: function ( depthFunc ) {
22815
22911
 
22912
+ if ( reversed ) depthFunc = reversedFuncs[ depthFunc ];
22913
+
22816
22914
  if ( currentDepthFunc !== depthFunc ) {
22817
22915
 
22818
22916
  switch ( depthFunc ) {
@@ -24358,6 +24456,28 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24358
24456
 
24359
24457
  }
24360
24458
 
24459
+ if ( glFormat === _gl.RGB_INTEGER ) {
24460
+
24461
+ if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGB8UI;
24462
+ if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RGB16UI;
24463
+ if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RGB32UI;
24464
+ if ( glType === _gl.BYTE ) internalFormat = _gl.RGB8I;
24465
+ if ( glType === _gl.SHORT ) internalFormat = _gl.RGB16I;
24466
+ if ( glType === _gl.INT ) internalFormat = _gl.RGB32I;
24467
+
24468
+ }
24469
+
24470
+ if ( glFormat === _gl.RGBA_INTEGER ) {
24471
+
24472
+ if ( glType === _gl.UNSIGNED_BYTE ) internalFormat = _gl.RGBA8UI;
24473
+ if ( glType === _gl.UNSIGNED_SHORT ) internalFormat = _gl.RGBA16UI;
24474
+ if ( glType === _gl.UNSIGNED_INT ) internalFormat = _gl.RGBA32UI;
24475
+ if ( glType === _gl.BYTE ) internalFormat = _gl.RGBA8I;
24476
+ if ( glType === _gl.SHORT ) internalFormat = _gl.RGBA16I;
24477
+ if ( glType === _gl.INT ) internalFormat = _gl.RGBA32I;
24478
+
24479
+ }
24480
+
24361
24481
  if ( glFormat === _gl.RGB ) {
24362
24482
 
24363
24483
  if ( glType === _gl.UNSIGNED_INT_5_9_9_9_REV ) internalFormat = _gl.RGB9_E5;
@@ -29765,6 +29885,7 @@ class WebGLRenderer {
29765
29885
 
29766
29886
  // camera matrices cache
29767
29887
 
29888
+ const _currentProjectionMatrix = new Matrix4();
29768
29889
  const _projScreenMatrix = new Matrix4();
29769
29890
 
29770
29891
  const _vector3 = new Vector3();
@@ -29861,6 +29982,8 @@ class WebGLRenderer {
29861
29982
 
29862
29983
  state = new WebGLState( _gl );
29863
29984
 
29985
+ if ( capabilities.reverseDepthBuffer ) state.buffers.depth.setReversed( true );
29986
+
29864
29987
  info = new WebGLInfo( _gl );
29865
29988
  properties = new WebGLProperties();
29866
29989
  textures = new WebGLTextures( _gl, extensions, state, properties, capabilities, utils, info );
@@ -30161,7 +30284,13 @@ class WebGLRenderer {
30161
30284
 
30162
30285
  }
30163
30286
 
30164
- if ( depth ) bits |= _gl.DEPTH_BUFFER_BIT;
30287
+ if ( depth ) {
30288
+
30289
+ bits |= _gl.DEPTH_BUFFER_BIT;
30290
+ _gl.clearDepth( this.capabilities.reverseDepthBuffer ? 0 : 1 );
30291
+
30292
+ }
30293
+
30165
30294
  if ( stencil ) {
30166
30295
 
30167
30296
  bits |= _gl.STENCIL_BUFFER_BIT;
@@ -30550,6 +30679,12 @@ class WebGLRenderer {
30550
30679
 
30551
30680
  scene.traverse( function ( object ) {
30552
30681
 
30682
+ if ( ! ( object.isMesh || object.isPoints || object.isLine || object.isSprite ) ) {
30683
+
30684
+ return;
30685
+
30686
+ }
30687
+
30553
30688
  const material = object.material;
30554
30689
 
30555
30690
  if ( material ) {
@@ -31567,7 +31702,21 @@ class WebGLRenderer {
31567
31702
 
31568
31703
  } else {
31569
31704
 
31570
- p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
31705
+ if ( capabilities.reverseDepthBuffer ) {
31706
+
31707
+ _currentProjectionMatrix.copy( camera.projectionMatrix );
31708
+
31709
+ toNormalizedProjectionMatrix( _currentProjectionMatrix );
31710
+ toReversedProjectionMatrix( _currentProjectionMatrix );
31711
+
31712
+ p_uniforms.setValue( _gl, 'projectionMatrix', _currentProjectionMatrix );
31713
+
31714
+ } else {
31715
+
31716
+ p_uniforms.setValue( _gl, 'projectionMatrix', camera.projectionMatrix );
31717
+
31718
+ }
31719
+
31571
31720
  p_uniforms.setValue( _gl, 'viewMatrix', camera.matrixWorldInverse );
31572
31721
 
31573
31722
  }
@@ -32085,61 +32234,55 @@ class WebGLRenderer {
32085
32234
 
32086
32235
  if ( framebuffer ) {
32087
32236
 
32088
- state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
32089
-
32090
- try {
32091
-
32092
- const texture = renderTarget.texture;
32093
- const textureFormat = texture.format;
32094
- const textureType = texture.type;
32095
-
32096
- if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
32237
+ const texture = renderTarget.texture;
32238
+ const textureFormat = texture.format;
32239
+ const textureType = texture.type;
32097
32240
 
32098
- throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
32241
+ if ( ! capabilities.textureFormatReadable( textureFormat ) ) {
32099
32242
 
32100
- }
32243
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in RGBA or implementation defined format.' );
32101
32244
 
32102
- if ( ! capabilities.textureTypeReadable( textureType ) ) {
32245
+ }
32103
32246
 
32104
- throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
32247
+ if ( ! capabilities.textureTypeReadable( textureType ) ) {
32105
32248
 
32106
- }
32249
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: renderTarget is not in UnsignedByteType or implementation defined type.' );
32107
32250
 
32108
- // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
32109
- if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
32251
+ }
32110
32252
 
32111
- const glBuffer = _gl.createBuffer();
32112
- _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
32113
- _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
32114
- _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
32115
- _gl.flush();
32253
+ // the following if statement ensures valid read requests (no out-of-bounds pixels, see #8604)
32254
+ if ( ( x >= 0 && x <= ( renderTarget.width - width ) ) && ( y >= 0 && y <= ( renderTarget.height - height ) ) ) {
32116
32255
 
32117
- // check if the commands have finished every 8 ms
32118
- const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 );
32119
- await probeAsync( _gl, sync, 4 );
32256
+ // set the active frame buffer to the one we want to read
32257
+ state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
32120
32258
 
32121
- try {
32259
+ const glBuffer = _gl.createBuffer();
32260
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
32261
+ _gl.bufferData( _gl.PIXEL_PACK_BUFFER, buffer.byteLength, _gl.STREAM_READ );
32262
+ _gl.readPixels( x, y, width, height, utils.convert( textureFormat ), utils.convert( textureType ), 0 );
32122
32263
 
32123
- _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
32124
- _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer );
32264
+ // reset the frame buffer to the currently set buffer before waiting
32265
+ const currFramebuffer = _currentRenderTarget !== null ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
32266
+ state.bindFramebuffer( _gl.FRAMEBUFFER, currFramebuffer );
32125
32267
 
32126
- } finally {
32268
+ // check if the commands have finished every 8 ms
32269
+ const sync = _gl.fenceSync( _gl.SYNC_GPU_COMMANDS_COMPLETE, 0 );
32127
32270
 
32128
- _gl.deleteBuffer( glBuffer );
32129
- _gl.deleteSync( sync );
32271
+ _gl.flush();
32130
32272
 
32131
- }
32273
+ await probeAsync( _gl, sync, 4 );
32132
32274
 
32133
- return buffer;
32275
+ // read the data and delete the buffer
32276
+ _gl.bindBuffer( _gl.PIXEL_PACK_BUFFER, glBuffer );
32277
+ _gl.getBufferSubData( _gl.PIXEL_PACK_BUFFER, 0, buffer );
32278
+ _gl.deleteBuffer( glBuffer );
32279
+ _gl.deleteSync( sync );
32134
32280
 
32135
- }
32281
+ return buffer;
32136
32282
 
32137
- } finally {
32283
+ } else {
32138
32284
 
32139
- // restore framebuffer of current render target if necessary
32140
-
32141
- const framebuffer = ( _currentRenderTarget !== null ) ? properties.get( _currentRenderTarget ).__webglFramebuffer : null;
32142
- state.bindFramebuffer( _gl.FRAMEBUFFER, framebuffer );
32285
+ throw new Error( 'THREE.WebGLRenderer.readRenderTargetPixelsAsync: requested read bounds are out of range.' );
32143
32286
 
32144
32287
  }
32145
32288
 
@@ -32625,7 +32768,6 @@ class InterleavedBuffer {
32625
32768
  this.count = array !== undefined ? array.length / stride : 0;
32626
32769
 
32627
32770
  this.usage = StaticDrawUsage;
32628
- this._updateRange = { offset: 0, count: - 1 };
32629
32771
  this.updateRanges = [];
32630
32772
 
32631
32773
  this.version = 0;
@@ -32642,13 +32784,6 @@ class InterleavedBuffer {
32642
32784
 
32643
32785
  }
32644
32786
 
32645
- get updateRange() {
32646
-
32647
- warnOnce( 'THREE.InterleavedBuffer: updateRange() is deprecated and will be removed in r169. Use addUpdateRange() instead.' ); // @deprecated, r159
32648
- return this._updateRange;
32649
-
32650
- }
32651
-
32652
32787
  setUsage( value ) {
32653
32788
 
32654
32789
  this.usage = value;
@@ -33413,6 +33548,27 @@ class LOD extends Object3D {
33413
33548
 
33414
33549
  }
33415
33550
 
33551
+ removeLevel( distance ) {
33552
+
33553
+ const levels = this.levels;
33554
+
33555
+ for ( let i = 0; i < levels.length; i ++ ) {
33556
+
33557
+ if ( levels[ i ].distance === distance ) {
33558
+
33559
+ const removedElements = levels.splice( i, 1 );
33560
+ this.remove( removedElements[ 0 ].object );
33561
+
33562
+ return true;
33563
+
33564
+ }
33565
+
33566
+ }
33567
+
33568
+ return false;
33569
+
33570
+ }
33571
+
33416
33572
  getCurrentLevel() {
33417
33573
 
33418
33574
  return this._currentLevel;
@@ -34532,6 +34688,9 @@ class BatchedMesh extends Mesh {
34532
34688
  // stores visible, active, and geometry id per object
34533
34689
  this._drawInfo = [];
34534
34690
 
34691
+ // instance ids that have been set as inactive, and are available to be overwritten
34692
+ this._availableInstanceIds = [];
34693
+
34535
34694
  // geometry information
34536
34695
  this._drawRanges = [];
34537
34696
  this._reservedRanges = [];
@@ -34731,23 +34890,36 @@ class BatchedMesh extends Mesh {
34731
34890
 
34732
34891
  addInstance( geometryId ) {
34733
34892
 
34893
+ const atCapacity = this._drawInfo.length >= this.maxInstanceCount;
34894
+
34734
34895
  // ensure we're not over geometry
34735
- if ( this._drawInfo.length >= this._maxInstanceCount ) {
34896
+ if ( atCapacity && this._availableInstanceIds.length === 0 ) {
34736
34897
 
34737
34898
  throw new Error( 'BatchedMesh: Maximum item count reached.' );
34738
34899
 
34739
34900
  }
34740
34901
 
34741
- this._drawInfo.push( {
34742
-
34902
+ const instanceDrawInfo = {
34743
34903
  visible: true,
34744
34904
  active: true,
34745
34905
  geometryIndex: geometryId,
34906
+ };
34746
34907
 
34747
- } );
34908
+ let drawId = null;
34909
+
34910
+ // Prioritize using previously freed instance ids
34911
+ if ( this._availableInstanceIds.length > 0 ) {
34912
+
34913
+ drawId = this._availableInstanceIds.pop();
34914
+ this._drawInfo[ drawId ] = instanceDrawInfo;
34915
+
34916
+ } else {
34917
+
34918
+ drawId = this._drawInfo.length;
34919
+ this._drawInfo.push( instanceDrawInfo );
34920
+
34921
+ }
34748
34922
 
34749
- // initialize the matrix
34750
- const drawId = this._drawInfo.length - 1;
34751
34923
  const matricesTexture = this._matricesTexture;
34752
34924
  const matricesArray = matricesTexture.image.data;
34753
34925
  _identityMatrix.toArray( matricesArray, drawId * 16 );
@@ -34996,11 +35168,8 @@ class BatchedMesh extends Mesh {
34996
35168
  }
34997
35169
  */
34998
35170
 
34999
- /*
35000
35171
  deleteInstance( instanceId ) {
35001
35172
 
35002
- // Note: User needs to call optimize() afterward to pack the data.
35003
-
35004
35173
  const drawInfo = this._drawInfo;
35005
35174
  if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35006
35175
 
@@ -35009,12 +35178,12 @@ class BatchedMesh extends Mesh {
35009
35178
  }
35010
35179
 
35011
35180
  drawInfo[ instanceId ].active = false;
35181
+ this._availableInstanceIds.push( instanceId );
35012
35182
  this._visibilityChanged = true;
35013
35183
 
35014
35184
  return this;
35015
35185
 
35016
35186
  }
35017
- */
35018
35187
 
35019
35188
  // get bounding box and compute it if it doesn't exist
35020
35189
  getBoundingBoxAt( geometryId, target ) {
@@ -35219,6 +35388,59 @@ class BatchedMesh extends Mesh {
35219
35388
 
35220
35389
  }
35221
35390
 
35391
+ setGeometryIdAt( instanceId, geometryId ) {
35392
+
35393
+ // return early if the geometry is out of range or not active
35394
+ const drawInfo = this._drawInfo;
35395
+ if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35396
+
35397
+ return null;
35398
+
35399
+ }
35400
+
35401
+ // check if the provided geometryId is within the valid range
35402
+ if ( geometryId < 0 || geometryId >= this._geometryCount ) {
35403
+
35404
+ return null;
35405
+
35406
+ }
35407
+
35408
+ drawInfo[ instanceId ].geometryIndex = geometryId;
35409
+
35410
+ return this;
35411
+
35412
+ }
35413
+
35414
+ getGeometryIdAt( instanceId ) {
35415
+
35416
+ const drawInfo = this._drawInfo;
35417
+ if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35418
+
35419
+ return - 1;
35420
+
35421
+ }
35422
+
35423
+ return drawInfo[ instanceId ].geometryIndex;
35424
+
35425
+ }
35426
+
35427
+ getGeometryRangeAt( geometryId, target = {} ) {
35428
+
35429
+ if ( geometryId < 0 || geometryId >= this._geometryCount ) {
35430
+
35431
+ return null;
35432
+
35433
+ }
35434
+
35435
+ const drawRange = this._drawRanges[ geometryId ];
35436
+
35437
+ target.start = drawRange.start;
35438
+ target.count = drawRange.count;
35439
+
35440
+ return target;
35441
+
35442
+ }
35443
+
35222
35444
  raycast( raycaster, intersects ) {
35223
35445
 
35224
35446
  const drawInfo = this._drawInfo;
@@ -35770,6 +35992,7 @@ function checkIntersection( object, raycaster, ray, thresholdSq, a, b ) {
35770
35992
  index: a,
35771
35993
  face: null,
35772
35994
  faceIndex: null,
35995
+ barycoord: null,
35773
35996
  object: object
35774
35997
 
35775
35998
  };
@@ -36035,6 +36258,8 @@ function testPoint( point, index, localThresholdSq, matrixWorld, raycaster, inte
36035
36258
  point: intersectPoint,
36036
36259
  index: index,
36037
36260
  face: null,
36261
+ faceIndex: null,
36262
+ barycoord: null,
36038
36263
  object: object
36039
36264
 
36040
36265
  } );
@@ -38537,12 +38762,19 @@ class CylinderGeometry extends BufferGeometry {
38537
38762
 
38538
38763
  // faces
38539
38764
 
38540
- indices.push( a, b, d );
38541
- indices.push( b, c, d );
38765
+ if ( radiusTop > 0 ) {
38542
38766
 
38543
- // update group counter
38767
+ indices.push( a, b, d );
38768
+ groupCount += 3;
38544
38769
 
38545
- groupCount += 6;
38770
+ }
38771
+
38772
+ if ( radiusBottom > 0 ) {
38773
+
38774
+ indices.push( b, c, d );
38775
+ groupCount += 3;
38776
+
38777
+ }
38546
38778
 
38547
38779
  }
38548
38780
 
@@ -46852,7 +47084,7 @@ class MaterialLoader extends Loader {
46852
47084
 
46853
47085
  }
46854
47086
 
46855
- const material = MaterialLoader.createMaterialFromType( json.type );
47087
+ const material = this.createMaterialFromType( json.type );
46856
47088
 
46857
47089
  if ( json.uuid !== undefined ) material.uuid = json.uuid;
46858
47090
  if ( json.name !== undefined ) material.name = json.name;
@@ -47108,6 +47340,12 @@ class MaterialLoader extends Loader {
47108
47340
 
47109
47341
  }
47110
47342
 
47343
+ createMaterialFromType( type ) {
47344
+
47345
+ return MaterialLoader.createMaterialFromType( type );
47346
+
47347
+ }
47348
+
47111
47349
  static createMaterialFromType( type ) {
47112
47350
 
47113
47351
  const materialLib = {
@@ -48953,7 +49191,7 @@ class Clock {
48953
49191
 
48954
49192
  function now() {
48955
49193
 
48956
- return ( typeof performance === 'undefined' ? Date : performance ).now(); // see #10732
49194
+ return performance.now();
48957
49195
 
48958
49196
  }
48959
49197
 
@@ -49245,7 +49483,7 @@ class Audio extends Object3D {
49245
49483
 
49246
49484
  }
49247
49485
 
49248
- stop() {
49486
+ stop( delay = 0 ) {
49249
49487
 
49250
49488
  if ( this.hasPlaybackControl === false ) {
49251
49489
 
@@ -49258,7 +49496,7 @@ class Audio extends Object3D {
49258
49496
 
49259
49497
  if ( this.source !== null ) {
49260
49498
 
49261
- this.source.stop();
49499
+ this.source.stop( this.context.currentTime + delay );
49262
49500
  this.source.onended = null;
49263
49501
 
49264
49502
  }
@@ -54900,7 +55138,7 @@ class ShapePath {
54900
55138
 
54901
55139
  class Controls extends EventDispatcher {
54902
55140
 
54903
- constructor( object, domElement ) {
55141
+ constructor( object, domElement = null ) {
54904
55142
 
54905
55143
  super();
54906
55144