Skip to content
This repository was archived by the owner on Dec 12, 2022. It is now read-only.

Commit ea2865c

Browse files
committed
Do not throw when serializing CompressedTexture
1 parent b932009 commit ea2865c

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

src/content/toJSON.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
export default (() => {
22

33
const isDevtoolsSerialization = meta => !!(meta && meta.devtoolsConfig);
4+
const isObject = o => Object.prototype.toString.call(o) === '[object Object]';
45
const tempPosition = new THREE.Vector3();
56
const tempRotation = new THREE.Quaternion();
67
const tempScale = new THREE.Vector3();
@@ -44,16 +45,15 @@ return function InstrumentedToJSON (meta) {
4445

4546
let textureData;
4647
if (this.isTexture) {
47-
// If `image` is a plain object, probably from DataTexture
48-
// or a texture from a render target, hide it during serialization
49-
// so an attempt to turn it into a data URL doesn't throw.
48+
// If `image` is a plain object (via DataTexture or WebGLRenderTarget)
49+
// or an array of plain objects (via CompressedTexture) hide it during
50+
// serialization so an attempt to turn it into a data URL doesn't throw.
5051
// Patch for DataTexture.toJSON (https://github.com/mrdoob/three.js/pull/17745)
51-
if (Object.prototype.toString.call(this.image) === '[object Object]') {
52+
if (isObject(this.image) || (Array.isArray(this.image) && this.image.some(isObject))) {
5253
textureData = this.image;
5354
this.image = undefined;
5455
}
5556
}
56-
5757

5858
let children;
5959
if (this.isObject3D && !serializeChildren) {

0 commit comments

Comments
 (0)