@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.
@@ -982,11 +982,15 @@ BoundingBox._tempVec31 = new Vector3();
982
982
  var normal = plane.normal;
983
983
  var zeroTolerance = MathUtil.zeroTolerance;
984
984
  var dir = Vector3.dot(normal, ray.direction);
985
+ var position = Vector3.dot(normal, ray.origin);
985
986
  // Parallel
986
987
  if (Math.abs(dir) < zeroTolerance) {
988
+ // Check if ray origin is on the plane
989
+ if (Math.abs(position + plane.distance) < zeroTolerance) {
990
+ return 0;
991
+ }
987
992
  return -1;
988
993
  }
989
- var position = Vector3.dot(normal, ray.origin);
990
994
  var distance = (-plane.distance - position) / dir;
991
995
  if (distance < 0) {
992
996
  if (distance < -zeroTolerance) {
@@ -5314,74 +5318,69 @@ function _instanceof1$2(left, right) {
5314
5318
  return cloneModes;
5315
5319
  };
5316
5320
  CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode, srcRoot, targetRoot, deepInstanceMap) {
5317
- if (cloneMode === CloneMode.Ignore) {
5321
+ var sourceProperty = source[k];
5322
+ // Remappable references (Entity/Component) are always remapped, regardless of clone decorator
5323
+ if (_instanceof1$2(sourceProperty, Object) && sourceProperty._remap) {
5324
+ target[k] = sourceProperty._remap(srcRoot, targetRoot);
5318
5325
  return;
5319
5326
  }
5320
- var sourceProperty = source[k];
5321
- if (_instanceof1$2(sourceProperty, Object)) {
5322
- if (cloneMode === undefined || cloneMode === CloneMode.Assignment) {
5323
- target[k] = sourceProperty;
5324
- return;
5325
- }
5326
- var type = sourceProperty.constructor;
5327
- switch(type){
5328
- case Uint8Array:
5329
- case Uint16Array:
5330
- case Uint32Array:
5331
- case Int8Array:
5332
- case Int16Array:
5333
- case Int32Array:
5334
- case Float32Array:
5335
- case Float64Array:
5336
- var targetPropertyT = target[k];
5337
- if (targetPropertyT == null || targetPropertyT.length !== sourceProperty.length) {
5338
- target[k] = sourceProperty.slice();
5339
- } else {
5340
- targetPropertyT.set(sourceProperty);
5341
- }
5342
- break;
5343
- case Array:
5344
- var targetPropertyA = target[k];
5345
- var length = sourceProperty.length;
5346
- if (targetPropertyA == null) {
5347
- target[k] = targetPropertyA = new Array(length);
5348
- } else {
5349
- targetPropertyA.length = length;
5350
- }
5351
- for(var i = 0; i < length; i++){
5352
- CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
5353
- }
5354
- break;
5355
- default:
5356
- var targetProperty = target[k];
5357
- // If the target property is undefined, create new instance and keep reference sharing like the source
5327
+ if (cloneMode === CloneMode.Ignore) return;
5328
+ // Primitives, undecorated, or @assignmentClone: direct assign
5329
+ if (!_instanceof1$2(sourceProperty, Object) || cloneMode === undefined || cloneMode === CloneMode.Assignment) {
5330
+ target[k] = sourceProperty;
5331
+ return;
5332
+ }
5333
+ // @shallowClone / @deepClone: deep copy complex objects
5334
+ var type = sourceProperty.constructor;
5335
+ switch(type){
5336
+ case Uint8Array:
5337
+ case Uint16Array:
5338
+ case Uint32Array:
5339
+ case Int8Array:
5340
+ case Int16Array:
5341
+ case Int32Array:
5342
+ case Float32Array:
5343
+ case Float64Array:
5344
+ var targetPropertyT = target[k];
5345
+ if (targetPropertyT == null || targetPropertyT.length !== sourceProperty.length) {
5346
+ target[k] = sourceProperty.slice();
5347
+ } else {
5348
+ targetPropertyT.set(sourceProperty);
5349
+ }
5350
+ break;
5351
+ case Array:
5352
+ var targetPropertyA = target[k];
5353
+ var length = sourceProperty.length;
5354
+ if (targetPropertyA == null) {
5355
+ target[k] = targetPropertyA = new Array(length);
5356
+ } else {
5357
+ targetPropertyA.length = length;
5358
+ }
5359
+ for(var i = 0; i < length; i++){
5360
+ CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
5361
+ }
5362
+ break;
5363
+ default:
5364
+ var targetProperty = target[k];
5365
+ // If the target property is undefined, create new instance and keep reference sharing like the source
5366
+ if (!targetProperty) {
5367
+ targetProperty = deepInstanceMap.get(sourceProperty);
5358
5368
  if (!targetProperty) {
5359
- targetProperty = deepInstanceMap.get(sourceProperty);
5360
- if (!targetProperty) {
5361
- targetProperty = new sourceProperty.constructor();
5362
- deepInstanceMap.set(sourceProperty, targetProperty);
5363
- }
5364
- target[k] = targetProperty;
5369
+ targetProperty = new sourceProperty.constructor();
5370
+ deepInstanceMap.set(sourceProperty, targetProperty);
5365
5371
  }
5366
- if (sourceProperty.copyFrom) {
5367
- // Custom clone
5368
- targetProperty.copyFrom(sourceProperty);
5369
- } else {
5370
- // Universal clone
5371
- var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5372
- for(var _$k in sourceProperty){
5373
- CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
5374
- }
5375
- // Custom incremental clone
5376
- if (sourceProperty._cloneTo) {
5377
- sourceProperty._cloneTo(targetProperty, srcRoot, targetRoot);
5378
- }
5372
+ target[k] = targetProperty;
5373
+ }
5374
+ if (sourceProperty.copyFrom) {
5375
+ targetProperty.copyFrom(sourceProperty);
5376
+ } else {
5377
+ var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5378
+ for(var _$k in sourceProperty){
5379
+ CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
5379
5380
  }
5380
- break;
5381
- }
5382
- } else {
5383
- // null, undefined, primitive type, function
5384
- target[k] = sourceProperty;
5381
+ sourceProperty._cloneTo == null ? void 0 : sourceProperty._cloneTo.call(sourceProperty, targetProperty, srcRoot, targetRoot);
5382
+ }
5383
+ break;
5385
5384
  }
5386
5385
  };
5387
5386
  CloneManager.deepCloneObject = function deepCloneObject(source, target, deepInstanceMap) {
@@ -12328,6 +12327,44 @@ Sky._projectionMatrix = new Matrix(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, Sky._epsilon -
12328
12327
  return Background;
12329
12328
  }();
12330
12329
  /** @internal */ Background._premultiplySolidColor = new Color();
12330
+ /**
12331
+ * @internal
12332
+ * Utility functions for remapping Entity/Component references during cloning.
12333
+ */ var CloneUtils = /*#__PURE__*/ function() {
12334
+ function CloneUtils() {}
12335
+ CloneUtils.remapEntity = function remapEntity(srcRoot, targetRoot, entity) {
12336
+ var path = CloneUtils._tempRemapPath;
12337
+ if (!CloneUtils._getEntityHierarchyPath(srcRoot, entity, path)) return entity;
12338
+ return CloneUtils._getEntityByHierarchyPath(targetRoot, path);
12339
+ };
12340
+ CloneUtils.remapComponent = function remapComponent(srcRoot, targetRoot, component) {
12341
+ var path = CloneUtils._tempRemapPath;
12342
+ var srcEntity = component.entity;
12343
+ if (!CloneUtils._getEntityHierarchyPath(srcRoot, srcEntity, path)) return component;
12344
+ return CloneUtils._getEntityByHierarchyPath(targetRoot, path)._components[srcEntity._components.indexOf(component)];
12345
+ };
12346
+ CloneUtils._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
12347
+ inversePath.length = 0;
12348
+ while(searchEntity !== rootEntity){
12349
+ var parent = searchEntity.parent;
12350
+ if (!parent) {
12351
+ return false;
12352
+ }
12353
+ inversePath.push(searchEntity.siblingIndex);
12354
+ searchEntity = parent;
12355
+ }
12356
+ return true;
12357
+ };
12358
+ CloneUtils._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
12359
+ var entity = rootEntity;
12360
+ for(var i = inversePath.length - 1; i >= 0; i--){
12361
+ entity = entity.children[inversePath[i]];
12362
+ }
12363
+ return entity;
12364
+ };
12365
+ return CloneUtils;
12366
+ }();
12367
+ CloneUtils._tempRemapPath = [];
12331
12368
  var ActiveChangeFlag = /*#__PURE__*/ function(ActiveChangeFlag) {
12332
12369
  ActiveChangeFlag[ActiveChangeFlag["None"] = 0] = "None";
12333
12370
  ActiveChangeFlag[ActiveChangeFlag["Scene"] = 1] = "Scene";
@@ -12402,6 +12439,11 @@ var ActiveChangeFlag = /*#__PURE__*/ function(ActiveChangeFlag) {
12402
12439
  }
12403
12440
  }
12404
12441
  };
12442
+ /**
12443
+ * @internal
12444
+ */ _proto._remap = function _remap(srcRoot, targetRoot) {
12445
+ return CloneUtils.remapComponent(srcRoot, targetRoot, this);
12446
+ };
12405
12447
  _proto._addResourceReferCount = function _addResourceReferCount(resource, count) {
12406
12448
  this._entity._isTemplate || resource._addReferCount(count);
12407
12449
  };
@@ -12475,9 +12517,6 @@ var ActiveChangeFlag = /*#__PURE__*/ function(ActiveChangeFlag) {
12475
12517
  ]);
12476
12518
  return Component;
12477
12519
  }(EngineObject);
12478
- __decorate$1([
12479
- ignoreClone
12480
- ], Component.prototype, "_entity", void 0);
12481
12520
  __decorate$1([
12482
12521
  ignoreClone
12483
12522
  ], Component.prototype, "_awoken", void 0);
@@ -12841,7 +12880,7 @@ function dependentComponents(componentOrComponents, dependentMode) {
12841
12880
  };
