@damienmortini/three 0.1.168 → 0.1.171

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.
@@ -129,6 +129,12 @@ class GLTFLoader extends Loader {
129
129
 
130
130
  } );
131
131
 
132
+ this.register( function ( parser ) {
133
+
134
+ return new GLTFMaterialsIridescenceExtension( parser );
135
+
136
+ } );
137
+
132
138
  this.register( function ( parser ) {
133
139
 
134
140
  return new GLTFLightsExtension( parser );
@@ -454,6 +460,7 @@ const EXTENSIONS = {
454
460
  KHR_MATERIALS_SHEEN: 'KHR_materials_sheen',
455
461
  KHR_MATERIALS_SPECULAR: 'KHR_materials_specular',
456
462
  KHR_MATERIALS_TRANSMISSION: 'KHR_materials_transmission',
463
+ KHR_MATERIALS_IRIDESCENCE: 'KHR_materials_iridescence',
457
464
  KHR_MATERIALS_UNLIT: 'KHR_materials_unlit',
458
465
  KHR_MATERIALS_VOLUME: 'KHR_materials_volume',
459
466
  KHR_TEXTURE_BASISU: 'KHR_texture_basisu',
@@ -768,6 +775,94 @@ class GLTFMaterialsClearcoatExtension {
768
775
 
769
776
  }
770
777
 
778
+ /**
779
+ * Iridescence Materials Extension
780
+ *
781
+ * Specification: https://github.com/KhronosGroup/glTF/tree/master/extensions/2.0/Khronos/KHR_materials_iridescence
782
+ */
783
+ class GLTFMaterialsIridescenceExtension {
784
+
785
+ constructor( parser ) {
786
+
787
+ this.parser = parser;
788
+ this.name = EXTENSIONS.KHR_MATERIALS_IRIDESCENCE;
789
+
790
+ }
791
+
792
+ getMaterialType( materialIndex ) {
793
+
794
+ const parser = this.parser;
795
+ const materialDef = parser.json.materials[ materialIndex ];
796
+
797
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) return null;
798
+
799
+ return MeshPhysicalMaterial;
800
+
801
+ }
802
+
803
+ extendMaterialParams( materialIndex, materialParams ) {
804
+
805
+ const parser = this.parser;
806
+ const materialDef = parser.json.materials[ materialIndex ];
807
+
808
+ if ( ! materialDef.extensions || ! materialDef.extensions[ this.name ] ) {
809
+
810
+ return Promise.resolve();
811
+
812
+ }
813
+
814
+ const pending = [];
815
+
816
+ const extension = materialDef.extensions[ this.name ];
817
+
818
+ if ( extension.iridescenceFactor !== undefined ) {
819
+
820
+ materialParams.iridescence = extension.iridescenceFactor;
821
+
822
+ }
823
+
824
+ if ( extension.iridescenceTexture !== undefined ) {
825
+
826
+ pending.push( parser.assignTexture( materialParams, 'iridescenceMap', extension.iridescenceTexture ) );
827
+
828
+ }
829
+
830
+ if ( extension.iridescenceIor !== undefined ) {
831
+
832
+ materialParams.iridescenceIOR = extension.iridescenceIor;
833
+
834
+ }
835
+
836
+ if ( materialParams.iridescenceThicknessRange === undefined ) {
837
+
838
+ materialParams.iridescenceThicknessRange = [ 100, 400 ];
839
+
840
+ }
841
+
842
+ if ( extension.iridescenceThicknessMinimum !== undefined ) {
843
+
844
+ materialParams.iridescenceThicknessRange[ 0 ] = extension.iridescenceThicknessMinimum;
845
+
846
+ }
847
+
848
+ if ( extension.iridescenceThicknessMaximum !== undefined ) {
849
+
850
+ materialParams.iridescenceThicknessRange[ 1 ] = extension.iridescenceThicknessMaximum;
851
+
852
+ }
853
+
854
+ if ( extension.iridescenceThicknessTexture !== undefined ) {
855
+
856
+ pending.push( parser.assignTexture( materialParams, 'iridescenceThicknessMap', extension.iridescenceThicknessTexture ) );
857
+
858
+ }
859
+
860
+ return Promise.all( pending );
861
+
862
+ }
863
+
864
+ }
865
+
771
866
  /**
772
867
  * Sheen Materials Extension
773
868
  *
@@ -1860,51 +1955,47 @@ class GLTFCubicSplineInterpolant extends Interpolant {
1860
1955
 
1861
1956
  }
1862
1957
 
1863
- }
1864
-
1865
- GLTFCubicSplineInterpolant.prototype.beforeStart_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1958
+ interpolate_( i1, t0, t, t1 ) {
1866
1959
 
1867
- GLTFCubicSplineInterpolant.prototype.afterEnd_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1960
+ const result = this.resultBuffer;
1961
+ const values = this.sampleValues;
1962
+ const stride = this.valueSize;
1868
1963
 
1869
- GLTFCubicSplineInterpolant.prototype.interpolate_ = function ( i1, t0, t, t1 ) {
1964
+ const stride2 = stride * 2;
1965
+ const stride3 = stride * 3;
1870
1966
 
1871
- const result = this.resultBuffer;
1872
- const values = this.sampleValues;
1873
- const stride = this.valueSize;
1967
+ const td = t1 - t0;
1874
1968
 
1875
- const stride2 = stride * 2;
1876
- const stride3 = stride * 3;
1969
+ const p = ( t - t0 ) / td;
1970
+ const pp = p * p;
1971
+ const ppp = pp * p;
1877
1972
 
1878
- const td = t1 - t0;
1973
+ const offset1 = i1 * stride3;
1974
+ const offset0 = offset1 - stride3;
1879
1975
 
1880
- const p = ( t - t0 ) / td;
1881
- const pp = p * p;
1882
- const ppp = pp * p;
1976
+ const s2 = - 2 * ppp + 3 * pp;
1977
+ const s3 = ppp - pp;
1978
+ const s0 = 1 - s2;
1979
+ const s1 = s3 - pp + p;
1883
1980
 
1884
- const offset1 = i1 * stride3;
1885
- const offset0 = offset1 - stride3;
1981
+ // Layout of keyframe output values for CUBICSPLINE animations:
1982
+ // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
1983
+ for ( let i = 0; i !== stride; i ++ ) {
1886
1984
 
1887
- const s2 = - 2 * ppp + 3 * pp;
1888
- const s3 = ppp - pp;
1889
- const s0 = 1 - s2;
1890
- const s1 = s3 - pp + p;
1985
+ const p0 = values[ offset0 + i + stride ]; // splineVertex_k
1986
+ const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
1987
+ const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
1988
+ const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
1891
1989
 
1892
- // Layout of keyframe output values for CUBICSPLINE animations:
1893
- // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
1894
- for ( let i = 0; i !== stride; i ++ ) {
1990
+ result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1895
1991
 
1896
- const p0 = values[ offset0 + i + stride ]; // splineVertex_k
1897
- const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
1898
- const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
1899
- const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
1992
+ }
1900
1993
 
1901
- result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1994
+ return result;
1902
1995
 
1903
1996
  }
1904
1997
 
1905
- return result;
1906
-
1907
- };
1998
+ }
1908
1999
 
1909
2000
  const _q = new Quaternion();
1910
2001
 
@@ -3726,7 +3817,6 @@ class GLTFParser {
3726
3817
  if ( node === undefined ) continue;
3727
3818
 
3728
3819
  node.updateMatrix();
3729
- node.matrixAutoUpdate = true;
3730
3820
 
3731
3821
  let TypedKeyframeTrack;
3732
3822
 
@@ -3,8 +3,8 @@
3
3
  *
4
4
  * KTX 2.0 is a container format for various GPU texture formats. The loader
5
5
  * supports Basis Universal GPU textures, which can be quickly transcoded to
6
- * a wide variety of GPU texture compression formats. While KTX 2.0 also allows
7
- * other hardware-specific formats, this loader does not yet parse them.
6
+ * a wide variety of GPU texture compression formats, as well as some
7
+ * uncompressed DataTexture and Data3DTexture formats.
8
8
  *
9
9
  * References:
10
10
  * - KTX: http://github.khronos.org/KTX-Specification/
@@ -13,28 +13,52 @@
13
13
 
14
14
  import {
15
15
  CompressedTexture,
16
+ Data3DTexture,
17
+ DataTexture,
16
18
  FileLoader,
19
+ FloatType,
20
+ HalfFloatType,
17
21
  LinearEncoding,
18
22
  LinearFilter,
19
23
  LinearMipmapLinearFilter,
20
24
  Loader,
21
- RGBAFormat,
25
+ RedFormat,
26
+ RGB_ETC1_Format,
27
+ RGB_ETC2_Format,
28
+ RGB_PVRTC_4BPPV1_Format,
29
+ RGB_S3TC_DXT1_Format,
22
30
  RGBA_ASTC_4x4_Format,
23
31
  RGBA_BPTC_Format,
24
32
  RGBA_ETC2_EAC_Format,
25
33
  RGBA_PVRTC_4BPPV1_Format,
26
34
  RGBA_S3TC_DXT5_Format,
27
- RGB_ETC1_Format,
28
- RGB_ETC2_Format,
29
- RGB_PVRTC_4BPPV1_Format,
30
- RGB_S3TC_DXT1_Format,
35
+ RGBAFormat,
36
+ RGFormat,
31
37
  sRGBEncoding,
32
38
  UnsignedByteType
33
39
  } from '../../../../three/src/Three.js';
34
40
  import { WorkerPool } from '../utils/WorkerPool.js';
41
+ import * as KTX from '../libs/ktx-parse.module.js';
42
+
43
+ const {
44
+ read,
45
+ KHR_DF_FLAG_ALPHA_PREMULTIPLIED,
46
+ KHR_DF_TRANSFER_SRGB,
47
+ VK_FORMAT_UNDEFINED,
48
+ VK_FORMAT_R16_SFLOAT,
49
+ VK_FORMAT_R16G16_SFLOAT,
50
+ VK_FORMAT_R16G16B16A16_SFLOAT,
51
+ VK_FORMAT_R32_SFLOAT,
52
+ VK_FORMAT_R32G32_SFLOAT,
53
+ VK_FORMAT_R32G32B32A32_SFLOAT,
54
+ VK_FORMAT_R8_SRGB,
55
+ VK_FORMAT_R8_UNORM,
56
+ VK_FORMAT_R8G8_SRGB,
57
+ VK_FORMAT_R8G8_UNORM,
58
+ VK_FORMAT_R8G8B8A8_SRGB,
59
+ VK_FORMAT_R8G8B8A8_UNORM,
60
+ } = KTX; // eslint-disable-line no-undef
35
61
 
36
- const KTX2TransferSRGB = 2;
37
- const KTX2_ALPHA_PREMULTIPLIED = 1;
38
62
  const _taskCache = new WeakMap();
39
63
 
40
64
  let _activeLoaders = 0;
@@ -189,8 +213,6 @@ class KTX2Loader extends Loader {
189
213
  loader.setResponseType( 'arraybuffer' );
190
214
  loader.setWithCredentials( this.withCredentials );
191
215
 
192
- const texture = new CompressedTexture();
193
-
194
216
  loader.load( url, ( buffer ) => {
195
217
 
196
218
  // Check for an existing task using this buffer. A transferred buffer cannot be transferred
@@ -203,21 +225,12 @@ class KTX2Loader extends Loader {
203
225
 
204
226
  }
205
227
 
206
- this._createTexture( [ buffer ] )
207
- .then( function ( _texture ) {
208
-
209
- texture.copy( _texture );
210
- texture.needsUpdate = true;
211
-
212
- if ( onLoad ) onLoad( texture );
213
-
214
- } )
228
+ this._createTexture( buffer )
229
+ .then( ( texture ) => onLoad ? onLoad( texture ) : null )
215
230
  .catch( onError );
216
231
 
217
232
  }, onProgress, onError );
218
233
 
219
- return texture;
220
-
221
234
  }
222
235
 
223
236
  _createTextureFrom( transcodeResult ) {
@@ -231,29 +244,39 @@ class KTX2Loader extends Loader {
231
244
  texture.magFilter = LinearFilter;
232
245
  texture.generateMipmaps = false;
233
246
  texture.needsUpdate = true;
234
- texture.encoding = dfdTransferFn === KTX2TransferSRGB ? sRGBEncoding : LinearEncoding;
235
- texture.premultiplyAlpha = !! ( dfdFlags & KTX2_ALPHA_PREMULTIPLIED );
247
+ texture.encoding = dfdTransferFn === KHR_DF_TRANSFER_SRGB ? sRGBEncoding : LinearEncoding;
248
+ texture.premultiplyAlpha = !! ( dfdFlags & KHR_DF_FLAG_ALPHA_PREMULTIPLIED );
236
249
 
237
250
  return texture;
238
251
 
239
252
  }
240
253
 
241
254
  /**
242
- * @param {ArrayBuffer[]} buffers
255
+ * @param {ArrayBuffer} buffer
243
256
  * @param {object?} config
244
- * @return {Promise<CompressedTexture>}
257
+ * @return {Promise<CompressedTexture|DataTexture|Data3DTexture>}
245
258
  */
246
- _createTexture( buffers, config = {} ) {
259
+ _createTexture( buffer, config = {} ) {
260
+
261
+ const container = read( new Uint8Array( buffer ) );
262
+
263
+ if ( container.vkFormat !== VK_FORMAT_UNDEFINED ) {
264
+
265
+ return createDataTexture( container );
266
+
267
+ }
268
+
269
+ //
247
270
 
248
271
  const taskConfig = config;
249
272
  const texturePending = this.init().then( () => {
250
273
 
251
- return this.workerPool.postMessage( { type: 'transcode', buffers, taskConfig: taskConfig }, buffers );
274
+ return this.workerPool.postMessage( { type: 'transcode', buffer, taskConfig: taskConfig }, [ buffer ] );
252
275
 
253
276
  } ).then( ( e ) => this._createTextureFrom( e.data ) );
254
277
 
255
278
  // Cache the task result.
256
- _taskCache.set( buffers[ 0 ], { promise: texturePending } );
279
+ _taskCache.set( buffer, { promise: texturePending } );
257
280
 
258
281
  return texturePending;
259
282
 
@@ -342,7 +365,7 @@ KTX2Loader.BasisWorker = function () {
342
365
 
343
366
  try {
344
367
 
345
- const { width, height, hasAlpha, mipmaps, format, dfdTransferFn, dfdFlags } = transcode( message.buffers[ 0 ] );
368
+ const { width, height, hasAlpha, mipmaps, format, dfdTransferFn, dfdFlags } = transcode( message.buffer );
346
369
 
347
370
  const buffers = [];
348
371
 
@@ -588,4 +611,113 @@ KTX2Loader.BasisWorker = function () {
588
611
 
589
612
  };
590
613
 
614
+ //
615
+ // DataTexture and Data3DTexture parsing.
616
+
617
+ const FORMAT_MAP = {
618
+
619
+ [ VK_FORMAT_R32G32B32A32_SFLOAT ]: RGBAFormat,
620
+ [ VK_FORMAT_R16G16B16A16_SFLOAT ]: RGBAFormat,
621
+ [ VK_FORMAT_R8G8B8A8_UNORM ]: RGBAFormat,
622
+ [ VK_FORMAT_R8G8B8A8_SRGB ]: RGBAFormat,
623
+
624
+ [ VK_FORMAT_R32G32_SFLOAT ]: RGFormat,
625
+ [ VK_FORMAT_R16G16_SFLOAT ]: RGFormat,
626
+ [ VK_FORMAT_R8G8_UNORM ]: RGFormat,
627
+ [ VK_FORMAT_R8G8_SRGB ]: RGFormat,
628
+
629
+ [ VK_FORMAT_R32_SFLOAT ]: RedFormat,
630
+ [ VK_FORMAT_R16_SFLOAT ]: RedFormat,
631
+ [ VK_FORMAT_R8_SRGB ]: RedFormat,
632
+ [ VK_FORMAT_R8_UNORM ]: RedFormat,
633
+
634
+ };
635
+
636
+ const TYPE_MAP = {
637
+
638
+ [ VK_FORMAT_R32G32B32A32_SFLOAT ]: FloatType,
639
+ [ VK_FORMAT_R16G16B16A16_SFLOAT ]: HalfFloatType,
640
+ [ VK_FORMAT_R8G8B8A8_UNORM ]: UnsignedByteType,
641
+ [ VK_FORMAT_R8G8B8A8_SRGB ]: UnsignedByteType,
642
+
643
+ [ VK_FORMAT_R32G32_SFLOAT ]: FloatType,
644
+ [ VK_FORMAT_R16G16_SFLOAT ]: HalfFloatType,
645
+ [ VK_FORMAT_R8G8_UNORM ]: UnsignedByteType,
646
+ [ VK_FORMAT_R8G8_SRGB ]: UnsignedByteType,
647
+
648
+ [ VK_FORMAT_R32_SFLOAT ]: FloatType,
649
+ [ VK_FORMAT_R16_SFLOAT ]: HalfFloatType,
650
+ [ VK_FORMAT_R8_SRGB ]: UnsignedByteType,
651
+ [ VK_FORMAT_R8_UNORM ]: UnsignedByteType,
652
+
653
+ };
654
+
655
+ const ENCODING_MAP = {
656
+
657
+ [ VK_FORMAT_R8G8B8A8_SRGB ]: sRGBEncoding,
658
+ [ VK_FORMAT_R8G8_SRGB ]: sRGBEncoding,
659
+ [ VK_FORMAT_R8_SRGB ]: sRGBEncoding,
660
+
661
+ };
662
+
663
+ function createDataTexture( container ) {
664
+
665
+ const { vkFormat, pixelWidth, pixelHeight, pixelDepth } = container;
666
+
667
+ if ( FORMAT_MAP[ vkFormat ] === undefined ) {
668
+
669
+ throw new Error( 'THREE.KTX2Loader: Unsupported vkFormat.' );
670
+
671
+ }
672
+
673
+ //
674
+
675
+ let view;
676
+
677
+ const levelData = container.levels[ 0 ].levelData;
678
+
679
+ if ( TYPE_MAP[ vkFormat ] === FloatType ) {
680
+
681
+ view = new Float32Array(
682
+
683
+ levelData.buffer,
684
+ levelData.byteOffset,
685
+ levelData.byteLength / Float32Array.BYTES_PER_ELEMENT
686
+
687
+ );
688
+
689
+ } else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) {
690
+
691
+ view = new Uint16Array(
692
+
693
+ levelData.buffer,
694
+ levelData.byteOffset,
695
+ levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT
696
+
697
+ );
698
+
699
+ } else {
700
+
701
+ view = levelData;
702
+
703
+ }
704
+
705
+ //
706
+
707
+ const texture = pixelDepth === 0
708
+ ? new DataTexture( view, pixelWidth, pixelHeight )
709
+ : new Data3DTexture( view, pixelWidth, pixelHeight, pixelDepth );
710
+
711
+ texture.type = TYPE_MAP[ vkFormat ];
712
+ texture.format = FORMAT_MAP[ vkFormat ];
713
+ texture.encoding = ENCODING_MAP[ vkFormat ] || LinearEncoding;
714
+
715
+ texture.needsUpdate = true;
716
+
717
+ //
718
+
719
+ return Promise.resolve( texture );
720
+
721
+ }
722
+
591
723
  export { KTX2Loader };
@@ -21,6 +21,8 @@ class Lensflare extends Mesh {
21
21
 
22
22
  super( Lensflare.Geometry, new MeshBasicMaterial( { opacity: 0, transparent: true } ) );
23
23
 
24
+ this.isLensflare = true;
25
+
24
26
  this.type = 'Lensflare';
25
27
  this.frustumCulled = false;
26
28
  this.renderOrder = Infinity;
@@ -265,8 +267,6 @@ class Lensflare extends Mesh {
265
267
 
266
268
  }
267
269
 
268
- Lensflare.prototype.isLensflare = true;
269
-
270
270
  //
271
271
 
272
272
  class LensflareElement {
@@ -2,6 +2,7 @@ import {
2
2
  BufferAttribute,
3
3
  BufferGeometry,
4
4
  Float32BufferAttribute,
5
+ InstancedBufferAttribute,
5
6
  InterleavedBuffer,
6
7
  InterleavedBufferAttribute,
7
8
  MathUtils,
@@ -98,7 +99,7 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
98
99
 
99
100
  if ( geometry !== _geometry ) {
100
101
 
101
- geometry.copy( _geometry )
102
+ geometry.copy( _geometry );
102
103
 
103
104
  }
104
105
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@damienmortini/three",
3
- "version": "0.1.168",
3
+ "version": "0.1.171",
4
4
  "description": "Three.js helpers",
5
5
  "scripts": {
6
6
  "install": "npm run copyexamples",
@@ -25,9 +25,9 @@
25
25
  "bugs": "https://github.com/damienmortini/lib/issues",
26
26
  "homepage": "https://github.com/damienmortini/lib/tree/main/packages/three",
27
27
  "dependencies": {
28
- "@damienmortini/core": "^0.2.131",
29
- "fs-extra": "^10.0.1",
30
- "three": "0.140.2"
28
+ "@damienmortini/core": "^0.2.133",
29
+ "fs-extra": "^10.1.0",
30
+ "three": "0.143.0"
31
31
  },
32
- "gitHead": "9b36880886bbdadeb96b8e58597d7e7c9cfa8682"
32
+ "gitHead": "ca9574013c9ba1c2a195603346a2d90242d5b198"
33
33
  }