@galacean/engine 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/browser.js CHANGED
@@ -988,11 +988,15 @@
988
988
  var normal = plane.normal;
989
989
  var zeroTolerance = MathUtil.zeroTolerance;
990
990
  var dir = Vector3.dot(normal, ray.direction);
991
+ var position = Vector3.dot(normal, ray.origin);
991
992
  // Parallel
992
993
  if (Math.abs(dir) < zeroTolerance) {
994
+ // Check if ray origin is on the plane
995
+ if (Math.abs(position + plane.distance) < zeroTolerance) {
996
+ return 0;
997
+ }
993
998
  return -1;
994
999
  }
995
- var position = Vector3.dot(normal, ray.origin);
996
1000
  var distance = (-plane.distance - position) / dir;
997
1001
  if (distance < 0) {
998
1002
  if (distance < -zeroTolerance) {
@@ -5320,74 +5324,69 @@
5320
5324
  return cloneModes;
5321
5325
  };
5322
5326
  CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode, srcRoot, targetRoot, deepInstanceMap) {
5323
- if (cloneMode === CloneMode.Ignore) {
5327
+ var sourceProperty = source[k];
5328
+ // Remappable references (Entity/Component) are always remapped, regardless of clone decorator
5329
+ if (_instanceof1$2(sourceProperty, Object) && sourceProperty._remap) {
5330
+ target[k] = sourceProperty._remap(srcRoot, targetRoot);
5324
5331
  return;
5325
5332
  }
5326
- var sourceProperty = source[k];
5327
- if (_instanceof1$2(sourceProperty, Object)) {
5328
- if (cloneMode === undefined || cloneMode === CloneMode.Assignment) {
5329
- target[k] = sourceProperty;
5330
- return;
5331
- }
5332
- var type = sourceProperty.constructor;
5333
- switch(type){
5334
- case Uint8Array:
5335
- case Uint16Array:
5336
- case Uint32Array:
5337
- case Int8Array:
5338
- case Int16Array:
5339
- case Int32Array:
5340
- case Float32Array:
5341
- case Float64Array:
5342
- var targetPropertyT = target[k];
5343
- if (targetPropertyT == null || targetPropertyT.length !== sourceProperty.length) {
5344
- target[k] = sourceProperty.slice();
5345
- } else {
5346
- targetPropertyT.set(sourceProperty);
5347
- }
5348
- break;
5349
- case Array:
5350
- var targetPropertyA = target[k];
5351
- var length = sourceProperty.length;
5352
- if (targetPropertyA == null) {
5353
- target[k] = targetPropertyA = new Array(length);
5354
- } else {
5355
- targetPropertyA.length = length;
5356
- }
5357
- for(var i = 0; i < length; i++){
5358
- CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
5359
- }
5360
- break;
5361
- default:
5362
- var targetProperty = target[k];
5363
- // If the target property is undefined, create new instance and keep reference sharing like the source
5333
+ if (cloneMode === CloneMode.Ignore) return;
5334
+ // Primitives, undecorated, or @assignmentClone: direct assign
5335
+ if (!_instanceof1$2(sourceProperty, Object) || cloneMode === undefined || cloneMode === CloneMode.Assignment) {
5336
+ target[k] = sourceProperty;
5337
+ return;
5338
+ }
5339
+ // @shallowClone / @deepClone: deep copy complex objects
5340
+ var type = sourceProperty.constructor;
5341
+ switch(type){
5342
+ case Uint8Array:
5343
+ case Uint16Array:
5344
+ case Uint32Array:
5345
+ case Int8Array:
5346
+ case Int16Array:
5347
+ case Int32Array:
5348
+ case Float32Array:
5349
+ case Float64Array:
5350
+ var targetPropertyT = target[k];
5351
+ if (targetPropertyT == null || targetPropertyT.length !== sourceProperty.length) {
5352
+ target[k] = sourceProperty.slice();
5353
+ } else {
5354
+ targetPropertyT.set(sourceProperty);
5355
+ }
5356
+ break;
5357
+ case Array:
5358
+ var targetPropertyA = target[k];
5359
+ var length = sourceProperty.length;
5360
+ if (targetPropertyA == null) {
5361
+ target[k] = targetPropertyA = new Array(length);
5362
+ } else {
5363
+ targetPropertyA.length = length;
5364
+ }
5365
+ for(var i = 0; i < length; i++){
5366
+ CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
5367
+ }
5368
+ break;
5369
+ default:
5370
+ var targetProperty = target[k];
5371
+ // If the target property is undefined, create new instance and keep reference sharing like the source
5372
+ if (!targetProperty) {
5373
+ targetProperty = deepInstanceMap.get(sourceProperty);
5364
5374
  if (!targetProperty) {
5365
- targetProperty = deepInstanceMap.get(sourceProperty);
5366
- if (!targetProperty) {
5367
- targetProperty = new sourceProperty.constructor();
5368
- deepInstanceMap.set(sourceProperty, targetProperty);
5369
- }
5370
- target[k] = targetProperty;
5375
+ targetProperty = new sourceProperty.constructor();
5376
+ deepInstanceMap.set(sourceProperty, targetProperty);
5371
5377
  }
5372
- if (sourceProperty.copyFrom) {
5373
- // Custom clone
5374
- targetProperty.copyFrom(sourceProperty);
5375
- } else {
5376
- // Universal clone
5377
- var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5378
- for(var _$k in sourceProperty){
5379
- CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
5380
- }
5381
- // Custom incremental clone
5382
- if (sourceProperty._cloneTo) {
5383
- sourceProperty._cloneTo(targetProperty, srcRoot, targetRoot);
5384
- }
5378
+ target[k] = targetProperty;
5379
+ }
5380
+ if (sourceProperty.copyFrom) {
5381
+ targetProperty.copyFrom(sourceProperty);
5382
+ } else {
5383
+ var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5384
+ for(var _$k in sourceProperty){
5385
+ CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
5385
5386
  }
5386
- break;
5387
- }
5388
- } else {
5389
- // null, undefined, primitive type, function
5390
- target[k] = sourceProperty;
5387
+ sourceProperty._cloneTo == null ? void 0 : sourceProperty._cloneTo.call(sourceProperty, targetProperty, srcRoot, targetRoot);
5388
+ }
5389
+ break;
5391
5390
  }
5392
5391
  };
5393
5392
  CloneManager.deepCloneObject = function deepCloneObject(source, target, deepInstanceMap) {
@@ -12334,6 +12333,44 @@
12334
12333
  return Background;
12335
12334
  }();
12336
12335
  /** @internal */ Background._premultiplySolidColor = new Color();
12336
+ /**
12337
+ * @internal
12338
+ * Utility functions for remapping Entity/Component references during cloning.
12339
+ */ var CloneUtils = /*#__PURE__*/ function() {
12340
+ function CloneUtils() {}
12341
+ CloneUtils.remapEntity = function remapEntity(srcRoot, targetRoot, entity) {
12342
+ var path = CloneUtils._tempRemapPath;
12343
+ if (!CloneUtils._getEntityHierarchyPath(srcRoot, entity, path)) return entity;
12344
+ return CloneUtils._getEntityByHierarchyPath(targetRoot, path);
12345
+ };
12346
+ CloneUtils.remapComponent = function remapComponent(srcRoot, targetRoot, component) {
12347
+ var path = CloneUtils._tempRemapPath;
12348
+ var srcEntity = component.entity;
12349
+ if (!CloneUtils._getEntityHierarchyPath(srcRoot, srcEntity, path)) return component;
12350
+ return CloneUtils._getEntityByHierarchyPath(targetRoot, path)._components[srcEntity._components.indexOf(component)];
12351
+ };
12352
+ CloneUtils._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
12353
+ inversePath.length = 0;
12354
+ while(searchEntity !== rootEntity){
12355
+ var parent = searchEntity.parent;
12356
+ if (!parent) {
12357
+ return false;
12358
+ }
12359
+ inversePath.push(searchEntity.siblingIndex);
12360
+ searchEntity = parent;
12361
+ }
12362
+ return true;
12363
+ };
12364
+ CloneUtils._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
12365
+ var entity = rootEntity;
12366
+ for(var i = inversePath.length - 1; i >= 0; i--){
12367
+ entity = entity.children[inversePath[i]];
12368
+ }
12369
+ return entity;
12370
+ };
12371
+ return CloneUtils;
12372
+ }();
12373
+ CloneUtils._tempRemapPath = [];
12337
12374
  var ActiveChangeFlag = /*#__PURE__*/ function(ActiveChangeFlag) {
12338
12375
  ActiveChangeFlag[ActiveChangeFlag["None"] = 0] = "None";
12339
12376
  ActiveChangeFlag[ActiveChangeFlag["Scene"] = 1] = "Scene";
@@ -12408,6 +12445,11 @@
12408
12445
  }
12409
12446
  }
12410
12447
  };
12448
+ /**
12449
+ * @internal
12450
+ */ _proto._remap = function _remap(srcRoot, targetRoot) {
12451
+ return CloneUtils.remapComponent(srcRoot, targetRoot, this);
12452
+ };
12411
12453
  _proto._addResourceReferCount = function _addResourceReferCount(resource, count) {
12412
12454
  this._entity._isTemplate || resource._addReferCount(count);
12413
12455
  };
@@ -12481,9 +12523,6 @@
12481
12523
  ]);
12482
12524
  return Component;
12483
12525
  }(EngineObject);
12484
- __decorate$1([
12485
- ignoreClone
12486
- ], Component.prototype, "_entity", void 0);
12487
12526
  __decorate$1([
12488
12527
  ignoreClone
12489
12528
  ], Component.prototype, "_awoken", void 0);
@@ -12847,7 +12886,7 @@
12847
12886
  };
12848
12887
  /**
12849
12888
  * @internal
12850
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
12889
+ */ _proto._cloneTo = function _cloneTo(target) {
12851
12890
  var position = target._position, rotation = target._rotation, scale = target._scale;
12852
12891
  // @ts-ignore
12853
12892
  position._onValueChanged = rotation._onValueChanged = scale._onValueChanged = null;
@@ -13459,9 +13498,6 @@
13459
13498
  __decorate$1([
13460
13499
  ignoreClone
13461
13500
  ], Transform.prototype, "_isParentDirty", void 0);
13462
- __decorate$1([
13463
- ignoreClone
13464
- ], Transform.prototype, "_parentTransformCache", void 0);
13465
13501
  __decorate$1([
13466
13502
  ignoreClone
13467
13503
  ], Transform.prototype, "_dirtyFlag", void 0);
@@ -13920,7 +13956,7 @@
13920
13956
  };
13921
13957
  /**
13922
13958
  * @internal
13923
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
13959
+ */ _proto._cloneTo = function _cloneTo(target) {
13924
13960
  var _this__renderTarget;
13925
13961
  (_this__renderTarget = this._renderTarget) == null ? void 0 : _this__renderTarget._addReferCount(1);
13926
13962
  };
@@ -17123,9 +17159,6 @@
17123
17159
  return ColliderShape;
17124
17160
  }();
17125
17161
  ColliderShape._idGenerator = 0;
17126
- __decorate$1([
17127
- ignoreClone
17128
- ], ColliderShape.prototype, "_collider", void 0);
17129
17162
  __decorate$1([
17130
17163
  ignoreClone
17131
17164
  ], ColliderShape.prototype, "_nativeShape", void 0);
@@ -21507,7 +21540,7 @@
21507
21540
  };
21508
21541
  /**
21509
21542
  * @internal
21510
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
21543
+ */ _proto._cloneTo = function _cloneTo(target) {
21511
21544
  var materials = this._materials;
21512
21545
  for(var i = 0, n = materials.length; i < n; i++){
21513
21546
  target._setMaterial(i, materials[i]);
@@ -21762,9 +21795,6 @@
21762
21795
  __decorate$1([
21763
21796
  ignoreClone
21764
21797
  ], exports.Renderer.prototype, "_bounds", void 0);
21765
- __decorate$1([
21766
- ignoreClone
21767
- ], exports.Renderer.prototype, "_transformEntity", void 0);
21768
21798
  __decorate$1([
21769
21799
  deepClone
21770
21800
  ], exports.Renderer.prototype, "_shaderData", void 0);
@@ -21823,8 +21853,8 @@
21823
21853
  };
21824
21854
  /**
21825
21855
  * @internal
21826
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
21827
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
21856
+ */ _proto._cloneTo = function _cloneTo(target) {
21857
+ Renderer.prototype._cloneTo.call(this, target);
21828
21858
  target.sprite = this._sprite;
21829
21859
  };
21830
21860
  /**
@@ -22134,8 +22164,8 @@
22134
22164
  };
22135
22165
  /**
22136
22166
  * @internal
22137
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
22138
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
22167
+ */ _proto._cloneTo = function _cloneTo(target) {
22168
+ Renderer.prototype._cloneTo.call(this, target);
22139
22169
  target.sprite = this._sprite;
22140
22170
  target.drawMode = this._drawMode;
22141
22171
  };
@@ -22557,8 +22587,8 @@
22557
22587
  };
