super-three 0.172.0 → 0.173.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 (180) hide show
  1. package/LICENSE +1 -1
  2. package/build/three.cjs +439 -380
  3. package/build/three.core.js +413 -41
  4. package/build/three.core.min.js +2 -2
  5. package/build/three.module.js +28 -344
  6. package/build/three.module.min.js +2 -2
  7. package/build/three.tsl.js +11 -3
  8. package/build/three.tsl.min.js +2 -2
  9. package/build/three.webgpu.js +7550 -1798
  10. package/build/three.webgpu.min.js +2 -2
  11. package/build/three.webgpu.nodes.js +7551 -1798
  12. package/build/three.webgpu.nodes.min.js +2 -2
  13. package/examples/jsm/animation/CCDIKSolver.js +6 -5
  14. package/examples/jsm/capabilities/WebGPU.js +1 -1
  15. package/examples/jsm/controls/ArcballControls.js +23 -21
  16. package/examples/jsm/exporters/GLTFExporter.js +26 -25
  17. package/examples/jsm/geometries/TextGeometry.js +1 -12
  18. package/examples/jsm/interactive/InteractiveGroup.js +108 -51
  19. package/examples/jsm/libs/demuxer_mp4.js +109 -0
  20. package/examples/jsm/loaders/GCodeLoader.js +3 -1
  21. package/examples/jsm/loaders/GLTFLoader.js +0 -2
  22. package/examples/jsm/loaders/TDSLoader.js +0 -1
  23. package/examples/jsm/materials/MeshGouraudMaterial.js +2 -0
  24. package/examples/jsm/misc/GPUComputationRenderer.js +6 -7
  25. package/examples/jsm/misc/ProgressiveLightMap.js +4 -3
  26. package/examples/jsm/misc/ProgressiveLightMapGPU.js +4 -3
  27. package/examples/jsm/misc/Volume.js +7 -5
  28. package/examples/jsm/misc/VolumeSlice.js +5 -3
  29. package/examples/jsm/objects/WaterMesh.js +25 -20
  30. package/examples/jsm/physics/JoltPhysics.js +7 -7
  31. package/examples/jsm/physics/RapierPhysics.js +4 -4
  32. package/examples/jsm/postprocessing/EffectComposer.js +23 -2
  33. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  34. package/examples/jsm/postprocessing/Pass.js +6 -1
  35. package/examples/jsm/shaders/OutputShader.js +5 -1
  36. package/examples/jsm/transpiler/GLSLDecoder.js +2 -2
  37. package/examples/jsm/transpiler/TSLEncoder.js +2 -0
  38. package/package.json +1 -1
  39. package/src/Three.Core.js +2 -0
  40. package/src/Three.TSL.js +9 -1
  41. package/src/cameras/ArrayCamera.js +1 -0
  42. package/src/constants.js +6 -1
  43. package/src/core/BufferAttribute.js +4 -0
  44. package/src/core/EventDispatcher.js +8 -6
  45. package/src/extras/ImageUtils.js +1 -11
  46. package/src/loaders/nodes/NodeObjectLoader.js +1 -1
  47. package/src/materials/nodes/MeshBasicNodeMaterial.js +1 -1
  48. package/src/materials/nodes/MeshPhysicalNodeMaterial.js +1 -1
  49. package/src/materials/nodes/NodeMaterial.js +5 -5
  50. package/src/materials/nodes/NodeMaterials.js +0 -1
  51. package/src/materials/nodes/PointsNodeMaterial.js +109 -7
  52. package/src/materials/nodes/SpriteNodeMaterial.js +1 -1
  53. package/src/materials/nodes/VolumeNodeMaterial.js +3 -3
  54. package/src/materials/nodes/manager/NodeMaterialObserver.js +8 -0
  55. package/src/nodes/Nodes.js +4 -0
  56. package/src/nodes/TSL.js +4 -0
  57. package/src/nodes/accessors/Arrays.js +30 -8
  58. package/src/nodes/accessors/BatchNode.js +3 -3
  59. package/src/nodes/accessors/BufferAttributeNode.js +1 -1
  60. package/src/nodes/accessors/Camera.js +64 -3
  61. package/src/nodes/accessors/InstanceNode.js +1 -1
  62. package/src/nodes/accessors/MaterialNode.js +9 -9
  63. package/src/nodes/accessors/ModelViewProjectionNode.js +1 -1
  64. package/src/nodes/accessors/Normal.js +6 -2
  65. package/src/nodes/accessors/Object3DNode.js +0 -1
  66. package/src/nodes/accessors/Position.js +6 -6
  67. package/src/nodes/accessors/ReferenceBaseNode.js +2 -4
  68. package/src/nodes/accessors/ReferenceNode.js +2 -3
  69. package/src/nodes/accessors/StorageBufferNode.js +42 -5
  70. package/src/nodes/accessors/Tangent.js +2 -2
  71. package/src/nodes/accessors/Texture3DNode.js +1 -1
  72. package/src/nodes/accessors/TextureNode.js +12 -5
  73. package/src/nodes/accessors/UniformArrayNode.js +9 -3
  74. package/src/nodes/accessors/VelocityNode.js +0 -2
  75. package/src/nodes/code/ScriptableNode.js +3 -3
  76. package/src/nodes/core/ArrayNode.js +125 -0
  77. package/src/nodes/core/ConstNode.js +8 -0
  78. package/src/nodes/core/Node.js +14 -1
  79. package/src/nodes/core/NodeBuilder.js +229 -19
  80. package/src/nodes/core/NodeUtils.js +11 -1
  81. package/src/nodes/core/NodeVar.js +17 -1
  82. package/src/nodes/core/OutputStructNode.js +19 -9
  83. package/src/nodes/core/StackNode.js +20 -1
  84. package/src/nodes/core/StructNode.js +121 -0
  85. package/src/nodes/core/StructType.js +13 -0
  86. package/src/nodes/core/StructTypeNode.js +82 -21
  87. package/src/nodes/core/TempNode.js +1 -1
  88. package/src/nodes/core/VarNode.js +94 -7
  89. package/src/nodes/core/VaryingNode.js +19 -3
  90. package/src/nodes/display/BlendModes.js +88 -1
  91. package/src/nodes/display/BumpMapNode.js +6 -6
  92. package/src/nodes/display/NormalMapNode.js +6 -6
  93. package/src/nodes/display/PassNode.js +3 -1
  94. package/src/nodes/display/ScreenNode.js +9 -0
  95. package/src/nodes/fog/Fog.js +17 -0
  96. package/src/nodes/gpgpu/AtomicFunctionNode.js +20 -4
  97. package/src/nodes/gpgpu/ComputeBuiltinNode.js +8 -0
  98. package/src/nodes/gpgpu/WorkgroupInfoNode.js +1 -1
  99. package/src/nodes/lighting/ShadowNode.js +1 -1
  100. package/src/nodes/math/ConditionalNode.js +8 -1
  101. package/src/nodes/math/MathNode.js +14 -1
  102. package/src/nodes/math/OperatorNode.js +96 -18
  103. package/src/nodes/pmrem/PMREMUtils.js +1 -1
  104. package/src/nodes/shapes/Shapes.js +33 -0
  105. package/src/nodes/tsl/TSLBase.js +1 -0
  106. package/src/nodes/tsl/TSLCore.js +22 -2
  107. package/src/nodes/utils/ArrayElementNode.js +1 -1
  108. package/src/nodes/utils/LoopNode.js +8 -1
  109. package/src/nodes/utils/MemberNode.js +68 -0
  110. package/src/nodes/utils/StorageArrayElementNode.js +14 -0
  111. package/src/nodes/utils/Timer.js +21 -0
  112. package/src/objects/BatchedMesh.js +1 -1
  113. package/src/objects/Line.js +6 -6
  114. package/src/renderers/WebGLRenderer.js +7 -0
  115. package/src/renderers/common/Animation.js +23 -1
  116. package/src/renderers/common/Backend.js +58 -15
  117. package/src/renderers/common/Background.js +14 -0
  118. package/src/renderers/common/Binding.js +1 -1
  119. package/src/renderers/common/BufferUtils.js +1 -1
  120. package/src/renderers/common/BundleGroup.js +1 -1
  121. package/src/renderers/common/ChainMap.js +9 -7
  122. package/src/renderers/common/ClippingContext.js +1 -1
  123. package/src/renderers/common/Color4.js +7 -3
  124. package/src/renderers/common/Geometries.js +2 -23
  125. package/src/renderers/common/Info.js +1 -45
  126. package/src/renderers/common/Lighting.js +8 -6
  127. package/src/renderers/common/Pipelines.js +3 -3
  128. package/src/renderers/common/PostProcessing.js +24 -8
  129. package/src/renderers/common/QuadMesh.js +1 -1
  130. package/src/renderers/common/RenderBundles.js +9 -3
  131. package/src/renderers/common/RenderContext.js +37 -3
  132. package/src/renderers/common/RenderContexts.js +30 -17
  133. package/src/renderers/common/RenderList.js +2 -2
  134. package/src/renderers/common/RenderLists.js +9 -3
  135. package/src/renderers/common/RenderObject.js +76 -17
  136. package/src/renderers/common/RenderObjects.js +9 -7
  137. package/src/renderers/common/Renderer.js +86 -67
  138. package/src/renderers/common/SampledTexture.js +0 -1
  139. package/src/renderers/common/StorageBufferAttribute.js +1 -1
  140. package/src/renderers/common/StorageInstancedBufferAttribute.js +1 -1
  141. package/src/renderers/common/StorageTexture.js +1 -1
  142. package/src/renderers/common/Textures.js +14 -7
  143. package/src/renderers/common/TimestampQueryPool.js +39 -0
  144. package/src/renderers/common/Uniform.js +37 -1
  145. package/src/renderers/common/UniformsGroup.js +2 -0
  146. package/src/renderers/common/XRManager.js +1193 -0
  147. package/src/renderers/common/XRRenderTarget.js +74 -0
  148. package/src/renderers/common/extras/PMREMGenerator.js +53 -8
  149. package/src/renderers/common/nodes/NodeBuilderState.js +4 -4
  150. package/src/renderers/common/nodes/NodeLibrary.js +5 -5
  151. package/src/renderers/common/nodes/NodeSampledTexture.js +0 -1
  152. package/src/renderers/common/nodes/NodeUniform.js +54 -2
  153. package/src/renderers/common/nodes/Nodes.js +25 -18
  154. package/src/renderers/webgl/WebGLBackground.js +4 -0
  155. package/src/renderers/webgl-fallback/WebGLBackend.js +295 -110
  156. package/src/renderers/webgl-fallback/nodes/GLSLNodeBuilder.js +347 -17
  157. package/src/renderers/webgl-fallback/utils/WebGLAttributeUtils.js +57 -0
  158. package/src/renderers/webgl-fallback/utils/WebGLCapabilities.js +28 -0
  159. package/src/renderers/webgl-fallback/utils/WebGLExtensions.js +45 -0
  160. package/src/renderers/webgl-fallback/utils/WebGLState.js +323 -11
  161. package/src/renderers/webgl-fallback/utils/WebGLTextureUtils.js +167 -21
  162. package/src/renderers/webgl-fallback/utils/WebGLTimestampQueryPool.js +359 -0
  163. package/src/renderers/webgl-fallback/utils/WebGLUtils.js +43 -0
  164. package/src/renderers/webgpu/WebGPUBackend.js +132 -149
  165. package/src/renderers/webgpu/WebGPURenderer.Nodes.js +6 -4
  166. package/src/renderers/webgpu/WebGPURenderer.js +5 -4
  167. package/src/renderers/webgpu/nodes/WGSLNodeBuilder.js +615 -41
  168. package/src/renderers/webgpu/utils/WebGPUAttributeUtils.js +85 -6
  169. package/src/renderers/webgpu/utils/WebGPUBindingUtils.js +85 -0
  170. package/src/renderers/webgpu/utils/WebGPUPipelineUtils.js +102 -3
  171. package/src/renderers/webgpu/utils/WebGPUTexturePassUtils.js +98 -1
  172. package/src/renderers/webgpu/utils/WebGPUTextureUtils.js +257 -9
  173. package/src/renderers/webgpu/utils/WebGPUTimestampQueryPool.js +274 -0
  174. package/src/renderers/webgpu/utils/WebGPUUtils.js +86 -4
  175. package/src/renderers/webxr/WebXRManager.js +13 -2
  176. package/src/textures/VideoFrameTexture.js +35 -0
  177. package/examples/jsm/geometries/InstancedPointsGeometry.js +0 -176
  178. package/examples/jsm/objects/InstancedPoints.js +0 -19
  179. package/src/materials/nodes/InstancedPointsNodeMaterial.js +0 -209
  180. package/src/nodes/accessors/InstancedPointsMaterialNode.js +0 -37
