* copy with structuredClone when available * copy userData on BufferGeometry, Material and Texture * add deepClone function
@@ -8,7 +8,7 @@ import { Object3D } from './Object3D.js';
import { Matrix4 } from '../math/Matrix4.js';
import { Matrix3 } from '../math/Matrix3.js';
import * as MathUtils from '../math/MathUtils.js';
-import { arrayNeedsUint32 } from '../utils.js';
+import { arrayNeedsUint32, deepClone } from '../utils.js';
let _id = 0;
@@ -1071,7 +1071,7 @@ class BufferGeometry extends EventDispatcher {
// user data
- this.userData = source.userData;
+ this.userData = deepClone( source.userData );
return this;
@@ -6,6 +6,7 @@ import { Euler } from '../math/Euler.js';
import { Layers } from './Layers.js';
+import { deepClone } from '../utils.js';
let _object3DId = 0;
@@ -944,7 +945,7 @@ class Object3D extends EventDispatcher {
this.frustumCulled = source.frustumCulled;
this.renderOrder = source.renderOrder;
- this.userData = JSON.parse( JSON.stringify( source.userData ) );
if ( recursive === true ) {
@@ -1,6 +1,7 @@
import { EventDispatcher } from '../core/EventDispatcher.js';
import { FrontSide, NormalBlending, LessEqualDepth, AddEquation, OneMinusSrcAlphaFactor, SrcAlphaFactor, AlwaysStencilFunc, KeepStencilOp } from '../constants.js';
let materialId = 0;
@@ -473,7 +474,7 @@ class Material extends EventDispatcher {
this.toneMapped = source.toneMapped;
@@ -14,6 +14,7 @@ import * as MathUtils from '../math/MathUtils.js';
import { Vector2 } from '../math/Vector2.js';
import { Source } from './Source.js';
let textureId = 0;
@@ -136,7 +137,7 @@ class Texture extends EventDispatcher {
this.unpackAlignment = source.unpackAlignment;
this.encoding = source.encoding;
this.needsUpdate = true;
@@ -68,4 +68,16 @@ function createElementNS( name ) {
}
-export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS };
+function deepClone( value ) {
+
+ if ( typeof structuredClone === 'function' ) {
+ return structuredClone( value );
+ }
+ return JSON.parse( JSON.stringify( value ) );
+}
+export { arrayMin, arrayMax, arrayNeedsUint32, getTypedArray, createElementNS, deepClone };