22558
22588
  /**
22559
22589
  * @internal
22560
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
22561
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
22590
+ */ _proto._cloneTo = function _cloneTo(target) {
22591
+ Renderer.prototype._cloneTo.call(this, target);
22562
22592
  target.font = this._font;
22563
22593
  target._subFont = this._subFont;
22564
22594
  };
@@ -24240,8 +24270,8 @@
24240
24270
  };
24241
24271
  /**
24242
24272
  * @internal
24243
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
24244
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
24273
+ */ _proto._cloneTo = function _cloneTo(target) {
24274
+ Renderer.prototype._cloneTo.call(this, target);
24245
24275
  target.mesh = this._mesh;
24246
24276
  };
24247
24277
  /**
@@ -27096,224 +27126,861 @@
27096
27126
  ]);
27097
27127
  PrimitiveMesh._sphereEdgeIdx = 0;
27098
27128
  PrimitiveMesh._spherePoleIdx = 0;
27099
- function _is_native_reflect_construct$1() {
27100
- // Since Reflect.construct can't be properly polyfilled, some
27101
- // implementations (e.g. core-js@2) don't set the correct internal slots.
27102
- // Those polyfills don't allow us to subclass built-ins, so we need to
27103
- // use our fallback implementation.
27104
- try {
27105
- // If the internal slots aren't set, this throws an error similar to
27106
- // TypeError: this is not a Boolean object.
27107
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
27108
- } catch (_) {}
27109
- return (_is_native_reflect_construct$1 = function _is_native_reflect_construct() {
27110
- return !!result;
27111
- })();
27112
- }
27113
- function _construct$1(Parent, args, Class) {
27114
- if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
27115
- else {
27116
- _construct$1 = function construct(Parent, args, Class) {
27117
- var a = [
27118
- null
27119
- ];
27120
- a.push.apply(a, args);
27121
- var Constructor = Function.bind.apply(Parent, a);
27122
- var instance = new Constructor();
27123
- if (Class) _set_prototype_of$2(instance, Class.prototype);
27124
- return instance;
27125
- };
27129
+ /**
27130
+ * Skin used for skinned mesh renderer.
27131
+ */ var Skin = /*#__PURE__*/ function(EngineObject) {
27132
+ _inherits$2(Skin, EngineObject);
27133
+ function Skin(name) {
27134
+ var _this;
27135
+ _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 = [];
27136
+ return _this;
27126
27137
  }
27127
- return _construct$1.apply(null, arguments);
27128
- }
27129
- var ComponentCloner = /*#__PURE__*/ function() {
27130
- function ComponentCloner() {}
27138
+ var _proto = Skin.prototype;
27131
27139
  /**
27132
- * Clone component.
27133
- * @param source - Clone source
27134
- * @param target - Clone target
27135
- */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
27136
- var cloneModes = CloneManager.getCloneMode(source.constructor);
27137
- for(var k in source){
27138
- CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
27140
+ * @internal
27141
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
27142
+ if (this._updateMark === renderer.engine.time.frameCount) {
27143
+ return;
27139
27144
  }
27140
- if (source._cloneTo) {
27141
- source._cloneTo(target, srcRoot, targetRoot);
27145
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
27146
+ var _this_rootBone;
27147
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
27148
+ for(var i = bones.length - 1; i >= 0; i--){
27149
+ var bone = bones[i];
27150
+ var offset = i * 16;
27151
+ if (bone) {
27152
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
27153
+ } else {
27154
+ skinMatrices.set(bindMatrices[i].elements, offset);
27155
+ }
27156
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
27142
27157
  }
27158
+ this._updateMark = renderer.engine.time.frameCount;
27143
27159
  };
27144
- return ComponentCloner;
27145
- }();
27146
- /**
27147
- * The entity modify flags.
27148
- */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
27149
- /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
27150
- /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
27151
- return EntityModifyFlags;
27160
+ _create_class$2(Skin, [
27161
+ {
27162
+ key: "rootBone",
27163
+ get: /**
27164
+ * Root bone.
27165
+ */ function get() {
27166
+ return this._rootBone;
27167
+ },
27168
+ set: function set(value) {
27169
+ if (this._rootBone !== value) {
27170
+ this._updatedManager.dispatch(1, value);
27171
+ this._rootBone = value;
27172
+ }
27173
+ }
27174
+ },
27175
+ {
27176
+ key: "bones",
27177
+ get: /**
27178
+ * Bones of the skin.
27179
+ */ function get() {
27180
+ return this._bones;
27181
+ },
27182
+ set: function set(value) {
27183
+ var bones = this._bones;
27184
+ var _value_length;
27185
+ var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
27186
+ var lastBoneCount = bones.length;
27187
+ bones.length = boneCount;
27188
+ for(var i = 0; i < boneCount; i++){
27189
+ bones[i] = value[i];
27190
+ }
27191
+ if (lastBoneCount !== boneCount) {
27192
+ this._skinMatrices = new Float32Array(boneCount * 16);
27193
+ this._updatedManager.dispatch(0, boneCount);
27194
+ }
27195
+ }
27196
+ },
27197
+ {
27198
+ key: "skeleton",
27199
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
27200
+ var _this_rootBone;
27201
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
27202
+ },
27203
+ set: function set(value) {
27204
+ var rootBone = this._rootBone;
27205
+ if (rootBone) {
27206
+ rootBone.name = value;
27207
+ }
27208
+ }
27209
+ }
27210
+ ]);
27211
+ return Skin;
27212
+ }(EngineObject);
27213
+ __decorate$1([
27214
+ deepClone
27215
+ ], Skin.prototype, "inverseBindMatrices", void 0);
27216
+ __decorate$1([
27217
+ ignoreClone
27218
+ ], Skin.prototype, "_skinMatrices", void 0);
27219
+ __decorate$1([
27220
+ ignoreClone
27221
+ ], Skin.prototype, "_updatedManager", void 0);
27222
+ __decorate$1([
27223
+ deepClone
27224
+ ], Skin.prototype, "_bones", void 0);
27225
+ __decorate$1([
27226
+ ignoreClone
27227
+ ], Skin.prototype, "_updateMark", void 0);
27228
+ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
27229
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
27230
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
27231
+ return SkinUpdateFlag;
27152
27232
  }({});
