ultron-ai-sdk 1.0.3 → 1.0.4
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.
- package/dist/index.cjs +607 -0
- package/dist/index.mjs +607 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -43602,6 +43602,609 @@ function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
|
|
|
43602
43602
|
|
|
43603
43603
|
}
|
|
43604
43604
|
|
|
43605
|
+
const _taskCache = new WeakMap();
|
|
43606
|
+
|
|
43607
|
+
class DRACOLoader extends Loader {
|
|
43608
|
+
|
|
43609
|
+
constructor( manager ) {
|
|
43610
|
+
|
|
43611
|
+
super( manager );
|
|
43612
|
+
|
|
43613
|
+
this.decoderPath = '';
|
|
43614
|
+
this.decoderConfig = {};
|
|
43615
|
+
this.decoderBinary = null;
|
|
43616
|
+
this.decoderPending = null;
|
|
43617
|
+
|
|
43618
|
+
this.workerLimit = 4;
|
|
43619
|
+
this.workerPool = [];
|
|
43620
|
+
this.workerNextTaskID = 1;
|
|
43621
|
+
this.workerSourceURL = '';
|
|
43622
|
+
|
|
43623
|
+
this.defaultAttributeIDs = {
|
|
43624
|
+
position: 'POSITION',
|
|
43625
|
+
normal: 'NORMAL',
|
|
43626
|
+
color: 'COLOR',
|
|
43627
|
+
uv: 'TEX_COORD'
|
|
43628
|
+
};
|
|
43629
|
+
this.defaultAttributeTypes = {
|
|
43630
|
+
position: 'Float32Array',
|
|
43631
|
+
normal: 'Float32Array',
|
|
43632
|
+
color: 'Float32Array',
|
|
43633
|
+
uv: 'Float32Array'
|
|
43634
|
+
};
|
|
43635
|
+
|
|
43636
|
+
}
|
|
43637
|
+
|
|
43638
|
+
setDecoderPath( path ) {
|
|
43639
|
+
|
|
43640
|
+
this.decoderPath = path;
|
|
43641
|
+
|
|
43642
|
+
return this;
|
|
43643
|
+
|
|
43644
|
+
}
|
|
43645
|
+
|
|
43646
|
+
setDecoderConfig( config ) {
|
|
43647
|
+
|
|
43648
|
+
this.decoderConfig = config;
|
|
43649
|
+
|
|
43650
|
+
return this;
|
|
43651
|
+
|
|
43652
|
+
}
|
|
43653
|
+
|
|
43654
|
+
setWorkerLimit( workerLimit ) {
|
|
43655
|
+
|
|
43656
|
+
this.workerLimit = workerLimit;
|
|
43657
|
+
|
|
43658
|
+
return this;
|
|
43659
|
+
|
|
43660
|
+
}
|
|
43661
|
+
|
|
43662
|
+
load( url, onLoad, onProgress, onError ) {
|
|
43663
|
+
|
|
43664
|
+
const loader = new FileLoader( this.manager );
|
|
43665
|
+
|
|
43666
|
+
loader.setPath( this.path );
|
|
43667
|
+
loader.setResponseType( 'arraybuffer' );
|
|
43668
|
+
loader.setRequestHeader( this.requestHeader );
|
|
43669
|
+
loader.setWithCredentials( this.withCredentials );
|
|
43670
|
+
|
|
43671
|
+
loader.load( url, ( buffer ) => {
|
|
43672
|
+
|
|
43673
|
+
this.parse( buffer, onLoad, onError );
|
|
43674
|
+
|
|
43675
|
+
}, onProgress, onError );
|
|
43676
|
+
|
|
43677
|
+
}
|
|
43678
|
+
|
|
43679
|
+
|
|
43680
|
+
parse( buffer, onLoad, onError = ()=>{} ) {
|
|
43681
|
+
|
|
43682
|
+
this.decodeDracoFile( buffer, onLoad, null, null, SRGBColorSpace, onError ).catch( onError );
|
|
43683
|
+
|
|
43684
|
+
}
|
|
43685
|
+
|
|
43686
|
+
decodeDracoFile( buffer, callback, attributeIDs, attributeTypes, vertexColorSpace = LinearSRGBColorSpace, onError = () => {} ) {
|
|
43687
|
+
|
|
43688
|
+
const taskConfig = {
|
|
43689
|
+
attributeIDs: attributeIDs || this.defaultAttributeIDs,
|
|
43690
|
+
attributeTypes: attributeTypes || this.defaultAttributeTypes,
|
|
43691
|
+
useUniqueIDs: !! attributeIDs,
|
|
43692
|
+
vertexColorSpace: vertexColorSpace,
|
|
43693
|
+
};
|
|
43694
|
+
|
|
43695
|
+
return this.decodeGeometry( buffer, taskConfig ).then( callback ).catch( onError );
|
|
43696
|
+
|
|
43697
|
+
}
|
|
43698
|
+
|
|
43699
|
+
decodeGeometry( buffer, taskConfig ) {
|
|
43700
|
+
|
|
43701
|
+
const taskKey = JSON.stringify( taskConfig );
|
|
43702
|
+
|
|
43703
|
+
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
|
43704
|
+
// again from this thread.
|
|
43705
|
+
if ( _taskCache.has( buffer ) ) {
|
|
43706
|
+
|
|
43707
|
+
const cachedTask = _taskCache.get( buffer );
|
|
43708
|
+
|
|
43709
|
+
if ( cachedTask.key === taskKey ) {
|
|
43710
|
+
|
|
43711
|
+
return cachedTask.promise;
|
|
43712
|
+
|
|
43713
|
+
} else if ( buffer.byteLength === 0 ) {
|
|
43714
|
+
|
|
43715
|
+
// Technically, it would be possible to wait for the previous task to complete,
|
|
43716
|
+
// transfer the buffer back, and decode again with the second configuration. That
|
|
43717
|
+
// is complex, and I don't know of any reason to decode a Draco buffer twice in
|
|
43718
|
+
// different ways, so this is left unimplemented.
|
|
43719
|
+
throw new Error(
|
|
43720
|
+
|
|
43721
|
+
'THREE.DRACOLoader: Unable to re-decode a buffer with different ' +
|
|
43722
|
+
'settings. Buffer has already been transferred.'
|
|
43723
|
+
|
|
43724
|
+
);
|
|
43725
|
+
|
|
43726
|
+
}
|
|
43727
|
+
|
|
43728
|
+
}
|
|
43729
|
+
|
|
43730
|
+
//
|
|
43731
|
+
|
|
43732
|
+
let worker;
|
|
43733
|
+
const taskID = this.workerNextTaskID ++;
|
|
43734
|
+
const taskCost = buffer.byteLength;
|
|
43735
|
+
|
|
43736
|
+
// Obtain a worker and assign a task, and construct a geometry instance
|
|
43737
|
+
// when the task completes.
|
|
43738
|
+
const geometryPending = this._getWorker( taskID, taskCost )
|
|
43739
|
+
.then( ( _worker ) => {
|
|
43740
|
+
|
|
43741
|
+
worker = _worker;
|
|
43742
|
+
|
|
43743
|
+
return new Promise( ( resolve, reject ) => {
|
|
43744
|
+
|
|
43745
|
+
worker._callbacks[ taskID ] = { resolve, reject };
|
|
43746
|
+
|
|
43747
|
+
worker.postMessage( { type: 'decode', id: taskID, taskConfig, buffer }, [ buffer ] );
|
|
43748
|
+
|
|
43749
|
+
// this.debug();
|
|
43750
|
+
|
|
43751
|
+
} );
|
|
43752
|
+
|
|
43753
|
+
} )
|
|
43754
|
+
.then( ( message ) => this._createGeometry( message.geometry ) );
|
|
43755
|
+
|
|
43756
|
+
// Remove task from the task list.
|
|
43757
|
+
// Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
|
|
43758
|
+
geometryPending
|
|
43759
|
+
.catch( () => true )
|
|
43760
|
+
.then( () => {
|
|
43761
|
+
|
|
43762
|
+
if ( worker && taskID ) {
|
|
43763
|
+
|
|
43764
|
+
this._releaseTask( worker, taskID );
|
|
43765
|
+
|
|
43766
|
+
// this.debug();
|
|
43767
|
+
|
|
43768
|
+
}
|
|
43769
|
+
|
|
43770
|
+
} );
|
|
43771
|
+
|
|
43772
|
+
// Cache the task result.
|
|
43773
|
+
_taskCache.set( buffer, {
|
|
43774
|
+
|
|
43775
|
+
key: taskKey,
|
|
43776
|
+
promise: geometryPending
|
|
43777
|
+
|
|
43778
|
+
} );
|
|
43779
|
+
|
|
43780
|
+
return geometryPending;
|
|
43781
|
+
|
|
43782
|
+
}
|
|
43783
|
+
|
|
43784
|
+
_createGeometry( geometryData ) {
|
|
43785
|
+
|
|
43786
|
+
const geometry = new BufferGeometry();
|
|
43787
|
+
|
|
43788
|
+
if ( geometryData.index ) {
|
|
43789
|
+
|
|
43790
|
+
geometry.setIndex( new BufferAttribute( geometryData.index.array, 1 ) );
|
|
43791
|
+
|
|
43792
|
+
}
|
|
43793
|
+
|
|
43794
|
+
for ( let i = 0; i < geometryData.attributes.length; i ++ ) {
|
|
43795
|
+
|
|
43796
|
+
const result = geometryData.attributes[ i ];
|
|
43797
|
+
const name = result.name;
|
|
43798
|
+
const array = result.array;
|
|
43799
|
+
const itemSize = result.itemSize;
|
|
43800
|
+
|
|
43801
|
+
const attribute = new BufferAttribute( array, itemSize );
|
|
43802
|
+
|
|
43803
|
+
if ( name === 'color' ) {
|
|
43804
|
+
|
|
43805
|
+
this._assignVertexColorSpace( attribute, result.vertexColorSpace );
|
|
43806
|
+
|
|
43807
|
+
attribute.normalized = ( array instanceof Float32Array ) === false;
|
|
43808
|
+
|
|
43809
|
+
}
|
|
43810
|
+
|
|
43811
|
+
geometry.setAttribute( name, attribute );
|
|
43812
|
+
|
|
43813
|
+
}
|
|
43814
|
+
|
|
43815
|
+
return geometry;
|
|
43816
|
+
|
|
43817
|
+
}
|
|
43818
|
+
|
|
43819
|
+
_assignVertexColorSpace( attribute, inputColorSpace ) {
|
|
43820
|
+
|
|
43821
|
+
// While .drc files do not specify colorspace, the only 'official' tooling
|
|
43822
|
+
// is PLY and OBJ converters, which use sRGB. We'll assume sRGB when a .drc
|
|
43823
|
+
// file is passed into .load() or .parse(). GLTFLoader uses internal APIs
|
|
43824
|
+
// to decode geometry, and vertex colors are already Linear-sRGB in there.
|
|
43825
|
+
|
|
43826
|
+
if ( inputColorSpace !== SRGBColorSpace ) return;
|
|
43827
|
+
|
|
43828
|
+
const _color = new Color();
|
|
43829
|
+
|
|
43830
|
+
for ( let i = 0, il = attribute.count; i < il; i ++ ) {
|
|
43831
|
+
|
|
43832
|
+
_color.fromBufferAttribute( attribute, i );
|
|
43833
|
+
ColorManagement.toWorkingColorSpace( _color, SRGBColorSpace );
|
|
43834
|
+
attribute.setXYZ( i, _color.r, _color.g, _color.b );
|
|
43835
|
+
|
|
43836
|
+
}
|
|
43837
|
+
|
|
43838
|
+
}
|
|
43839
|
+
|
|
43840
|
+
_loadLibrary( url, responseType ) {
|
|
43841
|
+
|
|
43842
|
+
const loader = new FileLoader( this.manager );
|
|
43843
|
+
loader.setPath( this.decoderPath );
|
|
43844
|
+
loader.setResponseType( responseType );
|
|
43845
|
+
loader.setWithCredentials( this.withCredentials );
|
|
43846
|
+
|
|
43847
|
+
return new Promise( ( resolve, reject ) => {
|
|
43848
|
+
|
|
43849
|
+
loader.load( url, resolve, undefined, reject );
|
|
43850
|
+
|
|
43851
|
+
} );
|
|
43852
|
+
|
|
43853
|
+
}
|
|
43854
|
+
|
|
43855
|
+
preload() {
|
|
43856
|
+
|
|
43857
|
+
this._initDecoder();
|
|
43858
|
+
|
|
43859
|
+
return this;
|
|
43860
|
+
|
|
43861
|
+
}
|
|
43862
|
+
|
|
43863
|
+
_initDecoder() {
|
|
43864
|
+
|
|
43865
|
+
if ( this.decoderPending ) return this.decoderPending;
|
|
43866
|
+
|
|
43867
|
+
const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
|
|
43868
|
+
const librariesPending = [];
|
|
43869
|
+
|
|
43870
|
+
if ( useJS ) {
|
|
43871
|
+
|
|
43872
|
+
librariesPending.push( this._loadLibrary( 'draco_decoder.js', 'text' ) );
|
|
43873
|
+
|
|
43874
|
+
} else {
|
|
43875
|
+
|
|
43876
|
+
librariesPending.push( this._loadLibrary( 'draco_wasm_wrapper.js', 'text' ) );
|
|
43877
|
+
librariesPending.push( this._loadLibrary( 'draco_decoder.wasm', 'arraybuffer' ) );
|
|
43878
|
+
|
|
43879
|
+
}
|
|
43880
|
+
|
|
43881
|
+
this.decoderPending = Promise.all( librariesPending )
|
|
43882
|
+
.then( ( libraries ) => {
|
|
43883
|
+
|
|
43884
|
+
const jsContent = libraries[ 0 ];
|
|
43885
|
+
|
|
43886
|
+
if ( ! useJS ) {
|
|
43887
|
+
|
|
43888
|
+
this.decoderConfig.wasmBinary = libraries[ 1 ];
|
|
43889
|
+
|
|
43890
|
+
}
|
|
43891
|
+
|
|
43892
|
+
const fn = DRACOWorker.toString();
|
|
43893
|
+
|
|
43894
|
+
const body = [
|
|
43895
|
+
'/* draco decoder */',
|
|
43896
|
+
jsContent,
|
|
43897
|
+
'',
|
|
43898
|
+
'/* worker */',
|
|
43899
|
+
fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
|
|
43900
|
+
].join( '\n' );
|
|
43901
|
+
|
|
43902
|
+
this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
|
|
43903
|
+
|
|
43904
|
+
} );
|
|
43905
|
+
|
|
43906
|
+
return this.decoderPending;
|
|
43907
|
+
|
|
43908
|
+
}
|
|
43909
|
+
|
|
43910
|
+
_getWorker( taskID, taskCost ) {
|
|
43911
|
+
|
|
43912
|
+
return this._initDecoder().then( () => {
|
|
43913
|
+
|
|
43914
|
+
if ( this.workerPool.length < this.workerLimit ) {
|
|
43915
|
+
|
|
43916
|
+
const worker = new Worker( this.workerSourceURL );
|
|
43917
|
+
|
|
43918
|
+
worker._callbacks = {};
|
|
43919
|
+
worker._taskCosts = {};
|
|
43920
|
+
worker._taskLoad = 0;
|
|
43921
|
+
|
|
43922
|
+
worker.postMessage( { type: 'init', decoderConfig: this.decoderConfig } );
|
|
43923
|
+
|
|
43924
|
+
worker.onmessage = function ( e ) {
|
|
43925
|
+
|
|
43926
|
+
const message = e.data;
|
|
43927
|
+
|
|
43928
|
+
switch ( message.type ) {
|
|
43929
|
+
|
|
43930
|
+
case 'decode':
|
|
43931
|
+
worker._callbacks[ message.id ].resolve( message );
|
|
43932
|
+
break;
|
|
43933
|
+
|
|
43934
|
+
case 'error':
|
|
43935
|
+
worker._callbacks[ message.id ].reject( message );
|
|
43936
|
+
break;
|
|
43937
|
+
|
|
43938
|
+
default:
|
|
43939
|
+
console.error( 'THREE.DRACOLoader: Unexpected message, "' + message.type + '"' );
|
|
43940
|
+
|
|
43941
|
+
}
|
|
43942
|
+
|
|
43943
|
+
};
|
|
43944
|
+
|
|
43945
|
+
this.workerPool.push( worker );
|
|
43946
|
+
|
|
43947
|
+
} else {
|
|
43948
|
+
|
|
43949
|
+
this.workerPool.sort( function ( a, b ) {
|
|
43950
|
+
|
|
43951
|
+
return a._taskLoad > b._taskLoad ? -1 : 1;
|
|
43952
|
+
|
|
43953
|
+
} );
|
|
43954
|
+
|
|
43955
|
+
}
|
|
43956
|
+
|
|
43957
|
+
const worker = this.workerPool[ this.workerPool.length - 1 ];
|
|
43958
|
+
worker._taskCosts[ taskID ] = taskCost;
|
|
43959
|
+
worker._taskLoad += taskCost;
|
|
43960
|
+
return worker;
|
|
43961
|
+
|
|
43962
|
+
} );
|
|
43963
|
+
|
|
43964
|
+
}
|
|
43965
|
+
|
|
43966
|
+
_releaseTask( worker, taskID ) {
|
|
43967
|
+
|
|
43968
|
+
worker._taskLoad -= worker._taskCosts[ taskID ];
|
|
43969
|
+
delete worker._callbacks[ taskID ];
|
|
43970
|
+
delete worker._taskCosts[ taskID ];
|
|
43971
|
+
|
|
43972
|
+
}
|
|
43973
|
+
|
|
43974
|
+
debug() {
|
|
43975
|
+
|
|
43976
|
+
console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) );
|
|
43977
|
+
|
|
43978
|
+
}
|
|
43979
|
+
|
|
43980
|
+
dispose() {
|
|
43981
|
+
|
|
43982
|
+
for ( let i = 0; i < this.workerPool.length; ++ i ) {
|
|
43983
|
+
|
|
43984
|
+
this.workerPool[ i ].terminate();
|
|
43985
|
+
|
|
43986
|
+
}
|
|
43987
|
+
|
|
43988
|
+
this.workerPool.length = 0;
|
|
43989
|
+
|
|
43990
|
+
if ( this.workerSourceURL !== '' ) {
|
|
43991
|
+
|
|
43992
|
+
URL.revokeObjectURL( this.workerSourceURL );
|
|
43993
|
+
|
|
43994
|
+
}
|
|
43995
|
+
|
|
43996
|
+
return this;
|
|
43997
|
+
|
|
43998
|
+
}
|
|
43999
|
+
|
|
44000
|
+
}
|
|
44001
|
+
|
|
44002
|
+
/* WEB WORKER */
|
|
44003
|
+
|
|
44004
|
+
function DRACOWorker() {
|
|
44005
|
+
|
|
44006
|
+
let decoderConfig;
|
|
44007
|
+
let decoderPending;
|
|
44008
|
+
|
|
44009
|
+
onmessage = function ( e ) {
|
|
44010
|
+
|
|
44011
|
+
const message = e.data;
|
|
44012
|
+
|
|
44013
|
+
switch ( message.type ) {
|
|
44014
|
+
|
|
44015
|
+
case 'init':
|
|
44016
|
+
decoderConfig = message.decoderConfig;
|
|
44017
|
+
decoderPending = new Promise( function ( resolve/*, reject*/ ) {
|
|
44018
|
+
|
|
44019
|
+
decoderConfig.onModuleLoaded = function ( draco ) {
|
|
44020
|
+
|
|
44021
|
+
// Module is Promise-like. Wrap before resolving to avoid loop.
|
|
44022
|
+
resolve( { draco: draco } );
|
|
44023
|
+
|
|
44024
|
+
};
|
|
44025
|
+
|
|
44026
|
+
DracoDecoderModule( decoderConfig ); // eslint-disable-line no-undef
|
|
44027
|
+
|
|
44028
|
+
} );
|
|
44029
|
+
break;
|
|
44030
|
+
|
|
44031
|
+
case 'decode':
|
|
44032
|
+
const buffer = message.buffer;
|
|
44033
|
+
const taskConfig = message.taskConfig;
|
|
44034
|
+
decoderPending.then( ( module ) => {
|
|
44035
|
+
|
|
44036
|
+
const draco = module.draco;
|
|
44037
|
+
const decoder = new draco.Decoder();
|
|
44038
|
+
|
|
44039
|
+
try {
|
|
44040
|
+
|
|
44041
|
+
const geometry = decodeGeometry( draco, decoder, new Int8Array( buffer ), taskConfig );
|
|
44042
|
+
|
|
44043
|
+
const buffers = geometry.attributes.map( ( attr ) => attr.array.buffer );
|
|
44044
|
+
|
|
44045
|
+
if ( geometry.index ) buffers.push( geometry.index.array.buffer );
|
|
44046
|
+
|
|
44047
|
+
self.postMessage( { type: 'decode', id: message.id, geometry }, buffers );
|
|
44048
|
+
|
|
44049
|
+
} catch ( error ) {
|
|
44050
|
+
|
|
44051
|
+
console.error( error );
|
|
44052
|
+
|
|
44053
|
+
self.postMessage( { type: 'error', id: message.id, error: error.message } );
|
|
44054
|
+
|
|
44055
|
+
} finally {
|
|
44056
|
+
|
|
44057
|
+
draco.destroy( decoder );
|
|
44058
|
+
|
|
44059
|
+
}
|
|
44060
|
+
|
|
44061
|
+
} );
|
|
44062
|
+
break;
|
|
44063
|
+
|
|
44064
|
+
}
|
|
44065
|
+
|
|
44066
|
+
};
|
|
44067
|
+
|
|
44068
|
+
function decodeGeometry( draco, decoder, array, taskConfig ) {
|
|
44069
|
+
|
|
44070
|
+
const attributeIDs = taskConfig.attributeIDs;
|
|
44071
|
+
const attributeTypes = taskConfig.attributeTypes;
|
|
44072
|
+
|
|
44073
|
+
let dracoGeometry;
|
|
44074
|
+
let decodingStatus;
|
|
44075
|
+
|
|
44076
|
+
const geometryType = decoder.GetEncodedGeometryType( array );
|
|
44077
|
+
|
|
44078
|
+
if ( geometryType === draco.TRIANGULAR_MESH ) {
|
|
44079
|
+
|
|
44080
|
+
dracoGeometry = new draco.Mesh();
|
|
44081
|
+
decodingStatus = decoder.DecodeArrayToMesh( array, array.byteLength, dracoGeometry );
|
|
44082
|
+
|
|
44083
|
+
} else if ( geometryType === draco.POINT_CLOUD ) {
|
|
44084
|
+
|
|
44085
|
+
dracoGeometry = new draco.PointCloud();
|
|
44086
|
+
decodingStatus = decoder.DecodeArrayToPointCloud( array, array.byteLength, dracoGeometry );
|
|
44087
|
+
|
|
44088
|
+
} else {
|
|
44089
|
+
|
|
44090
|
+
throw new Error( 'THREE.DRACOLoader: Unexpected geometry type.' );
|
|
44091
|
+
|
|
44092
|
+
}
|
|
44093
|
+
|
|
44094
|
+
if ( ! decodingStatus.ok() || dracoGeometry.ptr === 0 ) {
|
|
44095
|
+
|
|
44096
|
+
throw new Error( 'THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg() );
|
|
44097
|
+
|
|
44098
|
+
}
|
|
44099
|
+
|
|
44100
|
+
const geometry = { index: null, attributes: [] };
|
|
44101
|
+
|
|
44102
|
+
// Gather all vertex attributes.
|
|
44103
|
+
for ( const attributeName in attributeIDs ) {
|
|
44104
|
+
|
|
44105
|
+
const attributeType = self[ attributeTypes[ attributeName ] ];
|
|
44106
|
+
|
|
44107
|
+
let attribute;
|
|
44108
|
+
let attributeID;
|
|
44109
|
+
|
|
44110
|
+
// A Draco file may be created with default vertex attributes, whose attribute IDs
|
|
44111
|
+
// are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
|
|
44112
|
+
// a Draco file may contain a custom set of attributes, identified by known unique
|
|
44113
|
+
// IDs. glTF files always do the latter, and `.drc` files typically do the former.
|
|
44114
|
+
if ( taskConfig.useUniqueIDs ) {
|
|
44115
|
+
|
|
44116
|
+
attributeID = attributeIDs[ attributeName ];
|
|
44117
|
+
attribute = decoder.GetAttributeByUniqueId( dracoGeometry, attributeID );
|
|
44118
|
+
|
|
44119
|
+
} else {
|
|
44120
|
+
|
|
44121
|
+
attributeID = decoder.GetAttributeId( dracoGeometry, draco[ attributeIDs[ attributeName ] ] );
|
|
44122
|
+
|
|
44123
|
+
if ( attributeID === -1 ) continue;
|
|
44124
|
+
|
|
44125
|
+
attribute = decoder.GetAttribute( dracoGeometry, attributeID );
|
|
44126
|
+
|
|
44127
|
+
}
|
|
44128
|
+
|
|
44129
|
+
const attributeResult = decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute );
|
|
44130
|
+
|
|
44131
|
+
if ( attributeName === 'color' ) {
|
|
44132
|
+
|
|
44133
|
+
attributeResult.vertexColorSpace = taskConfig.vertexColorSpace;
|
|
44134
|
+
|
|
44135
|
+
}
|
|
44136
|
+
|
|
44137
|
+
geometry.attributes.push( attributeResult );
|
|
44138
|
+
|
|
44139
|
+
}
|
|
44140
|
+
|
|
44141
|
+
// Add index.
|
|
44142
|
+
if ( geometryType === draco.TRIANGULAR_MESH ) {
|
|
44143
|
+
|
|
44144
|
+
geometry.index = decodeIndex( draco, decoder, dracoGeometry );
|
|
44145
|
+
|
|
44146
|
+
}
|
|
44147
|
+
|
|
44148
|
+
draco.destroy( dracoGeometry );
|
|
44149
|
+
|
|
44150
|
+
return geometry;
|
|
44151
|
+
|
|
44152
|
+
}
|
|
44153
|
+
|
|
44154
|
+
function decodeIndex( draco, decoder, dracoGeometry ) {
|
|
44155
|
+
|
|
44156
|
+
const numFaces = dracoGeometry.num_faces();
|
|
44157
|
+
const numIndices = numFaces * 3;
|
|
44158
|
+
const byteLength = numIndices * 4;
|
|
44159
|
+
|
|
44160
|
+
const ptr = draco._malloc( byteLength );
|
|
44161
|
+
decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr );
|
|
44162
|
+
const index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
|
|
44163
|
+
draco._free( ptr );
|
|
44164
|
+
|
|
44165
|
+
return { array: index, itemSize: 1 };
|
|
44166
|
+
|
|
44167
|
+
}
|
|
44168
|
+
|
|
44169
|
+
function decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute ) {
|
|
44170
|
+
|
|
44171
|
+
const numComponents = attribute.num_components();
|
|
44172
|
+
const numPoints = dracoGeometry.num_points();
|
|
44173
|
+
const numValues = numPoints * numComponents;
|
|
44174
|
+
const byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
|
|
44175
|
+
const dataType = getDracoDataType( draco, attributeType );
|
|
44176
|
+
|
|
44177
|
+
const ptr = draco._malloc( byteLength );
|
|
44178
|
+
decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dataType, byteLength, ptr );
|
|
44179
|
+
const array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice();
|
|
44180
|
+
draco._free( ptr );
|
|
44181
|
+
|
|
44182
|
+
return {
|
|
44183
|
+
name: attributeName,
|
|
44184
|
+
array: array,
|
|
44185
|
+
itemSize: numComponents
|
|
44186
|
+
};
|
|
44187
|
+
|
|
44188
|
+
}
|
|
44189
|
+
|
|
44190
|
+
function getDracoDataType( draco, attributeType ) {
|
|
44191
|
+
|
|
44192
|
+
switch ( attributeType ) {
|
|
44193
|
+
|
|
44194
|
+
case Float32Array: return draco.DT_FLOAT32;
|
|
44195
|
+
case Int8Array: return draco.DT_INT8;
|
|
44196
|
+
case Int16Array: return draco.DT_INT16;
|
|
44197
|
+
case Int32Array: return draco.DT_INT32;
|
|
44198
|
+
case Uint8Array: return draco.DT_UINT8;
|
|
44199
|
+
case Uint16Array: return draco.DT_UINT16;
|
|
44200
|
+
case Uint32Array: return draco.DT_UINT32;
|
|
44201
|
+
|
|
44202
|
+
}
|
|
44203
|
+
|
|
44204
|
+
}
|
|
44205
|
+
|
|
44206
|
+
}
|
|
44207
|
+
|
|
43605
44208
|
class AudioListener {
|
|
43606
44209
|
constructor() {
|
|
43607
44210
|
this.mediaRecorder = null;
|
|
@@ -44183,6 +44786,10 @@ class Character {
|
|
|
44183
44786
|
}
|
|
44184
44787
|
console.log("loading model", this.modelUrl);
|
|
44185
44788
|
const loader = new GLTFLoader();
|
|
44789
|
+
const dracoLoader = new DRACOLoader();
|
|
44790
|
+
dracoLoader.setDecoderPath('https://threejs.org/examples/jsm/libs/draco/');
|
|
44791
|
+
console.log('draco loader working');
|
|
44792
|
+
loader.setDRACOLoader(dracoLoader);
|
|
44186
44793
|
let gltf = await loader.loadAsync(this.modelUrl, this.onModelLoadProgress, this.onModelLoadError);
|
|
44187
44794
|
if(gltf)console.log("gltf loaded",gltf);
|
|
44188
44795
|
this.model = gltf.scene;
|
package/dist/index.mjs
CHANGED
|
@@ -43600,6 +43600,609 @@ function addPrimitiveAttributes( geometry, primitiveDef, parser ) {
|
|
|
43600
43600
|
|
|
43601
43601
|
}
|
|
43602
43602
|
|
|
43603
|
+
const _taskCache = new WeakMap();
|
|
43604
|
+
|
|
43605
|
+
class DRACOLoader extends Loader {
|
|
43606
|
+
|
|
43607
|
+
constructor( manager ) {
|
|
43608
|
+
|
|
43609
|
+
super( manager );
|
|
43610
|
+
|
|
43611
|
+
this.decoderPath = '';
|
|
43612
|
+
this.decoderConfig = {};
|
|
43613
|
+
this.decoderBinary = null;
|
|
43614
|
+
this.decoderPending = null;
|
|
43615
|
+
|
|
43616
|
+
this.workerLimit = 4;
|
|
43617
|
+
this.workerPool = [];
|
|
43618
|
+
this.workerNextTaskID = 1;
|
|
43619
|
+
this.workerSourceURL = '';
|
|
43620
|
+
|
|
43621
|
+
this.defaultAttributeIDs = {
|
|
43622
|
+
position: 'POSITION',
|
|
43623
|
+
normal: 'NORMAL',
|
|
43624
|
+
color: 'COLOR',
|
|
43625
|
+
uv: 'TEX_COORD'
|
|
43626
|
+
};
|
|
43627
|
+
this.defaultAttributeTypes = {
|
|
43628
|
+
position: 'Float32Array',
|
|
43629
|
+
normal: 'Float32Array',
|
|
43630
|
+
color: 'Float32Array',
|
|
43631
|
+
uv: 'Float32Array'
|
|
43632
|
+
};
|
|
43633
|
+
|
|
43634
|
+
}
|
|
43635
|
+
|
|
43636
|
+
setDecoderPath( path ) {
|
|
43637
|
+
|
|
43638
|
+
this.decoderPath = path;
|
|
43639
|
+
|
|
43640
|
+
return this;
|
|
43641
|
+
|
|
43642
|
+
}
|
|
43643
|
+
|
|
43644
|
+
setDecoderConfig( config ) {
|
|
43645
|
+
|
|
43646
|
+
this.decoderConfig = config;
|
|
43647
|
+
|
|
43648
|
+
return this;
|
|
43649
|
+
|
|
43650
|
+
}
|
|
43651
|
+
|
|
43652
|
+
setWorkerLimit( workerLimit ) {
|
|
43653
|
+
|
|
43654
|
+
this.workerLimit = workerLimit;
|
|
43655
|
+
|
|
43656
|
+
return this;
|
|
43657
|
+
|
|
43658
|
+
}
|
|
43659
|
+
|
|
43660
|
+
load( url, onLoad, onProgress, onError ) {
|
|
43661
|
+
|
|
43662
|
+
const loader = new FileLoader( this.manager );
|
|
43663
|
+
|
|
43664
|
+
loader.setPath( this.path );
|
|
43665
|
+
loader.setResponseType( 'arraybuffer' );
|
|
43666
|
+
loader.setRequestHeader( this.requestHeader );
|
|
43667
|
+
loader.setWithCredentials( this.withCredentials );
|
|
43668
|
+
|
|
43669
|
+
loader.load( url, ( buffer ) => {
|
|
43670
|
+
|
|
43671
|
+
this.parse( buffer, onLoad, onError );
|
|
43672
|
+
|
|
43673
|
+
}, onProgress, onError );
|
|
43674
|
+
|
|
43675
|
+
}
|
|
43676
|
+
|
|
43677
|
+
|
|
43678
|
+
parse( buffer, onLoad, onError = ()=>{} ) {
|
|
43679
|
+
|
|
43680
|
+
this.decodeDracoFile( buffer, onLoad, null, null, SRGBColorSpace, onError ).catch( onError );
|
|
43681
|
+
|
|
43682
|
+
}
|
|
43683
|
+
|
|
43684
|
+
decodeDracoFile( buffer, callback, attributeIDs, attributeTypes, vertexColorSpace = LinearSRGBColorSpace, onError = () => {} ) {
|
|
43685
|
+
|
|
43686
|
+
const taskConfig = {
|
|
43687
|
+
attributeIDs: attributeIDs || this.defaultAttributeIDs,
|
|
43688
|
+
attributeTypes: attributeTypes || this.defaultAttributeTypes,
|
|
43689
|
+
useUniqueIDs: !! attributeIDs,
|
|
43690
|
+
vertexColorSpace: vertexColorSpace,
|
|
43691
|
+
};
|
|
43692
|
+
|
|
43693
|
+
return this.decodeGeometry( buffer, taskConfig ).then( callback ).catch( onError );
|
|
43694
|
+
|
|
43695
|
+
}
|
|
43696
|
+
|
|
43697
|
+
decodeGeometry( buffer, taskConfig ) {
|
|
43698
|
+
|
|
43699
|
+
const taskKey = JSON.stringify( taskConfig );
|
|
43700
|
+
|
|
43701
|
+
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
|
|
43702
|
+
// again from this thread.
|
|
43703
|
+
if ( _taskCache.has( buffer ) ) {
|
|
43704
|
+
|
|
43705
|
+
const cachedTask = _taskCache.get( buffer );
|
|
43706
|
+
|
|
43707
|
+
if ( cachedTask.key === taskKey ) {
|
|
43708
|
+
|
|
43709
|
+
return cachedTask.promise;
|
|
43710
|
+
|
|
43711
|
+
} else if ( buffer.byteLength === 0 ) {
|
|
43712
|
+
|
|
43713
|
+
// Technically, it would be possible to wait for the previous task to complete,
|
|
43714
|
+
// transfer the buffer back, and decode again with the second configuration. That
|
|
43715
|
+
// is complex, and I don't know of any reason to decode a Draco buffer twice in
|
|
43716
|
+
// different ways, so this is left unimplemented.
|
|
43717
|
+
throw new Error(
|
|
43718
|
+
|
|
43719
|
+
'THREE.DRACOLoader: Unable to re-decode a buffer with different ' +
|
|
43720
|
+
'settings. Buffer has already been transferred.'
|
|
43721
|
+
|
|
43722
|
+
);
|
|
43723
|
+
|
|
43724
|
+
}
|
|
43725
|
+
|
|
43726
|
+
}
|
|
43727
|
+
|
|
43728
|
+
//
|
|
43729
|
+
|
|
43730
|
+
let worker;
|
|
43731
|
+
const taskID = this.workerNextTaskID ++;
|
|
43732
|
+
const taskCost = buffer.byteLength;
|
|
43733
|
+
|
|
43734
|
+
// Obtain a worker and assign a task, and construct a geometry instance
|
|
43735
|
+
// when the task completes.
|
|
43736
|
+
const geometryPending = this._getWorker( taskID, taskCost )
|
|
43737
|
+
.then( ( _worker ) => {
|
|
43738
|
+
|
|
43739
|
+
worker = _worker;
|
|
43740
|
+
|
|
43741
|
+
return new Promise( ( resolve, reject ) => {
|
|
43742
|
+
|
|
43743
|
+
worker._callbacks[ taskID ] = { resolve, reject };
|
|
43744
|
+
|
|
43745
|
+
worker.postMessage( { type: 'decode', id: taskID, taskConfig, buffer }, [ buffer ] );
|
|
43746
|
+
|
|
43747
|
+
// this.debug();
|
|
43748
|
+
|
|
43749
|
+
} );
|
|
43750
|
+
|
|
43751
|
+
} )
|
|
43752
|
+
.then( ( message ) => this._createGeometry( message.geometry ) );
|
|
43753
|
+
|
|
43754
|
+
// Remove task from the task list.
|
|
43755
|
+
// Note: replaced '.finally()' with '.catch().then()' block - iOS 11 support (#19416)
|
|
43756
|
+
geometryPending
|
|
43757
|
+
.catch( () => true )
|
|
43758
|
+
.then( () => {
|
|
43759
|
+
|
|
43760
|
+
if ( worker && taskID ) {
|
|
43761
|
+
|
|
43762
|
+
this._releaseTask( worker, taskID );
|
|
43763
|
+
|
|
43764
|
+
// this.debug();
|
|
43765
|
+
|
|
43766
|
+
}
|
|
43767
|
+
|
|
43768
|
+
} );
|
|
43769
|
+
|
|
43770
|
+
// Cache the task result.
|
|
43771
|
+
_taskCache.set( buffer, {
|
|
43772
|
+
|
|
43773
|
+
key: taskKey,
|
|
43774
|
+
promise: geometryPending
|
|
43775
|
+
|
|
43776
|
+
} );
|
|
43777
|
+
|
|
43778
|
+
return geometryPending;
|
|
43779
|
+
|
|
43780
|
+
}
|
|
43781
|
+
|
|
43782
|
+
_createGeometry( geometryData ) {
|
|
43783
|
+
|
|
43784
|
+
const geometry = new BufferGeometry();
|
|
43785
|
+
|
|
43786
|
+
if ( geometryData.index ) {
|
|
43787
|
+
|
|
43788
|
+
geometry.setIndex( new BufferAttribute( geometryData.index.array, 1 ) );
|
|
43789
|
+
|
|
43790
|
+
}
|
|
43791
|
+
|
|
43792
|
+
for ( let i = 0; i < geometryData.attributes.length; i ++ ) {
|
|
43793
|
+
|
|
43794
|
+
const result = geometryData.attributes[ i ];
|
|
43795
|
+
const name = result.name;
|
|
43796
|
+
const array = result.array;
|
|
43797
|
+
const itemSize = result.itemSize;
|
|
43798
|
+
|
|
43799
|
+
const attribute = new BufferAttribute( array, itemSize );
|
|
43800
|
+
|
|
43801
|
+
if ( name === 'color' ) {
|
|
43802
|
+
|
|
43803
|
+
this._assignVertexColorSpace( attribute, result.vertexColorSpace );
|
|
43804
|
+
|
|
43805
|
+
attribute.normalized = ( array instanceof Float32Array ) === false;
|
|
43806
|
+
|
|
43807
|
+
}
|
|
43808
|
+
|
|
43809
|
+
geometry.setAttribute( name, attribute );
|
|
43810
|
+
|
|
43811
|
+
}
|
|
43812
|
+
|
|
43813
|
+
return geometry;
|
|
43814
|
+
|
|
43815
|
+
}
|
|
43816
|
+
|
|
43817
|
+
_assignVertexColorSpace( attribute, inputColorSpace ) {
|
|
43818
|
+
|
|
43819
|
+
// While .drc files do not specify colorspace, the only 'official' tooling
|
|
43820
|
+
// is PLY and OBJ converters, which use sRGB. We'll assume sRGB when a .drc
|
|
43821
|
+
// file is passed into .load() or .parse(). GLTFLoader uses internal APIs
|
|
43822
|
+
// to decode geometry, and vertex colors are already Linear-sRGB in there.
|
|
43823
|
+
|
|
43824
|
+
if ( inputColorSpace !== SRGBColorSpace ) return;
|
|
43825
|
+
|
|
43826
|
+
const _color = new Color();
|
|
43827
|
+
|
|
43828
|
+
for ( let i = 0, il = attribute.count; i < il; i ++ ) {
|
|
43829
|
+
|
|
43830
|
+
_color.fromBufferAttribute( attribute, i );
|
|
43831
|
+
ColorManagement.toWorkingColorSpace( _color, SRGBColorSpace );
|
|
43832
|
+
attribute.setXYZ( i, _color.r, _color.g, _color.b );
|
|
43833
|
+
|
|
43834
|
+
}
|
|
43835
|
+
|
|
43836
|
+
}
|
|
43837
|
+
|
|
43838
|
+
_loadLibrary( url, responseType ) {
|
|
43839
|
+
|
|
43840
|
+
const loader = new FileLoader( this.manager );
|
|
43841
|
+
loader.setPath( this.decoderPath );
|
|
43842
|
+
loader.setResponseType( responseType );
|
|
43843
|
+
loader.setWithCredentials( this.withCredentials );
|
|
43844
|
+
|
|
43845
|
+
return new Promise( ( resolve, reject ) => {
|
|
43846
|
+
|
|
43847
|
+
loader.load( url, resolve, undefined, reject );
|
|
43848
|
+
|
|
43849
|
+
} );
|
|
43850
|
+
|
|
43851
|
+
}
|
|
43852
|
+
|
|
43853
|
+
preload() {
|
|
43854
|
+
|
|
43855
|
+
this._initDecoder();
|
|
43856
|
+
|
|
43857
|
+
return this;
|
|
43858
|
+
|
|
43859
|
+
}
|
|
43860
|
+
|
|
43861
|
+
_initDecoder() {
|
|
43862
|
+
|
|
43863
|
+
if ( this.decoderPending ) return this.decoderPending;
|
|
43864
|
+
|
|
43865
|
+
const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
|
|
43866
|
+
const librariesPending = [];
|
|
43867
|
+
|
|
43868
|
+
if ( useJS ) {
|
|
43869
|
+
|
|
43870
|
+
librariesPending.push( this._loadLibrary( 'draco_decoder.js', 'text' ) );
|
|
43871
|
+
|
|
43872
|
+
} else {
|
|
43873
|
+
|
|
43874
|
+
librariesPending.push( this._loadLibrary( 'draco_wasm_wrapper.js', 'text' ) );
|
|
43875
|
+
librariesPending.push( this._loadLibrary( 'draco_decoder.wasm', 'arraybuffer' ) );
|
|
43876
|
+
|
|
43877
|
+
}
|
|
43878
|
+
|
|
43879
|
+
this.decoderPending = Promise.all( librariesPending )
|
|
43880
|
+
.then( ( libraries ) => {
|
|
43881
|
+
|
|
43882
|
+
const jsContent = libraries[ 0 ];
|
|
43883
|
+
|
|
43884
|
+
if ( ! useJS ) {
|
|
43885
|
+
|
|
43886
|
+
this.decoderConfig.wasmBinary = libraries[ 1 ];
|
|
43887
|
+
|
|
43888
|
+
}
|
|
43889
|
+
|
|
43890
|
+
const fn = DRACOWorker.toString();
|
|
43891
|
+
|
|
43892
|
+
const body = [
|
|
43893
|
+
'/* draco decoder */',
|
|
43894
|
+
jsContent,
|
|
43895
|
+
'',
|
|
43896
|
+
'/* worker */',
|
|
43897
|
+
fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) )
|
|
43898
|
+
].join( '\n' );
|
|
43899
|
+
|
|
43900
|
+
this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
|
|
43901
|
+
|
|
43902
|
+
} );
|
|
43903
|
+
|
|
43904
|
+
return this.decoderPending;
|
|
43905
|
+
|
|
43906
|
+
}
|
|
43907
|
+
|
|
43908
|
+
_getWorker( taskID, taskCost ) {
|
|
43909
|
+
|
|
43910
|
+
return this._initDecoder().then( () => {
|
|
43911
|
+
|
|
43912
|
+
if ( this.workerPool.length < this.workerLimit ) {
|
|
43913
|
+
|
|
43914
|
+
const worker = new Worker( this.workerSourceURL );
|
|
43915
|
+
|
|
43916
|
+
worker._callbacks = {};
|
|
43917
|
+
worker._taskCosts = {};
|
|
43918
|
+
worker._taskLoad = 0;
|
|
43919
|
+
|
|
43920
|
+
worker.postMessage( { type: 'init', decoderConfig: this.decoderConfig } );
|
|
43921
|
+
|
|
43922
|
+
worker.onmessage = function ( e ) {
|
|
43923
|
+
|
|
43924
|
+
const message = e.data;
|
|
43925
|
+
|
|
43926
|
+
switch ( message.type ) {
|
|
43927
|
+
|
|
43928
|
+
case 'decode':
|
|
43929
|
+
worker._callbacks[ message.id ].resolve( message );
|
|
43930
|
+
break;
|
|
43931
|
+
|
|
43932
|
+
case 'error':
|
|
43933
|
+
worker._callbacks[ message.id ].reject( message );
|
|
43934
|
+
break;
|
|
43935
|
+
|
|
43936
|
+
default:
|
|
43937
|
+
console.error( 'THREE.DRACOLoader: Unexpected message, "' + message.type + '"' );
|
|
43938
|
+
|
|
43939
|
+
}
|
|
43940
|
+
|
|
43941
|
+
};
|
|
43942
|
+
|
|
43943
|
+
this.workerPool.push( worker );
|
|
43944
|
+
|
|
43945
|
+
} else {
|
|
43946
|
+
|
|
43947
|
+
this.workerPool.sort( function ( a, b ) {
|
|
43948
|
+
|
|
43949
|
+
return a._taskLoad > b._taskLoad ? -1 : 1;
|
|
43950
|
+
|
|
43951
|
+
} );
|
|
43952
|
+
|
|
43953
|
+
}
|
|
43954
|
+
|
|
43955
|
+
const worker = this.workerPool[ this.workerPool.length - 1 ];
|
|
43956
|
+
worker._taskCosts[ taskID ] = taskCost;
|
|
43957
|
+
worker._taskLoad += taskCost;
|
|
43958
|
+
return worker;
|
|
43959
|
+
|
|
43960
|
+
} );
|
|
43961
|
+
|
|
43962
|
+
}
|
|
43963
|
+
|
|
43964
|
+
_releaseTask( worker, taskID ) {
|
|
43965
|
+
|
|
43966
|
+
worker._taskLoad -= worker._taskCosts[ taskID ];
|
|
43967
|
+
delete worker._callbacks[ taskID ];
|
|
43968
|
+
delete worker._taskCosts[ taskID ];
|
|
43969
|
+
|
|
43970
|
+
}
|
|
43971
|
+
|
|
43972
|
+
debug() {
|
|
43973
|
+
|
|
43974
|
+
console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) );
|
|
43975
|
+
|
|
43976
|
+
}
|
|
43977
|
+
|
|
43978
|
+
dispose() {
|
|
43979
|
+
|
|
43980
|
+
for ( let i = 0; i < this.workerPool.length; ++ i ) {
|
|
43981
|
+
|
|
43982
|
+
this.workerPool[ i ].terminate();
|
|
43983
|
+
|
|
43984
|
+
}
|
|
43985
|
+
|
|
43986
|
+
this.workerPool.length = 0;
|
|
43987
|
+
|
|
43988
|
+
if ( this.workerSourceURL !== '' ) {
|
|
43989
|
+
|
|
43990
|
+
URL.revokeObjectURL( this.workerSourceURL );
|
|
43991
|
+
|
|
43992
|
+
}
|
|
43993
|
+
|
|
43994
|
+
return this;
|
|
43995
|
+
|
|
43996
|
+
}
|
|
43997
|
+
|
|
43998
|
+
}
|
|
43999
|
+
|
|
44000
|
+
/* WEB WORKER */
|
|
44001
|
+
|
|
44002
|
+
function DRACOWorker() {
|
|
44003
|
+
|
|
44004
|
+
let decoderConfig;
|
|
44005
|
+
let decoderPending;
|
|
44006
|
+
|
|
44007
|
+
onmessage = function ( e ) {
|
|
44008
|
+
|
|
44009
|
+
const message = e.data;
|
|
44010
|
+
|
|
44011
|
+
switch ( message.type ) {
|
|
44012
|
+
|
|
44013
|
+
case 'init':
|
|
44014
|
+
decoderConfig = message.decoderConfig;
|
|
44015
|
+
decoderPending = new Promise( function ( resolve/*, reject*/ ) {
|
|
44016
|
+
|
|
44017
|
+
decoderConfig.onModuleLoaded = function ( draco ) {
|
|
44018
|
+
|
|
44019
|
+
// Module is Promise-like. Wrap before resolving to avoid loop.
|
|
44020
|
+
resolve( { draco: draco } );
|
|
44021
|
+
|
|
44022
|
+
};
|
|
44023
|
+
|
|
44024
|
+
DracoDecoderModule( decoderConfig ); // eslint-disable-line no-undef
|
|
44025
|
+
|
|
44026
|
+
} );
|
|
44027
|
+
break;
|
|
44028
|
+
|
|
44029
|
+
case 'decode':
|
|
44030
|
+
const buffer = message.buffer;
|
|
44031
|
+
const taskConfig = message.taskConfig;
|
|
44032
|
+
decoderPending.then( ( module ) => {
|
|
44033
|
+
|
|
44034
|
+
const draco = module.draco;
|
|
44035
|
+
const decoder = new draco.Decoder();
|
|
44036
|
+
|
|
44037
|
+
try {
|
|
44038
|
+
|
|
44039
|
+
const geometry = decodeGeometry( draco, decoder, new Int8Array( buffer ), taskConfig );
|
|
44040
|
+
|
|
44041
|
+
const buffers = geometry.attributes.map( ( attr ) => attr.array.buffer );
|
|
44042
|
+
|
|
44043
|
+
if ( geometry.index ) buffers.push( geometry.index.array.buffer );
|
|
44044
|
+
|
|
44045
|
+
self.postMessage( { type: 'decode', id: message.id, geometry }, buffers );
|
|
44046
|
+
|
|
44047
|
+
} catch ( error ) {
|
|
44048
|
+
|
|
44049
|
+
console.error( error );
|
|
44050
|
+
|
|
44051
|
+
self.postMessage( { type: 'error', id: message.id, error: error.message } );
|
|
44052
|
+
|
|
44053
|
+
} finally {
|
|
44054
|
+
|
|
44055
|
+
draco.destroy( decoder );
|
|
44056
|
+
|
|
44057
|
+
}
|
|
44058
|
+
|
|
44059
|
+
} );
|
|
44060
|
+
break;
|
|
44061
|
+
|
|
44062
|
+
}
|
|
44063
|
+
|
|
44064
|
+
};
|
|
44065
|
+
|
|
44066
|
+
function decodeGeometry( draco, decoder, array, taskConfig ) {
|
|
44067
|
+
|
|
44068
|
+
const attributeIDs = taskConfig.attributeIDs;
|
|
44069
|
+
const attributeTypes = taskConfig.attributeTypes;
|
|
44070
|
+
|
|
44071
|
+
let dracoGeometry;
|
|
44072
|
+
let decodingStatus;
|
|
44073
|
+
|
|
44074
|
+
const geometryType = decoder.GetEncodedGeometryType( array );
|
|
44075
|
+
|
|
44076
|
+
if ( geometryType === draco.TRIANGULAR_MESH ) {
|
|
44077
|
+
|
|
44078
|
+
dracoGeometry = new draco.Mesh();
|
|
44079
|
+
decodingStatus = decoder.DecodeArrayToMesh( array, array.byteLength, dracoGeometry );
|
|
44080
|
+
|
|
44081
|
+
} else if ( geometryType === draco.POINT_CLOUD ) {
|
|
44082
|
+
|
|
44083
|
+
dracoGeometry = new draco.PointCloud();
|
|
44084
|
+
decodingStatus = decoder.DecodeArrayToPointCloud( array, array.byteLength, dracoGeometry );
|
|
44085
|
+
|
|
44086
|
+
} else {
|
|
44087
|
+
|
|
44088
|
+
throw new Error( 'THREE.DRACOLoader: Unexpected geometry type.' );
|
|
44089
|
+
|
|
44090
|
+
}
|
|
44091
|
+
|
|
44092
|
+
if ( ! decodingStatus.ok() || dracoGeometry.ptr === 0 ) {
|
|
44093
|
+
|
|
44094
|
+
throw new Error( 'THREE.DRACOLoader: Decoding failed: ' + decodingStatus.error_msg() );
|
|
44095
|
+
|
|
44096
|
+
}
|
|
44097
|
+
|
|
44098
|
+
const geometry = { index: null, attributes: [] };
|
|
44099
|
+
|
|
44100
|
+
// Gather all vertex attributes.
|
|
44101
|
+
for ( const attributeName in attributeIDs ) {
|
|
44102
|
+
|
|
44103
|
+
const attributeType = self[ attributeTypes[ attributeName ] ];
|
|
44104
|
+
|
|
44105
|
+
let attribute;
|
|
44106
|
+
let attributeID;
|
|
44107
|
+
|
|
44108
|
+
// A Draco file may be created with default vertex attributes, whose attribute IDs
|
|
44109
|
+
// are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
|
|
44110
|
+
// a Draco file may contain a custom set of attributes, identified by known unique
|
|
44111
|
+
// IDs. glTF files always do the latter, and `.drc` files typically do the former.
|
|
44112
|
+
if ( taskConfig.useUniqueIDs ) {
|
|
44113
|
+
|
|
44114
|
+
attributeID = attributeIDs[ attributeName ];
|
|
44115
|
+
attribute = decoder.GetAttributeByUniqueId( dracoGeometry, attributeID );
|
|
44116
|
+
|
|
44117
|
+
} else {
|
|
44118
|
+
|
|
44119
|
+
attributeID = decoder.GetAttributeId( dracoGeometry, draco[ attributeIDs[ attributeName ] ] );
|
|
44120
|
+
|
|
44121
|
+
if ( attributeID === -1 ) continue;
|
|
44122
|
+
|
|
44123
|
+
attribute = decoder.GetAttribute( dracoGeometry, attributeID );
|
|
44124
|
+
|
|
44125
|
+
}
|
|
44126
|
+
|
|
44127
|
+
const attributeResult = decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute );
|
|
44128
|
+
|
|
44129
|
+
if ( attributeName === 'color' ) {
|
|
44130
|
+
|
|
44131
|
+
attributeResult.vertexColorSpace = taskConfig.vertexColorSpace;
|
|
44132
|
+
|
|
44133
|
+
}
|
|
44134
|
+
|
|
44135
|
+
geometry.attributes.push( attributeResult );
|
|
44136
|
+
|
|
44137
|
+
}
|
|
44138
|
+
|
|
44139
|
+
// Add index.
|
|
44140
|
+
if ( geometryType === draco.TRIANGULAR_MESH ) {
|
|
44141
|
+
|
|
44142
|
+
geometry.index = decodeIndex( draco, decoder, dracoGeometry );
|
|
44143
|
+
|
|
44144
|
+
}
|
|
44145
|
+
|
|
44146
|
+
draco.destroy( dracoGeometry );
|
|
44147
|
+
|
|
44148
|
+
return geometry;
|
|
44149
|
+
|
|
44150
|
+
}
|
|
44151
|
+
|
|
44152
|
+
function decodeIndex( draco, decoder, dracoGeometry ) {
|
|
44153
|
+
|
|
44154
|
+
const numFaces = dracoGeometry.num_faces();
|
|
44155
|
+
const numIndices = numFaces * 3;
|
|
44156
|
+
const byteLength = numIndices * 4;
|
|
44157
|
+
|
|
44158
|
+
const ptr = draco._malloc( byteLength );
|
|
44159
|
+
decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr );
|
|
44160
|
+
const index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
|
|
44161
|
+
draco._free( ptr );
|
|
44162
|
+
|
|
44163
|
+
return { array: index, itemSize: 1 };
|
|
44164
|
+
|
|
44165
|
+
}
|
|
44166
|
+
|
|
44167
|
+
function decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute ) {
|
|
44168
|
+
|
|
44169
|
+
const numComponents = attribute.num_components();
|
|
44170
|
+
const numPoints = dracoGeometry.num_points();
|
|
44171
|
+
const numValues = numPoints * numComponents;
|
|
44172
|
+
const byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
|
|
44173
|
+
const dataType = getDracoDataType( draco, attributeType );
|
|
44174
|
+
|
|
44175
|
+
const ptr = draco._malloc( byteLength );
|
|
44176
|
+
decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dataType, byteLength, ptr );
|
|
44177
|
+
const array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice();
|
|
44178
|
+
draco._free( ptr );
|
|
44179
|
+
|
|
44180
|
+
return {
|
|
44181
|
+
name: attributeName,
|
|
44182
|
+
array: array,
|
|
44183
|
+
itemSize: numComponents
|
|
44184
|
+
};
|
|
44185
|
+
|
|
44186
|
+
}
|
|
44187
|
+
|
|
44188
|
+
function getDracoDataType( draco, attributeType ) {
|
|
44189
|
+
|
|
44190
|
+
switch ( attributeType ) {
|
|
44191
|
+
|
|
44192
|
+
case Float32Array: return draco.DT_FLOAT32;
|
|
44193
|
+
case Int8Array: return draco.DT_INT8;
|
|
44194
|
+
case Int16Array: return draco.DT_INT16;
|
|
44195
|
+
case Int32Array: return draco.DT_INT32;
|
|
44196
|
+
case Uint8Array: return draco.DT_UINT8;
|
|
44197
|
+
case Uint16Array: return draco.DT_UINT16;
|
|
44198
|
+
case Uint32Array: return draco.DT_UINT32;
|
|
44199
|
+
|
|
44200
|
+
}
|
|
44201
|
+
|
|
44202
|
+
}
|
|
44203
|
+
|
|
44204
|
+
}
|
|
44205
|
+
|
|
43603
44206
|
class AudioListener {
|
|
43604
44207
|
constructor() {
|
|
43605
44208
|
this.mediaRecorder = null;
|
|
@@ -44181,6 +44784,10 @@ class Character {
|
|
|
44181
44784
|
}
|
|
44182
44785
|
console.log("loading model", this.modelUrl);
|
|
44183
44786
|
const loader = new GLTFLoader();
|
|
44787
|
+
const dracoLoader = new DRACOLoader();
|
|
44788
|
+
dracoLoader.setDecoderPath('https://threejs.org/examples/jsm/libs/draco/');
|
|
44789
|
+
console.log('draco loader working');
|
|
44790
|
+
loader.setDRACOLoader(dracoLoader);
|
|
44184
44791
|
let gltf = await loader.loadAsync(this.modelUrl, this.onModelLoadProgress, this.onModelLoadError);
|
|
44185
44792
|
if(gltf)console.log("gltf loaded",gltf);
|
|
44186
44793
|
this.model = gltf.scene;
|