@galacean/engine-core 2.0.0-alpha.15 → 2.0.0-alpha.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -220,74 +220,69 @@ function _instanceof(left, right) {
220
220
  return cloneModes;
221
221
  };
222
222
  CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode, srcRoot, targetRoot, deepInstanceMap) {
223
- if (cloneMode === CloneMode.Ignore) {
223
+ var sourceProperty = source[k];
224
+ // Remappable references (Entity/Component) are always remapped, regardless of clone decorator
225
+ if (_instanceof(sourceProperty, Object) && sourceProperty._remap) {
226
+ target[k] = sourceProperty._remap(srcRoot, targetRoot);
224
227
  return;
225
228
  }
226
- var sourceProperty = source[k];
227
- if (_instanceof(sourceProperty, Object)) {
228
- if (cloneMode === undefined || cloneMode === CloneMode.Assignment) {
229
- target[k] = sourceProperty;
230
- return;
231
- }
232
- var type = sourceProperty.constructor;
233
- switch(type){
234
- case Uint8Array:
235
- case Uint16Array:
236
- case Uint32Array:
237
- case Int8Array:
238
- case Int16Array:
239
- case Int32Array:
240
- case Float32Array:
241
- case Float64Array:
242
- var targetPropertyT = target[k];
243
- if (targetPropertyT == null || targetPropertyT.length !== sourceProperty.length) {
244
- target[k] = sourceProperty.slice();
245
- } else {
246
- targetPropertyT.set(sourceProperty);
247
- }
248
- break;
249
- case Array:
250
- var targetPropertyA = target[k];
251
- var length = sourceProperty.length;
252
- if (targetPropertyA == null) {
253
- target[k] = targetPropertyA = new Array(length);
254
- } else {
255
- targetPropertyA.length = length;
256
- }
257
- for(var i = 0; i < length; i++){
258
- CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
259
- }
260
- break;
261
- default:
262
- var targetProperty = target[k];
263
- // If the target property is undefined, create new instance and keep reference sharing like the source
229
+ if (cloneMode === CloneMode.Ignore) return;
230
+ // Primitives, undecorated, or @assignmentClone: direct assign
231
+ if (!_instanceof(sourceProperty, Object) || cloneMode === undefined || cloneMode === CloneMode.Assignment) {
232
+ target[k] = sourceProperty;
233
+ return;
234
+ }
235
+ // @shallowClone / @deepClone: deep copy complex objects
236
+ var type = sourceProperty.constructor;
237
+ switch(type){
238
+ case Uint8Array:
239
+ case Uint16Array:
240
+ case Uint32Array:
241
+ case Int8Array:
242
+ case Int16Array:
243
+ case Int32Array:
244
+ case Float32Array:
245
+ case Float64Array:
246
+ var targetPropertyT = target[k];
247
+ if (targetPropertyT == null || targetPropertyT.length !== sourceProperty.length) {
248
+ target[k] = sourceProperty.slice();
249
+ } else {
250
+ targetPropertyT.set(sourceProperty);
251
+ }
252
+ break;
253
+ case Array:
254
+ var targetPropertyA = target[k];
255
+ var length = sourceProperty.length;
256
+ if (targetPropertyA == null) {
257
+ target[k] = targetPropertyA = new Array(length);
258
+ } else {
259
+ targetPropertyA.length = length;
260
+ }
261
+ for(var i = 0; i < length; i++){
262
+ CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
263
+ }
264
+ break;
265
+ default:
266
+ var targetProperty = target[k];
267
+ // If the target property is undefined, create new instance and keep reference sharing like the source
268
+ if (!targetProperty) {
269
+ targetProperty = deepInstanceMap.get(sourceProperty);
264
270
  if (!targetProperty) {
265
- targetProperty = deepInstanceMap.get(sourceProperty);
266
- if (!targetProperty) {
267
- targetProperty = new sourceProperty.constructor();
268
- deepInstanceMap.set(sourceProperty, targetProperty);
269
- }
270
- target[k] = targetProperty;
271
+ targetProperty = new sourceProperty.constructor();
272
+ deepInstanceMap.set(sourceProperty, targetProperty);
271
273
  }
272
- if (sourceProperty.copyFrom) {
273
- // Custom clone
274
- targetProperty.copyFrom(sourceProperty);
275
- } else {
276
- // Universal clone
277
- var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
278
- for(var _$k in sourceProperty){
279
- CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
280
- }
281
- // Custom incremental clone
282
- if (sourceProperty._cloneTo) {
283
- sourceProperty._cloneTo(targetProperty, srcRoot, targetRoot);
284
- }
274
+ target[k] = targetProperty;
275
+ }
276
+ if (sourceProperty.copyFrom) {
277
+ targetProperty.copyFrom(sourceProperty);
278
+ } else {
279
+ var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
280
+ for(var _$k in sourceProperty){
281
+ CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
285
282
  }
286
- break;
287
- }
288
- } else {
289
- // null, undefined, primitive type, function
290
- target[k] = sourceProperty;
283
+ sourceProperty._cloneTo == null ? void 0 : sourceProperty._cloneTo.call(sourceProperty, targetProperty, srcRoot, targetRoot);
284
+ }
285
+ break;
291
286
  }
292
287
  };
293
288
  CloneManager.deepCloneObject = function deepCloneObject(source, target, deepInstanceMap) {
@@ -7394,6 +7389,45 @@ Sky._projectionMatrix = new engineMath.Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, Sky.
7394
7389
  }();
7395
7390
  /** @internal */ Background._premultiplySolidColor = new engineMath.Color();
7396
7391
 
7392
+ /**
7393
+ * @internal
7394
+ * Utility functions for remapping Entity/Component references during cloning.
7395
+ */ var CloneUtils = /*#__PURE__*/ function() {
7396
+ function CloneUtils() {}
7397
+ CloneUtils.remapEntity = function remapEntity(srcRoot, targetRoot, entity) {
7398
+ var path = CloneUtils._tempRemapPath;
7399
+ if (!CloneUtils._getEntityHierarchyPath(srcRoot, entity, path)) return entity;
7400
+ return CloneUtils._getEntityByHierarchyPath(targetRoot, path);
7401
+ };
7402
+ CloneUtils.remapComponent = function remapComponent(srcRoot, targetRoot, component) {
7403
+ var path = CloneUtils._tempRemapPath;
7404
+ var srcEntity = component.entity;
7405
+ if (!CloneUtils._getEntityHierarchyPath(srcRoot, srcEntity, path)) return component;
7406
+ return CloneUtils._getEntityByHierarchyPath(targetRoot, path)._components[srcEntity._components.indexOf(component)];
7407
+ };
7408
+ CloneUtils._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
7409
+ inversePath.length = 0;
7410
+ while(searchEntity !== rootEntity){
7411
+ var parent = searchEntity.parent;
7412
+ if (!parent) {
7413
+ return false;
7414
+ }
7415
+ inversePath.push(searchEntity.siblingIndex);
7416
+ searchEntity = parent;
7417
+ }
7418
+ return true;
7419
+ };
7420
+ CloneUtils._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
7421
+ var entity = rootEntity;
7422
+ for(var i = inversePath.length - 1; i >= 0; i--){
7423
+ entity = entity.children[inversePath[i]];
7424
+ }
7425
+ return entity;
7426
+ };
7427
+ return CloneUtils;
7428
+ }();
7429
+ CloneUtils._tempRemapPath = [];
7430
+
7397
7431
  var ActiveChangeFlag = /*#__PURE__*/ function(ActiveChangeFlag) {
7398
7432
  ActiveChangeFlag[ActiveChangeFlag["None"] = 0] = "None";
7399
7433
  ActiveChangeFlag[ActiveChangeFlag["Scene"] = 1] = "Scene";
@@ -7469,6 +7503,11 @@ var ActiveChangeFlag = /*#__PURE__*/ function(ActiveChangeFlag) {
7469
7503
  }
7470
7504
  }
7471
7505
  };