27153
27233
  /**
27154
- * Entity, be used as components container.
27155
- */ var Entity = /*#__PURE__*/ function(EngineObject) {
27156
- _inherits$2(Entity, EngineObject);
27157
- function Entity(engine, name) {
27158
- for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
27159
- components[_key - 2] = arguments[_key];
27160
- }
27234
+ * SkinnedMeshRenderer.
27235
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
27236
+ _inherits$2(SkinnedMeshRenderer, MeshRenderer);
27237
+ function SkinnedMeshRenderer(entity) {
27161
27238
  var _this;
27162
- _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, _this._invModelMatrix = new Matrix();
27163
- _this.name = name != null ? name : "Entity";
27164
- for(var i = 0, n = components.length; i < n; i++){
27165
- _this.addComponent(components[i]);
27166
- }
27167
- !_this._transform && _this.addComponent(Transform);
27168
- _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
27239
+ _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new BoundingBox(), _this._jointDataCreateCache = new Vector2(-1, -1);
27240
+ _this._skin = null;
27241
+ var rhi = _this.entity.engine._hardwareRenderer;
27242
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
27243
+ // Limit size to 256 to avoid some problem:
27244
+ // 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!
27245
+ // 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.
27246
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
27247
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
27248
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
27249
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
27250
+ var localBounds = _this._localBounds;
27251
+ // @ts-ignore
27252
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
27253
+ // @ts-ignore
27254
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
27169
27255
  return _this;
27170
27256
  }
27171
- var _proto = Entity.prototype;
27257
+ var _proto = SkinnedMeshRenderer.prototype;
27172
27258
  /**
27173
- * Add component based on the component type.
27174
- * @param type - The type of the component
27175
- * @param args - The arguments of the component
27176
- * @returns The component which has been added
27177
- */ _proto.addComponent = function addComponent(type) {
27178
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
27179
- args[_key - 1] = arguments[_key];
27180
- }
27181
- ComponentsDependencies._addCheck(this, type);
27182
- var component = _construct$1(type, [].concat([
27183
- this
27184
- ], args));
27185
- this._components.push(component);
27186
- // @todo: temporary solution
27187
- if (_instanceof1$2(component, Transform)) this._setTransform(component);
27188
- component._setActive(true, ActiveChangeFlag.All);
27189
- return component;
27259
+ * @internal
27260
+ */ _proto._onDestroy = function _onDestroy() {
27261
+ var _this__jointTexture;
27262
+ MeshRenderer.prototype._onDestroy.call(this);
27263
+ this._jointDataCreateCache = null;
27264
+ this._skin = null;
27265
+ this._blendShapeWeights = null;
27266
+ this._localBounds = null;
27267
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27268
+ this._jointTexture = null;
27190
27269
  };
27191
27270
  /**
27192
- * Get component which match the type.
27193
- * @param type - The type of the component
27194
- * @returns The first component which match type
27195
- */ _proto.getComponent = function getComponent(type) {
27196
- var components = this._components;
27197
- for(var i = 0, n = components.length; i < n; i++){
27198
- var component = components[i];
27199
- if (_instanceof1$2(component, type)) {
27200
- return component;
27201
- }
27271
+ * @internal
27272
+ */ _proto._cloneTo = function _cloneTo(target) {
27273
+ MeshRenderer.prototype._cloneTo.call(this, target);
27274
+ if (this.skin) {
27275
+ target._applySkin(null, target.skin);
27202
27276
  }
27203
- return null;
27277
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
27204
27278
  };
27205
- /**
27206
- * Get components which match the type.
27207
- * @param type - The type of the component
27208
- * @param results - The components which match type
27209
- * @returns The components which match type
27210
- */ _proto.getComponents = function getComponents(type, results) {
27211
- results.length = 0;
27212
- var components = this._components;
27213
- for(var i = 0, n = components.length; i < n; i++){
27214
- var component = components[i];
27215
- if (_instanceof1$2(component, type)) {
27216
- results.push(component);
27279
+ _proto._update = function _update(context) {
27280
+ var skin = this.skin;
27281
+ if ((skin == null ? void 0 : skin.bones.length) > 0) {
27282
+ skin._updateSkinMatrices(this);
27283
+ }
27284
+ var shaderData = this.shaderData;
27285
+ var mesh = this.mesh;
27286
+ var blendShapeManager = mesh._blendShapeManager;
27287
+ blendShapeManager._updateShaderData(shaderData, this);
27288
+ var bones = skin == null ? void 0 : skin.bones;
27289
+ if (bones) {
27290
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
27291
+ var boneCount = bones.length;
27292
+ var boneDataCreateCache = this._jointDataCreateCache;
27293
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
27294
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
27295
+ // directly use max joint count to avoid shader recompile
27296
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
27297
+ if (boneCount > remainUniformJointCount) {
27298
+ var engine = this.engine;
27299
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
27300
+ if (boneCountChange) {
27301
+ var _this__jointTexture;
27302
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27303
+ this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
27304
+ this._jointTexture.filterMode = TextureFilterMode.Point;
27305
+ this._jointTexture.isGCIgnored = true;
27306
+ }
27307
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
27308
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
27309
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
27310
+ } else {
27311
+ 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);
27312
+ }
27313
+ } else {
27314
+ var _this__jointTexture1;
27315
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
27316
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
27317
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
27318
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
27319
+ }
27320
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
27321
+ }
27322
+ if (this._jointTexture) {
27323
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
27217
27324
  }
27218
27325
  }
27219
- return results;
27326
+ MeshRenderer.prototype._update.call(this, context);
27220
27327
  };
27221
27328
  /**
27222
- * Get the components which match the type of the entity and it's children.
27223
- * @param type - The component type
27224
- * @param results - The components collection
27225
- * @returns The components collection which match the type
27226
- */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
27227
- results.length = 0;
27228
- this._getComponentsInChildren(type, results);
27229
- return results;
27230
- };
27231
- _proto.addChild = function addChild(indexOrChild, child) {
27232
- var index;
27233
- if (typeof indexOrChild === "number") {
27234
- index = indexOrChild;
27329
+ * @internal
27330
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
27331
+ var _this_skin;
27332
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
27333
+ if (rootBone) {
27334
+ BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
27235
27335
  } else {
27236
- index = undefined;
27237
- child = indexOrChild;
27336
+ MeshRenderer.prototype._updateBounds.call(this, worldBounds);
27238
27337
  }
27239
- child._setParent(this, index);
27240
- };
27241
- /**
27242
- * Remove child entity.
27243
- * @param child - The child entity which want to be removed
27244
- */ _proto.removeChild = function removeChild(child) {
27245
- if (child._parent !== this) return;
27246
- child._setParent(null);
27247
- };
27248
- /**
27249
- * @deprecated Please use `children` property instead.
27250
- * Find child entity by index.
27251
- * @param index - The index of the child entity
27252
- * @returns The component which be found
27253
- */ _proto.getChild = function getChild(index) {
27254
- return this._children[index];
27255
27338
  };
27256
- /**
27257
- * Find entity by name.
27258
- * @param name - The name of the entity which want to be found
27259
- * @returns The component which be found
27260
- */ _proto.findByName = function findByName(name) {
27261
- if (name === this.name) {
27262
- return this;
27263
- }
27264
- var children = this._children;
27265
- for(var i = 0, n = children.length; i < n; i++){
27266
- var target = children[i].findByName(name);
27267
- if (target) {
27268
- return target;
27339
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
27340
+ var mesh = this._mesh;
27341
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
27342
+ var lastBlendShapeWeights = this._blendShapeWeights;
27343
+ if (lastBlendShapeWeights) {
27344
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
27345
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
27346
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
27347
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
27348
+ newBlendShapeWeights.set(lastBlendShapeWeights);
27349
+ } else {
27350
+ for(var i = 0; i < newBlendShapeCount; i++){
27351
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
27352
+ }
27353
+ }
27354
+ this._blendShapeWeights = newBlendShapeWeights;
27269
27355
  }
27356
+ } else {
27357
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
27270
27358
  }
27271
- return null;
27272
27359
  };
27273
- /**
27274
- * Find the entity by path.
27275
- * @param path - The path of the entity eg: /entity
27276
- * @returns The component which be found
27277
- */ _proto.findByPath = function findByPath(path) {
27278
- var splits = path.split("/").filter(Boolean);
27279
- if (!splits.length) {
27280
- return this;
27281
- }
27282
- return Entity._findChildByName(this, 0, splits, 0);
27360
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
27361
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
27283
27362
  };
27284
- /**
27285
- * Create child entity.
27286
- * @param name - The child entity's name
27287
- * @returns The child entity
27288
- */ _proto.createChild = function createChild(name) {
27289
- var transform = this._transform;
27290
- var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
27291
- child.layer = this.layer;
27292
- child.parent = this;
27293
- return child;
27363
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
27364
+ switch(type){
27365
+ case SkinUpdateFlag.BoneCountChanged:
27366
+ var shaderData = this.shaderData;
27367
+ if (value > 0) {
27368
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
27369
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
27370
+ } else {
27371
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
27372
+ }
27373
+ break;
27374
+ case SkinUpdateFlag.RootBoneChanged:
27375
+ this._setTransformEntity(value);
27376
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
27377
+ break;
27378
+ }
27294
27379
  };
27295
- /**
27296
- * Clear children entities.
27297
- */ _proto.clearChildren = function clearChildren() {
27298
- var children = this._children;
27299
- for(var i = children.length - 1; i >= 0; i--){
27300
- var child = children[i];
27301
- child._parent = null;
27302
- var activeChangeFlag = ActiveChangeFlag.None;
27303
- child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27304
- child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
27305
- activeChangeFlag && child._processInActive(activeChangeFlag);
27306
- Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
27380
+ _proto._applySkin = function _applySkin(lastSkin, value) {
27381
+ var _lastSkin_bones, _value_bones;
27382
+ var _lastSkin_bones_length;
27383
+ var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
27384
+ var _lastSkin_rootBone;
27385
+ var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
27386
+ lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
27387
+ var _value_bones_length;
27388
+ var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
27389
+ var _value_rootBone;
27390
+ var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
27391
+ value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
27392
+ if (lastSkinBoneCount !== skinBoneCount) {
27393
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
27394
+ }
27395
+ if (lastRootBone !== rootBone) {
27396
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
27307
27397
  }
27308
- children.length = 0;
27309
27398
  };
27310
- /**
27311
- * Clone this entity include children and components.
27312
- * @returns Cloned entity
27313
- */ _proto.clone = function clone() {
27314
- var cloneEntity = this._createCloneEntity();
27315
- this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
27316
- return cloneEntity;
27399
+ _create_class$2(SkinnedMeshRenderer, [
27400
+ {
27401
+ key: "skin",
27402
+ get: /**
27403
+ * Skin of the SkinnedMeshRenderer.
27404
+ */ function get() {
27405
+ return this._skin;
27406
+ },
27407
+ set: function set(value) {
27408
+ var lastSkin = this._skin;
27409
+ if (lastSkin !== value) {
27410
+ this._applySkin(lastSkin, value);
27411
+ this._skin = value;
27412
+ }
27413
+ }
27414
+ },
27415
+ {
27416
+ key: "blendShapeWeights",
27417
+ get: /**
27418
+ * The weights of the BlendShapes.
27419
+ * @remarks Array index is BlendShape index.
27420
+ */ function get() {
27421
+ this._checkBlendShapeWeightLength();
27422
+ return this._blendShapeWeights;
27423
+ },
27424
+ set: function set(value) {
27425
+ this._checkBlendShapeWeightLength();
27426
+ var blendShapeWeights = this._blendShapeWeights;
27427
+ if (value.length <= blendShapeWeights.length) {
27428
+ blendShapeWeights.set(value);
27429
+ } else {
27430
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
27431
+ blendShapeWeights[i] = value[i];
27432
+ }
27433
+ }
27434
+ }
27435
+ },
27436
+ {
27437
+ key: "localBounds",
27438
+ get: /**
27439
+ * Local bounds.
27440
+ */ function get() {
27441
+ return this._localBounds;
27442
+ },
27443
+ set: function set(value) {
27444
+ if (this._localBounds !== value) {
27445
+ this._localBounds.copyFrom(value);
27446
+ }
27447
+ }
27448
+ },
27449
+ {
27450
+ key: "rootBone",
27451
+ get: /**
27452
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
27453
+ */ function get() {
27454
+ return this.skin.rootBone;
27455
+ },
27456
+ set: function set(value) {
27457
+ this.skin.rootBone = value;
27458
+ }
27459
+ },
27460
+ {
27461
+ key: "bones",
27462
+ get: /**
27463
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
27464
+ */ function get() {
27465
+ return this.skin.bones;
27466
+ },
27467
+ set: function set(value) {
27468
+ this.skin.bones = value;
27469
+ }
27470
+ }
27471
+ ]);
27472
+ return SkinnedMeshRenderer;
27473
+ }(MeshRenderer);
27474
+ // @TODO: different shader type should use different count, not always 48
27475
+ /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
27476
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
27477
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
27478
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
27479
+ __decorate$1([
27480
+ ignoreClone
27481
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
27482
+ __decorate$1([
27483
+ deepClone
27484
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
27485
+ __decorate$1([
27486
+ ignoreClone
27487
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
27488
+ __decorate$1([
27489
+ ignoreClone
27490
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
27491
+ __decorate$1([
27492
+ ignoreClone
27493
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
27494
+ __decorate$1([
27495
+ ignoreClone
27496
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
27497
+ __decorate$1([
27498
+ deepClone
27499
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
27500
+ __decorate$1([
27501
+ ignoreClone
27502
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
27503
+ __decorate$1([
27504
+ ignoreClone
27505
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
27506
+ /**
27507
+ * @internal
27508
+ */ var BasicResources = /*#__PURE__*/ function() {
27509
+ function BasicResources(engine) {
27510
+ this.engine = engine;
27511
+ // prettier-ignore
27512
+ var vertices = new Float32Array([
27513
+ -1,
27514
+ -1,
27515
+ 0,
27516
+ 1,
27517
+ 3,
27518
+ -1,
27519
+ 2,
27520
+ 1,
27521
+ -1,
27522
+ 3,
27523
+ 0,
27524
+ -1
27525
+ ]); // left-top
27526
+ // prettier-ignore
27527
+ var flipYVertices = new Float32Array([
27528
+ 3,
27529
+ -1,
27530
+ 2,
27531
+ 0,
27532
+ -1,
27533
+ -1,
27534
+ 0,
27535
+ 0,
27536
+ -1,
27537
+ 3,
27538
+ 0,
27539
+ 2
27540
+ ]); // left-top
27541
+ var blitMaterial = new Material(engine, Shader.find("blit"));
27542
+ blitMaterial._addReferCount(1);
27543
+ blitMaterial.renderState.depthState.enabled = false;
27544
+ blitMaterial.renderState.depthState.writeEnabled = false;
27545
+ var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
27546
+ blitScreenMaterial._addReferCount(1);
27547
+ blitScreenMaterial.renderState.depthState.enabled = false;
27548
+ blitScreenMaterial.renderState.depthState.writeEnabled = false;
27549
+ this.blitMaterial = blitMaterial;
27550
+ this.blitScreenMaterial = blitScreenMaterial;
27551
+ this.blitMesh = this._createBlitMesh(engine, vertices);
27552
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
27553
+ // Create white and magenta textures
27554
+ var whitePixel = new Uint8Array([
27555
+ 255,
27556
+ 255,
27557
+ 255,
27558
+ 255
27559
+ ]);
27560
+ this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
27561
+ this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
27562
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
27563
+ if (isWebGL2) {
27564
+ this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
27565
+ var whitePixel32 = new Uint32Array([
27566
+ 255,
27567
+ 255,
27568
+ 255,
27569
+ 255
27570
+ ]);
27571
+ this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
27572
+ }
27573
+ this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
27574
+ this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
27575
+ this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
27576
+ this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
27577
+ this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
27578
+ }
27579
+ var _proto = BasicResources.prototype;
27580
+ /**
27581
+ * @internal
27582
+ */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
27583
+ return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
27584
+ };
27585
+ /**
27586
+ * @internal
27587
+ */ _proto._initialize = function _initialize() {
27588
+ var _this = this;
27589
+ return new Promise(function(resolve, reject) {
27590
+ PrefilteredDFG.create(_this.engine).then(function(texture) {
27591
+ _this._prefilteredDFGTexture = texture;
27592
+ resolve(_this);
27593
+ }).catch(reject);
27594
+ });
27595
+ };
27596
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
27597
+ var mesh = new ModelMesh(engine);
27598
+ mesh._addReferCount(1);
27599
+ mesh.setVertexElements([
27600
+ new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
27601
+ ]);
27602
+ var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
27603
+ mesh.setVertexBufferBinding(buffer, 16);
27604
+ mesh.addSubMesh(0, 3, MeshTopology.Triangles);
27605
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
27606
+ _inherits$2(_class, ContentRestorer);
27607
+ function _class() {
27608
+ return ContentRestorer.call(this, mesh) || this;
27609
+ }
27610
+ var _proto = _class.prototype;
27611
+ _proto.restoreContent = function restoreContent() {
27612
+ buffer.setData(buffer.data);
27613
+ };
27614
+ return _class;
27615
+ }(ContentRestorer))());
27616
+ return mesh;
27617
+ };
27618
+ _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
27619
+ var texture;
27620
+ switch(type){
27621
+ case 0:
27622
+ var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
27623
+ texture2D.setPixelBuffer(pixel);
27624
+ texture = texture2D;
27625
+ break;
27626
+ case 2:
27627
+ var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
27628
+ texture2DArray.setPixelBuffer(0, pixel);
27629
+ texture = texture2DArray;
27630
+ break;
27631
+ case 1:
27632
+ var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
27633
+ for(var i = 0; i < 6; i++){
27634
+ textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
27635
+ }
27636
+ texture = textureCube;
27637
+ break;
27638
+ default:
27639
+ throw "Invalid texture type";
27640
+ }
27641
+ texture.isGCIgnored = true;
27642
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
27643
+ _inherits$2(_class, ContentRestorer);
27644
+ function _class() {
27645
+ return ContentRestorer.call(this, texture) || this;
27646
+ }
27647
+ var _proto = _class.prototype;
27648
+ _proto.restoreContent = function restoreContent() {
27649
+ switch(type){
27650
+ case 0:
27651
+ this.resource.setPixelBuffer(pixel);
27652
+ break;
27653
+ case 2:
27654
+ this.resource.setPixelBuffer(0, pixel);
27655
+ break;
27656
+ case 1:
27657
+ for(var i = 0; i < 6; i++){
27658
+ this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
27659
+ }
27660
+ break;
27661
+ }
27662
+ };
27663
+ return _class;
27664
+ }(ContentRestorer))());
27665
+ return texture;
27666
+ };
27667
+ _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
27668
+ var material = new Material(engine, shader);
27669
+ var renderState = material.renderState;
27670
+ var target = renderState.blendState.targetBlendState;
27671
+ target.enabled = true;
27672
+ target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
27673
+ target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
27674
+ target.sourceAlphaBlendFactor = BlendFactor.One;
27675
+ target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
27676
+ target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
27677
+ renderState.depthState.writeEnabled = false;
27678
+ renderState.rasterState.cullMode = CullMode.Off;
27679
+ renderState.renderQueueType = RenderQueueType.Transparent;
27680
+ material.isGCIgnored = true;
27681
+ return material;
27682
+ };
27683
+ _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
27684
+ var material = new Material(engine, Shader.find(shaderName));
27685
+ material.isGCIgnored = true;
27686
+ material.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
27687
+ return material;
27688
+ };
27689
+ _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
27690
+ var material = new Material(engine, Shader.find("SpriteMask"));
27691
+ material.isGCIgnored = true;
27692
+ return material;
27693
+ };
27694
+ BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
27695
+ var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
27696
+ var renderStates;
27697
+ var compareFunction;
27698
+ if (visibleInsideMask) {
27699
+ renderStates = BasicResources._maskReadInsideRenderStates;
27700
+ if (renderStates) {
27701
+ return renderStates;
27702
+ }
27703
+ BasicResources._maskReadInsideRenderStates = renderStates = {};
27704
+ compareFunction = CompareFunction.LessEqual;
27705
+ } else {
27706
+ renderStates = BasicResources._maskReadOutsideRenderStates;
27707
+ if (renderStates) {
27708
+ return renderStates;
27709
+ }
27710
+ BasicResources._maskReadOutsideRenderStates = renderStates = {};
27711
+ compareFunction = CompareFunction.Greater;
27712
+ }
27713
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
27714
+ renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
27715
+ renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
27716
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
27717
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
27718
+ return renderStates;
27719
+ };
27720
+ BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
27721
+ var isIncrement = maskType === RenderQueueMaskType.Increment;
27722
+ var renderStates;
27723
+ var passOperation;
27724
+ if (isIncrement) {
27725
+ renderStates = BasicResources._maskWriteIncrementRenderStates;
27726
+ if (renderStates) {
27727
+ return renderStates;
27728
+ }
27729
+ BasicResources._maskWriteIncrementRenderStates = renderStates = {};
27730
+ passOperation = StencilOperation.IncrementSaturate;
27731
+ } else {
27732
+ renderStates = BasicResources._maskWriteDecrementRenderStates;
27733
+ if (renderStates) {
27734
+ return renderStates;
27735
+ }
27736
+ BasicResources._maskWriteDecrementRenderStates = renderStates = {};
27737
+ passOperation = StencilOperation.DecrementSaturate;
27738
+ }
27739
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
27740
+ renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
27741
+ renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
27742
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
27743
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
27744
+ var failStencilOperation = StencilOperation.Keep;
27745
+ renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
27746
+ renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
27747
+ renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
27748
+ renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
27749
+ renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
27750
+ renderStates[RenderStateElementKey.DepthStateEnabled] = false;
27751
+ renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
27752
+ return renderStates;
27753
+ };
27754
+ _create_class$2(BasicResources, [
27755
+ {
27756
+ key: "prefilteredDFGTexture",
27757
+ get: function get() {
27758
+ return this._prefilteredDFGTexture;
27759
+ }
27760
+ }
27761
+ ]);
27762
+ return BasicResources;
27763
+ }();
27764
+ BasicResources._maskReadInsideRenderStates = null;
27765
+ BasicResources._maskReadOutsideRenderStates = null;
27766
+ BasicResources._maskWriteIncrementRenderStates = null;
27767
+ BasicResources._maskWriteDecrementRenderStates = null;
27768
+ function _is_native_reflect_construct$1() {
27769
+ // Since Reflect.construct can't be properly polyfilled, some
27770
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
27771
+ // Those polyfills don't allow us to subclass built-ins, so we need to
27772
+ // use our fallback implementation.
27773
+ try {
27774
+ // If the internal slots aren't set, this throws an error similar to
27775
+ // TypeError: this is not a Boolean object.
27776
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
27777
+ } catch (_) {}
27778
+ return (_is_native_reflect_construct$1 = function _is_native_reflect_construct() {
27779
+ return !!result;
27780
+ })();
27781
+ }
27782
+ function _construct$1(Parent, args, Class) {
27783
+ if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
27784
+ else {
27785
+ _construct$1 = function construct(Parent, args, Class) {
27786
+ var a = [
27787
+ null
27788
+ ];
27789
+ a.push.apply(a, args);
27790
+ var Constructor = Function.bind.apply(Parent, a);
27791
+ var instance = new Constructor();
27792
+ if (Class) _set_prototype_of$2(instance, Class.prototype);
27793
+ return instance;
27794
+ };
27795
+ }
27796
+ return _construct$1.apply(null, arguments);
27797
+ }
27798
+ var ComponentCloner = /*#__PURE__*/ function() {
27799
+ function ComponentCloner() {}
27800
+ /**
27801
+ * Clone component.
27802
+ * @param source - Clone source
27803
+ * @param target - Clone target
27804
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
27805
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
27806
+ for(var k in source){
27807
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
27808
+ }
27809
+ source._cloneTo == null ? void 0 : source._cloneTo.call(source, target, srcRoot, targetRoot);
27810
+ };
27811
+ return ComponentCloner;
27812
+ }();
27813
+ /**
27814
+ * The entity modify flags.
27815
+ */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
27816
+ /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
27817
+ /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
27818
+ return EntityModifyFlags;
27819
+ }({});
27820
+ /**
27821
+ * Entity, be used as components container.
27822
+ */ var Entity = /*#__PURE__*/ function(EngineObject) {
27823
+ _inherits$2(Entity, EngineObject);
27824
+ function Entity(engine, name) {
27825
+ for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
27826
+ components[_key - 2] = arguments[_key];
27827
+ }
27828
+ var _this;
27829
+ _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, _this._invModelMatrix = new Matrix();
27830
+ _this.name = name != null ? name : "Entity";
27831
+ for(var i = 0, n = components.length; i < n; i++){
27832
+ _this.addComponent(components[i]);
27833
+ }
27834
+ !_this._transform && _this.addComponent(Transform);
27835
+ _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
27836
+ return _this;
27837
+ }
27838
+ var _proto = Entity.prototype;
27839
+ /**
27840
+ * Add component based on the component type.
27841
+ * @param type - The type of the component
27842
+ * @param args - The arguments of the component
27843
+ * @returns The component which has been added
27844
+ */ _proto.addComponent = function addComponent(type) {
27845
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
27846
+ args[_key - 1] = arguments[_key];
27847
+ }
27848
+ ComponentsDependencies._addCheck(this, type);
27849
+ var component = _construct$1(type, [].concat([
27850
+ this
27851
+ ], args));
27852
+ this._components.push(component);
27853
+ // @todo: temporary solution
27854
+ if (_instanceof1$2(component, Transform)) this._setTransform(component);
27855
+ component._setActive(true, ActiveChangeFlag.All);
27856
+ return component;
27857
+ };
27858
+ /**
27859
+ * Get component which match the type.
27860
+ * @param type - The type of the component
27861
+ * @returns The first component which match type
27862
+ */ _proto.getComponent = function getComponent(type) {
27863
+ var components = this._components;
27864
+ for(var i = 0, n = components.length; i < n; i++){
27865
+ var component = components[i];
27866
+ if (_instanceof1$2(component, type)) {
27867
+ return component;
27868
+ }
27869
+ }
27870
+ return null;
27871
+ };
27872
+ /**
27873
+ * Get components which match the type.
27874
+ * @param type - The type of the component
27875
+ * @param results - The components which match type
27876
+ * @returns The components which match type
27877
+ */ _proto.getComponents = function getComponents(type, results) {
27878
+ results.length = 0;
27879
+ var components = this._components;
27880
+ for(var i = 0, n = components.length; i < n; i++){
27881
+ var component = components[i];
27882
+ if (_instanceof1$2(component, type)) {
27883
+ results.push(component);
27884
+ }
27885
+ }
27886
+ return results;
27887
+ };
27888
+ /**
27889
+ * Get the components which match the type of the entity and it's children.
27890
+ * @param type - The component type
27891
+ * @param results - The components collection
27892
+ * @returns The components collection which match the type
27893
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
27894
+ results.length = 0;
27895
+ this._getComponentsInChildren(type, results);
27896
+ return results;
27897
+ };
27898
+ _proto.addChild = function addChild(indexOrChild, child) {
27899
+ var index;
27900
+ if (typeof indexOrChild === "number") {
27901
+ index = indexOrChild;
27902
+ } else {
27903
+ index = undefined;
27904
+ child = indexOrChild;
27905
+ }
27906
+ child._setParent(this, index);
27907
+ };
27908
+ /**
27909
+ * Remove child entity.
27910
+ * @param child - The child entity which want to be removed
27911
+ */ _proto.removeChild = function removeChild(child) {
27912
+ if (child._parent !== this) return;
27913
+ child._setParent(null);
27914
+ };
27915
+ /**
27916
+ * @deprecated Please use `children` property instead.
27917
+ * Find child entity by index.
27918
+ * @param index - The index of the child entity
27919
+ * @returns The component which be found
27920
+ */ _proto.getChild = function getChild(index) {
27921
+ return this._children[index];
27922
+ };
27923
+ /**
27924
+ * Find entity by name.
27925
+ * @param name - The name of the entity which want to be found
27926
+ * @returns The component which be found
27927
+ */ _proto.findByName = function findByName(name) {
27928
+ if (name === this.name) {
27929
+ return this;
27930
+ }
27931
+ var children = this._children;
27932
+ for(var i = 0, n = children.length; i < n; i++){
27933
+ var target = children[i].findByName(name);
27934
+ if (target) {
27935
+ return target;
27936
+ }
27937
+ }
27938
+ return null;
27939
+ };
27940
+ /**
27941
+ * Find the entity by path.
27942
+ * @param path - The path of the entity eg: /entity
27943
+ * @returns The component which be found
27944
+ */ _proto.findByPath = function findByPath(path) {
27945
+ var splits = path.split("/").filter(Boolean);
27946
+ if (!splits.length) {
27947
+ return this;
27948
+ }
27949
+ return Entity._findChildByName(this, 0, splits, 0);
27950
+ };
27951
+ /**
27952
+ * Create child entity.
27953
+ * @param name - The child entity's name
27954
+ * @returns The child entity
27955
+ */ _proto.createChild = function createChild(name) {
27956
+ var transform = this._transform;
27957
+ var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
27958
+ child.layer = this.layer;
27959
+ child.parent = this;
27960
+ return child;
27961
+ };
27962
+ /**
27963
+ * Clear children entities.
27964
+ */ _proto.clearChildren = function clearChildren() {
27965
+ var children = this._children;
27966
+ for(var i = children.length - 1; i >= 0; i--){
27967
+ var child = children[i];
27968
+ child._parent = null;
27969
+ var activeChangeFlag = ActiveChangeFlag.None;
27970
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27971
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
27972
+ activeChangeFlag && child._processInActive(activeChangeFlag);
27973
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
27974
+ }
27975
+ children.length = 0;
27976
+ };
27977
+ /**
27978
+ * Clone this entity include children and components.
27979
+ * @returns Cloned entity
27980
+ */ _proto.clone = function clone() {
27981
+ var cloneEntity = this._createCloneEntity();
27982
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
27983
+ return cloneEntity;
27317
27984
  };
27318
27985
  /**
27319
27986
  * Listen for changes in the world pose of this `Entity`.
@@ -27323,6 +27990,11 @@
27323
27990
  };
27324
27991
  /**
27325
27992
  * @internal
27993
+ */ _proto._remap = function _remap(srcRoot, targetRoot) {
27994
+ return CloneUtils.remapEntity(srcRoot, targetRoot, this);
27995
+ };
27996
+ /**
27997
+ * @internal
27326
27998
  */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
27327
27999
  this._isTemplate = true;
27328
28000
  this._templateResource = templateResource;
@@ -27631,834 +28303,146 @@
27631
28303
  for(var i = children.length - 1; i >= 0; i--){
27632
28304
  this._traverseSetOwnerScene(children[i], scene);
27633
28305
  }
27634
- };
27635
- /**
27636
- * @internal
27637
- */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
27638
- inversePath.length = 0;
27639
- while(searchEntity !== rootEntity){
27640
- var parent = searchEntity.parent;
27641
- if (!parent) {
27642
- return false;
27643
- }
27644
- inversePath.push(searchEntity.siblingIndex);
27645
- searchEntity = parent;
27646
- }
27647
- return true;
27648
- };
27649
- /**
27650
- * @internal
27651
- */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
27652
- var entity = rootEntity;
27653
- for(var i = inversePath.length - 1; i >= 0; i--){
27654
- entity = entity.children[inversePath[i]];
27655
- }
27656
- return entity;
27657
- };
27658
- /**
27659
- * @internal
27660
- */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
27661
- var count = children.length - 1;
27662
- for(var i = entity._siblingIndex; i < count; i++){
27663
- var child = children[i + 1];
27664
- children[i] = child;
27665
- child._siblingIndex = i;
27666
- }
27667
- children.length = count;
27668
- entity._siblingIndex = -1;
27669
- };
27670
- /**
27671
- * @internal
27672
- */ Entity._addToChildren = function _addToChildren(children, entity, index) {
27673
- var childCount = children.length;
27674
- children.length = childCount + 1;
27675
- if (index === undefined) {
27676
- children[childCount] = entity;
27677
- entity._siblingIndex = childCount;
27678
- } else {
27679
- if (index < 0 || index > childCount) {
27680
- throw "The index " + index + " is out of child list bounds " + childCount;
27681
- }
27682
- for(var i = childCount; i > index; i--){
27683
- var swapChild = children[i - 1];
27684
- swapChild._siblingIndex = i;
27685
- children[i] = swapChild;
27686
- }
27687
- entity._siblingIndex = index;
27688
- children[index] = entity;
27689
- }
27690
- };
27691
- _create_class$2(Entity, [
27692
- {
27693
- key: "transform",
27694
- get: /**
27695
- * The transform of this entity.
27696
- */ function get() {
27697
- return this._transform;
27698
- }
27699
- },
27700
- {
27701
- key: "isActive",
27702
- get: /**
27703
- * Whether to activate locally.
27704
- */ function get() {
27705
- return this._isActive;
27706
- },
27707
- set: function set(value) {
27708
- if (value !== this._isActive) {
27709
- this._isActive = value;
27710
- if (value) {
27711
- var parent = this._parent;
27712
- var activeChangeFlag = ActiveChangeFlag.None;
27713
- if (this._isRoot && this._scene._isActiveInEngine) {
27714
- activeChangeFlag |= ActiveChangeFlag.All;
27715
- } else {
27716
- (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27717
- (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
27718
- }
27719
- activeChangeFlag && this._processActive(activeChangeFlag);
27720
- } else {
27721
- var activeChangeFlag1 = ActiveChangeFlag.None;
27722
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
27723
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
27724
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
27725
- }
27726
- }
27727
- }
27728
- },
27729
- {
27730
- key: "isActiveInHierarchy",
27731
- get: /**
27732
- * Whether it is active in the hierarchy.
27733
- */ function get() {
27734
- return this._isActiveInHierarchy;
27735
- }
27736
- },
27737
- {
27738
- key: "parent",
27739
- get: /**
27740
- * The parent entity.
27741
- */ function get() {
27742
- return this._parent;
27743
- },
27744
- set: function set(value) {
27745
- this._setParent(value);
27746
- }
27747
- },
27748
- {
27749
- key: "children",
27750
- get: /**
27751
- * The children entities
27752
- */ function get() {
27753
- return this._children;
27754
- }
27755
- },
27756
- {
27757
- key: "childCount",
27758
- get: /**
27759
- * @deprecated Please use `children.length` property instead.
27760
- * Number of the children entities
27761
- */ function get() {
27762
- return this._children.length;
27763
- }
27764
- },
27765
- {
27766
- key: "scene",
27767
- get: /**
27768
- * The scene the entity belongs to.
27769
- */ function get() {
27770
- return this._scene;
27771
- }
27772
- },
27773
- {
27774
- key: "siblingIndex",
27775
- get: /**
27776
- * The sibling index.
27777
- */ function get() {
27778
- return this._siblingIndex;
27779
- },
27780
- set: function set(value) {
27781
- if (this._siblingIndex === -1) {
27782
- throw "The entity " + this.name + " is not in the hierarchy";
27783
- }
27784
- if (this._isRoot) {
27785
- this._setSiblingIndex(this._scene._rootEntities, value);
27786
- } else {
27787
- var parent = this._parent;
27788
- this._setSiblingIndex(parent._children, value);
27789
- parent._dispatchModify(EntityModifyFlags.Child, parent);
27790
- }
27791
- }
27792
- }
27793
- ]);
27794
- return Entity;
27795
- }(EngineObject);
27796
- /** @internal */ Entity._tempComponentConstructors = [];
27797
- /**
27798
- * Skin used for skinned mesh renderer.
27799
- */ var Skin = /*#__PURE__*/ function(EngineObject) {
27800
- _inherits$2(Skin, EngineObject);
27801
- function Skin(name) {
27802
- var _this;
27803
- _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 = [];
27804
- return _this;
27805
- }
27806
- var _proto = Skin.prototype;
27807
- /**
27808
- * @internal
27809
- */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
27810
- if (this._updateMark === renderer.engine.time.frameCount) {
27811
- return;
27812
- }
27813
- var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
27814
- var _this_rootBone;
27815
- var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
27816
- for(var i = bones.length - 1; i >= 0; i--){
27817
- var bone = bones[i];
27818
- var offset = i * 16;
27819
- if (bone) {
27820
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
27821
- } else {
27822
- skinMatrices.set(bindMatrices[i].elements, offset);
27823
- }
27824
- Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
27825
- }
27826
- this._updateMark = renderer.engine.time.frameCount;
27827
- };
27828
- /**
27829
- * @internal
27830
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27831
- var paths = new Array();
27832
- // Clone rootBone
27833
- var rootBone = this.rootBone;
27834
- if (rootBone) {
27835
- var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
27836
- target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
27837
- }
27838
- // Clone bones
27839
- var bones = this.bones;
27840
- if (bones.length > 0) {
27841
- var boneCount = bones.length;
27842
- var destBones = new Array(boneCount);
27843
- for(var i = 0; i < boneCount; i++){
27844
- var bone = bones[i];
27845
- var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
27846
- destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
27847
- }
27848
- target.bones = destBones;
27849
- }
27850
- };
27851
- _create_class$2(Skin, [
27852
- {
27853
- key: "rootBone",
27854
- get: /**
27855
- * Root bone.
27856
- */ function get() {
27857
- return this._rootBone;
27858
- },
27859
- set: function set(value) {
27860
- if (this._rootBone !== value) {
27861
- this._updatedManager.dispatch(1, value);
27862
- this._rootBone = value;
27863
- }
27864
- }
27865
- },
27866
- {
27867
- key: "bones",
27868
- get: /**
27869
- * Bones of the skin.
27870
- */ function get() {
27871
- return this._bones;
27872
- },
27873
- set: function set(value) {
27874
- var bones = this._bones;
27875
- var _value_length;
27876
- var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
27877
- var lastBoneCount = bones.length;
27878
- bones.length = boneCount;
27879
- for(var i = 0; i < boneCount; i++){
27880
- bones[i] = value[i];
27881
- }
27882
- if (lastBoneCount !== boneCount) {
27883
- this._skinMatrices = new Float32Array(boneCount * 16);
27884
- this._updatedManager.dispatch(0, boneCount);
27885
- }
27886
- }
27887
- },
27888
- {
27889
- key: "skeleton",
27890
- get: /** @deprecated Please use `rootBone` instead. */ function get() {
27891
- var _this_rootBone;
27892
- return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
27893
- },
27894
- set: function set(value) {
27895
- var rootBone = this._rootBone;
27896
- if (rootBone) {
27897
- rootBone.name = value;
27898
- }
27899
- }
27900
- }
27901
- ]);
27902
- return Skin;
27903
- }(EngineObject);
27904
- __decorate$1([
27905
- deepClone
27906
- ], Skin.prototype, "inverseBindMatrices", void 0);
27907
- __decorate$1([
27908
- ignoreClone
27909
- ], Skin.prototype, "_skinMatrices", void 0);
27910
- __decorate$1([
27911
- ignoreClone
27912
- ], Skin.prototype, "_updatedManager", void 0);
27913
- __decorate$1([
27914
- ignoreClone
27915
- ], Skin.prototype, "_rootBone", void 0);
27916
- __decorate$1([
27917
- ignoreClone
27918
- ], Skin.prototype, "_bones", void 0);
27919
- __decorate$1([
27920
- ignoreClone
27921
- ], Skin.prototype, "_updateMark", void 0);
27922
- var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
27923
- SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
27924
- SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
27925
- return SkinUpdateFlag;
27926
- }({});
27927
- /**
27928
- * SkinnedMeshRenderer.
27929
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
27930
- _inherits$2(SkinnedMeshRenderer, MeshRenderer);
27931
- function SkinnedMeshRenderer(entity) {
27932
- var _this;
27933
- _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new BoundingBox(), _this._jointDataCreateCache = new Vector2(-1, -1);
27934
- _this._skin = null;
27935
- var rhi = _this.entity.engine._hardwareRenderer;
27936
- var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
27937
- // Limit size to 256 to avoid some problem:
27938
- // 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!
27939
- // 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.
27940
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
27941
- _this._maxVertexUniformVectors = maxVertexUniformVectors;
27942
- _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
27943
- _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
27944
- var localBounds = _this._localBounds;
27945
- // @ts-ignore
27946
- localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
27947
- // @ts-ignore
27948
- localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
27949
- return _this;
27950
- }
27951
- var _proto = SkinnedMeshRenderer.prototype;
27952
- /**
27953
- * @internal
27954
- */ _proto._onDestroy = function _onDestroy() {
27955
- var _this__jointTexture;
27956
- MeshRenderer.prototype._onDestroy.call(this);
27957
- this._jointDataCreateCache = null;
27958
- this._skin = null;
27959
- this._blendShapeWeights = null;
27960
- this._localBounds = null;
27961
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27962
- this._jointTexture = null;
27963
- };
27964
- /**
27965
- * @internal
27966
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27967
- MeshRenderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
27968
- if (this.skin) {
27969
- target._applySkin(null, target.skin);
27970
- }
27971
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
27972
- };
27973
- _proto._update = function _update(context) {
27974
- var skin = this.skin;
27975
- if ((skin == null ? void 0 : skin.bones.length) > 0) {
27976
- skin._updateSkinMatrices(this);
27977
- }
27978
- var shaderData = this.shaderData;
27979
- var mesh = this.mesh;
27980
- var blendShapeManager = mesh._blendShapeManager;
27981
- blendShapeManager._updateShaderData(shaderData, this);
27982
- var bones = skin == null ? void 0 : skin.bones;
27983
- if (bones) {
27984
- var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
27985
- var boneCount = bones.length;
27986
- var boneDataCreateCache = this._jointDataCreateCache;
27987
- var boneCountChange = boneCount !== boneDataCreateCache.x;
27988
- if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
27989
- // directly use max joint count to avoid shader recompile
27990
- var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
27991
- if (boneCount > remainUniformJointCount) {
27992
- var engine = this.engine;
27993
- if (engine._hardwareRenderer.canIUseMoreJoints) {
27994
- if (boneCountChange) {
27995
- var _this__jointTexture;
27996
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27997
- this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
27998
- this._jointTexture.filterMode = TextureFilterMode.Point;
27999
- this._jointTexture.isGCIgnored = true;
28000
- }
28001
- shaderData.disableMacro("RENDERER_JOINTS_NUM");
28002
- shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
28003
- shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
28004
- } else {
28005
- 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);
28006
- }
28007
- } else {
28008
- var _this__jointTexture1;
28009
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
28010
- shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
28011
- shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
28012
- shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
28013
- }
28014
- boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
28015
- }
28016
- if (this._jointTexture) {
28017
- this._jointTexture.setPixelBuffer(skin._skinMatrices);
28018
- }
28019
- }
28020
- MeshRenderer.prototype._update.call(this, context);
28021
- };
28022
- /**
28023
- * @internal
28024
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
28025
- var _this_skin;
28026
- var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
28027
- if (rootBone) {
28028
- BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
28029
- } else {
28030
- MeshRenderer.prototype._updateBounds.call(this, worldBounds);
28031
- }
28032
- };
28033
- _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
28034
- var mesh = this._mesh;
28035
- var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
28036
- var lastBlendShapeWeights = this._blendShapeWeights;
28037
- if (lastBlendShapeWeights) {
28038
- var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
28039
- if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
28040
- var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
28041
- if (newBlendShapeCount > lastBlendShapeWeightsCount) {
28042
- newBlendShapeWeights.set(lastBlendShapeWeights);
28043
- } else {
28044
- for(var i = 0; i < newBlendShapeCount; i++){
28045
- newBlendShapeWeights[i] = lastBlendShapeWeights[i];
28046
- }
28047
- }
28048
- this._blendShapeWeights = newBlendShapeWeights;
28049
- }
28050
- } else {
28051
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
28052
- }
28053
- };
28054
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
28055
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
28056
- };
28057
- _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
28058
- switch(type){
28059
- case SkinUpdateFlag.BoneCountChanged:
28060
- var shaderData = this.shaderData;
28061
- if (value > 0) {
28062
- shaderData.enableMacro("RENDERER_HAS_SKIN");
28063
- shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
28064
- } else {
28065
- shaderData.disableMacro("RENDERER_HAS_SKIN");
28066
- }
28067
- break;
28068
- case SkinUpdateFlag.RootBoneChanged:
28069
- this._setTransformEntity(value);
28070
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
28071
- break;
28072
- }
28073
- };
28074
- _proto._applySkin = function _applySkin(lastSkin, value) {
28075
- var _lastSkin_bones, _value_bones;
28076
- var _lastSkin_bones_length;
28077
- var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
28078
- var _lastSkin_rootBone;
28079
- var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
28080
- lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
28081
- var _value_bones_length;
28082
- var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
28083
- var _value_rootBone;
28084
- var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
28085
- value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
28086
- if (lastSkinBoneCount !== skinBoneCount) {
28087
- this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
28088
- }
28089
- if (lastRootBone !== rootBone) {
28090
- this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
28306
+ };
28307
+ /**
28308
+ * @internal
28309
+ */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
28310
+ var count = children.length - 1;
28311
+ for(var i = entity._siblingIndex; i < count; i++){
28312
+ var child = children[i + 1];
28313
+ children[i] = child;
28314
+ child._siblingIndex = i;
28091
28315
  }
