super-three 0.170.0 → 0.170.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/build/three.cjs +24410 -24422
  2. package/build/three.core.js +37002 -0
  3. package/build/three.core.min.js +6 -0
  4. package/build/three.module.js +10573 -47578
  5. package/build/three.module.min.js +1 -1
  6. package/build/three.tsl.js +533 -0
  7. package/build/three.tsl.min.js +6 -0
  8. package/build/three.webgpu.js +2907 -37975
  9. package/build/three.webgpu.min.js +1 -1
  10. package/build/three.webgpu.nodes.js +2914 -37959
  11. package/build/three.webgpu.nodes.min.js +1 -1
  12. package/examples/jsm/capabilities/WebGPU.js +1 -10
  13. package/examples/jsm/controls/ArcballControls.js +25 -21
  14. package/examples/jsm/controls/OrbitControls.js +41 -9
  15. package/examples/jsm/controls/PointerLockControls.js +2 -5
  16. package/examples/jsm/csm/CSMShadowNode.js +7 -5
  17. package/examples/jsm/geometries/DecalGeometry.js +5 -1
  18. package/examples/jsm/lighting/TiledLighting.js +1 -1
  19. package/examples/jsm/lines/LineGeometry.js +25 -0
  20. package/examples/jsm/lines/LineMaterial.js +1 -7
  21. package/examples/jsm/lines/webgpu/Line2.js +2 -1
  22. package/examples/jsm/lines/webgpu/LineSegments2.js +2 -1
  23. package/examples/jsm/lines/webgpu/Wireframe.js +2 -1
  24. package/examples/jsm/loaders/KTX2Loader.js +3 -0
  25. package/examples/jsm/loaders/MMDLoader.js +2 -6
  26. package/examples/jsm/loaders/MaterialXLoader.js +2 -2
  27. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -6
  28. package/examples/jsm/misc/ProgressiveLightMapGPU.js +2 -2
  29. package/examples/jsm/objects/InstancedPoints.js +2 -4
  30. package/examples/jsm/objects/LensflareMesh.js +4 -2
  31. package/examples/jsm/objects/SkyMesh.js +5 -3
  32. package/examples/jsm/objects/Water2Mesh.js +7 -3
  33. package/examples/jsm/objects/WaterMesh.js +5 -3
  34. package/examples/jsm/transpiler/AST.js +2 -2
  35. package/examples/jsm/transpiler/GLSLDecoder.js +57 -25
  36. package/examples/jsm/transpiler/TSLEncoder.js +11 -6
  37. package/examples/jsm/tsl/display/AfterImageNode.js +3 -3
  38. package/examples/jsm/tsl/display/AnaglyphPassNode.js +2 -2
  39. package/examples/jsm/tsl/display/AnamorphicNode.js +2 -2
  40. package/examples/jsm/tsl/display/BloomNode.js +3 -3
  41. package/examples/jsm/tsl/display/DenoiseNode.js +48 -12
  42. package/examples/jsm/tsl/display/DepthOfFieldNode.js +3 -2
  43. package/examples/jsm/tsl/display/DotScreenNode.js +2 -2
  44. package/examples/jsm/tsl/display/FXAANode.js +3 -3
  45. package/examples/jsm/tsl/display/FilmNode.js +3 -2
  46. package/examples/jsm/tsl/display/GTAONode.js +62 -27
  47. package/examples/jsm/tsl/display/GaussianBlurNode.js +6 -8
  48. package/examples/jsm/tsl/display/LensflareNode.js +3 -3
  49. package/examples/jsm/tsl/display/Lut3DNode.js +3 -2
  50. package/examples/jsm/tsl/display/OutlineNode.js +2 -2
  51. package/examples/jsm/tsl/display/ParallaxBarrierPassNode.js +2 -1
  52. package/examples/jsm/tsl/display/PixelationPassNode.js +4 -4
  53. package/examples/jsm/tsl/display/RGBShiftNode.js +2 -1
  54. package/examples/jsm/tsl/display/SMAANode.js +3 -3
  55. package/examples/jsm/tsl/display/SSAAPassNode.js +2 -2
  56. package/examples/jsm/tsl/display/SSRNode.js +31 -8
  57. package/examples/jsm/tsl/display/SobelOperatorNode.js +3 -3
  58. package/examples/jsm/tsl/display/StereoCompositePassNode.js +4 -4
  59. package/examples/jsm/tsl/display/StereoPassNode.js +2 -2
  60. package/examples/jsm/tsl/display/TRAAPassNode.js +2 -2
  61. package/examples/jsm/tsl/display/TransitionNode.js +3 -2
  62. package/examples/jsm/tsl/lighting/TiledLightsNode.js +6 -9
  63. package/examples/jsm/utils/SceneOptimizer.js +410 -0
  64. package/examples/jsm/utils/UVsDebug.js +1 -1
  65. package/package.json +3 -3
  66. package/src/Three.Core.js +178 -0
  67. package/src/Three.TSL.js +526 -0
  68. package/src/Three.WebGPU.Nodes.js +5 -186
  69. package/src/Three.WebGPU.js +4 -186
  70. package/src/Three.js +1 -177
  71. package/src/animation/AnimationClip.js +2 -2
  72. package/src/animation/AnimationObjectGroup.js +2 -2
  73. package/src/audio/Audio.js +38 -0
  74. package/src/cameras/PerspectiveCamera.js +6 -6
  75. package/src/cameras/StereoCamera.js +2 -2
  76. package/src/constants.js +1 -1
  77. package/src/core/BufferGeometry.js +5 -3
  78. package/src/core/InterleavedBuffer.js +4 -4
  79. package/src/core/Object3D.js +2 -2
  80. package/src/extras/core/Curve.js +3 -3
  81. package/src/extras/core/Shape.js +2 -2
  82. package/src/geometries/EdgesGeometry.js +2 -2
  83. package/src/geometries/LatheGeometry.js +2 -2
  84. package/src/lights/SpotLightShadow.js +2 -2
  85. package/src/materials/LineBasicMaterial.js +2 -6
  86. package/src/materials/LineDashedMaterial.js +1 -6
  87. package/src/materials/Material.js +3 -16
  88. package/src/materials/MeshBasicMaterial.js +2 -6
  89. package/src/materials/MeshDepthMaterial.js +2 -6
  90. package/src/materials/MeshDistanceMaterial.js +2 -6
  91. package/src/materials/MeshLambertMaterial.js +2 -6
  92. package/src/materials/MeshMatcapMaterial.js +2 -6
  93. package/src/materials/MeshNormalMaterial.js +2 -6
  94. package/src/materials/MeshPhongMaterial.js +3 -7
  95. package/src/materials/MeshPhysicalMaterial.js +4 -8
  96. package/src/materials/MeshStandardMaterial.js +2 -6
  97. package/src/materials/MeshToonMaterial.js +2 -6
  98. package/src/materials/PointsMaterial.js +2 -6
  99. package/src/materials/RawShaderMaterial.js +2 -6
  100. package/src/materials/ShaderMaterial.js +2 -6
  101. package/src/materials/ShadowMaterial.js +2 -6
  102. package/src/materials/SpriteMaterial.js +2 -6
  103. package/src/materials/nodes/Line2NodeMaterial.js +32 -13
  104. package/src/materials/nodes/LineDashedNodeMaterial.js +4 -2
  105. package/src/materials/nodes/NodeMaterial.js +64 -16
  106. package/src/materials/nodes/manager/NodeMaterialObserver.js +13 -10
  107. package/src/math/ColorManagement.js +130 -122
  108. package/src/math/Line3.js +2 -2
  109. package/src/math/Quaternion.js +2 -2
  110. package/src/math/Spherical.js +3 -3
  111. package/src/math/Vector2.js +7 -7
  112. package/src/math/Vector3.js +9 -9
  113. package/src/math/Vector4.js +11 -9
  114. package/src/nodes/Nodes.js +1 -0
  115. package/src/nodes/TSL.js +3 -1
  116. package/src/nodes/accessors/Arrays.js +27 -0
  117. package/src/nodes/accessors/BuiltinNode.js +26 -0
  118. package/src/nodes/accessors/ClippingNode.js +76 -42
  119. package/src/nodes/accessors/InstanceNode.js +17 -20
  120. package/src/nodes/accessors/InstancedMeshNode.js +26 -0
  121. package/src/nodes/accessors/Lights.js +32 -0
  122. package/src/nodes/accessors/StorageBufferNode.js +29 -9
  123. package/src/nodes/accessors/StorageTextureNode.js +10 -4
  124. package/src/nodes/accessors/TextureNode.js +1 -1
  125. package/src/nodes/core/NodeBuilder.js +2 -9
  126. package/src/nodes/core/NodeUtils.js +28 -0
  127. package/src/nodes/core/constants.js +6 -0
  128. package/src/nodes/display/BlendModes.js +99 -0
  129. package/src/nodes/display/ToonOutlinePassNode.js +3 -3
  130. package/src/nodes/display/ViewportDepthNode.js +21 -6
  131. package/src/nodes/functions/material/getAlphaHashThreshold.js +13 -7
  132. package/src/nodes/functions/material/getParallaxCorrectNormal.js +1 -1
  133. package/src/nodes/lighting/AnalyticLightNode.js +12 -4
  134. package/src/nodes/lighting/PointLightNode.js +10 -1
  135. package/src/nodes/lighting/PointShadowNode.js +254 -0
  136. package/src/nodes/lighting/ShadowNode.js +176 -67
  137. package/src/nodes/lighting/SpotLightNode.js +14 -2
  138. package/src/nodes/utils/RTTNode.js +9 -1
  139. package/src/nodes/utils/StorageArrayElementNode.js +2 -2
  140. package/src/objects/BatchedMesh.js +54 -95
  141. package/src/objects/ClippingGroup.js +19 -0
  142. package/src/objects/Skeleton.js +2 -2
  143. package/src/renderers/WebGLRenderer.js +94 -23
  144. package/src/renderers/common/Animation.js +23 -11
  145. package/src/renderers/common/Background.js +1 -1
  146. package/src/renderers/common/Bindings.js +20 -4
  147. package/src/renderers/common/ClippingContext.js +77 -85
  148. package/src/renderers/common/RenderList.js +9 -6
  149. package/src/renderers/common/RenderObject.js +27 -27
  150. package/src/renderers/common/RenderObjects.js +12 -6
  151. package/src/renderers/common/Renderer.js +63 -57
  152. package/src/renderers/common/Textures.js +11 -3
  153. package/src/renderers/common/UniformsGroup.js +16 -4
  154. package/src/renderers/common/extras/PMREMGenerator.js +89 -13
  155. package/src/renderers/common/nodes/NodeLibrary.js +2 -2
  156. package/src/renderers/common/nodes/NodeStorageBuffer.js +2 -3
  157. package/src/renderers/common/nodes/NodeUniform.js +42 -0
  158. package/src/renderers/webgl/WebGLBackground.js +20 -1
  159. package/src/renderers/webgl/WebGLGeometries.js +0 -28
  160. package/src/renderers/webgl-fallback/WebGLBackend.js +13 -6
  161. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +43 -12
  162. package/src/renderers/webgl-fallback/utils/WebGLState.js +26 -1
  163. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +4 -1
  164. package/src/renderers/webgpu/WebGPUBackend.js +47 -31
  165. package/src/renderers/webgpu/nodes/StandardNodeLibrary.js +13 -26
  166. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +184 -74
  167. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +15 -2
  168. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +72 -7
  169. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +5 -1
  170. package/src/textures/Source.js +2 -2
  171. package/src/textures/Texture.js +2 -2
  172. package/src/nodes/display/BlendMode.js +0 -54
