super-three 0.169.0 → 0.170.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 (195) hide show
  1. package/build/three.cjs +989 -1131
  2. package/build/three.module.js +990 -1128
  3. package/build/three.module.min.js +1 -1
  4. package/build/three.webgpu.js +8398 -9842
  5. package/build/three.webgpu.min.js +1 -1
  6. package/build/three.webgpu.nodes.js +8398 -9842
  7. package/build/three.webgpu.nodes.min.js +1 -1
  8. package/examples/jsm/Addons.js +3 -3
  9. package/examples/jsm/animation/MMDAnimationHelper.js +2 -0
  10. package/examples/jsm/animation/MMDPhysics.js +2 -0
  11. package/examples/jsm/controls/TransformControls.js +22 -6
  12. package/examples/jsm/csm/CSM.js +2 -2
  13. package/examples/jsm/csm/CSMFrustum.js +7 -4
  14. package/examples/jsm/csm/CSMHelper.js +2 -0
  15. package/examples/jsm/csm/CSMShadowNode.js +435 -0
  16. package/examples/jsm/curves/NURBSCurve.js +34 -3
  17. package/examples/jsm/exporters/GLTFExporter.js +138 -71
  18. package/examples/jsm/exporters/KTX2Exporter.js +35 -12
  19. package/examples/jsm/exporters/MMDExporter.js +6 -0
  20. package/examples/jsm/exporters/USDZExporter.js +21 -3
  21. package/examples/jsm/geometries/DecalGeometry.js +65 -20
  22. package/examples/jsm/geometries/InstancedPointsGeometry.js +2 -0
  23. package/examples/jsm/helpers/TextureHelperGPU.js +175 -0
  24. package/examples/jsm/interactive/HTMLMesh.js +1 -0
  25. package/examples/jsm/lighting/TiledLighting.js +18 -0
  26. package/examples/jsm/lights/RectAreaLightTexturesLib.js +1 -1
  27. package/examples/jsm/lines/LineMaterial.js +7 -2
  28. package/examples/jsm/lines/LineSegmentsGeometry.js +2 -0
  29. package/examples/jsm/lines/webgpu/LineSegments2.js +0 -15
  30. package/examples/jsm/lines/webgpu/Wireframe.js +56 -0
  31. package/examples/jsm/loaders/3DMLoader.js +1 -0
  32. package/examples/jsm/loaders/3MFLoader.js +91 -0
  33. package/examples/jsm/loaders/FBXLoader.js +12 -2
  34. package/examples/jsm/loaders/GLTFLoader.js +2 -0
  35. package/examples/jsm/loaders/KTX2Loader.js +140 -49
  36. package/examples/jsm/loaders/LDrawLoader.js +22 -136
  37. package/examples/jsm/loaders/LottieLoader.js +1 -0
  38. package/examples/jsm/loaders/MMDLoader.js +9 -2
  39. package/examples/jsm/materials/LDrawConditionalLineMaterial.js +143 -0
  40. package/examples/jsm/materials/LDrawConditionalLineNodeMaterial.js +114 -0
  41. package/examples/jsm/materials/MeshGouraudMaterial.js +6 -2
  42. package/examples/jsm/math/ColorSpaces.js +76 -0
  43. package/examples/jsm/misc/ProgressiveLightMap.js +52 -40
  44. package/examples/jsm/misc/ProgressiveLightMapGPU.js +293 -0
  45. package/examples/jsm/misc/VolumeSlice.js +1 -0
  46. package/examples/jsm/objects/WaterMesh.js +8 -8
  47. package/examples/jsm/postprocessing/AfterimagePass.js +14 -3
  48. package/examples/jsm/postprocessing/SSRPass.js +6 -0
  49. package/examples/jsm/renderers/CSS2DRenderer.js +6 -3
  50. package/examples/jsm/renderers/CSS3DRenderer.js +7 -4
  51. package/examples/jsm/shaders/FXAAShader.js +225 -224
  52. package/examples/jsm/transpiler/ShaderToyDecoder.js +1 -1
  53. package/{src/nodes → examples/jsm/tsl}/display/AfterImageNode.js +17 -20
  54. package/{src/nodes → examples/jsm/tsl}/display/AnaglyphPassNode.js +2 -6
  55. package/{src/nodes → examples/jsm/tsl}/display/AnamorphicNode.js +12 -18
  56. package/{src/nodes → examples/jsm/tsl}/display/BleachBypass.js +1 -3
  57. package/{src/nodes → examples/jsm/tsl}/display/BloomNode.js +11 -40
  58. package/{src/nodes → examples/jsm/tsl}/display/DenoiseNode.js +18 -41
  59. package/{src/nodes → examples/jsm/tsl}/display/DepthOfFieldNode.js +2 -8
  60. package/{src/nodes → examples/jsm/tsl}/display/DotScreenNode.js +2 -9
  61. package/examples/jsm/tsl/display/FXAANode.js +316 -0
  62. package/{src/nodes → examples/jsm/tsl}/display/FilmNode.js +2 -6
  63. package/{src/nodes → examples/jsm/tsl}/display/GTAONode.js +30 -70
  64. package/{src/nodes → examples/jsm/tsl}/display/GaussianBlurNode.js +74 -36
  65. package/examples/jsm/tsl/display/LensflareNode.js +161 -0
  66. package/{src/nodes → examples/jsm/tsl}/display/Lut3DNode.js +1 -4
  67. package/{src/nodes → examples/jsm/tsl}/display/MotionBlur.js +2 -3
  68. package/examples/jsm/tsl/display/OutlineNode.js +434 -0
  69. package/{src/nodes → examples/jsm/tsl}/display/ParallaxBarrierPassNode.js +1 -5
  70. package/{src/nodes → examples/jsm/tsl}/display/PixelationPassNode.js +3 -15
  71. package/{src/nodes → examples/jsm/tsl}/display/RGBShiftNode.js +1 -6
  72. package/examples/jsm/tsl/display/SMAANode.js +620 -0
  73. package/{src/nodes → examples/jsm/tsl}/display/SSAAPassNode.js +10 -25
  74. package/examples/jsm/tsl/display/SSRNode.js +343 -0
  75. package/{src/nodes → examples/jsm/tsl}/display/Sepia.js +1 -2
  76. package/{src/nodes → examples/jsm/tsl}/display/SobelOperatorNode.js +3 -11
  77. package/{src/nodes → examples/jsm/tsl}/display/StereoCompositePassNode.js +9 -11
  78. package/{src/nodes → examples/jsm/tsl}/display/StereoPassNode.js +10 -11
  79. package/examples/jsm/tsl/display/TRAAPassNode.js +355 -0
  80. package/{src/nodes → examples/jsm/tsl}/display/TransitionNode.js +1 -6
  81. package/examples/jsm/tsl/display/hashBlur.js +24 -0
  82. package/examples/jsm/tsl/lighting/TiledLightsNode.js +392 -0
  83. package/examples/jsm/utils/{TextureUtilsGPU.js → WebGPUTextureUtils.js} +2 -1
  84. package/examples/jsm/webxr/OculusHandPointerModel.js +21 -21
  85. package/examples/jsm/webxr/Text2D.js +6 -6
  86. package/package.json +2 -2
  87. package/src/Three.WebGPU.Nodes.js +4 -0
  88. package/src/Three.WebGPU.js +4 -0
  89. package/src/constants.js +1 -6
  90. package/src/core/BufferGeometry.js +44 -6
  91. package/src/geometries/CylinderGeometry.js +2 -2
  92. package/src/materials/LineBasicMaterial.js +6 -2
  93. package/src/materials/LineDashedMaterial.js +6 -2
  94. package/src/materials/Material.js +14 -1
  95. package/src/materials/MeshBasicMaterial.js +6 -2
  96. package/src/materials/MeshDepthMaterial.js +6 -2
  97. package/src/materials/MeshDistanceMaterial.js +6 -2
  98. package/src/materials/MeshLambertMaterial.js +6 -2
  99. package/src/materials/MeshMatcapMaterial.js +6 -2
  100. package/src/materials/MeshNormalMaterial.js +6 -2
  101. package/src/materials/MeshPhongMaterial.js +6 -2
  102. package/src/materials/MeshPhysicalMaterial.js +6 -2
  103. package/src/materials/MeshStandardMaterial.js +6 -2
  104. package/src/materials/MeshToonMaterial.js +6 -2
  105. package/src/materials/PointsMaterial.js +6 -2
  106. package/src/materials/RawShaderMaterial.js +6 -2
  107. package/src/materials/ShaderMaterial.js +6 -2
  108. package/src/materials/ShadowMaterial.js +6 -2
  109. package/src/materials/SpriteMaterial.js +6 -2
  110. package/src/materials/nodes/NodeMaterial.js +31 -9
  111. package/src/materials/nodes/SpriteNodeMaterial.js +11 -2
  112. package/src/materials/nodes/manager/NodeMaterialObserver.js +111 -2
  113. package/src/math/ColorManagement.js +118 -85
  114. package/src/math/Vector4.js +11 -0
  115. package/src/nodes/Nodes.js +1 -21
  116. package/src/nodes/TSL.js +6 -24
  117. package/src/nodes/accessors/Camera.js +0 -1
  118. package/src/nodes/accessors/SceneNode.js +35 -1
  119. package/src/nodes/accessors/StorageBufferNode.js +32 -10
  120. package/src/nodes/accessors/VelocityNode.js +13 -3
  121. package/src/nodes/code/FunctionCallNode.js +16 -5
  122. package/src/nodes/code/ScriptableNode.js +4 -4
  123. package/src/nodes/core/Node.js +1 -0
  124. package/src/nodes/core/NodeBuilder.js +29 -5
  125. package/src/nodes/core/VarNode.js +15 -3
  126. package/src/nodes/display/ColorAdjustment.js +53 -4
  127. package/src/nodes/display/ColorSpaceFunctions.js +5 -5
  128. package/src/nodes/display/ColorSpaceNode.js +27 -39
  129. package/src/nodes/display/PassNode.js +6 -4
  130. package/src/nodes/display/ToneMappingNode.js +1 -1
  131. package/src/nodes/display/ViewportDepthNode.js +33 -1
  132. package/src/nodes/functions/PhysicalLightingModel.js +21 -15
  133. package/src/nodes/functions/material/getAlphaHashThreshold.js +64 -0
  134. package/src/nodes/functions/material/getGeometryRoughness.js +8 -2
  135. package/src/nodes/functions/material/getParallaxCorrectNormal.js +22 -0
  136. package/src/nodes/gpgpu/ComputeNode.js +9 -1
  137. package/src/nodes/lighting/AnalyticLightNode.js +12 -416
  138. package/src/nodes/lighting/LightsNode.js +24 -12
  139. package/src/nodes/lighting/PointLightNode.js +36 -26
  140. package/src/nodes/lighting/RectAreaLightNode.js +3 -0
  141. package/src/nodes/lighting/ShadowNode.js +484 -0
  142. package/src/nodes/utils/LoopNode.js +2 -2
  143. package/src/nodes/utils/Oscillators.js +6 -0
  144. package/src/nodes/utils/PostProcessingUtils.js +89 -0
  145. package/src/nodes/utils/ReflectorNode.js +101 -15
  146. package/src/nodes/utils/Timer.js +29 -0
  147. package/src/objects/BatchedMesh.js +458 -241
  148. package/src/renderers/WebGLRenderer.js +121 -126
  149. package/src/renderers/common/Attributes.js +4 -0
  150. package/src/renderers/common/Backend.js +2 -0
  151. package/src/renderers/common/Background.js +14 -4
  152. package/src/renderers/common/Bindings.js +3 -2
  153. package/src/renderers/common/Constants.js +2 -1
  154. package/src/renderers/common/Geometries.js +20 -0
  155. package/src/renderers/common/IndirectStorageBufferAttribute.js +15 -0
  156. package/src/renderers/common/Lighting.js +45 -0
  157. package/src/renderers/common/PostProcessingUtils.js +86 -0
  158. package/src/renderers/common/RenderList.js +39 -11
  159. package/src/renderers/common/RenderLists.js +4 -2
  160. package/src/renderers/common/RenderObject.js +18 -1
  161. package/src/renderers/common/Renderer.js +165 -26
  162. package/src/renderers/common/Textures.js +30 -14
  163. package/src/renderers/common/nodes/NodeLibrary.js +1 -14
  164. package/src/renderers/common/nodes/Nodes.js +2 -2
  165. package/src/renderers/shaders/ShaderChunk/colorspace_pars_fragment.glsl.js +4 -24
  166. package/src/renderers/shaders/ShaderChunk/emissivemap_fragment.glsl.js +8 -0
  167. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +2 -2
  168. package/src/renderers/webgl/WebGLBufferRenderer.js +2 -6
  169. package/src/renderers/webgl/WebGLCapabilities.js +0 -7
  170. package/src/renderers/webgl/WebGLIndexedBufferRenderer.js +2 -6
  171. package/src/renderers/webgl/WebGLProgram.js +24 -28
  172. package/src/renderers/webgl/WebGLPrograms.js +5 -2
  173. package/src/renderers/webgl/WebGLState.js +37 -1
  174. package/src/renderers/webgl/WebGLTextures.js +29 -12
  175. package/src/renderers/webgl-fallback/WebGLBackend.js +98 -31
  176. package/src/renderers/webgl-fallback/WebGLBufferRenderer.js +2 -7
  177. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +33 -8
  178. package/src/renderers/webgpu/WebGPUBackend.js +105 -25
  179. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +1 -1
  180. package/src/renderers/webgpu/WebGPURenderer.js +1 -1
  181. package/src/renderers/webgpu/nodes/BasicNodeLibrary.js +0 -8
  182. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +0 -8
  183. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +10 -20
  184. package/src/renderers/webgpu/nodes/WGSLNodeFunction.js +12 -4
  185. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +29 -9
  186. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +24 -6
  187. package/src/renderers/webgpu/utils/WebGPUUtils.js +0 -1
  188. package/src/renderers/webxr/WebXRManager.js +4 -4
  189. package/examples/jsm/cameras/CinematicCamera.js +0 -208
  190. package/src/nodes/display/FXAANode.js +0 -332
  191. package/src/nodes/utils/OscNode.js +0 -85
  192. package/src/nodes/utils/TimerNode.js +0 -97
  193. package/src/renderers/webvr/WebVRManager.js +0 -495
  194. package/src/renderers/webvr/WebVRUtils.js +0 -66
  195. /package/examples/jsm/utils/{TextureUtils.js → WebGLTextureUtils.js} +0 -0
package/build/three.cjs CHANGED
@@ -5,7 +5,7 @@
5
5
  */
6
6
  'use strict';
7
7
 
8
- const REVISION = '169';
8
+ const REVISION = '170';
9
9
 
10
10
  const MOUSE = { LEFT: 0, MIDDLE: 1, RIGHT: 2, ROTATE: 0, DOLLY: 1, PAN: 2 };
11
11
  const TOUCH = { ROTATE: 0, PAN: 1, DOLLY_PAN: 2, DOLLY_ROTATE: 3 };
@@ -170,15 +170,10 @@ const ObjectSpaceNormalMap = 1;
170
170
  const NoColorSpace = '';
171
171
  const SRGBColorSpace = 'srgb';
172
172
  const LinearSRGBColorSpace = 'srgb-linear';
173
- const DisplayP3ColorSpace = 'display-p3';
174
- const LinearDisplayP3ColorSpace = 'display-p3-linear';
175
173
 
176
174
  const LinearTransfer = 'linear';
177
175
  const SRGBTransfer = 'srgb';
178
176
 
179
- const Rec709Primaries = 'rec709';
180
- const P3Primaries = 'p3';
181
-
182
177
  const ZeroStencilOp = 0;
183
178
  const KeepStencilOp = 7680;
184
179
  const ReplaceStencilOp = 7681;
@@ -1626,121 +1621,82 @@ function toReversedProjectionMatrix( projectionMatrix ) {
1626
1621
 
1627
1622
  }
1628
1623
 
