@damienmortini/three 0.1.170 → 0.1.172

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.
@@ -73,21 +73,12 @@ class DRACOLoader extends Loader {
73
73
 
74
74
  loader.load( url, ( buffer ) => {
75
75
 
76
- const taskConfig = {
77
- attributeIDs: this.defaultAttributeIDs,
78
- attributeTypes: this.defaultAttributeTypes,
79
- useUniqueIDs: false
80
- };
81
-
82
- this.decodeGeometry( buffer, taskConfig )
83
- .then( onLoad )
84
- .catch( onError );
76
+ this.decodeDracoFile( buffer, onLoad ).catch( onError );
85
77
 
86
78
  }, onProgress, onError );
87
79
 
88
80
  }
89
81
 
90
- /** @deprecated Kept for backward-compatibility with previous DRACOLoader versions. */
91
82
  decodeDracoFile( buffer, callback, attributeIDs, attributeTypes ) {
92
83
 
93
84
  const taskConfig = {
@@ -96,29 +87,12 @@ class DRACOLoader extends Loader {
96
87
  useUniqueIDs: !! attributeIDs
97
88
  };
98
89
 
99
- this.decodeGeometry( buffer, taskConfig ).then( callback );
90
+ return this.decodeGeometry( buffer, taskConfig ).then( callback );
100
91
 
101
92
  }
102
93
 
103
94
  decodeGeometry( buffer, taskConfig ) {
104
95
 
105
- // TODO: For backward-compatibility, support 'attributeTypes' objects containing
106
- // references (rather than names) to typed array constructors. These must be
107
- // serialized before sending them to the worker.
108
- for ( const attribute in taskConfig.attributeTypes ) {
109
-
110
- const type = taskConfig.attributeTypes[ attribute ];
111
-
112
- if ( type.BYTES_PER_ELEMENT !== undefined ) {
113
-
114
- taskConfig.attributeTypes[ attribute ] = type.name;
115
-
116
- }
117
-
118
- }
119
-
120
- //
121
-
122
96
  const taskKey = JSON.stringify( taskConfig );
123
97
 
124
98
  // Check for an existing task using this buffer. A transferred buffer cannot be transferred
@@ -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
  *
@@ -949,7 +1044,7 @@ class GLTFMaterialsVolumeExtension {
949
1044
 
950
1045
  }
951
1046
 
952
- materialParams.attenuationDistance = extension.attenuationDistance || 0;
1047
+ materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
953
1048
 
954
1049
  const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
955
1050
  materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
@@ -1246,7 +1341,7 @@ class GLTFMeshoptCompression {
1246
1341
 
1247
1342
  }
1248
1343
 
1249
- return Promise.all( [ buffer, decoder.ready ] ).then( function ( res ) {
1344
+ return buffer.then( function ( res ) {
1250
1345
 
1251
1346
  const byteOffset = extensionDef.byteOffset || 0;
1252
1347
  const byteLength = extensionDef.byteLength || 0;
@@ -1254,11 +1349,28 @@ class GLTFMeshoptCompression {
1254
1349
  const count = extensionDef.count;
1255
1350
  const stride = extensionDef.byteStride;
1256
1351
 
1257
- const result = new ArrayBuffer( count * stride );
1258
- const source = new Uint8Array( res[ 0 ], byteOffset, byteLength );
1352
+ const source = new Uint8Array( res, byteOffset, byteLength );
1353
+
1354
+ if ( decoder.decodeGltfBufferAsync ) {
1355
+
1356
+ return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
1357
+
1358
+ return res.buffer;
1259
1359
 
1260
- decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
1261
- return result;
1360
+ } );
1361
+
1362
+ } else {
1363
+
1364
+ // Support for MeshoptDecoder 0.18 or earlier, without decodeGltfBufferAsync
1365
+ return decoder.ready.then( function () {
1366
+
1367
+ const result = new ArrayBuffer( count * stride );
1368
+ decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
1369
+ return result;
1370
+
1371
+ } );
1372
+
1373
+ }
1262
1374
 
1263
1375
  } );
1264
1376
 
@@ -1392,7 +1504,7 @@ class GLTFDracoMeshCompressionExtension {
1392
1504
  const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
1393
1505
  const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
1394
1506
 
1395
- attributeTypeMap[ threeAttributeName ] = componentType;
1507
+ attributeTypeMap[ threeAttributeName ] = componentType.name;
1396
1508
  attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
1397
1509
 
1398
1510
  }
@@ -1860,51 +1972,47 @@ class GLTFCubicSplineInterpolant extends Interpolant {
1860
1972
 
1861
1973
  }
1862
1974
 
1863
- }
1864
-
1865
- GLTFCubicSplineInterpolant.prototype.beforeStart_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1975
+ interpolate_( i1, t0, t, t1 ) {
1866
1976
 
1867
- GLTFCubicSplineInterpolant.prototype.afterEnd_ = GLTFCubicSplineInterpolant.prototype.copySampleValue_;
1977
+ const result = this.resultBuffer;
1978
+ const values = this.sampleValues;
1979
+ const stride = this.valueSize;
1868
1980
 
1869
- GLTFCubicSplineInterpolant.prototype.interpolate_ = function ( i1, t0, t, t1 ) {
1981
+ const stride2 = stride * 2;
1982
+ const stride3 = stride * 3;
1870
1983
 
1871
- const result = this.resultBuffer;
1872
- const values = this.sampleValues;
1873
- const stride = this.valueSize;
1984
+ const td = t1 - t0;
1874
1985
 
1875
- const stride2 = stride * 2;
1876
- const stride3 = stride * 3;
1986
+ const p = ( t - t0 ) / td;
1987
+ const pp = p * p;
1988
+ const ppp = pp * p;
1877
1989
 
1878
- const td = t1 - t0;
1990
+ const offset1 = i1 * stride3;
1991
+ const offset0 = offset1 - stride3;
1879
1992
 
1880
- const p = ( t - t0 ) / td;
1881
- const pp = p * p;
1882
- const ppp = pp * p;
1993
+ const s2 = - 2 * ppp + 3 * pp;
1994
+ const s3 = ppp - pp;
1995
+ const s0 = 1 - s2;
1996
+ const s1 = s3 - pp + p;
1883
1997
 
1884
- const offset1 = i1 * stride3;
1885
- const offset0 = offset1 - stride3;
1998
+ // Layout of keyframe output values for CUBICSPLINE animations:
1999
+ // [ inTangent_1, splineVertex_1, outTangent_1, inTangent_2, splineVertex_2, ... ]
2000
+ for ( let i = 0; i !== stride; i ++ ) {
1886
2001
 
1887
- const s2 = - 2 * ppp + 3 * pp;
1888
- const s3 = ppp - pp;
1889
- const s0 = 1 - s2;
1890
- const s1 = s3 - pp + p;
2002
+ const p0 = values[ offset0 + i + stride ]; // splineVertex_k
2003
+ const m0 = values[ offset0 + i + stride2 ] * td; // outTangent_k * (t_k+1 - t_k)
2004
+ const p1 = values[ offset1 + i + stride ]; // splineVertex_k+1
2005
+ const m1 = values[ offset1 + i ] * td; // inTangent_k+1 * (t_k+1 - t_k)
1891
2006
 
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 ++ ) {
2007
+ result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
1895
2008
 
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)
2009
+ }
1900
2010
 
1901
- result[ i ] = s0 * p0 + s1 * m0 + s2 * p1 + s3 * m1;
2011
+ return result;
1902
2012
 
1903
2013
  }
1904
2014
 
1905
- return result;
1906
-
1907
- };
2015
+ }
1908
2016
 
