super-three 0.161.0 → 0.162.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 (131) hide show
  1. package/build/three.cjs +490 -393
  2. package/build/three.module.js +490 -391
  3. package/build/three.module.min.js +1 -1
  4. package/examples/jsm/controls/DragControls.js +91 -30
  5. package/examples/jsm/controls/OrbitControls.js +32 -6
  6. package/examples/jsm/controls/TransformControls.js +6 -6
  7. package/examples/jsm/exporters/GLTFExporter.js +11 -1
  8. package/examples/jsm/interactive/InteractiveGroup.js +15 -25
  9. package/examples/jsm/libs/rhino3dm/rhino3dm.js +1 -8723
  10. package/examples/jsm/libs/rhino3dm/rhino3dm.module.js +1 -8734
  11. package/examples/jsm/libs/rhino3dm/rhino3dm.wasm +0 -0
  12. package/examples/jsm/libs/tween.module.js +32 -14
  13. package/examples/jsm/loaders/3DMLoader.js +13 -21
  14. package/examples/jsm/loaders/VOXLoader.js +9 -2
  15. package/examples/jsm/loaders/VRMLLoader.js +6 -2
  16. package/examples/jsm/misc/ProgressiveLightMap.js +1 -0
  17. package/examples/jsm/nodes/Nodes.js +9 -7
  18. package/examples/jsm/nodes/accessors/AccessorsUtils.js +10 -0
  19. package/examples/jsm/nodes/accessors/ClippingNode.js +144 -0
  20. package/examples/jsm/nodes/accessors/MaterialNode.js +2 -2
  21. package/examples/jsm/nodes/accessors/MaterialReferenceNode.js +2 -12
  22. package/examples/jsm/nodes/accessors/MorphNode.js +8 -8
  23. package/examples/jsm/nodes/accessors/ReferenceNode.js +87 -29
  24. package/examples/jsm/nodes/accessors/SkinningNode.js +31 -10
  25. package/examples/jsm/nodes/accessors/StorageBufferNode.js +18 -0
  26. package/examples/jsm/nodes/accessors/TangentNode.js +8 -2
  27. package/examples/jsm/nodes/accessors/TextureNode.js +1 -1
  28. package/examples/jsm/nodes/accessors/UniformsNode.js +140 -0
  29. package/examples/jsm/nodes/code/CodeNode.js +6 -0
  30. package/examples/jsm/nodes/core/AssignNode.js +68 -12
  31. package/examples/jsm/nodes/core/Node.js +14 -4
  32. package/examples/jsm/nodes/core/NodeBuilder.js +3 -9
  33. package/examples/jsm/nodes/core/NodeFrame.js +2 -2
  34. package/examples/jsm/nodes/core/TempNode.js +1 -1
  35. package/examples/jsm/nodes/display/BlendModeNode.js +30 -1
  36. package/examples/jsm/nodes/display/NormalMapNode.js +3 -5
  37. package/examples/jsm/nodes/materials/NodeMaterial.js +37 -6
  38. package/examples/jsm/nodes/math/CondNode.js +42 -7
  39. package/examples/jsm/nodes/math/MathNode.js +20 -0
  40. package/examples/jsm/nodes/utils/ArrayElementNode.js +0 -6
  41. package/examples/jsm/nodes/utils/LoopNode.js +2 -0
  42. package/examples/jsm/nodes/utils/StorageArrayElementNode.js +91 -0
  43. package/examples/jsm/postprocessing/OutputPass.js +2 -0
  44. package/examples/jsm/renderers/common/Background.js +2 -2
  45. package/examples/jsm/renderers/common/ClippingContext.js +165 -0
  46. package/examples/jsm/renderers/common/RenderContext.js +2 -0
  47. package/examples/jsm/renderers/common/RenderContexts.js +2 -13
  48. package/examples/jsm/renderers/common/RenderObject.js +44 -1
  49. package/examples/jsm/renderers/common/RenderObjects.js +3 -1
  50. package/examples/jsm/renderers/common/Renderer.js +94 -37
  51. package/examples/jsm/renderers/common/StorageBufferAttribute.js +2 -2
  52. package/examples/jsm/renderers/common/StorageInstancedBufferAttribute.js +17 -0
  53. package/examples/jsm/renderers/common/Textures.js +3 -13
  54. package/examples/jsm/renderers/common/UniformsGroup.js +6 -4
  55. package/examples/jsm/renderers/common/nodes/NodeStorageBuffer.js +23 -0
  56. package/examples/jsm/renderers/common/nodes/NodeUniformBuffer.js +23 -0
  57. package/examples/jsm/renderers/common/nodes/Nodes.js +1 -0
  58. package/examples/jsm/renderers/webgl/WebGLBackend.js +26 -6
  59. package/examples/jsm/renderers/webgl/nodes/GLSLNodeBuilder.js +135 -10
  60. package/examples/jsm/renderers/webgl/utils/WebGLAttributeUtils.js +7 -1
  61. package/examples/jsm/renderers/webgl/utils/WebGLTextureUtils.js +47 -0
  62. package/examples/jsm/renderers/webgl/utils/WebGLUtils.js +1 -0
  63. package/examples/jsm/renderers/webgpu/WebGPUBackend.js +13 -12
  64. package/examples/jsm/renderers/webgpu/nodes/WGSLNodeBuilder.js +15 -40
  65. package/examples/jsm/renderers/webgpu/utils/WebGPUAttributeUtils.js +7 -1
  66. package/examples/jsm/renderers/webgpu/utils/WebGPUTextureUtils.js +2 -2
  67. package/examples/jsm/shaders/OutputShader.js +4 -0
  68. package/examples/jsm/utils/SkeletonUtils.js +14 -3
  69. package/examples/jsm/webxr/VRButton.js +13 -5
  70. package/examples/jsm/webxr/XRButton.js +0 -1
  71. package/examples/jsm/webxr/XRControllerModelFactory.js +8 -0
  72. package/package.json +4 -3
  73. package/src/Three.Legacy.js +20 -0
  74. package/src/Three.js +0 -1
  75. package/src/constants.js +2 -5
  76. package/src/core/BufferAttribute.js +0 -11
  77. package/src/core/BufferGeometry.js +23 -29
  78. package/src/core/Object3D.js +11 -0
  79. package/src/core/Raycaster.js +18 -4
  80. package/src/core/RenderTarget.js +44 -21
  81. package/src/extras/PMREMGenerator.js +2 -0
  82. package/src/extras/curves/EllipseCurve.js +2 -2
  83. package/src/helpers/SpotLightHelper.js +18 -1
  84. package/src/loaders/DataTextureLoader.js +0 -4
  85. package/src/loaders/MaterialLoader.js +1 -0
  86. package/src/loaders/ObjectLoader.js +2 -1
  87. package/src/materials/Material.js +2 -1
  88. package/src/materials/MeshBasicMaterial.js +3 -0
  89. package/src/materials/MeshLambertMaterial.js +3 -0
  90. package/src/materials/MeshPhongMaterial.js +3 -0
  91. package/src/materials/MeshStandardMaterial.js +3 -0
  92. package/src/math/Quaternion.js +13 -12
  93. package/src/math/Vector3.js +7 -7
  94. package/src/objects/InstancedMesh.js +53 -0
  95. package/src/objects/Mesh.js +0 -1
  96. package/src/renderers/WebGLCubeRenderTarget.js +1 -10
  97. package/src/renderers/WebGLRenderer.js +15 -22
  98. package/src/renderers/shaders/ShaderChunk/envmap_common_pars_fragment.glsl.js +1 -0
  99. package/src/renderers/shaders/ShaderChunk/envmap_fragment.glsl.js +1 -1
  100. package/src/renderers/shaders/ShaderChunk/envmap_physical_pars_fragment.glsl.js +2 -2
  101. package/src/renderers/shaders/ShaderChunk/map_fragment.glsl.js +1 -1
  102. package/src/renderers/shaders/ShaderChunk/morphinstance_vertex.glsl.js +14 -0
  103. package/src/renderers/shaders/ShaderChunk/morphtarget_pars_vertex.glsl.js +11 -2
  104. package/src/renderers/shaders/ShaderChunk/tonemapping_pars_fragment.glsl.js +23 -0
  105. package/src/renderers/shaders/ShaderChunk.js +2 -0
  106. package/src/renderers/shaders/ShaderLib/backgroundCube.glsl.js +3 -2
  107. package/src/renderers/shaders/ShaderLib/depth.glsl.js +2 -0
  108. package/src/renderers/shaders/ShaderLib/distanceRGBA.glsl.js +2 -0
  109. package/src/renderers/shaders/ShaderLib/linedashed.glsl.js +1 -0
  110. package/src/renderers/shaders/ShaderLib/meshbasic.glsl.js +1 -0
  111. package/src/renderers/shaders/ShaderLib/meshlambert.glsl.js +1 -0
  112. package/src/renderers/shaders/ShaderLib/meshmatcap.glsl.js +1 -0
  113. package/src/renderers/shaders/ShaderLib/meshnormal.glsl.js +1 -0
  114. package/src/renderers/shaders/ShaderLib/meshphong.glsl.js +1 -0
  115. package/src/renderers/shaders/ShaderLib/meshphysical.glsl.js +1 -0
  116. package/src/renderers/shaders/ShaderLib/meshtoon.glsl.js +1 -0
  117. package/src/renderers/shaders/ShaderLib/points.glsl.js +1 -0
  118. package/src/renderers/shaders/ShaderLib/shadow.glsl.js +1 -0
  119. package/src/renderers/shaders/ShaderLib.js +2 -1
  120. package/src/renderers/shaders/UniformsLib.js +1 -0
  121. package/src/renderers/webgl/WebGLBackground.js +18 -0
  122. package/src/renderers/webgl/WebGLMaterials.js +24 -1
  123. package/src/renderers/webgl/WebGLMorphtargets.js +15 -8
  124. package/src/renderers/webgl/WebGLProgram.js +12 -1
  125. package/src/renderers/webgl/WebGLPrograms.js +19 -16
  126. package/src/renderers/webgl/WebGLState.js +11 -21
  127. package/src/renderers/webgl/WebGLTextures.js +80 -50
  128. package/src/scenes/Scene.js +8 -0
  129. package/src/textures/Texture.js +1 -29
  130. package/examples/jsm/nodes/core/ArrayUniformNode.js +0 -26
  131. package/src/renderers/WebGLMultipleRenderTargets.js +0 -82