@@ -306,7 +306,7 @@ class BatchedMesh extends Mesh {
306
306
  const batchGeometry = this.geometry;
307
307
  if ( Boolean( geometry.getIndex() ) !== Boolean( batchGeometry.getIndex() ) ) {
308
308
 
309
- throw new Error( 'BatchedMesh: All geometries must consistently have "index".' );
309
+ throw new Error( 'THREE.BatchedMesh: All geometries must consistently have "index".' );
310
310
 
311
311
  }
312
312
 
@@ -314,7 +314,7 @@ class BatchedMesh extends Mesh {
314
314
 
315
315
  if ( ! geometry.hasAttribute( attributeName ) ) {
316
316
 
317
- throw new Error( `BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
317
+ throw new Error( `THREE.BatchedMesh: Added geometry missing "${ attributeName }". All geometries must have consistent attributes.` );
318
318
 
319
319
  }
320
320
 
@@ -322,7 +322,7 @@ class BatchedMesh extends Mesh {
322
322
  const dstAttribute = batchGeometry.getAttribute( attributeName );
323
323
  if ( srcAttribute.itemSize !== dstAttribute.itemSize || srcAttribute.normalized !== dstAttribute.normalized ) {
324
324
 
325
- throw new Error( 'BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
325
+ throw new Error( 'THREE.BatchedMesh: All attributes must have a consistent itemSize and normalized value.' );
326
326
 
327
327
  }
328
328
 
@@ -330,6 +330,29 @@ class BatchedMesh extends Mesh {
330
330
 
331
331
  }
332
332
 
333
+ validateInstanceId( instanceId ) {
334
+
335
+ const instanceInfo = this._instanceInfo;
336
+ if ( instanceId < 0 || instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
337
+
338
+ throw new Error( `THREE.BatchedMesh: Invalid instanceId ${instanceId}. Instance is either out of range or has been deleted.` );
339
+
340
+ }
341
+
342
+ }
343
+
344
+ validateGeometryId( geometryId ) {
345
+
346
+ const geometryInfoList = this._geometryInfo;
347
+ if ( geometryId < 0 || geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
348
+
349
+ throw new Error( `THREE.BatchedMesh: Invalid geometryId ${geometryId}. Geometry is either out of range or has been deleted.` );
350
+
351
+ }
352
+
353
+ }
354
+
355
+
333
356
  setCustomSort( func ) {
334
357
 
335
358
  this.customSort = func;
@@ -394,7 +417,7 @@ class BatchedMesh extends Mesh {
394
417
  // ensure we're not over geometry
395
418
  if ( atCapacity && this._availableInstanceIds.length === 0 ) {
396
419
 
397
- throw new Error( 'BatchedMesh: Maximum item count reached.' );
420
+ throw new Error( 'THREE.BatchedMesh: Maximum item count reached.' );
398
421
 
399
422
  }
400
423
 
@@ -483,7 +506,7 @@ class BatchedMesh extends Mesh {
483
506
  geometryInfo.vertexStart + geometryInfo.reservedVertexCount > this._maxVertexCount
484
507
  ) {
485
508
 
486
- throw new Error( 'BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
509
+ throw new Error( 'THREE.BatchedMesh: Reserved space request exceeds the maximum buffer size.' );
487
510
 
488
511
  }
489
512
 
@@ -520,7 +543,7 @@ class BatchedMesh extends Mesh {
520
543
 
521
544
  if ( geometryId >= this._geometryCount ) {
522
545
 
523
- throw new Error( 'BatchedMesh: Maximum geometry count reached.' );
546
+ throw new Error( 'THREE.BatchedMesh: Maximum geometry count reached.' );
524
547
 
525
548
  }
526
549
 
@@ -537,7 +560,7 @@ class BatchedMesh extends Mesh {
537
560
  geometry.attributes.position.count > geometryInfo.reservedVertexCount
538
561
  ) {
539
562
 
540
- throw new Error( 'BatchedMesh: Reserved space not large enough for provided geometry.' );
563
+ throw new Error( 'THREE.BatchedMesh: Reserved space not large enough for provided geometry.' );
541
564
 
542
565
  }
543
566
 
@@ -652,14 +675,9 @@ class BatchedMesh extends Mesh {
652
675
 
653
676
  deleteInstance( instanceId ) {
654
677
 
655
- const instanceInfo = this._instanceInfo;
656
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
657
-
658
- return this;
678
+ this.validateInstanceId( instanceId );
659
679
 
660
- }
661
-
662
- instanceInfo[ instanceId ].active = false;
680
+ this._instanceInfo[ instanceId ].active = false;
663
681
  this._availableInstanceIds.push( instanceId );
664
682
  this._visibilityChanged = true;
665
683
 
@@ -843,15 +861,10 @@ class BatchedMesh extends Mesh {
843
861
 
844
862
  setMatrixAt( instanceId, matrix ) {
845
863
 
846
- const instanceInfo = this._instanceInfo;
864
+ this.validateInstanceId( instanceId );
865
+
847
866
  const matricesTexture = this._matricesTexture;
848
867
  const matricesArray = this._matricesTexture.image.data;
849
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
850
-
851
- return this;
852
-
853
- }
854
-
855
868
  matrix.toArray( matricesArray, instanceId * 16 );
856
869
  matricesTexture.needsUpdate = true;
857
870
 
@@ -861,37 +874,23 @@ class BatchedMesh extends Mesh {
861
874
 
862
875
  getMatrixAt( instanceId, matrix ) {
863
876
 
864
- const instanceInfo = this._instanceInfo;
865
- const matricesArray = this._matricesTexture.image.data;
866
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
867
-
868
- return null;
869
-
870
- }
871
-
872
- return matrix.fromArray( matricesArray, instanceId * 16 );
877
+ this.validateInstanceId( instanceId );
878
+ return matrix.fromArray( this._matricesTexture.image.data, instanceId * 16 );
873
879
 
874
880
  }
875
881
 
876
882
  setColorAt( instanceId, color ) {
877
883
 
884
+ this.validateInstanceId( instanceId );
885
+
878
886
  if ( this._colorsTexture === null ) {
879
887
 
880
888
  this._initColorsTexture();
881
889
 
882
890
  }
883
891
 
884
- const colorsTexture = this._colorsTexture;
885
- const colorsArray = this._colorsTexture.image.data;
886
- const instanceInfo = this._instanceInfo;
887
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
888
-
889
- return this;
890
-
891
- }
892
-
893
- color.toArray( colorsArray, instanceId * 4 );
894
- colorsTexture.needsUpdate = true;
892
+ color.toArray( this._colorsTexture.image.data, instanceId * 4 );
893
+ this._colorsTexture.needsUpdate = true;
895
894
 
896
895
  return this;
897
896
 
@@ -899,34 +898,22 @@ class BatchedMesh extends Mesh {
899
898
 
900
899
  getColorAt( instanceId, color ) {
901
900
 
902
- const colorsArray = this._colorsTexture.image.data;
903
- const instanceInfo = this._instanceInfo;
904
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
905
-
906
- return null;
907
-
908
- }
909
-
910
- return color.fromArray( colorsArray, instanceId * 4 );
901
+ this.validateInstanceId( instanceId );
902
+ return color.fromArray( this._colorsTexture.image.data, instanceId * 4 );
911
903
 
912
904
  }
913
905
 
914
906
  setVisibleAt( instanceId, value ) {
915
907
 
916
- // if the geometry is out of range, not active, or visibility state
917
- // does not change then return early
918
- const instanceInfo = this._instanceInfo;
919
- if (
920
- instanceId >= instanceInfo.length ||
921
- instanceInfo[ instanceId ].active === false ||
922
- instanceInfo[ instanceId ].visible === value
923
- ) {
908
+ this.validateInstanceId( instanceId );
909
+
910
+ if ( this._instanceInfo[ instanceId ].visible === value ) {
924
911
 
925
912
  return this;
926
913
 
927
914
  }
928
915
 
929
- instanceInfo[ instanceId ].visible = value;
916
+ this._instanceInfo[ instanceId ].visible = value;
930
917
  this._visibilityChanged = true;
931
918
 
932
919
  return this;
@@ -935,37 +922,18 @@ class BatchedMesh extends Mesh {
935
922
 
936
923
  getVisibleAt( instanceId ) {
937
924
 
938
- // return early if the geometry is out of range or not active
939
- const instanceInfo = this._instanceInfo;
940
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
941
-
942
- return false;
925
+ this.validateInstanceId( instanceId );
943
926
 
944
- }
945
-
946
- return instanceInfo[ instanceId ].visible;
927
+ return this._instanceInfo[ instanceId ].visible;
947
928
 
948
929
  }
949
930
 
950
931
  setGeometryIdAt( instanceId, geometryId ) {
951
932
 
952
- // return early if the geometry is out of range or not active
953
- const instanceInfo = this._instanceInfo;
954
- const geometryInfoList = this._geometryInfo;
955
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
956
-
957
- return null;
958
-
959
- }
933
+ this.validateInstanceId( instanceId );
934
+ this.validateGeometryId( geometryId );
960
935
 
961
- // check if the provided geometryId is within the valid range
962
- if ( geometryId >= geometryInfoList.length || geometryInfoList[ geometryId ].active === false ) {
963
-
964
- return null;
965
-
966
- }
967
-
968
- instanceInfo[ instanceId ].geometryIndex = geometryId;
936
+ this._instanceInfo[ instanceId ].geometryIndex = geometryId;
969
937
 
970
938
  return this;
971
939
 
@@ -973,24 +941,15 @@ class BatchedMesh extends Mesh {
973
941
 
974
942
  getGeometryIdAt( instanceId ) {
975
943
 
976
- const instanceInfo = this._instanceInfo;
977
- if ( instanceId >= instanceInfo.length || instanceInfo[ instanceId ].active === false ) {
978
-
979
- return - 1;
980
-
981
- }
944
+ this.validateInstanceId( instanceId );
982
945
 
983
- return instanceInfo[ instanceId ].geometryIndex;
946
+ return this._instanceInfo[ instanceId ].geometryIndex;
984
947
 
985
948
  }
986
949
 
987
950
  getGeometryRangeAt( geometryId, target = {} ) {
988
951
 
989
- if ( geometryId < 0 || geometryId >= this._geometryCount ) {
990
-
991
- return null;
992
-
993
- }
952
+ this.validateGeometryId( geometryId );
994
953
 
995
954
  const geometryInfo = this._geometryInfo[ geometryId ];
996
955
  target.vertexStart = geometryInfo.vertexStart;
@@ -0,0 +1,19 @@
1
+ import { Group } from './Group.js';
2
+
3
+ class ClippingGroup extends Group {
4
+
5
+ constructor() {
6
+
7
+ super();
8
+
9
+ this.isClippingGroup = true;
10
+ this.clippingPlanes = [];
11
+ this.enabled = true;
12
+ this.clipIntersection = false;
13
+ this.clipShadows = false;
14
+
15
+ }
16
+
17
+ }
18
+
19
+ export { ClippingGroup };
@@ -5,7 +5,7 @@ import {
5
5
  import { Bone } from './Bone.js';
6
6
  import { Matrix4 } from '../math/Matrix4.js';
7
7
  import { DataTexture } from '../textures/DataTexture.js';
8
- import * as MathUtils from '../math/MathUtils.js';
8
+ import { generateUUID } from '../math/MathUtils.js';
9
9
 
10
10
  const _offsetMatrix = /*@__PURE__*/ new Matrix4();
11
11
  const _identityMatrix = /*@__PURE__*/ new Matrix4();
@@ -14,7 +14,7 @@ class Skeleton {
14
14
 
15
15
  constructor( bones = [], boneInverses = [] ) {
16
16
 
17
- this.uuid = MathUtils.generateUUID();
17
+ this.uuid = generateUUID();
18
18
 
19
19
  this.bones = bones.slice( 0 );
20
20
  this.boneInverses = boneInverses;
@@ -643,6 +643,7 @@ class WebGLRenderer {
643
643
  canvas.removeEventListener( 'webglcontextrestored', onContextRestore, false );
644
644
  canvas.removeEventListener( 'webglcontextcreationerror', onContextCreationError, false );
645
645
 
646
+ background.dispose();
646
647
  renderLists.dispose();
647
648
  renderStates.dispose();
648
649
  properties.dispose();
@@ -2628,7 +2629,9 @@ class WebGLRenderer {
2628
2629
 
2629
2630
  };
2630
2631
 
2631
- this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, level = 0 ) {
2632
+ const _srcFramebuffer = _gl.createFramebuffer();
2633
+ const _dstFramebuffer = _gl.createFramebuffer();
2634
+ this.copyTextureToTexture = function ( srcTexture, dstTexture, srcRegion = null, dstPosition = null, srcLevel = 0, dstLevel = null ) {
2632
2635
 
2633
2636
  // support previous signature with dstPosition first
2634
2637
  if ( srcTexture.isTexture !== true ) {
@@ -2639,15 +2642,33 @@ class WebGLRenderer {
2639
2642
  dstPosition = arguments[ 0 ] || null;
2640
2643
  srcTexture = arguments[ 1 ];
2641
2644
  dstTexture = arguments[ 2 ];
2642
- level = arguments[ 3 ] || 0;
2645
+ dstLevel = arguments[ 3 ] || 0;
2643
2646
  srcRegion = null;
2644
2647
 
2645
2648
  }
2646
2649
 
2650
+ // support the previous signature with just a single dst mipmap level
2651
+ if ( dstLevel === null ) {
2652
+
2653
+ if ( srcLevel !== 0 ) {
2654
+
2655
+ // @deprecated, r171
2656
+ warnOnce( 'WebGLRenderer: copyTextureToTexture function signature has changed to support src and dst mipmap levels.' );
2657
+ dstLevel = srcLevel;
2658
+ srcLevel = 0;
2659
+
2660
+ } else {
2661
+
2662
+ dstLevel = 0;
2663
+
2664
+ }
2665
+
2666
+ }
2667
+
2647
2668
  // gather the necessary dimensions to copy
2648
2669
  let width, height, depth, minX, minY, minZ;
2649
2670
  let dstX, dstY, dstZ;
2650
- const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ level ] : srcTexture.image;
2671
+ const image = srcTexture.isCompressedTexture ? srcTexture.mipmaps[ dstLevel ] : srcTexture.image;
2651
2672
  if ( srcRegion !== null ) {
2652
2673
 
2653
2674
  width = srcRegion.max.x - srcRegion.min.x;
@@ -2659,9 +2680,23 @@ class WebGLRenderer {
2659
2680
 
2660
2681
  } else {
2661
2682
 
2662
- width = image.width;
2663
- height = image.height;
2664
- depth = image.depth || 1;
2683
+ const levelScale = Math.pow( 2, - srcLevel );
2684
+ width = Math.floor( image.width * levelScale );
2685
+ height = Math.floor( image.height * levelScale );
2686
+ if ( srcTexture.isDataArrayTexture ) {
2687
+
2688
+ depth = image.depth;
2689
+
2690
+ } else if ( srcTexture.isData3DTexture ) {
2691
+
2692
+ depth = Math.floor( image.depth * levelScale );
2693
+
2694
+ } else {
2695
+
2696
+ depth = 1;
2697
+
2698
+ }
2699
+
2665
2700
  minX = 0;
2666
2701
  minY = 0;
2667
2702
  minZ = 0;
@@ -2724,13 +2759,12 @@ class WebGLRenderer {
2724
2759
  // set up the src texture
2725
2760
  const isSrc3D = srcTexture.isDataArrayTexture || srcTexture.isData3DTexture;
2726
2761
  const isDst3D = dstTexture.isDataArrayTexture || dstTexture.isData3DTexture;
2727
- if ( srcTexture.isRenderTargetTexture || srcTexture.isDepthTexture ) {
2762
+ if ( srcTexture.isDepthTexture ) {
2728
2763
 
2729
2764
  const srcTextureProperties = properties.get( srcTexture );
2730
2765
  const dstTextureProperties = properties.get( dstTexture );
2731
2766
  const srcRenderTargetProperties = properties.get( srcTextureProperties.__renderTarget );
2732
2767
  const dstRenderTargetProperties = properties.get( dstTextureProperties.__renderTarget );
2733
-
2734
2768
  state.bindFramebuffer( _gl.READ_FRAMEBUFFER, srcRenderTargetProperties.__webglFramebuffer );
2735
2769
  state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, dstRenderTargetProperties.__webglFramebuffer );
2736
2770
 
@@ -2739,32 +2773,69 @@ class WebGLRenderer {
2739
2773
  // if the source or destination are a 3d target then a layer needs to be bound
2740
2774
  if ( isSrc3D ) {
2741
2775
 
2742
- _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( srcTexture ).__webglTexture, level, minZ + i );
2776
+ _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( srcTexture ).__webglTexture, srcLevel, minZ + i );
2777
+ _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( dstTexture ).__webglTexture, dstLevel, dstZ + i );
2778
+
2779
+ }
2780
+
2781
+ _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.DEPTH_BUFFER_BIT, _gl.NEAREST );
2782
+
2783
+ }
2784
+
2785
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
2786
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );
2787
+
2788
+ } else if ( srcLevel !== 0 || srcTexture.isRenderTargetTexture || properties.has( srcTexture ) ) {
2789
+
2790
+ // get the appropriate frame buffers
2791
+ const srcTextureProperties = properties.get( srcTexture );
2792
+ const dstTextureProperties = properties.get( dstTexture );
2793
+
2794
+ // bind the frame buffer targets
2795
+ state.bindFramebuffer( _gl.READ_FRAMEBUFFER, _srcFramebuffer );
2796
+ state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, _dstFramebuffer );
2797
+
2798
+ for ( let i = 0; i < depth; i ++ ) {
2799
+
2800
+ // assign the correct layers and mip maps to the frame buffers
2801
+ if ( isSrc3D ) {
2802
+
2803
+ _gl.framebufferTextureLayer( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, srcTextureProperties.__webglTexture, srcLevel, minZ + i );
2804
+
2805
+ } else {
2806
+
2807
+ _gl.framebufferTexture2D( _gl.READ_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, srcTextureProperties.__webglTexture, srcLevel );
2743
2808
 
2744
2809
  }
2745
2810
 
2746
- if ( srcTexture.isDepthTexture ) {
2811
+ if ( isDst3D ) {
2747
2812
 
2748
- if ( isDst3D ) {
2813
+ _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, dstTextureProperties.__webglTexture, dstLevel, dstZ + i );
2749
2814
 
2750
- _gl.framebufferTextureLayer( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, properties.get( dstTexture ).__webglTexture, level, dstZ + i );
2815
+ } else {
2751
2816
 
2752
- }
2817
+ _gl.framebufferTexture2D( _gl.DRAW_FRAMEBUFFER, _gl.COLOR_ATTACHMENT0, _gl.TEXTURE_2D, dstTextureProperties.__webglTexture, dstLevel );
2818
+
2819
+ }
2820
+
2821
+ // copy the data using the fastest function that can achieve the copy
2822
+ if ( srcLevel !== 0 ) {
2753
2823
 
2754
- _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.DEPTH_BUFFER_BIT, _gl.NEAREST );
2824
+ _gl.blitFramebuffer( minX, minY, width, height, dstX, dstY, width, height, _gl.COLOR_BUFFER_BIT, _gl.NEAREST );
2755
2825
 
2756
2826
  } else if ( isDst3D ) {
2757
2827
 
2758
- _gl.copyTexSubImage3D( glTarget, level, dstX, dstY, dstZ + i, minX, minY, width, height );
2828
+ _gl.copyTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ + i, minX, minY, width, height );
2759
2829
 
2760
2830
  } else {
2761
2831
 
2762
- _gl.copyTexSubImage2D( glTarget, level, dstX, dstY, dstZ + i, minX, minY, width, height );
2832
+ _gl.copyTexSubImage2D( glTarget, dstLevel, dstX, dstY, minX, minY, width, height );
2763
2833
 
2764
2834
  }
2765
2835
 
2766
2836
  }
2767
2837
 
2838
+ // unbind read, draw buffers
2768
2839
  state.bindFramebuffer( _gl.READ_FRAMEBUFFER, null );
2769
2840
  state.bindFramebuffer( _gl.DRAW_FRAMEBUFFER, null );
2770
2841
 
@@ -2775,15 +2846,15 @@ class WebGLRenderer {
2775
2846
  // copy data into the 3d texture
2776
2847
  if ( srcTexture.isDataTexture || srcTexture.isData3DTexture ) {
2777
2848
 
2778
- _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
2849
+ _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image.data );
2779
2850
 
2780
2851
  } else if ( dstTexture.isCompressedArrayTexture ) {
2781
2852
 
2782
- _gl.compressedTexSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
2853
+ _gl.compressedTexSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, image.data );
2783
2854
 
2784
2855
  } else {
2785
2856
 
2786
- _gl.texSubImage3D( glTarget, level, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
2857
+ _gl.texSubImage3D( glTarget, dstLevel, dstX, dstY, dstZ, width, height, depth, glFormat, glType, image );
2787
2858
 
2788
2859
  }
2789
2860
 
@@ -2792,15 +2863,15 @@ class WebGLRenderer {
2792
2863
  // copy data into the 2d texture
2793
2864
  if ( srcTexture.isDataTexture ) {
2794
2865
 
2795
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image.data );
2866
+ _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image.data );
2796
2867
 
2797
2868
  } else if ( srcTexture.isCompressedTexture ) {
2798
2869
 
2799
- _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, image.width, image.height, glFormat, image.data );
2870
+ _gl.compressedTexSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, image.width, image.height, glFormat, image.data );
2800
2871
 
2801
2872
  } else {
2802
2873
 
2803
- _gl.texSubImage2D( _gl.TEXTURE_2D, level, dstX, dstY, width, height, glFormat, glType, image );
2874
+ _gl.texSubImage2D( _gl.TEXTURE_2D, dstLevel, dstX, dstY, width, height, glFormat, glType, image );
2804
2875
 
2805
2876
  }
2806
2877
 
@@ -2816,7 +2887,7 @@ class WebGLRenderer {
2816
2887
  _gl.pixelStorei( _gl.UNPACK_SKIP_IMAGES, currentUnpackSkipImages );
2817
2888
 
2818
2889
  // Generate mipmaps only when copying level 0
2819
- if ( level === 0 && dstTexture.generateMipmaps ) {
2890
+ if ( dstLevel === 0 && dstTexture.generateMipmaps ) {
2820
2891
 
2821
2892
  _gl.generateMipmap( glTarget );
2822
2893
 
@@ -5,18 +5,17 @@ class Animation {
5
5
  this.nodes = nodes;
6
6
  this.info = info;
7
7
 
8
- this.animationLoop = null;
9
- this.requestId = null;
10
-
11
- this._init();
8
+ this._context = self;
9
+ this._animationLoop = null;
10
+ this._requestId = null;
12
11
 
13
12
  }
14
13
 
15
- _init() {
14
+ start() {
16
15
 
17
16
  const update = ( time, frame ) => {
18
17
 
19
- this.requestId = self.requestAnimationFrame( update );
18
+ this._requestId = this._context.requestAnimationFrame( update );
20
19
 
21
20
  if ( this.info.autoReset === true ) this.info.reset();
22
21
 
@@ -24,7 +23,7 @@ class Animation {
24
23
 
25
24
  this.info.frame = this.nodes.nodeFrame.frameId;
26
25
 
27
- if ( this.animationLoop !== null ) this.animationLoop( time, frame );
26
+ if ( this._animationLoop !== null ) this._animationLoop( time, frame );
28
27
 
29
28
  };
30
29
 
@@ -32,16 +31,29 @@ class Animation {
32
31
 
33
32
  }
34
33
 
35
- dispose() {
34
+ stop() {
35
+
36
+ this._context.cancelAnimationFrame( this._requestId );
36
37
 
37
- self.cancelAnimationFrame( this.requestId );
38
- this.requestId = null;
38
+ this._requestId = null;
39
39
 
40
40
  }
41
41
 
42
42
  setAnimationLoop( callback ) {
43
43
 
44
- this.animationLoop = callback;
44
+ this._animationLoop = callback;
45
+
46
+ }
47
+
48
+ setContext( context ) {
49
+
50
+ this._context = context;
51
+
52
+ }
53
+
54
+ dispose() {
55
+
56
+ this.stop();
45
57
 
46
58
  }
47
59
 
@@ -99,7 +99,7 @@ class Background extends DataMap {
99
99
 
100
100
  }
101
101
 
102
- renderList.unshift( backgroundMesh, backgroundMesh.geometry, backgroundMesh.material, 0, 0, null );
102
+ renderList.unshift( backgroundMesh, backgroundMesh.geometry, backgroundMesh.material, 0, 0, null, null );
103
103
 
104
104
  } else {
105
105
 
@@ -32,7 +32,7 @@ class Bindings extends DataMap {
32
32
 
33
33
  this._init( bindGroup );
34
34
 
35
- this.backend.createBindings( bindGroup, bindings );
35
+ this.backend.createBindings( bindGroup, bindings, 0 );
36
36
 
37
37
  groupData.bindGroup = bindGroup;
38
38
 
@@ -56,7 +56,7 @@ class Bindings extends DataMap {
56
56
 
57
57
  this._init( bindGroup );
58
58
 
59
- this.backend.createBindings( bindGroup, bindings );
59
+ this.backend.createBindings( bindGroup, bindings, 0 );
60
60
 
61
61
  groupData.bindGroup = bindGroup;
62
62
 
@@ -116,6 +116,9 @@ class Bindings extends DataMap {
116
116
  const { backend } = this;
117
117
 
118
118
  let needsBindingsUpdate = false;
119
+ let cacheBindings = true;
120
+ let cacheIndex = 0;
121
+ let version = 0;
119
122
 
120
123
  // iterate over all bindings and check if buffer updates or a new binding group is required
121
124
 
@@ -145,7 +148,9 @@ class Bindings extends DataMap {
145
148
 
146
149
  } else if ( binding.isSampledTexture ) {
147
150
 
148
- if ( binding.needsBindingsUpdate( this.textures.get( binding.texture ).generation ) ) needsBindingsUpdate = true;
151
+ const texturesTextureData = this.textures.get( binding.texture );
152
+
153
+ if ( binding.needsBindingsUpdate( texturesTextureData.generation ) ) needsBindingsUpdate = true;
149
154
 
150
155
  const updated = binding.update();
151
156
 
@@ -159,6 +164,17 @@ class Bindings extends DataMap {
159
164
 
160
165
  const textureData = backend.get( texture );
161
166
 
167
+ if ( textureData.externalTexture !== undefined || texturesTextureData.isDefaultTexture ) {
168
+
169
+ cacheBindings = false;
170
+
171
+ } else {
172
+
173
+ cacheIndex = cacheIndex * 10 + texture.id;
174
+ version += texture.version;
175
+
176
+ }
177
+
162
178
  if ( backend.isWebGPUBackend === true && textureData.texture === undefined && textureData.externalTexture === undefined ) {
163
179
 
164
180
  // TODO: Remove this once we found why updated === false isn't bound to a texture in the WebGPU backend
@@ -193,7 +209,7 @@ class Bindings extends DataMap {
193
209
 
194
210
  if ( needsBindingsUpdate === true ) {
195
211
 
196
- this.backend.updateBindings( bindGroup, bindings );
212
+ this.backend.updateBindings( bindGroup, bindings, cacheBindings ? cacheIndex : 0, version );
197
213
 
198
214
  }
199
215