7506
+ /**
7507
+ * @internal
7508
+ */ _proto._remap = function _remap(srcRoot, targetRoot) {
7509
+ return CloneUtils.remapComponent(srcRoot, targetRoot, this);
7510
+ };
7472
7511
  _proto._addResourceReferCount = function _addResourceReferCount(resource, count) {
7473
7512
  this._entity._isTemplate || resource._addReferCount(count);
7474
7513
  };
@@ -7542,9 +7581,6 @@ var ActiveChangeFlag = /*#__PURE__*/ function(ActiveChangeFlag) {
7542
7581
  ]);
7543
7582
  return Component;
7544
7583
  }(EngineObject);
7545
- __decorate([
7546
- ignoreClone
7547
- ], Component.prototype, "_entity", void 0);
7548
7584
  __decorate([
7549
7585
  ignoreClone
7550
7586
  ], Component.prototype, "_awoken", void 0);
@@ -7913,7 +7949,7 @@ function dependentComponents(componentOrComponents, dependentMode) {
7913
7949
  };
7914
7950
  /**
7915
7951
  * @internal
7916
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
7952
+ */ _proto._cloneTo = function _cloneTo(target) {
7917
7953
  var position = target._position, rotation = target._rotation, scale = target._scale;
7918
7954
  // @ts-ignore
7919
7955
  position._onValueChanged = rotation._onValueChanged = scale._onValueChanged = null;
@@ -8525,9 +8561,6 @@ __decorate([
8525
8561
  __decorate([
8526
8562
  ignoreClone
8527
8563
  ], Transform.prototype, "_isParentDirty", void 0);
8528
- __decorate([
8529
- ignoreClone
8530
- ], Transform.prototype, "_parentTransformCache", void 0);
8531
8564
  __decorate([
8532
8565
  ignoreClone
8533
8566
  ], Transform.prototype, "_dirtyFlag", void 0);
@@ -8997,7 +9030,7 @@ exports.Camera = /*#__PURE__*/ function(Component) {
8997
9030
  };
8998
9031
  /**
8999
9032
  * @internal
9000
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
9033
+ */ _proto._cloneTo = function _cloneTo(target) {
9001
9034
  var _this__renderTarget;
9002
9035
  (_this__renderTarget = this._renderTarget) == null ? void 0 : _this__renderTarget._addReferCount(1);
9003
9036
  };
@@ -12233,9 +12266,6 @@ __decorate([
12233
12266
  return ColliderShape;
12234
12267
  }();
12235
12268
  ColliderShape._idGenerator = 0;
12236
- __decorate([
12237
- ignoreClone
12238
- ], ColliderShape.prototype, "_collider", void 0);
12239
12269
  __decorate([
12240
12270
  ignoreClone
12241
12271
  ], ColliderShape.prototype, "_nativeShape", void 0);
@@ -16671,7 +16701,7 @@ exports.Renderer = /*#__PURE__*/ function(Component) {
16671
16701
  };
16672
16702
  /**
16673
16703
  * @internal
16674
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16704
+ */ _proto._cloneTo = function _cloneTo(target) {
16675
16705
  var materials = this._materials;
16676
16706
  for(var i = 0, n = materials.length; i < n; i++){
16677
16707
  target._setMaterial(i, materials[i]);
@@ -16926,9 +16956,6 @@ __decorate([
16926
16956
  __decorate([
16927
16957
  ignoreClone
16928
16958
  ], exports.Renderer.prototype, "_bounds", void 0);
16929
- __decorate([
16930
- ignoreClone
16931
- ], exports.Renderer.prototype, "_transformEntity", void 0);
16932
16959
  __decorate([
16933
16960
  deepClone
16934
16961
  ], exports.Renderer.prototype, "_shaderData", void 0);
@@ -16988,8 +17015,8 @@ var RendererUpdateFlags = /*#__PURE__*/ function(RendererUpdateFlags) {
16988
17015
  };
16989
17016
  /**
16990
17017
  * @internal
16991
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16992
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
17018
+ */ _proto._cloneTo = function _cloneTo(target) {
17019
+ Renderer.prototype._cloneTo.call(this, target);
16993
17020
  target.sprite = this._sprite;
16994
17021
  };
16995
17022
  /**
@@ -17300,8 +17327,8 @@ __decorate([
17300
17327
  };
17301
17328
  /**
17302
17329
  * @internal
17303
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
17304
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
17330
+ */ _proto._cloneTo = function _cloneTo(target) {
17331
+ Renderer.prototype._cloneTo.call(this, target);
17305
17332
  target.sprite = this._sprite;
17306
17333
  target.drawMode = this._drawMode;
17307
17334
  };
@@ -17724,8 +17751,8 @@ __decorate([
17724
17751
  };
17725
17752
  /**
17726
17753
  * @internal
17727
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
17728
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
17754
+ */ _proto._cloneTo = function _cloneTo(target) {
17755
+ Renderer.prototype._cloneTo.call(this, target);
17729
17756
  target.font = this._font;
17730
17757
  target._subFont = this._subFont;
17731
17758
  };
@@ -19427,8 +19454,8 @@ var BlendShapeFrameDirty = /*#__PURE__*/ function(BlendShapeFrameDirty) {
19427
19454
  };
19428
19455
  /**
19429
19456
  * @internal
19430
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
19431
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
19457
+ */ _proto._cloneTo = function _cloneTo(target) {
19458
+ Renderer.prototype._cloneTo.call(this, target);
19432
19459
  target.mesh = this._mesh;
19433
19460
  };
19434
19461
  /**
@@ -22294,45 +22321,6 @@ PrimitiveMesh._sphereSeedCells = new Float32Array([
22294
22321
  PrimitiveMesh._sphereEdgeIdx = 0;
22295
22322
  PrimitiveMesh._spherePoleIdx = 0;
22296
22323
 
22297
- /**
22298
- * @internal
22299
- * Utility functions for remapping Entity/Component references during cloning.
22300
- */ var CloneUtils = /*#__PURE__*/ function() {
22301
- function CloneUtils() {}
22302
- CloneUtils.remapEntity = function remapEntity(srcRoot, targetRoot, entity) {
22303
- var paths = CloneUtils._tempRemapPath;
22304
- var success = CloneUtils._getEntityHierarchyPath(srcRoot, entity, paths);
22305
- return success ? CloneUtils._getEntityByHierarchyPath(targetRoot, paths) : entity;
22306
- };
22307
- CloneUtils.remapComponent = function remapComponent(srcRoot, targetRoot, component) {
22308
- var _CloneUtils__getEntityByHierarchyPath;
22309
- var paths = CloneUtils._tempRemapPath;
22310
- var success = CloneUtils._getEntityHierarchyPath(srcRoot, component.entity, paths);
22311
- return success ? (_CloneUtils__getEntityByHierarchyPath = CloneUtils._getEntityByHierarchyPath(targetRoot, paths)) == null ? void 0 : _CloneUtils__getEntityByHierarchyPath.getComponent(component.constructor) : component;
22312
- };
22313
- CloneUtils._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
22314
- inversePath.length = 0;
22315
- while(searchEntity !== rootEntity){
22316
- var parent = searchEntity.parent;
22317
- if (!parent) {
22318
- return false;
22319
- }
22320
- inversePath.push(searchEntity.siblingIndex);
22321
- searchEntity = parent;
22322
- }
22323
- return true;
22324
- };
22325
- CloneUtils._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
22326
- var entity = rootEntity;
22327
- for(var i = inversePath.length - 1; i >= 0; i--){
22328
- entity = entity.children[inversePath[i]];
22329
- }
22330
- return entity;
22331
- };
22332
- return CloneUtils;
22333
- }();
22334
- CloneUtils._tempRemapPath = [];
22335
-
22336
22324
  /**
22337
22325
  * Skin used for skinned mesh renderer.
22338
22326
  */ var Skin = /*#__PURE__*/ function(EngineObject) {
@@ -22364,25 +22352,6 @@ CloneUtils._tempRemapPath = [];
22364
22352
  }
22365
22353
  this._updateMark = renderer.engine.time.frameCount;
22366
22354
  };
22367
- /**
22368
- * @internal
22369
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
22370
- // Clone rootBone
22371
- var rootBone = this.rootBone;
22372
- if (rootBone) {
22373
- target.rootBone = CloneUtils.remapEntity(srcRoot, targetRoot, rootBone);
22374
- }
22375
- // Clone bones
22376
- var bones = this.bones;
22377
- if (bones.length > 0) {
22378
- var boneCount = bones.length;
22379
- var destBones = new Array(boneCount);
22380
- for(var i = 0; i < boneCount; i++){
22381
- destBones[i] = CloneUtils.remapEntity(srcRoot, targetRoot, bones[i]);
22382
- }
22383
- target.bones = destBones;
22384
- }
22385
- };
22386
22355
  _create_class(Skin, [
22387
22356
  {
22388
22357
  key: "rootBone",
@@ -22446,10 +22415,7 @@ __decorate([
22446
22415
  ignoreClone
22447
22416
  ], Skin.prototype, "_updatedManager", void 0);
22448
22417
  __decorate([
22449
- ignoreClone
22450
- ], Skin.prototype, "_rootBone", void 0);
22451
- __decorate([
22452
- ignoreClone
22418
+ deepClone
22453
22419
  ], Skin.prototype, "_bones", void 0);
22454
22420
  __decorate([
22455
22421
  ignoreClone
@@ -22499,8 +22465,8 @@ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
22499
22465
  };
22500
22466
  /**
22501
22467
  * @internal
22502
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
22503
- MeshRenderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
22468
+ */ _proto._cloneTo = function _cloneTo(target) {
22469
+ MeshRenderer.prototype._cloneTo.call(this, target);
22504
22470
  if (this.skin) {
22505
22471
  target._applySkin(null, target.skin);
22506
22472
  }
@@ -23041,9 +23007,7 @@ var ComponentCloner = /*#__PURE__*/ function() {
23041
23007
  for(var k in source){
23042
23008
  CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
23043
23009
  }
23044
- if (source._cloneTo) {
23045
- source._cloneTo(target, srcRoot, targetRoot);
23046
- }
23010
+ source._cloneTo == null ? void 0 : source._cloneTo.call(source, target, srcRoot, targetRoot);
23047
23011
  };
23048
23012
  return ComponentCloner;
23049
23013
  }();
@@ -23230,6 +23194,11 @@ var ComponentCloner = /*#__PURE__*/ function() {
23230
23194
  };
23231
23195
  /**
23232
23196
  * @internal
23197
+ */ _proto._remap = function _remap(srcRoot, targetRoot) {
23198
+ return CloneUtils.remapEntity(srcRoot, targetRoot, this);
23199
+ };
23200
+ /**
23201
+ * @internal
23233
23202
  */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
23234
23203
  this._isTemplate = true;
23235
23204
  this._templateResource = templateResource;
@@ -31338,7 +31307,7 @@ function _type_of(obj) {
31338
31307
  };
31339
31308
  /**
31340
31309
  * @internal
31341
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
31310
+ */ _proto._cloneTo = function _cloneTo(target) {
31342
31311
  var animatorController = target._animatorController;
31343
31312
  if (animatorController) {
31344
31313
  target._addResourceReferCount(animatorController, 1);
@@ -36489,9 +36458,6 @@ __decorate([
36489
36458
  __decorate([
36490
36459
  ignoreClone
36491
36460
  ], ParticleGenerator.prototype, "_subPrimitive", void 0);
36492
- __decorate([
36493
- ignoreClone
36494
- ], ParticleGenerator.prototype, "_renderer", void 0);
36495
36461
  __decorate([
36496
36462
  ignoreClone
36497
36463
  ], ParticleGenerator.prototype, "_isPlaying", void 0);
@@ -37230,7 +37196,7 @@ ConeShape._tempVector31 = new engineMath.Vector3();
37230
37196
  };
37231
37197
  /**
37232
37198
  * @internal
37233
- */ _proto._cloneTo = function _cloneTo(target, _, __) {
37199
+ */ _proto._cloneTo = function _cloneTo(target) {
37234
37200
  target.mesh = this._mesh;
37235
37201
  };
37236
37202
  _create_class(MeshShape, [
@@ -38210,7 +38176,7 @@ AudioManager._needsUserGestureResume = false;
38210
38176
  };
38211
38177
  /**
38212
38178
  * @internal
38213
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
38179
+ */ _proto._cloneTo = function _cloneTo(target) {
38214
38180
  var _target__clip;
38215
38181
  (_target__clip = target._clip) == null ? void 0 : _target__clip._addReferCount(1);
38216
38182
  target._gainNode.gain.setValueAtTime(target._volume, AudioManager.getContext().currentTime);