@damienmortini/three 0.1.171 → 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
@@ -1044,7 +1044,7 @@ class GLTFMaterialsVolumeExtension {
1044
1044
 
1045
1045
  }
1046
1046
 
1047
- materialParams.attenuationDistance = extension.attenuationDistance || 0;
1047
+ materialParams.attenuationDistance = extension.attenuationDistance || Infinity;
1048
1048
 
1049
1049
  const colorArray = extension.attenuationColor || [ 1, 1, 1 ];
1050
1050
  materialParams.attenuationColor = new Color( colorArray[ 0 ], colorArray[ 1 ], colorArray[ 2 ] );
@@ -1341,7 +1341,7 @@ class GLTFMeshoptCompression {
1341
1341
 
1342
1342
  }
1343
1343
 
1344
- return Promise.all( [ buffer, decoder.ready ] ).then( function ( res ) {
1344
+ return buffer.then( function ( res ) {
1345
1345
 
1346
1346
  const byteOffset = extensionDef.byteOffset || 0;
1347
1347
  const byteLength = extensionDef.byteLength || 0;
@@ -1349,11 +1349,28 @@ class GLTFMeshoptCompression {
1349
1349
  const count = extensionDef.count;
1350
1350
  const stride = extensionDef.byteStride;
1351
1351
 
1352
- const result = new ArrayBuffer( count * stride );
1353
- const source = new Uint8Array( res[ 0 ], byteOffset, byteLength );
1352
+ const source = new Uint8Array( res, byteOffset, byteLength );
1354
1353
 
1355
- decoder.decodeGltfBuffer( new Uint8Array( result ), count, stride, source, extensionDef.mode, extensionDef.filter );
1356
- return result;
1354
+ if ( decoder.decodeGltfBufferAsync ) {
1355
+
1356
+ return decoder.decodeGltfBufferAsync( count, stride, source, extensionDef.mode, extensionDef.filter ).then( function ( res ) {
1357
+
1358
+ return res.buffer;
1359
+
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
+ }
1357
1374
 
1358
1375
  } );
1359
1376
 
@@ -1487,7 +1504,7 @@ class GLTFDracoMeshCompressionExtension {
1487
1504
  const accessorDef = json.accessors[ primitive.attributes[ attributeName ] ];
1488
1505
  const componentType = WEBGL_COMPONENT_TYPES[ accessorDef.componentType ];
1489
1506
 
1490
- attributeTypeMap[ threeAttributeName ] = componentType;
1507
+ attributeTypeMap[ threeAttributeName ] = componentType.name;
1491
1508
  attributeNormalizedMap[ threeAttributeName ] = accessorDef.normalized === true;
1492
1509
 
1493
1510
  }
@@ -3776,7 +3793,7 @@ class GLTFParser {
3776
3793
  const channel = animationDef.channels[ i ];
3777
3794
  const sampler = animationDef.samplers[ channel.sampler ];
3778
3795
  const target = channel.target;
3779
- const name = target.node !== undefined ? target.node : target.id; // NOTE: target.id is deprecated.
3796
+ const name = target.node;
3780
3797
  const input = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.input ] : sampler.input;
3781
3798
  const output = animationDef.parameters !== undefined ? animationDef.parameters[ sampler.output ] : sampler.output;
3782
3799
 
@@ -38,12 +38,12 @@ import {
38
38
  UnsignedByteType
39
39
  } from '../../../../three/src/Three.js';
40
40
  import { WorkerPool } from '../utils/WorkerPool.js';
41
- import * as KTX from '../libs/ktx-parse.module.js';
42
-
43
- const {
41
+ import {
44
42
  read,
45
43
  KHR_DF_FLAG_ALPHA_PREMULTIPLIED,
46
44
  KHR_DF_TRANSFER_SRGB,
45
+ KHR_SUPERCOMPRESSION_NONE,
46
+ KHR_SUPERCOMPRESSION_ZSTD,
47
47
  VK_FORMAT_UNDEFINED,
48
48
  VK_FORMAT_R16_SFLOAT,
49
49
  VK_FORMAT_R16G16_SFLOAT,
@@ -57,12 +57,15 @@ const {
57
57
  VK_FORMAT_R8G8_UNORM,
58
58
  VK_FORMAT_R8G8B8A8_SRGB,
59
59
  VK_FORMAT_R8G8B8A8_UNORM,
60
- } = KTX; // eslint-disable-line no-undef
60
+ } from '../libs/ktx-parse.module.js';
61
+ import { ZSTDDecoder } from '../libs/zstddec.module.js';
61
62
 
62
63
  const _taskCache = new WeakMap();
63
64
 
64
65
  let _activeLoaders = 0;
65
66
 
67
+ let _zstd;
68
+
66
69
  class KTX2Loader extends Loader {
67
70
 
68
71
  constructor( manager ) {
@@ -660,7 +663,7 @@ const ENCODING_MAP = {
660
663
 
661
664
  };
662
665
 
663
- function createDataTexture( container ) {
666
+ async function createDataTexture( container ) {
664
667
 
665
668
  const { vkFormat, pixelWidth, pixelHeight, pixelDepth } = container;
666
669
 
@@ -672,9 +675,36 @@ function createDataTexture( container ) {
672
675
 
673
676
  //
674
677
 
678
+ const level = container.levels[ 0 ];
679
+
680
+ let levelData;
675
681
  let view;
676
682
 
677
- const levelData = container.levels[ 0 ].levelData;
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
+ }
678
708
 
679
709
  if ( TYPE_MAP[ vkFormat ] === FloatType ) {
680
710
 
@@ -5,7 +5,6 @@ import {
5
5
  InstancedBufferAttribute,
6
6
  InterleavedBuffer,
7
7
  InterleavedBufferAttribute,
8
- MathUtils,
9
8
  TriangleFanDrawMode,
10
9
  TriangleStripDrawMode,
11
10
  TrianglesDrawMode,
@@ -36,17 +35,16 @@ function computeMikkTSpaceTangents( geometry, MikkTSpace, negateSign = true ) {
36
35
 
37
36
  if ( attribute.normalized || attribute.isInterleavedBufferAttribute ) {
38
37
 
39
- const srcArray = attribute.isInterleavedBufferAttribute ? attribute.data.array : attribute.array;
40
38
  const dstArray = new Float32Array( attribute.getCount() * attribute.itemSize );
41
39
 
42
40
  for ( let i = 0, j = 0; i < attribute.getCount(); i ++ ) {
43
41
 
44
- dstArray[ j ++ ] = MathUtils.denormalize( attribute.getX( i ), srcArray );
45
- dstArray[ j ++ ] = MathUtils.denormalize( attribute.getY( i ), srcArray );
42
+ dstArray[ j ++ ] = attribute.getX( i );
43
+ dstArray[ j ++ ] = attribute.getY( i );
46
44
 
47
45
  if ( attribute.itemSize > 2 ) {
48
46
 
49
- dstArray[ j ++ ] = MathUtils.denormalize( attribute.getZ( i ), srcArray );
47
+ dstArray[ j ++ ] = attribute.getZ( i );
50
48
 
51
49
  }
52
50
 
@@ -385,7 +383,7 @@ function interleaveAttributes( attributes ) {
385
383
  let arrayLength = 0;
386
384
  let stride = 0;
387
385
 
388
- // calculate the the length and type of the interleavedBuffer
386
+ // calculate the length and type of the interleavedBuffer
389
387
  for ( let i = 0, l = attributes.length; i < l; ++ i ) {
390
388
 
391
389
  const attribute = attributes[ i ];
@@ -555,7 +553,7 @@ function estimateBytesUsed( geometry ) {
555
553
  /**
556
554
  * @param {BufferGeometry} geometry
557
555
  * @param {number} tolerance
558
- * @return {BufferGeometry>}
556
+ * @return {BufferGeometry}
559
557
  */
560
558
  function mergeVertices( geometry, tolerance = 1e-4 ) {
561
559
 
@@ -573,22 +571,33 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
573
571
 
574
572
  // attributes and new attribute arrays
575
573
  const attributeNames = Object.keys( geometry.attributes );
576
- const attrArrays = {};
577
- const morphAttrsArrays = {};
574
+ const tmpAttributes = {};
575
+ const tmpMorphAttributes = {};
578
576
  const newIndices = [];
579
577
  const getters = [ 'getX', 'getY', 'getZ', 'getW' ];
578
+ const setters = [ 'setX', 'setY', 'setZ', 'setW' ];
580
579
 
581
- // initialize the arrays
580
+ // Initialize the arrays, allocating space conservatively. Extra
581
+ // space will be trimmed in the last step.
582
582
  for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
583
583
 
584
584
  const name = attributeNames[ i ];
585
+ const attr = geometry.attributes[ name ];
585
586
 
586
- attrArrays[ name ] = [];
587
+ tmpAttributes[ name ] = new BufferAttribute(
588
+ new attr.array.constructor( attr.count * attr.itemSize ),
589
+ attr.itemSize,
590
+ attr.normalized
591
+ );
587
592
 
588
593
  const morphAttr = geometry.morphAttributes[ name ];
589
594
  if ( morphAttr ) {
590
595
 
591
- 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
+ );
592
601
 
593
602
  }
594
603
 
@@ -626,26 +635,27 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
626
635
 
627
636
  } else {
628
637
 
629
- // copy data to the new index in the attribute arrays
638
+ // copy data to the new index in the temporary attributes
630
639
  for ( let j = 0, l = attributeNames.length; j < l; j ++ ) {
631
640
 
632
641
  const name = attributeNames[ j ];
633
642
  const attribute = geometry.getAttribute( name );
634
643
  const morphAttr = geometry.morphAttributes[ name ];
635
644
  const itemSize = attribute.itemSize;
636
- const newarray = attrArrays[ name ];
637
- const newMorphArrays = morphAttrsArrays[ name ];
645
+ const newarray = tmpAttributes[ name ];
646
+ const newMorphArrays = tmpMorphAttributes[ name ];
638
647
 
639
648
  for ( let k = 0; k < itemSize; k ++ ) {
640
649
 
641
650
  const getterFunc = getters[ k ];
642
- newarray.push( attribute[ getterFunc ]( index ) );
651
+ const setterFunc = setters[ k ];
652
+ newarray[ setterFunc ]( nextIndex, attribute[ getterFunc ]( index ) );
643
653
 
644
654
  if ( morphAttr ) {
645
655
 
646
656
  for ( let m = 0, ml = morphAttr.length; m < ml; m ++ ) {
647
657
 
648
- newMorphArrays[ m ].push( morphAttr[ m ][ getterFunc ]( index ) );
658
+ newMorphArrays[ m ][ setterFunc ]( nextIndex, morphAttr[ m ][ getterFunc ]( index ) );
649
659
 
650
660
  }
651
661
 
@@ -663,31 +673,29 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
663
673
 
664
674
  }
665
675
 
666
- // Generate typed arrays from new attribute arrays and update
667
- // the attributeBuffers
676
+ // generate result BufferGeometry
668
677
  const result = geometry.clone();
669
- for ( let i = 0, l = attributeNames.length; i < l; i ++ ) {
670
-
671
- const name = attributeNames[ i ];
672
- const oldAttribute = geometry.getAttribute( name );
673
-
674
- const buffer = new oldAttribute.array.constructor( attrArrays[ name ] );
675
- const attribute = new BufferAttribute( buffer, oldAttribute.itemSize, oldAttribute.normalized );
678
+ for ( const name in geometry.attributes ) {
676
679
 
677
- result.setAttribute( name, attribute );
680
+ const tmpAttribute = tmpAttributes[ name ];
678
681
 
679
- // Update the attribute arrays
680
- 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
+ ) );
681
687
 
682
- for ( let j = 0; j < morphAttrsArrays[ name ].length; j ++ ) {
688
+ if ( ! ( name in tmpMorphAttributes ) ) continue;
683
689
 
684
- const oldMorphAttribute = geometry.morphAttributes[ name ][ j ];
690
+ for ( let j = 0; j < tmpMorphAttributes[ name ].length; j ++ ) {
685
691
 
686
- const buffer = new oldMorphAttribute.array.constructor( morphAttrsArrays[ name ][ j ] );
687
- const morphAttribute = new BufferAttribute( buffer, oldMorphAttribute.itemSize, oldMorphAttribute.normalized );
688
- result.morphAttributes[ name ][ j ] = morphAttribute;
692
+ const tmpMorphAttribute = tmpMorphAttributes[ name ][ j ];
689
693
 
690
- }
694
+ result.morphAttributes[ name ][ j ] = new BufferAttribute(
695
+ tmpMorphAttribute.array.slice( 0, nextIndex * tmpMorphAttribute.itemSize ),
696
+ tmpMorphAttribute.itemSize,
697
+ tmpMorphAttribute.normalized,
698
+ );
691
699
 
692
700
  }
693
701
 
@@ -704,7 +712,7 @@ function mergeVertices( geometry, tolerance = 1e-4 ) {
704
712
  /**
705
713
  * @param {BufferGeometry} geometry
706
714
  * @param {number} drawMode
707
- * @return {BufferGeometry>}
715
+ * @return {BufferGeometry}
708
716
  */
709
717
  function toTrianglesDrawMode( geometry, drawMode ) {
710
718
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@damienmortini/three",
3
- "version": "0.1.171",
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",
28
+ "@damienmortini/core": "^0.2.134",
29
29
  "fs-extra": "^10.1.0",
30
- "three": "0.143.0"
30
+ "three": "0.145.0"
31
31
  },
32
- "gitHead": "ca9574013c9ba1c2a195603346a2d90242d5b198"
32
+ "gitHead": "9df921714722d7ffbe00c7ae4f0cdf77f0cbc6a4"
33
33
  }