12842
12881
  /**
12843
12882
  * @internal
12844
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
12883
+ */ _proto._cloneTo = function _cloneTo(target) {
12845
12884
  var position = target._position, rotation = target._rotation, scale = target._scale;
12846
12885
  // @ts-ignore
12847
12886
  position._onValueChanged = rotation._onValueChanged = scale._onValueChanged = null;
@@ -13453,9 +13492,6 @@ __decorate$1([
13453
13492
  __decorate$1([
13454
13493
  ignoreClone
13455
13494
  ], Transform.prototype, "_isParentDirty", void 0);
13456
- __decorate$1([
13457
- ignoreClone
13458
- ], Transform.prototype, "_parentTransformCache", void 0);
13459
13495
  __decorate$1([
13460
13496
  ignoreClone
13461
13497
  ], Transform.prototype, "_dirtyFlag", void 0);
@@ -13914,7 +13950,7 @@ var Camera = /*#__PURE__*/ function(Component) {
13914
13950
  };
13915
13951
  /**
13916
13952
  * @internal
13917
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
13953
+ */ _proto._cloneTo = function _cloneTo(target) {
13918
13954
  var _this__renderTarget;
13919
13955
  (_this__renderTarget = this._renderTarget) == null ? void 0 : _this__renderTarget._addReferCount(1);
13920
13956
  };
@@ -17117,9 +17153,6 @@ __decorate$1([
17117
17153
  return ColliderShape;
17118
17154
  }();
17119
17155
  ColliderShape._idGenerator = 0;
17120
- __decorate$1([
17121
- ignoreClone
17122
- ], ColliderShape.prototype, "_collider", void 0);
17123
17156
  __decorate$1([
17124
17157
  ignoreClone
17125
17158
  ], ColliderShape.prototype, "_nativeShape", void 0);
@@ -21501,7 +21534,7 @@ var Renderer = /*#__PURE__*/ function(Component) {
21501
21534
  };
21502
21535
  /**
21503
21536
  * @internal
21504
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
21537
+ */ _proto._cloneTo = function _cloneTo(target) {
21505
21538
  var materials = this._materials;
21506
21539
  for(var i = 0, n = materials.length; i < n; i++){
21507
21540
  target._setMaterial(i, materials[i]);
@@ -21756,9 +21789,6 @@ __decorate$1([
21756
21789
  __decorate$1([
21757
21790
  ignoreClone
21758
21791
  ], Renderer.prototype, "_bounds", void 0);
21759
- __decorate$1([
21760
- ignoreClone
21761
- ], Renderer.prototype, "_transformEntity", void 0);
21762
21792
  __decorate$1([
21763
21793
  deepClone
21764
21794
  ], Renderer.prototype, "_shaderData", void 0);
@@ -21817,8 +21847,8 @@ var RendererUpdateFlags = /*#__PURE__*/ function(RendererUpdateFlags) {
21817
21847
  };
21818
21848
  /**
21819
21849
  * @internal
21820
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
21821
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
21850
+ */ _proto._cloneTo = function _cloneTo(target) {
21851
+ Renderer.prototype._cloneTo.call(this, target);
21822
21852
  target.sprite = this._sprite;
21823
21853
  };
21824
21854
  /**
@@ -22128,8 +22158,8 @@ __decorate$1([
22128
22158
  };
22129
22159
  /**
22130
22160
  * @internal
22131
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
22132
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
22161
+ */ _proto._cloneTo = function _cloneTo(target) {
22162
+ Renderer.prototype._cloneTo.call(this, target);
22133
22163
  target.sprite = this._sprite;
22134
22164
  target.drawMode = this._drawMode;
22135
22165
  };
@@ -22551,8 +22581,8 @@ __decorate$1([
22551
22581
  };
22552
22582
  /**
22553
22583
  * @internal
22554
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
22555
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
22584
+ */ _proto._cloneTo = function _cloneTo(target) {
22585
+ Renderer.prototype._cloneTo.call(this, target);
22556
22586
  target.font = this._font;
22557
22587
  target._subFont = this._subFont;
22558
22588
  };
@@ -24234,8 +24264,8 @@ var BlendShapeFrameDirty = /*#__PURE__*/ function(BlendShapeFrameDirty) {
24234
24264
  };
24235
24265
  /**
24236
24266
  * @internal
24237
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
24238
- Renderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
24267
+ */ _proto._cloneTo = function _cloneTo(target) {
24268
+ Renderer.prototype._cloneTo.call(this, target);
24239
24269
  target.mesh = this._mesh;
24240
24270
  };
24241
24271
  /**
@@ -27090,224 +27120,861 @@ PrimitiveMesh._sphereSeedCells = new Float32Array([
27090
27120
  ]);
27091
27121
  PrimitiveMesh._sphereEdgeIdx = 0;
27092
27122
  PrimitiveMesh._spherePoleIdx = 0;
27093
- function _is_native_reflect_construct$1() {
27094
- // Since Reflect.construct can't be properly polyfilled, some
27095
- // implementations (e.g. core-js@2) don't set the correct internal slots.
27096
- // Those polyfills don't allow us to subclass built-ins, so we need to
27097
- // use our fallback implementation.
27098
- try {
27099
- // If the internal slots aren't set, this throws an error similar to
27100
- // TypeError: this is not a Boolean object.
27101
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
27102
- } catch (_) {}
27103
- return (_is_native_reflect_construct$1 = function _is_native_reflect_construct() {
27104
- return !!result;
27105
- })();
27106
- }
27107
- function _construct$1(Parent, args, Class) {
27108
- if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
27109
- else {
27110
- _construct$1 = function construct(Parent, args, Class) {
27111
- var a = [
27112
- null
27113
- ];
27114
- a.push.apply(a, args);
27115
- var Constructor = Function.bind.apply(Parent, a);
27116
- var instance = new Constructor();
27117
- if (Class) _set_prototype_of$2(instance, Class.prototype);
27118
- return instance;
27119
- };
27123
+ /**
27124
+ * Skin used for skinned mesh renderer.
27125
+ */ var Skin = /*#__PURE__*/ function(EngineObject) {
27126
+ _inherits$2(Skin, EngineObject);
27127
+ function Skin(name) {
27128
+ var _this;
27129
+ _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 = [];
27130
+ return _this;
27120
27131
  }
27121
- return _construct$1.apply(null, arguments);
27122
- }
27123
- var ComponentCloner = /*#__PURE__*/ function() {
27124
- function ComponentCloner() {}
27132
+ var _proto = Skin.prototype;
27125
27133
  /**
27126
- * Clone component.
27127
- * @param source - Clone source
27128
- * @param target - Clone target
27129
- */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
27130
- var cloneModes = CloneManager.getCloneMode(source.constructor);
27131
- for(var k in source){
27132
- CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
27134
+ * @internal
27135
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
27136
+ if (this._updateMark === renderer.engine.time.frameCount) {
27137
+ return;
27133
27138
  }
27134
- if (source._cloneTo) {
27135
- source._cloneTo(target, srcRoot, targetRoot);
27139
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
27140
+ var _this_rootBone;
27141
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
27142
+ for(var i = bones.length - 1; i >= 0; i--){
27143
+ var bone = bones[i];
27144
+ var offset = i * 16;
27145
+ if (bone) {
27146
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
27147
+ } else {
27148
+ skinMatrices.set(bindMatrices[i].elements, offset);
27149
+ }
27150
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
27136
27151
  }
27152
+ this._updateMark = renderer.engine.time.frameCount;
27137
27153
  };
27138
- return ComponentCloner;
27139
- }();
27140
- /**
27141
- * The entity modify flags.
27142
- */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
27143
- /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
27144
- /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
27145
- return EntityModifyFlags;
27154
+ _create_class$2(Skin, [
27155
+ {
27156
+ key: "rootBone",
27157
+ get: /**
27158
+ * Root bone.
27159
+ */ function get() {
27160
+ return this._rootBone;
27161
+ },
27162
+ set: function set(value) {
27163
+ if (this._rootBone !== value) {
27164
+ this._updatedManager.dispatch(1, value);
27165
+ this._rootBone = value;
27166
+ }
27167
+ }
27168
+ },
27169
+ {
27170
+ key: "bones",
27171
+ get: /**
27172
+ * Bones of the skin.
27173
+ */ function get() {
27174
+ return this._bones;
27175
+ },
27176
+ set: function set(value) {
27177
+ var bones = this._bones;
27178
+ var _value_length;
27179
+ var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
27180
+ var lastBoneCount = bones.length;
27181
+ bones.length = boneCount;
27182
+ for(var i = 0; i < boneCount; i++){
27183
+ bones[i] = value[i];
27184
+ }
27185
+ if (lastBoneCount !== boneCount) {
27186
+ this._skinMatrices = new Float32Array(boneCount * 16);
27187
+ this._updatedManager.dispatch(0, boneCount);
27188
+ }
27189
+ }
27190
+ },
27191
+ {
27192
+ key: "skeleton",
27193
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
27194
+ var _this_rootBone;
27195
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
27196
+ },
27197
+ set: function set(value) {
27198
+ var rootBone = this._rootBone;
27199
+ if (rootBone) {
27200
+ rootBone.name = value;
27201
+ }
27202
+ }
27203
+ }
27204
+ ]);
27205
+ return Skin;
27206
+ }(EngineObject);
27207
+ __decorate$1([
27208
+ deepClone
27209
+ ], Skin.prototype, "inverseBindMatrices", void 0);
27210
+ __decorate$1([
27211
+ ignoreClone
27212
+ ], Skin.prototype, "_skinMatrices", void 0);
27213
+ __decorate$1([
27214
+ ignoreClone
27215
+ ], Skin.prototype, "_updatedManager", void 0);
27216
+ __decorate$1([
27217
+ deepClone
27218
+ ], Skin.prototype, "_bones", void 0);
27219
+ __decorate$1([
27220
+ ignoreClone
27221
+ ], Skin.prototype, "_updateMark", void 0);
27222
+ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
27223
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
27224
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
27225
+ return SkinUpdateFlag;
27146
27226
  }({});
27147
27227
  /**
27148
- * Entity, be used as components container.
27149
- */ var Entity = /*#__PURE__*/ function(EngineObject) {
27150
- _inherits$2(Entity, EngineObject);
27151
- function Entity(engine, name) {
27152
- for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
27153
- components[_key - 2] = arguments[_key];
27154
- }
27228
+ * SkinnedMeshRenderer.
27229
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
27230
+ _inherits$2(SkinnedMeshRenderer, MeshRenderer);
27231
+ function SkinnedMeshRenderer(entity) {
27155
27232
  var _this;
27156
- _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();
27157
- _this.name = name != null ? name : "Entity";
27158
- for(var i = 0, n = components.length; i < n; i++){
27159
- _this.addComponent(components[i]);
27160
- }
27161
- !_this._transform && _this.addComponent(Transform);
27162
- _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
27233
+ _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new BoundingBox(), _this._jointDataCreateCache = new Vector2(-1, -1);
27234
+ _this._skin = null;
27235
+ var rhi = _this.entity.engine._hardwareRenderer;
27236
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
27237
+ // Limit size to 256 to avoid some problem:
27238
+ // 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!
27239
+ // 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.
27240
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
27241
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
27242
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
27243
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
27244
+ var localBounds = _this._localBounds;
27245
+ // @ts-ignore
27246
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
27247
+ // @ts-ignore
27248
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
27163
27249
  return _this;
27164
27250
  }
27165
- var _proto = Entity.prototype;
27251
+ var _proto = SkinnedMeshRenderer.prototype;
27166
27252
  /**
27167
- * Add component based on the component type.
27168
- * @param type - The type of the component
27169
- * @param args - The arguments of the component
27170
- * @returns The component which has been added
27171
- */ _proto.addComponent = function addComponent(type) {
27172
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
27173
- args[_key - 1] = arguments[_key];
27174
- }
27175
- ComponentsDependencies._addCheck(this, type);
27176
- var component = _construct$1(type, [].concat([
27177
- this
27178
- ], args));
27179
- this._components.push(component);
27180
- // @todo: temporary solution
27181
- if (_instanceof1$2(component, Transform)) this._setTransform(component);
27182
- component._setActive(true, ActiveChangeFlag.All);
27183
- return component;
27253
+ * @internal
27254
+ */ _proto._onDestroy = function _onDestroy() {
27255
+ var _this__jointTexture;
27256
+ MeshRenderer.prototype._onDestroy.call(this);
27257
+ this._jointDataCreateCache = null;
27258
+ this._skin = null;
27259
+ this._blendShapeWeights = null;
27260
+ this._localBounds = null;
27261
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27262
+ this._jointTexture = null;
27184
27263
  };
27185
27264
  /**
27186
- * Get component which match the type.
27187
- * @param type - The type of the component
27188
- * @returns The first component which match type
27189
- */ _proto.getComponent = function getComponent(type) {
27190
- var components = this._components;
27191
- for(var i = 0, n = components.length; i < n; i++){
27192
- var component = components[i];
27193
- if (_instanceof1$2(component, type)) {
27194
- return component;
27195
- }
27265
+ * @internal
27266
+ */ _proto._cloneTo = function _cloneTo(target) {
27267
+ MeshRenderer.prototype._cloneTo.call(this, target);
27268
+ if (this.skin) {
27269
+ target._applySkin(null, target.skin);
27196
27270
  }
27197
- return null;
27271
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
27198
27272
  };
27199
- /**
27200
- * Get components which match the type.
27201
- * @param type - The type of the component
27202
- * @param results - The components which match type
27203
- * @returns The components which match type
27204
- */ _proto.getComponents = function getComponents(type, results) {
27205
- results.length = 0;
27206
- var components = this._components;
27207
- for(var i = 0, n = components.length; i < n; i++){
27208
- var component = components[i];
27209
- if (_instanceof1$2(component, type)) {
27210
- results.push(component);
27273
+ _proto._update = function _update(context) {
27274
+ var skin = this.skin;
27275
+ if ((skin == null ? void 0 : skin.bones.length) > 0) {
27276
+ skin._updateSkinMatrices(this);
27277
+ }
27278
+ var shaderData = this.shaderData;
27279
+ var mesh = this.mesh;
27280
+ var blendShapeManager = mesh._blendShapeManager;
27281
+ blendShapeManager._updateShaderData(shaderData, this);
27282
+ var bones = skin == null ? void 0 : skin.bones;
27283
+ if (bones) {
27284
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
27285
+ var boneCount = bones.length;
27286
+ var boneDataCreateCache = this._jointDataCreateCache;
27287
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
27288
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
27289
+ // directly use max joint count to avoid shader recompile
27290
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
27291
+ if (boneCount > remainUniformJointCount) {
27292
+ var engine = this.engine;
27293
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
27294
+ if (boneCountChange) {
27295
+ var _this__jointTexture;
27296
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27297
+ this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
27298
+ this._jointTexture.filterMode = TextureFilterMode.Point;
27299
+ this._jointTexture.isGCIgnored = true;
27300
+ }
27301
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
27302
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
27303
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
27304
+ } else {
27305
+ 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);
27306
+ }
27307
+ } else {
27308
+ var _this__jointTexture1;
27309
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
27310
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
27311
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
27312
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
27313
+ }
27314
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
27315
+ }
27316
+ if (this._jointTexture) {
27317
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
27211
27318
  }
27212
27319
  }
27213
- return results;
27320
+ MeshRenderer.prototype._update.call(this, context);
27214
27321
  };
27215
27322
  /**
27216
- * Get the components which match the type of the entity and it's children.
27217
- * @param type - The component type
27218
- * @param results - The components collection
27219
- * @returns The components collection which match the type
27220
- */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
27221
- results.length = 0;
27222
- this._getComponentsInChildren(type, results);
27223
- return results;
27224
- };
27225
- _proto.addChild = function addChild(indexOrChild, child) {
27226
- var index;
27227
- if (typeof indexOrChild === "number") {
27228
- index = indexOrChild;
27323
+ * @internal
27324
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
27325
+ var _this_skin;
27326
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
27327
+ if (rootBone) {
27328
+ BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
27229
27329
  } else {
27230
- index = undefined;
27231
- child = indexOrChild;
27330
+ MeshRenderer.prototype._updateBounds.call(this, worldBounds);
27232
27331
  }
27233
- child._setParent(this, index);
27234
- };
27235
- /**
27236
- * Remove child entity.
27237
- * @param child - The child entity which want to be removed
27238
- */ _proto.removeChild = function removeChild(child) {
27239
- if (child._parent !== this) return;
27240
- child._setParent(null);
27241
- };
27242
- /**
27243
- * @deprecated Please use `children` property instead.
27244
- * Find child entity by index.
27245
- * @param index - The index of the child entity
27246
- * @returns The component which be found
27247
- */ _proto.getChild = function getChild(index) {
27248
- return this._children[index];
27249
27332
  };
27250
- /**
27251
- * Find entity by name.
27252
- * @param name - The name of the entity which want to be found
27253
- * @returns The component which be found
27254
- */ _proto.findByName = function findByName(name) {
27255
- if (name === this.name) {
27256
- return this;
27257
- }
27258
- var children = this._children;
27259
- for(var i = 0, n = children.length; i < n; i++){
27260
- var target = children[i].findByName(name);
27261
- if (target) {
27262
- return target;
27333
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
27334
+ var mesh = this._mesh;
27335
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
27336
+ var lastBlendShapeWeights = this._blendShapeWeights;
27337
+ if (lastBlendShapeWeights) {
27338
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
27339
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
27340
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
27341
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
27342
+ newBlendShapeWeights.set(lastBlendShapeWeights);
27343
+ } else {
27344
+ for(var i = 0; i < newBlendShapeCount; i++){
27345
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
27346
+ }
27347
+ }
27348
+ this._blendShapeWeights = newBlendShapeWeights;
27263
27349
  }
27350
+ } else {
27351
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
27264
27352
  }
27265
- return null;
27266
27353
  };
27267
- /**
27268
- * Find the entity by path.
27269
- * @param path - The path of the entity eg: /entity
27270
- * @returns The component which be found
27271
- */ _proto.findByPath = function findByPath(path) {
27272
- var splits = path.split("/").filter(Boolean);
27273
- if (!splits.length) {
27274
- return this;
27275
- }
27276
- return Entity._findChildByName(this, 0, splits, 0);
27354
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
27355
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
27277
27356
  };
27278
- /**
27279
- * Create child entity.
27280
- * @param name - The child entity's name
27281
- * @returns The child entity
27282
- */ _proto.createChild = function createChild(name) {
27283
- var transform = this._transform;
27284
- var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
27285
- child.layer = this.layer;
27286
- child.parent = this;
27287
- return child;
27357
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
27358
+ switch(type){
27359
+ case SkinUpdateFlag.BoneCountChanged:
27360
+ var shaderData = this.shaderData;
27361
+ if (value > 0) {
27362
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
27363
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
27364
+ } else {
27365
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
27366
+ }
27367
+ break;
27368
+ case SkinUpdateFlag.RootBoneChanged:
27369
+ this._setTransformEntity(value);
27370
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
27371
+ break;
27372
+ }
27288
27373
  };
27289
- /**
27290
- * Clear children entities.
27291
- */ _proto.clearChildren = function clearChildren() {
27292
- var children = this._children;
27293
- for(var i = children.length - 1; i >= 0; i--){
27294
- var child = children[i];
27295
- child._parent = null;
27296
- var activeChangeFlag = ActiveChangeFlag.None;
27297
- child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27298
- child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
27299
- activeChangeFlag && child._processInActive(activeChangeFlag);
27300
- Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
27374
+ _proto._applySkin = function _applySkin(lastSkin, value) {
27375
+ var _lastSkin_bones, _value_bones;
27376
+ var _lastSkin_bones_length;
27377
+ var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
27378
+ var _lastSkin_rootBone;
27379
+ var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
27380
+ lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
27381
+ var _value_bones_length;
27382
+ var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
27383
+ var _value_rootBone;
27384
+ var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
27385
+ value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
27386
+ if (lastSkinBoneCount !== skinBoneCount) {
27387
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
27388
+ }
27389
+ if (lastRootBone !== rootBone) {
27390
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
27301
27391
  }
27302
- children.length = 0;
27303
27392
  };
27304
- /**
27305
- * Clone this entity include children and components.
27306
- * @returns Cloned entity
27307
- */ _proto.clone = function clone() {
27308
- var cloneEntity = this._createCloneEntity();
27309
- this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
27310
- return cloneEntity;
27393
+ _create_class$2(SkinnedMeshRenderer, [
27394
+ {
27395
+ key: "skin",
27396
+ get: /**
27397
+ * Skin of the SkinnedMeshRenderer.
27398
+ */ function get() {
27399
+ return this._skin;
27400
+ },
27401
+ set: function set(value) {
27402
+ var lastSkin = this._skin;
27403
+ if (lastSkin !== value) {
27404
+ this._applySkin(lastSkin, value);
27405
+ this._skin = value;
27406
+ }
27407
+ }
27408
+ },
27409
+ {
27410
+ key: "blendShapeWeights",
27411
+ get: /**
27412
+ * The weights of the BlendShapes.
27413
+ * @remarks Array index is BlendShape index.
27414
+ */ function get() {
27415
+ this._checkBlendShapeWeightLength();
27416
+ return this._blendShapeWeights;
27417
+ },
27418
+ set: function set(value) {
27419
+ this._checkBlendShapeWeightLength();
27420
+ var blendShapeWeights = this._blendShapeWeights;
27421
+ if (value.length <= blendShapeWeights.length) {
27422
+ blendShapeWeights.set(value);
27423
+ } else {
27424
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
27425
+ blendShapeWeights[i] = value[i];
27426
+ }
27427
+ }
27428
+ }
27429
+ },
27430
+ {
27431
+ key: "localBounds",
27432
+ get: /**
27433
+ * Local bounds.
27434
+ */ function get() {
27435
+ return this._localBounds;
27436
+ },
27437
+ set: function set(value) {
27438
+ if (this._localBounds !== value) {
27439
+ this._localBounds.copyFrom(value);
27440
+ }
27441
+ }
27442
+ },
27443
+ {
27444
+ key: "rootBone",
27445
+ get: /**
27446
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
27447
+ */ function get() {
27448
+ return this.skin.rootBone;
27449
+ },
27450
+ set: function set(value) {
27451
+ this.skin.rootBone = value;
27452
+ }
27453
+ },
27454
+ {
27455
+ key: "bones",
27456
+ get: /**
27457
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
27458
+ */ function get() {
27459
+ return this.skin.bones;
27460
+ },
27461
+ set: function set(value) {
27462
+ this.skin.bones = value;
27463
+ }
27464
+ }
27465
+ ]);
27466
+ return SkinnedMeshRenderer;
27467
+ }(MeshRenderer);
27468
+ // @TODO: different shader type should use different count, not always 48
27469
+ /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
27470
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
27471
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
27472
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
27473
+ __decorate$1([
27474
+ ignoreClone
27475
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
27476
+ __decorate$1([
27477
+ deepClone
27478
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
27479
+ __decorate$1([
27480
+ ignoreClone
27481
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
27482
+ __decorate$1([
27483
+ ignoreClone
27484
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
27485
+ __decorate$1([
27486
+ ignoreClone
27487
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
27488
+ __decorate$1([
27489
+ ignoreClone
27490
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
27491
+ __decorate$1([
27492
+ deepClone
27493
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
27494
+ __decorate$1([
27495
+ ignoreClone
27496
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
27497
+ __decorate$1([
27498
+ ignoreClone
27499
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
27500
+ /**
27501
+ * @internal
27502
+ */ var BasicResources = /*#__PURE__*/ function() {
27503
+ function BasicResources(engine) {
27504
+ this.engine = engine;
27505
+ // prettier-ignore
27506
+ var vertices = new Float32Array([
27507
+ -1,
27508
+ -1,
27509
+ 0,
27510
+ 1,
27511
+ 3,
27512
+ -1,
27513
+ 2,
27514
+ 1,
27515
+ -1,
27516
+ 3,
27517
+ 0,
27518
+ -1
27519
+ ]); // left-top
27520
+ // prettier-ignore
27521
+ var flipYVertices = new Float32Array([
27522
+ 3,
27523
+ -1,
27524
+ 2,
27525
+ 0,
27526
+ -1,
27527
+ -1,
27528
+ 0,
27529
+ 0,
27530
+ -1,
27531
+ 3,
27532
+ 0,
27533
+ 2
27534
+ ]); // left-top
27535
+ var blitMaterial = new Material(engine, Shader.find("blit"));
27536
+ blitMaterial._addReferCount(1);
27537
+ blitMaterial.renderState.depthState.enabled = false;
27538
+ blitMaterial.renderState.depthState.writeEnabled = false;
27539
+ var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
27540
+ blitScreenMaterial._addReferCount(1);
27541
+ blitScreenMaterial.renderState.depthState.enabled = false;
27542
+ blitScreenMaterial.renderState.depthState.writeEnabled = false;
27543
+ this.blitMaterial = blitMaterial;
27544
+ this.blitScreenMaterial = blitScreenMaterial;
27545
+ this.blitMesh = this._createBlitMesh(engine, vertices);
27546
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
27547
+ // Create white and magenta textures
27548
+ var whitePixel = new Uint8Array([
27549
+ 255,
27550
+ 255,
27551
+ 255,
27552
+ 255
27553
+ ]);
27554
+ this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
27555
+ this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
27556
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
27557
+ if (isWebGL2) {
27558
+ this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
27559
+ var whitePixel32 = new Uint32Array([
27560
+ 255,
27561
+ 255,
27562
+ 255,
27563
+ 255
27564
+ ]);
27565
+ this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
27566
+ }
27567
+ this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
27568
+ this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
27569
+ this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
27570
+ this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
27571
+ this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
27572
+ }
27573
+ var _proto = BasicResources.prototype;
27574
+ /**
27575
+ * @internal
27576
+ */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
27577
+ return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
27578
+ };
27579
+ /**
27580
+ * @internal
27581
+ */ _proto._initialize = function _initialize() {
27582
+ var _this = this;
27583
+ return new Promise(function(resolve, reject) {
27584
+ PrefilteredDFG.create(_this.engine).then(function(texture) {
27585
+ _this._prefilteredDFGTexture = texture;
27586
+ resolve(_this);
27587
+ }).catch(reject);
27588
+ });
27589
+ };
27590
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
27591
+ var mesh = new ModelMesh(engine);
27592
+ mesh._addReferCount(1);
27593
+ mesh.setVertexElements([
27594
+ new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
27595
+ ]);
27596
+ var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
27597
+ mesh.setVertexBufferBinding(buffer, 16);
27598
+ mesh.addSubMesh(0, 3, MeshTopology.Triangles);
27599
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
27600
+ _inherits$2(_class, ContentRestorer);
27601
+ function _class() {
27602
+ return ContentRestorer.call(this, mesh) || this;
27603
+ }
27604
+ var _proto = _class.prototype;
27605
+ _proto.restoreContent = function restoreContent() {
27606
+ buffer.setData(buffer.data);
27607
+ };
27608
+ return _class;
27609
+ }(ContentRestorer))());
27610
+ return mesh;
27611
+ };
27612
+ _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
27613
+ var texture;
27614
+ switch(type){
27615
+ case 0:
27616
+ var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
27617
+ texture2D.setPixelBuffer(pixel);
27618
+ texture = texture2D;
27619
+ break;
27620
+ case 2:
27621
+ var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
27622
+ texture2DArray.setPixelBuffer(0, pixel);
27623
+ texture = texture2DArray;
27624
+ break;
27625
+ case 1:
27626
+ var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
27627
+ for(var i = 0; i < 6; i++){
27628
+ textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
27629
+ }
27630
+ texture = textureCube;
27631
+ break;
27632
+ default:
27633
+ throw "Invalid texture type";
27634
+ }
27635
+ texture.isGCIgnored = true;
27636
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
27637
+ _inherits$2(_class, ContentRestorer);
27638
+ function _class() {
27639
+ return ContentRestorer.call(this, texture) || this;
27640
+ }
27641
+ var _proto = _class.prototype;
27642
+ _proto.restoreContent = function restoreContent() {
27643
+ switch(type){
27644
+ case 0:
27645
+ this.resource.setPixelBuffer(pixel);
27646
+ break;
27647
+ case 2:
27648
+ this.resource.setPixelBuffer(0, pixel);
27649
+ break;
27650
+ case 1:
27651
+ for(var i = 0; i < 6; i++){
27652
+ this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
27653
+ }
27654
+ break;
27655
+ }
27656
+ };
27657
+ return _class;
27658
+ }(ContentRestorer))());
27659
+ return texture;
27660
+ };
27661
+ _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
27662
+ var material = new Material(engine, shader);
27663
+ var renderState = material.renderState;
27664
+ var target = renderState.blendState.targetBlendState;
27665
+ target.enabled = true;
27666
+ target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
27667
+ target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
27668
+ target.sourceAlphaBlendFactor = BlendFactor.One;
27669
+ target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
27670
+ target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
27671
+ renderState.depthState.writeEnabled = false;
27672
+ renderState.rasterState.cullMode = CullMode.Off;
27673
+ renderState.renderQueueType = RenderQueueType.Transparent;
27674
+ material.isGCIgnored = true;
27675
+ return material;
27676
+ };
27677
+ _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
27678
+ var material = new Material(engine, Shader.find(shaderName));
27679
+ material.isGCIgnored = true;
27680
+ material.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
27681
+ return material;
27682
+ };
27683
+ _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
27684
+ var material = new Material(engine, Shader.find("SpriteMask"));
27685
+ material.isGCIgnored = true;
27686
+ return material;
27687
+ };
27688
+ BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
27689
+ var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
27690
+ var renderStates;
27691
+ var compareFunction;
27692
+ if (visibleInsideMask) {
27693
+ renderStates = BasicResources._maskReadInsideRenderStates;
27694
+ if (renderStates) {
27695
+ return renderStates;
27696
+ }
27697
+ BasicResources._maskReadInsideRenderStates = renderStates = {};
27698
+ compareFunction = CompareFunction.LessEqual;
27699
+ } else {
27700
+ renderStates = BasicResources._maskReadOutsideRenderStates;
27701
+ if (renderStates) {
27702
+ return renderStates;
27703
+ }
27704
+ BasicResources._maskReadOutsideRenderStates = renderStates = {};
27705
+ compareFunction = CompareFunction.Greater;
27706
+ }
27707
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
27708
+ renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
27709
+ renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
27710
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
27711
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
27712
+ return renderStates;
27713
+ };
27714
+ BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
27715
+ var isIncrement = maskType === RenderQueueMaskType.Increment;
27716
+ var renderStates;
27717
+ var passOperation;
27718
+ if (isIncrement) {
27719
+ renderStates = BasicResources._maskWriteIncrementRenderStates;
27720
+ if (renderStates) {
27721
+ return renderStates;
27722
+ }
27723
+ BasicResources._maskWriteIncrementRenderStates = renderStates = {};
27724
+ passOperation = StencilOperation.IncrementSaturate;
27725
+ } else {
27726
+ renderStates = BasicResources._maskWriteDecrementRenderStates;
27727
+ if (renderStates) {
27728
+ return renderStates;
27729
+ }
27730
+ BasicResources._maskWriteDecrementRenderStates = renderStates = {};
27731
+ passOperation = StencilOperation.DecrementSaturate;
27732
+ }
27733
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
27734
+ renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
27735
+ renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
27736
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
27737
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
27738
+ var failStencilOperation = StencilOperation.Keep;
27739
+ renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
27740
+ renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
27741
+ renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
27742
+ renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
27743
+ renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
27744
+ renderStates[RenderStateElementKey.DepthStateEnabled] = false;
27745
+ renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
27746
+ return renderStates;
27747
+ };
27748
+ _create_class$2(BasicResources, [
27749
+ {
27750
+ key: "prefilteredDFGTexture",
27751
+ get: function get() {
27752
+ return this._prefilteredDFGTexture;
27753
+ }
27754
+ }
27755
+ ]);
27756
+ return BasicResources;
27757
+ }();
27758
+ BasicResources._maskReadInsideRenderStates = null;
27759
+ BasicResources._maskReadOutsideRenderStates = null;
27760
+ BasicResources._maskWriteIncrementRenderStates = null;
27761
+ BasicResources._maskWriteDecrementRenderStates = null;
27762
+ function _is_native_reflect_construct$1() {
27763
+ // Since Reflect.construct can't be properly polyfilled, some
27764
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
27765
+ // Those polyfills don't allow us to subclass built-ins, so we need to
27766
+ // use our fallback implementation.
27767
+ try {
27768
+ // If the internal slots aren't set, this throws an error similar to
27769
+ // TypeError: this is not a Boolean object.
27770
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
27771
+ } catch (_) {}
27772
+ return (_is_native_reflect_construct$1 = function _is_native_reflect_construct() {
27773
+ return !!result;
27774
+ })();
27775
+ }
27776
+ function _construct$1(Parent, args, Class) {
27777
+ if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
27778
+ else {
27779
+ _construct$1 = function construct(Parent, args, Class) {
27780
+ var a = [
27781
+ null
27782
+ ];
27783
+ a.push.apply(a, args);
27784
+ var Constructor = Function.bind.apply(Parent, a);
27785
+ var instance = new Constructor();
27786
+ if (Class) _set_prototype_of$2(instance, Class.prototype);
27787
+ return instance;
27788
+ };
27789
+ }
27790
+ return _construct$1.apply(null, arguments);
27791
+ }
27792
+ var ComponentCloner = /*#__PURE__*/ function() {
27793
+ function ComponentCloner() {}
27794
+ /**
27795
+ * Clone component.
27796
+ * @param source - Clone source
27797
+ * @param target - Clone target
27798
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
27799
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
27800
+ for(var k in source){
27801
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
27802
+ }
27803
+ source._cloneTo == null ? void 0 : source._cloneTo.call(source, target, srcRoot, targetRoot);
27804
+ };
27805
+ return ComponentCloner;
27806
+ }();
27807
+ /**
27808
+ * The entity modify flags.
27809
+ */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
27810
+ /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
27811
+ /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
27812
+ return EntityModifyFlags;
27813
+ }({});
27814
+ /**
27815
+ * Entity, be used as components container.
27816
+ */ var Entity = /*#__PURE__*/ function(EngineObject) {
27817
+ _inherits$2(Entity, EngineObject);
27818
+ function Entity(engine, name) {
27819
+ for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
27820
+ components[_key - 2] = arguments[_key];
27821
+ }
27822
+ var _this;
27823
+ _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();
27824
+ _this.name = name != null ? name : "Entity";
27825
+ for(var i = 0, n = components.length; i < n; i++){
27826
+ _this.addComponent(components[i]);
27827
+ }
27828
+ !_this._transform && _this.addComponent(Transform);
27829
+ _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
27830
+ return _this;
27831
+ }
27832
+ var _proto = Entity.prototype;
27833
+ /**
27834
+ * Add component based on the component type.
27835
+ * @param type - The type of the component
27836
+ * @param args - The arguments of the component
27837
+ * @returns The component which has been added
27838
+ */ _proto.addComponent = function addComponent(type) {
27839
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
27840
+ args[_key - 1] = arguments[_key];
27841
+ }
27842
+ ComponentsDependencies._addCheck(this, type);
27843
+ var component = _construct$1(type, [].concat([
27844
+ this
27845
+ ], args));
27846
+ this._components.push(component);
27847
+ // @todo: temporary solution
27848
+ if (_instanceof1$2(component, Transform)) this._setTransform(component);
27849
+ component._setActive(true, ActiveChangeFlag.All);
27850
+ return component;
27851
+ };
27852
+ /**
27853
+ * Get component which match the type.
27854
+ * @param type - The type of the component
27855
+ * @returns The first component which match type
27856
+ */ _proto.getComponent = function getComponent(type) {
27857
+ var components = this._components;
27858
+ for(var i = 0, n = components.length; i < n; i++){
27859
+ var component = components[i];
27860
+ if (_instanceof1$2(component, type)) {
27861
+ return component;
27862
+ }
27863
+ }
27864
+ return null;
27865
+ };
27866
+ /**
27867
+ * Get components which match the type.
27868
+ * @param type - The type of the component
27869
+ * @param results - The components which match type
27870
+ * @returns The components which match type
27871
+ */ _proto.getComponents = function getComponents(type, results) {
27872
+ results.length = 0;
27873
+ var components = this._components;
27874
+ for(var i = 0, n = components.length; i < n; i++){
27875
+ var component = components[i];
27876
+ if (_instanceof1$2(component, type)) {
27877
+ results.push(component);
27878
+ }
27879
+ }
27880
+ return results;
27881
+ };
27882
+ /**
27883
+ * Get the components which match the type of the entity and it's children.
27884
+ * @param type - The component type
27885
+ * @param results - The components collection
27886
+ * @returns The components collection which match the type
27887
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
27888
+ results.length = 0;
27889
+ this._getComponentsInChildren(type, results);
27890
+ return results;
27891
+ };
27892
+ _proto.addChild = function addChild(indexOrChild, child) {
27893
+ var index;
27894
+ if (typeof indexOrChild === "number") {
27895
+ index = indexOrChild;
27896
+ } else {
27897
+ index = undefined;
27898
+ child = indexOrChild;
27899
+ }
27900
+ child._setParent(this, index);
27901
+ };
27902
+ /**
27903
+ * Remove child entity.
27904
+ * @param child - The child entity which want to be removed
27905
+ */ _proto.removeChild = function removeChild(child) {
27906
+ if (child._parent !== this) return;
27907
+ child._setParent(null);
27908
+ };
27909
+ /**
27910
+ * @deprecated Please use `children` property instead.
27911
+ * Find child entity by index.
27912
+ * @param index - The index of the child entity
27913
+ * @returns The component which be found
27914
+ */ _proto.getChild = function getChild(index) {
27915
+ return this._children[index];
27916
+ };
27917
+ /**
27918
+ * Find entity by name.
27919
+ * @param name - The name of the entity which want to be found
27920
+ * @returns The component which be found
27921
+ */ _proto.findByName = function findByName(name) {
27922
+ if (name === this.name) {
27923
+ return this;
27924
+ }
27925
+ var children = this._children;
27926
+ for(var i = 0, n = children.length; i < n; i++){
27927
+ var target = children[i].findByName(name);
27928
+ if (target) {
27929
+ return target;
27930
+ }
27931
+ }
27932
+ return null;
27933
+ };
27934
+ /**
27935
+ * Find the entity by path.
27936
+ * @param path - The path of the entity eg: /entity
27937
+ * @returns The component which be found
27938
+ */ _proto.findByPath = function findByPath(path) {
27939
+ var splits = path.split("/").filter(Boolean);
27940
+ if (!splits.length) {
27941
+ return this;
27942
+ }
27943
+ return Entity._findChildByName(this, 0, splits, 0);
27944
+ };
27945
+ /**
27946
+ * Create child entity.
27947
+ * @param name - The child entity's name
27948
+ * @returns The child entity
27949
+ */ _proto.createChild = function createChild(name) {
27950
+ var transform = this._transform;
27951
+ var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
27952
+ child.layer = this.layer;
27953
+ child.parent = this;
27954
+ return child;
27955
+ };
27956
+ /**
27957
+ * Clear children entities.
27958
+ */ _proto.clearChildren = function clearChildren() {
27959
+ var children = this._children;
27960
+ for(var i = children.length - 1; i >= 0; i--){
27961
+ var child = children[i];
27962
+ child._parent = null;
27963
+ var activeChangeFlag = ActiveChangeFlag.None;
27964
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27965
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
27966
+ activeChangeFlag && child._processInActive(activeChangeFlag);
27967
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
27968
+ }
27969
+ children.length = 0;
27970
+ };
27971
+ /**
27972
+ * Clone this entity include children and components.
27973
+ * @returns Cloned entity
27974
+ */ _proto.clone = function clone() {
27975
+ var cloneEntity = this._createCloneEntity();
27976
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
27977
+ return cloneEntity;
27311
27978
  };
27312
27979
  /**
27313
27980
  * Listen for changes in the world pose of this `Entity`.
@@ -27317,6 +27984,11 @@ var ComponentCloner = /*#__PURE__*/ function() {
27317
27984
  };
27318
27985
  /**
27319
27986
  * @internal
27987
+ */ _proto._remap = function _remap(srcRoot, targetRoot) {
27988
+ return CloneUtils.remapEntity(srcRoot, targetRoot, this);
27989
+ };
27990
+ /**
27991
+ * @internal
27320
27992
  */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
27321
27993
  this._isTemplate = true;
27322
27994
  this._templateResource = templateResource;
@@ -27625,834 +28297,146 @@ var ComponentCloner = /*#__PURE__*/ function() {
27625
28297
  for(var i = children.length - 1; i >= 0; i--){
27626
28298
  this._traverseSetOwnerScene(children[i], scene);
27627
28299
  }
27628
- };
27629
- /**
27630
- * @internal
27631
- */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
27632
- inversePath.length = 0;
27633
- while(searchEntity !== rootEntity){
27634
- var parent = searchEntity.parent;
27635
- if (!parent) {
27636
- return false;
27637
- }
27638
- inversePath.push(searchEntity.siblingIndex);
27639
- searchEntity = parent;
27640
- }
27641
- return true;
27642
- };
27643
- /**
27644
- * @internal
27645
- */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
27646
- var entity = rootEntity;
27647
- for(var i = inversePath.length - 1; i >= 0; i--){
27648
- entity = entity.children[inversePath[i]];
27649
- }
27650
- return entity;
27651
- };
27652
- /**
27653
- * @internal
27654
- */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
27655
- var count = children.length - 1;
27656
- for(var i = entity._siblingIndex; i < count; i++){
27657
- var child = children[i + 1];
27658
- children[i] = child;
27659
- child._siblingIndex = i;
27660
- }
27661
- children.length = count;
27662
- entity._siblingIndex = -1;
27663
- };
27664
- /**
27665
- * @internal
27666
- */ Entity._addToChildren = function _addToChildren(children, entity, index) {
27667
- var childCount = children.length;
27668
- children.length = childCount + 1;
27669
- if (index === undefined) {
27670
- children[childCount] = entity;
27671
- entity._siblingIndex = childCount;
27672
- } else {
27673
- if (index < 0 || index > childCount) {
27674
- throw "The index " + index + " is out of child list bounds " + childCount;
27675
- }
27676
- for(var i = childCount; i > index; i--){
27677
- var swapChild = children[i - 1];
27678
- swapChild._siblingIndex = i;
27679
- children[i] = swapChild;
27680
- }
27681
- entity._siblingIndex = index;
27682
- children[index] = entity;
27683
- }
27684
- };
27685
- _create_class$2(Entity, [
27686
- {
27687
- key: "transform",
27688
- get: /**
27689
- * The transform of this entity.
27690
- */ function get() {
27691
- return this._transform;
27692
- }
27693
- },
27694
- {
27695
- key: "isActive",
27696
- get: /**
27697
- * Whether to activate locally.
27698
- */ function get() {
27699
- return this._isActive;
27700
- },
27701
- set: function set(value) {
27702
- if (value !== this._isActive) {
27703
- this._isActive = value;
27704
- if (value) {
27705
- var parent = this._parent;
27706
- var activeChangeFlag = ActiveChangeFlag.None;
27707
- if (this._isRoot && this._scene._isActiveInEngine) {
27708
- activeChangeFlag |= ActiveChangeFlag.All;
27709
- } else {
27710
- (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27711
- (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
27712
- }
27713
- activeChangeFlag && this._processActive(activeChangeFlag);
27714
- } else {
27715
- var activeChangeFlag1 = ActiveChangeFlag.None;
27716
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
27717
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
27718
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
27719
- }
27720
- }
27721
- }
27722
- },
27723
- {
27724
- key: "isActiveInHierarchy",
27725
- get: /**
27726
- * Whether it is active in the hierarchy.
27727
- */ function get() {
27728
- return this._isActiveInHierarchy;
27729
- }
27730
- },
27731
- {
27732
- key: "parent",
27733
- get: /**
27734
- * The parent entity.
27735
- */ function get() {
27736
- return this._parent;
27737
- },
27738
- set: function set(value) {
27739
- this._setParent(value);
27740
- }
27741
- },
27742
- {
27743
- key: "children",
27744
- get: /**
27745
- * The children entities
27746
- */ function get() {
27747
- return this._children;
27748
- }
27749
- },
27750
- {
27751
- key: "childCount",
27752
- get: /**
27753
- * @deprecated Please use `children.length` property instead.
27754
- * Number of the children entities
27755
- */ function get() {
27756
- return this._children.length;
27757
- }
27758
- },
27759
- {
27760
- key: "scene",
27761
- get: /**
27762
- * The scene the entity belongs to.
27763
- */ function get() {
27764
- return this._scene;
27765
- }
27766
- },
27767
- {
27768
- key: "siblingIndex",
27769
- get: /**
27770
- * The sibling index.
27771
- */ function get() {
27772
- return this._siblingIndex;
27773
- },
27774
- set: function set(value) {
27775
- if (this._siblingIndex === -1) {
27776
- throw "The entity " + this.name + " is not in the hierarchy";
27777
- }
27778
- if (this._isRoot) {
27779
- this._setSiblingIndex(this._scene._rootEntities, value);
27780
- } else {
27781
- var parent = this._parent;
27782
- this._setSiblingIndex(parent._children, value);
27783
- parent._dispatchModify(EntityModifyFlags.Child, parent);
27784
- }
27785
- }
27786
- }
27787
- ]);
27788
- return Entity;
27789
- }(EngineObject);
27790
- /** @internal */ Entity._tempComponentConstructors = [];
27791
- /**
27792
- * Skin used for skinned mesh renderer.
27793
- */ var Skin = /*#__PURE__*/ function(EngineObject) {
27794
- _inherits$2(Skin, EngineObject);
27795
- function Skin(name) {
27796
- var _this;
27797
- _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 = [];
27798
- return _this;
27799
- }
27800
- var _proto = Skin.prototype;
27801
- /**
27802
- * @internal
27803
- */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
27804
- if (this._updateMark === renderer.engine.time.frameCount) {
27805
- return;
27806
- }
27807
- var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
27808
- var _this_rootBone;
27809
- var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
27810
- for(var i = bones.length - 1; i >= 0; i--){
27811
- var bone = bones[i];
27812
- var offset = i * 16;
27813
- if (bone) {
27814
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
27815
- } else {
27816
- skinMatrices.set(bindMatrices[i].elements, offset);
27817
- }
27818
- Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
27819
- }
27820
- this._updateMark = renderer.engine.time.frameCount;
27821
- };
27822
- /**
27823
- * @internal
27824
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27825
- var paths = new Array();
27826
- // Clone rootBone
27827
- var rootBone = this.rootBone;
27828
- if (rootBone) {
27829
- var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
27830
- target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
27831
- }
27832
- // Clone bones
27833
- var bones = this.bones;
27834
- if (bones.length > 0) {
27835
- var boneCount = bones.length;
27836
- var destBones = new Array(boneCount);
27837
- for(var i = 0; i < boneCount; i++){
27838
- var bone = bones[i];
27839
- var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
27840
- destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
27841
- }
27842
- target.bones = destBones;
27843
- }
27844
- };
27845
- _create_class$2(Skin, [
27846
- {
27847
- key: "rootBone",
27848
- get: /**
27849
- * Root bone.
27850
- */ function get() {
27851
- return this._rootBone;
27852
- },
27853
- set: function set(value) {
27854
- if (this._rootBone !== value) {
27855
- this._updatedManager.dispatch(1, value);
27856
- this._rootBone = value;
27857
- }
27858
- }
27859
- },
27860
- {
27861
- key: "bones",
27862
- get: /**
27863
- * Bones of the skin.
27864
- */ function get() {
27865
- return this._bones;
27866
- },
27867
- set: function set(value) {
27868
- var bones = this._bones;
27869
- var _value_length;
27870
- var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
27871
- var lastBoneCount = bones.length;
27872
- bones.length = boneCount;
27873
- for(var i = 0; i < boneCount; i++){
27874
- bones[i] = value[i];
27875
- }
27876
- if (lastBoneCount !== boneCount) {
27877
- this._skinMatrices = new Float32Array(boneCount * 16);
27878
- this._updatedManager.dispatch(0, boneCount);
27879
- }
27880
- }
27881
- },
27882
- {
27883
- key: "skeleton",
27884
- get: /** @deprecated Please use `rootBone` instead. */ function get() {
27885
- var _this_rootBone;
27886
- return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
27887
- },
27888
- set: function set(value) {
27889
- var rootBone = this._rootBone;
27890
- if (rootBone) {
27891
- rootBone.name = value;
27892
- }
27893
- }
27894
- }
27895
- ]);
27896
- return Skin;
27897
- }(EngineObject);
27898
- __decorate$1([
27899
- deepClone
27900
- ], Skin.prototype, "inverseBindMatrices", void 0);
27901
- __decorate$1([
27902
- ignoreClone
27903
- ], Skin.prototype, "_skinMatrices", void 0);
27904
- __decorate$1([
27905
- ignoreClone
27906
- ], Skin.prototype, "_updatedManager", void 0);
27907
- __decorate$1([
27908
- ignoreClone
27909
- ], Skin.prototype, "_rootBone", void 0);
27910
- __decorate$1([
27911
- ignoreClone
27912
- ], Skin.prototype, "_bones", void 0);
27913
- __decorate$1([
27914
- ignoreClone
27915
- ], Skin.prototype, "_updateMark", void 0);
27916
- var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
27917
- SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
27918
- SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
27919
- return SkinUpdateFlag;
27920
- }({});
27921
- /**
27922
- * SkinnedMeshRenderer.
27923
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
27924
- _inherits$2(SkinnedMeshRenderer, MeshRenderer);
27925
- function SkinnedMeshRenderer(entity) {
27926
- var _this;
27927
- _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new BoundingBox(), _this._jointDataCreateCache = new Vector2(-1, -1);
27928
- _this._skin = null;
27929
- var rhi = _this.entity.engine._hardwareRenderer;
27930
- var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
27931
- // Limit size to 256 to avoid some problem:
27932
- // 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!
27933
- // 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.
27934
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
27935
- _this._maxVertexUniformVectors = maxVertexUniformVectors;
27936
- _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
27937
- _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
27938
- var localBounds = _this._localBounds;
27939
- // @ts-ignore
27940
- localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
27941
- // @ts-ignore
27942
- localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
27943
- return _this;
27944
- }
27945
- var _proto = SkinnedMeshRenderer.prototype;
27946
- /**
27947
- * @internal
27948
- */ _proto._onDestroy = function _onDestroy() {
27949
- var _this__jointTexture;
27950
- MeshRenderer.prototype._onDestroy.call(this);
27951
- this._jointDataCreateCache = null;
27952
- this._skin = null;
27953
- this._blendShapeWeights = null;
27954
- this._localBounds = null;
27955
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27956
- this._jointTexture = null;
27957
- };
27958
- /**
27959
- * @internal
27960
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27961
- MeshRenderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
27962
- if (this.skin) {
27963
- target._applySkin(null, target.skin);
27964
- }
27965
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
27966
- };
27967
- _proto._update = function _update(context) {
27968
- var skin = this.skin;
27969
- if ((skin == null ? void 0 : skin.bones.length) > 0) {
27970
- skin._updateSkinMatrices(this);
27971
- }
27972
- var shaderData = this.shaderData;
27973
- var mesh = this.mesh;
27974
- var blendShapeManager = mesh._blendShapeManager;
27975
- blendShapeManager._updateShaderData(shaderData, this);
27976
- var bones = skin == null ? void 0 : skin.bones;
27977
- if (bones) {
27978
- var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
27979
- var boneCount = bones.length;
27980
- var boneDataCreateCache = this._jointDataCreateCache;
27981
- var boneCountChange = boneCount !== boneDataCreateCache.x;
27982
- if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
27983
- // directly use max joint count to avoid shader recompile
27984
- var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
27985
- if (boneCount > remainUniformJointCount) {
27986
- var engine = this.engine;
27987
- if (engine._hardwareRenderer.canIUseMoreJoints) {
27988
- if (boneCountChange) {
27989
- var _this__jointTexture;
27990
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27991
- this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
27992
- this._jointTexture.filterMode = TextureFilterMode.Point;
27993
- this._jointTexture.isGCIgnored = true;
27994
- }
27995
- shaderData.disableMacro("RENDERER_JOINTS_NUM");
27996
- shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
27997
- shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
27998
- } else {
27999
- 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);
28000
- }
28001
- } else {
28002
- var _this__jointTexture1;
28003
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
28004
- shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
28005
- shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
28006
- shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
28007
- }
28008
- boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
28009
- }
28010
- if (this._jointTexture) {
28011
- this._jointTexture.setPixelBuffer(skin._skinMatrices);
28012
- }
28013
- }
28014
- MeshRenderer.prototype._update.call(this, context);
28015
- };
28016
- /**
28017
- * @internal
28018
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
28019
- var _this_skin;
28020
- var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
28021
- if (rootBone) {
28022
- BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
28023
- } else {
28024
- MeshRenderer.prototype._updateBounds.call(this, worldBounds);
28025
- }
28026
- };
28027
- _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
28028
- var mesh = this._mesh;
28029
- var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
28030
- var lastBlendShapeWeights = this._blendShapeWeights;
28031
- if (lastBlendShapeWeights) {
28032
- var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
28033
- if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
28034
- var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
28035
- if (newBlendShapeCount > lastBlendShapeWeightsCount) {
28036
- newBlendShapeWeights.set(lastBlendShapeWeights);
28037
- } else {
28038
- for(var i = 0; i < newBlendShapeCount; i++){
28039
- newBlendShapeWeights[i] = lastBlendShapeWeights[i];
28040
- }
28041
- }
28042
- this._blendShapeWeights = newBlendShapeWeights;
28043
- }
28044
- } else {
28045
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
28046
- }
28047
- };
28048
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
28049
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
28050
- };
28051
- _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
28052
- switch(type){
28053
- case SkinUpdateFlag.BoneCountChanged:
28054
- var shaderData = this.shaderData;
28055
- if (value > 0) {
28056
- shaderData.enableMacro("RENDERER_HAS_SKIN");
28057
- shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
28058
- } else {
28059
- shaderData.disableMacro("RENDERER_HAS_SKIN");
28060
- }
28061
- break;
28062
- case SkinUpdateFlag.RootBoneChanged:
28063
- this._setTransformEntity(value);
28064
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
28065
- break;
28066
- }
28067
- };
28068
- _proto._applySkin = function _applySkin(lastSkin, value) {
28069
- var _lastSkin_bones, _value_bones;
28070
- var _lastSkin_bones_length;
28071
- var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
28072
- var _lastSkin_rootBone;
28073
- var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
28074
- lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
28075
- var _value_bones_length;
28076
- var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
28077
- var _value_rootBone;
28078
- var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
28079
- value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
28080
- if (lastSkinBoneCount !== skinBoneCount) {
28081
- this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
28082
- }
28083
- if (lastRootBone !== rootBone) {
28084
- this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
28300
+ };
28301
+ /**
28302
+ * @internal
28303
+ */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
28304
+ var count = children.length - 1;
28305
+ for(var i = entity._siblingIndex; i < count; i++){
28306
+ var child = children[i + 1];
28307
+ children[i] = child;
28308
+ child._siblingIndex = i;
28085
28309
  }
28310
+ children.length = count;
28311
+ entity._siblingIndex = -1;
28086
28312
  };
28087
- _create_class$2(SkinnedMeshRenderer, [
28313
+ /**
28314
+ * @internal
28315
+ */ Entity._addToChildren = function _addToChildren(children, entity, index) {
28316
+ var childCount = children.length;
28317
+ children.length = childCount + 1;
28318
+ if (index === undefined) {
28319
+ children[childCount] = entity;
28320
+ entity._siblingIndex = childCount;
28321
+ } else {
28322
+ if (index < 0 || index > childCount) {
28323
+ throw "The index " + index + " is out of child list bounds " + childCount;
28324
+ }
28325
+ for(var i = childCount; i > index; i--){
28326
+ var swapChild = children[i - 1];
28327
+ swapChild._siblingIndex = i;
28328
+ children[i] = swapChild;
28329
+ }
28330
+ entity._siblingIndex = index;
28331
+ children[index] = entity;
28332
+ }
28333
+ };
28334
+ _create_class$2(Entity, [
28088
28335
  {
28089
- key: "skin",
28336
+ key: "transform",
28090
28337
  get: /**
28091
- * Skin of the SkinnedMeshRenderer.
28338
+ * The transform of this entity.
28092
28339
  */ function get() {
28093
- return this._skin;
28094
- },
28095
- set: function set(value) {
28096
- var lastSkin = this._skin;
28097
- if (lastSkin !== value) {
28098
- this._applySkin(lastSkin, value);
28099
- this._skin = value;
28100
- }
28340
+ return this._transform;
28101
28341
  }
28102
28342
  },
28103
28343
  {
28104
- key: "blendShapeWeights",
28344
+ key: "isActive",
28105
28345
  get: /**
28106
- * The weights of the BlendShapes.
28107
- * @remarks Array index is BlendShape index.
28346
+ * Whether to activate locally.
28108
28347
  */ function get() {
28109
- this._checkBlendShapeWeightLength();
28110
- return this._blendShapeWeights;
28348
+ return this._isActive;
28111
28349
  },
28112
28350
  set: function set(value) {
28113
- this._checkBlendShapeWeightLength();
28114
- var blendShapeWeights = this._blendShapeWeights;
28115
- if (value.length <= blendShapeWeights.length) {
28116
- blendShapeWeights.set(value);
28117
- } else {
28118
- for(var i = 0, n = blendShapeWeights.length; i < n; i++){
28119
- blendShapeWeights[i] = value[i];
28351
+ if (value !== this._isActive) {
28352
+ this._isActive = value;
28353
+ if (value) {
28354
+ var parent = this._parent;
28355
+ var activeChangeFlag = ActiveChangeFlag.None;
28356
+ if (this._isRoot && this._scene._isActiveInEngine) {
28357
+ activeChangeFlag |= ActiveChangeFlag.All;
28358
+ } else {
28359
+ (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
28360
+ (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
28361
+ }
28362
+ activeChangeFlag && this._processActive(activeChangeFlag);
28363
+ } else {
28364
+ var activeChangeFlag1 = ActiveChangeFlag.None;
28365
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
28366
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
28367
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
28120
28368
  }
28121
28369
  }
28122
28370
  }
28123
28371
  },
28124
28372
  {
28125
- key: "localBounds",
28373
+ key: "isActiveInHierarchy",
28126
28374
  get: /**
28127
- * Local bounds.
28375
+ * Whether it is active in the hierarchy.
28128
28376
  */ function get() {
28129
- return this._localBounds;
28130
- },
28131
- set: function set(value) {
28132
- if (this._localBounds !== value) {
28133
- this._localBounds.copyFrom(value);
28134
- }
28377
+ return this._isActiveInHierarchy;
28135
28378
  }
28136
28379
  },
28137
28380
  {
28138
- key: "rootBone",
28381
+ key: "parent",
28139
28382
  get: /**
28140
- * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
28383
+ * The parent entity.
28141
28384
  */ function get() {
28142
- return this.skin.rootBone;
28385
+ return this._parent;
28143
28386
  },
28144
28387
  set: function set(value) {
28145
- this.skin.rootBone = value;
28388
+ this._setParent(value);
28146
28389
  }
28147
28390
  },
28148
28391
  {
28149
- key: "bones",
28392
+ key: "children",
28150
28393
  get: /**
28151
- * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
28394
+ * The children entities
28152
28395
  */ function get() {
28153
- return this.skin.bones;
28154
- },
28155
- set: function set(value) {
28156
- this.skin.bones = value;
28157
- }
28158
- }
28159
- ]);
28160
- return SkinnedMeshRenderer;
28161
- }(MeshRenderer);
28162
- // @TODO: different shader type should use different count, not always 48
28163
- /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
28164
- SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
28165
- SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
28166
- SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
28167
- __decorate$1([
28168
- ignoreClone
28169
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
28170
- __decorate$1([
28171
- deepClone
28172
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
28173
- __decorate$1([
28174
- ignoreClone
28175
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
28176
- __decorate$1([
28177
- ignoreClone
28178
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
28179
- __decorate$1([
28180
- ignoreClone
28181
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
28182
- __decorate$1([
28183
- ignoreClone
28184
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
28185
- __decorate$1([
28186
- deepClone
28187
- ], SkinnedMeshRenderer.prototype, "_skin", void 0);
28188
- __decorate$1([
28189
- ignoreClone
28190
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
28191
- __decorate$1([
28192
- ignoreClone
28193
- ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
28194
- /**
28195
- * @internal
28196
- */ var BasicResources = /*#__PURE__*/ function() {
28197
- function BasicResources(engine) {
28198
- this.engine = engine;
28199
- // prettier-ignore
28200
- var vertices = new Float32Array([
28201
- -1,
28202
- -1,
28203
- 0,
28204
- 1,
28205
- 3,
28206
- -1,
28207
- 2,
28208
- 1,
28209
- -1,
28210
- 3,
28211
- 0,
28212
- -1
28213
- ]); // left-top
28214
- // prettier-ignore
28215
- var flipYVertices = new Float32Array([
28216
- 3,
28217
- -1,
28218
- 2,
28219
- 0,
28220
- -1,
28221
- -1,
28222
- 0,
28223
- 0,
28224
- -1,
28225
- 3,
28226
- 0,
28227
- 2
28228
- ]); // left-top
28229
- var blitMaterial = new Material(engine, Shader.find("blit"));
28230
- blitMaterial._addReferCount(1);
28231
- blitMaterial.renderState.depthState.enabled = false;
28232
- blitMaterial.renderState.depthState.writeEnabled = false;
28233
- var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
28234
- blitScreenMaterial._addReferCount(1);
28235
- blitScreenMaterial.renderState.depthState.enabled = false;
28236
- blitScreenMaterial.renderState.depthState.writeEnabled = false;
28237
- this.blitMaterial = blitMaterial;
28238
- this.blitScreenMaterial = blitScreenMaterial;
28239
- this.blitMesh = this._createBlitMesh(engine, vertices);
28240
- this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
28241
- // Create white and magenta textures
28242
- var whitePixel = new Uint8Array([
28243
- 255,
28244
- 255,
28245
- 255,
28246
- 255
28247
- ]);
28248
- this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
28249
- this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
28250
- var isWebGL2 = engine._hardwareRenderer.isWebGL2;
28251
- if (isWebGL2) {
28252
- this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
28253
- var whitePixel32 = new Uint32Array([
28254
- 255,
28255
- 255,
28256
- 255,
28257
- 255
28258
- ]);
28259
- this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
28260
- }
28261
- this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
28262
- this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
28263
- this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
28264
- this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
28265
- this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
28266
- }
28267
- var _proto = BasicResources.prototype;
28268
- /**
28269
- * @internal
28270
- */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
28271
- return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
28272
- };
28273
- /**
28274
- * @internal
28275
- */ _proto._initialize = function _initialize() {
28276
- var _this = this;
28277
- return new Promise(function(resolve, reject) {
28278
- PrefilteredDFG.create(_this.engine).then(function(texture) {
28279
- _this._prefilteredDFGTexture = texture;
28280
- resolve(_this);
28281
- }).catch(reject);
28282
- });
28283
- };
28284
- _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
28285
- var mesh = new ModelMesh(engine);
28286
- mesh._addReferCount(1);
28287
- mesh.setVertexElements([
28288
- new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
28289
- ]);
28290
- var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
28291
- mesh.setVertexBufferBinding(buffer, 16);
28292
- mesh.addSubMesh(0, 3, MeshTopology.Triangles);
28293
- engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
28294
- _inherits$2(_class, ContentRestorer);
28295
- function _class() {
28296
- return ContentRestorer.call(this, mesh) || this;
28297
- }
28298
- var _proto = _class.prototype;
28299
- _proto.restoreContent = function restoreContent() {
28300
- buffer.setData(buffer.data);
28301
- };
28302
- return _class;
28303
- }(ContentRestorer))());
28304
- return mesh;
28305
- };
28306
- _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
28307
- var texture;
28308
- switch(type){
28309
- case 0:
28310
- var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
28311
- texture2D.setPixelBuffer(pixel);
28312
- texture = texture2D;
28313
- break;
28314
- case 2:
28315
- var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
28316
- texture2DArray.setPixelBuffer(0, pixel);
28317
- texture = texture2DArray;
28318
- break;
28319
- case 1:
28320
- var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
28321
- for(var i = 0; i < 6; i++){
28322
- textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
28323
- }
28324
- texture = textureCube;
28325
- break;
28326
- default:
28327
- throw "Invalid texture type";
28328
- }
28329
- texture.isGCIgnored = true;
28330
- engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
28331
- _inherits$2(_class, ContentRestorer);
28332
- function _class() {
28333
- return ContentRestorer.call(this, texture) || this;
28334
- }
28335
- var _proto = _class.prototype;
28336
- _proto.restoreContent = function restoreContent() {
28337
- switch(type){
28338
- case 0:
28339
- this.resource.setPixelBuffer(pixel);
28340
- break;
28341
- case 2:
28342
- this.resource.setPixelBuffer(0, pixel);
28343
- break;
28344
- case 1:
28345
- for(var i = 0; i < 6; i++){
28346
- this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
28347
- }
28348
- break;
28349
- }
28350
- };
28351
- return _class;
28352
- }(ContentRestorer))());
28353
- return texture;
28354
- };
28355
- _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
28356
- var material = new Material(engine, shader);
28357
- var renderState = material.renderState;
28358
- var target = renderState.blendState.targetBlendState;
28359
- target.enabled = true;
28360
- target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
28361
- target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
28362
- target.sourceAlphaBlendFactor = BlendFactor.One;
28363
- target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
28364
- target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
28365
- renderState.depthState.writeEnabled = false;
28366
- renderState.rasterState.cullMode = CullMode.Off;
28367
- renderState.renderQueueType = RenderQueueType.Transparent;
28368
- material.isGCIgnored = true;
28369
- return material;
28370
- };
28371
- _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
28372
- var material = new Material(engine, Shader.find(shaderName));
28373
- material.isGCIgnored = true;
28374
- material.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
28375
- return material;
28376
- };
28377
- _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
28378
- var material = new Material(engine, Shader.find("SpriteMask"));
28379
- material.isGCIgnored = true;
28380
- return material;
28381
- };
28382
- BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
28383
- var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
28384
- var renderStates;
28385
- var compareFunction;
28386
- if (visibleInsideMask) {
28387
- renderStates = BasicResources._maskReadInsideRenderStates;
28388
- if (renderStates) {
28389
- return renderStates;
28390
- }
28391
- BasicResources._maskReadInsideRenderStates = renderStates = {};
28392
- compareFunction = CompareFunction.LessEqual;
28393
- } else {
28394
- renderStates = BasicResources._maskReadOutsideRenderStates;
28395
- if (renderStates) {
28396
- return renderStates;
28396
+ return this._children;
28397
28397
  }
28398
- BasicResources._maskReadOutsideRenderStates = renderStates = {};
28399
- compareFunction = CompareFunction.Greater;
28400
- }
28401
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
28402
- renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
28403
- renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
28404
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
28405
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
28406
- return renderStates;
28407
- };
28408
- BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
28409
- var isIncrement = maskType === RenderQueueMaskType.Increment;
28410
- var renderStates;
28411
- var passOperation;
28412
- if (isIncrement) {
28413
- renderStates = BasicResources._maskWriteIncrementRenderStates;
28414
- if (renderStates) {
28415
- return renderStates;
28398
+ },
28399
+ {
28400
+ key: "childCount",
28401
+ get: /**
28402
+ * @deprecated Please use `children.length` property instead.
28403
+ * Number of the children entities
28404
+ */ function get() {
28405
+ return this._children.length;
28416
28406
  }
28417
- BasicResources._maskWriteIncrementRenderStates = renderStates = {};
28418
- passOperation = StencilOperation.IncrementSaturate;
28419
- } else {
28420
- renderStates = BasicResources._maskWriteDecrementRenderStates;
28421
- if (renderStates) {
28422
- return renderStates;
28407
+ },
28408
+ {
28409
+ key: "scene",
28410
+ get: /**
28411
+ * The scene the entity belongs to.
28412
+ */ function get() {
28413
+ return this._scene;
28423
28414
  }
28424
- BasicResources._maskWriteDecrementRenderStates = renderStates = {};
28425
- passOperation = StencilOperation.DecrementSaturate;
28426
- }
28427
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
28428
- renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
28429
- renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
28430
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
28431
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
28432
- var failStencilOperation = StencilOperation.Keep;
28433
- renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
28434
- renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
28435
- renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
28436
- renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
28437
- renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
28438
- renderStates[RenderStateElementKey.DepthStateEnabled] = false;
28439
- renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
28440
- return renderStates;
28441
- };
28442
- _create_class$2(BasicResources, [
28415
+ },
28443
28416
  {
28444
- key: "prefilteredDFGTexture",
28445
- get: function get() {
28446
- return this._prefilteredDFGTexture;
28417
+ key: "siblingIndex",
28418
+ get: /**
28419
+ * The sibling index.
28420
+ */ function get() {
28421
+ return this._siblingIndex;
28422
+ },
28423
+ set: function set(value) {
28424
+ if (this._siblingIndex === -1) {
28425
+ throw "The entity " + this.name + " is not in the hierarchy";
28426
+ }
28427
+ if (this._isRoot) {
28428
+ this._setSiblingIndex(this._scene._rootEntities, value);
28429
+ } else {
28430
+ var parent = this._parent;
28431
+ this._setSiblingIndex(parent._children, value);
28432
+ parent._dispatchModify(EntityModifyFlags.Child, parent);
28433
+ }
28447
28434
  }
28448
28435
  }
28449
28436
  ]);
28450
- return BasicResources;
28451
- }();
28452
- BasicResources._maskReadInsideRenderStates = null;
28453
- BasicResources._maskReadOutsideRenderStates = null;
28454
- BasicResources._maskWriteIncrementRenderStates = null;
28455
- BasicResources._maskWriteDecrementRenderStates = null;
28437
+ return Entity;
28438
+ }(EngineObject);
28439
+ /** @internal */ Entity._tempComponentConstructors = [];
28456
28440
  var ObjectPool = /*#__PURE__*/ function() {
28457
28441
  function ObjectPool(type) {
28458
28442
  this._type = type;
@@ -33729,6 +33713,183 @@ var PointerMethods = /*#__PURE__*/ function(PointerMethods) {
33729
33713
  PointerMethods["onPointerDrop"] = "onPointerDrop";
33730
33714
  return PointerMethods;
33731
33715
  }({});
33716
+ /**
33717
+ * Signal is a typed event mechanism for Galacean Engine.
33718
+ * @typeParam T - Tuple type of the signal arguments
33719
+ */ var Signal = /*#__PURE__*/ function() {
33720
+ function Signal() {
33721
+ this._listeners = new SafeLoopArray();
33722
+ }
33723
+ var _proto = Signal.prototype;
33724
+ _proto.on = function on(fnOrTarget, targetOrMethodName) {
33725
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
33726
+ args[_key - 2] = arguments[_key];
33727
+ }
33728
+ this._addListener.apply(this, [].concat([
33729
+ fnOrTarget,
33730
+ targetOrMethodName,
33731
+ false
33732
+ ], args));
33733
+ };
33734
+ _proto.once = function once(fnOrTarget, targetOrMethodName) {
33735
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
33736
+ args[_key - 2] = arguments[_key];
33737
+ }
33738
+ this._addListener.apply(this, [].concat([
33739
+ fnOrTarget,
33740
+ targetOrMethodName,
33741
+ true
33742
+ ], args));
33743
+ };
33744
+ _proto.off = function off(fnOrTarget, targetOrMethodName) {
33745
+ if (typeof fnOrTarget === "function") {
33746
+ var target = targetOrMethodName != null ? targetOrMethodName : null;
33747
+ this._listeners.findAndRemove(function(listener) {
33748
+ if (listener.fn === fnOrTarget && listener.target === target) {
33749
+ listener.destroyed = true;
33750
+ return true;
33751
+ }
33752
+ return false;
33753
+ });
33754
+ } else {
33755
+ var target1 = fnOrTarget;
33756
+ var methodName = targetOrMethodName;
33757
+ this._listeners.findAndRemove(function(listener) {
33758
+ if (listener.target === target1 && listener.methodName === methodName) {
33759
+ listener.destroyed = true;
33760
+ return true;
33761
+ }
33762
+ return false;
33763
+ });
33764
+ }
33765
+ };
33766
+ /**
33767
+ * Remove all listeners, or all listeners for a specific target.
33768
+ * @param target - If provided, only remove listeners bound to this target
33769
+ */ _proto.removeAll = function removeAll(target) {
33770
+ if (target !== undefined) {
33771
+ this._listeners.findAndRemove(function(listener) {
33772
+ if (listener.target === target) {
33773
+ return listener.destroyed = true;
33774
+ }
33775
+ return false;
33776
+ });
33777
+ } else {
33778
+ this._listeners.findAndRemove(function(listener) {
33779
+ return listener.destroyed = true;
33780
+ });
33781
+ }
33782
+ };
33783
+ /**
33784
+ * Invoke the signal, calling all listeners in order.
33785
+ * @param args - Arguments to pass to each listener
33786
+ */ _proto.invoke = function invoke() {
33787
+ var _this, _loop = function _loop(i, n) {
33788
+ var listener = listeners[i];
33789
+ if (listener.destroyed) return "continue";
33790
+ if (listener.methodName && listener.target.destroyed) {
33791
+ listener.destroyed = true;
33792
+ _this._listeners.findAndRemove(function(l) {
33793
+ return l === listener;
33794
+ });
33795
+ return "continue";
33796
+ }
33797
+ listener.fn.apply(listener.target, args);
33798
+ if (listener.once) {
33799
+ listener.destroyed = true;
33800
+ _this._listeners.findAndRemove(function(l) {
33801
+ return l === listener;
33802
+ });
33803
+ }
33804
+ };
33805
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
33806
+ args[_key] = arguments[_key];
33807
+ }
33808
+ var listeners = this._listeners.getLoopArray();
33809
+ for(var i = 0, n = listeners.length; i < n; i++)_this = this, _loop(i);
33810
+ };
33811
+ /**
33812
+ * @internal
33813
+ * Clone listeners to target signal, remapping entity/component references.
33814
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
33815
+ var listeners = this._listeners.getLoopArray();
33816
+ for(var i = 0, n = listeners.length; i < n; i++){
33817
+ var listener = listeners[i];
33818
+ if (listener.destroyed || !listener.methodName) continue;
33819
+ var clonedTarget = CloneUtils.remapComponent(srcRoot, targetRoot, listener.target);
33820
+ if (clonedTarget) {
33821
+ var clonedArgs = this._cloneArguments(listener.arguments, srcRoot, targetRoot);
33822
+ if (listener.once) {
33823
+ var _target;
33824
+ (_target = target).once.apply(_target, [].concat([
33825
+ clonedTarget,
33826
+ listener.methodName
33827
+ ], clonedArgs));
33828
+ } else {
33829
+ var _target1;
33830
+ (_target1 = target).on.apply(_target1, [].concat([
33831
+ clonedTarget,
33832
+ listener.methodName
33833
+ ], clonedArgs));
33834
+ }
33835
+ }
33836
+ }
33837
+ };
33838
+ _proto._cloneArguments = function _cloneArguments(args, srcRoot, targetRoot) {
33839
+ if (!args || args.length === 0) return [];
33840
+ var len = args.length;
33841
+ var clonedArgs = new Array(len);
33842
+ for(var i = 0; i < len; i++){
33843
+ var arg = args[i];
33844
+ if (_instanceof1$2(arg, Entity)) {
33845
+ clonedArgs[i] = CloneUtils.remapEntity(srcRoot, targetRoot, arg);
33846
+ } else if (_instanceof1$2(arg, Component)) {
33847
+ clonedArgs[i] = CloneUtils.remapComponent(srcRoot, targetRoot, arg);
33848
+ } else {
33849
+ clonedArgs[i] = arg;
33850
+ }
33851
+ }
33852
+ return clonedArgs;
33853
+ };
33854
+ _proto._addListener = function _addListener(fnOrTarget, targetOrMethodName, once) {
33855
+ for(var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
33856
+ args[_key - 3] = arguments[_key];
33857
+ }
33858
+ if (typeof fnOrTarget === "function") {
33859
+ this._listeners.push({
33860
+ fn: fnOrTarget,
33861
+ target: targetOrMethodName != null ? targetOrMethodName : null,
33862
+ once: once
33863
+ });
33864
+ } else {
33865
+ var _target, _target1;
33866
+ var target = fnOrTarget;
33867
+ var methodName = targetOrMethodName;
33868
+ var fn = args.length > 0 ? function fn() {
33869
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
33870
+ signalArgs[_key] = arguments[_key];
33871
+ }
33872
+ return (_target = target)[methodName].apply(_target, [].concat(args, signalArgs));
33873
+ } : function() {
33874
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
33875
+ signalArgs[_key] = arguments[_key];
33876
+ }
33877
+ return (_target1 = target)[methodName].apply(_target1, [].concat(signalArgs));
33878
+ };
33879
+ this._listeners.push({
33880
+ fn: fn,
33881
+ target: target,
33882
+ once: once,
33883
+ methodName: methodName,
33884
+ arguments: args
33885
+ });
33886
+ }
33887
+ };
33888
+ return Signal;
33889
+ }();
33890
+ __decorate$1([
33891
+ ignoreClone
33892
+ ], Signal.prototype, "_listeners", void 0);
33732
33893
  /**
33733
33894
  * Loader abstract class.
33734
33895
  */ var Loader = /*#__PURE__*/ function() {
@@ -35803,7 +35964,7 @@ function _type_of1$1(obj) {
35803
35964
  };
35804
35965
  /**
35805
35966
  * @internal
35806
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
35967
+ */ _proto._cloneTo = function _cloneTo(target) {
35807
35968
  var animatorController = target._animatorController;
35808
35969
  if (animatorController) {
35809
35970
  target._addResourceReferCount(animatorController, 1);
@@ -40912,9 +41073,6 @@ __decorate$1([
40912
41073
  __decorate$1([
40913
41074
  ignoreClone
40914
41075
  ], ParticleGenerator.prototype, "_subPrimitive", void 0);
40915
- __decorate$1([
40916
- ignoreClone
40917
- ], ParticleGenerator.prototype, "_renderer", void 0);
40918
41076
  __decorate$1([
40919
41077
  ignoreClone
40920
41078
  ], ParticleGenerator.prototype, "_isPlaying", void 0);
@@ -41641,7 +41799,7 @@ ConeShape._tempVector31 = new Vector3();
41641
41799
  };
41642
41800
  /**
41643
41801
  * @internal
41644
- */ _proto._cloneTo = function _cloneTo(target, _, __) {
41802
+ */ _proto._cloneTo = function _cloneTo(target) {
41645
41803
  target.mesh = this._mesh;
41646
41804
  };
41647
41805
  _create_class$2(MeshShape, [
@@ -42608,7 +42766,7 @@ AudioManager._needsUserGestureResume = false;
42608
42766
  };
42609
42767
  /**
42610
42768
  * @internal
42611
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
42769
+ */ _proto._cloneTo = function _cloneTo(target) {
42612
42770
  var _target__clip;
42613
42771
  (_target__clip = target._clip) == null ? void 0 : _target__clip._addReferCount(1);
42614
42772
  target._gainNode.gain.setValueAtTime(target._volume, AudioManager.getContext().currentTime);
@@ -43003,6 +43161,7 @@ var CoreObjects = /*#__PURE__*/Object.freeze({
43003
43161
  CircleShape: CircleShape,
43004
43162
  ClearableObjectPool: ClearableObjectPool,
43005
43163
  CloneManager: CloneManager,
43164
+ CloneUtils: CloneUtils,
43006
43165
  get Collider () { return Collider; },
43007
43166
  ColliderShape: ColliderShape,
43008
43167
  ColliderShapeUpAxis: ColliderShapeUpAxis,
@@ -43159,6 +43318,7 @@ var CoreObjects = /*#__PURE__*/Object.freeze({
43159
43318
  ShadowCascadesMode: ShadowCascadesMode,
43160
43319
  ShadowResolution: ShadowResolution,
43161
43320
  ShadowType: ShadowType,
43321
+ Signal: Signal,
43162
43322
  get SimpleSpriteAssembler () { return SimpleSpriteAssembler; },
43163
43323
  SizeOverLifetimeModule: SizeOverLifetimeModule,
43164
43324
  Skin: Skin,
@@ -46260,6 +46420,29 @@ var ReflectionParser = /*#__PURE__*/ function() {
46260
46420
  }
46261
46421
  });
46262
46422
  };
46423
+ _proto.parseSignal = function parseSignal(signalRef) {
46424
+ var _this = this;
46425
+ var signal = new Signal();
46426
+ return Promise.all(signalRef.listeners.map(function(listener) {
46427
+ return Promise.all([
46428
+ _this.parseBasicType(listener.target),
46429
+ listener.arguments ? Promise.all(listener.arguments.map(function(a) {
46430
+ return _this.parseBasicType(a);
46431
+ })) : Promise.resolve([])
46432
+ ]).then(function(param) {
46433
+ var target = param[0], resolvedArgs = param[1];
46434
+ if (target) {
46435
+ var _signal;
46436
+ (_signal = signal).on.apply(_signal, [].concat([
46437
+ target,
46438
+ listener.methodName
46439
+ ], resolvedArgs));
46440
+ }
46441
+ });
46442
+ })).then(function() {
46443
+ return signal;
46444
+ });
46445
+ };
46263
46446
  _proto.parseBasicType = function parseBasicType(value, originValue) {
46264
46447
  var _this = this;
46265
46448
  if (Array.isArray(value)) {
@@ -46284,11 +46467,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
46284
46467
  return resource;
46285
46468
  });
46286
46469
  } else if (ReflectionParser._isComponentRef(value)) {
46287
- var _this__context_components_get;
46288
- return Promise.resolve((_this__context_components_get = this._context.components.get(value.componentId)) != null ? _this__context_components_get : null);
46470
+ var entity = this._resolveEntityByPath(value.entityPath);
46471
+ if (!entity) return Promise.resolve(null);
46472
+ var type = Loader.getClass(value.componentType);
46473
+ if (!type) return Promise.resolve(null);
46474
+ var _entity_getComponents_value_componentIndex;
46475
+ return Promise.resolve((_entity_getComponents_value_componentIndex = entity.getComponents(type, [])[value.componentIndex]) != null ? _entity_getComponents_value_componentIndex : null);
46289
46476
  } else if (ReflectionParser._isEntityRef(value)) {
46290
- // entity reference
46291
- return Promise.resolve(this._context.entityMap.get(value.entityId));
46477
+ return Promise.resolve(this._resolveEntityByPath(value.entityPath));
46478
+ } else if (ReflectionParser._isSignalRef(value)) {
46479
+ return this.parseSignal(value);
46292
46480
  } else if (originValue) {
46293
46481
  var _this2, _loop = function _loop(key) {
46294
46482
  if (key === "methods") {
@@ -46344,6 +46532,16 @@ var ReflectionParser = /*#__PURE__*/ function() {
46344
46532
  return Promise.resolve(entity);
46345
46533
  }
46346
46534
  };
46535
+ _proto._resolveEntityByPath = function _resolveEntityByPath(entityPath) {
46536
+ var _this__context = this._context, rootIds = _this__context.rootIds, entityMap = _this__context.entityMap;
46537
+ if (!entityPath.length || entityPath[0] >= rootIds.length) return null;
46538
+ var entity = entityMap.get(rootIds[entityPath[0]]);
46539
+ for(var i = 1; i < entityPath.length; i++){
46540
+ if (!entity || entityPath[i] >= entity.children.length) return null;
46541
+ entity = entity.children[entityPath[i]];
46542
+ }
46543
+ return entity;
46544
+ };
46347
46545
  ReflectionParser._isClass = function _isClass(value) {
46348
46546
  return value["class"] !== undefined;
46349
46547
  };
@@ -46354,10 +46552,13 @@ var ReflectionParser = /*#__PURE__*/ function() {
46354
46552
  return value["url"] !== undefined;
46355
46553
  };
46356
46554
  ReflectionParser._isEntityRef = function _isEntityRef(value) {
46357
- return value["entityId"] !== undefined;
46555
+ return Array.isArray(value["entityPath"]) && value["componentType"] === undefined;
46358
46556
  };
46359
46557
  ReflectionParser._isComponentRef = function _isComponentRef(value) {
46360
- return value["ownerId"] !== undefined && value["componentId"] !== undefined;
46558
+ return Array.isArray(value["entityPath"]) && value["componentType"] !== undefined;
46559
+ };
46560
+ ReflectionParser._isSignalRef = function _isSignalRef(value) {
46561
+ return value["listeners"] !== undefined;
46361
46562
  };
46362
46563
  ReflectionParser._isMethodObject = function _isMethodObject(value) {
46363
46564
  return Array.isArray(value == null ? void 0 : value.params);
@@ -46580,6 +46781,13 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
46580
46781
  for(var i = 0, l = entities.length; i < l; i++){
46581
46782
  entityMap.set(entitiesConfig[i].id, entities[i]);
46582
46783
  }
46784
+ // Build rootIds in serialization order (not async completion order)
46785
+ var rootIds = _this.context.rootIds;
46786
+ for(var i1 = 0, l1 = entitiesConfig.length; i1 < l1; i1++){
46787
+ if (!entitiesConfig[i1].parent && !entitiesConfig[i1].strippedId) {
46788
+ rootIds.push(entitiesConfig[i1].id);
46789
+ }
46790
+ }
46583
46791
  return entities;
46584
46792
  });
46585
46793
  };
@@ -46705,7 +46913,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
46705
46913
  _proto._parseEntity = function _parseEntity(entityConfig, engine) {
46706
46914
  var transform = entityConfig.transform;
46707
46915
  var entity = new Entity(engine, entityConfig.name, transform ? Loader.getClass(transform.class) : Transform);
46708
- if (!entityConfig.parent) this.context.rootIds.push(entityConfig.id);
46709
46916
  this._addEntityPlugin(entityConfig.id, entity);
46710
46917
  return Promise.resolve(entity);
46711
46918
  };
@@ -46718,7 +46925,6 @@ function _create_for_of_iterator_helper_loose(o, allowArrayLike) {
46718
46925
  }).then(function(prefabResource) {
46719
46926
  var entity = _instanceof1(prefabResource, PrefabResource) ? prefabResource.instantiate() : prefabResource.instantiateSceneRoot();
46720
46927
  var instanceContext = new ParserContext(engine, ParserType.Prefab, null);
46721
- if (!entityConfig.parent) _this.context.rootIds.push(entityConfig.id);
46722
46928
  _this._generateInstanceContext(entity, instanceContext, "");
46723
46929
  _this._prefabContextMap.set(entity, instanceContext);
46724
46930
  var cbArray = _this._prefabPromiseMap.get(entityConfig.id);
@@ -52698,11 +52904,11 @@ EXT_texture_webp = __decorate([
52698
52904
  ], EXT_texture_webp);
52699
52905
 
52700
52906
  //@ts-ignore
52701
- var version = "2.0.0-alpha.14";
52907
+ var version = "2.0.0-alpha.16";
52702
52908
  console.log("Galacean Engine Version: " + version);
52703
52909
  for(var key in CoreObjects){
52704
52910
  Loader.registerClass(key, CoreObjects[key]);
52705
52911
  }
52706
52912
 
52707
- export { AccessorType, AmbientLight, AmbientOcclusion, AmbientOcclusionQuality, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationClipDecoder, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorCondition, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorControllerParameter, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AntiAliasing, AssetPromise, AssetType, AudioClip, AudioManager, AudioSource, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, BasicRenderPipeline, BatchUtils, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, Blitter, BloomDownScaleMode, BloomEffect, BoolUpdateFlag, BoundingBox, BoundingFrustum, BoundingSphere, BoxColliderShape, BoxShape, Buffer, BufferAsset, BufferBindFlag, BufferInfo, BufferMesh, BufferReader, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraModifyFlags, CameraType$1 as CameraType, Canvas, CapsuleColliderShape, CharRenderInfo, CharacterController, CircleShape, ClearableObjectPool, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, Collision, CollisionDetectionMode, CollisionUtil, Color, ColorOverLifetimeModule, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContactPoint, ContainmentType, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DisorderedArray, Downsampling, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EntityModifyFlags, EventDispatcher, FileHeader, FinalPass, FixedJoint, FogMode, Font, FontStyle, FrustumFace, GLCapabilityType, GLCompressedTextureInternalFormat, GLTFAnimationParser, GLTFAnimatorControllerParser, GLTFBufferParser, GLTFBufferViewParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFLoader, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, GradientAlphaKey, GradientColorKey, HDRDecoder, HemisphereShape, HierarchyParser, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolableValueType, InterpolationType, JSONAsset, Joint, JointLimits, JointMotor, KTX2Loader, KTX2TargetFormat, Keyframe, Keys, Layer, LayerPathMask, Light, Loader, Logger, MSAASamples, MainModule, Material, MaterialLoaderType, MathUtil, Matrix, Matrix3x3, Mesh, MeshColliderShape, MeshColliderShapeCookingFlag, MeshDecoder, MeshRenderer, MeshShape, MeshTopology, ModelMesh, OverflowMode, PBRMaterial, ParserContext, ParserType, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, Plane, PlaneColliderShape, PlaneIntersectionType, Platform, PointLight, Pointer, PointerButton, PointerEventData, PointerEventEmitter, PointerPhase, PostProcess, PostProcessEffect, PostProcessEffectBoolParameter, PostProcessEffectColorParameter, PostProcessEffectEnumParameter, PostProcessEffectFloatParameter, PostProcessEffectParameter, PostProcessEffectTextureParameter, PostProcessEffectVector2Parameter, PostProcessEffectVector3Parameter, PostProcessEffectVector4Parameter, PostProcessManager, PostProcessPass, PostProcessPassEvent, PostProcessUberPass, PrefabResource, Primitive, PrimitiveMesh, Probe, Quaternion, Rand, RasterState, Ray, Rect, ReferResource, ReflectionParser, RefractionMode, RenderBufferDepthFormat, RenderFace, RenderQueue, RenderQueueFlags, RenderQueueType, RenderState, RenderStateElementKey, RenderTarget, RenderTargetBlendState, Renderer, RendererUpdateFlags, RenderingStatistics, ReplacementFailureStrategy, ResourceManager, ReturnableObjectPool, RotationOverLifetimeModule, SafeLoopArray, Scene, SceneManager, SceneParser, Script, SetDataOptions, Shader, ShaderData, ShaderDataGroup, ShaderFactory, ShaderLanguage, ShaderLib, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, SimpleSpriteAssembler, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SlicedSpriteAssembler, SpecularMode, SphereColliderShape, SphereShape, SphericalHarmonics3, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteModifyFlags, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubFont, SubMesh, SubPrimitive, SubShader, SunMode, SystemInfo, TextAsset, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, Texture2DDecoder, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureUtils, TextureWrapMode$1 as TextureWrapMode, TiledSpriteAssembler, Time, TonemappingEffect, TonemappingMode, TrailMaterial, TrailRenderer, TrailTextureMode, Transform, TransformModifyFlags, UnlitMaterial, Utils, Vector2, Vector3, Vector4, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice, WebGLMode, WrapMode, XRManager, assignmentClone, decode, decoder, decoderMap, deepClone, dependentComponents, ignoreClone, parseSingleKTX, registerGLTFExtension, registerGLTFParser, registerPointerEventEmitter, request, resourceLoader, shallowClone, version };
52913
+ export { AccessorType, AmbientLight, AmbientOcclusion, AmbientOcclusionQuality, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationClipDecoder, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationRectCurve, AnimationRefCurve, AnimationStringCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorCondition, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorControllerParameter, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorLayerMask, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AntiAliasing, AssetPromise, AssetType, AudioClip, AudioManager, AudioSource, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, BasicRenderPipeline, BatchUtils, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, Blitter, BloomDownScaleMode, BloomEffect, BoolUpdateFlag, BoundingBox, BoundingFrustum, BoundingSphere, BoxColliderShape, BoxShape, Buffer, BufferAsset, BufferBindFlag, BufferInfo, BufferMesh, BufferReader, BufferUsage, BufferUtil, Burst, Camera, CameraClearFlags, CameraModifyFlags, CameraType$1 as CameraType, Canvas, CapsuleColliderShape, CharRenderInfo, CharacterController, CircleShape, ClearableObjectPool, CloneManager, CloneUtils, Collider, ColliderShape, ColliderShapeUpAxis, Collision, CollisionDetectionMode, CollisionUtil, Color, ColorOverLifetimeModule, ColorWriteMask, CompareFunction, Component, ConeEmitType, ConeShape, ContactPoint, ContainmentType, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, CurveKey, DataType, DependentMode, DepthState, DepthTextureMode, DiffuseMode, DirectLight, DisorderedArray, Downsampling, DynamicCollider, DynamicColliderConstraints, EmissionModule, Engine, EngineObject, Entity, EntityModifyFlags, EventDispatcher, FileHeader, FinalPass, FixedJoint, FogMode, Font, FontStyle, FrustumFace, GLCapabilityType, GLCompressedTextureInternalFormat, GLTFAnimationParser, GLTFAnimatorControllerParser, GLTFBufferParser, GLTFBufferViewParser, GLTFEntityParser, GLTFExtensionMode, GLTFExtensionParser, GLTFLoader, GLTFMaterialParser, GLTFMeshParser, GLTFParser, GLTFParserContext, GLTFParserType, GLTFResource, GLTFSceneParser, GLTFSchemaParser, GLTFSkinParser, GLTFTextureParser, GLTFUtils, GLTFValidator, GradientAlphaKey, GradientColorKey, HDRDecoder, HemisphereShape, HierarchyParser, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolableValueType, InterpolationType, JSONAsset, Joint, JointLimits, JointMotor, KTX2Loader, KTX2TargetFormat, Keyframe, Keys, Layer, LayerPathMask, Light, Loader, Logger, MSAASamples, MainModule, Material, MaterialLoaderType, MathUtil, Matrix, Matrix3x3, Mesh, MeshColliderShape, MeshColliderShapeCookingFlag, MeshDecoder, MeshRenderer, MeshShape, MeshTopology, ModelMesh, OverflowMode, PBRMaterial, ParserContext, ParserType, ParticleCompositeCurve, ParticleCompositeGradient, ParticleCurve, ParticleCurveMode, ParticleGenerator, ParticleGradient, ParticleGradientMode, ParticleMaterial, ParticleRenderMode, ParticleRenderer, ParticleScaleMode, ParticleShapeArcMode, ParticleShapeType, ParticleSimulationSpace, ParticleStopMode, PhysicsMaterial, PhysicsMaterialCombineMode, PhysicsScene, PipelineStage, Plane, PlaneColliderShape, PlaneIntersectionType, Platform, PointLight, Pointer, PointerButton, PointerEventData, PointerEventEmitter, PointerPhase, PostProcess, PostProcessEffect, PostProcessEffectBoolParameter, PostProcessEffectColorParameter, PostProcessEffectEnumParameter, PostProcessEffectFloatParameter, PostProcessEffectParameter, PostProcessEffectTextureParameter, PostProcessEffectVector2Parameter, PostProcessEffectVector3Parameter, PostProcessEffectVector4Parameter, PostProcessManager, PostProcessPass, PostProcessPassEvent, PostProcessUberPass, PrefabResource, Primitive, PrimitiveMesh, Probe, Quaternion, Rand, RasterState, Ray, Rect, ReferResource, ReflectionParser, RefractionMode, RenderBufferDepthFormat, RenderFace, RenderQueue, RenderQueueFlags, RenderQueueType, RenderState, RenderStateElementKey, RenderTarget, RenderTargetBlendState, Renderer, RendererUpdateFlags, RenderingStatistics, ReplacementFailureStrategy, ResourceManager, ReturnableObjectPool, RotationOverLifetimeModule, SafeLoopArray, Scene, SceneManager, SceneParser, Script, SetDataOptions, Shader, ShaderData, ShaderDataGroup, ShaderFactory, ShaderLanguage, ShaderLib, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, Signal, SimpleSpriteAssembler, SizeOverLifetimeModule, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SlicedSpriteAssembler, SpecularMode, SphereColliderShape, SphereShape, SphericalHarmonics3, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteModifyFlags, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubFont, SubMesh, SubPrimitive, SubShader, SunMode, SystemInfo, TextAsset, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, Texture2DDecoder, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureSheetAnimationModule, TextureUsage, TextureUtils, TextureWrapMode$1 as TextureWrapMode, TiledSpriteAssembler, Time, TonemappingEffect, TonemappingMode, TrailMaterial, TrailRenderer, TrailTextureMode, Transform, TransformModifyFlags, UnlitMaterial, Utils, Vector2, Vector3, Vector4, VelocityOverLifetimeModule, VertexAttribute, VertexBufferBinding, VertexElement, VertexElementFormat, WebCanvas, WebGLEngine, WebGLGraphicDevice, WebGLMode, WrapMode, XRManager, assignmentClone, decode, decoder, decoderMap, deepClone, dependentComponents, ignoreClone, parseSingleKTX, registerGLTFExtension, registerGLTFParser, registerPointerEventEmitter, request, resourceLoader, shallowClone, version };
52708
52914
  //# sourceMappingURL=bundled.module.js.map