@@ -300,7 +300,7 @@ class BufferGeometry extends EventDispatcher {
300
300
 
301
301
  if ( position && position.isGLBufferAttribute ) {
302
302
 
303
- console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box. Alternatively set "mesh.frustumCulled" to "false".', this );
303
+ console.error( 'THREE.BufferGeometry.computeBoundingBox(): GLBufferAttribute requires a manual bounding box.', this );
304
304
 
305
305
  this.boundingBox.set(
306
306
  new Vector3( - Infinity, - Infinity, - Infinity ),
@@ -370,7 +370,7 @@ class BufferGeometry extends EventDispatcher {
370
370
 
371
371
  if ( position && position.isGLBufferAttribute ) {
372
372
 
373
- console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere. Alternatively set "mesh.frustumCulled" to "false".', this );
373
+ console.error( 'THREE.BufferGeometry.computeBoundingSphere(): GLBufferAttribute requires a manual bounding sphere.', this );
374
374
 
375
375
  this.boundingSphere.set( new Vector3(), Infinity );
376
376
 
@@ -487,24 +487,21 @@ class BufferGeometry extends EventDispatcher {
487
487
 
488
488
  }
489
489
 
490
- const indices = index.array;
491
- const positions = attributes.position.array;
492
- const normals = attributes.normal.array;
493
- const uvs = attributes.uv.array;
494
-
495
- const nVertices = positions.length / 3;
490
+ const positionAttribute = attributes.position;
491
+ const normalAttribute = attributes.normal;
492
+ const uvAttribute = attributes.uv;
496
493
 
497
494
  if ( this.hasAttribute( 'tangent' ) === false ) {
498
495
 
499
- this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * nVertices ), 4 ) );
496
+ this.setAttribute( 'tangent', new BufferAttribute( new Float32Array( 4 * positionAttribute.count ), 4 ) );
500
497
 
501
498
  }
502
499
 
503
- const tangents = this.getAttribute( 'tangent' ).array;
500
+ const tangentAttribute = this.getAttribute( 'tangent' );
504
501
 
505
502
  const tan1 = [], tan2 = [];
506
503
 
507
- for ( let i = 0; i < nVertices; i ++ ) {
504
+ for ( let i = 0; i < positionAttribute.count; i ++ ) {
508
505
 
509
506
  tan1[ i ] = new Vector3();
510
507
  tan2[ i ] = new Vector3();
@@ -524,13 +521,13 @@ class BufferGeometry extends EventDispatcher {
524
521
 
525
522
  function handleTriangle( a, b, c ) {
526
523
 
527
- vA.fromArray( positions, a * 3 );
528
- vB.fromArray( positions, b * 3 );
529
- vC.fromArray( positions, c * 3 );
524
+ vA.fromBufferAttribute( positionAttribute, a );
525
+ vB.fromBufferAttribute( positionAttribute, b );
526
+ vC.fromBufferAttribute( positionAttribute, c );
530
527
 
531
- uvA.fromArray( uvs, a * 2 );
532
- uvB.fromArray( uvs, b * 2 );
533
- uvC.fromArray( uvs, c * 2 );
528
+ uvA.fromBufferAttribute( uvAttribute, a );
529
+ uvB.fromBufferAttribute( uvAttribute, b );
530
+ uvC.fromBufferAttribute( uvAttribute, c );
534
531
 
535
532
  vB.sub( vA );
536
533
  vC.sub( vA );
@@ -563,7 +560,7 @@ class BufferGeometry extends EventDispatcher {
563
560
 
564
561
  groups = [ {
565
562
  start: 0,
566
- count: indices.length
563
+ count: index.count
567
564
  } ];
568
565
 
569
566
  }
@@ -578,9 +575,9 @@ class BufferGeometry extends EventDispatcher {
578
575
  for ( let j = start, jl = start + count; j < jl; j += 3 ) {
579
576
 
580
577
  handleTriangle(
581
- indices[ j + 0 ],
582
- indices[ j + 1 ],
583
- indices[ j + 2 ]
578
+ index.getX( j + 0 ),
579
+ index.getX( j + 1 ),
580
+ index.getX( j + 2 )
584
581
  );
585
582
 
586
583
  }
@@ -592,7 +589,7 @@ class BufferGeometry extends EventDispatcher {
592
589
 
593
590
  function handleVertex( v ) {
594
591
 
595
- n.fromArray( normals, v * 3 );
592
+ n.fromBufferAttribute( normalAttribute, v );
596
593
  n2.copy( n );
597
594
 
598
595
  const t = tan1[ v ];
@@ -608,10 +605,7 @@ class BufferGeometry extends EventDispatcher {
608
605
  const test = tmp2.dot( tan2[ v ] );
609
606
  const w = ( test < 0.0 ) ? - 1.0 : 1.0;
610
607
 
611
- tangents[ v * 4 ] = tmp.x;
612
- tangents[ v * 4 + 1 ] = tmp.y;
613
- tangents[ v * 4 + 2 ] = tmp.z;
614
- tangents[ v * 4 + 3 ] = w;
608
+ tangentAttribute.setXYZW( v, tmp.x, tmp.y, tmp.z, w );
615
609
 
616
610
  }
617
611
 
@@ -624,9 +618,9 @@ class BufferGeometry extends EventDispatcher {
624
618
 
625
619
  for ( let j = start, jl = start + count; j < jl; j += 3 ) {
626
620
 
627
- handleVertex( indices[ j + 0 ] );
628
- handleVertex( indices[ j + 1 ] );
629
- handleVertex( indices[ j + 2 ] );
621
+ handleVertex( index.getX( j + 0 ) );
622
+ handleVertex( index.getX( j + 1 ) );
623
+ handleVertex( index.getX( j + 2 ) );
630
624
 
631
625
  }
632
626
 
@@ -25,6 +25,9 @@ const _zAxis = /*@__PURE__*/ new Vector3( 0, 0, 1 );
25
25
  const _addedEvent = { type: 'added' };
26
26
  const _removedEvent = { type: 'removed' };
27
27
 
28
+ const _childaddedEvent = { type: 'childadded', child: null };
29
+ const _childremovedEvent = { type: 'childremoved', child: null };
30
+
28
31
  class Object3D extends EventDispatcher {
29
32
 
30
33
  constructor() {
@@ -341,6 +344,10 @@ class Object3D extends EventDispatcher {
341
344
 
342
345
  object.dispatchEvent( _addedEvent );
343
346
 
347
+ _childaddedEvent.child = object;
348
+ this.dispatchEvent( _childaddedEvent );
349
+ _childaddedEvent.child = null;
350
+
344
351
  } else {
345
352
 
346
353
  console.error( 'THREE.Object3D.add: object not an instance of THREE.Object3D.', object );
@@ -374,6 +381,10 @@ class Object3D extends EventDispatcher {
374
381
 
375
382
  object.dispatchEvent( _removedEvent );
376
383
 
384
+ _childremovedEvent.child = object;
385
+ this.dispatchEvent( _childremovedEvent );
386
+ _childremovedEvent.child = null;
387
+
377
388
  }
378
389
 
379
390
  return this;
@@ -1,6 +1,9 @@
1
+ import { Matrix4 } from '../math/Matrix4.js';
1
2
  import { Ray } from '../math/Ray.js';
2
3
  import { Layers } from './Layers.js';
3
4
 
5
+ const _matrix = /*@__PURE__*/ new Matrix4();
6
+
4
7
  class Raycaster {
5
8
 
6
9
  constructor( origin, direction, near = 0, far = Infinity ) {
@@ -53,9 +56,20 @@ class Raycaster {
53
56
 
54
57
  }
55
58
 
59
+ setFromXRController( controller ) {
60
+
61
+ _matrix.identity().extractRotation( controller.matrixWorld );
62
+
63
+ this.ray.origin.setFromMatrixPosition( controller.matrixWorld );
64
+ this.ray.direction.set( 0, 0, - 1 ).applyMatrix4( _matrix );
65
+
66
+ return this;
67
+
68
+ }
69
+
56
70
  intersectObject( object, recursive = true, intersects = [] ) {
57
71
 
58
- intersectObject( object, this, intersects, recursive );
72
+ intersect( object, this, intersects, recursive );
59
73
 
60
74
  intersects.sort( ascSort );
61
75
 
@@ -67,7 +81,7 @@ class Raycaster {
67
81
 
68
82
  for ( let i = 0, l = objects.length; i < l; i ++ ) {
69
83
 
70
- intersectObject( objects[ i ], this, intersects, recursive );
84
+ intersect( objects[ i ], this, intersects, recursive );
71
85
 
72
86
  }
73
87
 
@@ -85,7 +99,7 @@ function ascSort( a, b ) {
85
99
 
86
100
  }
87
101
 
88
- function intersectObject( object, raycaster, intersects, recursive ) {
102
+ function intersect( object, raycaster, intersects, recursive ) {
89
103
 
90
104
  if ( object.layers.test( raycaster.layers ) ) {
91
105
 
@@ -99,7 +113,7 @@ function intersectObject( object, raycaster, intersects, recursive ) {
99
113
 
100
114
  for ( let i = 0, l = children.length; i < l; i ++ ) {
101
115
 
102
- intersectObject( children[ i ], raycaster, intersects, true );
116
+ intersect( children[ i ], raycaster, intersects, true );
103
117
 
104
118
  }
105
119
 
@@ -1,9 +1,8 @@
1
1
  import { EventDispatcher } from './EventDispatcher.js';
2
2
  import { Texture } from '../textures/Texture.js';
3
- import { LinearFilter, NoColorSpace, SRGBColorSpace, sRGBEncoding } from '../constants.js';
3
+ import { LinearFilter } from '../constants.js';
4
4
  import { Vector4 } from '../math/Vector4.js';
5
5
  import { Source } from '../textures/Source.js';
6
- import { warnOnce } from '../utils.js';
7
6
 
8
7
  /*
9
8
  In options, we can specify:
@@ -29,14 +28,6 @@ class RenderTarget extends EventDispatcher {
29
28
 
30
29
  const image = { width: width, height: height, depth: 1 };
31
30
 
32
- if ( options.encoding !== undefined ) {
33
-
34
- // @deprecated, r152
35
- warnOnce( 'THREE.WebGLRenderTarget: option.encoding has been replaced by option.colorSpace.' );
36
- options.colorSpace = options.encoding === sRGBEncoding ? SRGBColorSpace : NoColorSpace;
37
-
38
- }
39
-
40
31
  options = Object.assign( {
41
32
  generateMipmaps: false,
42
33
  internalFormat: null,
@@ -44,15 +35,25 @@ class RenderTarget extends EventDispatcher {
44
35
  depthBuffer: true,
45
36
  stencilBuffer: false,
46
37
  depthTexture: null,
47
- samples: 0
38
+ samples: 0,
39
+ count: 1
48
40
  }, options );
49
41
 
50
- this.texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
51
- this.texture.isRenderTargetTexture = true;
42
+ const texture = new Texture( image, options.mapping, options.wrapS, options.wrapT, options.magFilter, options.minFilter, options.format, options.type, options.anisotropy, options.colorSpace );
43
+
44
+ texture.flipY = false;
45
+ texture.generateMipmaps = options.generateMipmaps;
46
+ texture.internalFormat = options.internalFormat;
47
+
48
+ this.textures = [];
52
49
 
53
- this.texture.flipY = false;
54
- this.texture.generateMipmaps = options.generateMipmaps;
55
- this.texture.internalFormat = options.internalFormat;
50
+ const count = options.count;
51
+ for ( let i = 0; i < count; i ++ ) {
52
+
53
+ this.textures[ i ] = texture.clone();
54
+ this.textures[ i ].isRenderTargetTexture = true;
55
+
56
+ }
56
57
 
57
58
  this.depthBuffer = options.depthBuffer;
58
59
  this.stencilBuffer = options.stencilBuffer;
@@ -63,6 +64,18 @@ class RenderTarget extends EventDispatcher {
63
64
 
64
65
  }
65
66
 
67
+ get texture() {
68
+
69
+ return this.textures[ 0 ];
70
+
71
+ }
72
+
73
+ set texture( value ) {
74
+
75
+ this.textures[ 0 ] = value;
76
+
77
+ }
78
+
66
79
  setSize( width, height, depth = 1 ) {
67
80
 
68
81
  if ( this.width !== width || this.height !== height || this.depth !== depth ) {
@@ -71,9 +84,13 @@ class RenderTarget extends EventDispatcher {
71
84
  this.height = height;
72
85
  this.depth = depth;
73
86
 
74
- this.texture.image.width = width;
75
- this.texture.image.height = height;
76
- this.texture.image.depth = depth;
87
+ for ( let i = 0, il = this.textures.length; i < il; i ++ ) {
88
+
89
+ this.textures[ i ].image.width = width;
90
+ this.textures[ i ].image.height = height;
91
+ this.textures[ i ].image.depth = depth;
92
+
93
+ }
77
94
 
78
95
  this.dispose();
79
96
 
@@ -101,8 +118,14 @@ class RenderTarget extends EventDispatcher {
101
118
 
102
119
  this.viewport.copy( source.viewport );
103
120
 
104
- this.texture = source.texture.clone();
105
- this.texture.isRenderTargetTexture = true;
121
+ this.textures.length = 0;
122
+
123
+ for ( let i = 0, il = source.textures.length; i < il; i ++ ) {
124
+
125
+ this.textures[ i ] = source.textures[ i ].clone();
126
+ this.textures[ i ].isRenderTargetTexture = true;
127
+
128
+ }
106
129
 
107
130
  // ensure image object is not shared, see #20328
108
131
 
@@ -132,6 +132,7 @@ class PMREMGenerator {
132
132
  * Generates a PMREM from an equirectangular texture, which can be either LDR
133
133
  * or HDR. The ideal input image size is 1k (1024 x 512),
134
134
  * as this matches best with the 256 x 256 cubemap output.
135
+ * The smallest supported equirectangular image size is 64 x 32.
135
136
  */
136
137
  fromEquirectangular( equirectangular, renderTarget = null ) {
137
138
 
@@ -143,6 +144,7 @@ class PMREMGenerator {
143
144
  * Generates a PMREM from an cubemap texture, which can be either LDR
144
145
  * or HDR. The ideal input cube size is 256 x 256,
145
146
  * as this matches best with the 256 x 256 cubemap output.
147
+ * The smallest supported cube size is 16 x 16.
146
148
  */
147
149
  fromCubemap( cubemap, renderTarget = null ) {
148
150
 
@@ -26,9 +26,9 @@ class EllipseCurve extends Curve {
26
26
 
27
27
  }
28
28
 
29
- getPoint( t, optionalTarget ) {
29
+ getPoint( t, optionalTarget = new Vector2() ) {
30
30
 
31
- const point = optionalTarget || new Vector2();
31
+ const point = optionalTarget;
32
32
 
33
33
  const twoPi = Math.PI * 2;
34
34
  let deltaAngle = this.aEndAngle - this.aStartAngle;
@@ -15,7 +15,6 @@ class SpotLightHelper extends Object3D {
15
15
 
16
16
  this.light = light;
17
17
 
18
- this.matrix = light.matrixWorld;
19
18
  this.matrixAutoUpdate = false;
20
19
 
21
20
  this.color = color;
@@ -67,6 +66,24 @@ class SpotLightHelper extends Object3D {
67
66
  this.light.updateWorldMatrix( true, false );
68
67
  this.light.target.updateWorldMatrix( true, false );
69
68
 
69
+ // update the local matrix based on the parent and light target transforms
70
+ if ( this.parent ) {
71
+
72
+ this.parent.updateWorldMatrix( true );
73
+
74
+ this.matrix
75
+ .copy( this.parent.matrixWorld )
76
+ .invert()
77
+ .multiply( this.light.matrixWorld );
78
+
79
+ } else {
80
+
81
+ this.matrix.copy( this.light.matrixWorld );
82
+
83
+ }
84
+
85
+ this.matrixWorld.copy( this.light.matrixWorld );
86
+
70
87
  const coneLength = this.light.distance ? this.light.distance : 1000;
71
88
  const coneWidth = coneLength * Math.tan( this.light.angle );
72
89
 
@@ -75,10 +75,6 @@ class DataTextureLoader extends Loader {
75
75
 
76
76
  texture.colorSpace = texData.colorSpace;
77
77
 
78
- } else if ( texData.encoding !== undefined ) { // @deprecated, r152
79
-
80
- texture.encoding = texData.encoding;
81
-
82
78
  }
83
79
 
84
80
  if ( texData.flipY !== undefined ) {
@@ -300,6 +300,7 @@ class MaterialLoader extends Loader {
300
300
  if ( json.specularColorMap !== undefined ) material.specularColorMap = getTexture( json.specularColorMap );
301
301
 
302
302
  if ( json.envMap !== undefined ) material.envMap = getTexture( json.envMap );
303
+ if ( json.envMapRotation !== undefined ) material.envMapRotation.fromArray( json.envMapRotation );
303
304
  if ( json.envMapIntensity !== undefined ) material.envMapIntensity = json.envMapIntensity;
304
305
 
305
306
  if ( json.reflectivity !== undefined ) material.reflectivity = json.reflectivity;
@@ -674,7 +674,6 @@ class ObjectLoader extends Loader {
674
674
  if ( data.internalFormat !== undefined ) texture.internalFormat = data.internalFormat;
675
675
  if ( data.type !== undefined ) texture.type = data.type;
676
676
  if ( data.colorSpace !== undefined ) texture.colorSpace = data.colorSpace;
677
- if ( data.encoding !== undefined ) texture.encoding = data.encoding; // @deprecated, r152
678
677
 
679
678
  if ( data.minFilter !== undefined ) texture.minFilter = parseConstant( data.minFilter, TEXTURE_FILTER );
680
679
  if ( data.magFilter !== undefined ) texture.magFilter = parseConstant( data.magFilter, TEXTURE_FILTER );
@@ -813,6 +812,8 @@ class ObjectLoader extends Loader {
813
812
 
814
813
  if ( data.backgroundBlurriness !== undefined ) object.backgroundBlurriness = data.backgroundBlurriness;
815
814
  if ( data.backgroundIntensity !== undefined ) object.backgroundIntensity = data.backgroundIntensity;
815
+ if ( data.backgroundRotation !== undefined ) object.backgroundRotation.fromArray( data.backgroundRotation );
816
+ if ( data.environmentRotation !== undefined ) object.environmentRotation.fromArray( data.environmentRotation );
816
817
 
817
818
  break;
818
819
 
@@ -190,7 +190,7 @@ class Material extends EventDispatcher {
190
190
  if ( this.sheenColor && this.sheenColor.isColor ) data.sheenColor = this.sheenColor.getHex();
191
191
  if ( this.sheenRoughness !== undefined ) data.sheenRoughness = this.sheenRoughness;
192
192
  if ( this.emissive && this.emissive.isColor ) data.emissive = this.emissive.getHex();
193
- if ( this.emissiveIntensity && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
193
+ if ( this.emissiveIntensity !== undefined && this.emissiveIntensity !== 1 ) data.emissiveIntensity = this.emissiveIntensity;
194
194
 
195
195
  if ( this.specular && this.specular.isColor ) data.specular = this.specular.getHex();
196
196
  if ( this.specularIntensity !== undefined ) data.specularIntensity = this.specularIntensity;
@@ -300,6 +300,7 @@ class Material extends EventDispatcher {
300
300
 
301
301
  }
302
302
 
303
+ if ( this.envMapRotation !== undefined ) data.envMapRotation = this.envMapRotation.toArray();
303
304
  if ( this.envMapIntensity !== undefined ) data.envMapIntensity = this.envMapIntensity;
304
305
  if ( this.reflectivity !== undefined ) data.reflectivity = this.reflectivity;
305
306
  if ( this.refractionRatio !== undefined ) data.refractionRatio = this.refractionRatio;
@@ -1,6 +1,7 @@
1
1
  import { Material } from './Material.js';
2
2
  import { MultiplyOperation } from '../constants.js';
3
3
  import { Color } from '../math/Color.js';
4
+ import { Euler } from '../math/Euler.js';
4
5
 
5
6
  class MeshBasicMaterial extends Material {
6
7
 
@@ -27,6 +28,7 @@ class MeshBasicMaterial extends Material {
27
28
  this.alphaMap = null;
28
29
 
29
30
  this.envMap = null;
31
+ this.envMapRotation = new Euler();
30
32
  this.combine = MultiplyOperation;
31
33
  this.reflectivity = 1;
32
34
  this.refractionRatio = 0.98;
@@ -61,6 +63,7 @@ class MeshBasicMaterial extends Material {
61
63
  this.alphaMap = source.alphaMap;
62
64
 
63
65
  this.envMap = source.envMap;
66
+ this.envMapRotation.copy( source.envMapRotation );
64
67
  this.combine = source.combine;
65
68
  this.reflectivity = source.reflectivity;
66
69
  this.refractionRatio = source.refractionRatio;
@@ -2,6 +2,7 @@ import { MultiplyOperation, TangentSpaceNormalMap } from '../constants.js';
2
2
  import { Material } from './Material.js';
3
3
  import { Vector2 } from '../math/Vector2.js';
4
4
  import { Color } from '../math/Color.js';
5
+ import { Euler } from '../math/Euler.js';
5
6
 
6
7
  class MeshLambertMaterial extends Material {
7
8
 
@@ -43,6 +44,7 @@ class MeshLambertMaterial extends Material {
43
44
  this.alphaMap = null;
44
45
 
45
46
  this.envMap = null;
47
+ this.envMapRotation = new Euler();
46
48
  this.combine = MultiplyOperation;
47
49
  this.reflectivity = 1;
48
50
  this.refractionRatio = 0.98;
@@ -94,6 +96,7 @@ class MeshLambertMaterial extends Material {
94
96
  this.alphaMap = source.alphaMap;
95
97
 
96
98
  this.envMap = source.envMap;
99
+ this.envMapRotation.copy( source.envMapRotation );
97
100
  this.combine = source.combine;
98
101
  this.reflectivity = source.reflectivity;
99
102
  this.refractionRatio = source.refractionRatio;
@@ -2,6 +2,7 @@ import { MultiplyOperation, TangentSpaceNormalMap } from '../constants.js';
2
2
  import { Material } from './Material.js';
3
3
  import { Vector2 } from '../math/Vector2.js';
4
4
  import { Color } from '../math/Color.js';
5
+ import { Euler } from '../math/Euler.js';
5
6
 
6
7
  class MeshPhongMaterial extends Material {
7
8
 
@@ -45,6 +46,7 @@ class MeshPhongMaterial extends Material {
45
46
  this.alphaMap = null;
46
47
 
47
48
  this.envMap = null;
49
+ this.envMapRotation = new Euler();
48
50
  this.combine = MultiplyOperation;
49
51
  this.reflectivity = 1;
50
52
  this.refractionRatio = 0.98;
@@ -98,6 +100,7 @@ class MeshPhongMaterial extends Material {
98
100
  this.alphaMap = source.alphaMap;
99
101
 
100
102
  this.envMap = source.envMap;
103
+ this.envMapRotation.copy( source.envMapRotation );
101
104
  this.combine = source.combine;
102
105
  this.reflectivity = source.reflectivity;
103
106
  this.refractionRatio = source.refractionRatio;
@@ -2,6 +2,7 @@ import { TangentSpaceNormalMap } from '../constants.js';
2
2
  import { Material } from './Material.js';
3
3
  import { Vector2 } from '../math/Vector2.js';
4
4
  import { Color } from '../math/Color.js';
5
+ import { Euler } from '../math/Euler.js';
5
6
 
6
7
  class MeshStandardMaterial extends Material {
7
8
 
@@ -49,6 +50,7 @@ class MeshStandardMaterial extends Material {
49
50
  this.alphaMap = null;
50
51
 
51
52
  this.envMap = null;
53
+ this.envMapRotation = new Euler();
52
54
  this.envMapIntensity = 1.0;
53
55
 
54
56
  this.wireframe = false;
@@ -104,6 +106,7 @@ class MeshStandardMaterial extends Material {
104
106
  this.alphaMap = source.alphaMap;
105
107
 
106
108
  this.envMap = source.envMap;
109
+ this.envMapRotation.copy( source.envMapRotation );
107
110
  this.envMapIntensity = source.envMapIntensity;
108
111
 
109
112
  this.wireframe = source.wireframe;
@@ -591,23 +591,24 @@ class Quaternion {
591
591
 
592
592
  random() {
593
593
 
594
- // Derived from http://planning.cs.uiuc.edu/node198.html
595
- // Note, this source uses w, x, y, z ordering,
596
- // so we swap the order below.
594
+ // sets this quaternion to a uniform random unit quaternnion
597
595
 
598
- const u1 = Math.random();
599
- const sqrt1u1 = Math.sqrt( 1 - u1 );
600
- const sqrtu1 = Math.sqrt( u1 );
596
+ // Ken Shoemake
597
+ // Uniform random rotations
598
+ // D. Kirk, editor, Graphics Gems III, pages 124-132. Academic Press, New York, 1992.
601
599
 
602
- const u2 = 2 * Math.PI * Math.random();
600
+ const theta1 = 2 * Math.PI * Math.random();
601
+ const theta2 = 2 * Math.PI * Math.random();
603
602
 
604
- const u3 = 2 * Math.PI * Math.random();
603
+ const x0 = Math.random();
604
+ const r1 = Math.sqrt( 1 - x0 );
605
+ const r2 = Math.sqrt( x0 );
605
606
 
606
607
  return this.set(
607
- sqrt1u1 * Math.cos( u2 ),
608
- sqrtu1 * Math.sin( u3 ),
609
- sqrtu1 * Math.cos( u3 ),
610
- sqrt1u1 * Math.sin( u2 ),
608
+ r1 * Math.sin( theta1 ),
609
+ r1 * Math.cos( theta1 ),
610
+ r2 * Math.sin( theta2 ),
611
+ r2 * Math.cos( theta2 ),
611
612
  );
612
613
 
613
614
  }
@@ -694,15 +694,15 @@ class Vector3 {
694
694
 
695
695
  randomDirection() {
696
696
 
697
- // Derived from https://mathworld.wolfram.com/SpherePointPicking.html
697
+ // https://mathworld.wolfram.com/SpherePointPicking.html
698
698
 
699
- const u = ( Math.random() - 0.5 ) * 2;
700
- const t = Math.random() * Math.PI * 2;
701
- const f = Math.sqrt( 1 - u ** 2 );
699
+ const theta = Math.random() * Math.PI * 2;
700
+ const u = Math.random() * 2 - 1;
701
+ const c = Math.sqrt( 1 - u * u );
702
702
 
703
- this.x = f * Math.cos( t );
704
- this.y = f * Math.sin( t );
705
- this.z = u;
703
+ this.x = c * Math.cos( theta );
704
+ this.y = u;
705
+ this.z = c * Math.sin( theta );
706
706
 
707
707
  return this;
708
708
 
@@ -3,6 +3,8 @@ import { Mesh } from './Mesh.js';
3
3
  import { Box3 } from '../math/Box3.js';
4
4
  import { Matrix4 } from '../math/Matrix4.js';
5
5
  import { Sphere } from '../math/Sphere.js';
6
+ import { DataTexture } from '../textures/DataTexture.js';
7
+ import { FloatType, RedFormat } from '../constants.js';
6
8
 
7
9
  const _instanceLocalMatrix = /*@__PURE__*/ new Matrix4();
8
10
  const _instanceWorldMatrix = /*@__PURE__*/ new Matrix4();
@@ -24,6 +26,7 @@ class InstancedMesh extends Mesh {
24
26
 
25
27
  this.instanceMatrix = new InstancedBufferAttribute( new Float32Array( count * 16 ), 16 );
26
28
  this.instanceColor = null;
29
+ this.morphTexture = null;
27
30
 
28
31
  this.count = count;
29
32
 
@@ -129,6 +132,24 @@ class InstancedMesh extends Mesh {
129
132
 
130
133
  }
131
134
 
135
+ getMorphAt( index, object ) {
136
+
137
+ const objectInfluences = object.morphTargetInfluences;
138
+
139
+ const array = this.morphTexture.source.data.data;
140
+
141
+ const len = objectInfluences.length + 1; // All influences + the baseInfluenceSum
142
+
143
+ const dataIndex = index * len + 1; // Skip the baseInfluenceSum at the beginning
144
+
145
+ for ( let i = 0; i < objectInfluences.length; i ++ ) {
146
+
147
+ objectInfluences[ i ] = array[ dataIndex + i ];
148
+
149
+ }
150
+
151
+ }
152
+
132
153
  raycast( raycaster, intersects ) {
133
154
 
134
155
  const matrixWorld = this.matrixWorld;
@@ -199,6 +220,38 @@ class InstancedMesh extends Mesh {
199
220
 
200
221
  }
201
222
 
223
+ setMorphAt( index, object ) {
224
+
225
+ const objectInfluences = object.morphTargetInfluences;
226
+
227
+ const len = objectInfluences.length + 1; // morphBaseInfluence + all influences
228
+
229
+ if ( this.morphTexture === null ) {
230
+
231
+ this.morphTexture = new DataTexture( new Float32Array( len * this.count ), len, this.count, RedFormat, FloatType );
232
+
233
+ }
234
+
235
+ const array = this.morphTexture.source.data.data;
236
+
237
+ let morphInfluencesSum = 0;
238
+
239
+ for ( let i = 0; i < objectInfluences.length; i ++ ) {
240
+
241
+ morphInfluencesSum += objectInfluences[ i ];
242
+
243
+ }
244
+
245
+ const morphBaseInfluence = this.geometry.morphTargetsRelative ? 1 : 1 - morphInfluencesSum;
246
+
247
+ const dataIndex = len * index;
248
+
249
+ array[ dataIndex ] = morphBaseInfluence;
250
+
251
+ array.set( objectInfluences, dataIndex + 1 );
252
+
253
+ }
254
+
202
255
  updateMorphTargets() {
203
256
 
204
257
  }