28316
+ children.length = count;
28317
+ entity._siblingIndex = -1;
28092
28318
  };
28093
- _create_class$2(SkinnedMeshRenderer, [
28319
+ /**
28320
+ * @internal
28321
+ */ Entity._addToChildren = function _addToChildren(children, entity, index) {
28322
+ var childCount = children.length;
28323
+ children.length = childCount + 1;
28324
+ if (index === undefined) {
28325
+ children[childCount] = entity;
28326
+ entity._siblingIndex = childCount;
28327
+ } else {
28328
+ if (index < 0 || index > childCount) {
28329
+ throw "The index " + index + " is out of child list bounds " + childCount;
28330
+ }
28331
+ for(var i = childCount; i > index; i--){
28332
+ var swapChild = children[i - 1];
28333
+ swapChild._siblingIndex = i;
28334
+ children[i] = swapChild;
28335
+ }
28336
+ entity._siblingIndex = index;
28337
+ children[index] = entity;
28338
+ }
28339
+ };
28340
+ _create_class$2(Entity, [
28094
28341
  {
28095
- key: "skin",
28342
+ key: "transform",
28096
28343
  get: /**
28097
- * Skin of the SkinnedMeshRenderer.
28344
+ * The transform of this entity.
28098
28345
  */ function get() {
28099
- return this._skin;
28100
- },
28101
- set: function set(value) {
28102
- var lastSkin = this._skin;
28103
- if (lastSkin !== value) {
28104
- this._applySkin(lastSkin, value);
28105
- this._skin = value;
28106
- }
28346
+ return this._transform;
28107
28347
  }
28108
28348
  },
28109
28349
  {
28110
- key: "blendShapeWeights",
28350
+ key: "isActive",
28111
28351
  get: /**
28112
- * The weights of the BlendShapes.
28113
- * @remarks Array index is BlendShape index.
28352
+ * Whether to activate locally.
28114
28353
  */ function get() {
28115
- this._checkBlendShapeWeightLength();
28116
- return this._blendShapeWeights;
28354
+ return this._isActive;
28117
28355
  },
28118
28356
  set: function set(value) {
28119
- this._checkBlendShapeWeightLength();
28120
- var blendShapeWeights = this._blendShapeWeights;
28121
- if (value.length <= blendShapeWeights.length) {
28122
- blendShapeWeights.set(value);
28123
- } else {
28124
- for(var i = 0, n = blendShapeWeights.length; i < n; i++){
28125
- blendShapeWeights[i] = value[i];
28357
+ if (value !== this._isActive) {
28358
+ this._isActive = value;
28359
+ if (value) {
28360
+ var parent = this._parent;
28361
+ var activeChangeFlag = ActiveChangeFlag.None;
28362
+ if (this._isRoot && this._scene._isActiveInEngine) {
28363
+ activeChangeFlag |= ActiveChangeFlag.All;
28364
+ } else {
28365
+ (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
28366
+ (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
28367
+ }
28368
+ activeChangeFlag && this._processActive(activeChangeFlag);
28369
+ } else {
28370
+ var activeChangeFlag1 = ActiveChangeFlag.None;
28371
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
28372
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
28373
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
28126
28374
  }
28127
28375
  }
28128
28376
  }
28129
28377
  },
28130
28378
  {
28131
- key: "localBounds",
28379
+ key: "isActiveInHierarchy",
28132
28380
  get: /**
28133
- * Local bounds.
28381
+ * Whether it is active in the hierarchy.
28134
28382
  */ function get() {
28135
- return this._localBounds;
28136
- },
28137
- set: function set(value) {
28138
- if (this._localBounds !== value) {
28139
- this._localBounds.copyFrom(value);
28140
- }
28383
+ return this._isActiveInHierarchy;
28141
28384
  }
28142
28385
  },
28143
28386
  {
28144
- key: "rootBone",
28387
+ key: "parent",
28145
28388
  get: /**
28146
- * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
28389
+ * The parent entity.
28147
28390
  */ function get() {
28148
- return this.skin.rootBone;
28391
+ return this._parent;
28149
28392
  },
28150
28393
  set: function set(value) {
28151
- this.skin.rootBone = value;
28394
+ this._setParent(value);
28152
28395
  }
28153
28396
  },
28154
28397
  {
28155
- key: "bones",
28398
+ key: "children",
28156
28399
  get: /**
28157
- * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
28400
+ * The children entities
28158
28401
  */ function get() {
28159
- return this.skin.bones;
28160
- },
28161
- set: function set(value) {
28162
- this.skin.bones = value;
28163
- }
28164
- }
28165
- ]);
28166
- return SkinnedMeshRenderer;
28167
- }(MeshRenderer);
28168
- // @TODO: different shader type should use different count, not always 48
28169
- /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
28170
- SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
28171
- SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
28172
- SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
28173
- __decorate$1([
28174
- ignoreClone
28175
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
28176
- __decorate$1([
28177
- deepClone
28178
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
28179
- __decorate$1([
28180
- ignoreClone
28181
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
28182
- __decorate$1([
28183
- ignoreClone
28184
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
28185
- __decorate$1([
28186
- ignoreClone
28187
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
28188
- __decorate$1([
28189
- ignoreClone
28190
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
28191
- __decorate$1([
28192
- deepClone
28193
- ], SkinnedMeshRenderer.prototype, "_skin", void 0);
28194
- __decorate$1([
28195
- ignoreClone
28196
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
28197
- __decorate$1([
28198
- ignoreClone
28199
- ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
28200
- /**
28201
- * @internal
28202
- */ var BasicResources = /*#__PURE__*/ function() {
28203
- function BasicResources(engine) {
28204
- this.engine = engine;
28205
- // prettier-ignore
28206
- var vertices = new Float32Array([
28207
- -1,
28208
- -1,
28209
- 0,
28210
- 1,
28211
- 3,
28212
- -1,
28213
- 2,
28214
- 1,
28215
- -1,
28216
- 3,
28217
- 0,
28218
- -1
28219
- ]); // left-top
28220
- // prettier-ignore
28221
- var flipYVertices = new Float32Array([
28222
- 3,
28223
- -1,
28224
- 2,
28225
- 0,
28226
- -1,
28227
- -1,
28228
- 0,
28229
- 0,
28230
- -1,
28231
- 3,
28232
- 0,
28233
- 2
28234
- ]); // left-top
28235
- var blitMaterial = new Material(engine, Shader.find("blit"));
28236
- blitMaterial._addReferCount(1);
28237
- blitMaterial.renderState.depthState.enabled = false;
28238
- blitMaterial.renderState.depthState.writeEnabled = false;
28239
- var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
28240
- blitScreenMaterial._addReferCount(1);
28241
- blitScreenMaterial.renderState.depthState.enabled = false;
28242
- blitScreenMaterial.renderState.depthState.writeEnabled = false;
28243
- this.blitMaterial = blitMaterial;
28244
- this.blitScreenMaterial = blitScreenMaterial;
28245
- this.blitMesh = this._createBlitMesh(engine, vertices);
28246
- this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
28247
- // Create white and magenta textures
28248
- var whitePixel = new Uint8Array([
28249
- 255,
28250
- 255,
28251
- 255,
28252
- 255
28253
- ]);
28254
- this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
28255
- this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
28256
- var isWebGL2 = engine._hardwareRenderer.isWebGL2;
28257
- if (isWebGL2) {
28258
- this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
28259
- var whitePixel32 = new Uint32Array([
28260
- 255,
28261
- 255,
28262
- 255,
28263
- 255
28264
- ]);
28265
- this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
28266
- }
28267
- this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
28268
- this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
28269
- this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
28270
- this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
28271
- this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
28272
- }
28273
- var _proto = BasicResources.prototype;
28274
- /**
28275
- * @internal
28276
- */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
28277
- return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
28278
- };
28279
- /**
28280
- * @internal
28281
- */ _proto._initialize = function _initialize() {
28282
- var _this = this;
28283
- return new Promise(function(resolve, reject) {
28284
- PrefilteredDFG.create(_this.engine).then(function(texture) {
28285
- _this._prefilteredDFGTexture = texture;
28286
- resolve(_this);
28287
- }).catch(reject);
28288
- });
28289
- };
28290
- _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
28291
- var mesh = new ModelMesh(engine);
28292
- mesh._addReferCount(1);
28293
- mesh.setVertexElements([
28294
- new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
28295
- ]);
28296
- var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
28297
- mesh.setVertexBufferBinding(buffer, 16);
28298
- mesh.addSubMesh(0, 3, MeshTopology.Triangles);
28299
- engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
28300
- _inherits$2(_class, ContentRestorer);
28301
- function _class() {
28302
- return ContentRestorer.call(this, mesh) || this;
28303
- }
28304
- var _proto = _class.prototype;
28305
- _proto.restoreContent = function restoreContent() {
28306
- buffer.setData(buffer.data);
28307
- };
28308
- return _class;
28309
- }(ContentRestorer))());
28310
- return mesh;
28311
- };
28312
- _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
28313
- var texture;
28314
- switch(type){
28315
- case 0:
28316
- var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
28317
- texture2D.setPixelBuffer(pixel);
28318
- texture = texture2D;
28319
- break;
28320
- case 2:
28321
- var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
28322
- texture2DArray.setPixelBuffer(0, pixel);
28323
- texture = texture2DArray;
28324
- break;
28325
- case 1:
28326
- var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
28327
- for(var i = 0; i < 6; i++){
28328
- textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
28329
- }
28330
- texture = textureCube;
28331
- break;
28332
- default:
28333
- throw "Invalid texture type";
28334
- }
28335
- texture.isGCIgnored = true;
28336
- engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
28337
- _inherits$2(_class, ContentRestorer);
28338
- function _class() {
28339
- return ContentRestorer.call(this, texture) || this;
28340
- }
28341
- var _proto = _class.prototype;
28342
- _proto.restoreContent = function restoreContent() {
28343
- switch(type){
28344
- case 0:
28345
- this.resource.setPixelBuffer(pixel);
28346
- break;
28347
- case 2:
28348
- this.resource.setPixelBuffer(0, pixel);
28349
- break;
28350
- case 1:
28351
- for(var i = 0; i < 6; i++){
28352
- this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
28353
- }
28354
- break;
28355
- }
28356
- };
28357
- return _class;
28358
- }(ContentRestorer))());
28359
- return texture;
28360
- };
28361
- _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
28362
- var material = new Material(engine, shader);
28363
- var renderState = material.renderState;
28364
- var target = renderState.blendState.targetBlendState;
28365
- target.enabled = true;
28366
- target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
28367
- target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
28368
- target.sourceAlphaBlendFactor = BlendFactor.One;
28369
- target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
28370
- target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
28371
- renderState.depthState.writeEnabled = false;
28372
- renderState.rasterState.cullMode = CullMode.Off;
28373
- renderState.renderQueueType = RenderQueueType.Transparent;
28374
- material.isGCIgnored = true;
28375
- return material;
28376
- };
28377
- _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
28378
- var material = new Material(engine, Shader.find(shaderName));
28379
- material.isGCIgnored = true;
28380
- material.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
28381
- return material;
28382
- };
28383
- _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
28384
- var material = new Material(engine, Shader.find("SpriteMask"));
28385
- material.isGCIgnored = true;
28386
- return material;
28387
- };
28388
- BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
28389
- var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
28390
- var renderStates;
28391
- var compareFunction;
28392
- if (visibleInsideMask) {
28393
- renderStates = BasicResources._maskReadInsideRenderStates;
28394
- if (renderStates) {
28395
- return renderStates;
28396
- }
28397
- BasicResources._maskReadInsideRenderStates = renderStates = {};
28398
- compareFunction = CompareFunction.LessEqual;
28399
- } else {
28400
- renderStates = BasicResources._maskReadOutsideRenderStates;
28401
- if (renderStates) {
28402
- return renderStates;
28402
+ return this._children;
28403
28403
  }
28404
- BasicResources._maskReadOutsideRenderStates = renderStates = {};
28405
- compareFunction = CompareFunction.Greater;
28406
- }
28407
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
28408
- renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
28409
- renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
28410
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
28411
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
28412
- return renderStates;
28413
- };
28414
- BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
28415
- var isIncrement = maskType === RenderQueueMaskType.Increment;
28416
- var renderStates;
28417
- var passOperation;
28418
- if (isIncrement) {
28419
- renderStates = BasicResources._maskWriteIncrementRenderStates;
28420
- if (renderStates) {
28421
- return renderStates;
28404
+ },
28405
+ {
28406
+ key: "childCount",
28407
+ get: /**
28408
+ * @deprecated Please use `children.length` property instead.
28409
+ * Number of the children entities
28410
+ */ function get() {
28411
+ return this._children.length;
28422
28412
  }
28423
- BasicResources._maskWriteIncrementRenderStates = renderStates = {};
28424
- passOperation = StencilOperation.IncrementSaturate;
28425
- } else {
28426
- renderStates = BasicResources._maskWriteDecrementRenderStates;
28427
- if (renderStates) {
28428
- return renderStates;
28413
+ },
28414
+ {
28415
+ key: "scene",
28416
+ get: /**
28417
+ * The scene the entity belongs to.
28418
+ */ function get() {
28419
+ return this._scene;
28429
28420
  }
28430
- BasicResources._maskWriteDecrementRenderStates = renderStates = {};
28431
- passOperation = StencilOperation.DecrementSaturate;
28432
- }
28433
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
28434
- renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
28435
- renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
28436
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
28437
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
28438
- var failStencilOperation = StencilOperation.Keep;
28439
- renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
28440
- renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
28441
- renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
28442
- renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
28443
- renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
28444
- renderStates[RenderStateElementKey.DepthStateEnabled] = false;
28445
- renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
28446
- return renderStates;
28447
- };
28448
- _create_class$2(BasicResources, [
28421
+ },
28449
28422
  {
28450
- key: "prefilteredDFGTexture",
28451
- get: function get() {
28452
- return this._prefilteredDFGTexture;
28423
+ key: "siblingIndex",
28424
+ get: /**
28425
+ * The sibling index.
28426
+ */ function get() {
28427
+ return this._siblingIndex;
28428
+ },
28429
+ set: function set(value) {
28430
+ if (this._siblingIndex === -1) {
28431
+ throw "The entity " + this.name + " is not in the hierarchy";
28432
+ }
28433
+ if (this._isRoot) {
28434
+ this._setSiblingIndex(this._scene._rootEntities, value);
28435
+ } else {
28436
+ var parent = this._parent;
28437
+ this._setSiblingIndex(parent._children, value);
28438
+ parent._dispatchModify(EntityModifyFlags.Child, parent);
28439
+ }
28453
28440
  }
28454
28441
  }
28455
28442
  ]);
28456
- return BasicResources;
28457
- }();
28458
- BasicResources._maskReadInsideRenderStates = null;
28459
- BasicResources._maskReadOutsideRenderStates = null;
28460
- BasicResources._maskWriteIncrementRenderStates = null;
28461
- BasicResources._maskWriteDecrementRenderStates = null;
28443
+ return Entity;
28444
+ }(EngineObject);
28445
+ /** @internal */ Entity._tempComponentConstructors = [];
28462
28446
  var ObjectPool = /*#__PURE__*/ function() {
28463
28447
  function ObjectPool(type) {
28464
28448
  this._type = type;
@@ -33735,6 +33719,183 @@
33735
33719
  PointerMethods["onPointerDrop"] = "onPointerDrop";
33736
33720
  return PointerMethods;
33737
33721
  }({});
33722
+ /**
33723
+ * Signal is a typed event mechanism for Galacean Engine.
33724
+ * @typeParam T - Tuple type of the signal arguments
33725
+ */ var Signal = /*#__PURE__*/ function() {
33726
+ function Signal() {
33727
+ this._listeners = new SafeLoopArray();
33728
+ }
33729
+ var _proto = Signal.prototype;
33730
+ _proto.on = function on(fnOrTarget, targetOrMethodName) {
33731
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
33732
+ args[_key - 2] = arguments[_key];
33733
+ }
33734
+ this._addListener.apply(this, [].concat([
33735
+ fnOrTarget,
33736
+ targetOrMethodName,
33737
+ false
33738
+ ], args));
33739
+ };
33740
+ _proto.once = function once(fnOrTarget, targetOrMethodName) {
33741
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
33742
+ args[_key - 2] = arguments[_key];
33743
+ }
33744
+ this._addListener.apply(this, [].concat([
33745
+ fnOrTarget,
33746
+ targetOrMethodName,
33747
+ true
33748
+ ], args));
33749
+ };
33750
+ _proto.off = function off(fnOrTarget, targetOrMethodName) {
33751
+ if (typeof fnOrTarget === "function") {
33752
+ var target = targetOrMethodName != null ? targetOrMethodName : null;
33753
+ this._listeners.findAndRemove(function(listener) {
33754
+ if (listener.fn === fnOrTarget && listener.target === target) {
33755
+ listener.destroyed = true;
33756
+ return true;
33757
+ }
33758
+ return false;
33759
+ });
33760
+ } else {
33761
+ var target1 = fnOrTarget;
33762
+ var methodName = targetOrMethodName;
33763
+ this._listeners.findAndRemove(function(listener) {
33764
+ if (listener.target === target1 && listener.methodName === methodName) {
33765
+ listener.destroyed = true;
33766
+ return true;
33767
+ }
33768
+ return false;
33769
+ });
33770
+ }
33771
+ };
33772
+ /**
33773
+ * Remove all listeners, or all listeners for a specific target.
33774
+ * @param target - If provided, only remove listeners bound to this target
33775
+ */ _proto.removeAll = function removeAll(target) {
33776
+ if (target !== undefined) {
33777
+ this._listeners.findAndRemove(function(listener) {
33778
+ if (listener.target === target) {
33779
+ return listener.destroyed = true;
33780
+ }
33781
+ return false;
33782
+ });
33783
+ } else {
33784
+ this._listeners.findAndRemove(function(listener) {
33785
+ return listener.destroyed = true;
33786
+ });
33787
+ }
33788
+ };
33789
+ /**
33790
+ * Invoke the signal, calling all listeners in order.
33791
+ * @param args - Arguments to pass to each listener
33792
+ */ _proto.invoke = function invoke() {
33793
+ var _this, _loop = function _loop(i, n) {
33794
+ var listener = listeners[i];
33795
+ if (listener.destroyed) return "continue";
33796
+ if (listener.methodName && listener.target.destroyed) {
33797
+ listener.destroyed = true;
33798
+ _this._listeners.findAndRemove(function(l) {
33799
+ return l === listener;
33800
+ });
33801
+ return "continue";
33802
+ }
33803
+ listener.fn.apply(listener.target, args);
33804
+ if (listener.once) {
33805
+ listener.destroyed = true;
33806
+ _this._listeners.findAndRemove(function(l) {
33807
+ return l === listener;
33808
+ });
33809
+ }
33810
+ };
33811
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
33812
+ args[_key] = arguments[_key];
33813
+ }
33814
+ var listeners = this._listeners.getLoopArray();
33815
+ for(var i = 0, n = listeners.length; i < n; i++)_this = this, _loop(i);
33816
+ };
33817
+ /**
33818
+ * @internal
33819
+ * Clone listeners to target signal, remapping entity/component references.
33820
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
33821
+ var listeners = this._listeners.getLoopArray();
33822
+ for(var i = 0, n = listeners.length; i < n; i++){
33823
+ var listener = listeners[i];
33824
+ if (listener.destroyed || !listener.methodName) continue;
33825
+ var clonedTarget = CloneUtils.remapComponent(srcRoot, targetRoot, listener.target);
33826
+ if (clonedTarget) {
33827
+ var clonedArgs = this._cloneArguments(listener.arguments, srcRoot, targetRoot);
33828
+ if (listener.once) {
33829
+ var _target;
33830
+ (_target = target).once.apply(_target, [].concat([
33831
+ clonedTarget,
33832
+ listener.methodName
33833
+ ], clonedArgs));
33834
+ } else {
33835
+ var _target1;
33836
+ (_target1 = target).on.apply(_target1, [].concat([
33837
+ clonedTarget,
33838
+ listener.methodName
33839
+ ], clonedArgs));
33840
+ }
33841
+ }
33842
+ }
33843
+ };
33844
+ _proto._cloneArguments = function _cloneArguments(args, srcRoot, targetRoot) {
33845
+ if (!args || args.length === 0) return [];
33846
+ var len = args.length;
33847
+ var clonedArgs = new Array(len);
33848
+ for(var i = 0; i < len; i++){
33849
+ var arg = args[i];
33850
+ if (_instanceof1$2(arg, Entity)) {
33851
+ clonedArgs[i] = CloneUtils.remapEntity(srcRoot, targetRoot, arg);
33852
+ } else if (_instanceof1$2(arg, Component)) {
33853
+ clonedArgs[i] = CloneUtils.remapComponent(srcRoot, targetRoot, arg);
33854
+ } else {
33855
+ clonedArgs[i] = arg;
33856
+ }
33857
+ }
33858
+ return clonedArgs;
33859
+ };
33860
+ _proto._addListener = function _addListener(fnOrTarget, targetOrMethodName, once) {
33861
+ for(var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
33862
+ args[_key - 3] = arguments[_key];
33863
+ }
33864
+ if (typeof fnOrTarget === "function") {
33865
+ this._listeners.push({
33866
+ fn: fnOrTarget,
33867
+ target: targetOrMethodName != null ? targetOrMethodName : null,
33868
+ once: once
33869
+ });
33870
+ } else {
33871
+ var _target, _target1;
33872
+ var target = fnOrTarget;
33873
+ var methodName = targetOrMethodName;
33874
+ var fn = args.length > 0 ? function fn() {
33875
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
33876
+ signalArgs[_key] = arguments[_key];
33877
+ }
33878
+ return (_target = target)[methodName].apply(_target, [].concat(args, signalArgs));
33879
+ } : function() {
33880
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
33881
+ signalArgs[_key] = arguments[_key];
33882
+ }
33883
+ return (_target1 = target)[methodName].apply(_target1, [].concat(signalArgs));
33884
+ };
33885
+ this._listeners.push({
33886
+ fn: fn,
33887
+ target: target,
33888
+ once: once,
33889
+ methodName: methodName,
33890
+ arguments: args
33891
+ });
33892
+ }
33893
+ };
33894
+ return Signal;
33895
+ }();
33896
+ __decorate$1([
33897
+ ignoreClone
33898
+ ], Signal.prototype, "_listeners", void 0);
33738
33899
  /**
33739
33900
  * Loader abstract class.
33740
33901
  */ var Loader = /*#__PURE__*/ function() {
@@ -35809,7 +35970,7 @@
35809
35970
  };
35810
35971
  /**
35811
35972
  * @internal
35812
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
35973
+ */ _proto._cloneTo = function _cloneTo(target) {
35813
35974
  var animatorController = target._animatorController;
35814
35975
  if (animatorController) {
35815
35976
  target._addResourceReferCount(animatorController, 1);
@@ -40918,9 +41079,6 @@
40918
41079
  __decorate$1([
40919
41080
  ignoreClone
40920
41081
  ], ParticleGenerator.prototype, "_subPrimitive", void 0);
40921
- __decorate$1([
40922
- ignoreClone
40923
- ], ParticleGenerator.prototype, "_renderer", void 0);
40924
41082
  __decorate$1([
40925
41083
  ignoreClone
40926
41084
  ], ParticleGenerator.prototype, "_isPlaying", void 0);
@@ -41647,7 +41805,7 @@
41647
41805
  };
41648
41806
  /**
41649
41807
  * @internal
41650
- */ _proto._cloneTo = function _cloneTo(target, _, __) {
41808
+ */ _proto._cloneTo = function _cloneTo(target) {
41651
41809
  target.mesh = this._mesh;
41652
41810
  };
41653
41811
  _create_class$2(MeshShape, [
@@ -42614,7 +42772,7 @@
42614
42772
  };
42615
42773
  /**
42616
42774
  * @internal
42617
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
42775
+ */ _proto._cloneTo = function _cloneTo(target) {
42618
42776
  var _target__clip;
42619
42777
  (_target__clip = target._clip) == null ? void 0 : _target__clip._addReferCount(1);
42620
42778
  target._gainNode.gain.setValueAtTime(target._volume, AudioManager.getContext().currentTime);
@@ -43009,6 +43167,7 @@
43009
43167
  CircleShape: CircleShape,
43010
43168
  ClearableObjectPool: ClearableObjectPool,
43011
43169
  CloneManager: CloneManager,
43170
+ CloneUtils: CloneUtils,
43012
43171
  get Collider () { return exports.Collider; },
43013
43172
  ColliderShape: ColliderShape,
43014
43173
  ColliderShapeUpAxis: ColliderShapeUpAxis,
@@ -43165,6 +43324,7 @@
43165
43324
  ShadowCascadesMode: ShadowCascadesMode,
43166
43325
  ShadowResolution: ShadowResolution,
43167
43326
  ShadowType: ShadowType,
43327
+ Signal: Signal,
43168
43328
  get SimpleSpriteAssembler () { return exports.SimpleSpriteAssembler; },
43169
43329
  SizeOverLifetimeModule: SizeOverLifetimeModule,
43170
43330
  Skin: Skin,
@@ -46266,6 +46426,29 @@
46266
46426
  }
46267
46427
  });
46268
46428
  };
46429
+ _proto.parseSignal = function parseSignal(signalRef) {
46430
+ var _this = this;
46431
+ var signal = new Signal();
46432
+ return Promise.all(signalRef.listeners.map(function(listener) {
46433
+ return Promise.all([
46434
+ _this.parseBasicType(listener.target),
46435
+ listener.arguments ? Promise.all(listener.arguments.map(function(a) {
46436
+ return _this.parseBasicType(a);
46437
+ })) : Promise.resolve([])
46438
+ ]).then(function(param) {
46439
+ var target = param[0], resolvedArgs = param[1];
46440
+ if (target) {
46441
+ var _signal;
46442
+ (_signal = signal).on.apply(_signal, [].concat([
46443
+ target,
46444
+ listener.methodName
46445
+ ], resolvedArgs));
46446
+ }
46447
+ });
46448
+ })).then(function() {
46449
+ return signal;
46450
+ });
46451
+ };
46269
46452
  _proto.parseBasicType = function parseBasicType(value, originValue) {
46270
46453
  var _this = this;
46271
46454
  if (Array.isArray(value)) {
@@ -46290,11 +46473,16 @@
46290
46473
  return resource;
46291
46474
  });
46292
46475
  } else if (ReflectionParser._isComponentRef(value)) {
46293
- var _this__context_components_get;
46294
- return Promise.resolve((_this__context_components_get = this._context.components.get(value.componentId)) != null ? _this__context_components_get : null);
46476
+ var entity = this._resolveEntityByPath(value.entityPath);
46477
+ if (!entity) return Promise.resolve(null);
46478
+ var type = Loader.getClass(value.componentType);
46479
+ if (!type) return Promise.resolve(null);
46480
+ var _entity_getComponents_value_componentIndex;
46481
+ return Promise.resolve((_entity_getComponents_value_componentIndex = entity.getComponents(type, [])[value.componentIndex]) != null ? _entity_getComponents_value_componentIndex : null);
46295
46482
  } else if (ReflectionParser._isEntityRef(value)) {
46296
- // entity reference
46297
- return Promise.resolve(this._context.entityMap.get(value.entityId));
46483
+ return Promise.resolve(this._resolveEntityByPath(value.entityPath));
46484
+ } else if (ReflectionParser._isSignalRef(value)) {
46485
+ return this.parseSignal(value);
46298
46486
  } else if (originValue) {
46299
46487
  var _this2, _loop = function _loop(key) {
46300
46488
  if (key === "methods") {
@@ -46350,6 +46538,16 @@
46350
46538
  return Promise.resolve(entity);
46351
46539
  }
46352
46540
  };
46541
+ _proto._resolveEntityByPath = function _resolveEntityByPath(entityPath) {
46542
+ var _this__context = this._context, rootIds = _this__context.rootIds, entityMap = _this__context.entityMap;
46543
+ if (!entityPath.length || entityPath[0] >= rootIds.length) return null;
46544
+ var entity = entityMap.get(rootIds[entityPath[0]]);
46545
+ for(var i = 1; i < entityPath.length; i++){
46546
+ if (!entity || entityPath[i] >= entity.children.length) return null;
46547
+ entity = entity.children[entityPath[i]];
46548
+ }
46549
+ return entity;
46550
+ };
46353
46551
  ReflectionParser._isClass = function _isClass(value) {
46354
46552
  return value["class"] !== undefined;
46355
46553
  };
@@ -46360,10 +46558,13 @@
46360
46558
  return value["url"] !== undefined;
46361
46559
  };
46362
46560
  ReflectionParser._isEntityRef = function _isEntityRef(value) {
46363
- return value["entityId"] !== undefined;
46561
+ return Array.isArray(value["entityPath"]) && value["componentType"] === undefined;
46364
46562
  };
46365
46563
  ReflectionParser._isComponentRef = function _isComponentRef(value) {
46366
- return value["ownerId"] !== undefined && value["componentId"] !== undefined;
46564
+ return Array.isArray(value["entityPath"]) && value["componentType"] !== undefined;
46565
+ };
46566
+ ReflectionParser._isSignalRef = function _isSignalRef(value) {
46567
+ return value["listeners"] !== undefined;
46367
46568
  };
46368
46569
  ReflectionParser._isMethodObject = function _isMethodObject(value) {
46369
46570
  return Array.isArray(value == null ? void 0 : value.params);
@@ -46586,6 +46787,13 @@
46586
46787
  for(var i = 0, l = entities.length; i < l; i++){
46587
46788
  entityMap.set(entitiesConfig[i].id, entities[i]);
46588
46789
  }
46790
+ // Build rootIds in serialization order (not async completion order)
46791
+ var rootIds = _this.context.rootIds;
46792
+ for(var i1 = 0, l1 = entitiesConfig.length; i1 < l1; i1++){
46793
+ if (!entitiesConfig[i1].parent && !entitiesConfig[i1].strippedId) {
46794
+ rootIds.push(entitiesConfig[i1].id);
46795
+ }
46796
+ }
46589
46797
  return entities;
46590
46798
  });
46591
46799
  };
@@ -46711,7 +46919,6 @@
46711
46919
  _proto._parseEntity = function _parseEntity(entityConfig, engine) {
46712
46920
  var transform = entityConfig.transform;
46713
46921
  var entity = new Entity(engine, entityConfig.name, transform ? Loader.getClass(transform.class) : Transform);
46714
- if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
46715
46922
  this._addEntityPlugin(entityConfig.id, entity);
46716
46923
  return Promise.resolve(entity);
46717
46924
  };
@@ -46724,7 +46931,6 @@
46724
46931
  }).then(function(prefabResource) {
46725
46932
  var entity = _instanceof1(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
46726
46933
  var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
46727
- if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
46728
46934
  _this._generateInstanceContext(entity, instanceContext, "");
46729
46935
  _this._prefabContextMap.set(entity, instanceContext);
46730
46936
  var cbArray = _this._prefabPromiseMap.get(entityConfig.id);
@@ -52704,7 +52910,7 @@
52704
52910
  ], EXT_texture_webp);
52705
52911
 
52706
52912
  //@ts-ignore
52707
- var version = "2.0.0-alpha.14";
52913
+ var version = "2.0.0-alpha.16";
52708
52914
  console.log("Galacean Engine Version: " + version);
52709
52915
  for(var key in CoreObjects){
52710
52916
  Loader.registerClass(key, CoreObjects[key]);
@@ -52777,6 +52983,7 @@
52777
52983
  exports.CircleShape = CircleShape;
52778
52984
  exports.ClearableObjectPool = ClearableObjectPool;
52779
52985
  exports.CloneManager = CloneManager;
52986
+ exports.CloneUtils = CloneUtils;
52780
52987
  exports.ColliderShape = ColliderShape;
52781
52988
  exports.ColliderShapeUpAxis = ColliderShapeUpAxis;
52782
52989
  exports.Collision = Collision;
@@ -52962,6 +53169,7 @@
52962
53169
  exports.ShadowCascadesMode = ShadowCascadesMode;
52963
53170
  exports.ShadowResolution = ShadowResolution;
52964
53171
  exports.ShadowType = ShadowType;
53172
+ exports.Signal = Signal;
52965
53173
  exports.SizeOverLifetimeModule = SizeOverLifetimeModule;
52966
53174
  exports.Skin = Skin;
52967
53175
  exports.SkinnedMeshRenderer = SkinnedMeshRenderer;