|
@@ -44,6 +44,7 @@ import { PerspectiveCamera } from '../cameras/PerspectiveCamera.js';
|
|
|
import { Scene } from '../scenes/Scene.js';
|
|
|
import { CubeTexture } from '../textures/CubeTexture.js';
|
|
|
import { Texture } from '../textures/Texture.js';
|
|
|
+import { DataTexture } from '../textures/DataTexture.js';
|
|
|
import { ImageLoader } from './ImageLoader.js';
|
|
|
import { LoadingManager } from './LoadingManager.js';
|
|
|
import { AnimationClip } from '../animation/AnimationClip.js';
|
|
@@ -552,6 +553,32 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ function deserializeImage( image ) {
|
|
|
+
|
|
|
+ if ( typeof image === 'string' ) {
|
|
|
+
|
|
|
+ var url = image;
|
|
|
+
|
|
|
+ var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( url ) ? url : scope.resourcePath + url;
|
|
|
+
|
|
|
+ return loadImage( path );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ if ( image.data ) {
|
|
|
+
|
|
|
+ return {
|
|
|
+ data: new TYPED_ARRAYS[ image.type ]( image.data ),
|
|
|
+ width: image.width,
|
|
|
+ height: image.height
|
|
|
+ };
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
if ( json !== undefined && json.length > 0 ) {
|
|
|
|
|
|
var manager = new LoadingManager( onLoad );
|
|
@@ -574,9 +601,23 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
|
|
|
|
|
|
var currentUrl = url[ j ];
|
|
|
|
|
|
- var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( currentUrl ) ? currentUrl : scope.resourcePath + currentUrl;
|
|
|
+ var deserializedImage = deserializeImage( currentUrl );
|
|
|
+
|
|
|
+ if ( deserializedImage ) {
|
|
|
+
|
|
|
+ if ( deserializedImage instanceof HTMLImageElement ) {
|
|
|
|
|
|
- images[ image.uuid ].push( loadImage( path ) );
|
|
|
+ images[ image.uuid ].push( deserializedImage );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ // special case: handle array of data textures for cube textures
|
|
|
+
|
|
|
+ images[ image.uuid ].push( new DataTexture( deserializedImage.data, deserializedImage.width, deserializedImage.height ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -584,9 +625,7 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
|
|
|
|
|
|
// load single image
|
|
|
|
|
|
- var path = /^(\/\/)|([a-z]+:(\/\/)?)/i.test( image.url ) ? image.url : scope.resourcePath + image.url;
|
|
|
-
|
|
|
- images[ image.uuid ] = loadImage( path );
|
|
|
+ images[ image.uuid ] = deserializeImage( image.url );
|
|
|
|
|
|
}
|
|
|
|
|
@@ -631,18 +670,29 @@ ObjectLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
|
|
|
}
|
|
|
|
|
|
var texture;
|
|
|
+ var 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 );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ texture = new Texture( image );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( image ) texture.needsUpdate = true; // textures can have undefined image data
|
|
|
|
|
|
- texture.needsUpdate = true;
|
|
|
+ }
|
|
|
|
|
|
texture.uuid = data.uuid;
|
|
|
|
|
@@ -999,5 +1049,17 @@ var TEXTURE_FILTER = {
|
|
|
LinearMipmapLinearFilter: LinearMipmapLinearFilter
|
|
|
};
|
|
|
|
|
|
+var 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
|
|
|
+};
|
|
|
|
|
|
export { ObjectLoader };
|