@galacean/engine-core 2.0.0-alpha.14 → 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,227 +22321,867 @@ PrimitiveMesh._sphereSeedCells = new Float32Array([
22294
22321
  PrimitiveMesh._sphereEdgeIdx = 0;
22295
22322
  PrimitiveMesh._spherePoleIdx = 0;
22296
22323
 
22297
- function _is_native_reflect_construct() {
22298
- // Since Reflect.construct can't be properly polyfilled, some
22299
- // implementations (e.g. core-js@2) don't set the correct internal slots.
22300
- // Those polyfills don't allow us to subclass built-ins, so we need to
22301
- // use our fallback implementation.
22302
- try {
22303
- // If the internal slots aren't set, this throws an error similar to
22304
- // TypeError: this is not a Boolean object.
22305
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
22306
- } catch (_) {}
22307
- return (_is_native_reflect_construct = function() {
22308
- return !!result;
22309
- })();
22310
- }
22311
-
22312
- function _construct(Parent, args, Class) {
22313
- if (_is_native_reflect_construct()) _construct = Reflect.construct;
22314
- else {
22315
- _construct = function construct(Parent, args, Class) {
22316
- var a = [null];
22317
- a.push.apply(a, args);
22318
- var Constructor = Function.bind.apply(Parent, a);
22319
- var instance = new Constructor();
22320
-
22321
- if (Class) _set_prototype_of(instance, Class.prototype);
22322
-
22323
- return instance;
22324
- };
22324
+ /**
22325
+ * Skin used for skinned mesh renderer.
22326
+ */ var Skin = /*#__PURE__*/ function(EngineObject) {
22327
+ _inherits(Skin, EngineObject);
22328
+ function Skin(name) {
22329
+ var _this;
22330
+ _this = EngineObject.call(this, null) || this, _this.name = name, _this.inverseBindMatrices = new Array(), _this._updatedManager = new UpdateFlagManager(), _this._bones = new Array(), _this._updateMark = -1, _this.joints = [];
22331
+ return _this;
22325
22332
  }
22326
-
22327
- return _construct.apply(null, arguments);
22328
- }
22329
-
22330
- var ComponentCloner = /*#__PURE__*/ function() {
22331
- function ComponentCloner() {}
22333
+ var _proto = Skin.prototype;
22332
22334
  /**
22333
- * Clone component.
22334
- * @param source - Clone source
22335
- * @param target - Clone target
22336
- */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
22337
- var cloneModes = CloneManager.getCloneMode(source.constructor);
22338
- for(var k in source){
22339
- CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
22335
+ * @internal
22336
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
22337
+ if (this._updateMark === renderer.engine.time.frameCount) {
22338
+ return;
22340
22339
  }
22341
- if (source._cloneTo) {
22342
- source._cloneTo(target, srcRoot, targetRoot);
22340
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
22341
+ var _this_rootBone;
22342
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
22343
+ for(var i = bones.length - 1; i >= 0; i--){
22344
+ var bone = bones[i];
22345
+ var offset = i * 16;
22346
+ if (bone) {
22347
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
22348
+ } else {
22349
+ skinMatrices.set(bindMatrices[i].elements, offset);
22350
+ }
22351
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
22343
22352
  }
22353
+ this._updateMark = renderer.engine.time.frameCount;
22344
22354
  };
22345
- return ComponentCloner;
22346
- }();
22347
-
22348
- /**
22349
- * The entity modify flags.
22350
- */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
22351
- /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
22352
- /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
22353
- return EntityModifyFlags;
22355
+ _create_class(Skin, [
22356
+ {
22357
+ key: "rootBone",
22358
+ get: /**
22359
+ * Root bone.
22360
+ */ function get() {
22361
+ return this._rootBone;
22362
+ },
22363
+ set: function set(value) {
22364
+ if (this._rootBone !== value) {
22365
+ this._updatedManager.dispatch(1, value);
22366
+ this._rootBone = value;
22367
+ }
22368
+ }
22369
+ },
22370
+ {
22371
+ key: "bones",
22372
+ get: /**
22373
+ * Bones of the skin.
22374
+ */ function get() {
22375
+ return this._bones;
22376
+ },
22377
+ set: function set(value) {
22378
+ var bones = this._bones;
22379
+ var _value_length;
22380
+ var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
22381
+ var lastBoneCount = bones.length;
22382
+ bones.length = boneCount;
22383
+ for(var i = 0; i < boneCount; i++){
22384
+ bones[i] = value[i];
22385
+ }
22386
+ if (lastBoneCount !== boneCount) {
22387
+ this._skinMatrices = new Float32Array(boneCount * 16);
22388
+ this._updatedManager.dispatch(0, boneCount);
22389
+ }
22390
+ }
22391
+ },
22392
+ {
22393
+ key: "skeleton",
22394
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
22395
+ var _this_rootBone;
22396
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
22397
+ },
22398
+ set: function set(value) {
22399
+ var rootBone = this._rootBone;
22400
+ if (rootBone) {
22401
+ rootBone.name = value;
22402
+ }
22403
+ }
22404
+ }
22405
+ ]);
22406
+ return Skin;
22407
+ }(EngineObject);
22408
+ __decorate([
22409
+ deepClone
22410
+ ], Skin.prototype, "inverseBindMatrices", void 0);
22411
+ __decorate([
22412
+ ignoreClone
22413
+ ], Skin.prototype, "_skinMatrices", void 0);
22414
+ __decorate([
22415
+ ignoreClone
22416
+ ], Skin.prototype, "_updatedManager", void 0);
22417
+ __decorate([
22418
+ deepClone
22419
+ ], Skin.prototype, "_bones", void 0);
22420
+ __decorate([
22421
+ ignoreClone
22422
+ ], Skin.prototype, "_updateMark", void 0);
22423
+ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
22424
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
22425
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
22426
+ return SkinUpdateFlag;
22354
22427
  }({});
22355
22428
 
22356
22429
  /**
22357
- * Entity, be used as components container.
22358
- */ var Entity = /*#__PURE__*/ function(EngineObject) {
22359
- _inherits(Entity, EngineObject);
22360
- function Entity(engine, name) {
22361
- for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
22362
- components[_key - 2] = arguments[_key];
22363
- }
22430
+ * SkinnedMeshRenderer.
22431
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
22432
+ _inherits(SkinnedMeshRenderer, MeshRenderer);
22433
+ function SkinnedMeshRenderer(entity) {
22364
22434
  var _this;
22365
- _this = EngineObject.call(this, engine) || this, /** The layer the entity belongs to. */ _this.layer = Layer.Layer0, /** @internal */ _this._isActiveInHierarchy = false, /** @internal */ _this._isActiveInScene = false, /** @internal */ _this._components = [], /** @internal */ _this._scripts = new DisorderedArray(), /** @internal */ _this._children = [], /** @internal */ _this._isRoot = false, /** @internal */ _this._isActive = true, /** @internal */ _this._siblingIndex = -1, /** @internal */ _this._isTemplate = false, /** @internal */ _this._updateFlagManager = new UpdateFlagManager(), _this._parent = null, //--------------------------------------------------------------deprecated----------------------------------------------------------------
22366
- _this._invModelMatrix = new engineMath.Matrix();
22367
- _this.name = name != null ? name : "Entity";
22368
- for(var i = 0, n = components.length; i < n; i++){
22369
- _this.addComponent(components[i]);
22370
- }
22371
- !_this._transform && _this.addComponent(Transform);
22372
- _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
22435
+ _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new engineMath.BoundingBox(), _this._jointDataCreateCache = new engineMath.Vector2(-1, -1);
22436
+ _this._skin = null;
22437
+ var rhi = _this.entity.engine._hardwareRenderer;
22438
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
22439
+ // Limit size to 256 to avoid some problem:
22440
+ // For renderer is "Apple GPU", when uniform is large than 256 the skeleton matrix array access in shader very slow in Safari or WKWebview. This may be a apple bug, Chrome and Firefox is OK!
22441
+ // For renderer is "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3011 vs_5_0 ps_5_0, D3011)", compile shader si very slow because of max uniform is 4096.
22442
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
22443
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
22444
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
22445
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
22446
+ var localBounds = _this._localBounds;
22447
+ // @ts-ignore
22448
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
22449
+ // @ts-ignore
22450
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
22373
22451
  return _this;
22374
22452
  }
22375
- var _proto = Entity.prototype;
22453
+ var _proto = SkinnedMeshRenderer.prototype;
22376
22454
  /**
22377
- * Add component based on the component type.
22378
- * @param type - The type of the component
22379
- * @param args - The arguments of the component
22380
- * @returns The component which has been added
22381
- */ _proto.addComponent = function addComponent(type) {
22382
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
22383
- args[_key - 1] = arguments[_key];
22384
- }
22385
- ComponentsDependencies._addCheck(this, type);
22386
- var component = _construct(type, [].concat([
22387
- this
22388
- ], args));
22389
- this._components.push(component);
22390
- // @todo: temporary solution
22391
- if (_instanceof(component, Transform)) this._setTransform(component);
22392
- component._setActive(true, ActiveChangeFlag.All);
22393
- return component;
22455
+ * @internal
22456
+ */ _proto._onDestroy = function _onDestroy() {
22457
+ var _this__jointTexture;
22458
+ MeshRenderer.prototype._onDestroy.call(this);
22459
+ this._jointDataCreateCache = null;
22460
+ this._skin = null;
22461
+ this._blendShapeWeights = null;
22462
+ this._localBounds = null;
22463
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
22464
+ this._jointTexture = null;
22394
22465
  };
22395
22466
  /**
22396
- * Get component which match the type.
22397
- * @param type - The type of the component
22398
- * @returns The first component which match type
22399
- */ _proto.getComponent = function getComponent(type) {
22400
- var components = this._components;
22401
- for(var i = 0, n = components.length; i < n; i++){
22402
- var component = components[i];
22403
- if (_instanceof(component, type)) {
22404
- return component;
22405
- }
22467
+ * @internal
22468
+ */ _proto._cloneTo = function _cloneTo(target) {
22469
+ MeshRenderer.prototype._cloneTo.call(this, target);
22470
+ if (this.skin) {
22471
+ target._applySkin(null, target.skin);
22406
22472
  }
22407
- return null;
22473
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
22408
22474
  };
22409
- /**
22410
- * Get components which match the type.
22411
- * @param type - The type of the component
22412
- * @param results - The components which match type
22413
- * @returns The components which match type
22414
- */ _proto.getComponents = function getComponents(type, results) {
22415
- results.length = 0;
22416
- var components = this._components;
22417
- for(var i = 0, n = components.length; i < n; i++){
22418
- var component = components[i];
22419
- if (_instanceof(component, type)) {
22420
- results.push(component);
22475
+ _proto._update = function _update(context) {
22476
+ var skin = this.skin;
22477
+ if ((skin == null ? void 0 : skin.bones.length) > 0) {
22478
+ skin._updateSkinMatrices(this);
22479
+ }
22480
+ var shaderData = this.shaderData;
22481
+ var mesh = this.mesh;
22482
+ var blendShapeManager = mesh._blendShapeManager;
22483
+ blendShapeManager._updateShaderData(shaderData, this);
22484
+ var bones = skin == null ? void 0 : skin.bones;
22485
+ if (bones) {
22486
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
22487
+ var boneCount = bones.length;
22488
+ var boneDataCreateCache = this._jointDataCreateCache;
22489
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
22490
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
22491
+ // directly use max joint count to avoid shader recompile
22492
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
22493
+ if (boneCount > remainUniformJointCount) {
22494
+ var engine = this.engine;
22495
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
22496
+ if (boneCountChange) {
22497
+ var _this__jointTexture;
22498
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
22499
+ this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
22500
+ this._jointTexture.filterMode = TextureFilterMode.Point;
22501
+ this._jointTexture.isGCIgnored = true;
22502
+ }
22503
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
22504
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
22505
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
22506
+ } else {
22507
+ Logger.error("component's joints count(" + boneCount + ") greater than device's MAX_VERTEX_UNIFORM_VECTORS number " + this._maxVertexUniformVectors + ", and don't support jointTexture in this device. suggest joint count less than " + remainUniformJointCount + ".", this);
22508
+ }
22509
+ } else {
22510
+ var _this__jointTexture1;
22511
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
22512
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
22513
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
22514
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
22515
+ }
22516
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
22517
+ }
22518
+ if (this._jointTexture) {
22519
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
22421
22520
  }
22422
22521
  }
22423
- return results;
22522
+ MeshRenderer.prototype._update.call(this, context);
22424
22523
  };
22425
22524
  /**
22426
- * Get the components which match the type of the entity and it's children.
22427
- * @param type - The component type
22428
- * @param results - The components collection
22429
- * @returns The components collection which match the type
22430
- */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
22431
- results.length = 0;
22432
- this._getComponentsInChildren(type, results);
22433
- return results;
22434
- };
22435
- _proto.addChild = function addChild(indexOrChild, child) {
22436
- var index;
22437
- if (typeof indexOrChild === "number") {
22438
- index = indexOrChild;
22525
+ * @internal
22526
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
22527
+ var _this_skin;
22528
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
22529
+ if (rootBone) {
22530
+ engineMath.BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
22439
22531
  } else {
22440
- index = undefined;
22441
- child = indexOrChild;
22532
+ MeshRenderer.prototype._updateBounds.call(this, worldBounds);
22442
22533
  }
22443
- child._setParent(this, index);
22444
- };
22445
- /**
22446
- * Remove child entity.
22447
- * @param child - The child entity which want to be removed
22448
- */ _proto.removeChild = function removeChild(child) {
22449
- if (child._parent !== this) return;
22450
- child._setParent(null);
22451
22534
  };
22452
- /**
22453
- * @deprecated Please use `children` property instead.
22454
- * Find child entity by index.
22455
- * @param index - The index of the child entity
22456
- * @returns The component which be found
22457
- */ _proto.getChild = function getChild(index) {
22458
- return this._children[index];
22459
- };
22460
- /**
22461
- * Find entity by name.
22462
- * @param name - The name of the entity which want to be found
22463
- * @returns The component which be found
22464
- */ _proto.findByName = function findByName(name) {
22465
- if (name === this.name) {
22466
- return this;
22467
- }
22468
- var children = this._children;
22469
- for(var i = 0, n = children.length; i < n; i++){
22470
- var target = children[i].findByName(name);
22471
- if (target) {
22472
- return target;
22535
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
22536
+ var mesh = this._mesh;
22537
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
22538
+ var lastBlendShapeWeights = this._blendShapeWeights;
22539
+ if (lastBlendShapeWeights) {
22540
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
22541
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
22542
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
22543
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
22544
+ newBlendShapeWeights.set(lastBlendShapeWeights);
22545
+ } else {
22546
+ for(var i = 0; i < newBlendShapeCount; i++){
22547
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
22548
+ }
22549
+ }
22550
+ this._blendShapeWeights = newBlendShapeWeights;
22473
22551
  }
22552
+ } else {
22553
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
22474
22554
  }
22475
- return null;
22476
22555
  };
22477
- /**
22478
- * Find the entity by path.
22479
- * @param path - The path of the entity eg: /entity
22480
- * @returns The component which be found
22481
- */ _proto.findByPath = function findByPath(path) {
22482
- var splits = path.split("/").filter(Boolean);
22483
- if (!splits.length) {
22484
- return this;
22485
- }
22486
- return Entity._findChildByName(this, 0, splits, 0);
22556
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
22557
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
22487
22558
  };
22488
- /**
22489
- * Create child entity.
22490
- * @param name - The child entity's name
22491
- * @returns The child entity
22492
- */ _proto.createChild = function createChild(name) {
22493
- var transform = this._transform;
22494
- var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
22495
- child.layer = this.layer;
22496
- child.parent = this;
22497
- return child;
22559
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
22560
+ switch(type){
22561
+ case SkinUpdateFlag.BoneCountChanged:
22562
+ var shaderData = this.shaderData;
22563
+ if (value > 0) {
22564
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
22565
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
22566
+ } else {
22567
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
22568
+ }
22569
+ break;
22570
+ case SkinUpdateFlag.RootBoneChanged:
22571
+ this._setTransformEntity(value);
22572
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
22573
+ break;
22574
+ }
22498
22575
  };
22499
- /**
22500
- * Clear children entities.
22501
- */ _proto.clearChildren = function clearChildren() {
22502
- var children = this._children;
22503
- for(var i = children.length - 1; i >= 0; i--){
22504
- var child = children[i];
22505
- child._parent = null;
22506
- var activeChangeFlag = ActiveChangeFlag.None;
22507
- child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
22508
- child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
22509
- activeChangeFlag && child._processInActive(activeChangeFlag);
22510
- Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
22576
+ _proto._applySkin = function _applySkin(lastSkin, value) {
22577
+ var _lastSkin_bones, _value_bones;
22578
+ var _lastSkin_bones_length;
22579
+ var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
22580
+ var _lastSkin_rootBone;
22581
+ var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
22582
+ lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
22583
+ var _value_bones_length;
22584
+ var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
22585
+ var _value_rootBone;
22586
+ var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
22587
+ value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
22588
+ if (lastSkinBoneCount !== skinBoneCount) {
22589
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
22590
+ }
22591
+ if (lastRootBone !== rootBone) {
22592
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
22511
22593
  }
22512
- children.length = 0;
22513
22594
  };
22514
- /**
22515
- * Clone this entity include children and components.
22516
- * @returns Cloned entity
22517
- */ _proto.clone = function clone() {
22595
+ _create_class(SkinnedMeshRenderer, [
22596
+ {
22597
+ key: "skin",
22598
+ get: /**
22599
+ * Skin of the SkinnedMeshRenderer.
22600
+ */ function get() {
22601
+ return this._skin;
22602
+ },
22603
+ set: function set(value) {
22604
+ var lastSkin = this._skin;
22605
+ if (lastSkin !== value) {
22606
+ this._applySkin(lastSkin, value);
22607
+ this._skin = value;
22608
+ }
22609
+ }
22610
+ },
22611
+ {
22612
+ key: "blendShapeWeights",
22613
+ get: /**
22614
+ * The weights of the BlendShapes.
22615
+ * @remarks Array index is BlendShape index.
22616
+ */ function get() {
22617
+ this._checkBlendShapeWeightLength();
22618
+ return this._blendShapeWeights;
22619
+ },
22620
+ set: function set(value) {
22621
+ this._checkBlendShapeWeightLength();
22622
+ var blendShapeWeights = this._blendShapeWeights;
22623
+ if (value.length <= blendShapeWeights.length) {
22624
+ blendShapeWeights.set(value);
22625
+ } else {
22626
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
22627
+ blendShapeWeights[i] = value[i];
22628
+ }
22629
+ }
22630
+ }
22631
+ },
22632
+ {
22633
+ key: "localBounds",
22634
+ get: /**
22635
+ * Local bounds.
22636
+ */ function get() {
22637
+ return this._localBounds;
22638
+ },
22639
+ set: function set(value) {
22640
+ if (this._localBounds !== value) {
22641
+ this._localBounds.copyFrom(value);
22642
+ }
22643
+ }
22644
+ },
22645
+ {
22646
+ key: "rootBone",
22647
+ get: /**
22648
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
22649
+ */ function get() {
22650
+ return this.skin.rootBone;
22651
+ },
22652
+ set: function set(value) {
22653
+ this.skin.rootBone = value;
22654
+ }
22655
+ },
22656
+ {
22657
+ key: "bones",
22658
+ get: /**
22659
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
22660
+ */ function get() {
22661
+ return this.skin.bones;
22662
+ },
22663
+ set: function set(value) {
22664
+ this.skin.bones = value;
22665
+ }
22666
+ }
22667
+ ]);
22668
+ return SkinnedMeshRenderer;
22669
+ }(MeshRenderer);
22670
+ // @TODO: different shader type should use different count, not always 48
22671
+ /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
22672
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
22673
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
22674
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
22675
+ __decorate([
22676
+ ignoreClone
22677
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
22678
+ __decorate([
22679
+ deepClone
22680
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
22681
+ __decorate([
22682
+ ignoreClone
22683
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
22684
+ __decorate([
22685
+ ignoreClone
22686
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
22687
+ __decorate([
22688
+ ignoreClone
22689
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
22690
+ __decorate([
22691
+ ignoreClone
22692
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
22693
+ __decorate([
22694
+ deepClone
22695
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
22696
+ __decorate([
22697
+ ignoreClone
22698
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
22699
+ __decorate([
22700
+ ignoreClone
22701
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
22702
+
22703
+ /**
22704
+ * @internal
22705
+ */ var BasicResources = /*#__PURE__*/ function() {
22706
+ function BasicResources(engine) {
22707
+ this.engine = engine;
22708
+ // prettier-ignore
22709
+ var vertices = new Float32Array([
22710
+ -1,
22711
+ -1,
22712
+ 0,
22713
+ 1,
22714
+ 3,
22715
+ -1,
22716
+ 2,
22717
+ 1,
22718
+ -1,
22719
+ 3,
22720
+ 0,
22721
+ -1
22722
+ ]); // left-top
22723
+ // prettier-ignore
22724
+ var flipYVertices = new Float32Array([
22725
+ 3,
22726
+ -1,
22727
+ 2,
22728
+ 0,
22729
+ -1,
22730
+ -1,
22731
+ 0,
22732
+ 0,
22733
+ -1,
22734
+ 3,
22735
+ 0,
22736
+ 2
22737
+ ]); // left-top
22738
+ var blitMaterial = new Material(engine, Shader.find("blit"));
22739
+ blitMaterial._addReferCount(1);
22740
+ blitMaterial.renderState.depthState.enabled = false;
22741
+ blitMaterial.renderState.depthState.writeEnabled = false;
22742
+ var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
22743
+ blitScreenMaterial._addReferCount(1);
22744
+ blitScreenMaterial.renderState.depthState.enabled = false;
22745
+ blitScreenMaterial.renderState.depthState.writeEnabled = false;
22746
+ this.blitMaterial = blitMaterial;
22747
+ this.blitScreenMaterial = blitScreenMaterial;
22748
+ this.blitMesh = this._createBlitMesh(engine, vertices);
22749
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
22750
+ // Create white and magenta textures
22751
+ var whitePixel = new Uint8Array([
22752
+ 255,
22753
+ 255,
22754
+ 255,
22755
+ 255
22756
+ ]);
22757
+ this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
22758
+ this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
22759
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
22760
+ if (isWebGL2) {
22761
+ this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
22762
+ var whitePixel32 = new Uint32Array([
22763
+ 255,
22764
+ 255,
22765
+ 255,
22766
+ 255
22767
+ ]);
22768
+ this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
22769
+ }
22770
+ this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
22771
+ this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
22772
+ this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
22773
+ this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
22774
+ this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
22775
+ }
22776
+ var _proto = BasicResources.prototype;
22777
+ /**
22778
+ * @internal
22779
+ */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
22780
+ return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
22781
+ };
22782
+ /**
22783
+ * @internal
22784
+ */ _proto._initialize = function _initialize() {
22785
+ var _this = this;
22786
+ return new Promise(function(resolve, reject) {
22787
+ PrefilteredDFG.create(_this.engine).then(function(texture) {
22788
+ _this._prefilteredDFGTexture = texture;
22789
+ resolve(_this);
22790
+ }).catch(reject);
22791
+ });
22792
+ };
22793
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
22794
+ var mesh = new ModelMesh(engine);
22795
+ mesh._addReferCount(1);
22796
+ mesh.setVertexElements([
22797
+ new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
22798
+ ]);
22799
+ var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
22800
+ mesh.setVertexBufferBinding(buffer, 16);
22801
+ mesh.addSubMesh(0, 3, MeshTopology.Triangles);
22802
+ engine.resourceManager.addContentRestorer(new (/*#__PURE__*/ function(ContentRestorer) {
22803
+ _inherits(_class, ContentRestorer);
22804
+ function _class() {
22805
+ return ContentRestorer.call(this, mesh) || this;
22806
+ }
22807
+ var _proto = _class.prototype;
22808
+ _proto.restoreContent = function restoreContent() {
22809
+ buffer.setData(buffer.data);
22810
+ };
22811
+ return _class;
22812
+ }(ContentRestorer))());
22813
+ return mesh;
22814
+ };
22815
+ _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
22816
+ var texture;
22817
+ switch(type){
22818
+ case 0:
22819
+ var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
22820
+ texture2D.setPixelBuffer(pixel);
22821
+ texture = texture2D;
22822
+ break;
22823
+ case 2:
22824
+ var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
22825
+ texture2DArray.setPixelBuffer(0, pixel);
22826
+ texture = texture2DArray;
22827
+ break;
22828
+ case 1:
22829
+ var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
22830
+ for(var i = 0; i < 6; i++){
22831
+ textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
22832
+ }
22833
+ texture = textureCube;
22834
+ break;
22835
+ default:
22836
+ throw "Invalid texture type";
22837
+ }
22838
+ texture.isGCIgnored = true;
22839
+ engine.resourceManager.addContentRestorer(new (/*#__PURE__*/ function(ContentRestorer) {
22840
+ _inherits(_class, ContentRestorer);
22841
+ function _class() {
22842
+ return ContentRestorer.call(this, texture) || this;
22843
+ }
22844
+ var _proto = _class.prototype;
22845
+ _proto.restoreContent = function restoreContent() {
22846
+ switch(type){
22847
+ case 0:
22848
+ this.resource.setPixelBuffer(pixel);
22849
+ break;
22850
+ case 2:
22851
+ this.resource.setPixelBuffer(0, pixel);
22852
+ break;
22853
+ case 1:
22854
+ for(var i = 0; i < 6; i++){
22855
+ this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
22856
+ }
22857
+ break;
22858
+ }
22859
+ };
22860
+ return _class;
22861
+ }(ContentRestorer))());
22862
+ return texture;
22863
+ };
22864
+ _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
22865
+ var material = new Material(engine, shader);
22866
+ var renderState = material.renderState;
22867
+ var target = renderState.blendState.targetBlendState;
22868
+ target.enabled = true;
22869
+ target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
22870
+ target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
22871
+ target.sourceAlphaBlendFactor = BlendFactor.One;
22872
+ target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
22873
+ target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
22874
+ renderState.depthState.writeEnabled = false;
22875
+ renderState.rasterState.cullMode = CullMode.Off;
22876
+ renderState.renderQueueType = RenderQueueType.Transparent;
22877
+ material.isGCIgnored = true;
22878
+ return material;
22879
+ };
22880
+ _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
22881
+ var material = new Material(engine, Shader.find(shaderName));
22882
+ material.isGCIgnored = true;
22883
+ material.shaderData.setColor("material_BaseColor", new engineMath.Color(1.0, 0.0, 1.01, 1.0));
22884
+ return material;
22885
+ };
22886
+ _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
22887
+ var material = new Material(engine, Shader.find("SpriteMask"));
22888
+ material.isGCIgnored = true;
22889
+ return material;
22890
+ };
22891
+ BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
22892
+ var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
22893
+ var renderStates;
22894
+ var compareFunction;
22895
+ if (visibleInsideMask) {
22896
+ renderStates = BasicResources._maskReadInsideRenderStates;
22897
+ if (renderStates) {
22898
+ return renderStates;
22899
+ }
22900
+ BasicResources._maskReadInsideRenderStates = renderStates = {};
22901
+ compareFunction = CompareFunction.LessEqual;
22902
+ } else {
22903
+ renderStates = BasicResources._maskReadOutsideRenderStates;
22904
+ if (renderStates) {
22905
+ return renderStates;
22906
+ }
22907
+ BasicResources._maskReadOutsideRenderStates = renderStates = {};
22908
+ compareFunction = CompareFunction.Greater;
22909
+ }
22910
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
22911
+ renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
22912
+ renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
22913
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
22914
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
22915
+ return renderStates;
22916
+ };
22917
+ BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
22918
+ var isIncrement = maskType === RenderQueueMaskType.Increment;
22919
+ var renderStates;
22920
+ var passOperation;
22921
+ if (isIncrement) {
22922
+ renderStates = BasicResources._maskWriteIncrementRenderStates;
22923
+ if (renderStates) {
22924
+ return renderStates;
22925
+ }
22926
+ BasicResources._maskWriteIncrementRenderStates = renderStates = {};
22927
+ passOperation = StencilOperation.IncrementSaturate;
22928
+ } else {
22929
+ renderStates = BasicResources._maskWriteDecrementRenderStates;
22930
+ if (renderStates) {
22931
+ return renderStates;
22932
+ }
22933
+ BasicResources._maskWriteDecrementRenderStates = renderStates = {};
22934
+ passOperation = StencilOperation.DecrementSaturate;
22935
+ }
22936
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
22937
+ renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
22938
+ renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
22939
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
22940
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
22941
+ var failStencilOperation = StencilOperation.Keep;
22942
+ renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
22943
+ renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
22944
+ renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
22945
+ renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
22946
+ renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
22947
+ renderStates[RenderStateElementKey.DepthStateEnabled] = false;
22948
+ renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
22949
+ return renderStates;
22950
+ };
22951
+ _create_class(BasicResources, [
22952
+ {
22953
+ key: "prefilteredDFGTexture",
22954
+ get: function get() {
22955
+ return this._prefilteredDFGTexture;
22956
+ }
22957
+ }
22958
+ ]);
22959
+ return BasicResources;
22960
+ }();
22961
+ BasicResources._maskReadInsideRenderStates = null;
22962
+ BasicResources._maskReadOutsideRenderStates = null;
22963
+ BasicResources._maskWriteIncrementRenderStates = null;
22964
+ BasicResources._maskWriteDecrementRenderStates = null;
22965
+
22966
+ function _is_native_reflect_construct() {
22967
+ // Since Reflect.construct can't be properly polyfilled, some
22968
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
22969
+ // Those polyfills don't allow us to subclass built-ins, so we need to
22970
+ // use our fallback implementation.
22971
+ try {
22972
+ // If the internal slots aren't set, this throws an error similar to
22973
+ // TypeError: this is not a Boolean object.
22974
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
22975
+ } catch (_) {}
22976
+ return (_is_native_reflect_construct = function() {
22977
+ return !!result;
22978
+ })();
22979
+ }
22980
+
22981
+ function _construct(Parent, args, Class) {
22982
+ if (_is_native_reflect_construct()) _construct = Reflect.construct;
22983
+ else {
22984
+ _construct = function construct(Parent, args, Class) {
22985
+ var a = [null];
22986
+ a.push.apply(a, args);
22987
+ var Constructor = Function.bind.apply(Parent, a);
22988
+ var instance = new Constructor();
22989
+
22990
+ if (Class) _set_prototype_of(instance, Class.prototype);
22991
+
22992
+ return instance;
22993
+ };
22994
+ }
22995
+
22996
+ return _construct.apply(null, arguments);
22997
+ }
22998
+
22999
+ var ComponentCloner = /*#__PURE__*/ function() {
23000
+ function ComponentCloner() {}
23001
+ /**
23002
+ * Clone component.
23003
+ * @param source - Clone source
23004
+ * @param target - Clone target
23005
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
23006
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
23007
+ for(var k in source){
23008
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
23009
+ }
23010
+ source._cloneTo == null ? void 0 : source._cloneTo.call(source, target, srcRoot, targetRoot);
23011
+ };
23012
+ return ComponentCloner;
23013
+ }();
23014
+
23015
+ /**
23016
+ * The entity modify flags.
23017
+ */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
23018
+ /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
23019
+ /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
23020
+ return EntityModifyFlags;
23021
+ }({});
23022
+
23023
+ /**
23024
+ * Entity, be used as components container.
23025
+ */ var Entity = /*#__PURE__*/ function(EngineObject) {
23026
+ _inherits(Entity, EngineObject);
23027
+ function Entity(engine, name) {
23028
+ for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
23029
+ components[_key - 2] = arguments[_key];
23030
+ }
23031
+ var _this;
23032
+ _this = EngineObject.call(this, engine) || this, /** The layer the entity belongs to. */ _this.layer = Layer.Layer0, /** @internal */ _this._isActiveInHierarchy = false, /** @internal */ _this._isActiveInScene = false, /** @internal */ _this._components = [], /** @internal */ _this._scripts = new DisorderedArray(), /** @internal */ _this._children = [], /** @internal */ _this._isRoot = false, /** @internal */ _this._isActive = true, /** @internal */ _this._siblingIndex = -1, /** @internal */ _this._isTemplate = false, /** @internal */ _this._updateFlagManager = new UpdateFlagManager(), _this._parent = null, //--------------------------------------------------------------deprecated----------------------------------------------------------------
23033
+ _this._invModelMatrix = new engineMath.Matrix();
23034
+ _this.name = name != null ? name : "Entity";
23035
+ for(var i = 0, n = components.length; i < n; i++){
23036
+ _this.addComponent(components[i]);
23037
+ }
23038
+ !_this._transform && _this.addComponent(Transform);
23039
+ _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
23040
+ return _this;
23041
+ }
23042
+ var _proto = Entity.prototype;
23043
+ /**
23044
+ * Add component based on the component type.
23045
+ * @param type - The type of the component
23046
+ * @param args - The arguments of the component
23047
+ * @returns The component which has been added
23048
+ */ _proto.addComponent = function addComponent(type) {
23049
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
23050
+ args[_key - 1] = arguments[_key];
23051
+ }
23052
+ ComponentsDependencies._addCheck(this, type);
23053
+ var component = _construct(type, [].concat([
23054
+ this
23055
+ ], args));
23056
+ this._components.push(component);
23057
+ // @todo: temporary solution
23058
+ if (_instanceof(component, Transform)) this._setTransform(component);
23059
+ component._setActive(true, ActiveChangeFlag.All);
23060
+ return component;
23061
+ };
23062
+ /**
23063
+ * Get component which match the type.
23064
+ * @param type - The type of the component
23065
+ * @returns The first component which match type
23066
+ */ _proto.getComponent = function getComponent(type) {
23067
+ var components = this._components;
23068
+ for(var i = 0, n = components.length; i < n; i++){
23069
+ var component = components[i];
23070
+ if (_instanceof(component, type)) {
23071
+ return component;
23072
+ }
23073
+ }
23074
+ return null;
23075
+ };
23076
+ /**
23077
+ * Get components which match the type.
23078
+ * @param type - The type of the component
23079
+ * @param results - The components which match type
23080
+ * @returns The components which match type
23081
+ */ _proto.getComponents = function getComponents(type, results) {
23082
+ results.length = 0;
23083
+ var components = this._components;
23084
+ for(var i = 0, n = components.length; i < n; i++){
23085
+ var component = components[i];
23086
+ if (_instanceof(component, type)) {
23087
+ results.push(component);
23088
+ }
23089
+ }
23090
+ return results;
23091
+ };
23092
+ /**
23093
+ * Get the components which match the type of the entity and it's children.
23094
+ * @param type - The component type
23095
+ * @param results - The components collection
23096
+ * @returns The components collection which match the type
23097
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
23098
+ results.length = 0;
23099
+ this._getComponentsInChildren(type, results);
23100
+ return results;
23101
+ };
23102
+ _proto.addChild = function addChild(indexOrChild, child) {
23103
+ var index;
23104
+ if (typeof indexOrChild === "number") {
23105
+ index = indexOrChild;
23106
+ } else {
23107
+ index = undefined;
23108
+ child = indexOrChild;
23109
+ }
23110
+ child._setParent(this, index);
23111
+ };
23112
+ /**
23113
+ * Remove child entity.
23114
+ * @param child - The child entity which want to be removed
23115
+ */ _proto.removeChild = function removeChild(child) {
23116
+ if (child._parent !== this) return;
23117
+ child._setParent(null);
23118
+ };
23119
+ /**
23120
+ * @deprecated Please use `children` property instead.
23121
+ * Find child entity by index.
23122
+ * @param index - The index of the child entity
23123
+ * @returns The component which be found
23124
+ */ _proto.getChild = function getChild(index) {
23125
+ return this._children[index];
23126
+ };
23127
+ /**
23128
+ * Find entity by name.
23129
+ * @param name - The name of the entity which want to be found
23130
+ * @returns The component which be found
23131
+ */ _proto.findByName = function findByName(name) {
23132
+ if (name === this.name) {
23133
+ return this;
23134
+ }
23135
+ var children = this._children;
23136
+ for(var i = 0, n = children.length; i < n; i++){
23137
+ var target = children[i].findByName(name);
23138
+ if (target) {
23139
+ return target;
23140
+ }
23141
+ }
23142
+ return null;
23143
+ };
23144
+ /**
23145
+ * Find the entity by path.
23146
+ * @param path - The path of the entity eg: /entity
23147
+ * @returns The component which be found
23148
+ */ _proto.findByPath = function findByPath(path) {
23149
+ var splits = path.split("/").filter(Boolean);
23150
+ if (!splits.length) {
23151
+ return this;
23152
+ }
23153
+ return Entity._findChildByName(this, 0, splits, 0);
23154
+ };
23155
+ /**
23156
+ * Create child entity.
23157
+ * @param name - The child entity's name
23158
+ * @returns The child entity
23159
+ */ _proto.createChild = function createChild(name) {
23160
+ var transform = this._transform;
23161
+ var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
23162
+ child.layer = this.layer;
23163
+ child.parent = this;
23164
+ return child;
23165
+ };
23166
+ /**
23167
+ * Clear children entities.
23168
+ */ _proto.clearChildren = function clearChildren() {
23169
+ var children = this._children;
23170
+ for(var i = children.length - 1; i >= 0; i--){
23171
+ var child = children[i];
23172
+ child._parent = null;
23173
+ var activeChangeFlag = ActiveChangeFlag.None;
23174
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
23175
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
23176
+ activeChangeFlag && child._processInActive(activeChangeFlag);
23177
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
23178
+ }
23179
+ children.length = 0;
23180
+ };
23181
+ /**
23182
+ * Clone this entity include children and components.
23183
+ * @returns Cloned entity
23184
+ */ _proto.clone = function clone() {
22518
23185
  var cloneEntity = this._createCloneEntity();
22519
23186
  this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
22520
23187
  return cloneEntity;
@@ -22527,6 +23194,11 @@ var ComponentCloner = /*#__PURE__*/ function() {
22527
23194
  };
22528
23195
  /**
22529
23196
  * @internal
23197
+ */ _proto._remap = function _remap(srcRoot, targetRoot) {
23198
+ return CloneUtils.remapEntity(srcRoot, targetRoot, this);
23199
+ };
23200
+ /**
23201
+ * @internal
22530
23202
  */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
22531
23203
  this._isTemplate = true;
22532
23204
  this._templateResource = templateResource;
@@ -22838,834 +23510,143 @@ var ComponentCloner = /*#__PURE__*/ function() {
22838
23510
  };
22839
23511
  /**
22840
23512
  * @internal
22841
- */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
22842
- inversePath.length = 0;
22843
- while(searchEntity !== rootEntity){
22844
- var parent = searchEntity.parent;
22845
- if (!parent) {
22846
- return false;
22847
- }
22848
- inversePath.push(searchEntity.siblingIndex);
22849
- searchEntity = parent;
22850
- }
22851
- return true;
22852
- };
22853
- /**
22854
- * @internal
22855
- */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
22856
- var entity = rootEntity;
22857
- for(var i = inversePath.length - 1; i >= 0; i--){
22858
- entity = entity.children[inversePath[i]];
22859
- }
22860
- return entity;
22861
- };
22862
- /**
22863
- * @internal
22864
- */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
22865
- var count = children.length - 1;
22866
- for(var i = entity._siblingIndex; i < count; i++){
22867
- var child = children[i + 1];
22868
- children[i] = child;
22869
- child._siblingIndex = i;
22870
- }
22871
- children.length = count;
22872
- entity._siblingIndex = -1;
22873
- };
22874
- /**
22875
- * @internal
22876
- */ Entity._addToChildren = function _addToChildren(children, entity, index) {
22877
- var childCount = children.length;
22878
- children.length = childCount + 1;
22879
- if (index === undefined) {
22880
- children[childCount] = entity;
22881
- entity._siblingIndex = childCount;
22882
- } else {
22883
- if (index < 0 || index > childCount) {
22884
- throw "The index " + index + " is out of child list bounds " + childCount;
22885
- }
22886
- for(var i = childCount; i > index; i--){
22887
- var swapChild = children[i - 1];
22888
- swapChild._siblingIndex = i;
22889
- children[i] = swapChild;
22890
- }
22891
- entity._siblingIndex = index;
22892
- children[index] = entity;
22893
- }
22894
- };
22895
- _create_class(Entity, [
22896
- {
22897
- key: "transform",
22898
- get: /**
22899
- * The transform of this entity.
22900
- */ function get() {
22901
- return this._transform;
22902
- }
22903
- },
22904
- {
22905
- key: "isActive",
22906
- get: /**
22907
- * Whether to activate locally.
22908
- */ function get() {
22909
- return this._isActive;
22910
- },
22911
- set: function set(value) {
22912
- if (value !== this._isActive) {
22913
- this._isActive = value;
22914
- if (value) {
22915
- var parent = this._parent;
22916
- var activeChangeFlag = ActiveChangeFlag.None;
22917
- if (this._isRoot && this._scene._isActiveInEngine) {
22918
- activeChangeFlag |= ActiveChangeFlag.All;
22919
- } else {
22920
- (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
22921
- (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
22922
- }
22923
- activeChangeFlag && this._processActive(activeChangeFlag);
22924
- } else {
22925
- var activeChangeFlag1 = ActiveChangeFlag.None;
22926
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
22927
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
22928
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
22929
- }
22930
- }
22931
- }
22932
- },
22933
- {
22934
- key: "isActiveInHierarchy",
22935
- get: /**
22936
- * Whether it is active in the hierarchy.
22937
- */ function get() {
22938
- return this._isActiveInHierarchy;
22939
- }
22940
- },
22941
- {
22942
- key: "parent",
22943
- get: /**
22944
- * The parent entity.
22945
- */ function get() {
22946
- return this._parent;
22947
- },
22948
- set: function set(value) {
22949
- this._setParent(value);
22950
- }
22951
- },
22952
- {
22953
- key: "children",
22954
- get: /**
22955
- * The children entities
22956
- */ function get() {
22957
- return this._children;
22958
- }
22959
- },
22960
- {
22961
- key: "childCount",
22962
- get: /**
22963
- * @deprecated Please use `children.length` property instead.
22964
- * Number of the children entities
22965
- */ function get() {
22966
- return this._children.length;
22967
- }
22968
- },
22969
- {
22970
- key: "scene",
22971
- get: /**
22972
- * The scene the entity belongs to.
22973
- */ function get() {
22974
- return this._scene;
22975
- }
22976
- },
22977
- {
22978
- key: "siblingIndex",
22979
- get: /**
22980
- * The sibling index.
22981
- */ function get() {
22982
- return this._siblingIndex;
22983
- },
22984
- set: function set(value) {
22985
- if (this._siblingIndex === -1) {
22986
- throw "The entity " + this.name + " is not in the hierarchy";
22987
- }
22988
- if (this._isRoot) {
22989
- this._setSiblingIndex(this._scene._rootEntities, value);
22990
- } else {
22991
- var parent = this._parent;
22992
- this._setSiblingIndex(parent._children, value);
22993
- parent._dispatchModify(EntityModifyFlags.Child, parent);
22994
- }
22995
- }
22996
- }
22997
- ]);
22998
- return Entity;
22999
- }(EngineObject);
23000
- /** @internal */ Entity._tempComponentConstructors = [];
23001
-
23002
- /**
23003
- * Skin used for skinned mesh renderer.
23004
- */ var Skin = /*#__PURE__*/ function(EngineObject) {
23005
- _inherits(Skin, EngineObject);
23006
- function Skin(name) {
23007
- var _this;
23008
- _this = EngineObject.call(this, null) || this, _this.name = name, _this.inverseBindMatrices = new Array(), _this._updatedManager = new UpdateFlagManager(), _this._bones = new Array(), _this._updateMark = -1, _this.joints = [];
23009
- return _this;
23010
- }
23011
- var _proto = Skin.prototype;
23012
- /**
23013
- * @internal
23014
- */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
23015
- if (this._updateMark === renderer.engine.time.frameCount) {
23016
- return;
23017
- }
23018
- var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
23019
- var _this_rootBone;
23020
- var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
23021
- for(var i = bones.length - 1; i >= 0; i--){
23022
- var bone = bones[i];
23023
- var offset = i * 16;
23024
- if (bone) {
23025
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
23026
- } else {
23027
- skinMatrices.set(bindMatrices[i].elements, offset);
23028
- }
23029
- Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
23030
- }
23031
- this._updateMark = renderer.engine.time.frameCount;
23032
- };
23033
- /**
23034
- * @internal
23035
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
23036
- var paths = new Array();
23037
- // Clone rootBone
23038
- var rootBone = this.rootBone;
23039
- if (rootBone) {
23040
- var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
23041
- target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
23042
- }
23043
- // Clone bones
23044
- var bones = this.bones;
23045
- if (bones.length > 0) {
23046
- var boneCount = bones.length;
23047
- var destBones = new Array(boneCount);
23048
- for(var i = 0; i < boneCount; i++){
23049
- var bone = bones[i];
23050
- var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
23051
- destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
23052
- }
23053
- target.bones = destBones;
23054
- }
23055
- };
23056
- _create_class(Skin, [
23057
- {
23058
- key: "rootBone",
23059
- get: /**
23060
- * Root bone.
23061
- */ function get() {
23062
- return this._rootBone;
23063
- },
23064
- set: function set(value) {
23065
- if (this._rootBone !== value) {
23066
- this._updatedManager.dispatch(1, value);
23067
- this._rootBone = value;
23068
- }
23069
- }
23070
- },
23071
- {
23072
- key: "bones",
23073
- get: /**
23074
- * Bones of the skin.
23075
- */ function get() {
23076
- return this._bones;
23077
- },
23078
- set: function set(value) {
23079
- var bones = this._bones;
23080
- var _value_length;
23081
- var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
23082
- var lastBoneCount = bones.length;
23083
- bones.length = boneCount;
23084
- for(var i = 0; i < boneCount; i++){
23085
- bones[i] = value[i];
23086
- }
23087
- if (lastBoneCount !== boneCount) {
23088
- this._skinMatrices = new Float32Array(boneCount * 16);
23089
- this._updatedManager.dispatch(0, boneCount);
23090
- }
23091
- }
23092
- },
23093
- {
23094
- key: "skeleton",
23095
- get: /** @deprecated Please use `rootBone` instead. */ function get() {
23096
- var _this_rootBone;
23097
- return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
23098
- },
23099
- set: function set(value) {
23100
- var rootBone = this._rootBone;
23101
- if (rootBone) {
23102
- rootBone.name = value;
23103
- }
23104
- }
23105
- }
23106
- ]);
23107
- return Skin;
23108
- }(EngineObject);
23109
- __decorate([
23110
- deepClone
23111
- ], Skin.prototype, "inverseBindMatrices", void 0);
23112
- __decorate([
23113
- ignoreClone
23114
- ], Skin.prototype, "_skinMatrices", void 0);
23115
- __decorate([
23116
- ignoreClone
23117
- ], Skin.prototype, "_updatedManager", void 0);
23118
- __decorate([
23119
- ignoreClone
23120
- ], Skin.prototype, "_rootBone", void 0);
23121
- __decorate([
23122
- ignoreClone
23123
- ], Skin.prototype, "_bones", void 0);
23124
- __decorate([
23125
- ignoreClone
23126
- ], Skin.prototype, "_updateMark", void 0);
23127
- var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
23128
- SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
23129
- SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
23130
- return SkinUpdateFlag;
23131
- }({});
23132
-
23133
- /**
23134
- * SkinnedMeshRenderer.
23135
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
23136
- _inherits(SkinnedMeshRenderer, MeshRenderer);
23137
- function SkinnedMeshRenderer(entity) {
23138
- var _this;
23139
- _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new engineMath.BoundingBox(), _this._jointDataCreateCache = new engineMath.Vector2(-1, -1);
23140
- _this._skin = null;
23141
- var rhi = _this.entity.engine._hardwareRenderer;
23142
- var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
23143
- // Limit size to 256 to avoid some problem:
23144
- // For renderer is "Apple GPU", when uniform is large than 256 the skeleton matrix array access in shader very slow in Safari or WKWebview. This may be a apple bug, Chrome and Firefox is OK!
23145
- // For renderer is "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3011 vs_5_0 ps_5_0, D3011)", compile shader si very slow because of max uniform is 4096.
23146
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
23147
- _this._maxVertexUniformVectors = maxVertexUniformVectors;
23148
- _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
23149
- _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
23150
- var localBounds = _this._localBounds;
23151
- // @ts-ignore
23152
- localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
23153
- // @ts-ignore
23154
- localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
23155
- return _this;
23156
- }
23157
- var _proto = SkinnedMeshRenderer.prototype;
23158
- /**
23159
- * @internal
23160
- */ _proto._onDestroy = function _onDestroy() {
23161
- var _this__jointTexture;
23162
- MeshRenderer.prototype._onDestroy.call(this);
23163
- this._jointDataCreateCache = null;
23164
- this._skin = null;
23165
- this._blendShapeWeights = null;
23166
- this._localBounds = null;
23167
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
23168
- this._jointTexture = null;
23169
- };
23170
- /**
23171
- * @internal
23172
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
23173
- MeshRenderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
23174
- if (this.skin) {
23175
- target._applySkin(null, target.skin);
23176
- }
23177
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
23178
- };
23179
- _proto._update = function _update(context) {
23180
- var skin = this.skin;
23181
- if ((skin == null ? void 0 : skin.bones.length) > 0) {
23182
- skin._updateSkinMatrices(this);
23183
- }
23184
- var shaderData = this.shaderData;
23185
- var mesh = this.mesh;
23186
- var blendShapeManager = mesh._blendShapeManager;
23187
- blendShapeManager._updateShaderData(shaderData, this);
23188
- var bones = skin == null ? void 0 : skin.bones;
23189
- if (bones) {
23190
- var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
23191
- var boneCount = bones.length;
23192
- var boneDataCreateCache = this._jointDataCreateCache;
23193
- var boneCountChange = boneCount !== boneDataCreateCache.x;
23194
- if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
23195
- // directly use max joint count to avoid shader recompile
23196
- var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
23197
- if (boneCount > remainUniformJointCount) {
23198
- var engine = this.engine;
23199
- if (engine._hardwareRenderer.canIUseMoreJoints) {
23200
- if (boneCountChange) {
23201
- var _this__jointTexture;
23202
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
23203
- this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
23204
- this._jointTexture.filterMode = TextureFilterMode.Point;
23205
- this._jointTexture.isGCIgnored = true;
23206
- }
23207
- shaderData.disableMacro("RENDERER_JOINTS_NUM");
23208
- shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
23209
- shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
23210
- } else {
23211
- Logger.error("component's joints count(" + boneCount + ") greater than device's MAX_VERTEX_UNIFORM_VECTORS number " + this._maxVertexUniformVectors + ", and don't support jointTexture in this device. suggest joint count less than " + remainUniformJointCount + ".", this);
23212
- }
23213
- } else {
23214
- var _this__jointTexture1;
23215
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
23216
- shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
23217
- shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
23218
- shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
23219
- }
23220
- boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
23221
- }
23222
- if (this._jointTexture) {
23223
- this._jointTexture.setPixelBuffer(skin._skinMatrices);
23224
- }
23225
- }
23226
- MeshRenderer.prototype._update.call(this, context);
23227
- };
23228
- /**
23229
- * @internal
23230
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
23231
- var _this_skin;
23232
- var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
23233
- if (rootBone) {
23234
- engineMath.BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
23235
- } else {
23236
- MeshRenderer.prototype._updateBounds.call(this, worldBounds);
23237
- }
23238
- };
23239
- _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
23240
- var mesh = this._mesh;
23241
- var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
23242
- var lastBlendShapeWeights = this._blendShapeWeights;
23243
- if (lastBlendShapeWeights) {
23244
- var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
23245
- if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
23246
- var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
23247
- if (newBlendShapeCount > lastBlendShapeWeightsCount) {
23248
- newBlendShapeWeights.set(lastBlendShapeWeights);
23249
- } else {
23250
- for(var i = 0; i < newBlendShapeCount; i++){
23251
- newBlendShapeWeights[i] = lastBlendShapeWeights[i];
23252
- }
23253
- }
23254
- this._blendShapeWeights = newBlendShapeWeights;
23255
- }
23256
- } else {
23257
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
23258
- }
23259
- };
23260
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
23261
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
23262
- };
23263
- _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
23264
- switch(type){
23265
- case SkinUpdateFlag.BoneCountChanged:
23266
- var shaderData = this.shaderData;
23267
- if (value > 0) {
23268
- shaderData.enableMacro("RENDERER_HAS_SKIN");
23269
- shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
23270
- } else {
23271
- shaderData.disableMacro("RENDERER_HAS_SKIN");
23272
- }
23273
- break;
23274
- case SkinUpdateFlag.RootBoneChanged:
23275
- this._setTransformEntity(value);
23276
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
23277
- break;
23513
+ */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
23514
+ var count = children.length - 1;
23515
+ for(var i = entity._siblingIndex; i < count; i++){
23516
+ var child = children[i + 1];
23517
+ children[i] = child;
23518
+ child._siblingIndex = i;
23278
23519
  }
23520
+ children.length = count;
23521
+ entity._siblingIndex = -1;
23279
23522
  };
23280
- _proto._applySkin = function _applySkin(lastSkin, value) {
23281
- var _lastSkin_bones, _value_bones;
23282
- var _lastSkin_bones_length;
23283
- var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
23284
- var _lastSkin_rootBone;
23285
- var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
23286
- lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
23287
- var _value_bones_length;
23288
- var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
23289
- var _value_rootBone;
23290
- var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
23291
- value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
23292
- if (lastSkinBoneCount !== skinBoneCount) {
23293
- this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
23294
- }
23295
- if (lastRootBone !== rootBone) {
23296
- this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
23523
+ /**
23524
+ * @internal
23525
+ */ Entity._addToChildren = function _addToChildren(children, entity, index) {
23526
+ var childCount = children.length;
23527
+ children.length = childCount + 1;
23528
+ if (index === undefined) {
23529
+ children[childCount] = entity;
23530
+ entity._siblingIndex = childCount;
23531
+ } else {
23532
+ if (index < 0 || index > childCount) {
23533
+ throw "The index " + index + " is out of child list bounds " + childCount;
23534
+ }
23535
+ for(var i = childCount; i > index; i--){
23536
+ var swapChild = children[i - 1];
23537
+ swapChild._siblingIndex = i;
23538
+ children[i] = swapChild;
23539
+ }
23540
+ entity._siblingIndex = index;
23541
+ children[index] = entity;
23297
23542
  }
23298
23543
  };
23299
- _create_class(SkinnedMeshRenderer, [
23544
+ _create_class(Entity, [
23300
23545
  {
23301
- key: "skin",
23546
+ key: "transform",
23302
23547
  get: /**
23303
- * Skin of the SkinnedMeshRenderer.
23548
+ * The transform of this entity.
23304
23549
  */ function get() {
23305
- return this._skin;
23306
- },
23307
- set: function set(value) {
23308
- var lastSkin = this._skin;
23309
- if (lastSkin !== value) {
23310
- this._applySkin(lastSkin, value);
23311
- this._skin = value;
23312
- }
23550
+ return this._transform;
23313
23551
  }
23314
23552
  },
23315
23553
  {
23316
- key: "blendShapeWeights",
23554
+ key: "isActive",
23317
23555
  get: /**
23318
- * The weights of the BlendShapes.
23319
- * @remarks Array index is BlendShape index.
23556
+ * Whether to activate locally.
23320
23557
  */ function get() {
23321
- this._checkBlendShapeWeightLength();
23322
- return this._blendShapeWeights;
23558
+ return this._isActive;
23323
23559
  },
23324
23560
  set: function set(value) {
23325
- this._checkBlendShapeWeightLength();
23326
- var blendShapeWeights = this._blendShapeWeights;
23327
- if (value.length <= blendShapeWeights.length) {
23328
- blendShapeWeights.set(value);
23329
- } else {
23330
- for(var i = 0, n = blendShapeWeights.length; i < n; i++){
23331
- blendShapeWeights[i] = value[i];
23561
+ if (value !== this._isActive) {
23562
+ this._isActive = value;
23563
+ if (value) {
23564
+ var parent = this._parent;
23565
+ var activeChangeFlag = ActiveChangeFlag.None;
23566
+ if (this._isRoot && this._scene._isActiveInEngine) {
23567
+ activeChangeFlag |= ActiveChangeFlag.All;
23568
+ } else {
23569
+ (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
23570
+ (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
23571
+ }
23572
+ activeChangeFlag && this._processActive(activeChangeFlag);
23573
+ } else {
23574
+ var activeChangeFlag1 = ActiveChangeFlag.None;
23575
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
23576
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
23577
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
23332
23578
  }
23333
23579
  }
23334
23580
  }
23335
23581
  },
23336
23582
  {
23337
- key: "localBounds",
23583
+ key: "isActiveInHierarchy",
23338
23584
  get: /**
23339
- * Local bounds.
23585
+ * Whether it is active in the hierarchy.
23340
23586
  */ function get() {
23341
- return this._localBounds;
23342
- },
23343
- set: function set(value) {
23344
- if (this._localBounds !== value) {
23345
- this._localBounds.copyFrom(value);
23346
- }
23587
+ return this._isActiveInHierarchy;
23347
23588
  }
23348
23589
  },
23349
23590
  {
23350
- key: "rootBone",
23591
+ key: "parent",
23351
23592
  get: /**
23352
- * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
23593
+ * The parent entity.
23353
23594
  */ function get() {
23354
- return this.skin.rootBone;
23595
+ return this._parent;
23355
23596
  },
23356
23597
  set: function set(value) {
23357
- this.skin.rootBone = value;
23598
+ this._setParent(value);
23358
23599
  }
23359
23600
  },
23360
23601
  {
23361
- key: "bones",
23602
+ key: "children",
23362
23603
  get: /**
23363
- * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
23604
+ * The children entities
23364
23605
  */ function get() {
23365
- return this.skin.bones;
23366
- },
23367
- set: function set(value) {
23368
- this.skin.bones = value;
23369
- }
23370
- }
23371
- ]);
23372
- return SkinnedMeshRenderer;
23373
- }(MeshRenderer);
23374
- // @TODO: different shader type should use different count, not always 48
23375
- /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
23376
- SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
23377
- SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
23378
- SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
23379
- __decorate([
23380
- ignoreClone
23381
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
23382
- __decorate([
23383
- deepClone
23384
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
23385
- __decorate([
23386
- ignoreClone
23387
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
23388
- __decorate([
23389
- ignoreClone
23390
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
23391
- __decorate([
23392
- ignoreClone
23393
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
23394
- __decorate([
23395
- ignoreClone
23396
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
23397
- __decorate([
23398
- deepClone
23399
- ], SkinnedMeshRenderer.prototype, "_skin", void 0);
23400
- __decorate([
23401
- ignoreClone
23402
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
23403
- __decorate([
23404
- ignoreClone
23405
- ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
23406
-
23407
- /**
23408
- * @internal
23409
- */ var BasicResources = /*#__PURE__*/ function() {
23410
- function BasicResources(engine) {
23411
- this.engine = engine;
23412
- // prettier-ignore
23413
- var vertices = new Float32Array([
23414
- -1,
23415
- -1,
23416
- 0,
23417
- 1,
23418
- 3,
23419
- -1,
23420
- 2,
23421
- 1,
23422
- -1,
23423
- 3,
23424
- 0,
23425
- -1
23426
- ]); // left-top
23427
- // prettier-ignore
23428
- var flipYVertices = new Float32Array([
23429
- 3,
23430
- -1,
23431
- 2,
23432
- 0,
23433
- -1,
23434
- -1,
23435
- 0,
23436
- 0,
23437
- -1,
23438
- 3,
23439
- 0,
23440
- 2
23441
- ]); // left-top
23442
- var blitMaterial = new Material(engine, Shader.find("blit"));
23443
- blitMaterial._addReferCount(1);
23444
- blitMaterial.renderState.depthState.enabled = false;
23445
- blitMaterial.renderState.depthState.writeEnabled = false;
23446
- var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
23447
- blitScreenMaterial._addReferCount(1);
23448
- blitScreenMaterial.renderState.depthState.enabled = false;
23449
- blitScreenMaterial.renderState.depthState.writeEnabled = false;
23450
- this.blitMaterial = blitMaterial;
23451
- this.blitScreenMaterial = blitScreenMaterial;
23452
- this.blitMesh = this._createBlitMesh(engine, vertices);
23453
- this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
23454
- // Create white and magenta textures
23455
- var whitePixel = new Uint8Array([
23456
- 255,
23457
- 255,
23458
- 255,
23459
- 255
23460
- ]);
23461
- this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
23462
- this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
23463
- var isWebGL2 = engine._hardwareRenderer.isWebGL2;
23464
- if (isWebGL2) {
23465
- this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
23466
- var whitePixel32 = new Uint32Array([
23467
- 255,
23468
- 255,
23469
- 255,
23470
- 255
23471
- ]);
23472
- this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
23473
- }
23474
- this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
23475
- this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
23476
- this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
23477
- this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
23478
- this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
23479
- }
23480
- var _proto = BasicResources.prototype;
23481
- /**
23482
- * @internal
23483
- */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
23484
- return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
23485
- };
23486
- /**
23487
- * @internal
23488
- */ _proto._initialize = function _initialize() {
23489
- var _this = this;
23490
- return new Promise(function(resolve, reject) {
23491
- PrefilteredDFG.create(_this.engine).then(function(texture) {
23492
- _this._prefilteredDFGTexture = texture;
23493
- resolve(_this);
23494
- }).catch(reject);
23495
- });
23496
- };
23497
- _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
23498
- var mesh = new ModelMesh(engine);
23499
- mesh._addReferCount(1);
23500
- mesh.setVertexElements([
23501
- new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
23502
- ]);
23503
- var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
23504
- mesh.setVertexBufferBinding(buffer, 16);
23505
- mesh.addSubMesh(0, 3, MeshTopology.Triangles);
23506
- engine.resourceManager.addContentRestorer(new (/*#__PURE__*/ function(ContentRestorer) {
23507
- _inherits(_class, ContentRestorer);
23508
- function _class() {
23509
- return ContentRestorer.call(this, mesh) || this;
23510
- }
23511
- var _proto = _class.prototype;
23512
- _proto.restoreContent = function restoreContent() {
23513
- buffer.setData(buffer.data);
23514
- };
23515
- return _class;
23516
- }(ContentRestorer))());
23517
- return mesh;
23518
- };
23519
- _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
23520
- var texture;
23521
- switch(type){
23522
- case 0:
23523
- var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
23524
- texture2D.setPixelBuffer(pixel);
23525
- texture = texture2D;
23526
- break;
23527
- case 2:
23528
- var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
23529
- texture2DArray.setPixelBuffer(0, pixel);
23530
- texture = texture2DArray;
23531
- break;
23532
- case 1:
23533
- var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
23534
- for(var i = 0; i < 6; i++){
23535
- textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
23536
- }
23537
- texture = textureCube;
23538
- break;
23539
- default:
23540
- throw "Invalid texture type";
23541
- }
23542
- texture.isGCIgnored = true;
23543
- engine.resourceManager.addContentRestorer(new (/*#__PURE__*/ function(ContentRestorer) {
23544
- _inherits(_class, ContentRestorer);
23545
- function _class() {
23546
- return ContentRestorer.call(this, texture) || this;
23547
- }
23548
- var _proto = _class.prototype;
23549
- _proto.restoreContent = function restoreContent() {
23550
- switch(type){
23551
- case 0:
23552
- this.resource.setPixelBuffer(pixel);
23553
- break;
23554
- case 2:
23555
- this.resource.setPixelBuffer(0, pixel);
23556
- break;
23557
- case 1:
23558
- for(var i = 0; i < 6; i++){
23559
- this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
23560
- }
23561
- break;
23562
- }
23563
- };
23564
- return _class;
23565
- }(ContentRestorer))());
23566
- return texture;
23567
- };
23568
- _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
23569
- var material = new Material(engine, shader);
23570
- var renderState = material.renderState;
23571
- var target = renderState.blendState.targetBlendState;
23572
- target.enabled = true;
23573
- target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
23574
- target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
23575
- target.sourceAlphaBlendFactor = BlendFactor.One;
23576
- target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
23577
- target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
23578
- renderState.depthState.writeEnabled = false;
23579
- renderState.rasterState.cullMode = CullMode.Off;
23580
- renderState.renderQueueType = RenderQueueType.Transparent;
23581
- material.isGCIgnored = true;
23582
- return material;
23583
- };
23584
- _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
23585
- var material = new Material(engine, Shader.find(shaderName));
23586
- material.isGCIgnored = true;
23587
- material.shaderData.setColor("material_BaseColor", new engineMath.Color(1.0, 0.0, 1.01, 1.0));
23588
- return material;
23589
- };
23590
- _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
23591
- var material = new Material(engine, Shader.find("SpriteMask"));
23592
- material.isGCIgnored = true;
23593
- return material;
23594
- };
23595
- BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
23596
- var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
23597
- var renderStates;
23598
- var compareFunction;
23599
- if (visibleInsideMask) {
23600
- renderStates = BasicResources._maskReadInsideRenderStates;
23601
- if (renderStates) {
23602
- return renderStates;
23603
- }
23604
- BasicResources._maskReadInsideRenderStates = renderStates = {};
23605
- compareFunction = CompareFunction.LessEqual;
23606
- } else {
23607
- renderStates = BasicResources._maskReadOutsideRenderStates;
23608
- if (renderStates) {
23609
- return renderStates;
23606
+ return this._children;
23610
23607
  }
23611
- BasicResources._maskReadOutsideRenderStates = renderStates = {};
23612
- compareFunction = CompareFunction.Greater;
23613
- }
23614
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
23615
- renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
23616
- renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
23617
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
23618
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
23619
- return renderStates;
23620
- };
23621
- BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
23622
- var isIncrement = maskType === RenderQueueMaskType.Increment;
23623
- var renderStates;
23624
- var passOperation;
23625
- if (isIncrement) {
23626
- renderStates = BasicResources._maskWriteIncrementRenderStates;
23627
- if (renderStates) {
23628
- return renderStates;
23608
+ },
23609
+ {
23610
+ key: "childCount",
23611
+ get: /**
23612
+ * @deprecated Please use `children.length` property instead.
23613
+ * Number of the children entities
23614
+ */ function get() {
23615
+ return this._children.length;
23629
23616
  }
23630
- BasicResources._maskWriteIncrementRenderStates = renderStates = {};
23631
- passOperation = StencilOperation.IncrementSaturate;
23632
- } else {
23633
- renderStates = BasicResources._maskWriteDecrementRenderStates;
23634
- if (renderStates) {
23635
- return renderStates;
23617
+ },
23618
+ {
23619
+ key: "scene",
23620
+ get: /**
23621
+ * The scene the entity belongs to.
23622
+ */ function get() {
23623
+ return this._scene;
23636
23624
  }
23637
- BasicResources._maskWriteDecrementRenderStates = renderStates = {};
23638
- passOperation = StencilOperation.DecrementSaturate;
23639
- }
23640
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
23641
- renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
23642
- renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
23643
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
23644
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
23645
- var failStencilOperation = StencilOperation.Keep;
23646
- renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
23647
- renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
23648
- renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
23649
- renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
23650
- renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
23651
- renderStates[RenderStateElementKey.DepthStateEnabled] = false;
23652
- renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
23653
- return renderStates;
23654
- };
23655
- _create_class(BasicResources, [
23625
+ },
23656
23626
  {
23657
- key: "prefilteredDFGTexture",
23658
- get: function get() {
23659
- return this._prefilteredDFGTexture;
23627
+ key: "siblingIndex",
23628
+ get: /**
23629
+ * The sibling index.
23630
+ */ function get() {
23631
+ return this._siblingIndex;
23632
+ },
23633
+ set: function set(value) {
23634
+ if (this._siblingIndex === -1) {
23635
+ throw "The entity " + this.name + " is not in the hierarchy";
23636
+ }
23637
+ if (this._isRoot) {
23638
+ this._setSiblingIndex(this._scene._rootEntities, value);
23639
+ } else {
23640
+ var parent = this._parent;
23641
+ this._setSiblingIndex(parent._children, value);
23642
+ parent._dispatchModify(EntityModifyFlags.Child, parent);
23643
+ }
23660
23644
  }
23661
23645
  }
23662
23646
  ]);
23663
- return BasicResources;
23664
- }();
23665
- BasicResources._maskReadInsideRenderStates = null;
23666
- BasicResources._maskReadOutsideRenderStates = null;
23667
- BasicResources._maskWriteIncrementRenderStates = null;
23668
- BasicResources._maskWriteDecrementRenderStates = null;
23647
+ return Entity;
23648
+ }(EngineObject);
23649
+ /** @internal */ Entity._tempComponentConstructors = [];
23669
23650
 
23670
23651
  var ObjectPool = /*#__PURE__*/ function() {
23671
23652
  function ObjectPool(type) {
@@ -29030,6 +29011,184 @@ var PointerMethods = /*#__PURE__*/ function(PointerMethods) {
29030
29011
  return PointerMethods;
29031
29012
  }({});
29032
29013
 
29014
+ /**
29015
+ * Signal is a typed event mechanism for Galacean Engine.
29016
+ * @typeParam T - Tuple type of the signal arguments
29017
+ */ var Signal = /*#__PURE__*/ function() {
29018
+ function Signal() {
29019
+ this._listeners = new SafeLoopArray();
29020
+ }
29021
+ var _proto = Signal.prototype;
29022
+ _proto.on = function on(fnOrTarget, targetOrMethodName) {
29023
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
29024
+ args[_key - 2] = arguments[_key];
29025
+ }
29026
+ this._addListener.apply(this, [].concat([
29027
+ fnOrTarget,
29028
+ targetOrMethodName,
29029
+ false
29030
+ ], args));
29031
+ };
29032
+ _proto.once = function once(fnOrTarget, targetOrMethodName) {
29033
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
29034
+ args[_key - 2] = arguments[_key];
29035
+ }
29036
+ this._addListener.apply(this, [].concat([
29037
+ fnOrTarget,
29038
+ targetOrMethodName,
29039
+ true
29040
+ ], args));
29041
+ };
29042
+ _proto.off = function off(fnOrTarget, targetOrMethodName) {
29043
+ if (typeof fnOrTarget === "function") {
29044
+ var target = targetOrMethodName != null ? targetOrMethodName : null;
29045
+ this._listeners.findAndRemove(function(listener) {
29046
+ if (listener.fn === fnOrTarget && listener.target === target) {
29047
+ listener.destroyed = true;
29048
+ return true;
29049
+ }
29050
+ return false;
29051
+ });
29052
+ } else {
29053
+ var target1 = fnOrTarget;
29054
+ var methodName = targetOrMethodName;
29055
+ this._listeners.findAndRemove(function(listener) {
29056
+ if (listener.target === target1 && listener.methodName === methodName) {
29057
+ listener.destroyed = true;
29058
+ return true;
29059
+ }
29060
+ return false;
29061
+ });
29062
+ }
29063
+ };
29064
+ /**
29065
+ * Remove all listeners, or all listeners for a specific target.
29066
+ * @param target - If provided, only remove listeners bound to this target
29067
+ */ _proto.removeAll = function removeAll(target) {
29068
+ if (target !== undefined) {
29069
+ this._listeners.findAndRemove(function(listener) {
29070
+ if (listener.target === target) {
29071
+ return listener.destroyed = true;
29072
+ }
29073
+ return false;
29074
+ });
29075
+ } else {
29076
+ this._listeners.findAndRemove(function(listener) {
29077
+ return listener.destroyed = true;
29078
+ });
29079
+ }
29080
+ };
29081
+ /**
29082
+ * Invoke the signal, calling all listeners in order.
29083
+ * @param args - Arguments to pass to each listener
29084
+ */ _proto.invoke = function invoke() {
29085
+ var _this, _loop = function(i, n) {
29086
+ var listener = listeners[i];
29087
+ if (listener.destroyed) return "continue";
29088
+ if (listener.methodName && listener.target.destroyed) {
29089
+ listener.destroyed = true;
29090
+ _this._listeners.findAndRemove(function(l) {
29091
+ return l === listener;
29092
+ });
29093
+ return "continue";
29094
+ }
29095
+ listener.fn.apply(listener.target, args);
29096
+ if (listener.once) {
29097
+ listener.destroyed = true;
29098
+ _this._listeners.findAndRemove(function(l) {
29099
+ return l === listener;
29100
+ });
29101
+ }
29102
+ };
29103
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
29104
+ args[_key] = arguments[_key];
29105
+ }
29106
+ var listeners = this._listeners.getLoopArray();
29107
+ for(var i = 0, n = listeners.length; i < n; i++)_this = this, _loop(i);
29108
+ };
29109
+ /**
29110
+ * @internal
29111
+ * Clone listeners to target signal, remapping entity/component references.
29112
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
29113
+ var listeners = this._listeners.getLoopArray();
29114
+ for(var i = 0, n = listeners.length; i < n; i++){
29115
+ var listener = listeners[i];
29116
+ if (listener.destroyed || !listener.methodName) continue;
29117
+ var clonedTarget = CloneUtils.remapComponent(srcRoot, targetRoot, listener.target);
29118
+ if (clonedTarget) {
29119
+ var clonedArgs = this._cloneArguments(listener.arguments, srcRoot, targetRoot);
29120
+ if (listener.once) {
29121
+ var _target;
29122
+ (_target = target).once.apply(_target, [].concat([
29123
+ clonedTarget,
29124
+ listener.methodName
29125
+ ], clonedArgs));
29126
+ } else {
29127
+ var _target1;
29128
+ (_target1 = target).on.apply(_target1, [].concat([
29129
+ clonedTarget,
29130
+ listener.methodName
29131
+ ], clonedArgs));
29132
+ }
29133
+ }
29134
+ }
29135
+ };
29136
+ _proto._cloneArguments = function _cloneArguments(args, srcRoot, targetRoot) {
29137
+ if (!args || args.length === 0) return [];
29138
+ var len = args.length;
29139
+ var clonedArgs = new Array(len);
29140
+ for(var i = 0; i < len; i++){
29141
+ var arg = args[i];
29142
+ if (_instanceof(arg, Entity)) {
29143
+ clonedArgs[i] = CloneUtils.remapEntity(srcRoot, targetRoot, arg);
29144
+ } else if (_instanceof(arg, Component)) {
29145
+ clonedArgs[i] = CloneUtils.remapComponent(srcRoot, targetRoot, arg);
29146
+ } else {
29147
+ clonedArgs[i] = arg;
29148
+ }
29149
+ }
29150
+ return clonedArgs;
29151
+ };
29152
+ _proto._addListener = function _addListener(fnOrTarget, targetOrMethodName, once) {
29153
+ for(var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
29154
+ args[_key - 3] = arguments[_key];
29155
+ }
29156
+ if (typeof fnOrTarget === "function") {
29157
+ this._listeners.push({
29158
+ fn: fnOrTarget,
29159
+ target: targetOrMethodName != null ? targetOrMethodName : null,
29160
+ once: once
29161
+ });
29162
+ } else {
29163
+ var _target, _target1;
29164
+ var target = fnOrTarget;
29165
+ var methodName = targetOrMethodName;
29166
+ var fn = args.length > 0 ? function() {
29167
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
29168
+ signalArgs[_key] = arguments[_key];
29169
+ }
29170
+ return (_target = target)[methodName].apply(_target, [].concat(args, signalArgs));
29171
+ } : function() {
29172
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
29173
+ signalArgs[_key] = arguments[_key];
29174
+ }
29175
+ return (_target1 = target)[methodName].apply(_target1, [].concat(signalArgs));
29176
+ };
29177
+ this._listeners.push({
29178
+ fn: fn,
29179
+ target: target,
29180
+ once: once,
29181
+ methodName: methodName,
29182
+ arguments: args
29183
+ });
29184
+ }
29185
+ };
29186
+ return Signal;
29187
+ }();
29188
+ __decorate([
29189
+ ignoreClone
29190
+ ], Signal.prototype, "_listeners", void 0);
29191
+
29033
29192
  /**
29034
29193
  * Loader abstract class.
29035
29194
  */ var Loader = /*#__PURE__*/ function() {
@@ -31148,7 +31307,7 @@ function _type_of(obj) {
31148
31307
  };
31149
31308
  /**
31150
31309
  * @internal
31151
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
31310
+ */ _proto._cloneTo = function _cloneTo(target) {
31152
31311
  var animatorController = target._animatorController;
31153
31312
  if (animatorController) {
31154
31313
  target._addResourceReferCount(animatorController, 1);
@@ -36299,9 +36458,6 @@ __decorate([
36299
36458
  __decorate([
36300
36459
  ignoreClone
36301
36460
  ], ParticleGenerator.prototype, "_subPrimitive", void 0);
36302
- __decorate([
36303
- ignoreClone
36304
- ], ParticleGenerator.prototype, "_renderer", void 0);
36305
36461
  __decorate([
36306
36462
  ignoreClone
36307
36463
  ], ParticleGenerator.prototype, "_isPlaying", void 0);
@@ -37040,7 +37196,7 @@ ConeShape._tempVector31 = new engineMath.Vector3();
37040
37196
  };
37041
37197
  /**
37042
37198
  * @internal
37043
- */ _proto._cloneTo = function _cloneTo(target, _, __) {
37199
+ */ _proto._cloneTo = function _cloneTo(target) {
37044
37200
  target.mesh = this._mesh;
37045
37201
  };
37046
37202
  _create_class(MeshShape, [
@@ -38020,7 +38176,7 @@ AudioManager._needsUserGestureResume = false;
38020
38176
  };
38021
38177
  /**
38022
38178
  * @internal
38023
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
38179
+ */ _proto._cloneTo = function _cloneTo(target) {
38024
38180
  var _target__clip;
38025
38181
  (_target__clip = target._clip) == null ? void 0 : _target__clip._addReferCount(1);
38026
38182
  target._gainNode.gain.setValueAtTime(target._volume, AudioManager.getContext().currentTime);
@@ -38402,6 +38558,7 @@ exports.CharacterController = CharacterController;
38402
38558
  exports.CircleShape = CircleShape;
38403
38559
  exports.ClearableObjectPool = ClearableObjectPool;
38404
38560
  exports.CloneManager = CloneManager;
38561
+ exports.CloneUtils = CloneUtils;
38405
38562
  exports.ColliderShape = ColliderShape;
38406
38563
  exports.ColliderShapeUpAxis = ColliderShapeUpAxis;
38407
38564
  exports.Collision = Collision;
@@ -38555,6 +38712,7 @@ exports.ShaderTagKey = ShaderTagKey;
38555
38712
  exports.ShadowCascadesMode = ShadowCascadesMode;
38556
38713
  exports.ShadowResolution = ShadowResolution;
38557
38714
  exports.ShadowType = ShadowType;
38715
+ exports.Signal = Signal;
38558
38716
  exports.SizeOverLifetimeModule = SizeOverLifetimeModule;
38559
38717
  exports.Skin = Skin;
38560
38718
  exports.SkinnedMeshRenderer = SkinnedMeshRenderer;