|
@@ -48,6 +48,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';
|
|
@@ -58,6 +59,7 @@ import { Loader } from './Loader.js';
|
|
|
import { FileLoader } from './FileLoader.js';
|
|
|
import * as Geometries from '../geometries/Geometries.js';
|
|
|
import * as Curves from '../extras/curves/Curves.js';
|
|
|
+import { getTypedArray } from '../utils.js';
|
|
|
|
|
|
class ObjectLoader extends Loader {
|
|
|
|
|
@@ -579,6 +581,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 );
|
|
@@ -601,9 +633,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 ) {
|
|
|
|
|
|
- images[ image.uuid ].push( loadImage( path ) );
|
|
|
+ if ( deserializedImage instanceof HTMLImageElement ) {
|
|
|
+
|
|
|
+ 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 ) );
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -611,9 +657,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 ] = deserializedImage;
|
|
|
|
|
|
- images[ image.uuid ] = loadImage( path );
|
|
|
+ }
|
|
|
|
|
|
}
|
|
|
|
|
@@ -658,18 +708,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 );
|
|
|
+
|
|
|
+ } else {
|
|
|
+
|
|
|
+ texture = new Texture( image );
|
|
|
|
|
|
- texture.needsUpdate = true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if ( image ) texture.needsUpdate = true; // textures can have undefined image data
|
|
|
+
|
|
|
+ }
|
|
|
|
|
|
texture.uuid = data.uuid;
|
|
|
|