@@ -28,7 +28,7 @@ const _matrix = new Matrix4();
28
28
 
29
29
  /**
30
30
  * CCD Algorithm
31
- * - https://sites.google.com/site/auraliusproject/ccd-algorithm
31
+ * - https://web.archive.org/web/20221206080850/https://sites.google.com/site/auraliusproject/ccd-algorithm
32
32
  *
33
33
  * // ik parameter example
34
34
  * //
@@ -277,13 +277,14 @@ function setPositionOfBoneToAttributeArray( array, index, bone, matrixWorldInv )
277
277
 
278
278
  /**
279
279
  * Visualize IK bones
280
- *
281
- * @param {SkinnedMesh} mesh
282
- * @param {Array<Object>} iks
283
- * @param {number} sphereSize
284
280
  */
285
281
  class CCDIKHelper extends Object3D {
286
282
 
283
+ /**
284
+ * @param {SkinnedMesh} mesh
285
+ * @param {Array<Object>} [iks=[]]
286
+ * @param {number} [sphereSize=0.25]
287
+ */
287
288
  constructor( mesh, iks = [], sphereSize = 0.25 ) {
288
289
 
289
290
  super();
@@ -1,4 +1,4 @@
1
- let isAvailable = ( typeof navigator !== 'undefined' && navigator.gpu !== undefined );
1
+ let isAvailable = ( typeof navigator !== 'undefined' && navigator.gpu !== undefined );
2
2
 
3
3
  if ( typeof window !== 'undefined' && isAvailable ) {
4
4
 
@@ -70,14 +70,18 @@ const _offset = new Vector3();
70
70
  const _gizmoMatrixStateTemp = new Matrix4();
71
71
  const _cameraMatrixStateTemp = new Matrix4();
72
72
  const _scalePointTemp = new Vector3();
73
- /**
74
- *
75
- * @param {Camera} camera Virtual camera used in the scene
76
- * @param {HTMLElement} domElement Renderer's dom element
77
- * @param {Scene} scene The scene to be rendered
78
- */
73
+
74
+ const _EPS = 0.000001;
75
+
76
+
79
77
  class ArcballControls extends Controls {
80
78
 
79
+ /**
80
+ *
81
+ * @param {Camera} camera Virtual camera used in the scene
82
+ * @param {HTMLElement?} [domElement=null] Renderer's dom element
83
+ * @param {Scene?} [scene=null] The scene to be rendered
84
+ */
81
85
  constructor( camera, domElement = null, scene = null ) {
82
86
 
83
87
  super( camera, domElement );
@@ -1100,9 +1104,9 @@ class ArcballControls extends Controls {
1100
1104
 
1101
1105
  /**
1102
1106
  * Set a new mouse action by specifying the operation to be performed and a mouse/key combination. In case of conflict, replaces the existing one
1103
- * @param {String} operation The operation to be performed ('PAN', 'ROTATE', 'ZOOM', 'FOV)
1104
- * @param {*} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1105
- * @param {*} key The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
1107
+ * @param {'PAN'|'ROTATE'|'ZOOM'|'FOV'} operation The operation to be performed ('PAN', 'ROTATE', 'ZOOM', 'FOV')
1108
+ * @param {0|1|2|'WHEEL'} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1109
+ * @param {'CTRL'|'SHIFT'|null} [key=null] The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
1106
1110
  * @returns {Boolean} True if the mouse action has been successfully added, false otherwise
1107
1111
  */
1108
1112
  setMouseAction( operation, mouse, key = null ) {
@@ -1181,8 +1185,8 @@ class ArcballControls extends Controls {
1181
1185
 
1182
1186
  /**
1183
1187
  * Remove a mouse action by specifying its mouse/key combination
1184
- * @param {*} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1185
- * @param {*} key The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
1188
+ * @param {0|1|2|'WHEEL'} mouse A mouse button (0, 1, 2) or 'WHEEL' for wheel notches
1189
+ * @param {'CTRL'|'SHIFT'|null} key The keyboard modifier ('CTRL', 'SHIFT') or null if key is not needed
1186
1190
  * @returns {Boolean} True if the operation has been successfully removed, false otherwise
1187
1191
  */
1188
1192
  unsetMouseAction( mouse, key = null ) {
@@ -1206,7 +1210,7 @@ class ArcballControls extends Controls {
1206
1210
  * Return the operation associated to a mouse/keyboard combination
1207
1211
  * @param {0|1|2|'WHEEL'} mouse Mouse button index (0, 1, 2) or 'WHEEL' for wheel notches
1208
1212
  * @param {'CTRL'|'SHIFT'|null} key Keyboard modifier
1209
- * @returns {string|null} The operation if it has been found, null otherwise
1213
+ * @returns {'PAN'|'ROTATE'|'ZOOM'|'FOV'|null} The operation if it has been found, null otherwise
1210
1214
  */
1211
1215
  getOpFromAction( mouse, key ) {
1212
1216
 
@@ -1246,7 +1250,7 @@ class ArcballControls extends Controls {
1246
1250
  * Get the operation associated to mouse and key combination and returns the corresponding FSA state
1247
1251
  * @param {0|1|2} mouse Mouse button index (0, 1, 2)
1248
1252
  * @param {'CTRL'|'SHIFT'|null} key Keyboard modifier
1249
- * @returns {STATE|null} The FSA state obtained from the operation associated to mouse/keyboard combination
1253
+ * @returns {STATE?} The FSA state obtained from the operation associated to mouse/keyboard combination
1250
1254
  */
1251
1255
  getOpStateFromAction( mouse, key ) {
1252
1256
 
@@ -1478,7 +1482,7 @@ class ArcballControls extends Controls {
1478
1482
  * Focus operation consist of positioning the point of interest in front of the camera and a slightly zoom in
1479
1483
  * @param {Vector3} point The point of interest
1480
1484
  * @param {Number} size Scale factor
1481
- * @param {Number} amount Amount of operation to be completed (used for focus animations, default is complete full operation)
1485
+ * @param {Number} [amount=1] Amount of operation to be completed (used for focus animations, default is complete full operation)
1482
1486
  */
1483
1487
  focus( point, size, amount = 1 ) {
1484
1488
 
@@ -1717,7 +1721,7 @@ class ArcballControls extends Controls {
1717
1721
 
1718
1722
  /**
1719
1723
  * Set gizmos radius factor and redraws gizmos
1720
- * @param {Float} value Value of radius factor
1724
+ * @param {Number} value Value of radius factor
1721
1725
  */
1722
1726
  setTbRadius( value ) {
1723
1727
 
@@ -2324,7 +2328,7 @@ class ArcballControls extends Controls {
2324
2328
  *
2325
2329
  * @param {Vector2} cursor Cursor coordinates in NDC
2326
2330
  * @param {Camera} camera Virtual camera
2327
- * @returns {Vector3|null} The point of intersection with the model, if exist, null otherwise
2331
+ * @returns {Vector3?} The point of intersection with the model, if exist, null otherwise
2328
2332
  */
2329
2333
  unprojectOnObj( cursor, camera ) {
2330
2334
 
@@ -2485,7 +2489,7 @@ class ArcballControls extends Controls {
2485
2489
  * @param {Number} cursorX Cursor horizontal coordinate on screen
2486
2490
  * @param {Number} cursorY Cursor vertical coordinate on screen
2487
2491
  * @param {HTMLElement} canvas The canvas where the renderer draws its output
2488
- * @param {Boolean} initialDistance If initial distance between camera and gizmos should be used for calculations instead of current (Perspective only)
2492
+ * @param {Boolean} [initialDistance=false] If initial distance between camera and gizmos should be used for calculations instead of current (Perspective only)
2489
2493
  * @returns {Vector3} The unprojected point on the trackball plane
2490
2494
  */
2491
2495
  unprojectOnTbPlane( camera, cursorX, cursorY, canvas, initialDistance = false ) {
@@ -2600,8 +2604,6 @@ class ArcballControls extends Controls {
2600
2604
 
2601
2605
  update() {
2602
2606
 
2603
- const EPS = 0.000001;
2604
-
2605
2607
  if ( this.target.equals( this._currentTarget ) === false ) {
2606
2608
 
2607
2609
  this._gizmos.position.copy( this.target ); //for correct radius calculation
@@ -2627,7 +2629,7 @@ class ArcballControls extends Controls {
2627
2629
  //check distance
2628
2630
  const distance = this.object.position.distanceTo( this._gizmos.position );
2629
2631
 
2630
- if ( distance > this.maxDistance + EPS || distance < this.minDistance - EPS ) {
2632
+ if ( distance > this.maxDistance + _EPS || distance < this.minDistance - _EPS ) {
2631
2633
 
2632
2634
  const newDistance = MathUtils.clamp( distance, this.minDistance, this.maxDistance );
2633
2635
  this.applyTransformMatrix( this.scale( newDistance / distance, this._gizmos.position ) );
@@ -2646,7 +2648,7 @@ class ArcballControls extends Controls {
2646
2648
  const oldRadius = this._tbRadius;
2647
2649
  this._tbRadius = this.calculateTbRadius( this.object );
2648
2650
 
2649
- if ( oldRadius < this._tbRadius - EPS || oldRadius > this._tbRadius + EPS ) {
2651
+ if ( oldRadius < this._tbRadius - _EPS || oldRadius > this._tbRadius + _EPS ) {
2650
2652
 
2651
2653
  const scale = ( this._gizmos.scale.x + this._gizmos.scale.y + this._gizmos.scale.z ) / 3;
2652
2654
  const newRadius = this._tbRadius / scale;
@@ -191,7 +191,7 @@ class GLTFExporter {
191
191
  /**
192
192
  * Parse scenes and generate GLTF output
193
193
  *
194
- * @param {Scene|THREE.Scenes} input Scene or Array of THREE.Scenes
194
+ * @param {Scene|Array<Scene>} input Scene or Array of THREE.Scenes
195
195
  * @param {Function} onDone Callback on completed
196
196
  * @param {Function} onError Callback on errors
197
197
  * @param {Object} options options
@@ -343,9 +343,10 @@ function isIdentityMatrix( matrix ) {
343
343
 
344
344
  /**
345
345
  * Get the min and max vectors from the given attribute
346
+ *
346
347
  * @param {BufferAttribute} attribute Attribute to find the min/max in range from start to start + count
347
- * @param {Integer} start
348
- * @param {Integer} count
348
+ * @param {Number} start Start index
349
+ * @param {Number} count Range to cover
349
350
  * @return {Object} Object containing the `min` and `max` values (As an array of attribute.itemSize components)
350
351
  */
351
352
  function getMinMax( attribute, start, count ) {
@@ -399,8 +400,8 @@ function getMinMax( attribute, start, count ) {
399
400
  * Get the required size + padding for a buffer, rounded to the next 4-byte boundary.
400
401
  * https://github.com/KhronosGroup/glTF/tree/master/specification/2.0#data-alignment
401
402
  *
402
- * @param {Integer} bufferSize The size the original buffer.
403
- * @returns {Integer} new buffer size with required padding.
403
+ * @param {Number} bufferSize The size the original buffer. Should be an integer.
404
+ * @returns {Number} new buffer size with required padding as an integer.
404
405
  *
405
406
  */
406
407
  function getPaddedBufferSize( bufferSize ) {
@@ -413,7 +414,7 @@ function getPaddedBufferSize( bufferSize ) {
413
414
  * Returns a buffer aligned to 4-byte boundary.
414
415
  *
415
416
  * @param {ArrayBuffer} arrayBuffer Buffer to pad
416
- * @param {Integer} paddingByte (Optional)
417
+ * @param {Number} [paddingByte=0] Should be an integer
417
418
  * @returns {ArrayBuffer} The same buffer if it's already aligned to 4-byte boundary or a new buffer
418
419
  */
419
420
  function getPaddedArrayBuffer( arrayBuffer, paddingByte = 0 ) {
@@ -545,8 +546,8 @@ class GLTFWriter {
545
546
  /**
546
547
  * Parse scenes and generate GLTF output
547
548
  *
548
- * @param {Scene|THREE.Scenes} input Scene or Array of THREE.Scenes
549
- * @param {Function} onDone Callback on completed
549
+ * @param {Scene|Array<Scene>} input Scene or Array of THREE.Scenes
550
+ * @param {Function} onDone Callback on completed
550
551
  * @param {Object} options options
551
552
  */
552
553
  async writeAsync( input, onDone, options = {} ) {
@@ -714,7 +715,7 @@ class GLTFWriter {
714
715
  *
715
716
  * @param {Object} attribute
716
717
  * @param {boolean} [isRelativeCopy=false]
717
- * @return {Integer}
718
+ * @return {Number} An integer
718
719
  */
719
720
  getUID( attribute, isRelativeCopy = false ) {
720
721
 
@@ -968,7 +969,7 @@ class GLTFWriter {
968
969
  /**
969
970
  * Process a buffer to append to the default one.
970
971
  * @param {ArrayBuffer} buffer
971
- * @return {Integer}
972
+ * @return {0}
972
973
  */
973
974
  processBuffer( buffer ) {
974
975
 
@@ -990,7 +991,7 @@ class GLTFWriter {
990
991
  * @param {number} componentType
991
992
  * @param {number} start
992
993
  * @param {number} count
993
- * @param {number} target (Optional) Target usage of the BufferView
994
+ * @param {number?} target Target usage of the BufferView
994
995
  * @return {Object}
995
996
  */
996
997
  processBufferView( attribute, componentType, start, count, target ) {
@@ -1144,7 +1145,7 @@ class GLTFWriter {
1144
1145
  /**
1145
1146
  * Process and generate a BufferView from an image Blob.
1146
1147
  * @param {Blob} blob
1147
- * @return {Promise<Integer>}
1148
+ * @return {Promise<Number>} An integer
1148
1149
  */
1149
1150
  processBufferViewImage( blob ) {
1150
1151
 
@@ -1179,10 +1180,10 @@ class GLTFWriter {
1179
1180
  /**
1180
1181
  * Process attribute to generate an accessor
1181
1182
  * @param {BufferAttribute} attribute Attribute to process
1182
- * @param {THREE.BufferGeometry} geometry (Optional) Geometry used for truncated draw range
1183
- * @param {Integer} start (Optional)
1184
- * @param {Integer} count (Optional)
1185
- * @return {Integer|null} Index of the processed accessor on the "accessors" array
1183
+ * @param {THREE.BufferGeometry?} geometry Geometry used for truncated draw range
1184
+ * @param {Number} [start=0]
1185
+ * @param {Number} [count=Infinity]
1186
+ * @return {Number?} Index of the processed accessor on the "accessors" array
1186
1187
  */
1187
1188
  processAccessor( attribute, geometry, start, count ) {
1188
1189
 
@@ -1277,10 +1278,10 @@ class GLTFWriter {
1277
1278
  /**
1278
1279
  * Process image
1279
1280
  * @param {Image} image to process
1280
- * @param {Integer} format of the image (RGBAFormat)
1281
+ * @param {Number} format Identifier of the format (RGBAFormat)
1281
1282
  * @param {Boolean} flipY before writing out the image
1282
1283
  * @param {String} mimeType export format
1283
- * @return {Integer} Index of the processed texture in the "images" array
1284
+ * @return {Number} Index of the processed texture in the "images" array
1284
1285
  */
1285
1286
  processImage( image, format, flipY, mimeType = 'image/png' ) {
1286
1287
 
@@ -1417,7 +1418,7 @@ class GLTFWriter {
1417
1418
  /**
1418
1419
  * Process sampler
1419
1420
  * @param {Texture} map Texture to process
1420
- * @return {Integer} Index of the processed texture in the "samplers" array
1421
+ * @return {Number} Index of the processed texture in the "samplers" array
1421
1422
  */
1422
1423
  processSampler( map ) {
1423
1424
 
@@ -1439,7 +1440,7 @@ class GLTFWriter {
1439
1440
  /**
1440
1441
  * Process texture
1441
1442
  * @param {Texture} map Map to process
1442
- * @return {Integer} Index of the processed texture in the "textures" array
1443
+ * @return {Promise<Number>} Index of the processed texture in the "textures" array
1443
1444
  */
1444
1445
  async processTextureAsync( map ) {
1445
1446
 
@@ -1485,7 +1486,7 @@ class GLTFWriter {
1485
1486
  /**
1486
1487
  * Process material
1487
1488
  * @param {THREE.Material} material Material to process
1488
- * @return {Integer|null} Index of the processed material in the "materials" array
1489
+ * @return {Promise<Number|null>} Index of the processed material in the "materials" array
1489
1490
  */
1490
1491
  async processMaterialAsync( material ) {
1491
1492
 
@@ -1661,7 +1662,7 @@ class GLTFWriter {
1661
1662
  /**
1662
1663
  * Process mesh
1663
1664
  * @param {THREE.Mesh} mesh Mesh to process
1664
- * @return {Integer|null} Index of the processed mesh in the "meshes" array
1665
+ * @return {Promise<Number|null>} Index of the processed mesh in the "meshes" array
1665
1666
  */
1666
1667
  async processMeshAsync( mesh ) {
1667
1668
 
@@ -2066,7 +2067,7 @@ class GLTFWriter {
2066
2067
  /**
2067
2068
  * Process camera
2068
2069
  * @param {THREE.Camera} camera Camera to process
2069
- * @return {Integer} Index of the processed mesh in the "camera" array
2070
+ * @return {Number} Index of the processed mesh in the "camera" array
2070
2071
  */
2071
2072
  processCamera( camera ) {
2072
2073
 
@@ -2267,7 +2268,7 @@ class GLTFWriter {
2267
2268
  /**
2268
2269
  * Process Object3D node
2269
2270
  * @param {THREE.Object3D} object Object3D to processNodeAsync
2270
- * @return {Integer} Index of the node in the nodes list
2271
+ * @return {Promise<Number>} Index of the node in the nodes list
2271
2272
  */
2272
2273
  async processNodeAsync( object ) {
2273
2274
 
@@ -2418,7 +2419,7 @@ class GLTFWriter {
2418
2419
 
2419
2420
  /**
2420
2421
  * Creates a Scene to hold a list of objects and parse it
2421
- * @param {Array} objects List of objects to process
2422
+ * @param {Array<THREE.Object3D>} objects List of objects to process
2422
2423
  */
2423
2424
  async processObjectsAsync( objects ) {
2424
2425
 
@@ -33,20 +33,9 @@ class TextGeometry extends ExtrudeGeometry {
33
33
 
34
34
  const shapes = font.generateShapes( text, parameters.size );
35
35
 
36
- // translate parameters to ExtrudeGeometry API
37
-
38
- if ( parameters.depth === undefined && parameters.height !== undefined ) {
39
-
40
- console.warn( 'THREE.TextGeometry: .height is now depreciated. Please use .depth instead' ); // @deprecated, r163
41
-
42
- }
43
-
44
- parameters.depth = parameters.depth !== undefined ?
45
- parameters.depth : parameters.height !== undefined ?
46
- parameters.height : 50;
47
-
48
36
  // defaults
49
37
 
38
+ if ( parameters.depth === undefined ) parameters.depth = 50;
50
39
  if ( parameters.bevelThickness === undefined ) parameters.bevelThickness = 10;
51
40
  if ( parameters.bevelSize === undefined ) parameters.bevelSize = 8;
52
41
  if ( parameters.bevelEnabled === undefined ) parameters.bevelEnabled = false;
@@ -7,97 +7,154 @@ import {
7
7
  const _pointer = new Vector2();
8
8
  const _event = { type: '', data: _pointer };
9
9
 
10
+ // TODO: Dispatch pointerevents too
11
+
12
+ /**
13
+ * The XR events that are mapped to "standard" pointer events
14
+ */
15
+ const _events = {
16
+ 'move': 'mousemove',
17
+ 'select': 'click',
18
+ 'selectstart': 'mousedown',
19
+ 'selectend': 'mouseup'
20
+ };
21
+
10
22
  const _raycaster = new Raycaster();
11
23
 
12
24
  class InteractiveGroup extends Group {
13
25
 
14
- listenToPointerEvents( renderer, camera ) {
26
+ constructor() {
27
+
28
+ super();
29
+
30
+ this.raycaster = new Raycaster();
15
31
 
16
- const scope = this;
17
- const raycaster = new Raycaster();
32
+ this.element = null;
33
+ this.camera = null;
18
34
 
19
- const element = renderer.domElement;
35
+ this.controllers = [];
20
36
 
21
- function onPointerEvent( event ) {
37
+ this._onPointerEvent = this.onPointerEvent.bind( this );
38
+ this._onXRControllerEvent = this.onXRControllerEvent.bind( this );
22
39
 
23
- event.stopPropagation();
40
+ }
41
+
42
+ onPointerEvent( event ) {
24
43
 
25
- const rect = renderer.domElement.getBoundingClientRect();
44
+ event.stopPropagation();
26
45
 
27
- _pointer.x = ( event.clientX - rect.left ) / rect.width * 2 - 1;
28
- _pointer.y = - ( event.clientY - rect.top ) / rect.height * 2 + 1;
46
+ const rect = this.element.getBoundingClientRect();
29
47
 
30
- raycaster.setFromCamera( _pointer, camera );
48
+ _pointer.x = ( event.clientX - rect.left ) / rect.width * 2 - 1;
49
+ _pointer.y = - ( event.clientY - rect.top ) / rect.height * 2 + 1;
31
50
 
32
- const intersects = raycaster.intersectObjects( scope.children, false );
51
+ this.raycaster.setFromCamera( _pointer, this.camera );
33
52
 
34
- if ( intersects.length > 0 ) {
53
+ const intersects = this.raycaster.intersectObjects( this.children, false );
35
54
 
36
- const intersection = intersects[ 0 ];
55
+ if ( intersects.length > 0 ) {
37
56
 
38
- const object = intersection.object;
39
- const uv = intersection.uv;
57
+ const intersection = intersects[ 0 ];
40
58
 
41
- _event.type = event.type;
42
- _event.data.set( uv.x, 1 - uv.y );
59
+ const object = intersection.object;
60
+ const uv = intersection.uv;
43
61
 
44
- object.dispatchEvent( _event );
62
+ _event.type = event.type;
63
+ _event.data.set( uv.x, 1 - uv.y );
45
64
 
46
- }
65
+ object.dispatchEvent( _event );
47
66
 
48
67
  }
49
68
 
50
- element.addEventListener( 'pointerdown', onPointerEvent );
51
- element.addEventListener( 'pointerup', onPointerEvent );
52
- element.addEventListener( 'pointermove', onPointerEvent );
53
- element.addEventListener( 'mousedown', onPointerEvent );
54
- element.addEventListener( 'mouseup', onPointerEvent );
55
- element.addEventListener( 'mousemove', onPointerEvent );
56
- element.addEventListener( 'click', onPointerEvent );
69
+ }
70
+
71
+ onXRControllerEvent( event ) {
72
+
73
+ const controller = event.target;
74
+
75
+ _raycaster.setFromXRController( controller );
76
+
77
+ const intersections = _raycaster.intersectObjects( this.children, false );
78
+
79
+ if ( intersections.length > 0 ) {
80
+
81
+ const intersection = intersections[ 0 ];
82
+
83
+ const object = intersection.object;
84
+ const uv = intersection.uv;
85
+
86
+ _event.type = _events[ event.type ];
87
+ _event.data.set( uv.x, 1 - uv.y );
88
+
89
+ object.dispatchEvent( _event );
90
+
91
+ }
57
92
 
58
93
  }
59
94
 
60
- listenToXRControllerEvents( controller ) {
95
+ listenToPointerEvents( renderer, camera ) {
61
96
 
62
- const scope = this;
97
+ this.camera = camera;
98
+ this.element = renderer.domElement;
63
99
 
64
- // TODO: Dispatch pointerevents too
100
+ this.element.addEventListener( 'pointerdown', this._onPointerEvent );
101
+ this.element.addEventListener( 'pointerup', this._onPointerEvent );
102
+ this.element.addEventListener( 'pointermove', this._onPointerEvent );
103
+ this.element.addEventListener( 'mousedown', this._onPointerEvent );
104
+ this.element.addEventListener( 'mouseup', this._onPointerEvent );
105
+ this.element.addEventListener( 'mousemove', this._onPointerEvent );
106
+ this.element.addEventListener( 'click', this._onPointerEvent );
65
107
 
66
- const events = {
67
- 'move': 'mousemove',
68
- 'select': 'click',
69
- 'selectstart': 'mousedown',
70
- 'selectend': 'mouseup'
71
- };
108
+ }
72
109
 
73
- function onXRControllerEvent( event ) {
110
+ disconnectionPointerEvents() {
74
111
 
75
- const controller = event.target;
112
+ if ( this.element !== null ) {
76
113
 
77
- _raycaster.setFromXRController( controller );
114
+ this.element.removeEventListener( 'pointerdown', this._onPointerEvent );
115
+ this.element.removeEventListener( 'pointerup', this._onPointerEvent );
116
+ this.element.removeEventListener( 'pointermove', this._onPointerEvent );
117
+ this.element.removeEventListener( 'mousedown', this._onPointerEvent );
118
+ this.element.removeEventListener( 'mouseup', this._onPointerEvent );
119
+ this.element.removeEventListener( 'mousemove', this._onPointerEvent );
120
+ this.element.removeEventListener( 'click', this._onPointerEvent );
78
121
 
79
- const intersections = _raycaster.intersectObjects( scope.children, false );
122
+ }
80
123
 
81
- if ( intersections.length > 0 ) {
124
+ }
82
125
 
83
- const intersection = intersections[ 0 ];
126
+ listenToXRControllerEvents( controller ) {
84
127
 
85
- const object = intersection.object;
86
- const uv = intersection.uv;
128
+ this.controllers.push( controller );
129
+ controller.addEventListener( 'move', this._onXRControllerEvent );
130
+ controller.addEventListener( 'select', this._onXRControllerEvent );
131
+ controller.addEventListener( 'selectstart', this._onXRControllerEvent );
132
+ controller.addEventListener( 'selectend', this._onXRControllerEvent );
87
133
 
88
- _event.type = events[ event.type ];
89
- _event.data.set( uv.x, 1 - uv.y );
134
+ }
135
+
136
+ disconnectXrControllerEvents() {
90
137
 
91
- object.dispatchEvent( _event );
138
+ for ( const controller of this.controllers ) {
92
139
 
93
- }
140
+ controller.removeEventListener( 'move', this._onXRControllerEvent );
141
+ controller.removeEventListener( 'select', this._onXRControllerEvent );
142
+ controller.removeEventListener( 'selectstart', this._onXRControllerEvent );
143
+ controller.removeEventListener( 'selectend', this._onXRControllerEvent );
94
144
 
95
145
  }
96
146
 
97
- controller.addEventListener( 'move', onXRControllerEvent );
98
- controller.addEventListener( 'select', onXRControllerEvent );
99
- controller.addEventListener( 'selectstart', onXRControllerEvent );
100
- controller.addEventListener( 'selectend', onXRControllerEvent );
147
+ }
148
+
149
+ disconnect() {
150
+
151
+ this.disconnectionPointerEvents();
152
+ this.disconnectXrControllerEvents();
153
+
154
+ this.camera = null;
155
+ this.element = null;
156
+
157
+ this.controllers = [];
101
158
 
102
159
  }
103
160
 
@@ -0,0 +1,109 @@
1
+ import MP4Box from 'https://cdn.jsdelivr.net/npm/mp4box@0.5.3/+esm';
2
+
3
+ // From: https://w3c.github.io/webcodecs/samples/video-decode-display/
4
+
5
+ // Wraps an MP4Box File as a WritableStream underlying sink.
6
+ class MP4FileSink {
7
+ #setStatus = null;
8
+ #file = null;
9
+ #offset = 0;
10
+
11
+ constructor(file, setStatus) {
12
+ this.#file = file;
13
+ this.#setStatus = setStatus;
14
+ }
15
+
16
+ write(chunk) {
17
+ // MP4Box.js requires buffers to be ArrayBuffers, but we have a Uint8Array.
18
+ const buffer = new ArrayBuffer(chunk.byteLength);
19
+ new Uint8Array(buffer).set(chunk);
20
+
21
+ // Inform MP4Box where in the file this chunk is from.
22
+ buffer.fileStart = this.#offset;
23
+ this.#offset += buffer.byteLength;
24
+
25
+ // Append chunk.
26
+ this.#setStatus("fetch", (this.#offset / (1024 ** 2)).toFixed(1) + " MiB");
27
+ this.#file.appendBuffer(buffer);
28
+ }
29
+
30
+ close() {
31
+ this.#setStatus("fetch", "Done");
32
+ this.#file.flush();
33
+ }
34
+ }
35
+
36
+ // Demuxes the first video track of an MP4 file using MP4Box, calling
37
+ // `onConfig()` and `onChunk()` with appropriate WebCodecs objects.
38
+ export class MP4Demuxer {
39
+ #onConfig = null;
40
+ #onChunk = null;
41
+ #setStatus = null;
42
+ #file = null;
43
+
44
+ constructor(uri, {onConfig, onChunk, setStatus}) {
45
+ this.#onConfig = onConfig;
46
+ this.#onChunk = onChunk;
47
+ this.#setStatus = setStatus;
48
+
49
+ // Configure an MP4Box File for demuxing.
50
+ this.#file = MP4Box.createFile();
51
+ this.#file.onError = error => setStatus("demux", error);
52
+ this.#file.onReady = this.#onReady.bind(this);
53
+ this.#file.onSamples = this.#onSamples.bind(this);
54
+
55
+ // Fetch the file and pipe the data through.
56
+ const fileSink = new MP4FileSink(this.#file, setStatus);
57
+ fetch(uri).then(response => {
58
+ // highWaterMark should be large enough for smooth streaming, but lower is
59
+ // better for memory usage.
60
+ response.body.pipeTo(new WritableStream(fileSink, {highWaterMark: 2}));
61
+ });
62
+ }
63
+
64
+ // Get the appropriate `description` for a specific track. Assumes that the
65
+ // track is H.264, H.265, VP8, VP9, or AV1.
66
+ #description(track) {
67
+ const trak = this.#file.getTrackById(track.id);
68
+ for (const entry of trak.mdia.minf.stbl.stsd.entries) {
69
+ const box = entry.avcC || entry.hvcC || entry.vpcC || entry.av1C;
70
+ if (box) {
71
+ const stream = new MP4Box.DataStream(undefined, 0, MP4Box.DataStream.BIG_ENDIAN);
72
+ box.write(stream);
73
+ return new Uint8Array(stream.buffer, 8); // Remove the box header.
74
+ }
75
+ }
76
+ throw new Error("avcC, hvcC, vpcC, or av1C box not found");
77
+ }
78
+
79
+ #onReady(info) {
80
+ this.#setStatus("demux", "Ready");
81
+ const track = info.videoTracks[0];
82
+
83
+ // Generate and emit an appropriate VideoDecoderConfig.
84
+ this.#onConfig({
85
+ // Browser doesn't support parsing full vp8 codec (eg: `vp08.00.41.08`),
86
+ // they only support `vp8`.
87
+ codec: track.codec.startsWith('vp08') ? 'vp8' : track.codec,
88
+ codedHeight: track.video.height,
89
+ codedWidth: track.video.width,
90
+ description: this.#description(track),
91
+ });
92
+
93
+ // Start demuxing.
94
+ this.#file.setExtractionOptions(track.id);
95
+ this.#file.start();
96
+ }
97
+
98
+ #onSamples(track_id, ref, samples) {
99
+ // Generate and emit an EncodedVideoChunk for each demuxed sample.
100
+ for (const sample of samples) {
101
+ this.#onChunk(new EncodedVideoChunk({
102
+ type: sample.is_sync ? "key" : "delta",
103
+ timestamp: 1e6 * sample.cts / sample.timescale,
104
+ duration: 1e6 * sample.duration / sample.timescale,
105
+ data: sample.data
106
+ }));
107
+ }
108
+ }
109
+ }