1629
- /**
1630
- * Matrices converting P3 <-> Rec. 709 primaries, without gamut mapping
1631
- * or clipping. Based on W3C specifications for sRGB and Display P3,
1632
- * and ICC specifications for the D50 connection space. Values in/out
1633
- * are _linear_ sRGB and _linear_ Display P3.
1634
- *
1635
- * Note that both sRGB and Display P3 use the sRGB transfer functions.
1636
- *
1637
- * Reference:
1638
- * - http://www.russellcottrell.com/photo/matrixCalculator.htm
1639
- */
1640
-
1641
- const LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = /*@__PURE__*/ new Matrix3().set(
1642
- 0.8224621, 0.177538, 0.0,
1643
- 0.0331941, 0.9668058, 0.0,
1644
- 0.0170827, 0.0723974, 0.9105199,
1645
- );
1646
-
1647
- const LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = /*@__PURE__*/ new Matrix3().set(
1648
- 1.2249401, - 0.2249404, 0.0,
1649
- - 0.0420569, 1.0420571, 0.0,
1650
- - 0.0196376, - 0.0786361, 1.0982735
1651
- );
1652
-
1653
- /**
1654
- * Defines supported color spaces by transfer function and primaries,
1655
- * and provides conversions to/from the Linear-sRGB reference space.
1656
- */
1657
- const COLOR_SPACES = {
1658
- [ LinearSRGBColorSpace ]: {
1659
- transfer: LinearTransfer,
1660
- primaries: Rec709Primaries,
1661
- luminanceCoefficients: [ 0.2126, 0.7152, 0.0722 ],
1662
- toReference: ( color ) => color,
1663
- fromReference: ( color ) => color,
1664
- },
1665
- [ SRGBColorSpace ]: {
1666
- transfer: SRGBTransfer,
1667
- primaries: Rec709Primaries,
1668
- luminanceCoefficients: [ 0.2126, 0.7152, 0.0722 ],
1669
- toReference: ( color ) => color.convertSRGBToLinear(),
1670
- fromReference: ( color ) => color.convertLinearToSRGB(),
1671
- },
1672
- [ LinearDisplayP3ColorSpace ]: {
1673
- transfer: LinearTransfer,
1674
- primaries: P3Primaries,
1675
- luminanceCoefficients: [ 0.2289, 0.6917, 0.0793 ],
1676
- toReference: ( color ) => color.applyMatrix3( LINEAR_DISPLAY_P3_TO_LINEAR_SRGB ),
1677
- fromReference: ( color ) => color.applyMatrix3( LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 ),
1678
- },
1679
- [ DisplayP3ColorSpace ]: {
1680
- transfer: SRGBTransfer,
1681
- primaries: P3Primaries,
1682
- luminanceCoefficients: [ 0.2289, 0.6917, 0.0793 ],
1683
- toReference: ( color ) => color.convertSRGBToLinear().applyMatrix3( LINEAR_DISPLAY_P3_TO_LINEAR_SRGB ),
1684
- fromReference: ( color ) => color.applyMatrix3( LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 ).convertLinearToSRGB(),
1685
- },
1686
- };
1687
-
1688
- const SUPPORTED_WORKING_COLOR_SPACES = new Set( [ LinearSRGBColorSpace, LinearDisplayP3ColorSpace ] );
1689
-
1690
1624
  const ColorManagement = {
1691
1625
 
1692
1626
  enabled: true,
1693
1627
 
1694
- _workingColorSpace: LinearSRGBColorSpace,
1628
+ workingColorSpace: LinearSRGBColorSpace,
1695
1629
 
1696
- get workingColorSpace() {
1630
+ /**
1631
+ * Implementations of supported color spaces.
1632
+ *
1633
+ * Required:
1634
+ * - primaries: chromaticity coordinates [ rx ry gx gy bx by ]
1635
+ * - whitePoint: reference white [ x y ]
1636
+ * - transfer: transfer function (pre-defined)
1637
+ * - toXYZ: Matrix3 RGB to XYZ transform
1638
+ * - fromXYZ: Matrix3 XYZ to RGB transform
1639
+ * - luminanceCoefficients: RGB luminance coefficients
1640
+ *
1641
+ * Optional:
1642
+ * - outputColorSpaceConfig: { drawingBufferColorSpace: ColorSpace }
1643
+ * - workingColorSpaceConfig: { unpackColorSpace: ColorSpace }
1644
+ *
1645
+ * Reference:
1646
+ * - https://www.russellcottrell.com/photo/matrixCalculator.htm
1647
+ */
1648
+ spaces: {},
1697
1649
 
1698
- return this._workingColorSpace;
1650
+ convert: function ( color, sourceColorSpace, targetColorSpace ) {
1699
1651
 
1700
- },
1652
+ if ( this.enabled === false || sourceColorSpace === targetColorSpace || ! sourceColorSpace || ! targetColorSpace ) {
1701
1653
 
1702
- set workingColorSpace( colorSpace ) {
1654
+ return color;
1655
+
1656
+ }
1703
1657
 
1704
- if ( ! SUPPORTED_WORKING_COLOR_SPACES.has( colorSpace ) ) {
1658
+ if ( this.spaces[ sourceColorSpace ].transfer === SRGBTransfer ) {
1705
1659
 
1706
- throw new Error( `Unsupported working color space, "${ colorSpace }".` );
1660
+ color.r = SRGBToLinear( color.r );
1661
+ color.g = SRGBToLinear( color.g );
1662
+ color.b = SRGBToLinear( color.b );
1707
1663
 
1708
1664
  }
1709
1665
 
1710
- this._workingColorSpace = colorSpace;
1666
+ if ( this.spaces[ sourceColorSpace ].primaries !== this.spaces[ targetColorSpace ].primaries ) {
1711
1667
 
1712
- },
1668
+ color.applyMatrix3( this.spaces[ sourceColorSpace ].toXYZ );
1669
+ color.applyMatrix3( this.spaces[ targetColorSpace ].fromXYZ );
1713
1670
 
1714
- convert: function ( color, sourceColorSpace, targetColorSpace ) {
1671
+ }
1715
1672
 
1716
- if ( this.enabled === false || sourceColorSpace === targetColorSpace || ! sourceColorSpace || ! targetColorSpace ) {
1673
+ if ( this.spaces[ targetColorSpace ].transfer === SRGBTransfer ) {
1717
1674
 
1718
- return color;
1675
+ color.r = LinearToSRGB( color.r );
1676
+ color.g = LinearToSRGB( color.g );
1677
+ color.b = LinearToSRGB( color.b );
1719
1678
 
1720
1679
  }
1721
1680
 
1722
- const sourceToReference = COLOR_SPACES[ sourceColorSpace ].toReference;
1723
- const targetFromReference = COLOR_SPACES[ targetColorSpace ].fromReference;
1724
-
1725
- return targetFromReference( sourceToReference( color ) );
1681
+ return color;
1726
1682
 
1727
1683
  },
1728
1684
 
1729
1685
  fromWorkingColorSpace: function ( color, targetColorSpace ) {
1730
1686
 
1731
- return this.convert( color, this._workingColorSpace, targetColorSpace );
1687
+ return this.convert( color, this.workingColorSpace, targetColorSpace );
1732
1688
 
1733
1689
  },
1734
1690
 
1735
1691
  toWorkingColorSpace: function ( color, sourceColorSpace ) {
1736
1692
 
1737
- return this.convert( color, sourceColorSpace, this._workingColorSpace );
1693
+ return this.convert( color, sourceColorSpace, this.workingColorSpace );
1738
1694
 
1739
1695
  },
1740
1696
 
1741
1697
  getPrimaries: function ( colorSpace ) {
1742
1698
 
1743
- return COLOR_SPACES[ colorSpace ].primaries;
1699
+ return this.spaces[ colorSpace ].primaries;
1744
1700
 
1745
1701
  },
1746
1702
 
@@ -1748,18 +1704,45 @@ const ColorManagement = {
1748
1704
 
1749
1705
  if ( colorSpace === NoColorSpace ) return LinearTransfer;
1750
1706
 
1751
- return COLOR_SPACES[ colorSpace ].transfer;
1707
+ return this.spaces[ colorSpace ].transfer;
1752
1708
 
1753
1709
  },
1754
1710
 
1755
- getLuminanceCoefficients: function ( target, colorSpace = this._workingColorSpace ) {
1711
+ getLuminanceCoefficients: function ( target, colorSpace = this.workingColorSpace ) {
1756
1712
 
1757
- return target.fromArray( COLOR_SPACES[ colorSpace ].luminanceCoefficients );
1713
+ return target.fromArray( this.spaces[ colorSpace ].luminanceCoefficients );
1758
1714
 
1759
1715
  },
1760
1716
 
1761
- };
1717
+ define: function ( colorSpaces ) {
1762
1718
 
1719
+ Object.assign( this.spaces, colorSpaces );
1720
+
1721
+ },
1722
+
1723
+ // Internal APIs
1724
+
1725
+ _getMatrix: function ( targetMatrix, sourceColorSpace, targetColorSpace ) {
1726
+
1727
+ return targetMatrix
1728
+ .copy( this.spaces[ sourceColorSpace ].toXYZ )
1729
+ .multiply( this.spaces[ targetColorSpace ].fromXYZ );
1730
+
1731
+ },
1732
+
1733
+ _getDrawingBufferColorSpace: function ( colorSpace ) {
1734
+
1735
+ return this.spaces[ colorSpace ].outputColorSpaceConfig.drawingBufferColorSpace;
1736
+
1737
+ },
1738
+
1739
+ _getUnpackColorSpace: function ( colorSpace = this.workingColorSpace ) {
1740
+
1741
+ return this.spaces[ colorSpace ].workingColorSpaceConfig.unpackColorSpace;
1742
+
1743
+ }
1744
+
1745
+ };
1763
1746
 
1764
1747
  function SRGBToLinear( c ) {
1765
1748
 
@@ -1773,6 +1756,51 @@ function LinearToSRGB( c ) {
1773
1756
 
1774
1757
  }
1775
1758
 
1759
+ /******************************************************************************
1760
+ * sRGB definitions
1761
+ */
1762
+
1763
+ const REC709_PRIMARIES = [ 0.640, 0.330, 0.300, 0.600, 0.150, 0.060 ];
1764
+ const REC709_LUMINANCE_COEFFICIENTS = [ 0.2126, 0.7152, 0.0722 ];
1765
+ const D65 = [ 0.3127, 0.3290 ];
1766
+
1767
+ const LINEAR_REC709_TO_XYZ = /*@__PURE__*/ new Matrix3().set(
1768
+ 0.4123908, 0.3575843, 0.1804808,
1769
+ 0.2126390, 0.7151687, 0.0721923,
1770
+ 0.0193308, 0.1191948, 0.9505322
1771
+ );
1772
+
1773
+ const XYZ_TO_LINEAR_REC709 = /*@__PURE__*/ new Matrix3().set(
1774
+ 3.2409699, - 1.5373832, - 0.4986108,
1775
+ - 0.9692436, 1.8759675, 0.0415551,
1776
+ 0.0556301, - 0.2039770, 1.0569715
1777
+ );
1778
+
1779
+ ColorManagement.define( {
1780
+
1781
+ [ LinearSRGBColorSpace ]: {
1782
+ primaries: REC709_PRIMARIES,
1783
+ whitePoint: D65,
1784
+ transfer: LinearTransfer,
1785
+ toXYZ: LINEAR_REC709_TO_XYZ,
1786
+ fromXYZ: XYZ_TO_LINEAR_REC709,
1787
+ luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
1788
+ workingColorSpaceConfig: { unpackColorSpace: SRGBColorSpace },
1789
+ outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
1790
+ },
1791
+
1792
+ [ SRGBColorSpace ]: {
1793
+ primaries: REC709_PRIMARIES,
1794
+ whitePoint: D65,
1795
+ transfer: SRGBTransfer,
1796
+ toXYZ: LINEAR_REC709_TO_XYZ,
1797
+ fromXYZ: XYZ_TO_LINEAR_REC709,
1798
+ luminanceCoefficients: REC709_LUMINANCE_COEFFICIENTS,
1799
+ outputColorSpaceConfig: { drawingBufferColorSpace: SRGBColorSpace }
1800
+ },
1801
+
1802
+ } );
1803
+
1776
1804
  let _canvas;
1777
1805
 
1778
1806
  class ImageUtils {
@@ -2575,6 +2603,17 @@ class Vector4 {
2575
2603
 
2576
2604
  }
2577
2605
 
2606
+ divide( v ) {
2607
+
2608
+ this.x /= v.x;
2609
+ this.y /= v.y;
2610
+ this.z /= v.z;
2611
+ this.w /= v.w;
2612
+
2613
+ return this;
2614
+
2615
+ }
2616
+
2578
2617
  divideScalar( scalar ) {
2579
2618
 
2580
2619
  return this.multiplyScalar( 1 / scalar );
@@ -9162,6 +9201,20 @@ let _materialId = 0;
9162
9201
 
9163
9202
  class Material extends EventDispatcher {
9164
9203
 
9204
+ static get type() {
9205
+
9206
+ return 'Material';
9207
+
9208
+ }
9209
+
9210
+ get type() {
9211
+
9212
+ return this.constructor.type;
9213
+
9214
+ }
9215
+
9216
+ set type( _value ) { /* */ }
9217
+
9165
9218
  constructor() {
9166
9219
 
9167
9220
  super();
@@ -9173,7 +9226,6 @@ class Material extends EventDispatcher {
9173
9226
  this.uuid = generateUUID();
9174
9227
 
9175
9228
  this.name = '';
9176
- this.type = 'Material';
9177
9229
 
9178
9230
  this.blending = NormalBlending;
9179
9231
  this.side = FrontSide;
@@ -9685,14 +9737,18 @@ class Material extends EventDispatcher {
9685
9737
 
9686
9738
  class MeshBasicMaterial extends Material {
9687
9739
 
9740
+ static get type() {
9741
+
9742
+ return 'MeshBasicMaterial';
9743
+
9744
+ }
9745
+
9688
9746
  constructor( parameters ) {
9689
9747
 
9690
9748
  super();
9691
9749
 
9692
9750
  this.isMeshBasicMaterial = true;
9693
9751
 
9694
- this.type = 'MeshBasicMaterial';
9695
-
9696
9752
  this.color = new Color( 0xffffff ); // emissive
9697
9753
 
9698
9754
  this.map = null;
@@ -10565,6 +10621,7 @@ class BufferGeometry extends EventDispatcher {
10565
10621
  this.type = 'BufferGeometry';
10566
10622
 
10567
10623
  this.index = null;
10624
+ this.indirect = null;
10568
10625
  this.attributes = {};
10569
10626
 
10570
10627
  this.morphAttributes = {};
@@ -10603,6 +10660,20 @@ class BufferGeometry extends EventDispatcher {
10603
10660
 
10604
10661
  }
10605
10662
 
10663
+ setIndirect( indirect ) {
10664
+
10665
+ this.indirect = indirect;
10666
+
10667
+ return this;
10668
+
10669
+ }
10670
+
10671
+ getIndirect() {
10672
+
10673
+ return this.indirect;
10674
+
10675
+ }
10676
+
10606
10677
  getAttribute( name ) {
10607
10678
 
10608
10679
  return this.attributes[ name ];
@@ -10802,16 +10873,39 @@ class BufferGeometry extends EventDispatcher {
10802
10873
 
10803
10874
  setFromPoints( points ) {
10804
10875
 
10805
- const position = [];
10876
+ const positionAttribute = this.getAttribute( 'position' );
10806
10877
 
10807
- for ( let i = 0, l = points.length; i < l; i ++ ) {
10878
+ if ( positionAttribute === undefined ) {
10808
10879
 
10809
- const point = points[ i ];
10810
- position.push( point.x, point.y, point.z || 0 );
10880
+ const position = [];
10811
10881
 
10812
- }
10882
+ for ( let i = 0, l = points.length; i < l; i ++ ) {
10883
+
10884
+ const point = points[ i ];
10885
+ position.push( point.x, point.y, point.z || 0 );
10886
+
10887
+ }
10888
+
10889
+ this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
10890
+
10891
+ } else {
10892
+
10893
+ for ( let i = 0, l = positionAttribute.count; i < l; i ++ ) {
10894
+
10895
+ const point = points[ i ];
10896
+ positionAttribute.setXYZ( i, point.x, point.y, point.z || 0 );
10897
+
10898
+ }
10899
+
10900
+ if ( points.length > positionAttribute.count ) {
10813
10901
 
10814
- this.setAttribute( 'position', new Float32BufferAttribute( position, 3 ) );
10902
+ console.warn( 'THREE.BufferGeometry: Buffer size too small for points data. Use .dispose() and create a new geometry.' );
10903
+
10904
+ }
10905
+
10906
+ positionAttribute.needsUpdate = true;
10907
+
10908
+ }
10815
10909
 
10816
10910
  return this;
10817
10911
 
@@ -12291,14 +12385,18 @@ var default_fragment = "void main() {\n\tgl_FragColor = vec4( 1.0, 0.0, 0.0, 1.0
12291
12385
 
12292
12386
  class ShaderMaterial extends Material {
12293
12387
 
12388
+ static get type() {
12389
+
12390
+ return 'ShaderMaterial';
12391
+
12392
+ }
12393
+
12294
12394
  constructor( parameters ) {
12295
12395
 
12296
12396
  super();
12297
12397
 
12298
12398
  this.isShaderMaterial = true;
12299
12399
 
12300
- this.type = 'ShaderMaterial';
12301
-
12302
12400
  this.defines = {};
12303
12401
  this.uniforms = {};
12304
12402
  this.uniformsGroups = [];
@@ -13939,13 +14037,13 @@ var displacementmap_pars_vertex = "#ifdef USE_DISPLACEMENTMAP\n\tuniform sampler
13939
14037
 
13940
14038
  var displacementmap_vertex = "#ifdef USE_DISPLACEMENTMAP\n\ttransformed += normalize( objectNormal ) * ( texture2D( displacementMap, vDisplacementMapUv ).x * displacementScale + displacementBias );\n#endif";
13941
14039
 
13942
- var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
14040
+ var emissivemap_fragment = "#ifdef USE_EMISSIVEMAP\n\tvec4 emissiveColor = texture2D( emissiveMap, vEmissiveMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE_EMISSIVE\n\t\temissiveColor = sRGBTransferEOTF( emissiveColor );\n\t#endif\n\ttotalEmissiveRadiance *= emissiveColor.rgb;\n#endif";
13943
14041
 
13944
14042
  var emissivemap_pars_fragment = "#ifdef USE_EMISSIVEMAP\n\tuniform sampler2D emissiveMap;\n#endif";
13945
14043
 
13946
14044
  var colorspace_fragment = "gl_FragColor = linearToOutputTexel( gl_FragColor );";
13947
14045
 
13948
- var colorspace_pars_fragment = "\nconst mat3 LINEAR_SRGB_TO_LINEAR_DISPLAY_P3 = mat3(\n\tvec3( 0.8224621, 0.177538, 0.0 ),\n\tvec3( 0.0331941, 0.9668058, 0.0 ),\n\tvec3( 0.0170827, 0.0723974, 0.9105199 )\n);\nconst mat3 LINEAR_DISPLAY_P3_TO_LINEAR_SRGB = mat3(\n\tvec3( 1.2249401, - 0.2249404, 0.0 ),\n\tvec3( - 0.0420569, 1.0420571, 0.0 ),\n\tvec3( - 0.0196376, - 0.0786361, 1.0982735 )\n);\nvec4 LinearSRGBToLinearDisplayP3( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_SRGB_TO_LINEAR_DISPLAY_P3, value.a );\n}\nvec4 LinearDisplayP3ToLinearSRGB( in vec4 value ) {\n\treturn vec4( value.rgb * LINEAR_DISPLAY_P3_TO_LINEAR_SRGB, value.a );\n}\nvec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}";
14046
+ var colorspace_pars_fragment = "vec4 LinearTransferOETF( in vec4 value ) {\n\treturn value;\n}\nvec4 sRGBTransferEOTF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), value.rgb * 0.0773993808, vec3( lessThanEqual( value.rgb, vec3( 0.04045 ) ) ) ), value.a );\n}\nvec4 sRGBTransferOETF( in vec4 value ) {\n\treturn vec4( mix( pow( value.rgb, vec3( 0.41666 ) ) * 1.055 - vec3( 0.055 ), value.rgb * 12.92, vec3( lessThanEqual( value.rgb, vec3( 0.0031308 ) ) ) ), value.a );\n}";
13949
14047
 
13950
14048
  var envmap_fragment = "#ifdef USE_ENVMAP\n\t#ifdef ENV_WORLDPOS\n\t\tvec3 cameraToFrag;\n\t\tif ( isOrthographic ) {\n\t\t\tcameraToFrag = normalize( vec3( - viewMatrix[ 0 ][ 2 ], - viewMatrix[ 1 ][ 2 ], - viewMatrix[ 2 ][ 2 ] ) );\n\t\t} else {\n\t\t\tcameraToFrag = normalize( vWorldPosition - cameraPosition );\n\t\t}\n\t\tvec3 worldNormal = inverseTransformDirection( normal, viewMatrix );\n\t\t#ifdef ENVMAP_MODE_REFLECTION\n\t\t\tvec3 reflectVec = reflect( cameraToFrag, worldNormal );\n\t\t#else\n\t\t\tvec3 reflectVec = refract( cameraToFrag, worldNormal, refractionRatio );\n\t\t#endif\n\t#else\n\t\tvec3 reflectVec = vReflect;\n\t#endif\n\t#ifdef ENVMAP_TYPE_CUBE\n\t\tvec4 envColor = textureCube( envMap, envMapRotation * vec3( flipEnvMap * reflectVec.x, reflectVec.yz ) );\n\t#else\n\t\tvec4 envColor = vec4( 0.0 );\n\t#endif\n\t#ifdef ENVMAP_BLENDING_MULTIPLY\n\t\toutgoingLight = mix( outgoingLight, outgoingLight * envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_MIX )\n\t\toutgoingLight = mix( outgoingLight, envColor.xyz, specularStrength * reflectivity );\n\t#elif defined( ENVMAP_BLENDING_ADD )\n\t\toutgoingLight += envColor.xyz * specularStrength * reflectivity;\n\t#endif\n#endif";
13951
14049
 
@@ -14003,7 +14101,7 @@ var logdepthbuf_pars_vertex = "#ifdef USE_LOGDEPTHBUF\n\tvarying float vFragDept
14003
14101
 
14004
14102
  var logdepthbuf_vertex = "#ifdef USE_LOGDEPTHBUF\n\tvFragDepth = 1.0 + gl_Position.w;\n\tvIsPerspective = float( isPerspectiveMatrix( projectionMatrix ) );\n#endif";
14005
14103
 
14006
- var map_fragment = "#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = vec4( mix( pow( sampledDiffuseColor.rgb * 0.9478672986 + vec3( 0.0521327014 ), vec3( 2.4 ) ), sampledDiffuseColor.rgb * 0.0773993808, vec3( lessThanEqual( sampledDiffuseColor.rgb, vec3( 0.04045 ) ) ) ), sampledDiffuseColor.w );\n\t\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif";
14104
+ var map_fragment = "#ifdef USE_MAP\n\tvec4 sampledDiffuseColor = texture2D( map, vMapUv );\n\t#ifdef DECODE_VIDEO_TEXTURE\n\t\tsampledDiffuseColor = sRGBTransferEOTF( sampledDiffuseColor );\n\t#endif\n\tdiffuseColor *= sampledDiffuseColor;\n#endif";
14007
14105
 
14008
14106
  var map_pars_fragment = "#ifdef USE_MAP\n\tuniform sampler2D map;\n#endif";
14009
14107
 
@@ -15811,15 +15909,11 @@ function WebGLBufferRenderer( gl, extensions, info ) {
15811
15909
  let elementCount = 0;
15812
15910
  for ( let i = 0; i < drawCount; i ++ ) {
15813
15911
 
15814
- elementCount += counts[ i ];
15912
+ elementCount += counts[ i ] * primcount[ i ];
15815
15913
 
15816
15914
  }
15817
15915
 
15818
- for ( let i = 0; i < primcount.length; i ++ ) {
15819
-
15820
- info.update( elementCount, mode, primcount[ i ] );
15821
-
15822
- }
15916
+ info.update( elementCount, mode, 1 );
15823
15917
 
15824
15918
  }
15825
15919
 
@@ -15929,13 +16023,6 @@ function WebGLCapabilities( gl, extensions, parameters, utils ) {
15929
16023
  const logarithmicDepthBuffer = parameters.logarithmicDepthBuffer === true;
15930
16024
  const reverseDepthBuffer = parameters.reverseDepthBuffer === true && extensions.has( 'EXT_clip_control' );
15931
16025
 
15932
- if ( reverseDepthBuffer === true ) {
15933
-
15934
- const ext = extensions.get( 'EXT_clip_control' );
15935
- ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT );
15936
-
15937
- }
15938
-
15939
16026
  const maxTextures = gl.getParameter( gl.MAX_TEXTURE_IMAGE_UNITS );
15940
16027
  const maxVertexTextures = gl.getParameter( gl.MAX_VERTEX_TEXTURE_IMAGE_UNITS );
15941
16028
  const maxTextureSize = gl.getParameter( gl.MAX_TEXTURE_SIZE );
@@ -17761,15 +17848,11 @@ function WebGLIndexedBufferRenderer( gl, extensions, info ) {
17761
17848
  let elementCount = 0;
17762
17849
  for ( let i = 0; i < drawCount; i ++ ) {
17763
17850
 
17764
- elementCount += counts[ i ];
17851
+ elementCount += counts[ i ] * primcount[ i ];
17765
17852
 
17766
17853
  }
17767
17854
 
17768
- for ( let i = 0; i < primcount.length; i ++ ) {
17769
-
17770
- info.update( elementCount, mode, primcount[ i ] );
17771
-
17772
- }
17855
+ info.update( elementCount, mode, 1 );
17773
17856
 
17774
17857
  }
17775
17858
 
@@ -19449,40 +19532,25 @@ function handleSource( string, errorLine ) {
19449
19532
 
19450
19533
  }
19451
19534
 
19452
- function getEncodingComponents( colorSpace ) {
19453
-
19454
- const workingPrimaries = ColorManagement.getPrimaries( ColorManagement.workingColorSpace );
19455
- const encodingPrimaries = ColorManagement.getPrimaries( colorSpace );
19456
-
19457
- let gamutMapping;
19458
-
19459
- if ( workingPrimaries === encodingPrimaries ) {
19460
-
19461
- gamutMapping = '';
19462
-
19463
- } else if ( workingPrimaries === P3Primaries && encodingPrimaries === Rec709Primaries ) {
19464
-
19465
- gamutMapping = 'LinearDisplayP3ToLinearSRGB';
19535
+ const _m0 = /*@__PURE__*/ new Matrix3();
19466
19536
 
19467
- } else if ( workingPrimaries === Rec709Primaries && encodingPrimaries === P3Primaries ) {
19537
+ function getEncodingComponents( colorSpace ) {
19468
19538
 
19469
- gamutMapping = 'LinearSRGBToLinearDisplayP3';
19539
+ ColorManagement._getMatrix( _m0, ColorManagement.workingColorSpace, colorSpace );
19470
19540
 
19471
- }
19541
+ const encodingMatrix = `mat3( ${ _m0.elements.map( ( v ) => v.toFixed( 4 ) ) } )`;
19472
19542
 
19473
- switch ( colorSpace ) {
19543
+ switch ( ColorManagement.getTransfer( colorSpace ) ) {
19474
19544
 
19475
- case LinearSRGBColorSpace:
19476
- case LinearDisplayP3ColorSpace:
19477
- return [ gamutMapping, 'LinearTransferOETF' ];
19545
+ case LinearTransfer:
19546
+ return [ encodingMatrix, 'LinearTransferOETF' ];
19478
19547
 
19479
- case SRGBColorSpace:
19480
- case DisplayP3ColorSpace:
19481
- return [ gamutMapping, 'sRGBTransferOETF' ];
19548
+ case SRGBTransfer:
19549
+ return [ encodingMatrix, 'sRGBTransferOETF' ];
19482
19550
 
19483
19551
  default:
19484
- console.warn( 'THREE.WebGLProgram: Unsupported color space:', colorSpace );
19485
- return [ gamutMapping, 'LinearTransferOETF' ];
19552
+ console.warn( 'THREE.WebGLProgram: Unsupported color space: ', colorSpace );
19553
+ return [ encodingMatrix, 'LinearTransferOETF' ];
19486
19554
 
19487
19555
  }
19488
19556
 
@@ -19515,7 +19583,16 @@ function getShaderErrors( gl, shader, type ) {
19515
19583
  function getTexelEncodingFunction( functionName, colorSpace ) {
19516
19584
 
19517
19585
  const components = getEncodingComponents( colorSpace );
19518
- return `vec4 ${functionName}( vec4 value ) { return ${components[ 0 ]}( ${components[ 1 ]}( value ) ); }`;
19586
+
19587
+ return [
19588
+
19589
+ `vec4 ${functionName}( vec4 value ) {`,
19590
+
19591
+ ` return ${components[ 1 ]}( vec4( value.rgb * ${components[ 0 ]}, value.a ) );`,
19592
+
19593
+ '}',
19594
+
19595
+ ].join( '\n' );
19519
19596
 
19520
19597
  }
19521
19598
 
@@ -20243,6 +20320,7 @@ function WebGLProgram( renderer, cacheKey, parameters, bindingStates ) {
20243
20320
  parameters.numLightProbes > 0 ? '#define USE_LIGHT_PROBES' : '',
20244
20321
 
20245
20322
  parameters.decodeVideoTexture ? '#define DECODE_VIDEO_TEXTURE' : '',
20323
+ parameters.decodeVideoTextureEmissive ? '#define DECODE_VIDEO_TEXTURE_EMISSIVE' : '',
20246
20324
 
20247
20325
  parameters.logarithmicDepthBuffer ? '#define USE_LOGDEPTHBUF' : '',
20248
20326
  parameters.reverseDepthBuffer ? '#define USE_REVERSEDEPTHBUF' : '',
@@ -20686,7 +20764,6 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20686
20764
  const programs = [];
20687
20765
 
20688
20766
  const logarithmicDepthBuffer = capabilities.logarithmicDepthBuffer;
20689
- const reverseDepthBuffer = capabilities.reverseDepthBuffer;
20690
20767
  const SUPPORTS_VERTEX_TEXTURES = capabilities.vertexTextures;
20691
20768
 
20692
20769
  let precision = capabilities.precision;
@@ -20781,6 +20858,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
20781
20858
  }
20782
20859
 
20783
20860
  const currentRenderTarget = renderer.getRenderTarget();
20861
+ const reverseDepthBuffer = renderer.state.buffers.depth.getReversed();
20784
20862
 
20785
20863
  const numMultiviewViews = currentRenderTarget && currentRenderTarget.isWebGLMultiviewRenderTarget ? currentRenderTarget.numViews : 0;
20786
20864
 
@@ -21016,6 +21094,7 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
21016
21094
  toneMapping: toneMapping,
21017
21095
 
21018
21096
  decodeVideoTexture: HAS_MAP && ( material.map.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.map.colorSpace ) === SRGBTransfer ),
21097
+ decodeVideoTextureEmissive: HAS_EMISSIVEMAP && ( material.emissiveMap.isVideoTexture === true ) && ( ColorManagement.getTransfer( material.emissiveMap.colorSpace ) === SRGBTransfer ),
21019
21098
 
21020
21099
  premultipliedAlpha: material.premultipliedAlpha,
21021
21100
 
@@ -21233,8 +21312,10 @@ function WebGLPrograms( renderer, cubemaps, cubeuvmaps, extensions, capabilities
21233
21312
  _programLayers.enable( 18 );
21234
21313
  if ( parameters.decodeVideoTexture )
21235
21314
  _programLayers.enable( 19 );
21236
- if ( parameters.alphaToCoverage )
21315
+ if ( parameters.decodeVideoTextureEmissive )
21237
21316
  _programLayers.enable( 20 );
21317
+ if ( parameters.alphaToCoverage )
21318
+ _programLayers.enable( 21 );
21238
21319
  if ( parameters.numMultiviewViews )
21239
21320
  _programLayers.enable( 21 );
21240
21321
 
@@ -22294,14 +22375,18 @@ function WebGLRenderStates( extensions ) {
22294
22375
 
22295
22376
  class MeshDepthMaterial extends Material {
22296
22377
 
22378
+ static get type() {
22379
+
22380
+ return 'MeshDepthMaterial';
22381
+
22382
+ }
22383
+
22297
22384
  constructor( parameters ) {
22298
22385
 
22299
22386
  super();
22300
22387
 
22301
22388
  this.isMeshDepthMaterial = true;
22302
22389
 
22303
- this.type = 'MeshDepthMaterial';
22304
-
22305
22390
  this.depthPacking = BasicDepthPacking;
22306
22391
 
22307
22392
  this.map = null;
@@ -22344,14 +22429,18 @@ class MeshDepthMaterial extends Material {
22344
22429
 
22345
22430
  class MeshDistanceMaterial extends Material {
22346
22431
 
22432
+ static get type() {
22433
+
22434
+ return 'MeshDistanceMaterial';
22435
+
22436
+ }
22437
+
22347
22438
  constructor( parameters ) {
22348
22439
 
22349
22440
  super();
22350
22441
 
22351
22442
  this.isMeshDistanceMaterial = true;
22352
22443
 
22353
- this.type = 'MeshDistanceMaterial';
22354
-
22355
22444
  this.map = null;
22356
22445
 
22357
22446
  this.alphaMap = null;
@@ -22806,7 +22895,7 @@ const reversedFuncs = {
22806
22895
  [ GreaterEqualDepth ]: LessEqualDepth,
22807
22896
  };
22808
22897
 
22809
- function WebGLState( gl ) {
22898
+ function WebGLState( gl, extensions ) {
22810
22899
 
22811
22900
  function ColorBuffer() {
22812
22901
 
@@ -22880,10 +22969,36 @@ function WebGLState( gl ) {
22880
22969
 
22881
22970
  setReversed: function ( value ) {
22882
22971
 
22972
+ if ( reversed !== value ) {
22973
+
22974
+ const ext = extensions.get( 'EXT_clip_control' );
22975
+
22976
+ if ( reversed ) {
22977
+
22978
+ ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.ZERO_TO_ONE_EXT );
22979
+
22980
+ } else {
22981
+
22982
+ ext.clipControlEXT( ext.LOWER_LEFT_EXT, ext.NEGATIVE_ONE_TO_ONE_EXT );
22983
+
22984
+ }
22985
+
22986
+ const oldDepth = currentDepthClear;
22987
+ currentDepthClear = null;
22988
+ this.setClear( oldDepth );
22989
+
22990
+ }
22991
+
22883
22992
  reversed = value;
22884
22993
 
22885
22994
  },
22886
22995
 
22996
+ getReversed: function () {
22997
+
22998
+ return reversed;
22999
+
23000
+ },
23001
+
22887
23002
  setTest: function ( depthTest ) {
22888
23003
 
22889
23004
  if ( depthTest ) {
@@ -22979,6 +23094,12 @@ function WebGLState( gl ) {
22979
23094
 
22980
23095
  if ( currentDepthClear !== depth ) {
22981
23096
 
23097
+ if ( reversed ) {
23098
+
23099
+ depth = 1 - depth;
23100
+
23101
+ }
23102
+
22982
23103
  gl.clearDepth( depth );
22983
23104
  currentDepthClear = depth;
22984
23105
 
@@ -22993,6 +23114,7 @@ function WebGLState( gl ) {
22993
23114
  currentDepthMask = null;
22994
23115
  currentDepthFunc = null;
22995
23116
  currentDepthClear = null;
23117
+ reversed = false;
22996
23118
 
22997
23119
  }
22998
23120
 
@@ -23963,6 +24085,9 @@ function WebGLState( gl ) {
23963
24085
 
23964
24086
  gl.depthMask( true );
23965
24087
  gl.depthFunc( gl.LESS );
24088
+
24089
+ depthBuffer.setReversed( false );
24090
+
23966
24091
  gl.clearDepth( 1 );
23967
24092
 
23968
24093
  gl.stencilMask( 0xffffffff );
@@ -24398,7 +24523,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24398
24523
 
24399
24524
  function textureNeedsGenerateMipmaps( texture ) {
24400
24525
 
24401
- return texture.generateMipmaps && texture.minFilter !== NearestFilter && texture.minFilter !== LinearFilter;
24526
+ return texture.generateMipmaps;
24402
24527
 
24403
24528
  }
24404
24529
 
@@ -24408,6 +24533,15 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24408
24533
 
24409
24534
  }
24410
24535
 
24536
+ function getTargetType( texture ) {
24537
+
24538
+ if ( texture.isWebGLCubeRenderTarget ) return _gl.TEXTURE_CUBE_MAP;
24539
+ if ( texture.isWebGL3DRenderTarget ) return _gl.TEXTURE_3D;
24540
+ if ( texture.isWebGLArrayRenderTarget || texture.isCompressedArrayTexture ) return _gl.TEXTURE_2D_ARRAY;
24541
+ return _gl.TEXTURE_2D;
24542
+
24543
+ }
24544
+
24411
24545
  function getInternalFormat( internalFormatName, glFormat, glType, colorSpace, forceLinearTransfer = false ) {
24412
24546
 
24413
24547
  if ( internalFormatName !== null ) {
@@ -24667,6 +24801,8 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
24667
24801
 
24668
24802
  renderTarget.depthTexture.dispose();
24669
24803
 
24804
+ properties.remove( renderTarget.depthTexture );
24805
+
24670
24806
  }
24671
24807
 
24672
24808
  if ( renderTarget.isWebGLCubeRenderTarget ) {
@@ -25216,7 +25352,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25216
25352
  layerIndex * layerByteLength / mipmap.data.BYTES_PER_ELEMENT,
25217
25353
  ( layerIndex + 1 ) * layerByteLength / mipmap.data.BYTES_PER_ELEMENT
25218
25354
  );
25219
- state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, layerData, 0, 0 );
25355
+ state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, layerIndex, mipmap.width, mipmap.height, 1, glFormat, layerData );
25220
25356
 
25221
25357
  }
25222
25358
 
@@ -25224,7 +25360,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25224
25360
 
25225
25361
  } else {
25226
25362
 
25227
- state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data, 0, 0 );
25363
+ state.compressedTexSubImage3D( _gl.TEXTURE_2D_ARRAY, i, 0, 0, 0, mipmap.width, mipmap.height, image.depth, glFormat, mipmap.data );
25228
25364
 
25229
25365
  }
25230
25366
 
@@ -25740,6 +25876,9 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25740
25876
  const glType = utils.convert( texture.type );
25741
25877
  const glInternalFormat = getInternalFormat( texture.internalFormat, glFormat, glType, texture.colorSpace );
25742
25878
  const renderTargetProperties = properties.get( renderTarget );
25879
+ const textureProperties = properties.get( texture );
25880
+
25881
+ textureProperties.__renderTarget = renderTarget;
25743
25882
 
25744
25883
  if ( ! renderTargetProperties.__hasExternalTextures ) {
25745
25884
 
@@ -25770,11 +25909,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25770
25909
 
25771
25910
  if ( multisampled ) {
25772
25911
 
25773
- multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ), 0, renderTarget.numViews );
25912
+ multiviewExt.framebufferTextureMultisampleMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, 0, getRenderTargetSamples( renderTarget ), 0, renderTarget.numViews );
25774
25913
 
25775
25914
  } else {
25776
25915
 
25777
- multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( texture ).__webglTexture, 0, 0, renderTarget.numViews );
25916
+ multiviewExt.framebufferTextureMultiviewOVR( _gl.FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, textureProperties.__webglTexture, 0, 0, renderTarget.numViews );
25778
25917
 
25779
25918
  }
25780
25919
 
@@ -25782,11 +25921,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25782
25921
 
25783
25922
  if ( multisampled ) {
25784
25923
 
25785
- multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
25924
+ multisampledRTTExt.framebufferTexture2DMultisampleEXT( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, 0, getRenderTargetSamples( renderTarget ) );
25786
25925
 
25787
25926
  } else {
25788
25927
 
25789
- _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, properties.get( texture ).__webglTexture, level );
25928
+ _gl.framebufferTexture2D( _gl.FRAMEBUFFER, attachment, textureTarget, textureProperties.__webglTexture, level );
25790
25929
 
25791
25930
  }
25792
25931
 
@@ -25929,8 +26068,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25929
26068
 
25930
26069
  }
25931
26070
 
26071
+ const textureProperties = properties.get( renderTarget.depthTexture );
26072
+ textureProperties.__renderTarget = renderTarget;
26073
+
25932
26074
  // upload an empty depth texture with framebuffer size
25933
- if ( ! properties.get( renderTarget.depthTexture ).__webglTexture ||
26075
+ if ( ! textureProperties.__webglTexture ||
25934
26076
  renderTarget.depthTexture.image.width !== renderTarget.width ||
25935
26077
  renderTarget.depthTexture.image.height !== renderTarget.height ) {
25936
26078
 
@@ -25951,7 +26093,7 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
25951
26093
 
25952
26094
  }
25953
26095
 
25954
- const webglDepthTexture = properties.get( renderTarget.depthTexture ).__webglTexture;
26096
+ const webglDepthTexture = textureProperties.__webglTexture;
25955
26097
  const samples = getRenderTargetSamples( renderTarget );
25956
26098
 
25957
26099
  if ( renderTarget.isWebGLMultiviewRenderTarget === true ) {
@@ -26387,11 +26529,11 @@ function WebGLTextures( _gl, extensions, state, properties, capabilities, utils,
26387
26529
 
26388
26530
  if ( textureNeedsGenerateMipmaps( texture ) ) {
26389
26531
 
26390
- const target = renderTarget.isWebGLCubeRenderTarget ? _gl.TEXTURE_CUBE_MAP : _gl.TEXTURE_2D;
26532
+ const targetType = getTargetType( renderTarget );
26391
26533
  const webglTexture = properties.get( texture ).__webglTexture;
26392
26534
 
26393
- state.bindTexture( target, webglTexture );
26394
- generateMipmap( target );
26535
+ state.bindTexture( targetType, webglTexture );
26536
+ generateMipmap( targetType );
26395
26537
  state.unbindTexture();
26396
26538
 
26397
26539
  }
@@ -26838,20 +26980,6 @@ function WebGLUtils( gl, extensions ) {
26838
26980
 
26839
26981
  }
26840
26982
 
26841
- class Group extends Object3D {
26842
-
26843
- constructor() {
26844
-
26845
- super();
26846
-
26847
- this.isGroup = true;
26848
-
26849
- this.type = 'Group';
26850
-
26851
- }
26852
-
26853
- }
26854
-
26855
26983
  class ArrayCamera extends PerspectiveCamera {
26856
26984
 
26857
26985
  constructor( array = [] ) {
@@ -26866,553 +26994,6 @@ class ArrayCamera extends PerspectiveCamera {
26866
26994
 
26867
26995
  }
26868
26996
 
26869
- /**
26870
- * @author jsantell / https://www.jsantell.com/
26871
- * @author mrdoob / http://mrdoob.com/
26872
- */
26873
-
26874
-
26875
- var cameraLPos = new Vector3();
26876
- var cameraRPos = new Vector3();
26877
-
26878
- /**
26879
- * Assumes 2 cameras that are parallel and share an X-axis, and that
26880
- * the cameras' projection and world matrices have already been set.
26881
- * And that near and far planes are identical for both cameras.
26882
- * Visualization of this technique: https://computergraphics.stackexchange.com/a/4765
26883
- */
26884
- function setProjectionFromUnion( camera, cameraL, cameraR ) {
26885
-
26886
- cameraLPos.setFromMatrixPosition( cameraL.matrixWorld );
26887
- cameraRPos.setFromMatrixPosition( cameraR.matrixWorld );
26888
-
26889
- var ipd = cameraLPos.distanceTo( cameraRPos );
26890
-
26891
- var projL = cameraL.projectionMatrix.elements;
26892
- var projR = cameraR.projectionMatrix.elements;
26893
-
26894
- // VR systems will have identical far and near planes, and
26895
- // most likely identical top and bottom frustum extents.
26896
- // Use the left camera for these values.
26897
- var near = projL[ 14 ] / ( projL[ 10 ] - 1 );
26898
- var far = projL[ 14 ] / ( projL[ 10 ] + 1 );
26899
- var topFov = ( projL[ 9 ] + 1 ) / projL[ 5 ];
26900
- var bottomFov = ( projL[ 9 ] - 1 ) / projL[ 5 ];
26901
-
26902
- var leftFov = ( projL[ 8 ] - 1 ) / projL[ 0 ];
26903
- var rightFov = ( projR[ 8 ] + 1 ) / projR[ 0 ];
26904
- var left = near * leftFov;
26905
- var right = near * rightFov;
26906
-
26907
- // Calculate the new camera's position offset from the
26908
- // left camera. xOffset should be roughly half `ipd`.
26909
- var zOffset = ipd / ( - leftFov + rightFov );
26910
- var xOffset = zOffset * - leftFov;
26911
-
26912
- // TODO: Better way to apply this offset?
26913
- cameraL.matrixWorld.decompose( camera.position, camera.quaternion, camera.scale );
26914
- camera.translateX( xOffset );
26915
- camera.translateZ( zOffset );
26916
- camera.matrixWorld.compose( camera.position, camera.quaternion, camera.scale );
26917
- camera.matrixWorldInverse.copy( camera.matrixWorld ).invert();
26918
-
26919
- // Find the union of the frustum values of the cameras and scale
26920
- // the values so that the near plane's position does not change in world space,
26921
- // although must now be relative to the new union camera.
26922
- var near2 = near + zOffset;
26923
- var far2 = far + zOffset;
26924
- var left2 = left - xOffset;
26925
- var right2 = right + ( ipd - xOffset );
26926
- var top2 = topFov * far / far2 * near2;
26927
- var bottom2 = bottomFov * far / far2 * near2;
26928
-
26929
- camera.projectionMatrix.makePerspective( left2, right2, top2, bottom2, near2, far2 );
26930
-
26931
- }
26932
-
26933
- /**
26934
- * @author mrdoob / http://mrdoob.com/
26935
- */
26936
-
26937
-
26938
- function WebVRManager( renderer ) {
26939
-
26940
- var renderWidth, renderHeight;
26941
- var scope = this;
26942
-
26943
- var device = null;
26944
- var frameData = null;
26945
-
26946
- var poseTarget = null;
26947
-
26948
- var controllers = [];
26949
- var standingMatrix = new Matrix4();
26950
- var standingMatrixInverse = new Matrix4();
26951
-
26952
- var framebufferScaleFactor = 1.0;
26953
-
26954
- var referenceSpaceType = 'local-floor';
26955
-
26956
- if ( typeof window !== 'undefined' && 'VRFrameData' in window ) {
26957
-
26958
- frameData = new window.VRFrameData();
26959
- window.addEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange, false );
26960
-
26961
- }
26962
-
26963
- var matrixWorldInverse = new Matrix4();
26964
- var tempQuaternion = new Quaternion();
26965
- var tempPosition = new Vector3();
26966
-
26967
- var cameraL = new PerspectiveCamera();
26968
- cameraL.viewport = new Vector4();
26969
- cameraL.layers.enable( 1 );
26970
-
26971
- var cameraR = new PerspectiveCamera();
26972
- cameraR.viewport = new Vector4();
26973
- cameraR.layers.enable( 2 );
26974
-
26975
- var cameraVR = new ArrayCamera( [ cameraL, cameraR ] );
26976
- cameraVR.layers.enable( 1 );
26977
- cameraVR.layers.enable( 2 );
26978
-
26979
- var currentSize = new Vector2(), currentPixelRatio;
26980
-
26981
- function onVRDisplayPresentChange() {
26982
-
26983
- var isPresenting = scope.isPresenting = device !== null && device.isPresenting === true;
26984
-
26985
- if ( isPresenting ) {
26986
-
26987
- var eyeParameters = device.getEyeParameters( 'left' );
26988
- renderWidth = 2 * eyeParameters.renderWidth * framebufferScaleFactor;
26989
- renderHeight = eyeParameters.renderHeight * framebufferScaleFactor;
26990
-
26991
- currentPixelRatio = renderer.getPixelRatio();
26992
- renderer.getSize( currentSize );
26993
-
26994
- renderer.setDrawingBufferSize( renderWidth, renderHeight, 1 );
26995
-
26996
- cameraL.viewport.set( 0, 0, renderWidth / 2, renderHeight );
26997
- cameraR.viewport.set( renderWidth / 2, 0, renderWidth / 2, renderHeight );
26998
-
26999
- animation.start();
27000
-
27001
- scope.dispatchEvent( { type: 'sessionstart' } );
27002
-
27003
- } else {
27004
-
27005
- if ( scope.enabled ) {
27006
-
27007
- renderer.setDrawingBufferSize( currentSize.width, currentSize.height, currentPixelRatio );
27008
-
27009
- }
27010
-
27011
- animation.stop();
27012
-
27013
- scope.dispatchEvent( { type: 'sessionend' } );
27014
-
27015
- }
27016
-
27017
- }
27018
-
27019
- //
27020
-
27021
- var triggers = [];
27022
- var grips = [];
27023
-
27024
- function findGamepad( id ) {
27025
-
27026
- var gamepads = navigator.getGamepads && navigator.getGamepads();
27027
-
27028
- for ( var i = 0, l = gamepads.length; i < l; i ++ ) {
27029
-
27030
- var gamepad = gamepads[ i ];
27031
-
27032
- if ( gamepad && ( gamepad.id === 'Daydream Controller' ||
27033
- gamepad.id === 'Gear VR Controller' || gamepad.id === 'Oculus Go Controller' ||
27034
- gamepad.id === 'OpenVR Gamepad' || gamepad.id.startsWith( 'Oculus Touch' ) ||
27035
- gamepad.id.startsWith( 'HTC Vive Focus' ) ||
27036
- gamepad.id.startsWith( 'Spatial Controller' ) ) ) {
27037
-
27038
- var hand = gamepad.hand;
27039
-
27040
- if ( id === 0 && ( hand === '' || hand === 'right' ) ) return gamepad;
27041
- if ( id === 1 && ( hand === 'left' ) ) return gamepad;
27042
-
27043
- }
27044
-
27045
- }
27046
-
27047
- }
27048
-
27049
- function updateControllers() {
27050
-
27051
- for ( var i = 0; i < controllers.length; i ++ ) {
27052
-
27053
- var controller = controllers[ i ];
27054
-
27055
- var gamepad = findGamepad( i );
27056
-
27057
- if ( gamepad !== undefined && gamepad.pose !== undefined ) {
27058
-
27059
- if ( gamepad.pose === null ) return;
27060
-
27061
- // Pose
27062
-
27063
- var pose = gamepad.pose;
27064
-
27065
- if ( pose.hasPosition === false ) controller.position.set( 0.2, - 0.6, - 0.05 );
27066
-
27067
- if ( pose.position !== null ) controller.position.fromArray( pose.position );
27068
- if ( pose.orientation !== null ) controller.quaternion.fromArray( pose.orientation );
27069
- controller.matrix.compose( controller.position, controller.quaternion, controller.scale );
27070
- controller.matrix.premultiply( standingMatrix );
27071
- controller.matrix.decompose( controller.position, controller.quaternion, controller.scale );
27072
- controller.matrixWorldNeedsUpdate = true;
27073
- controller.visible = true;
27074
-
27075
- // Trigger
27076
-
27077
- var buttonId = gamepad.id === 'Daydream Controller' ? 0 : 1;
27078
-
27079
- if ( triggers[ i ] === undefined ) triggers[ i ] = false;
27080
-
27081
- if ( triggers[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
27082
-
27083
- triggers[ i ] = gamepad.buttons[ buttonId ].pressed;
27084
-
27085
- if ( triggers[ i ] === true ) {
27086
-
27087
- controller.dispatchEvent( { type: 'selectstart' } );
27088
-
27089
- } else {
27090
-
27091
- controller.dispatchEvent( { type: 'selectend' } );
27092
- controller.dispatchEvent( { type: 'select' } );
27093
-
27094
- }
27095
-
27096
- }
27097
-
27098
- // Grip
27099
- buttonId = 2;
27100
-
27101
- if ( grips[ i ] === undefined ) grips[ i ] = false;
27102
-
27103
- // Skip if the grip button doesn't exist on this controller
27104
- if ( gamepad.buttons[ buttonId ] !== undefined ) {
27105
-
27106
- if ( grips[ i ] !== gamepad.buttons[ buttonId ].pressed ) {
27107
-
27108
- grips[ i ] = gamepad.buttons[ buttonId ].pressed;
27109
-
27110
- if ( grips[ i ] === true ) {
27111
-
27112
- controller.dispatchEvent( { type: 'squeezestart' } );
27113
-
27114
- } else {
27115
-
27116
- controller.dispatchEvent( { type: 'squeezeend' } );
27117
- controller.dispatchEvent( { type: 'squeeze' } );
27118
-
27119
- }
27120
-
27121
- }
27122
-
27123
- }
27124
-
27125
- } else {
27126
-
27127
- controller.visible = false;
27128
-
27129
- }
27130
-
27131
- }
27132
-
27133
- }
27134
-
27135
- function updateViewportFromBounds( viewport, bounds ) {
27136
-
27137
- if ( bounds !== null && bounds.length === 4 ) {
27138
-
27139
- viewport.set( bounds[ 0 ] * renderWidth, bounds[ 1 ] * renderHeight, bounds[ 2 ] * renderWidth, bounds[ 3 ] * renderHeight );
27140
-
27141
- }
27142
-
27143
- }
27144
-
27145
- //
27146
-
27147
- this.enabled = false;
27148
-
27149
- this.getController = function ( id ) {
27150
-
27151
- var controller = controllers[ id ];
27152
-
27153
- if ( controller === undefined ) {
27154
-
27155
- controller = new Group();
27156
- controller.matrixAutoUpdate = false;
27157
- controller.visible = false;
27158
-
27159
- controllers[ id ] = controller;
27160
-
27161
- }
27162
-
27163
- return controller;
27164
-
27165
- };
27166
-
27167
- this.getDevice = function () {
27168
-
27169
- return device;
27170
-
27171
- };
27172
-
27173
- this.setDevice = function ( value ) {
27174
-
27175
- if ( value !== undefined ) device = value;
27176
-
27177
- animation.setContext( value );
27178
-
27179
- };
27180
-
27181
- this.setFramebufferScaleFactor = function ( value ) {
27182
-
27183
- framebufferScaleFactor = value;
27184
-
27185
- };
27186
-
27187
- this.setReferenceSpaceType = function ( value ) {
27188
-
27189
- referenceSpaceType = value;
27190
-
27191
- };
27192
-
27193
- this.setPoseTarget = function ( object ) {
27194
-
27195
- if ( object !== undefined ) poseTarget = object;
27196
-
27197
- };
27198
-
27199
- //
27200
-
27201
- this.cameraAutoUpdate = true;
27202
-
27203
- this.updateCamera = function ( camera ) {
27204
-
27205
- var userHeight = referenceSpaceType === 'local-floor' ? 1.6 : 0;
27206
-
27207
- device.depthNear = camera.near;
27208
- device.depthFar = camera.far;
27209
-
27210
- device.getFrameData( frameData );
27211
-
27212
- //
27213
-
27214
- if ( referenceSpaceType === 'local-floor' ) {
27215
-
27216
- var stageParameters = device.stageParameters;
27217
-
27218
- if ( stageParameters ) {
27219
-
27220
- standingMatrix.fromArray( stageParameters.sittingToStandingTransform );
27221
-
27222
- } else {
27223
-
27224
- standingMatrix.makeTranslation( 0, userHeight, 0 );
27225
-
27226
- }
27227
-
27228
- }
27229
-
27230
-
27231
- var pose = frameData.pose;
27232
- var poseObject = poseTarget !== null ? poseTarget : camera;
27233
-
27234
- // We want to manipulate poseObject by its position and quaternion components since users may rely on them.
27235
- poseObject.matrix.copy( standingMatrix );
27236
- poseObject.matrix.decompose( poseObject.position, poseObject.quaternion, poseObject.scale );
27237
-
27238
- if ( pose.orientation !== null ) {
27239
-
27240
- tempQuaternion.fromArray( pose.orientation );
27241
- poseObject.quaternion.multiply( tempQuaternion );
27242
-
27243
- }
27244
-
27245
- if ( pose.position !== null ) {
27246
-
27247
- tempQuaternion.setFromRotationMatrix( standingMatrix );
27248
- tempPosition.fromArray( pose.position );
27249
- tempPosition.applyQuaternion( tempQuaternion );
27250
- poseObject.position.add( tempPosition );
27251
-
27252
- }
27253
-
27254
- poseObject.updateMatrixWorld();
27255
-
27256
- var children = poseObject.children;
27257
- for ( var i = 0, l = children.length; i < l; i ++ ) {
27258
-
27259
- children[ i ].updateMatrixWorld( true );
27260
-
27261
- }
27262
-
27263
- //
27264
-
27265
- cameraL.near = camera.near;
27266
- cameraR.near = camera.near;
27267
-
27268
- cameraL.far = camera.far;
27269
- cameraR.far = camera.far;
27270
-
27271
- cameraL.matrixWorldInverse.fromArray( frameData.leftViewMatrix );
27272
- cameraR.matrixWorldInverse.fromArray( frameData.rightViewMatrix );
27273
-
27274
- // TODO (mrdoob) Double check this code
27275
-
27276
- standingMatrixInverse.copy( standingMatrix ).invert();
27277
-
27278
- if ( referenceSpaceType === 'local-floor' ) {
27279
-
27280
- cameraL.matrixWorldInverse.multiply( standingMatrixInverse );
27281
- cameraR.matrixWorldInverse.multiply( standingMatrixInverse );
27282
-
27283
- }
27284
-
27285
- var parent = poseObject.parent;
27286
-
27287
- if ( parent !== null ) {
27288
-
27289
- matrixWorldInverse.copy( parent.matrixWorld ).invert();
27290
-
27291
- cameraL.matrixWorldInverse.multiply( matrixWorldInverse );
27292
- cameraR.matrixWorldInverse.multiply( matrixWorldInverse );
27293
-
27294
- }
27295
-
27296
- // envMap and Mirror needs camera.matrixWorld
27297
-
27298
- cameraL.matrixWorld.copy( cameraL.matrixWorldInverse ).invert();
27299
- cameraR.matrixWorld.copy( cameraR.matrixWorldInverse ).invert();
27300
-
27301
- cameraL.projectionMatrix.fromArray( frameData.leftProjectionMatrix );
27302
- cameraR.projectionMatrix.fromArray( frameData.rightProjectionMatrix );
27303
-
27304
- setProjectionFromUnion( cameraVR, cameraL, cameraR );
27305
-
27306
- //
27307
-
27308
- var layers = device.getLayers();
27309
-
27310
- if ( layers.length ) {
27311
-
27312
- var layer = layers[ 0 ];
27313
-
27314
- updateViewportFromBounds( cameraL.viewport, layer.leftBounds );
27315
- updateViewportFromBounds( cameraR.viewport, layer.rightBounds );
27316
-
27317
- }
27318
-
27319
- updateControllers();
27320
-
27321
- return cameraVR;
27322
-
27323
- };
27324
-
27325
- this.getCamera = function () {
27326
-
27327
- return cameraVR;
27328
-
27329
- };
27330
-
27331
- // Dummy getFoveation/setFoveation to have the same API as WebXR
27332
-
27333
- this.getFoveation = function () {
27334
-
27335
- return 1;
27336
-
27337
- };
27338
-
27339
- this.setFoveation = function ( foveation ) {
27340
-
27341
- if ( foveation !== 1 ) {
27342
-
27343
- console.warn( 'THREE.WebVRManager: setFoveation() not used in WebVR.' );
27344
-
27345
- }
27346
-
27347
- };
27348
-
27349
- // Dummy getEnvironmentBlendMode to have the same API as WebXR
27350
-
27351
- this.getEnvironmentBlendMode = function () {
27352
-
27353
- if ( scope.isPresenting ) {
27354
-
27355
- return 'opaque';
27356
-
27357
- }
27358
-
27359
- };
27360
-
27361
- //
27362
-
27363
- this.getStandingMatrix = function () {
27364
-
27365
- return standingMatrix;
27366
-
27367
- };
27368
-
27369
- this.isPresenting = false;
27370
-
27371
- // Animation Loop
27372
-
27373
- var animation = new WebGLAnimation();
27374
-
27375
- this.setAnimationLoop = function ( callback ) {
27376
-
27377
- animation.setAnimationLoop( callback );
27378
-
27379
- if ( this.isPresenting ) animation.start();
27380
-
27381
- };
27382
-
27383
- this.submitFrame = function () {
27384
-
27385
- if ( this.isPresenting ) device.submitFrame();
27386
-
27387
- };
27388
-
27389
- this.dispose = function () {
27390
-
27391
- if ( typeof window !== 'undefined' ) {
27392
-
27393
- window.removeEventListener( 'vrdisplaypresentchange', onVRDisplayPresentChange );
27394
-
27395
- }
27396
-
27397
- };
27398
-
27399
- // DEPRECATED
27400
-
27401
- this.setFrameOfReferenceType = function () {
27402
-
27403
- console.warn( 'THREE.WebVRManager: setFrameOfReferenceType() has been deprecated.' );
27404
-
27405
- };
27406
-
27407
- }
27408
-
27409
- Object.assign( WebVRManager.prototype, {
27410
- addEventListener: EventDispatcher.prototype.addEventListener,
27411
- hasEventListener: EventDispatcher.prototype.hasEventListener,
27412
- removeEventListener: EventDispatcher.prototype.removeEventListener,
27413
- dispatchEvent: EventDispatcher.prototype.dispatchEvent
27414
- } );
27415
-
27416
26997
  /**
27417
26998
  * @author fernandojsg / http://fernandojsg.com
27418
26999
  * @author Takahiro https://github.com/takahirox
@@ -27446,6 +27027,20 @@ class WebGLMultiviewRenderTarget extends WebGLRenderTarget {
27446
27027
 
27447
27028
  WebGLMultiviewRenderTarget.prototype.isWebGLMultiviewRenderTarget = true;
27448
27029
 
27030
+ class Group extends Object3D {
27031
+
27032
+ constructor() {
27033
+
27034
+ super();
27035
+
27036
+ this.isGroup = true;
27037
+
27038
+ this.type = 'Group';
27039
+
27040
+ }
27041
+
27042
+ }
27043
+
27449
27044
  const _moveEvent = { type: 'move' };
27450
27045
 
27451
27046
  class WebXRController {
@@ -27930,18 +27525,14 @@ class WebXRManager extends EventDispatcher {
27930
27525
  //
27931
27526
 
27932
27527
  const cameraL = new PerspectiveCamera();
27933
- cameraL.layers.enable( 1 );
27934
27528
  cameraL.viewport = new Vector4();
27935
27529
 
27936
27530
  const cameraR = new PerspectiveCamera();
27937
- cameraR.layers.enable( 2 );
27938
27531
  cameraR.viewport = new Vector4();
27939
27532
 
27940
27533
  const cameras = [ cameraL, cameraR ];
27941
27534
 
27942
27535
  const cameraXR = new ArrayCamera();
27943
- cameraXR.layers.enable( 1 );
27944
- cameraXR.layers.enable( 2 );
27945
27536
 
27946
27537
  let _currentDepthNear = null;
27947
27538
  let _currentDepthFar = null;
@@ -28507,6 +28098,10 @@ class WebXRManager extends EventDispatcher {
28507
28098
 
28508
28099
  }
28509
28100
 
28101
+ cameraL.layers.mask = camera.layers.mask | 0b010;
28102
+ cameraR.layers.mask = camera.layers.mask | 0b100;
28103
+ cameraXR.layers.mask = cameraL.layers.mask | cameraR.layers.mask;
28104
+
28510
28105
  const cameras = cameraXR.cameras;
28511
28106
  var object = poseTarget || camera;
28512
28107
  const parent = object.parent;
@@ -29762,6 +29357,7 @@ class WebGLRenderer {
29762
29357
  preserveDrawingBuffer = false,
29763
29358
  powerPreference = 'default',
29764
29359
  failIfMajorPerformanceCaveat = false,
29360
+ reverseDepthBuffer = false,
29765
29361
  multiviewStereo = false,
29766
29362
  } = parameters;
29767
29363
 
@@ -29982,9 +29578,13 @@ class WebGLRenderer {
29982
29578
 
29983
29579
  capabilities = new WebGLCapabilities( _gl, extensions, parameters, utils );
29984
29580
 
29985
- state = new WebGLState( _gl );
29581
+ state = new WebGLState( _gl, extensions );
29582
+
29583
+ if ( capabilities.reverseDepthBuffer && reverseDepthBuffer ) {
29986
29584
 
29987
- if ( capabilities.reverseDepthBuffer ) state.buffers.depth.setReversed( true );
29585
+ state.buffers.depth.setReversed( true );
29586
+
29587
+ }
29988
29588
 
29989
29589
  info = new WebGLInfo( _gl );
29990
29590
  properties = new WebGLProperties();
@@ -30025,7 +29625,7 @@ class WebGLRenderer {
30025
29625
 
30026
29626
  // xr
30027
29627
 
30028
- const xr = ( typeof navigator !== 'undefined' && 'xr' in navigator ) ? new WebXRManager( _this, _gl, extensions, multiviewStereo ) : new WebVRManager( _this );
29628
+ const xr = new WebXRManager( _this, _gl );
30029
29629
 
30030
29630
  this.xr = xr;
30031
29631
 
@@ -30289,7 +29889,6 @@ class WebGLRenderer {
30289
29889
  if ( depth ) {
30290
29890
 
30291
29891
  bits |= _gl.DEPTH_BUFFER_BIT;
30292
- _gl.clearDepth( this.capabilities.reverseDepthBuffer ? 0 : 1 );
30293
29892
 
30294
29893
  }
30295
29894
 
@@ -30985,13 +30584,6 @@ class WebGLRenderer {
30985
30584
 
30986
30585
  if ( scene.isScene === true ) scene.onAfterRender( _this, scene, camera );
30987
30586
 
30988
- textures.runDeferredUploads();
30989
-
30990
- if ( xr.enabled && xr.submitFrame ) {
30991
-
30992
- xr.submitFrame();
30993
-
30994
- }
30995
30587
  // _gl.finish();
30996
30588
 
30997
30589
  bindingStates.resetDefaultState();
@@ -31704,7 +31296,9 @@ class WebGLRenderer {
31704
31296
 
31705
31297
  } else {
31706
31298
 
31707
- if ( capabilities.reverseDepthBuffer ) {
31299
+ const reverseDepthBuffer = state.buffers.depth.getReversed();
31300
+
31301
+ if ( reverseDepthBuffer ) {
31708
31302
 
31709
31303
  _currentProjectionMatrix.copy( camera.projectionMatrix );
31710
31304
 
@@ -32336,21 +31930,27 @@ class WebGLRenderer {
32336
31930
 
32337
31931
  }
32338
31932
 
32339
- let width, height, minX, minY;
32340
- let dstX, dstY;
31933
+ // gather the necessary dimensions to copy
31934
+ let width, height, depth, minX, minY, minZ;
31935
+ let dstX, dstY, dstZ;
31936
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
32341
31937
  if ( srcRegion !== null ) {
32342
31938
 
32343
31939
  width = srcRegion.max.x - srcRegion.min.x;
32344
31940
  height = srcRegion.max.y - srcRegion.min.y;
31941
+ depth = srcRegion.isBox3 ? srcRegion.max.z - srcRegion.min.z : 1;
32345
31942
  minX = srcRegion.min.x;
32346
31943
  minY = srcRegion.min.y;
31944
+ minZ = srcRegion.isBox3 ? srcRegion.min.z : 0;
32347
31945
 
32348
31946
  } else {
32349
31947
 
32350
- width = srcTexture.image.width;
32351
- height = srcTexture.image.height;
31948
+ width = image.width;
31949
+ height = image.height;
31950
+ depth = image.depth || 1;
32352
31951
  minX = 0;
32353
31952
  minY = 0;
31953
+ minZ = 0;
32354
31954
 
32355
31955
  }
32356
31956
 
@@ -32358,177 +31958,143 @@ class WebGLRenderer {
32358
31958
 
32359
31959
  dstX = dstPosition.x;
32360
31960
  dstY = dstPosition.y;
31961
+ dstZ = dstPosition.z;
32361
31962
 
32362
31963
  } else {
32363
31964
 
32364
31965
  dstX = 0;
32365
31966
  dstY = 0;
31967
+ dstZ = 0;
32366
31968
 
32367
31969
  }
32368
31970
 
31971
+ // Set up the destination target
32369
31972
  const glFormat = utils.convert( dstTexture.format );
32370
31973
  const glType = utils.convert( dstTexture.type );
31974
+ let glTarget;
31975
+
31976
+ if ( dstTexture.isData3DTexture ) {
31977
+
31978
+ textures.setTexture3D( dstTexture, 0 );
31979
+ glTarget = _gl.TEXTURE_3D;
31980
+
31981
+ } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) {
31982
+
31983
+ textures.setTexture2DArray( dstTexture, 0 );
31984
+ glTarget = _gl.TEXTURE_2D_ARRAY;
31985
+
31986
+ } else {
32371
31987
 
32372
- textures.setTexture2D( dstTexture, 0 );
31988
+ textures.setTexture2D( dstTexture, 0 );
31989
+ glTarget = _gl.TEXTURE_2D;
31990
+
31991
+ }
32373
31992
 
32374
- // As another texture upload may have changed pixelStorei
32375
- // parameters, make sure they are correct for the dstTexture
32376
31993
  _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
32377
31994
  _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
32378
31995
  _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
32379
31996
 
31997
+ // used for copying data from cpu
32380
31998
  const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
32381
31999
  const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
32382
32000
  const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
32383
32001
  const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
32384
32002
  const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
32385
32003
 
32386
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
32387
-
32388
32004
  _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
32389
32005
  _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
32390
32006
  _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
32391
32007
  _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
32008
+ _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
32392
32009
 
32393
- if ( srcTexture.isDataTexture ) {
32394
-
32395
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
32396
-
32397
- } else {
32398
-
32399
- if ( srcTexture.isCompressedTexture ) {
32010
+ // set up the src texture
32011
+ const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture;
32012
+ const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture;
32013
+ if ( srcTexture.isRenderTargetTexture || srcTexture.isDepthTexture ) {
32400
32014
 
32401
- _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
32015
+ const srcTextureProperties = properties.get( srcTexture );
32016
+ const dstTextureProperties = properties.get( dstTexture );
32017
+ const srcRenderTargetProperties = properties.get( srcTextureProperties.__renderTarget );
32018
+ const dstRenderTargetProperties = properties.get( dstTextureProperties.__renderTarget );
32402
32019
 
32403
- } else {
32020
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, srcRenderTargetProperties.__webglFramebuffer );
32021
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, dstRenderTargetProperties.__webglFramebuffer );
32404
32022
 
32405
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image );
32023
+ for ( let i = 0; i < depth; i ++ ) {
32406
32024
 
32407
- }
32408
-
32409
- }
32410
-
32411
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
32412
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
32413
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
32414
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, currentUnpackSkipRows );
32415
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
32025
+ // if the source or destination are a 3d target then a layer needs to be bound
32026
+ if ( isSrc3D ) {
32416
32027
 
32417
- // Generate mipmaps only when copying level 0
32418
- if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( _gl.TEXTURE_2D );
32028
+ _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( srcTexture ).__webglTexture, level, minZ + i );
32419
32029
 
32420
- state.unbindTexture();
32030
+ }
32421
32031
 
32422
- };
32032
+ if ( srcTexture.isDepthTexture ) {
32423
32033
 
32424
- this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
32034
+ if ( isDst3D ) {
32425
32035
 
32426
- // support previous signature with source box first
32427
- if ( srcTexture.isTexture !== true ) {
32036
+ _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( dstTexture ).__webglTexture, level, dstZ + i );
32428
32037
 
32429
- // @deprecated, r165
32430
- warnOnce( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' );
32038
+ }
32431
32039
 
32432
- srcRegion = arguments[ 0 ] || null;
32433
- dstPosition = arguments[ 1 ] || null;
32434
- srcTexture = arguments[ 2 ];
32435
- dstTexture = arguments[ 3 ];
32436
- level = arguments[ 4 ] || 0;
32040
+ _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.DEPTH_BUFFER_BIT, _gl.NEAREST );
32437
32041
 
32438
- }
32042
+ } else if ( isDst3D ) {
32439
32043
 
32440
- let width, height, depth, minX, minY, minZ;
32441
- let dstX, dstY, dstZ;
32442
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
32443
- if ( srcRegion !== null ) {
32444
-
32445
- width = srcRegion.max.x - srcRegion.min.x;
32446
- height = srcRegion.max.y - srcRegion.min.y;
32447
- depth = srcRegion.max.z - srcRegion.min.z;
32448
- minX = srcRegion.min.x;
32449
- minY = srcRegion.min.y;
32450
- minZ = srcRegion.min.z;
32044
+ _gl.copyTexSubImage3D( glTarget, level, dstX, dstY, dstZ + i, minX, minY, width, height );
32451
32045
 
32452
- } else {
32046
+ } else {
32453
32047
 
32454
- width = image.width;
32455
- height = image.height;
32456
- depth = image.depth;
32457
- minX = 0;
32458
- minY = 0;
32459
- minZ = 0;
32048
+ _gl.copyTexSubImage2D( glTarget, level, dstX, dstY, dstZ + i, minX, minY, width, height );
32460
32049
 
32461
- }
32050
+ }
32462
32051
 
32463
- if ( dstPosition !== null ) {
32052
+ }
32464
32053
 
32465
- dstX = dstPosition.x;
32466
- dstY = dstPosition.y;
32467
- dstZ = dstPosition.z;
32054
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
32055
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );
32468
32056
 
32469
32057
  } else {
32470
32058
 
32471
- dstX = 0;
32472
- dstY = 0;
32473
- dstZ = 0;
32474
-
32475
- }
32476
-
32477
- const glFormat = utils.convert( dstTexture.format );
32478
- const glType = utils.convert( dstTexture.type );
32479
- let glTarget;
32480
-
32481
- if ( dstTexture.isData3DTexture ) {
32059
+ if ( isDst3D ) {
32482
32060
 
32483
- textures.setTexture3D( dstTexture, 0 );
32484
- glTarget = _gl.TEXTURE_3D;
32061
+ // copy data into the 3d texture
32062
+ if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
32485
32063
 
32486
- } else if ( dstTexture.isDataArrayTexture || dstTexture.isCompressedArrayTexture ) {
32064
+ _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
32487
32065
 
32488
- textures.setTexture2DArray( dstTexture, 0 );
32489
- glTarget = _gl.TEXTURE_2D_ARRAY;
32066
+ } else if ( dstTexture.isCompressedArrayTexture ) {
32490
32067
 
32491
- } else {
32492
-
32493
- console.warn( 'THREE.WebGLRenderer.copyTextureToTexture3D: only supports THREE.DataTexture3D and THREE.DataTexture2DArray.' );
32494
- return;
32068
+ _gl.compressedTexSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
32495
32069
 
32496
- }
32070
+ } else {
32497
32071
 
32498
- _gl.pixelStorei( _gl.UNPACK_FLIP_Y_WEBGL, dstTexture.flipY );
32499
- _gl.pixelStorei( _gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, dstTexture.premultiplyAlpha );
32500
- _gl.pixelStorei( _gl.UNPACK_ALIGNMENT, dstTexture.unpackAlignment );
32072
+ _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
32501
32073
 
32502
- const currentUnpackRowLen = _gl.getParameter( _gl.UNPACK_ROW_LENGTH );
32503
- const currentUnpackImageHeight = _gl.getParameter( _gl.UNPACK_IMAGE_HEIGHT );
32504
- const currentUnpackSkipPixels = _gl.getParameter( _gl.UNPACK_SKIP_PIXELS );
32505
- const currentUnpackSkipRows = _gl.getParameter( _gl.UNPACK_SKIP_ROWS );
32506
- const currentUnpackSkipImages = _gl.getParameter( _gl.UNPACK_SKIP_IMAGES );
32074
+ }
32507
32075
 
32508
- _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, image.width );
32509
- _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, image.height );
32510
- _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, minX );
32511
- _gl.pixelStorei( _gl.UNPACK_SKIP_ROWS, minY );
32512
- _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, minZ );
32076
+ } else {
32513
32077
 
32514
- if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
32078
+ // copy data into the 2d texture
32079
+ if ( srcTexture.isDataTexture ) {
32515
32080
 
32516
- _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
32081
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
32517
32082
 
32518
- } else {
32083
+ } else if ( srcTexture.isCompressedTexture ) {
32519
32084
 
32520
- if ( dstTexture.isCompressedArrayTexture ) {
32085
+ _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
32521
32086
 
32522
- _gl.compressedTexSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
32087
+ } else {
32523
32088
 
32524
- } else {
32089
+ _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image );
32525
32090
 
32526
- _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
32091
+ }
32527
32092
 
32528
32093
  }
32529
32094
 
32530
32095
  }
32531
32096
 
32097
+ // reset values
32532
32098
  _gl.pixelStorei( _gl.UNPACK_ROW_LENGTH, currentUnpackRowLen );
32533
32099
  _gl.pixelStorei( _gl.UNPACK_IMAGE_HEIGHT, currentUnpackImageHeight );
32534
32100
  _gl.pixelStorei( _gl.UNPACK_SKIP_PIXELS, currentUnpackSkipPixels );
@@ -32536,12 +32102,39 @@ class WebGLRenderer {
32536
32102
  _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
32537
32103
 
32538
32104
  // Generate mipmaps only when copying level 0
32539
- if ( level === 0 && dstTexture.generateMipmaps ) _gl.generateMipmap( glTarget );
32105
+ if ( level === 0 && dstTexture.generateMipmaps ) {
32106
+
32107
+ _gl.generateMipmap( glTarget );
32108
+
32109
+ }
32540
32110
 
32541
32111
  state.unbindTexture();
32542
32112
 
32543
32113
  };
32544
32114
 
32115
+ this.copyTextureToTexture3D = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
32116
+
32117
+ // support previous signature with source box first
32118
+ if ( srcTexture.isTexture !== true ) {
32119
+
32120
+ // @deprecated, r165
32121
+ warnOnce( 'WebGLRenderer: copyTextureToTexture3D function signature has changed.' );
32122
+
32123
+ srcRegion = arguments[ 0 ] || null;
32124
+ dstPosition = arguments[ 1 ] || null;
32125
+ srcTexture = arguments[ 2 ];
32126
+ dstTexture = arguments[ 3 ];
32127
+ level = arguments[ 4 ] || 0;
32128
+
32129
+ }
32130
+
32131
+ // @deprecated, r170
32132
+ warnOnce( 'WebGLRenderer: copyTextureToTexture3D function has been deprecated. Use "copyTextureToTexture" instead.' );
32133
+
32134
+ return this.copyTextureToTexture( srcTexture, dstTexture, srcRegion, dstPosition, level );
32135
+
32136
+ };
32137
+
32545
32138
  this.initRenderTarget = function ( target ) {
32546
32139
 
32547
32140
  if ( properties.get( target ).__webglFramebuffer === undefined ) {
@@ -32612,8 +32205,8 @@ class WebGLRenderer {
32612
32205
  this._outputColorSpace = colorSpace;
32613
32206
 
32614
32207
  const gl = this.getContext();
32615
- gl.drawingBufferColorSpace = colorSpace === DisplayP3ColorSpace ? 'display-p3' : 'srgb';
32616
- gl.unpackColorSpace = ColorManagement.workingColorSpace === LinearDisplayP3ColorSpace ? 'display-p3' : 'srgb';
32208
+ gl.drawingBufferColorspace = ColorManagement._getDrawingBufferColorSpace( colorSpace );
32209
+ gl.unpackColorSpace = ColorManagement._getUnpackColorSpace();
32617
32210
 
32618
32211
  }
32619
32212
 
@@ -33259,14 +32852,18 @@ class InterleavedBufferAttribute {
33259
32852
 
33260
32853
  class SpriteMaterial extends Material {
33261
32854
 
32855
+ static get type() {
32856
+
32857
+ return 'SpriteMaterial';
32858
+
32859
+ }
32860
+
33262
32861
  constructor( parameters ) {
33263
32862
 
33264
32863
  super();
33265
32864
 
33266
32865
  this.isSpriteMaterial = true;
33267
32866
 
33268
- this.type = 'SpriteMaterial';
33269
-
33270
32867
  this.color = new Color( 0xffffff );
33271
32868
 
33272
32869
  this.map = null;
@@ -33987,7 +33584,7 @@ class DataTexture extends Texture {
33987
33584
  }
33988
33585
 
33989
33586
  const _offsetMatrix = /*@__PURE__*/ new Matrix4();
33990
- const _identityMatrix$1 = /*@__PURE__*/ new Matrix4();
33587
+ const _identityMatrix = /*@__PURE__*/ new Matrix4();
33991
33588
 
33992
33589
  class Skeleton {
33993
33590
 
@@ -34116,7 +33713,7 @@ class Skeleton {
34116
33713
 
34117
33714
  // compute the offset between the current and the original transform
34118
33715
 
34119
- const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix$1;
33716
+ const matrix = bones[ i ] ? bones[ i ].matrixWorld : _identityMatrix;
34120
33717
 
34121
33718
  _offsetMatrix.multiplyMatrices( matrix, boneInverses[ i ] );
34122
33719
  _offsetMatrix.toArray( boneMatrices, i * 16 );
@@ -34557,6 +34154,12 @@ class InstancedMesh extends Mesh {
34557
34154
 
34558
34155
  }
34559
34156
 
34157
+ function ascIdSort( a, b ) {
34158
+
34159
+ return a - b;
34160
+
34161
+ }
34162
+
34560
34163
  function sortOpaque( a, b ) {
34561
34164
 
34562
34165
  return a.z - b.z;
@@ -34579,7 +34182,7 @@ class MultiDrawRenderList {
34579
34182
 
34580
34183
  }
34581
34184
 
34582
- push( drawRange, z, index ) {
34185
+ push( start, count, z, index ) {
34583
34186
 
34584
34187
  const pool = this.pool;
34585
34188
  const list = this.list;
@@ -34600,8 +34203,8 @@ class MultiDrawRenderList {
34600
34203
  list.push( item );
34601
34204
  this.index ++;
34602
34205
 
34603
- item.start = drawRange.start;
34604
- item.count = drawRange.count;
34206
+ item.start = start;
34207
+ item.count = count;
34605
34208
  item.z = z;
34606
34209
  item.index = index;
34607
34210
 
@@ -34617,10 +34220,7 @@ class MultiDrawRenderList {
34617
34220
  }
34618
34221
 
34619
34222
  const _matrix$1 = /*@__PURE__*/ new Matrix4();
34620
- const _invMatrixWorld = /*@__PURE__*/ new Matrix4();
34621
- const _identityMatrix = /*@__PURE__*/ new Matrix4();
34622
34223
  const _whiteColor = /*@__PURE__*/ new Color( 1, 1, 1 );
34623
- const _projScreenMatrix$2 = /*@__PURE__*/ new Matrix4();
34624
34224
  const _frustum = /*@__PURE__*/ new Frustum();
34625
34225
  const _box$1 = /*@__PURE__*/ new Box3();
34626
34226
  const _sphere$2 = /*@__PURE__*/ new Sphere();
@@ -34631,13 +34231,6 @@ const _renderList = /*@__PURE__*/ new MultiDrawRenderList();
34631
34231
  const _mesh = /*@__PURE__*/ new Mesh();
34632
34232
  const _batchIntersects = [];
34633
34233
 
34634
- // @TODO: SkinnedMesh support?
34635
- // @TODO: geometry.groups support?
34636
- // @TODO: geometry.drawRange support?
34637
- // @TODO: geometry.morphAttributes support?
34638
- // @TODO: Support uniform parameter per geometry
34639
- // @TODO: Add an "optimize" function to pack geometry and remove data gaps
34640
-
34641
34234
  // copies data from attribute "src" into "target" starting at "targetOffset"
34642
34235
  function copyAttributeData( src, target, targetOffset = 0 ) {
34643
34236
 
@@ -34668,6 +34261,29 @@ function copyAttributeData( src, target, targetOffset = 0 ) {
34668
34261
 
34669
34262
  }
34670
34263
 
34264
+ // safely copies array contents to a potentially smaller array
34265
+ function copyArrayContents( src, target ) {
34266
+
34267
+ if ( src.constructor !== target.constructor ) {
34268
+
34269
+ // if arrays are of a different type (eg due to index size increasing) then data must be per-element copied
34270
+ const len = Math.min( src.length, target.length );
34271
+ for ( let i = 0; i < len; i ++ ) {
34272
+
34273
+ target[ i ] = src[ i ];
34274
+
34275
+ }
34276
+
34277
+ } else {
34278
+
34279
+ // if the arrays use the same data layout we can use a fast block copy
34280
+ const len = Math.min( src.length, target.length );
34281
+ target.set( new src.constructor( src.buffer, 0, len ) );
34282
+
34283
+ }
34284
+
34285
+ }
34286
+
34671
34287
  class BatchedMesh extends Mesh {
34672
34288
 
34673
34289
  get maxInstanceCount() {
@@ -34676,6 +34292,24 @@ class BatchedMesh extends Mesh {
34676
34292
 
34677
34293
  }
34678
34294
 
34295
+ get instanceCount() {
34296
+
34297
+ return this._instanceInfo.length - this._availableInstanceIds.length;
34298
+
34299
+ }
34300
+
34301
+ get unusedVertexCount() {
34302
+
34303
+ return this._maxVertexCount - this._nextVertexStart;
34304
+
34305
+ }
34306
+
34307
+ get unusedIndexCount() {
34308
+
34309
+ return this._maxIndexCount - this._nextIndexStart;
34310
+
34311
+ }
34312
+
34679
34313
  constructor( maxInstanceCount, maxVertexCount, maxIndexCount = maxVertexCount * 2, material ) {
34680
34314
 
34681
34315
  super( new BufferGeometry(), material );
@@ -34687,28 +34321,33 @@ class BatchedMesh extends Mesh {
34687
34321
  this.boundingSphere = null;
34688
34322
  this.customSort = null;
34689
34323
 
34690
- // stores visible, active, and geometry id per object
34691
- this._drawInfo = [];
34324
+ // stores visible, active, and geometry id per instance and reserved buffer ranges for geometries
34325
+ this._instanceInfo = [];
34326
+ this._geometryInfo = [];
34692
34327
 
34693
- // instance ids that have been set as inactive, and are available to be overwritten
34328
+ // instance, geometry ids that have been set as inactive, and are available to be overwritten
34694
34329
  this._availableInstanceIds = [];
34330
+ this._availableGeometryIds = [];
34331
+
34332
+ // used to track where the next point is that geometry should be inserted
34333
+ this._nextIndexStart = 0;
34334
+ this._nextVertexStart = 0;
34335
+ this._geometryCount = 0;
34695
34336
 
34696
- // geometry information
34697
- this._drawRanges = [];
34698
- this._reservedRanges = [];
34699
- this._bounds = [];
34337
+ // flags
34338
+ this._visibilityChanged = true;
34339
+ this._geometryInitialized = false;
34700
34340
 
34341
+ // cached user options
34701
34342
  this._maxInstanceCount = maxInstanceCount;
34702
34343
  this._maxVertexCount = maxVertexCount;
34703
34344
  this._maxIndexCount = maxIndexCount;
34704
34345
 
34705
- this._geometryInitialized = false;
34706
- this._geometryCount = 0;
34346
+ // buffers for multi draw
34707
34347
  this._multiDrawCounts = new Int32Array( maxInstanceCount );
34708
34348
  this._multiDrawStarts = new Int32Array( maxInstanceCount );
34709
34349
  this._multiDrawCount = 0;
34710
34350
  this._multiDrawInstances = null;
34711
- this._visibilityChanged = true;
34712
34351
 
34713
34352
  // Local matrix per geometry by using data texture
34714
34353
  this._matricesTexture = null;
@@ -34849,14 +34488,14 @@ class BatchedMesh extends Mesh {
34849
34488
  }
34850
34489
 
34851
34490
  const boundingBox = this.boundingBox;
34852
- const drawInfo = this._drawInfo;
34491
+ const instanceInfo = this._instanceInfo;
34853
34492
 
34854
34493
  boundingBox.makeEmpty();
34855
- for ( let i = 0, l = drawInfo.length; i < l; i ++ ) {
34494
+ for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
34856
34495
 
34857
- if ( drawInfo[ i ].active === false ) continue;
34496
+ if ( instanceInfo[ i ].active === false ) continue;
34858
34497
 
34859
- const geometryId = drawInfo[ i ].geometryIndex;
34498
+ const geometryId = instanceInfo[ i ].geometryIndex;
34860
34499
  this.getMatrixAt( i, _matrix$1 );
34861
34500
  this.getBoundingBoxAt( geometryId, _box$1 ).applyMatrix4( _matrix$1 );
34862
34501
  boundingBox.union( _box$1 );
@@ -34874,14 +34513,14 @@ class BatchedMesh extends Mesh {
34874
34513
  }
34875
34514
 
34876
34515
  const boundingSphere = this.boundingSphere;
34877
- const drawInfo = this._drawInfo;
34516
+ const instanceInfo = this._instanceInfo;
34878
34517
 
34879
34518
  boundingSphere.makeEmpty();
34880
- for ( let i = 0, l = drawInfo.length; i < l; i ++ ) {
34519
+ for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
34881
34520
 
34882
- if ( drawInfo[ i ].active === false ) continue;
34521
+ if ( instanceInfo[ i ].active === false ) continue;
34883
34522
 
34884
- const geometryId = drawInfo[ i ].geometryIndex;
34523
+ const geometryId = instanceInfo[ i ].geometryIndex;
34885
34524
  this.getMatrixAt( i, _matrix$1 );
34886
34525
  this.getBoundingSphereAt( geometryId, _sphere$2 ).applyMatrix4( _matrix$1 );
34887
34526
  boundingSphere.union( _sphere$2 );
@@ -34892,7 +34531,7 @@ class BatchedMesh extends Mesh {
34892
34531
 
34893
34532
  addInstance( geometryId ) {
34894
34533
 
34895
- const atCapacity = this._drawInfo.length >= this.maxInstanceCount;
34534
+ const atCapacity = this._instanceInfo.length >= this.maxInstanceCount;
34896
34535
 
34897
34536
  // ensure we're not over geometry
34898
34537
  if ( atCapacity && this._availableInstanceIds.length === 0 ) {
@@ -34901,7 +34540,7 @@ class BatchedMesh extends Mesh {
34901
34540
 
34902
34541
  }
34903
34542
 
34904
- const instanceDrawInfo = {
34543
+ const instanceInfo = {
34905
34544
  visible: true,
34906
34545
  active: true,
34907
34546
  geometryIndex: geometryId,
@@ -34912,19 +34551,20 @@ class BatchedMesh extends Mesh {
34912
34551
  // Prioritize using previously freed instance ids
34913
34552
  if ( this._availableInstanceIds.length > 0 ) {
34914
34553
 
34915
- drawId = this._availableInstanceIds.pop();
34916
- this._drawInfo[ drawId ] = instanceDrawInfo;
34554
+ this._availableInstanceIds.sort( ascIdSort );
34555
+
34556
+ drawId = this._availableInstanceIds.shift();
34557
+ this._instanceInfo[ drawId ] = instanceInfo;
34917
34558
 
34918
34559
  } else {
34919
34560
 
34920
- drawId = this._drawInfo.length;
34921
- this._drawInfo.push( instanceDrawInfo );
34561
+ drawId = this._instanceInfo.length;
34562
+ this._instanceInfo.push( instanceInfo );
34922
34563
 
34923
34564
  }
34924
34565
 
34925
34566
  const matricesTexture = this._matricesTexture;
34926
- const matricesArray = matricesTexture.image.data;
34927
- _identityMatrix.toArray( matricesArray, drawId * 16 );
34567
+ _matrix$1.identity().toArray( matricesTexture.image.data, drawId * 16 );
34928
34568
  matricesTexture.needsUpdate = true;
34929
34569
 
34930
34570
  const colorsTexture = this._colorsTexture;
@@ -34935,91 +34575,54 @@ class BatchedMesh extends Mesh {
34935
34575
 
34936
34576
  }
34937
34577
 
34578
+ this._visibilityChanged = true;
34938
34579
  return drawId;
34939
34580
 
34940
34581
  }
34941
34582
 
34942
- addGeometry( geometry, vertexCount = - 1, indexCount = - 1 ) {
34583
+ addGeometry( geometry, reservedVertexCount = - 1, reservedIndexCount = - 1 ) {
34943
34584
 
34944
34585
  this._initializeGeometry( geometry );
34945
34586
 
34946
34587
  this._validateGeometry( geometry );
34947
34588
 
34948
- // ensure we're not over geometry
34949
- if ( this._drawInfo.length >= this._maxInstanceCount ) {
34950
-
34951
- throw new Error( 'BatchedMesh: Maximum item count reached.' );
34952
-
34953
- }
34954
-
34955
- // get the necessary range fo the geometry
34956
- const reservedRange = {
34589
+ const geometryInfo = {
34590
+ // geometry information
34957
34591
  vertexStart: - 1,
34958
34592
  vertexCount: - 1,
34593
+ reservedVertexCount: - 1,
34594
+
34959
34595
  indexStart: - 1,
34960
34596
  indexCount: - 1,
34961
- };
34962
-
34963
- let lastRange = null;
34964
- const reservedRanges = this._reservedRanges;
34965
- const drawRanges = this._drawRanges;
34966
- const bounds = this._bounds;
34967
- if ( this._geometryCount !== 0 ) {
34968
-
34969
- lastRange = reservedRanges[ reservedRanges.length - 1 ];
34970
-
34971
- }
34972
-
34973
- if ( vertexCount === - 1 ) {
34974
-
34975
- reservedRange.vertexCount = geometry.getAttribute( 'position' ).count;
34976
-
34977
- } else {
34978
-
34979
- reservedRange.vertexCount = vertexCount;
34980
-
34981
- }
34982
-
34983
- if ( lastRange === null ) {
34597
+ reservedIndexCount: - 1,
34984
34598
 
34985
- reservedRange.vertexStart = 0;
34599
+ // draw range information
34600
+ start: - 1,
34601
+ count: - 1,
34986
34602
 
34987
- } else {
34988
-
34989
- reservedRange.vertexStart = lastRange.vertexStart + lastRange.vertexCount;
34603
+ // state
34604
+ boundingBox: null,
34605
+ boundingSphere: null,
34606
+ active: true,
34607
+ };
34990
34608
 
34991
- }
34609
+ const geometryInfoList = this._geometryInfo;
34610
+ geometryInfo.vertexStart = this._nextVertexStart;
34611
+ geometryInfo.reservedVertexCount = reservedVertexCount === - 1 ? geometry.getAttribute( 'position' ).count : reservedVertexCount;
34992
34612
 
34993
34613
  const index = geometry.getIndex();
34994
34614
  const hasIndex = index !== null;
34995
34615
  if ( hasIndex ) {
34996
34616
 
34997
- if ( indexCount === - 1 ) {
34998
-
34999
- reservedRange.indexCount = index.count;
35000
-
35001
- } else {
35002
-
35003
- reservedRange.indexCount = indexCount;
35004
-
35005
- }
35006
-
35007
- if ( lastRange === null ) {
35008
-
35009
- reservedRange.indexStart = 0;
35010
-
35011
- } else {
35012
-
35013
- reservedRange.indexStart = lastRange.indexStart + lastRange.indexCount;
35014
-
35015
- }
34617
+ geometryInfo.indexStart = this._nextIndexStart;
34618
+ geometryInfo.reservedIndexCount = reservedIndexCount === - 1 ? index.count : reservedIndexCount;
35016
34619
 
35017
34620
  }
35018
34621
 
35019
34622
  if (
35020
- reservedRange.indexStart !== - 1 &&
35021
- reservedRange.indexStart + reservedRange.indexCount > this._maxIndexCount ||
35022
- reservedRange.vertexStart + reservedRange.vertexCount > this._maxVertexCount
34623
+ geometryInfo.indexStart !== - 1 &&
34624
+ geometryInfo.indexStart + geometryInfo.reservedIndexCount > this._maxIndexCount ||
34625
+ geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
35023
34626
  ) {
35024
34627
 
35025
34628
  throw new Error( 'BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
@@ -35027,26 +34630,30 @@ class BatchedMesh extends Mesh {
35027
34630
  }
35028
34631
 
35029
34632
  // update id
35030
- const geometryId = this._geometryCount;
35031
- this._geometryCount ++;
35032
-
35033
- // add the reserved range and draw range objects
35034
- reservedRanges.push( reservedRange );
35035
- drawRanges.push( {
35036
- start: hasIndex ? reservedRange.indexStart : reservedRange.vertexStart,
35037
- count: - 1
35038
- } );
35039
- bounds.push( {
35040
- boxInitialized: false,
35041
- box: new Box3(),
34633
+ let geometryId;
34634
+ if ( this._availableGeometryIds.length > 0 ) {
35042
34635
 
35043
- sphereInitialized: false,
35044
- sphere: new Sphere()
35045
- } );
34636
+ this._availableGeometryIds.sort( ascIdSort );
34637
+
34638
+ geometryId = this._availableGeometryIds.shift();
34639
+ geometryInfoList[ geometryId ] = geometryInfo;
34640
+
34641
+
34642
+ } else {
34643
+
34644
+ geometryId = this._geometryCount;
34645
+ this._geometryCount ++;
34646
+ geometryInfoList.push( geometryInfo );
34647
+
34648
+ }
35046
34649
 
35047
34650
  // update the geometry
35048
34651
  this.setGeometryAt( geometryId, geometry );
35049
34652
 
34653
+ // increment the next geometry position
34654
+ this._nextIndexStart = geometryInfo.indexStart + geometryInfo.reservedIndexCount;
34655
+ this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
34656
+
35050
34657
  return geometryId;
35051
34658
 
35052
34659
  }
@@ -35065,20 +34672,22 @@ class BatchedMesh extends Mesh {
35065
34672
  const hasIndex = batchGeometry.getIndex() !== null;
35066
34673
  const dstIndex = batchGeometry.getIndex();
35067
34674
  const srcIndex = geometry.getIndex();
35068
- const reservedRange = this._reservedRanges[ geometryId ];
34675
+ const geometryInfo = this._geometryInfo[ geometryId ];
35069
34676
  if (
35070
34677
  hasIndex &&
35071
- srcIndex.count > reservedRange.indexCount ||
35072
- geometry.attributes.position.count > reservedRange.vertexCount
34678
+ srcIndex.count > geometryInfo.reservedIndexCount ||
34679
+ geometry.attributes.position.count > geometryInfo.reservedVertexCount
35073
34680
  ) {
35074
34681
 
35075
34682
  throw new Error( 'BatchedMesh: Reserved space not large enough for provided geometry.' );
35076
34683
 
35077
34684
  }
35078
34685
 
35079
- // copy geometry over
35080
- const vertexStart = reservedRange.vertexStart;
35081
- const vertexCount = reservedRange.vertexCount;
34686
+ // copy geometry buffer data over
34687
+ const vertexStart = geometryInfo.vertexStart;
34688
+ const reservedVertexCount = geometryInfo.reservedVertexCount;
34689
+ geometryInfo.vertexCount = geometry.getAttribute( 'position' ).count;
34690
+
35082
34691
  for ( const attributeName in batchGeometry.attributes ) {
35083
34692
 
35084
34693
  // copy attribute data
@@ -35088,7 +34697,7 @@ class BatchedMesh extends Mesh {
35088
34697
 
35089
34698
  // fill the rest in with zeroes
35090
34699
  const itemSize = srcAttribute.itemSize;
35091
- for ( let i = srcAttribute.count, l = vertexCount; i < l; i ++ ) {
34700
+ for ( let i = srcAttribute.count, l = reservedVertexCount; i < l; i ++ ) {
35092
34701
 
35093
34702
  const index = vertexStart + i;
35094
34703
  for ( let c = 0; c < itemSize; c ++ ) {
@@ -35100,14 +34709,16 @@ class BatchedMesh extends Mesh {
35100
34709
  }
35101
34710
 
35102
34711
  dstAttribute.needsUpdate = true;
35103
- dstAttribute.addUpdateRange( vertexStart * itemSize, vertexCount * itemSize );
34712
+ dstAttribute.addUpdateRange( vertexStart * itemSize, reservedVertexCount * itemSize );
35104
34713
 
35105
34714
  }
35106
34715
 
35107
34716
  // copy index
35108
34717
  if ( hasIndex ) {
35109
34718
 
35110
- const indexStart = reservedRange.indexStart;
34719
+ const indexStart = geometryInfo.indexStart;
34720
+ const reservedIndexCount = geometryInfo.reservedIndexCount;
34721
+ geometryInfo.indexCount = geometry.getIndex().count;
35111
34722
 
35112
34723
  // copy index data over
35113
34724
  for ( let i = 0; i < srcIndex.count; i ++ ) {
@@ -35117,69 +34728,80 @@ class BatchedMesh extends Mesh {
35117
34728
  }
35118
34729
 
35119
34730
  // fill the rest in with zeroes
35120
- for ( let i = srcIndex.count, l = reservedRange.indexCount; i < l; i ++ ) {
34731
+ for ( let i = srcIndex.count, l = reservedIndexCount; i < l; i ++ ) {
35121
34732
 
35122
34733
  dstIndex.setX( indexStart + i, vertexStart );
35123
34734
 
35124
34735
  }
35125
34736
 
35126
34737
  dstIndex.needsUpdate = true;
35127
- dstIndex.addUpdateRange( indexStart, reservedRange.indexCount );
34738
+ dstIndex.addUpdateRange( indexStart, geometryInfo.reservedIndexCount );
35128
34739
 
35129
34740
  }
35130
34741
 
34742
+ // update the draw range
34743
+ geometryInfo.start = hasIndex ? geometryInfo.indexStart : geometryInfo.vertexStart;
34744
+ geometryInfo.count = hasIndex ? geometryInfo.indexCount : geometryInfo.vertexCount;
34745
+
35131
34746
  // store the bounding boxes
35132
- const bound = this._bounds[ geometryId ];
34747
+ geometryInfo.boundingBox = null;
35133
34748
  if ( geometry.boundingBox !== null ) {
35134
34749
 
35135
- bound.box.copy( geometry.boundingBox );
35136
- bound.boxInitialized = true;
35137
-
35138
- } else {
35139
-
35140
- bound.boxInitialized = false;
34750
+ geometryInfo.boundingBox = geometry.boundingBox.clone();
35141
34751
 
35142
34752
  }
35143
34753
 
34754
+ geometryInfo.boundingSphere = null;
35144
34755
  if ( geometry.boundingSphere !== null ) {
35145
34756
 
35146
- bound.sphere.copy( geometry.boundingSphere );
35147
- bound.sphereInitialized = true;
35148
-
35149
- } else {
35150
-
35151
- bound.sphereInitialized = false;
34757
+ geometryInfo.boundingSphere = geometry.boundingSphere.clone();
35152
34758
 
35153
34759
  }
35154
34760
 
35155
- // set drawRange count
35156
- const drawRange = this._drawRanges[ geometryId ];
35157
- const posAttr = geometry.getAttribute( 'position' );
35158
- drawRange.count = hasIndex ? srcIndex.count : posAttr.count;
35159
34761
  this._visibilityChanged = true;
35160
-
35161
34762
  return geometryId;
35162
34763
 
35163
34764
  }
35164
34765
 
35165
- /*
35166
34766
  deleteGeometry( geometryId ) {
35167
34767
 
35168
- // TODO: delete geometry and associated instances
34768
+ const geometryInfoList = this._geometryInfo;
34769
+ if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
34770
+
34771
+ return this;
34772
+
34773
+ }
34774
+
34775
+ // delete any instances associated with this geometry
34776
+ const instanceInfo = this._instanceInfo;
34777
+ for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
34778
+
34779
+ if ( instanceInfo[ i ].geometryIndex === geometryId ) {
34780
+
34781
+ this.deleteInstance( i );
34782
+
34783
+ }
34784
+
34785
+ }
34786
+
34787
+ geometryInfoList[ geometryId ].active = false;
34788
+ this._availableGeometryIds.push( geometryId );
34789
+ this._visibilityChanged = true;
34790
+
34791
+ return this;
35169
34792
 
35170
34793
  }
35171
- */
35172
34794
 
35173
34795
  deleteInstance( instanceId ) {
35174
34796
 
35175
- const drawInfo = this._drawInfo;
35176
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
34797
+ const instanceInfo = this._instanceInfo;
34798
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35177
34799
 
35178
34800
  return this;
35179
34801
 
35180
34802
  }
35181
34803
 
35182
- drawInfo[ instanceId ].active = false;
34804
+ instanceInfo[ instanceId ].active = false;
35183
34805
  this._availableInstanceIds.push( instanceId );
35184
34806
  this._visibilityChanged = true;
35185
34807
 
@@ -35187,6 +34809,95 @@ class BatchedMesh extends Mesh {
35187
34809
 
35188
34810
  }
35189
34811
 
34812
+ optimize() {
34813
+
34814
+ // track the next indices to copy data to
34815
+ let nextVertexStart = 0;
34816
+ let nextIndexStart = 0;
34817
+
34818
+ // Iterate over all geometry ranges in order sorted from earliest in the geometry buffer to latest
34819
+ // in the geometry buffer. Because draw range objects can be reused there is no guarantee of their order.
34820
+ const geometryInfoList = this._geometryInfo;
34821
+ const indices = geometryInfoList
34822
+ .map( ( e, i ) => i )
34823
+ .sort( ( a, b ) => {
34824
+
34825
+ return geometryInfoList[ a ].vertexStart - geometryInfoList[ b ].vertexStart;
34826
+
34827
+ } );
34828
+
34829
+ const geometry = this.geometry;
34830
+ for ( let i = 0, l = geometryInfoList.length; i < l; i ++ ) {
34831
+
34832
+ // if a geometry range is inactive then don't copy anything
34833
+ const index = indices[ i ];
34834
+ const geometryInfo = geometryInfoList[ index ];
34835
+ if ( geometryInfo.active === false ) {
34836
+
34837
+ continue;
34838
+
34839
+ }
34840
+
34841
+ // if a geometry contains an index buffer then shift it, as well
34842
+ if ( geometry.index !== null ) {
34843
+
34844
+ if ( geometryInfo.indexStart !== nextIndexStart ) {
34845
+
34846
+ const { indexStart, vertexStart, reservedIndexCount } = geometryInfo;
34847
+ const index = geometry.index;
34848
+ const array = index.array;
34849
+
34850
+ // shift the index pointers based on how the vertex data will shift
34851
+ // adjusting the index must happen first so the original vertex start value is available
34852
+ const elementDelta = nextVertexStart - vertexStart;
34853
+ for ( let j = indexStart; j < indexStart + reservedIndexCount; j ++ ) {
34854
+
34855
+ array[ j ] = array[ j ] + elementDelta;
34856
+
34857
+ }
34858
+
34859
+ index.array.copyWithin( nextIndexStart, indexStart, indexStart + reservedIndexCount );
34860
+ index.addUpdateRange( nextIndexStart, reservedIndexCount );
34861
+
34862
+ geometryInfo.indexStart = nextIndexStart;
34863
+
34864
+ }
34865
+
34866
+ nextIndexStart += geometryInfo.reservedIndexCount;
34867
+
34868
+ }
34869
+
34870
+ // if a geometry needs to be moved then copy attribute data to overwrite unused space
34871
+ if ( geometryInfo.vertexStart !== nextVertexStart ) {
34872
+
34873
+ const { vertexStart, reservedVertexCount } = geometryInfo;
34874
+ const attributes = geometry.attributes;
34875
+ for ( const key in attributes ) {
34876
+
34877
+ const attribute = attributes[ key ];
34878
+ const { array, itemSize } = attribute;
34879
+ array.copyWithin( nextVertexStart * itemSize, vertexStart * itemSize, ( vertexStart + reservedVertexCount ) * itemSize );
34880
+ attribute.addUpdateRange( nextVertexStart * itemSize, reservedVertexCount * itemSize );
34881
+
34882
+ }
34883
+
34884
+ geometryInfo.vertexStart = nextVertexStart;
34885
+
34886
+ }
34887
+
34888
+ nextVertexStart += geometryInfo.reservedVertexCount;
34889
+ geometryInfo.start = geometry.index ? geometryInfo.indexStart : geometryInfo.vertexStart;
34890
+
34891
+ // step the next geometry points to the shifted position
34892
+ this._nextIndexStart = geometry.index ? geometryInfo.indexStart + geometryInfo.reservedIndexCount : 0;
34893
+ this._nextVertexStart = geometryInfo.vertexStart + geometryInfo.reservedVertexCount;
34894
+
34895
+ }
34896
+
34897
+ return this;
34898
+
34899
+ }
34900
+
35190
34901
  // get bounding box and compute it if it doesn't exist
35191
34902
  getBoundingBoxAt( geometryId, target ) {
35192
34903
 
@@ -35197,17 +34908,14 @@ class BatchedMesh extends Mesh {
35197
34908
  }
35198
34909
 
35199
34910
  // compute bounding box
35200
- const bound = this._bounds[ geometryId ];
35201
- const box = bound.box;
35202
34911
  const geometry = this.geometry;
35203
- if ( bound.boxInitialized === false ) {
35204
-
35205
- box.makeEmpty();
34912
+ const geometryInfo = this._geometryInfo[ geometryId ];
34913
+ if ( geometryInfo.boundingBox === null ) {
35206
34914
 
34915
+ const box = new Box3();
35207
34916
  const index = geometry.index;
35208
34917
  const position = geometry.attributes.position;
35209
- const drawRange = this._drawRanges[ geometryId ];
35210
- for ( let i = drawRange.start, l = drawRange.start + drawRange.count; i < l; i ++ ) {
34918
+ for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
35211
34919
 
35212
34920
  let iv = i;
35213
34921
  if ( index ) {
@@ -35220,11 +34928,11 @@ class BatchedMesh extends Mesh {
35220
34928
 
35221
34929
  }
35222
34930
 
35223
- bound.boxInitialized = true;
34931
+ geometryInfo.boundingBox = box;
35224
34932
 
35225
34933
  }
35226
34934
 
35227
- target.copy( box );
34935
+ target.copy( geometryInfo.boundingBox );
35228
34936
  return target;
35229
34937
 
35230
34938
  }
@@ -35239,22 +34947,19 @@ class BatchedMesh extends Mesh {
35239
34947
  }
35240
34948
 
35241
34949
  // compute bounding sphere
35242
- const bound = this._bounds[ geometryId ];
35243
- const sphere = bound.sphere;
35244
34950
  const geometry = this.geometry;
35245
- if ( bound.sphereInitialized === false ) {
35246
-
35247
- sphere.makeEmpty();
34951
+ const geometryInfo = this._geometryInfo[ geometryId ];
34952
+ if ( geometryInfo.boundingSphere === null ) {
35248
34953
 
34954
+ const sphere = new Sphere();
35249
34955
  this.getBoundingBoxAt( geometryId, _box$1 );
35250
34956
  _box$1.getCenter( sphere.center );
35251
34957
 
35252
34958
  const index = geometry.index;
35253
34959
  const position = geometry.attributes.position;
35254
- const drawRange = this._drawRanges[ geometryId ];
35255
34960
 
35256
34961
  let maxRadiusSq = 0;
35257
- for ( let i = drawRange.start, l = drawRange.start + drawRange.count; i < l; i ++ ) {
34962
+ for ( let i = geometryInfo.start, l = geometryInfo.start + geometryInfo.count; i < l; i ++ ) {
35258
34963
 
35259
34964
  let iv = i;
35260
34965
  if ( index ) {
@@ -35269,24 +34974,21 @@ class BatchedMesh extends Mesh {
35269
34974
  }
35270
34975
 
35271
34976
  sphere.radius = Math.sqrt( maxRadiusSq );
35272
- bound.sphereInitialized = true;
34977
+ geometryInfo.boundingSphere = sphere;
35273
34978
 
35274
34979
  }
35275
34980
 
35276
- target.copy( sphere );
34981
+ target.copy( geometryInfo.boundingSphere );
35277
34982
  return target;
35278
34983
 
35279
34984
  }
35280
34985
 
35281
34986
  setMatrixAt( instanceId, matrix ) {
35282
34987
 
35283
- // @TODO: Map geometryId to index of the arrays because
35284
- // optimize() can make geometryId mismatch the index
35285
-
35286
- const drawInfo = this._drawInfo;
34988
+ const instanceInfo = this._instanceInfo;
35287
34989
  const matricesTexture = this._matricesTexture;
35288
34990
  const matricesArray = this._matricesTexture.image.data;
35289
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
34991
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35290
34992
 
35291
34993
  return this;
35292
34994
 
@@ -35301,9 +35003,9 @@ class BatchedMesh extends Mesh {
35301
35003
 
35302
35004
  getMatrixAt( instanceId, matrix ) {
35303
35005
 
35304
- const drawInfo = this._drawInfo;
35006
+ const instanceInfo = this._instanceInfo;
35305
35007
  const matricesArray = this._matricesTexture.image.data;
35306
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35008
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35307
35009
 
35308
35010
  return null;
35309
35011
 
@@ -35321,13 +35023,10 @@ class BatchedMesh extends Mesh {
35321
35023
 
35322
35024
  }
35323
35025
 
35324
- // @TODO: Map id to index of the arrays because
35325
- // optimize() can make id mismatch the index
35326
-
35327
35026
  const colorsTexture = this._colorsTexture;
35328
35027
  const colorsArray = this._colorsTexture.image.data;
35329
- const drawInfo = this._drawInfo;
35330
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35028
+ const instanceInfo = this._instanceInfo;
35029
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35331
35030
 
35332
35031
  return this;
35333
35032
 
@@ -35343,8 +35042,8 @@ class BatchedMesh extends Mesh {
35343
35042
  getColorAt( instanceId, color ) {
35344
35043
 
35345
35044
  const colorsArray = this._colorsTexture.image.data;
35346
- const drawInfo = this._drawInfo;
35347
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35045
+ const instanceInfo = this._instanceInfo;
35046
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35348
35047
 
35349
35048
  return null;
35350
35049
 
@@ -35358,18 +35057,18 @@ class BatchedMesh extends Mesh {
35358
35057
 
35359
35058
  // if the geometry is out of range, not active, or visibility state
35360
35059
  // does not change then return early
35361
- const drawInfo = this._drawInfo;
35060
+ const instanceInfo = this._instanceInfo;
35362
35061
  if (
35363
- instanceId >= drawInfo.length ||
35364
- drawInfo[ instanceId ].active === false ||
35365
- drawInfo[ instanceId ].visible === value
35062
+ instanceId >= instanceInfo.length ||
35063
+ instanceInfo[ instanceId ].active === false ||
35064
+ instanceInfo[ instanceId ].visible === value
35366
35065
  ) {
35367
35066
 
35368
35067
  return this;
35369
35068
 
35370
35069
  }
35371
35070
 
35372
- drawInfo[ instanceId ].visible = value;
35071
+ instanceInfo[ instanceId ].visible = value;
35373
35072
  this._visibilityChanged = true;
35374
35073
 
35375
35074
  return this;
@@ -35379,35 +35078,36 @@ class BatchedMesh extends Mesh {
35379
35078
  getVisibleAt( instanceId ) {
35380
35079
 
35381
35080
  // return early if the geometry is out of range or not active
35382
- const drawInfo = this._drawInfo;
35383
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35081
+ const instanceInfo = this._instanceInfo;
35082
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35384
35083
 
35385
35084
  return false;
35386
35085
 
35387
35086
  }
35388
35087
 
35389
- return drawInfo[ instanceId ].visible;
35088
+ return instanceInfo[ instanceId ].visible;
35390
35089
 
35391
35090
  }
35392
35091
 
35393
35092
  setGeometryIdAt( instanceId, geometryId ) {
35394
35093
 
35395
35094
  // return early if the geometry is out of range or not active
35396
- const drawInfo = this._drawInfo;
35397
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35095
+ const instanceInfo = this._instanceInfo;
35096
+ const geometryInfoList = this._geometryInfo;
35097
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35398
35098
 
35399
35099
  return null;
35400
35100
 
35401
35101
  }
35402
35102
 
35403
35103
  // check if the provided geometryId is within the valid range
35404
- if ( geometryId < 0 || geometryId >= this._geometryCount ) {
35104
+ if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
35405
35105
 
35406
35106
  return null;
35407
35107
 
35408
35108
  }
35409
35109
 
35410
- drawInfo[ instanceId ].geometryIndex = geometryId;
35110
+ instanceInfo[ instanceId ].geometryIndex = geometryId;
35411
35111
 
35412
35112
  return this;
35413
35113
 
@@ -35415,14 +35115,14 @@ class BatchedMesh extends Mesh {
35415
35115
 
35416
35116
  getGeometryIdAt( instanceId ) {
35417
35117
 
35418
- const drawInfo = this._drawInfo;
35419
- if ( instanceId >= drawInfo.length || drawInfo[ instanceId ].active === false ) {
35118
+ const instanceInfo = this._instanceInfo;
35119
+ if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
35420
35120
 
35421
35121
  return - 1;
35422
35122
 
35423
35123
  }
35424
35124
 
35425
- return drawInfo[ instanceId ].geometryIndex;
35125
+ return instanceInfo[ instanceId ].geometryIndex;
35426
35126
 
35427
35127
  }
35428
35128
 
@@ -35434,19 +35134,136 @@ class BatchedMesh extends Mesh {
35434
35134
 
35435
35135
  }
35436
35136
 
35437
- const drawRange = this._drawRanges[ geometryId ];
35137
+ const geometryInfo = this._geometryInfo[ geometryId ];
35138
+ target.vertexStart = geometryInfo.vertexStart;
35139
+ target.vertexCount = geometryInfo.vertexCount;
35140
+ target.reservedVertexCount = geometryInfo.reservedVertexCount;
35141
+
35142
+ target.indexStart = geometryInfo.indexStart;
35143
+ target.indexCount = geometryInfo.indexCount;
35144
+ target.reservedIndexCount = geometryInfo.reservedIndexCount;
35438
35145
 
35439
- target.start = drawRange.start;
35440
- target.count = drawRange.count;
35146
+ target.start = geometryInfo.start;
35147
+ target.count = geometryInfo.count;
35441
35148
 
35442
35149
  return target;
35443
35150
 
35444
35151
  }
35445
35152
 
35153
+ setInstanceCount( maxInstanceCount ) {
35154
+
35155
+ // shrink the available instances as much as possible
35156
+ const availableInstanceIds = this._availableInstanceIds;
35157
+ const instanceInfo = this._instanceInfo;
35158
+ availableInstanceIds.sort( ascIdSort );
35159
+ while ( availableInstanceIds[ availableInstanceIds.length - 1 ] === instanceInfo.length ) {
35160
+
35161
+ instanceInfo.pop();
35162
+ availableInstanceIds.pop();
35163
+
35164
+ }
35165
+
35166
+ // throw an error if it can't be shrunk to the desired size
35167
+ if ( maxInstanceCount < instanceInfo.length ) {
35168
+
35169
+ throw new Error( `BatchedMesh: Instance ids outside the range ${ maxInstanceCount } are being used. Cannot shrink instance count.` );
35170
+
35171
+ }
35172
+
35173
+ // copy the multi draw counts
35174
+ const multiDrawCounts = new Int32Array( maxInstanceCount );
35175
+ const multiDrawStarts = new Int32Array( maxInstanceCount );
35176
+ copyArrayContents( this._multiDrawCounts, multiDrawCounts );
35177
+ copyArrayContents( this._multiDrawStarts, multiDrawStarts );
35178
+
35179
+ this._multiDrawCounts = multiDrawCounts;
35180
+ this._multiDrawStarts = multiDrawStarts;
35181
+ this._maxInstanceCount = maxInstanceCount;
35182
+
35183
+ // update texture data for instance sampling
35184
+ const indirectTexture = this._indirectTexture;
35185
+ const matricesTexture = this._matricesTexture;
35186
+ const colorsTexture = this._colorsTexture;
35187
+
35188
+ indirectTexture.dispose();
35189
+ this._initIndirectTexture();
35190
+ copyArrayContents( indirectTexture.image.data, this._indirectTexture.image.data );
35191
+
35192
+ matricesTexture.dispose();
35193
+ this._initMatricesTexture();
35194
+ copyArrayContents( matricesTexture.image.data, this._matricesTexture.image.data );
35195
+
35196
+ if ( colorsTexture ) {
35197
+
35198
+ colorsTexture.dispose();
35199
+ this._initColorsTexture();
35200
+ copyArrayContents( colorsTexture.image.data, this._colorsTexture.image.data );
35201
+
35202
+ }
35203
+
35204
+ }
35205
+
35206
+ setGeometrySize( maxVertexCount, maxIndexCount ) {
35207
+
35208
+ // Check if we can shrink to the requested vertex attribute size
35209
+ const validRanges = [ ...this._geometryInfo ].filter( info => info.active );
35210
+ const requiredVertexLength = Math.max( ...validRanges.map( range => range.vertexStart + range.reservedVertexCount ) );
35211
+ if ( requiredVertexLength > maxVertexCount ) {
35212
+
35213
+ throw new Error( `BatchedMesh: Geometry vertex values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
35214
+
35215
+ }
35216
+
35217
+ // Check if we can shrink to the requested index attribute size
35218
+ if ( this.geometry.index ) {
35219
+
35220
+ const requiredIndexLength = Math.max( ...validRanges.map( range => range.indexStart + range.reservedIndexCount ) );
35221
+ if ( requiredIndexLength > maxIndexCount ) {
35222
+
35223
+ throw new Error( `BatchedMesh: Geometry index values are being used outside the range ${ maxIndexCount }. Cannot shrink further.` );
35224
+
35225
+ }
35226
+
35227
+ }
35228
+
35229
+ //
35230
+
35231
+ // dispose of the previous geometry
35232
+ const oldGeometry = this.geometry;
35233
+ oldGeometry.dispose();
35234
+
35235
+ // recreate the geometry needed based on the previous variant
35236
+ this._maxVertexCount = maxVertexCount;
35237
+ this._maxIndexCount = maxIndexCount;
35238
+
35239
+ if ( this._geometryInitialized ) {
35240
+
35241
+ this._geometryInitialized = false;
35242
+ this.geometry = new BufferGeometry();
35243
+ this._initializeGeometry( oldGeometry );
35244
+
35245
+ }
35246
+
35247
+ // copy data from the previous geometry
35248
+ const geometry = this.geometry;
35249
+ if ( oldGeometry.index ) {
35250
+
35251
+ copyArrayContents( oldGeometry.index.array, geometry.index.array );
35252
+
35253
+ }
35254
+
35255
+ for ( const key in oldGeometry.attributes ) {
35256
+
35257
+ copyArrayContents( oldGeometry.attributes[ key ].array, geometry.attributes[ key ].array );
35258
+
35259
+ }
35260
+
35261
+ }
35262
+
35446
35263
  raycast( raycaster, intersects ) {
35447
35264
 
35448
- const drawInfo = this._drawInfo;
35449
- const drawRanges = this._drawRanges;
35265
+ const instanceInfo = this._instanceInfo;
35266
+ const geometryInfoList = this._geometryInfo;
35450
35267
  const matrixWorld = this.matrixWorld;
35451
35268
  const batchGeometry = this.geometry;
35452
35269
 
@@ -35466,19 +35283,19 @@ class BatchedMesh extends Mesh {
35466
35283
 
35467
35284
  }
35468
35285
 
35469
- for ( let i = 0, l = drawInfo.length; i < l; i ++ ) {
35286
+ for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
35470
35287
 
35471
- if ( ! drawInfo[ i ].visible || ! drawInfo[ i ].active ) {
35288
+ if ( ! instanceInfo[ i ].visible || ! instanceInfo[ i ].active ) {
35472
35289
 
35473
35290
  continue;
35474
35291
 
35475
35292
  }
35476
35293
 
35477
- const geometryId = drawInfo[ i ].geometryIndex;
35478
- const drawRange = drawRanges[ geometryId ];
35479
- _mesh.geometry.setDrawRange( drawRange.start, drawRange.count );
35294
+ const geometryId = instanceInfo[ i ].geometryIndex;
35295
+ const geometryInfo = geometryInfoList[ geometryId ];
35296
+ _mesh.geometry.setDrawRange( geometryInfo.start, geometryInfo.count );
35480
35297
 
35481
- // ge the intersects
35298
+ // get the intersects
35482
35299
  this.getMatrixAt( i, _mesh.matrixWorld ).premultiply( matrixWorld );
35483
35300
  this.getBoundingBoxAt( geometryId, _mesh.geometry.boundingBox );
35484
35301
  this.getBoundingSphereAt( geometryId, _mesh.geometry.boundingSphere );
@@ -35515,17 +35332,13 @@ class BatchedMesh extends Mesh {
35515
35332
  this.boundingBox = source.boundingBox !== null ? source.boundingBox.clone() : null;
35516
35333
  this.boundingSphere = source.boundingSphere !== null ? source.boundingSphere.clone() : null;
35517
35334
 
35518
- this._drawRanges = source._drawRanges.map( range => ( { ...range } ) );
35519
- this._reservedRanges = source._reservedRanges.map( range => ( { ...range } ) );
35520
-
35521
- this._drawInfo = source._drawInfo.map( inf => ( { ...inf } ) );
35522
- this._bounds = source._bounds.map( bound => ( {
35523
- boxInitialized: bound.boxInitialized,
35524
- box: bound.box.clone(),
35335
+ this._geometryInfo = source._geometryInfo.map( info => ( {
35336
+ ...info,
35525
35337
 
35526
- sphereInitialized: bound.sphereInitialized,
35527
- sphere: bound.sphere.clone()
35338
+ boundingBox: info.boundingBox !== null ? info.boundingBox.clone() : null,
35339
+ boundingSphere: info.boundingSphere !== null ? info.boundingSphere.clone() : null,
35528
35340
  } ) );
35341
+ this._instanceInfo = source._instanceInfo.map( info => ( { ...info } ) );
35529
35342
 
35530
35343
  this._maxInstanceCount = source._maxInstanceCount;
35531
35344
  this._maxVertexCount = source._maxVertexCount;
@@ -35587,10 +35400,10 @@ class BatchedMesh extends Mesh {
35587
35400
  const index = geometry.getIndex();
35588
35401
  const bytesPerElement = index === null ? 1 : index.array.BYTES_PER_ELEMENT;
35589
35402
 
35590
- const drawInfo = this._drawInfo;
35403
+ const instanceInfo = this._instanceInfo;
35591
35404
  const multiDrawStarts = this._multiDrawStarts;
35592
35405
  const multiDrawCounts = this._multiDrawCounts;
35593
- const drawRanges = this._drawRanges;
35406
+ const geometryInfoList = this._geometryInfo;
35594
35407
  const perObjectFrustumCulled = this.perObjectFrustumCulled;
35595
35408
  const indirectTexture = this._indirectTexture;
35596
35409
  const indirectArray = indirectTexture.image.data;
@@ -35598,29 +35411,29 @@ class BatchedMesh extends Mesh {
35598
35411
  // prepare the frustum in the local frame
35599
35412
  if ( perObjectFrustumCulled ) {
35600
35413
 
35601
- _projScreenMatrix$2
35414
+ _matrix$1
35602
35415
  .multiplyMatrices( camera.projectionMatrix, camera.matrixWorldInverse )
35603
35416
  .multiply( this.matrixWorld );
35604
35417
  _frustum.setFromProjectionMatrix(
35605
- _projScreenMatrix$2,
35418
+ _matrix$1,
35606
35419
  renderer.coordinateSystem
35607
35420
  );
35608
35421
 
35609
35422
  }
35610
35423
 
35611
- let count = 0;
35424
+ let multiDrawCount = 0;
35612
35425
  if ( this.sortObjects ) {
35613
35426
 
35614
35427
  // get the camera position in the local frame
35615
- _invMatrixWorld.copy( this.matrixWorld ).invert();
35616
- _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _invMatrixWorld );
35617
- _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _invMatrixWorld );
35428
+ _matrix$1.copy( this.matrixWorld ).invert();
35429
+ _vector$5.setFromMatrixPosition( camera.matrixWorld ).applyMatrix4( _matrix$1 );
35430
+ _forward.set( 0, 0, - 1 ).transformDirection( camera.matrixWorld ).transformDirection( _matrix$1 );
35618
35431
 
35619
- for ( let i = 0, l = drawInfo.length; i < l; i ++ ) {
35432
+ for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
35620
35433
 
35621
- if ( drawInfo[ i ].visible && drawInfo[ i ].active ) {
35434
+ if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
35622
35435
 
35623
- const geometryId = drawInfo[ i ].geometryIndex;
35436
+ const geometryId = instanceInfo[ i ].geometryIndex;
35624
35437
 
35625
35438
  // get the bounds in world space
35626
35439
  this.getMatrixAt( i, _matrix$1 );
@@ -35637,8 +35450,9 @@ class BatchedMesh extends Mesh {
35637
35450
  if ( ! culled ) {
35638
35451
 
35639
35452
  // get the distance from camera used for sorting
35453
+ const geometryInfo = geometryInfoList[ geometryId ];
35640
35454
  const z = _temp.subVectors( _sphere$2.center, _vector$5 ).dot( _forward );
35641
- _renderList.push( drawRanges[ geometryId ], z, i );
35455
+ _renderList.push( geometryInfo.start, geometryInfo.count, z, i );
35642
35456
 
35643
35457
  }
35644
35458
 
@@ -35662,10 +35476,10 @@ class BatchedMesh extends Mesh {
35662
35476
  for ( let i = 0, l = list.length; i < l; i ++ ) {
35663
35477
 
35664
35478
  const item = list[ i ];
35665
- multiDrawStarts[ count ] = item.start * bytesPerElement;
35666
- multiDrawCounts[ count ] = item.count;
35667
- indirectArray[ count ] = item.index;
35668
- count ++;
35479
+ multiDrawStarts[ multiDrawCount ] = item.start * bytesPerElement;
35480
+ multiDrawCounts[ multiDrawCount ] = item.count;
35481
+ indirectArray[ multiDrawCount ] = item.index;
35482
+ multiDrawCount ++;
35669
35483
 
35670
35484
  }
35671
35485
 
@@ -35673,11 +35487,11 @@ class BatchedMesh extends Mesh {
35673
35487
 
35674
35488
  } else {
35675
35489
 
35676
- for ( let i = 0, l = drawInfo.length; i < l; i ++ ) {
35490
+ for ( let i = 0, l = instanceInfo.length; i < l; i ++ ) {
35677
35491
 
35678
- if ( drawInfo[ i ].visible && drawInfo[ i ].active ) {
35492
+ if ( instanceInfo[ i ].visible && instanceInfo[ i ].active ) {
35679
35493
 
35680
- const geometryId = drawInfo[ i ].geometryIndex;
35494
+ const geometryId = instanceInfo[ i ].geometryIndex;
35681
35495
 
35682
35496
  // determine whether the batched geometry is within the frustum
35683
35497
  let culled = false;
@@ -35692,11 +35506,11 @@ class BatchedMesh extends Mesh {
35692
35506
 
35693
35507
  if ( ! culled ) {
35694
35508
 
35695
- const range = drawRanges[ geometryId ];
35696
- multiDrawStarts[ count ] = range.start * bytesPerElement;
35697
- multiDrawCounts[ count ] = range.count;
35698
- indirectArray[ count ] = i;
35699
- count ++;
35509
+ const geometryInfo = geometryInfoList[ geometryId ];
35510
+ multiDrawStarts[ multiDrawCount ] = geometryInfo.start * bytesPerElement;
35511
+ multiDrawCounts[ multiDrawCount ] = geometryInfo.count;
35512
+ indirectArray[ multiDrawCount ] = i;
35513
+ multiDrawCount ++;
35700
35514
 
35701
35515
  }
35702
35516
 
@@ -35707,7 +35521,7 @@ class BatchedMesh extends Mesh {
35707
35521
  }
35708
35522
 
35709
35523
  indirectTexture.needsUpdate = true;
35710
- this._multiDrawCount = count;
35524
+ this._multiDrawCount = multiDrawCount;
35711
35525
  this._visibilityChanged = false;
35712
35526
 
35713
35527
  }
@@ -35722,14 +35536,18 @@ class BatchedMesh extends Mesh {
35722
35536
 
35723
35537
  class LineBasicMaterial extends Material {
35724
35538
 
35539
+ static get type() {
35540
+
35541
+ return 'LineBasicMaterial';
35542
+
35543
+ }
35544
+
35725
35545
  constructor( parameters ) {
35726
35546
 
35727
35547
  super();
35728
35548
 
35729
35549
  this.isLineBasicMaterial = true;
35730
35550
 
35731
- this.type = 'LineBasicMaterial';
35732
-
35733
35551
  this.color = new Color( 0xffffff );
35734
35552
 
35735
35553
  this.map = null;
@@ -36067,14 +35885,18 @@ class LineLoop extends Line {
36067
35885
 
36068
35886
  class PointsMaterial extends Material {
36069
35887
 
35888
+ static get type() {
35889
+
35890
+ return 'PointsMaterial';
35891
+
35892
+ }
35893
+
36070
35894
  constructor( parameters ) {
36071
35895
 
36072
35896
  super();
36073
35897
 
36074
35898
  this.isPointsMaterial = true;
36075
35899
 
36076
- this.type = 'PointsMaterial';
36077
-
36078
35900
  this.color = new Color( 0xffffff );
36079
35901
 
36080
35902
  this.map = null;
@@ -38764,14 +38586,14 @@ class CylinderGeometry extends BufferGeometry {
38764
38586
 
38765
38587
  // faces
38766
38588
 
38767
- if ( radiusTop > 0 ) {
38589
+ if ( radiusTop > 0 || y !== 0 ) {
38768
38590
 
38769
38591
  indices.push( a, b, d );
38770
38592
  groupCount += 3;
38771
38593
 
38772
38594
  }
38773
38595
 
38774
- if ( radiusBottom > 0 ) {
38596
+ if ( radiusBottom > 0 || y !== heightSegments - 1 ) {
38775
38597
 
38776
38598
  indices.push( b, c, d );
38777
38599
  groupCount += 3;
@@ -42431,14 +42253,18 @@ var Geometries = /*#__PURE__*/Object.freeze({
42431
42253
 
42432
42254
  class ShadowMaterial extends Material {
42433
42255
 
42256
+ static get type() {
42257
+
42258
+ return 'ShadowMaterial';
42259
+
42260
+ }
42261
+
42434
42262
  constructor( parameters ) {
42435
42263
 
42436
42264
  super();
42437
42265
 
42438
42266
  this.isShadowMaterial = true;
42439
42267
 
42440
- this.type = 'ShadowMaterial';
42441
-
42442
42268
  this.color = new Color( 0x000000 );
42443
42269
  this.transparent = true;
42444
42270
 
@@ -42464,20 +42290,30 @@ class ShadowMaterial extends Material {
42464
42290
 
42465
42291
  class RawShaderMaterial extends ShaderMaterial {
42466
42292
 
42293
+ static get type() {
42294
+
42295
+ return 'RawShaderMaterial';
42296
+
42297
+ }
42298
+
42467
42299
  constructor( parameters ) {
42468
42300
 
42469
42301
  super( parameters );
42470
42302
 
42471
42303
  this.isRawShaderMaterial = true;
42472
42304
 
42473
- this.type = 'RawShaderMaterial';
42474
-
42475
42305
  }
42476
42306
 
42477
42307
  }
42478
42308
 
42479
42309
  class MeshStandardMaterial extends Material {
42480
42310
 
42311
+ static get type() {
42312
+
42313
+ return 'MeshStandardMaterial';
42314
+
42315
+ }
42316
+
42481
42317
  constructor( parameters ) {
42482
42318
 
42483
42319
  super();
@@ -42486,8 +42322,6 @@ class MeshStandardMaterial extends Material {
42486
42322
 
42487
42323
  this.defines = { 'STANDARD': '' };
42488
42324
 
42489
- this.type = 'MeshStandardMaterial';
42490
-
42491
42325
  this.color = new Color( 0xffffff ); // diffuse
42492
42326
  this.roughness = 1.0;
42493
42327
  this.metalness = 0.0;
@@ -42598,6 +42432,12 @@ class MeshStandardMaterial extends Material {
42598
42432
 
42599
42433
  class MeshPhysicalMaterial extends MeshStandardMaterial {
42600
42434
 
42435
+ static get type() {
42436
+
42437
+ return 'MeshPhysicalMaterial';
42438
+
42439
+ }
42440
+
42601
42441
  constructor( parameters ) {
42602
42442
 
42603
42443
  super();
@@ -42611,8 +42451,6 @@ class MeshPhysicalMaterial extends MeshStandardMaterial {
42611
42451
 
42612
42452
  };
42613
42453
 
42614
- this.type = 'MeshPhysicalMaterial';
42615
-
42616
42454
  this.anisotropyRotation = 0;
42617
42455
  this.anisotropyMap = null;
42618
42456
 
@@ -42836,14 +42674,18 @@ class MeshPhysicalMaterial extends MeshStandardMaterial {
42836
42674
 
42837
42675
  class MeshPhongMaterial extends Material {
42838
42676
 
42677
+ static get type() {
42678
+
42679
+ return 'MeshPhongMaterial';
42680
+
42681
+ }
42682
+
42839
42683
  constructor( parameters ) {
42840
42684
 
42841
42685
  super();
42842
42686
 
42843
42687
  this.isMeshPhongMaterial = true;
42844
42688
 
42845
- this.type = 'MeshPhongMaterial';
42846
-
42847
42689
  this.color = new Color( 0xffffff ); // diffuse
42848
42690
  this.specular = new Color( 0x111111 );
42849
42691
  this.shininess = 30;
@@ -42952,6 +42794,12 @@ class MeshPhongMaterial extends Material {
42952
42794
 
42953
42795
  class MeshToonMaterial extends Material {
42954
42796
 
42797
+ static get type() {
42798
+
42799
+ return 'MeshToonMaterial';
42800
+
42801
+ }
42802
+
42955
42803
  constructor( parameters ) {
42956
42804
 
42957
42805
  super();
@@ -42960,8 +42808,6 @@ class MeshToonMaterial extends Material {
42960
42808
 
42961
42809
  this.defines = { 'TOON': '' };
42962
42810
 
42963
- this.type = 'MeshToonMaterial';
42964
-
42965
42811
  this.color = new Color( 0xffffff );
42966
42812
 
42967
42813
  this.map = null;
@@ -43048,14 +42894,18 @@ class MeshToonMaterial extends Material {
43048
42894
 
43049
42895
  class MeshNormalMaterial extends Material {
43050
42896
 
42897
+ static get type() {
42898
+
42899
+ return 'MeshNormalMaterial';
42900
+
42901
+ }
42902
+
43051
42903
  constructor( parameters ) {
43052
42904
 
43053
42905
  super();
43054
42906
 
43055
42907
  this.isMeshNormalMaterial = true;
43056
42908
 
43057
- this.type = 'MeshNormalMaterial';
43058
-
43059
42909
  this.bumpMap = null;
43060
42910
  this.bumpScale = 1;
43061
42911
 
@@ -43104,14 +42954,18 @@ class MeshNormalMaterial extends Material {
43104
42954
 
43105
42955
  class MeshLambertMaterial extends Material {
43106
42956
 
42957
+ static get type() {
42958
+
42959
+ return 'MeshLambertMaterial';
42960
+
42961
+ }
42962
+
43107
42963
  constructor( parameters ) {
43108
42964
 
43109
42965
  super();
43110
42966
 
43111
42967
  this.isMeshLambertMaterial = true;
43112
42968
 
43113
- this.type = 'MeshLambertMaterial';
43114
-
43115
42969
  this.color = new Color( 0xffffff ); // diffuse
43116
42970
 
43117
42971
  this.map = null;
@@ -43216,6 +43070,12 @@ class MeshLambertMaterial extends Material {
43216
43070
 
43217
43071
  class MeshMatcapMaterial extends Material {
43218
43072
 
43073
+ static get type() {
43074
+
43075
+ return 'MeshMatcapMaterial';
43076
+
43077
+ }
43078
+
43219
43079
  constructor( parameters ) {
43220
43080
 
43221
43081
  super();
@@ -43224,8 +43084,6 @@ class MeshMatcapMaterial extends Material {
43224
43084
 
43225
43085
  this.defines = { 'MATCAP': '' };
43226
43086
 
43227
- this.type = 'MeshMatcapMaterial';
43228
-
43229
43087
  this.color = new Color( 0xffffff ); // diffuse
43230
43088
 
43231
43089
  this.matcap = null;
@@ -43291,14 +43149,18 @@ class MeshMatcapMaterial extends Material {
43291
43149
 
43292
43150
  class LineDashedMaterial extends LineBasicMaterial {
43293
43151
 
43152
+ static get type() {
43153
+
43154
+ return 'LineDashedMaterial';
43155
+
43156
+ }
43157
+
43294
43158
  constructor( parameters ) {
43295
43159
 
43296
43160
  super();
43297
43161
 
43298
43162
  this.isLineDashedMaterial = true;
43299
43163
 
43300
- this.type = 'LineDashedMaterial';
43301
-
43302
43164
  this.scale = 1;
43303
43165
  this.dashSize = 3;
43304
43166
  this.gapSize = 1;
@@ -55306,7 +55168,6 @@ exports.DetachedBindMode = DetachedBindMode;
55306
55168
  exports.DirectionalLight = DirectionalLight;
55307
55169
  exports.DirectionalLightHelper = DirectionalLightHelper;
55308
55170
  exports.DiscreteInterpolant = DiscreteInterpolant;
55309
- exports.DisplayP3ColorSpace = DisplayP3ColorSpace;
55310
55171
  exports.DodecahedronGeometry = DodecahedronGeometry;
55311
55172
  exports.DoubleSide = DoubleSide;
55312
55173
  exports.DstAlphaFactor = DstAlphaFactor;
@@ -55389,7 +55250,6 @@ exports.LineCurve3 = LineCurve3;
55389
55250
  exports.LineDashedMaterial = LineDashedMaterial;
55390
55251
  exports.LineLoop = LineLoop;
55391
55252
  exports.LineSegments = LineSegments;
55392
- exports.LinearDisplayP3ColorSpace = LinearDisplayP3ColorSpace;
55393
55253
  exports.LinearFilter = LinearFilter;
55394
55254
  exports.LinearInterpolant = LinearInterpolant;
55395
55255
  exports.LinearMipMapLinearFilter = LinearMipMapLinearFilter;
@@ -55461,7 +55321,6 @@ exports.OneMinusDstColorFactor = OneMinusDstColorFactor;
55461
55321
  exports.OneMinusSrcAlphaFactor = OneMinusSrcAlphaFactor;
55462
55322
  exports.OneMinusSrcColorFactor = OneMinusSrcColorFactor;
55463
55323
  exports.OrthographicCamera = OrthographicCamera;
55464
- exports.P3Primaries = P3Primaries;
55465
55324
  exports.PCFShadowMap = PCFShadowMap;
55466
55325
  exports.PCFSoftShadowMap = PCFSoftShadowMap;
55467
55326
  exports.PMREMGenerator = PMREMGenerator;
@@ -55527,7 +55386,6 @@ exports.RGIntegerFormat = RGIntegerFormat;
55527
55386
  exports.RawShaderMaterial = RawShaderMaterial;
55528
55387
  exports.Ray = Ray;
55529
55388
  exports.Raycaster = Raycaster;
55530
- exports.Rec709Primaries = Rec709Primaries;
55531
55389
  exports.RectAreaLight = RectAreaLight;
55532
55390
  exports.RedFormat = RedFormat;
55533
55391
  exports.RedIntegerFormat = RedIntegerFormat;