未验证 提交 9ff1484f 编写于 作者: M Michael Herzog 提交者: GitHub

Examples: Convert loaders to ES6 Part III. (#21616)

上级 072d972b
( function () {
var Rhino3dmLoader = function ( manager ) {
THREE.Loader.call( this, manager );
this.libraryPath = '';
this.libraryPending = null;
this.libraryBinary = null;
this.libraryConfig = {};
this.url = '';
this.workerLimit = 4;
this.workerPool = [];
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.workerConfig = {};
this.materials = [];
};
Rhino3dmLoader.taskCache = new WeakMap();
Rhino3dmLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
constructor: Rhino3dmLoader,
setLibraryPath: function ( path ) {
const _taskCache = new WeakMap();
class Rhino3dmLoader extends THREE.Loader {
constructor( manager ) {
super( manager );
this.libraryPath = '';
this.libraryPending = null;
this.libraryBinary = null;
this.libraryConfig = {};
this.url = '';
this.workerLimit = 4;
this.workerPool = [];
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.workerConfig = {};
this.materials = [];
}
setLibraryPath( path ) {
this.libraryPath = path;
return this;
},
setWorkerLimit: function ( workerLimit ) {
}
setWorkerLimit( workerLimit ) {
this.workerLimit = workerLimit;
return this;
},
load: function ( url, onLoad, onProgress, onError ) {
}
load( url, onLoad, onProgress, onError ) {
var loader = new THREE.FileLoader( this.manager );
const loader = new THREE.FileLoader( this.manager );
loader.setPath( this.path );
loader.setResponseType( 'arraybuffer' );
loader.setRequestHeader( this.requestHeader );
......@@ -43,9 +46,10 @@
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
// again from this thread.
if ( Rhino3dmLoader.taskCache.has( buffer ) ) {
if ( _taskCache.has( buffer ) ) {
const cachedTask = _taskCache.get( buffer );
var cachedTask = Rhino3dmLoader.taskCache.get( buffer );
return cachedTask.promise.then( onLoad ).catch( onError );
}
......@@ -54,13 +58,15 @@
}, onProgress, onError );
},
debug: function () {
}
debug() {
console.log( 'Task load: ', this.workerPool.map( worker => worker._taskLoad ) );
},
decodeObjects: function ( buffer, url ) {
}
decodeObjects( buffer, url ) {
var worker;
var taskID;
......@@ -99,19 +105,22 @@
} ); // Cache the task result.
Rhino3dmLoader.taskCache.set( buffer, {
_taskCache.set( buffer, {
url: url,
promise: objectPending
} );
return objectPending;
},
parse: function ( data, onLoad, onError ) {
}
parse( data, onLoad, onError ) {
this.decodeObjects( data, '' ).then( onLoad ).catch( onError );
},
_compareMaterials: function ( material ) {
}
_compareMaterials( material ) {
var mat = {};
mat.name = material.name;
......@@ -143,8 +152,9 @@
this.materials.push( material );
return material;
},
_createMaterial: function ( material ) {
}
_createMaterial( material ) {
if ( material === undefined ) {
......@@ -213,8 +223,9 @@
return mat;
},
_createGeometry: function ( data ) {
}
_createGeometry( data ) {
// console.log(data);
var object = new THREE.Object3D();
......@@ -342,8 +353,9 @@
object.userData[ 'materials' ] = this.materials;
return object;
},
_createObject: function ( obj, mat ) {
}
_createObject( obj, mat ) {
var loader = new THREE.BufferGeometryLoader();
var attributes = obj.attributes;
......@@ -545,8 +557,9 @@
}
},
_initLibrary: function () {
}
_initLibrary() {
if ( ! this.libraryPending ) {
......@@ -571,7 +584,7 @@
//this.libraryBinary = binaryContent;
this.libraryConfig.wasmBinary = binaryContent;
var fn = Rhino3dmLoader.Rhino3dmWorker.toString();
var fn = Rhino3dmWorker.toString();
var body = [ '/* rhino3dm.js */', jsContent, '/* worker */', fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) ) ].join( '\n' );
this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
......@@ -581,8 +594,9 @@
return this.libraryPending;
},
_getWorker: function ( taskCost ) {
}
_getWorker( taskCost ) {
return this._initLibrary().then( () => {
......@@ -638,15 +652,17 @@
} );
},
_releaseTask: function ( worker, taskID ) {
}
_releaseTask( worker, taskID ) {
worker._taskLoad -= worker._taskCosts[ taskID ];
delete worker._callbacks[ taskID ];
delete worker._taskCosts[ taskID ];
},
dispose: function () {
}
dispose() {
for ( var i = 0; i < this.workerPool.length; ++ i ) {
......@@ -658,10 +674,12 @@
return this;
}
} );
}
/* WEB WORKER */
Rhino3dmLoader.Rhino3dmWorker = function () {
function Rhino3dmWorker() {
var libraryPending;
var libraryConfig;
......@@ -1257,7 +1275,7 @@
}
};
}
THREE.Rhino3dmLoader = Rhino3dmLoader;
......
( function () {
var DRACOLoader = function ( manager ) {
THREE.Loader.call( this, manager );
this.decoderPath = '';
this.decoderConfig = {};
this.decoderBinary = null;
this.decoderPending = null;
this.workerLimit = 4;
this.workerPool = [];
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.defaultAttributeIDs = {
position: 'POSITION',
normal: 'NORMAL',
color: 'COLOR',
uv: 'TEX_COORD'
};
this.defaultAttributeTypes = {
position: 'Float32Array',
normal: 'Float32Array',
color: 'Float32Array',
uv: 'Float32Array'
};
const _taskCache = new WeakMap();
class DRACOLoader extends THREE.Loader {
constructor( manager ) {
super( manager );
this.decoderPath = '';
this.decoderConfig = {};
this.decoderBinary = null;
this.decoderPending = null;
this.workerLimit = 4;
this.workerPool = [];
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.defaultAttributeIDs = {
position: 'POSITION',
normal: 'NORMAL',
color: 'COLOR',
uv: 'TEX_COORD'
};
this.defaultAttributeTypes = {
position: 'Float32Array',
normal: 'Float32Array',
color: 'Float32Array',
uv: 'Float32Array'
};
};
}
DRACOLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
constructor: DRACOLoader,
setDecoderPath: function ( path ) {
setDecoderPath( path ) {
this.decoderPath = path;
return this;
},
setDecoderConfig: function ( config ) {
}
setDecoderConfig( config ) {
this.decoderConfig = config;
return this;
},
setWorkerLimit: function ( workerLimit ) {
}
setWorkerLimit( workerLimit ) {
this.workerLimit = workerLimit;
return this;
},
/** @deprecated */
setVerbosity: function () {
console.warn( 'THREE.DRACOLoader: The .setVerbosity() method has been removed.' );
},
/** @deprecated */
setDrawMode: function () {
console.warn( 'THREE.DRACOLoader: The .setDrawMode() method has been removed.' );
},
/** @deprecated */
setSkipDequantization: function () {
console.warn( 'THREE.DRACOLoader: The .setSkipDequantization() method has been removed.' );
}
},
load: function ( url, onLoad, onProgress, onError ) {
load( url, onLoad, onProgress, onError ) {
var loader = new THREE.FileLoader( this.manager );
const loader = new THREE.FileLoader( this.manager );
loader.setPath( this.path );
loader.setResponseType( 'arraybuffer' );
loader.setRequestHeader( this.requestHeader );
loader.setWithCredentials( this.withCredentials );
loader.load( url, buffer => {
var taskConfig = {
const taskConfig = {
attributeIDs: this.defaultAttributeIDs,
attributeTypes: this.defaultAttributeTypes,
useUniqueIDs: false
......@@ -85,27 +69,29 @@
}, onProgress, onError );
},
}
/** @deprecated Kept for backward-compatibility with previous DRACOLoader versions. */
decodeDracoFile: function ( buffer, callback, attributeIDs, attributeTypes ) {
var taskConfig = {
decodeDracoFile( buffer, callback, attributeIDs, attributeTypes ) {
const taskConfig = {
attributeIDs: attributeIDs || this.defaultAttributeIDs,
attributeTypes: attributeTypes || this.defaultAttributeTypes,
useUniqueIDs: !! attributeIDs
};
this.decodeGeometry( buffer, taskConfig ).then( callback );
},
decodeGeometry: function ( buffer, taskConfig ) {
}
decodeGeometry( buffer, taskConfig ) {
// TODO: For backward-compatibility, support 'attributeTypes' objects containing
// references (rather than names) to typed array constructors. These must be
// serialized before sending them to the worker.
for ( var attribute in taskConfig.attributeTypes ) {
for ( const attribute in taskConfig.attributeTypes ) {
var type = taskConfig.attributeTypes[ attribute ];
const type = taskConfig.attributeTypes[ attribute ];
if ( type.BYTES_PER_ELEMENT !== undefined ) {
......@@ -116,12 +102,12 @@
} //
var taskKey = JSON.stringify( taskConfig ); // Check for an existing task using this buffer. A transferred buffer cannot be transferred
const taskKey = JSON.stringify( taskConfig ); // Check for an existing task using this buffer. A transferred buffer cannot be transferred
// again from this thread.
if ( DRACOLoader.taskCache.has( buffer ) ) {
if ( _taskCache.has( buffer ) ) {
var cachedTask = DRACOLoader.taskCache.get( buffer );
const cachedTask = _taskCache.get( buffer );
if ( cachedTask.key === taskKey ) {
......@@ -140,12 +126,12 @@
} //
var worker;
var taskID = this.workerNextTaskID ++;
var taskCost = buffer.byteLength; // Obtain a worker and assign a task, and construct a geometry instance
let worker;
const taskID = this.workerNextTaskID ++;
const taskCost = buffer.byteLength; // Obtain a worker and assign a task, and construct a geometry instance
// when the task completes.
var geometryPending = this._getWorker( taskID, taskCost ).then( _worker => {
const geometryPending = this._getWorker( taskID, taskCost ).then( _worker => {
worker = _worker;
return new Promise( ( resolve, reject ) => {
......@@ -177,16 +163,18 @@
} ); // Cache the task result.
DRACOLoader.taskCache.set( buffer, {
_taskCache.set( buffer, {
key: taskKey,
promise: geometryPending
} );
return geometryPending;
},
_createGeometry: function ( geometryData ) {
}
_createGeometry( geometryData ) {
var geometry = new THREE.BufferGeometry();
const geometry = new THREE.BufferGeometry();
if ( geometryData.index ) {
......@@ -194,22 +182,23 @@
}
for ( var i = 0; i < geometryData.attributes.length; i ++ ) {
for ( let i = 0; i < geometryData.attributes.length; i ++ ) {
var attribute = geometryData.attributes[ i ];
var name = attribute.name;
var array = attribute.array;
var itemSize = attribute.itemSize;
const attribute = geometryData.attributes[ i ];
const name = attribute.name;
const array = attribute.array;
const itemSize = attribute.itemSize;
geometry.setAttribute( name, new THREE.BufferAttribute( array, itemSize ) );
}
return geometry;
},
_loadLibrary: function ( url, responseType ) {
}
_loadLibrary( url, responseType ) {
var loader = new THREE.FileLoader( this.manager );
const loader = new THREE.FileLoader( this.manager );
loader.setPath( this.decoderPath );
loader.setResponseType( responseType );
loader.setWithCredentials( this.withCredentials );
......@@ -219,19 +208,21 @@
} );
},
preload: function () {
}
preload() {
this._initDecoder();
return this;
},
_initDecoder: function () {
}
_initDecoder() {
if ( this.decoderPending ) return this.decoderPending;
var useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
var librariesPending = [];
const useJS = typeof WebAssembly !== 'object' || this.decoderConfig.type === 'js';
const librariesPending = [];
if ( useJS ) {
......@@ -246,7 +237,7 @@
this.decoderPending = Promise.all( librariesPending ).then( libraries => {
var jsContent = libraries[ 0 ];
const jsContent = libraries[ 0 ];
if ( ! useJS ) {
......@@ -254,21 +245,22 @@
}
var fn = DRACOLoader.DRACOWorker.toString();
var body = [ '/* draco decoder */', jsContent, '', '/* worker */', fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) ) ].join( '\n' );
const fn = DRACOWorker.toString();
const body = [ '/* draco decoder */', jsContent, '', '/* worker */', fn.substring( fn.indexOf( '{' ) + 1, fn.lastIndexOf( '}' ) ) ].join( '\n' );
this.workerSourceURL = URL.createObjectURL( new Blob( [ body ] ) );
} );
return this.decoderPending;
},
_getWorker: function ( taskID, taskCost ) {
}
_getWorker( taskID, taskCost ) {
return this._initDecoder().then( () => {
if ( this.workerPool.length < this.workerLimit ) {
var worker = new Worker( this.workerSourceURL );
const worker = new Worker( this.workerSourceURL );
worker._callbacks = {};
worker._taskCosts = {};
worker._taskLoad = 0;
......@@ -279,7 +271,7 @@
worker.onmessage = function ( e ) {
var message = e.data;
const message = e.data;
switch ( message.type ) {
......@@ -312,29 +304,32 @@
}
var worker = this.workerPool[ this.workerPool.length - 1 ];
const worker = this.workerPool[ this.workerPool.length - 1 ];
worker._taskCosts[ taskID ] = taskCost;
worker._taskLoad += taskCost;
return worker;
} );
},
_releaseTask: function ( worker, taskID ) {
}
_releaseTask( worker, taskID ) {
worker._taskLoad -= worker._taskCosts[ taskID ];
delete worker._callbacks[ taskID ];
delete worker._taskCosts[ taskID ];
},
debug: function () {
}
debug() {
console.log( 'Task load: ', this.workerPool.map( worker => worker._taskLoad ) );
},
dispose: function () {
}
dispose() {
for ( var i = 0; i < this.workerPool.length; ++ i ) {
for ( let i = 0; i < this.workerPool.length; ++ i ) {
this.workerPool[ i ].terminate();
......@@ -344,17 +339,19 @@
return this;
}
} );
}
/* WEB WORKER */
DRACOLoader.DRACOWorker = function () {
var decoderConfig;
var decoderPending;
function DRACOWorker() {
let decoderConfig;
let decoderPending;
onmessage = function ( e ) {
var message = e.data;
const message = e.data;
switch ( message.type ) {
......@@ -379,19 +376,19 @@
break;
case 'decode':
var buffer = message.buffer;
var taskConfig = message.taskConfig;
const buffer = message.buffer;
const taskConfig = message.taskConfig;
decoderPending.then( module => {
var draco = module.draco;
var decoder = new draco.Decoder();
var decoderBuffer = new draco.DecoderBuffer();
const draco = module.draco;
const decoder = new draco.Decoder();
const decoderBuffer = new draco.DecoderBuffer();
decoderBuffer.Init( new Int8Array( buffer ), buffer.byteLength );
try {
var geometry = decodeGeometry( draco, decoder, decoderBuffer, taskConfig );
var buffers = geometry.attributes.map( attr => attr.array.buffer );
const geometry = decodeGeometry( draco, decoder, decoderBuffer, taskConfig );
const buffers = geometry.attributes.map( attr => attr.array.buffer );
if ( geometry.index ) buffers.push( geometry.index.array.buffer );
self.postMessage( {
type: 'decode',
......@@ -424,11 +421,11 @@
function decodeGeometry( draco, decoder, decoderBuffer, taskConfig ) {
var attributeIDs = taskConfig.attributeIDs;
var attributeTypes = taskConfig.attributeTypes;
var dracoGeometry;
var decodingStatus;
var geometryType = decoder.GetEncodedGeometryType( decoderBuffer );
const attributeIDs = taskConfig.attributeIDs;
const attributeTypes = taskConfig.attributeTypes;
let dracoGeometry;
let decodingStatus;
const geometryType = decoder.GetEncodedGeometryType( decoderBuffer );
if ( geometryType === draco.TRIANGULAR_MESH ) {
......@@ -452,16 +449,16 @@
}
var geometry = {
const geometry = {
index: null,
attributes: []
}; // Gather all vertex attributes.
for ( var attributeName in attributeIDs ) {
for ( const attributeName in attributeIDs ) {
var attributeType = self[ attributeTypes[ attributeName ] ];
var attribute;
var attributeID; // A Draco file may be created with default vertex attributes, whose attribute IDs
const attributeType = self[ attributeTypes[ attributeName ] ];
let attribute;
let attributeID; // A Draco file may be created with default vertex attributes, whose attribute IDs
// are mapped 1:1 from their semantic name (POSITION, NORMAL, ...). Alternatively,
// a Draco file may contain a custom set of attributes, identified by known unique
// IDs. glTF files always do the latter, and `.drc` files typically do the former.
......@@ -497,14 +494,14 @@
function decodeIndex( draco, decoder, dracoGeometry ) {
var numFaces = dracoGeometry.num_faces();
var numIndices = numFaces * 3;
var byteLength = numIndices * 4;
const numFaces = dracoGeometry.num_faces();
const numIndices = numFaces * 3;
const byteLength = numIndices * 4;
var ptr = draco._malloc( byteLength );
const ptr = draco._malloc( byteLength );
decoder.GetTrianglesUInt32Array( dracoGeometry, byteLength, ptr );
var index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
const index = new Uint32Array( draco.HEAPF32.buffer, ptr, numIndices ).slice();
draco._free( ptr );
......@@ -517,16 +514,16 @@
function decodeAttribute( draco, decoder, dracoGeometry, attributeName, attributeType, attribute ) {
var numComponents = attribute.num_components();
var numPoints = dracoGeometry.num_points();
var numValues = numPoints * numComponents;
var byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
var dataType = getDracoDataType( draco, attributeType );
const numComponents = attribute.num_components();
const numPoints = dracoGeometry.num_points();
const numValues = numPoints * numComponents;
const byteLength = numValues * attributeType.BYTES_PER_ELEMENT;
const dataType = getDracoDataType( draco, attributeType );
var ptr = draco._malloc( byteLength );
const ptr = draco._malloc( byteLength );
decoder.GetAttributeDataArrayForAllPoints( dracoGeometry, attribute, dataType, byteLength, ptr );
var array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice();
const array = new attributeType( draco.HEAPF32.buffer, ptr, numValues ).slice();
draco._free( ptr );
......@@ -567,42 +564,7 @@
}
};
DRACOLoader.taskCache = new WeakMap();
/** Deprecated static methods */
/** @deprecated */
DRACOLoader.setDecoderPath = function () {
console.warn( 'THREE.DRACOLoader: The .setDecoderPath() method has been removed. Use instance methods.' );
};
/** @deprecated */
DRACOLoader.setDecoderConfig = function () {
console.warn( 'THREE.DRACOLoader: The .setDecoderConfig() method has been removed. Use instance methods.' );
};
/** @deprecated */
DRACOLoader.releaseDecoderModule = function () {
console.warn( 'THREE.DRACOLoader: The .releaseDecoderModule() method has been removed. Use instance methods.' );
};
/** @deprecated */
DRACOLoader.getDecoderModule = function () {
console.warn( 'THREE.DRACOLoader: The .getDecoderModule() method has been removed. Use instance methods.' );
};
}
THREE.DRACOLoader = DRACOLoader;
......
......@@ -67,16 +67,16 @@
// ///////////////////////////////////////////////////////////////////////////
// // End of OpenEXR license -------------------------------------------------
var EXRLoader = function ( manager ) {
class EXRLoader extends THREE.DataTextureLoader {
THREE.DataTextureLoader.call( this, manager );
this.type = THREE.FloatType;
constructor( manager ) {
};
super( manager );
this.type = THREE.FloatType;
EXRLoader.prototype = Object.assign( Object.create( THREE.DataTextureLoader.prototype ), {
constructor: EXRLoader,
parse: function ( buffer ) {
}
parse( buffer ) {
const USHORT_RANGE = 1 << 16;
const BITMAP_SIZE = USHORT_RANGE >> 3;
......@@ -2155,14 +2155,16 @@
type: this.type
};
},
setDataType: function ( value ) {
}
setDataType( value ) {
this.type = value;
return this;
},
load: function ( url, onLoad, onProgress, onError ) {
}
load( url, onLoad, onProgress, onError ) {
function onLoadCallback( texture, texData ) {
......@@ -2191,10 +2193,11 @@
}
return THREE.DataTextureLoader.prototype.load.call( this, url, onLoadCallback, onProgress, onError );
return super.load( url, onLoadCallback, onProgress, onError );
}
} );
}
THREE.EXRLoader = EXRLoader;
......
此差异已折叠。
......@@ -9,19 +9,19 @@
* @param {Manager} manager Loading manager.
*/
var GCodeLoader = function ( manager ) {
class GCodeLoader extends THREE.Loader {
THREE.Loader.call( this, manager );
this.splitLayer = false;
constructor( manager ) {
};
super( manager );
this.splitLayer = false;
GCodeLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
constructor: GCodeLoader,
load: function ( url, onLoad, onProgress, onError ) {
}
load( url, onLoad, onProgress, onError ) {
var scope = this;
var loader = new THREE.FileLoader( scope.manager );
const scope = this;
const loader = new THREE.FileLoader( scope.manager );
loader.setPath( scope.path );
loader.setRequestHeader( scope.requestHeader );
loader.setWithCredentials( scope.withCredentials );
......@@ -49,8 +49,9 @@
}, onProgress, onError );
},
parse: function ( data ) {
}
parse( data ) {
var state = {
x: 0,
......@@ -248,7 +249,8 @@
return object;
}
} );
}
THREE.GCodeLoader = GCodeLoader;
......
此差异已折叠。
此差异已折叠。
( function () {
var NRRDLoader = function ( manager ) {
class NRRDLoader extends THREE.Loader {
THREE.Loader.call( this, manager );
constructor( manager ) {
};
super( manager );
}
NRRDLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
constructor: NRRDLoader,
load: function ( url, onLoad, onProgress, onError ) {
load( url, onLoad, onProgress, onError ) {
var scope = this;
var loader = new THREE.FileLoader( scope.manager );
const scope = this;
const loader = new THREE.FileLoader( scope.manager );
loader.setPath( scope.path );
loader.setResponseType( 'arraybuffer' );
loader.setRequestHeader( scope.requestHeader );
......@@ -40,17 +40,18 @@
}, onProgress, onError );
},
parse: function ( data ) {
}
parse( data ) {
// this parser is largely inspired from the XTK NRRD parser : https://github.com/xtk/X
var _data = data;
var _dataPointer = 0;
let _data = data;
let _dataPointer = 0;
var _nativeLittleEndian = new Int8Array( new Int16Array( [ 1 ] ).buffer )[ 0 ] > 0;
const _nativeLittleEndian = new Int8Array( new Int16Array( [ 1 ] ).buffer )[ 0 ] > 0;
var _littleEndian = true;
var headerObject = {};
const _littleEndian = true;
const headerObject = {};
function scan( type, chunks ) {
......@@ -60,8 +61,8 @@
}
var _chunkSize = 1;
var _array_type = Uint8Array;
let _chunkSize = 1;
let _array_type = Uint8Array;
switch ( type ) {
......@@ -113,7 +114,7 @@
} // increase the data pointer in-place
var _bytes = new _array_type( _data.slice( _dataPointer, _dataPointer += chunks * _chunkSize ) ); // if required, flip the endianness of the bytes
let _bytes = new _array_type( _data.slice( _dataPointer, _dataPointer += chunks * _chunkSize ) ); // if required, flip the endianness of the bytes
if ( _nativeLittleEndian != _littleEndian ) {
......@@ -138,13 +139,13 @@
function flipEndianness( array, chunkSize ) {
var u8 = new Uint8Array( array.buffer, array.byteOffset, array.byteLength );
const u8 = new Uint8Array( array.buffer, array.byteOffset, array.byteLength );
for ( var i = 0; i < array.byteLength; i += chunkSize ) {
for ( let i = 0; i < array.byteLength; i += chunkSize ) {
for ( var j = i + chunkSize - 1, k = i; j > k; j --, k ++ ) {
for ( let j = i + chunkSize - 1, k = i; j > k; j --, k ++ ) {
var tmp = u8[ k ];
const tmp = u8[ k ];
u8[ k ] = u8[ j ];
u8[ j ] = tmp;
......@@ -159,9 +160,9 @@
function parseHeader( header ) {
var data, field, fn, i, l, lines, m, _i, _len;
let data, field, fn, i, l, m, _i, _len;
lines = header.split( /\r?\n/ );
const lines = header.split( /\r?\n/ );
for ( _i = 0, _len = lines.length; _i < _len; _i ++ ) {
......@@ -175,7 +176,7 @@
field = m[ 1 ].trim();
data = m[ 2 ].trim();
fn = NRRDLoader.prototype.fieldFunctions[ field ];
fn = _fieldFunctions[ field ];
if ( fn ) {
......@@ -229,17 +230,17 @@
function parseDataAsText( data, start, end ) {
var number = '';
let number = '';
start = start || 0;
end = end || data.length;
var value; //length of the result is the product of the sizes
let value; //length of the result is the product of the sizes
var lengthOfTheResult = headerObject.sizes.reduce( function ( previous, current ) {
const lengthOfTheResult = headerObject.sizes.reduce( function ( previous, current ) {
return previous * current;
}, 1 );
var base = 10;
let base = 10;
if ( headerObject.encoding === 'hex' ) {
......@@ -247,9 +248,9 @@
}
var result = new headerObject.__array( lengthOfTheResult );
var resultIndex = 0;
var parsingFunction = parseInt;
const result = new headerObject.__array( lengthOfTheResult );
let resultIndex = 0;
let parsingFunction = parseInt;
if ( headerObject.__array === Float32Array || headerObject.__array === Float64Array ) {
......@@ -257,7 +258,7 @@
}
for ( var i = start; i < end; i ++ ) {
for ( let i = start; i < end; i ++ ) {
value = data[ i ]; //if value is not a space
......@@ -291,12 +292,12 @@
}
var _bytes = scan( 'uchar', data.byteLength );
const _bytes = scan( 'uchar', data.byteLength );
var _length = _bytes.length;
var _header = null;
var _data_start = 0;
var i;
const _length = _bytes.length;
let _header = null;
let _data_start = 0;
let i;
for ( i = 1; i < _length; i ++ ) {
......@@ -315,9 +316,7 @@
parseHeader( _header );
var _data = _bytes.subarray( _data_start ); // the data without header
_data = _bytes.subarray( _data_start ); // the data without header
if ( headerObject.encoding.substring( 0, 2 ) === 'gz' ) {
......@@ -332,9 +331,9 @@
} else if ( headerObject.encoding === 'raw' ) {
//we need to copy the array to create a new array buffer, else we retrieve the original arraybuffer with the header
var _copy = new Uint8Array( _data.length );
const _copy = new Uint8Array( _data.length );
for ( var i = 0; i < _data.length; i ++ ) {
for ( let i = 0; i < _data.length; i ++ ) {
_copy[ i ] = _data[ i ];
......@@ -346,16 +345,16 @@
_data = _data.buffer;
var volume = new THREE.Volume();
const volume = new THREE.Volume();
volume.header = headerObject; //
// parse the (unzipped) data to a datastream of the correct type
//
volume.data = new headerObject.__array( _data ); // get the min and max intensities
var min_max = volume.computeMinMax();
var min = min_max[ 0 ];
var max = min_max[ 1 ]; // attach the scalar range to the volume
const min_max = volume.computeMinMax();
const min = min_max[ 0 ];
const max = min_max[ 1 ]; // attach the scalar range to the volume
volume.windowLow = min;
volume.windowHigh = max; // get the image dimensions
......@@ -365,15 +364,15 @@
volume.yLength = volume.dimensions[ 1 ];
volume.zLength = volume.dimensions[ 2 ]; // spacing
var spacingX = new THREE.Vector3( headerObject.vectors[ 0 ][ 0 ], headerObject.vectors[ 0 ][ 1 ], headerObject.vectors[ 0 ][ 2 ] ).length();
var spacingY = new THREE.Vector3( headerObject.vectors[ 1 ][ 0 ], headerObject.vectors[ 1 ][ 1 ], headerObject.vectors[ 1 ][ 2 ] ).length();
var spacingZ = new THREE.Vector3( headerObject.vectors[ 2 ][ 0 ], headerObject.vectors[ 2 ][ 1 ], headerObject.vectors[ 2 ][ 2 ] ).length();
const spacingX = new THREE.Vector3( headerObject.vectors[ 0 ][ 0 ], headerObject.vectors[ 0 ][ 1 ], headerObject.vectors[ 0 ][ 2 ] ).length();
const spacingY = new THREE.Vector3( headerObject.vectors[ 1 ][ 0 ], headerObject.vectors[ 1 ][ 1 ], headerObject.vectors[ 1 ][ 2 ] ).length();
const spacingZ = new THREE.Vector3( headerObject.vectors[ 2 ][ 0 ], headerObject.vectors[ 2 ][ 1 ], headerObject.vectors[ 2 ][ 2 ] ).length();
volume.spacing = [ spacingX, spacingY, spacingZ ]; // Create IJKtoRAS matrix
volume.matrix = new THREE.Matrix4();
var _spaceX = 1;
var _spaceY = 1;
var _spaceZ = 1;
let _spaceX = 1;
let _spaceY = 1;
const _spaceZ = 1;
if ( headerObject.space == 'left-posterior-superior' ) {
......@@ -392,7 +391,7 @@
} else {
var v = headerObject.vectors;
const v = headerObject.vectors;
volume.matrix.set( _spaceX * v[ 0 ][ 0 ], _spaceX * v[ 1 ][ 0 ], _spaceX * v[ 2 ][ 0 ], 0, _spaceY * v[ 0 ][ 1 ], _spaceY * v[ 1 ][ 1 ], _spaceY * v[ 2 ][ 1 ], 0, _spaceZ * v[ 0 ][ 2 ], _spaceZ * v[ 1 ][ 2 ], _spaceZ * v[ 2 ][ 2 ], 0, 0, 0, 0, 1 );
}
......@@ -416,8 +415,9 @@
return volume;
},
parseChars: function ( array, start, end ) {
}
parseChars( array, start, end ) {
// without borders, use the whole array
if ( start === undefined ) {
......@@ -432,9 +432,9 @@
}
var output = ''; // create and append the chars
let output = ''; // create and append the chars
var i = 0;
let i = 0;
for ( i = start; i < end; ++ i ) {
......@@ -444,185 +444,181 @@
return output;
},
fieldFunctions: {
type: function ( data ) {
}
switch ( data ) {
}
case 'uchar':
case 'unsigned char':
case 'uint8':
case 'uint8_t':
this.__array = Uint8Array;
break;
const _fieldFunctions = {
type: function ( data ) {
case 'signed char':
case 'int8':
case 'int8_t':
this.__array = Int8Array;
break;
switch ( data ) {
case 'short':
case 'short int':
case 'signed short':
case 'signed short int':
case 'int16':
case 'int16_t':
this.__array = Int16Array;
break;
case 'uchar':
case 'unsigned char':
case 'uint8':
case 'uint8_t':
this.__array = Uint8Array;
break;
case 'ushort':
case 'unsigned short':
case 'unsigned short int':
case 'uint16':
case 'uint16_t':
this.__array = Uint16Array;
break;
case 'signed char':
case 'int8':
case 'int8_t':
this.__array = Int8Array;
break;
case 'int':
case 'signed int':
case 'int32':
case 'int32_t':
this.__array = Int32Array;
break;
case 'short':
case 'short int':
case 'signed short':
case 'signed short int':
case 'int16':
case 'int16_t':
this.__array = Int16Array;
break;
case 'uint':
case 'unsigned int':
case 'uint32':
case 'uint32_t':
this.__array = Uint32Array;
break;
case 'ushort':
case 'unsigned short':
case 'unsigned short int':
case 'uint16':
case 'uint16_t':
this.__array = Uint16Array;
break;
case 'float':
this.__array = Float32Array;
break;
case 'int':
case 'signed int':
case 'int32':
case 'int32_t':
this.__array = Int32Array;
break;
case 'double':
this.__array = Float64Array;
break;
case 'uint':
case 'unsigned int':
case 'uint32':
case 'uint32_t':
this.__array = Uint32Array;
break;
default:
throw new Error( 'Unsupported NRRD data type: ' + data );
case 'float':
this.__array = Float32Array;
break;
}
case 'double':
this.__array = Float64Array;
break;
return this.type = data;
default:
throw new Error( 'Unsupported NRRD data type: ' + data );
},
endian: function ( data ) {
}
return this.endian = data;
return this.type = data;
},
encoding: function ( data ) {
},
endian: function ( data ) {
return this.encoding = data;
return this.endian = data;
},
dimension: function ( data ) {
},
encoding: function ( data ) {
return this.dim = parseInt( data, 10 );
return this.encoding = data;
},
sizes: function ( data ) {
},
dimension: function ( data ) {
var i;
return this.sizes = function () {
return this.dim = parseInt( data, 10 );
var _i, _len, _ref, _results;
},
sizes: function ( data ) {
_ref = data.split( /\s+/ );
_results = [];
let i;
return this.sizes = function () {
for ( _i = 0, _len = _ref.length; _i < _len; _i ++ ) {
const _ref = data.split( /\s+/ );
i = _ref[ _i ];
const _results = [];
_results.push( parseInt( i, 10 ) );
for ( let _i = 0, _len = _ref.length; _i < _len; _i ++ ) {
}
i = _ref[ _i ];
return _results;
_results.push( parseInt( i, 10 ) );
}();
}
},
space: function ( data ) {
return _results;
return this.space = data;
}();
},
'space origin': function ( data ) {
},
space: function ( data ) {
return this.space_origin = data.split( '(' )[ 1 ].split( ')' )[ 0 ].split( ',' );
return this.space = data;
},
'space directions': function ( data ) {
},
'space origin': function ( data ) {
var f, parts, v;
parts = data.match( /\(.*?\)/g );
return this.vectors = function () {
return this.space_origin = data.split( '(' )[ 1 ].split( ')' )[ 0 ].split( ',' );
var _i, _len, _results;
},
'space directions': function ( data ) {
_results = [];
let f, v;
const parts = data.match( /\(.*?\)/g );
return this.vectors = function () {
for ( _i = 0, _len = parts.length; _i < _len; _i ++ ) {
const _results = [];
v = parts[ _i ];
for ( let _i = 0, _len = parts.length; _i < _len; _i ++ ) {
_results.push( function () {
v = parts[ _i ];
var _j, _len2, _ref, _results2;
_results.push( function () {
_ref = v.slice( 1, - 1 ).split( /,/ );
_results2 = [];
const _ref = v.slice( 1, - 1 ).split( /,/ );
for ( _j = 0, _len2 = _ref.length; _j < _len2; _j ++ ) {
const _results2 = [];
f = _ref[ _j ];
for ( let _j = 0, _len2 = _ref.length; _j < _len2; _j ++ ) {
_results2.push( parseFloat( f ) );
f = _ref[ _j ];
}
_results2.push( parseFloat( f ) );
return _results2;
}
}() );
return _results2;
}
}() );
return _results;
}
}();
return _results;
},
spacings: function ( data ) {
}();
var f, parts;
parts = data.split( /\s+/ );
return this.spacings = function () {
},
spacings: function ( data ) {
var _i,
_len,
_results = [];
let f;
const parts = data.split( /\s+/ );
return this.spacings = function () {
for ( _i = 0, _len = parts.length; _i < _len; _i ++ ) {
const _results = [];
f = parts[ _i ];
for ( let _i = 0, _len = parts.length; _i < _len; _i ++ ) {
_results.push( parseFloat( f ) );
f = parts[ _i ];
}
_results.push( parseFloat( f ) );
}
return _results;
return _results;
}();
}();
}
}
} );
};
THREE.NRRDLoader = NRRDLoader;
......
( function () {
var VTKLoader = function ( manager ) {
class VTKLoader extends THREE.Loader {
THREE.Loader.call( this, manager );
constructor( manager ) {
};
super( manager );
VTKLoader.prototype = Object.assign( Object.create( THREE.Loader.prototype ), {
constructor: VTKLoader,
load: function ( url, onLoad, onProgress, onError ) {
}
load( url, onLoad, onProgress, onError ) {
var scope = this;
var loader = new THREE.FileLoader( scope.manager );
const scope = this;
const loader = new THREE.FileLoader( scope.manager );
loader.setPath( scope.path );
loader.setResponseType( 'arraybuffer' );
loader.setRequestHeader( scope.requestHeader );
......@@ -40,8 +40,9 @@
}, onProgress, onError );
},
parse: function ( data ) {
}
parse( data ) {
function parseASCII( data ) {
......@@ -511,7 +512,7 @@
function Float32Concat( first, second ) {
var firstLength = first.length,
const firstLength = first.length,
result = new Float32Array( firstLength + second.length );
result.set( first );
result.set( second, firstLength );
......@@ -1121,7 +1122,8 @@
}
}
} );
}
THREE.VTKLoader = VTKLoader;
......
......@@ -24,52 +24,50 @@ import {
TextureLoader
} from '../../../build/three.module.js';
var Rhino3dmLoader = function ( manager ) {
const _taskCache = new WeakMap();
Loader.call( this, manager );
class Rhino3dmLoader extends Loader {
this.libraryPath = '';
this.libraryPending = null;
this.libraryBinary = null;
this.libraryConfig = {};
constructor( manager ) {
this.url = '';
super( manager );
this.workerLimit = 4;
this.workerPool = [];
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.workerConfig = {};
this.libraryPath = '';
this.libraryPending = null;
this.libraryBinary = null;
this.libraryConfig = {};
this.materials = [];
this.url = '';
};
this.workerLimit = 4;
this.workerPool = [];
this.workerNextTaskID = 1;
this.workerSourceURL = '';
this.workerConfig = {};
Rhino3dmLoader.taskCache = new WeakMap();
this.materials = [];
Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
constructor: Rhino3dmLoader,
}
setLibraryPath: function ( path ) {
setLibraryPath( path ) {
this.libraryPath = path;
return this;
},
}
setWorkerLimit: function ( workerLimit ) {
setWorkerLimit( workerLimit ) {
this.workerLimit = workerLimit;
return this;
},
}
load: function ( url, onLoad, onProgress, onError ) {
load( url, onLoad, onProgress, onError ) {
var loader = new FileLoader( this.manager );
const loader = new FileLoader( this.manager );
loader.setPath( this.path );
loader.setResponseType( 'arraybuffer' );
......@@ -81,9 +79,9 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
// Check for an existing task using this buffer. A transferred buffer cannot be transferred
// again from this thread.
if ( Rhino3dmLoader.taskCache.has( buffer ) ) {
if ( _taskCache.has( buffer ) ) {
var cachedTask = Rhino3dmLoader.taskCache.get( buffer );
const cachedTask = _taskCache.get( buffer );
return cachedTask.promise.then( onLoad ).catch( onError );
......@@ -96,15 +94,15 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}, onProgress, onError );
},
}
debug: function () {
debug() {
console.log( 'Task load: ', this.workerPool.map( ( worker ) => worker._taskLoad ) );
},
}
decodeObjects: function ( buffer, url ) {
decodeObjects( buffer, url ) {
var worker;
var taskID;
......@@ -147,7 +145,7 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
} );
// Cache the task result.
Rhino3dmLoader.taskCache.set( buffer, {
_taskCache.set( buffer, {
url: url,
promise: objectPending
......@@ -156,17 +154,17 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
return objectPending;
},
}
parse: function ( data, onLoad, onError ) {
parse( data, onLoad, onError ) {
this.decodeObjects( data, '' )
.then( onLoad )
.catch( onError );
},
}
_compareMaterials: function ( material ) {
_compareMaterials( material ) {
var mat = {};
mat.name = material.name;
......@@ -199,9 +197,9 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
return material;
},
}
_createMaterial: function ( material ) {
_createMaterial( material ) {
if ( material === undefined ) {
......@@ -281,9 +279,9 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
return mat;
},
}
_createGeometry: function ( data ) {
_createGeometry( data ) {
// console.log(data);
......@@ -420,9 +418,9 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
object.userData[ 'materials' ] = this.materials;
return object;
},
}
_createObject: function ( obj, mat ) {
_createObject( obj, mat ) {
var loader = new BufferGeometryLoader();
......@@ -635,9 +633,9 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}
},
}
_initLibrary: function () {
_initLibrary() {
if ( ! this.libraryPending ) {
......@@ -666,7 +664,7 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
//this.libraryBinary = binaryContent;
this.libraryConfig.wasmBinary = binaryContent;
var fn = Rhino3dmLoader.Rhino3dmWorker.toString();
var fn = Rhino3dmWorker.toString();
var body = [
'/* rhino3dm.js */',
......@@ -683,9 +681,9 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
return this.libraryPending;
},
}
_getWorker: function ( taskCost ) {
_getWorker( taskCost ) {
return this._initLibrary().then( () => {
......@@ -743,17 +741,17 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
} );
},
}
_releaseTask: function ( worker, taskID ) {
_releaseTask( worker, taskID ) {
worker._taskLoad -= worker._taskCosts[ taskID ];
delete worker._callbacks[ taskID ];
delete worker._taskCosts[ taskID ];
},
}
dispose: function () {
dispose() {
for ( var i = 0; i < this.workerPool.length; ++ i ) {
......@@ -767,11 +765,11 @@ Rhino3dmLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}
} );
}
/* WEB WORKER */
Rhino3dmLoader.Rhino3dmWorker = function () {
function Rhino3dmWorker() {
var libraryPending;
var libraryConfig;
......@@ -1416,6 +1414,6 @@ Rhino3dmLoader.Rhino3dmWorker = function () {
}
};
}
export { Rhino3dmLoader };
此差异已折叠。
......@@ -87,19 +87,17 @@ import * as fflate from '../libs/fflate.module.min.js';
// // End of OpenEXR license -------------------------------------------------
var EXRLoader = function ( manager ) {
class EXRLoader extends DataTextureLoader {
DataTextureLoader.call( this, manager );
constructor( manager ) {
this.type = FloatType;
super( manager );
};
this.type = FloatType;
EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype ), {
constructor: EXRLoader,
}
parse: function ( buffer ) {
parse( buffer ) {
const USHORT_RANGE = ( 1 << 16 );
const BITMAP_SIZE = ( USHORT_RANGE >> 3 );
......@@ -2366,16 +2364,16 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
type: this.type
};
},
}
setDataType: function ( value ) {
setDataType( value ) {
this.type = value;
return this;
},
}
load: function ( url, onLoad, onProgress, onError ) {
load( url, onLoad, onProgress, onError ) {
function onLoadCallback( texture, texData ) {
......@@ -2406,10 +2404,10 @@ EXRLoader.prototype = Object.assign( Object.create( DataTextureLoader.prototype
}
return DataTextureLoader.prototype.load.call( this, url, onLoadCallback, onProgress, onError );
return super.load( url, onLoadCallback, onProgress, onError );
}
} );
}
export { EXRLoader };
此差异已折叠。
......@@ -18,23 +18,21 @@ import {
* @param {Manager} manager Loading manager.
*/
var GCodeLoader = function ( manager ) {
class GCodeLoader extends Loader {
Loader.call( this, manager );
constructor( manager ) {
this.splitLayer = false;
super( manager );
};
this.splitLayer = false;
GCodeLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
constructor: GCodeLoader,
}
load: function ( url, onLoad, onProgress, onError ) {
load( url, onLoad, onProgress, onError ) {
var scope = this;
const scope = this;
var loader = new FileLoader( scope.manager );
const loader = new FileLoader( scope.manager );
loader.setPath( scope.path );
loader.setRequestHeader( scope.requestHeader );
loader.setWithCredentials( scope.withCredentials );
......@@ -62,9 +60,9 @@ GCodeLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}, onProgress, onError );
},
}
parse: function ( data ) {
parse( data ) {
var state = { x: 0, y: 0, z: 0, e: 0, f: 0, extruding: false, relative: false };
var layers = [];
......@@ -260,6 +258,6 @@ GCodeLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}
} );
}
export { GCodeLoader };
此差异已折叠。
此差异已折叠。
此差异已折叠。
import {
DefaultLoadingManager,
Loader,
FileLoader
} from '../../../build/three.module.js';
import * as Nodes from '../nodes/Nodes.js';
var NodeMaterialLoader = function ( manager, library ) {
class NodeMaterialLoader extends Loader {
this.manager = ( manager !== undefined ) ? manager : DefaultLoadingManager;
constructor( manager, library = {} ) {
this.nodes = {};
this.materials = {};
this.passes = {};
this.names = {};
this.library = library || {};
super( manager );
};
var NodeMaterialLoaderUtils = {
replaceUUIDObject: function ( object, uuid, value, recursive ) {
recursive = recursive !== undefined ? recursive : true;
if ( typeof uuid === 'object' ) uuid = uuid.uuid;
if ( typeof object === 'object' ) {
var keys = Object.keys( object );
for ( var i = 0; i < keys.length; i ++ ) {
var key = keys[ i ];
if ( recursive ) {
object[ key ] = this.replaceUUIDObject( object[ key ], uuid, value );
}
if ( key === uuid ) {
object[ uuid ] = object[ key ];
delete object[ key ];
}
}
}
return object === uuid ? value : object;
},
replaceUUID: function ( json, uuid, value ) {
this.replaceUUIDObject( json, uuid, value, false );
this.replaceUUIDObject( json.nodes, uuid, value );
this.replaceUUIDObject( json.materials, uuid, value );
this.replaceUUIDObject( json.passes, uuid, value );
this.replaceUUIDObject( json.library, uuid, value, false );
return json;
this.nodes = {};
this.materials = {};
this.passes = {};
this.names = {};
this.library = library;
}
};
Object.assign( NodeMaterialLoader.prototype, {
load: function ( url, onLoad, onProgress, onError ) {
load( url, onLoad, onProgress, onError ) {
var scope = this;
const scope = this;
var loader = new FileLoader( scope.manager );
const loader = new FileLoader( scope.manager );
loader.setPath( scope.path );
loader.load( url, function ( text ) {
......@@ -85,22 +33,15 @@ Object.assign( NodeMaterialLoader.prototype, {
return this;
},
setPath: function ( value ) {
this.path = value;
return this;
},
}
getObjectByName: function ( uuid ) {
getObjectByName( uuid ) {
return this.names[ uuid ];
},
}
getObjectById: function ( uuid ) {
getObjectById( uuid ) {
return this.library[ uuid ] ||
this.nodes[ uuid ] ||
......@@ -108,11 +49,11 @@ Object.assign( NodeMaterialLoader.prototype, {
this.passes[ uuid ] ||
this.names[ uuid ];
},
}
getNode: function ( uuid ) {
getNode( uuid ) {
var object = this.getObjectById( uuid );
const object = this.getObjectById( uuid );
if ( ! object ) {
......@@ -122,9 +63,9 @@ Object.assign( NodeMaterialLoader.prototype, {
return object;
},
}
resolve: function ( json ) {
resolve( json ) {
switch ( typeof json ) {
......@@ -147,7 +88,7 @@ Object.assign( NodeMaterialLoader.prototype, {
if ( Array.isArray( json ) ) {
for ( var i = 0; i < json.length; i ++ ) {
for ( let i = 0; i < json.length; i ++ ) {
json[ i ] = this.resolve( json[ i ] );
......@@ -155,7 +96,7 @@ Object.assign( NodeMaterialLoader.prototype, {
} else {
for ( var prop in json ) {
for ( const prop in json ) {
if ( prop === 'uuid' ) continue;
......@@ -169,11 +110,11 @@ Object.assign( NodeMaterialLoader.prototype, {
return json;
},
}
declare: function ( json ) {
declare( json ) {
var uuid, node, object;
let uuid, node, object;
for ( uuid in json.nodes ) {
......@@ -235,11 +176,11 @@ Object.assign( NodeMaterialLoader.prototype, {
return json;
},
}
parse: function ( json ) {
parse( json ) {
var uuid;
let uuid;
json = this.resolve( this.declare( json ) );
......@@ -265,6 +206,58 @@ Object.assign( NodeMaterialLoader.prototype, {
}
} );
}
class NodeMaterialLoaderUtils {
static replaceUUIDObject( object, uuid, value, recursive ) {
recursive = recursive !== undefined ? recursive : true;
if ( typeof uuid === 'object' ) uuid = uuid.uuid;
if ( typeof object === 'object' ) {
const keys = Object.keys( object );
for ( let i = 0; i < keys.length; i ++ ) {
const key = keys[ i ];
if ( recursive ) {
object[ key ] = this.replaceUUIDObject( object[ key ], uuid, value );
}
if ( key === uuid ) {
object[ uuid ] = object[ key ];
delete object[ key ];
}
}
}
return object === uuid ? value : object;
}
static replaceUUID( json, uuid, value ) {
this.replaceUUIDObject( json, uuid, value, false );
this.replaceUUIDObject( json.nodes, uuid, value );
this.replaceUUIDObject( json.materials, uuid, value );
this.replaceUUIDObject( json.passes, uuid, value );
this.replaceUUIDObject( json.library, uuid, value, false );
return json;
}
}
export { NodeMaterialLoader, NodeMaterialLoaderUtils };
......@@ -8,21 +8,19 @@ import {
} from '../../../build/three.module.js';
import * as fflate from '../libs/fflate.module.min.js';
var VTKLoader = function ( manager ) {
class VTKLoader extends Loader {
Loader.call( this, manager );
constructor( manager ) {
};
super( manager );
VTKLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
constructor: VTKLoader,
}
load: function ( url, onLoad, onProgress, onError ) {
load( url, onLoad, onProgress, onError ) {
var scope = this;
const scope = this;
var loader = new FileLoader( scope.manager );
const loader = new FileLoader( scope.manager );
loader.setPath( scope.path );
loader.setResponseType( 'arraybuffer' );
loader.setRequestHeader( scope.requestHeader );
......@@ -51,9 +49,9 @@ VTKLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}, onProgress, onError );
},
}
parse: function ( data ) {
parse( data ) {
function parseASCII( data ) {
......@@ -553,23 +551,23 @@ VTKLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
function Float32Concat( first, second ) {
var firstLength = first.length, result = new Float32Array( firstLength + second.length );
const firstLength = first.length, result = new Float32Array( firstLength + second.length );
result.set( first );
result.set( second, firstLength );
result.set( first );
result.set( second, firstLength );
return result;
return result;
}
function Int32Concat( first, second ) {
var firstLength = first.length, result = new Int32Array( firstLength + second.length );
var firstLength = first.length, result = new Int32Array( firstLength + second.length );
result.set( first );
result.set( second, firstLength );
result.set( first );
result.set( second, firstLength );
return result;
return result;
}
......@@ -1179,6 +1177,6 @@ VTKLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
}
} );
}
export { VTKLoader };
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册