1909
2017
  const _q = new Quaternion();
1910
2018
 
@@ -3685,7 +3793,7 @@ class GLTFParser {
3685
3793
  const channel = animationDef.channels[ i ];
3686
3794
  const sampler = animationDef.samplers[ channel.sampler ];
3687
3795
  const target = channel.target;
3688
- const name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
3796
+ const name = target.node;
3689
3797
  const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
3690
3798
  const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
3691
3799
 
@@ -3726,7 +3834,6 @@ class GLTFParser {
3726
3834
  if ( node === undefined ) continue;
3727
3835
 
3728
3836
  node.updateMatrix();
3729
- node.matrixAutoUpdate = true;
3730
3837
 
3731
3838
  let TypedKeyframeTrack;
3732
3839
 
@@ -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,32 +13,59 @@
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 {
42
+ read,
43
+ KHR_DF_FLAG_ALPHA_PREMULTIPLIED,
44
+ KHR_DF_TRANSFER_SRGB,
45
+ KHR_SUPERCOMPRESSION_NONE,
46
+ KHR_SUPERCOMPRESSION_ZSTD,
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
+ } from '../libs/ktx-parse.module.js';
61
+ import { ZSTDDecoder } from '../libs/zstddec.module.js';
35
62
 
36
- const KTX2TransferSRGB = 2;
37
- const KTX2_ALPHA_PREMULTIPLIED = 1;
38
63
  const _taskCache = new WeakMap();
39
64
 
40
65
  let _activeLoaders = 0;
41
66
 
67
+ let _zstd;
68
+
42
69
  class KTX2Loader extends Loader {
43
70
 
44
71
  constructor( manager ) {
@@ -189,8 +216,6 @@ class KTX2Loader extends Loader {
189
216
  loader.setResponseType( 'arraybuffer' );
190
217
  loader.setWithCredentials( this.withCredentials );
191
218
 
192
- const texture = new CompressedTexture();
193
-
194
219
  loader.load( url, ( buffer ) => {
195
220
 
196
221
  // Check for an existing task using this buffer. A transferred buffer cannot be transferred
@@ -203,21 +228,12 @@ class KTX2Loader extends Loader {
203
228
 
204
229
  }
205
230
 
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
- } )
231
+ this._createTexture( buffer )
232
+ .then( ( texture ) => onLoad ? onLoad( texture ) : null )
215
233
  .catch( onError );
216
234
 
217
235
  }, onProgress, onError );
218
236
 
219
- return texture;
220
-
221
237
  }
222
238
 
223
239
  _createTextureFrom( transcodeResult ) {
@@ -231,29 +247,39 @@ class KTX2Loader extends Loader {
231
247
  texture.magFilter = LinearFilter;
232
248
  texture.generateMipmaps = false;
233
249
  texture.needsUpdate = true;
234
- texture.encoding = dfdTransferFn === KTX2TransferSRGB ? sRGBEncoding : LinearEncoding;
235
- texture.premultiplyAlpha = !! ( dfdFlags & KTX2_ALPHA_PREMULTIPLIED );
250
+ texture.encoding = dfdTransferFn === KHR_DF_TRANSFER_SRGB ? sRGBEncoding : LinearEncoding;
251
+ texture.premultiplyAlpha = !! ( dfdFlags & KHR_DF_FLAG_ALPHA_PREMULTIPLIED );
236
252
 
237
253
  return texture;
238
254
 
239
255
  }
240
256
 
241
257
  /**
242
- * @param {ArrayBuffer[]} buffers
258
+ * @param {ArrayBuffer} buffer
243
259
  * @param {object?} config
244
- * @return {Promise<CompressedTexture>}
260
+ * @return {Promise<CompressedTexture|DataTexture|Data3DTexture>}
245
261
  */
246
- _createTexture( buffers, config = {} ) {
262
+ _createTexture( buffer, config = {} ) {
263
+
264
+ const container = read( new Uint8Array( buffer ) );
265
+
266
+ if ( container.vkFormat !== VK_FORMAT_UNDEFINED ) {
267
+
268
+ return createDataTexture( container );
269
+
270
+ }
271
+
272
+ //
247
273
 
248
274
  const taskConfig = config;
249
275
  const texturePending = this.init().then( () => {
250
276
 
251
- return this.workerPool.postMessage( { type: 'transcode', buffers, taskConfig: taskConfig }, buffers );
277
+ return this.workerPool.postMessage( { type: 'transcode', buffer, taskConfig: taskConfig }, [ buffer ] );
252
278
 
253
279
  } ).then( ( e ) => this._createTextureFrom( e.data ) );
254
280
 
255
281
  // Cache the task result.
256
- _taskCache.set( buffers[ 0 ], { promise: texturePending } );
282
+ _taskCache.set( buffer, { promise: texturePending } );
257
283
 
258
284
  return texturePending;
259
285
 
@@ -342,7 +368,7 @@ KTX2Loader.BasisWorker = function () {
342
368
 
343
369
  try {
344
370
 
345
- const { width, height, hasAlpha, mipmaps, format, dfdTransferFn, dfdFlags } = transcode( message.buffers[ 0 ] );
371
+ const { width, height, hasAlpha, mipmaps, format, dfdTransferFn, dfdFlags } = transcode( message.buffer );
346
372
 
347
373
  const buffers = [];
348
374
 
@@ -588,4 +614,140 @@ KTX2Loader.BasisWorker = function () {
588
614
 
589
615
  };
590
616
 
617
+ //
618
+ // DataTexture and Data3DTexture parsing.
619
+
620
+ const FORMAT_MAP = {
621
+
622
+ [ VK_FORMAT_R32G32B32A32_SFLOAT ]: RGBAFormat,
623
+ [ VK_FORMAT_R16G16B16A16_SFLOAT ]: RGBAFormat,
624
+ [ VK_FORMAT_R8G8B8A8_UNORM ]: RGBAFormat,
625
+ [ VK_FORMAT_R8G8B8A8_SRGB ]: RGBAFormat,
626
+
627
+ [ VK_FORMAT_R32G32_SFLOAT ]: RGFormat,
628
+ [ VK_FORMAT_R16G16_SFLOAT ]: RGFormat,
629
+ [ VK_FORMAT_R8G8_UNORM ]: RGFormat,
630
+ [ VK_FORMAT_R8G8_SRGB ]: RGFormat,
631
+
632
+ [ VK_FORMAT_R32_SFLOAT ]: RedFormat,
633
+ [ VK_FORMAT_R16_SFLOAT ]: RedFormat,
634
+ [ VK_FORMAT_R8_SRGB ]: RedFormat,
635
+ [ VK_FORMAT_R8_UNORM ]: RedFormat,
636
+
637
+ };
638
+
639
+ const TYPE_MAP = {
640
+
641
+ [ VK_FORMAT_R32G32B32A32_SFLOAT ]: FloatType,
642
+ [ VK_FORMAT_R16G16B16A16_SFLOAT ]: HalfFloatType,
643
+ [ VK_FORMAT_R8G8B8A8_UNORM ]: UnsignedByteType,
644
+ [ VK_FORMAT_R8G8B8A8_SRGB ]: UnsignedByteType,
645
+
646
+ [ VK_FORMAT_R32G32_SFLOAT ]: FloatType,
647
+ [ VK_FORMAT_R16G16_SFLOAT ]: HalfFloatType,
648
+ [ VK_FORMAT_R8G8_UNORM ]: UnsignedByteType,
649
+ [ VK_FORMAT_R8G8_SRGB ]: UnsignedByteType,
650
+
651
+ [ VK_FORMAT_R32_SFLOAT ]: FloatType,
652
+ [ VK_FORMAT_R16_SFLOAT ]: HalfFloatType,
653
+ [ VK_FORMAT_R8_SRGB ]: UnsignedByteType,
654
+ [ VK_FORMAT_R8_UNORM ]: UnsignedByteType,
655
+
656
+ };
657
+
658
+ const ENCODING_MAP = {
659
+
660
+ [ VK_FORMAT_R8G8B8A8_SRGB ]: sRGBEncoding,
661
+ [ VK_FORMAT_R8G8_SRGB ]: sRGBEncoding,
662
+ [ VK_FORMAT_R8_SRGB ]: sRGBEncoding,
663
+
664
+ };
665
+
666
+ async function createDataTexture( container ) {
667
+
668
+ const { vkFormat, pixelWidth, pixelHeight, pixelDepth } = container;
669
+
670
+ if ( FORMAT_MAP[ vkFormat ] === undefined ) {
671
+
672
+ throw new Error( 'THREE.KTX2Loader: Unsupported vkFormat.' );
673
+
674
+ }
675
+
676
+ //
677
+
678
+ const level = container.levels[ 0 ];
679
+
680
+ let levelData;
681
+ let view;
682
+
683
+ if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_NONE ) {
684
+
685
+ levelData = level.levelData;
686
+
687
+ } else if ( container.supercompressionScheme === KHR_SUPERCOMPRESSION_ZSTD ) {
688
+
689
+ if ( ! _zstd ) {
690
+
691
+ _zstd = new Promise( async ( resolve ) => {
692
+
693
+ const zstd = new ZSTDDecoder();
694
+ await zstd.init();
695
+ resolve( zstd );
696
+
697
+ } );
698
+
699
+ }
700
+
701
+ levelData = ( await _zstd ).decode( level.levelData, level.uncompressedByteLength );
702
+
703
+ } else {
704
+
705
+ throw new Error( 'THREE.KTX2Loader: Unsupported supercompressionScheme.' );
706
+
707
+ }
708
+
709
+ if ( TYPE_MAP[ vkFormat ] === FloatType ) {
710
+
711
+ view = new Float32Array(
712
+
713
+ levelData.buffer,
714
+ levelData.byteOffset,
715
+ levelData.byteLength / Float32Array.BYTES_PER_ELEMENT
716
+
717
+ );
718
+
719
+ } else if ( TYPE_MAP[ vkFormat ] === HalfFloatType ) {
720
+
721
+ view = new Uint16Array(
722
+
723
+ levelData.buffer,
724
+ levelData.byteOffset,
725
+ levelData.byteLength / Uint16Array.BYTES_PER_ELEMENT
726
+
727
+ );
728
+
729
+ } else {
730
+
731
+ view = levelData;
732
+
733
+ }
734
+
735
+ //
736
+
737
+ const texture = pixelDepth === 0
738
+ ? new DataTexture( view, pixelWidth, pixelHeight )
739
+ : new Data3DTexture( view, pixelWidth, pixelHeight, pixelDepth );
740
+
741
+ texture.type = TYPE_MAP[ vkFormat ];
742
+ texture.format = FORMAT_MAP[ vkFormat ];
743
+ texture.encoding = ENCODING_MAP[ vkFormat ] || LinearEncoding;
744
+
745
+ texture.needsUpdate = true;
746
+
747
+ //
748
+
749
+ return Promise.resolve( texture );
750
+
751
+ }
752
+
591
753
  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,9 +2,9 @@ import {
2
2
  BufferAttribute,
3
3
  BufferGeometry,
4
4
  Float32BufferAttribute,
5
+ InstancedBufferAttribute,
5
6
  InterleavedBuffer,
6
7
  InterleavedBufferAttribute,
7
- MathUtils,
8
8
  TriangleFanDrawMode,
9
9
  TriangleStripDrawMode,
10
10
  TrianglesDrawMode,
@@ -35,17 +35,16 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
35
35
 
36
36
  if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) {
37
37
 
38
- const srcArray = attribute.isInterleavedBufferAttribute ? attribute.data.array : attribute.array;
39
38
  const dstArray = new Float32Array( attribute.getCount() * attribute.itemSize );
40
39
 
41
40
  for ( let i = 0, j = 0; i < attribute.getCount(); i ++ ) {
42
41
 
43
- dstArray[ j ++ ] = MathUtils.denormalize( attribute.getX( i ), srcArray );
44
- dstArray[ j ++ ] = MathUtils.denormalize( attribute.getY( i ), srcArray );
42
+ dstArray[ j ++ ] = attribute.getX( i );
43
+ dstArray[ j ++ ] = attribute.getY( i );
45
44
 
46
45
  if ( attribute.itemSize > 2 ) {
47
46
 
48
- dstArray[ j ++ ] = MathUtils.denormalize( attribute.getZ( i ), srcArray );
47
+ dstArray[ j ++ ] = attribute.getZ( i );
49
48
 
50
49
  }
51
50
 
@@ -98,7 +97,7 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
98
97
 
99
98
  if ( geometry !== _geometry ) {
100
99
 
101
- geometry.copy( _geometry )
100
+ geometry.copy( _geometry );
102
101
 
103
102
  }
104
103
 
@@ -384,7 +383,7 @@ function interleaveAttributes( attributes ) {
384
383
  let arrayLength = 0;
385
384
  let stride = 0;
386
385
 
387
- // calculate the the length and type of the interleavedBuffer
386
+ // calculate the length and type of the interleavedBuffer
388
387
  for ( let i = 0, l = attributes.length; i < l; ++ i ) {
389
388
 
390
389
  const attribute = attributes[ i ];
@@ -554,7 +553,7 @@ function estimateBytesUsed( geometry ) {
554
553
  /**
555
554
  * @param {BufferGeometry} geometry
556
555
  * @param {number} tolerance
557
- * @return {BufferGeometry>}
556
+ * @return {BufferGeometry}
558
557
  */
559
558
  function mergeVertices( geometry, tolerance = 1e-4 ) {
560
559
 
@@ -572,22 +571,33 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
572
571
 
573
572
  // attributes and new attribute arrays
574
573
  const attributeNames = Object.keys( geometry.attributes );
575
- const attrArrays = {};
576
- const morphAttrsArrays = {};
574
+ const tmpAttributes = {};
575
+ const tmpMorphAttributes = {};
577
576
  const newIndices = [];
578
577
  const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
578
+ const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
579
579
 
580
- // initialize the arrays
580
+ // Initialize the arrays, allocating space conservatively. Extra
581
+ // space will be trimmed in the last step.
581
582
  for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
582
583
 
583
584
  const name = attributeNames[ i ];
585
+ const attr = geometry.attributes[ name ];
584
586
 
585
- attrArrays[ name ] = [];
587
+ tmpAttributes[ name ] = new BufferAttribute(
588
+ new attr.array.constructor( attr.count * attr.itemSize ),
589
+ attr.itemSize,
590
+ attr.normalized
591
+ );
586
592
 
587
593
  const morphAttr = geometry.morphAttributes[ name ];
588
594
  if ( morphAttr ) {
589
595
 
590
- morphAttrsArrays[ name ] = new Array( morphAttr.length ).fill().map( () => [] );
596
+ tmpMorphAttributes[ name ] = new BufferAttribute(
597
+ new morphAttr.array.constructor( morphAttr.count * morphAttr.itemSize ),
598
+ morphAttr.itemSize,
599
+ morphAttr.normalized
600
+ );
591
601
 
592
602
  }
593
603
 
@@ -625,26 +635,27 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
625
635
 
626
636
  } else {
627
637
 
628
- // copy data to the new index in the attribute arrays
638
+ // copy data to the new index in the temporary attributes
629
639
  for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
630
640
 
631
641
  const name = attributeNames[ j ];
632
642
  const attribute = geometry.getAttribute( name );
633
643
  const morphAttr = geometry.morphAttributes[ name ];
634
644
  const itemSize = attribute.itemSize;
635
- const newarray = attrArrays[ name ];
636
- const newMorphArrays = morphAttrsArrays[ name ];
645
+ const newarray = tmpAttributes[ name ];
646
+ const newMorphArrays = tmpMorphAttributes[ name ];
637
647
 
638
648
  for ( let k = 0; k < itemSize; k ++ ) {
639
649
 
640
650
  const getterFunc = getters[ k ];
641
- newarray.push( attribute[ getterFunc ]( index ) );
651
+ const setterFunc = setters[ k ];
652
+ newarray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );
642
653
 
643
654
  if ( morphAttr ) {
644
655
 
645
656
  for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {
646
657
 
647
- newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
658
+ newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttr[ m ][ getterFunc ]( index ) );
648
659
 
649
660
  }
650
661
 
@@ -662,31 +673,29 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
662
673
 
663
674
  }
664
675
 
665
- // Generate typed arrays from new attribute arrays and update
666
- // the attributeBuffers
676
+ // generate result BufferGeometry
667
677
  const result = geometry.clone();
668
- for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
669
-
670
- const name = attributeNames[ i ];
671
- const oldAttribute = geometry.getAttribute( name );
672
-
673
- const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
674
- const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
678
+ for ( const name in geometry.attributes ) {
675
679
 
676
- result.setAttribute( name, attribute );
680
+ const tmpAttribute = tmpAttributes[ name ];
677
681
 
678
- // Update the attribute arrays
679
- if ( name in morphAttrsArrays ) {
682
+ result.setAttribute( name, new BufferAttribute(
683
+ tmpAttribute.array.slice( 0, nextIndex * tmpAttribute.itemSize ),
684
+ tmpAttribute.itemSize,
685
+ tmpAttribute.normalized,
686
+ ) );
680
687
 
681
- for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
688
+ if ( ! ( name in tmpMorphAttributes ) ) continue;
682
689
 
683
- const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
690
+ for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) {
684
691
 
685
- const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
686
- const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
687
- result.morphAttributes[ name ][ j ] = morphAttribute;
692
+ const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];
688
693
 
689
- }
694
+ result.morphAttributes[ name ][ j ] = new BufferAttribute(
695
+ tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
696
+ tmpMorphAttribute.itemSize,
697
+ tmpMorphAttribute.normalized,
698
+ );
690
699
 
691
700
  }
692
701
 
@@ -703,7 +712,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
703
712
  /**
704
713
  * @param {BufferGeometry} geometry
705
714
  * @param {number} drawMode
706
- * @return {BufferGeometry>}
715
+ * @return {BufferGeometry}
707
716
  */
708
717
  function toTrianglesDrawMode( geometry, drawMode ) {
709
718
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@damienmortini/three",
3
- "version": "0.1.170",
3
+ "version": "0.1.172",
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.133",
29
- "fs-extra": "^10.0.1",
30
- "three": "0.140.2"
28
+ "@damienmortini/core": "^0.2.134",
29
+ "fs-extra": "^10.1.0",
30
+ "three": "0.145.0"
31
31
  },
32
- "gitHead": "d01a174f8b8a88763a27c2964f6f918a9c2b4075"
32
+ "gitHead": "9df921714722d7ffbe00c7ae4f0cdf77f0cbc6a4"
33
33
  }