|
@@ -1552,7 +1552,17 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
|
|
|
|
|
|
for ( let i = 0, l = image.length; i < l; i ++ ) {
|
|
|
|
|
|
- url.push( ImageUtils.getDataURL( image[ i ] ) );
|
|
|
+ // check cube texture with data textures
|
|
|
+
|
|
|
+ if ( image[ i ].isDataTexture ) {
|
|
|
+
|
|
|
+ url.push( serializeImage( image[ i ].image ) );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ url.push( serializeImage( image[ i ] ) );
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1560,7 +1570,7 @@ Texture.prototype = Object.assign( Object.create( EventDispatcher.prototype ), {
|
|
|
|
|
|
// process single image
|
|
|
|
|
|
- url = ImageUtils.getDataURL( image );
|
|
|
+ url = serializeImage( image );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -1683,6 +1693,40 @@ Object.defineProperty( Texture.prototype, "needsUpdate", {
|
|
|
|
|
|
} );
|
|
|
|
|
|
+function serializeImage( image ) {
|
|
|
+
|
|
|
+ if ( ( typeof HTMLImageElement !== 'undefined' && image instanceof HTMLImageElement ) ||
|
|
|
+ ( typeof HTMLCanvasElement !== 'undefined' && image instanceof HTMLCanvasElement ) ||
|
|
|
+ ( typeof ImageBitmap !== 'undefined' && image instanceof ImageBitmap ) ) {
|
|
|
+
|
|
|
+ // default images
|
|
|
+
|
|
|
+ return ImageUtils.getDataURL( image );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if ( image.data ) {
|
|
|
+
|
|
|
+ // images of DataTexture
|
|
|
+
|
|
|
+ return {
|
|
|
+ data: Array.prototype.slice.call( image.data ),
|
|
|
+ width: image.width,
|
|
|
+ height: image.height,
|
|
|
+ type: image.data.constructor.name
|
|
|
+ };
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ console.warn( 'THREE.Texture: Unable to serialize Texture.' );
|
|
|
+ return {};
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
class Vector4 {
|
|
|
|
|
|
constructor( x = 0, y = 0, z = 0, w = 1 ) {
|
|
@@ -9694,6 +9738,25 @@ function arrayMax( array ) {
|
|
|
|
|
|
}
|
|
|
|
|
|
+const TYPED_ARRAYS = {
|
|
|
+ Int8Array: Int8Array,
|
|
|
+ Uint8Array: Uint8Array,
|
|
|
+ // Workaround for IE11 pre KB2929437. See #11440
|
|
|
+ Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
|
|
|
+ Int16Array: Int16Array,
|
|
|
+ Uint16Array: Uint16Array,
|
|
|
+ Int32Array: Int32Array,
|
|
|
+ Uint32Array: Uint32Array,
|
|
|
+ Float32Array: Float32Array,
|
|
|
+ Float64Array: Float64Array
|
|
|
+};
|
|
|
+
|
|
|
+function getTypedArray( type, buffer ) {
|
|
|
+
|
|
|
+ return new TYPED_ARRAYS[ type ]( buffer );
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
let _bufferGeometryId = 1; // BufferGeometry uses odd numbers as Id
|
|
|
|
|
|
const _m1$2 = new Matrix4();
|
|
@@ -40640,7 +40703,7 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
|
|
|
|
|
|
const buffer = getArrayBuffer( json, interleavedBuffer.buffer );
|
|
|
|
|
|
- const array = new TYPED_ARRAYS[ interleavedBuffer.type ]( buffer );
|
|
|
+ const array = getTypedArray( interleavedBuffer.type, buffer );
|
|
|
const ib = new InterleavedBuffer( array, interleavedBuffer.stride );
|
|
|
ib.uuid = interleavedBuffer.uuid;
|
|
|
|
|
@@ -40671,7 +40734,7 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
|
|
|
|
|
|
if ( index !== undefined ) {
|
|
|
|
|
|
- const typedArray = new TYPED_ARRAYS[ index.type ]( index.array );
|
|
|
+ const typedArray = getTypedArray( index.type, index.array );
|
|
|
geometry.setIndex( new BufferAttribute( typedArray, 1 ) );
|
|
|
|
|
|
}
|
|
@@ -40690,7 +40753,7 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- const typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
|
|
|
+ const typedArray = getTypedArray( attribute.type, attribute.array );
|
|
|
const bufferAttributeConstr = attribute.isInstancedBufferAttribute ? InstancedBufferAttribute : BufferAttribute;
|
|
|
bufferAttribute = new bufferAttributeConstr( typedArray, attribute.itemSize, attribute.normalized );
|
|
|
|
|
@@ -40723,7 +40786,7 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- const typedArray = new TYPED_ARRAYS[ attribute.type ]( attribute.array );
|
|
|
+ const typedArray = getTypedArray( attribute.type, attribute.array );
|
|
|
bufferAttribute = new BufferAttribute( typedArray, attribute.itemSize, attribute.normalized );
|
|
|
|
|
|
}
|
|
@@ -40786,19 +40849,6 @@ BufferGeometryLoader.prototype = Object.assign( Object.create( Loader.prototype
|
|
|
|
|
|
} );
|
|
|
|
|
|
-const TYPED_ARRAYS = {
|
|
|
- Int8Array: Int8Array,
|
|
|
- Uint8Array: Uint8Array,
|
|
|
- // Workaround for IE11 pre KB2929437. See #11440
|
|
|
- Uint8ClampedArray: typeof Uint8ClampedArray !== 'undefined' ? Uint8ClampedArray : Uint8Array,
|
|
|
- Int16Array: Int16Array,
|
|
|
- Uint16Array: Uint16Array,
|
|
|
- Int32Array: Int32Array,
|
|
|
- Uint32Array: Uint32Array,
|
|
|
- Float32Array: Float32Array,
|
|
|
- Float64Array: Float64Array
|
|
|
-};
|
|
|
-
|
|
|
class ObjectLoader extends Loader {
|
|
|
|
|
|
constructor( manager ) {
|
|
@@ -41319,6 +41369,36 @@ class ObjectLoader extends Loader {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function deserializeImage( image ) {
|
|
|
+
|
|
|
+ if ( typeof image === 'string' ) {
|
|
|
+
|
|
|
+ const url = image;
|
|
|
+
|
|
|
+ const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
|
|
|
+
|
|
|
+ return loadImage( path );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if ( image.data ) {
|
|
|
+
|
|
|
+ return {
|
|
|
+ data: getTypedArray( image.type, image.data ),
|
|
|
+ width: image.width,
|
|
|
+ height: image.height
|
|
|
+ };
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ return null;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
if ( json !== undefined && json.length > 0 ) {
|
|
|
|
|
|
const manager = new LoadingManager( onLoad );
|
|
@@ -41341,9 +41421,23 @@ class ObjectLoader extends Loader {
|
|
|
|
|
|
const currentUrl = url[ j ];
|
|
|
|
|
|
- const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
|
|
|
+ const deserializedImage = deserializeImage( currentUrl );
|
|
|
+
|
|
|
+ if ( deserializedImage !== null ) {
|
|
|
+
|
|
|
+ if ( deserializedImage instanceof HTMLImageElement ) {
|
|
|
+
|
|
|
+ images[ image.uuid ].push( deserializedImage );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // special case: handle array of data textures for cube textures
|
|
|
|
|
|
- images[ image.uuid ].push( loadImage( path ) );
|
|
|
+ images[ image.uuid ].push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -41351,9 +41445,13 @@ class ObjectLoader extends Loader {
|
|
|
|
|
|
// load single image
|
|
|
|
|
|
- const path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
|
|
|
+ const deserializedImage = deserializeImage( image.url );
|
|
|
+
|
|
|
+ if ( deserializedImage !== null ) {
|
|
|
|
|
|
- images[ image.uuid ] = loadImage( path );
|
|
|
+ images[ image.uuid ] = deserializedImage;
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -41398,18 +41496,29 @@ class ObjectLoader extends Loader {
|
|
|
}
|
|
|
|
|
|
let texture;
|
|
|
+ const image = images[ data.image ];
|
|
|
+
|
|
|
+ if ( Array.isArray( image ) ) {
|
|
|
|
|
|
- if ( Array.isArray( images[ data.image ] ) ) {
|
|
|
+ texture = new CubeTexture( image );
|
|
|
|
|
|
- texture = new CubeTexture( images[ data.image ] );
|
|
|
+ if ( image.length === 6 ) texture.needsUpdate = true;
|
|
|
|
|
|
} else {
|
|
|
|
|
|
- texture = new Texture( images[ data.image ] );
|
|
|
+ if ( image && image.data ) {
|
|
|
|
|
|
- }
|
|
|
+ texture = new DataTexture( image.data, image.width, image.height );
|
|
|
|
|
|
- texture.needsUpdate = true;
|
|
|
+ } else {
|
|
|
+
|
|
|
+ texture = new Texture( image );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( image ) texture.needsUpdate = true; // textures can have undefined image data
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
texture.uuid = data.uuid;
|
|
|
|