@galacean/engine 2.0.0-alpha.14 → 2.0.0-alpha.15

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -988,11 +988,15 @@
988
988
  var normal = plane.normal;
989
989
  var zeroTolerance = MathUtil.zeroTolerance;
990
990
  var dir = Vector3.dot(normal, ray.direction);
991
+ var position = Vector3.dot(normal, ray.origin);
991
992
  // Parallel
992
993
  if (Math.abs(dir) < zeroTolerance) {
994
+ // Check if ray origin is on the plane
995
+ if (Math.abs(position + plane.distance) < zeroTolerance) {
996
+ return 0;
997
+ }
993
998
  return -1;
994
999
  }
995
- var position = Vector3.dot(normal, ray.origin);
996
1000
  var distance = (-plane.distance - position) / dir;
997
1001
  if (distance < 0) {
998
1002
  if (distance < -zeroTolerance) {
@@ -27096,279 +27100,978 @@
27096
27100
  ]);
27097
27101
  PrimitiveMesh._sphereEdgeIdx = 0;
27098
27102
  PrimitiveMesh._spherePoleIdx = 0;
27099
- function _is_native_reflect_construct$1() {
27100
- // Since Reflect.construct can't be properly polyfilled, some
27101
- // implementations (e.g. core-js@2) don't set the correct internal slots.
27102
- // Those polyfills don't allow us to subclass built-ins, so we need to
27103
- // use our fallback implementation.
27104
- try {
27105
- // If the internal slots aren't set, this throws an error similar to
27106
- // TypeError: this is not a Boolean object.
27107
- var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
27108
- } catch (_) {}
27109
- return (_is_native_reflect_construct$1 = function _is_native_reflect_construct() {
27110
- return !!result;
27111
- })();
27112
- }
27113
- function _construct$1(Parent, args, Class) {
27114
- if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
27115
- else {
27116
- _construct$1 = function construct(Parent, args, Class) {
27117
- var a = [
27118
- null
27119
- ];
27120
- a.push.apply(a, args);
27121
- var Constructor = Function.bind.apply(Parent, a);
27122
- var instance = new Constructor();
27123
- if (Class) _set_prototype_of$2(instance, Class.prototype);
27124
- return instance;
27125
- };
27126
- }
27127
- return _construct$1.apply(null, arguments);
27128
- }
27129
- var ComponentCloner = /*#__PURE__*/ function() {
27130
- function ComponentCloner() {}
27131
- /**
27132
- * Clone component.
27133
- * @param source - Clone source
27134
- * @param target - Clone target
27135
- */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
27136
- var cloneModes = CloneManager.getCloneMode(source.constructor);
27137
- for(var k in source){
27138
- CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
27103
+ /**
27104
+ * @internal
27105
+ * Utility functions for remapping Entity/Component references during cloning.
27106
+ */ var CloneUtils = /*#__PURE__*/ function() {
27107
+ function CloneUtils() {}
27108
+ CloneUtils.remapEntity = function remapEntity(srcRoot, targetRoot, entity) {
27109
+ var paths = CloneUtils._tempRemapPath;
27110
+ var success = CloneUtils._getEntityHierarchyPath(srcRoot, entity, paths);
27111
+ return success ? CloneUtils._getEntityByHierarchyPath(targetRoot, paths) : entity;
27112
+ };
27113
+ CloneUtils.remapComponent = function remapComponent(srcRoot, targetRoot, component) {
27114
+ var _CloneUtils__getEntityByHierarchyPath;
27115
+ var paths = CloneUtils._tempRemapPath;
27116
+ var success = CloneUtils._getEntityHierarchyPath(srcRoot, component.entity, paths);
27117
+ return success ? (_CloneUtils__getEntityByHierarchyPath = CloneUtils._getEntityByHierarchyPath(targetRoot, paths)) == null ? void 0 : _CloneUtils__getEntityByHierarchyPath.getComponent(component.constructor) : component;
27118
+ };
27119
+ CloneUtils._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
27120
+ inversePath.length = 0;
27121
+ while(searchEntity !== rootEntity){
27122
+ var parent = searchEntity.parent;
27123
+ if (!parent) {
27124
+ return false;
27125
+ }
27126
+ inversePath.push(searchEntity.siblingIndex);
27127
+ searchEntity = parent;
27139
27128
  }
27140
- if (source._cloneTo) {
27141
- source._cloneTo(target, srcRoot, targetRoot);
27129
+ return true;
27130
+ };
27131
+ CloneUtils._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
27132
+ var entity = rootEntity;
27133
+ for(var i = inversePath.length - 1; i >= 0; i--){
27134
+ entity = entity.children[inversePath[i]];
27142
27135
  }
27136
+ return entity;
27143
27137
  };
27144
- return ComponentCloner;
27138
+ return CloneUtils;
27145
27139
  }();
27140
+ CloneUtils._tempRemapPath = [];
27146
27141
  /**
27147
- * The entity modify flags.
27148
- */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
27149
- /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
27150
- /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
27151
- return EntityModifyFlags;
27152
- }({});
27153
- /**
27154
- * Entity, be used as components container.
27155
- */ var Entity = /*#__PURE__*/ function(EngineObject) {
27156
- _inherits$2(Entity, EngineObject);
27157
- function Entity(engine, name) {
27158
- for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
27159
- components[_key - 2] = arguments[_key];
27160
- }
27142
+ * Skin used for skinned mesh renderer.
27143
+ */ var Skin = /*#__PURE__*/ function(EngineObject) {
27144
+ _inherits$2(Skin, EngineObject);
27145
+ function Skin(name) {
27161
27146
  var _this;
27162
- _this = EngineObject.call(this, engine) || this, /** The layer the entity belongs to. */ _this.layer = Layer.Layer0, /** @internal */ _this._isActiveInHierarchy = false, /** @internal */ _this._isActiveInScene = false, /** @internal */ _this._components = [], /** @internal */ _this._scripts = new DisorderedArray(), /** @internal */ _this._children = [], /** @internal */ _this._isRoot = false, /** @internal */ _this._isActive = true, /** @internal */ _this._siblingIndex = -1, /** @internal */ _this._isTemplate = false, /** @internal */ _this._updateFlagManager = new UpdateFlagManager(), _this._parent = null, _this._invModelMatrix = new Matrix();
27163
- _this.name = name != null ? name : "Entity";
27164
- for(var i = 0, n = components.length; i < n; i++){
27165
- _this.addComponent(components[i]);
27166
- }
27167
- !_this._transform && _this.addComponent(Transform);
27168
- _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
27147
+ _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 = [];
27169
27148
  return _this;
27170
27149
  }
27171
- var _proto = Entity.prototype;
27150
+ var _proto = Skin.prototype;
27172
27151
  /**
27173
- * Add component based on the component type.
27174
- * @param type - The type of the component
27175
- * @param args - The arguments of the component
27176
- * @returns The component which has been added
27177
- */ _proto.addComponent = function addComponent(type) {
27178
- for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
27179
- args[_key - 1] = arguments[_key];
27152
+ * @internal
27153
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
27154
+ if (this._updateMark === renderer.engine.time.frameCount) {
27155
+ return;
27180
27156
  }
27181
- ComponentsDependencies._addCheck(this, type);
27182
- var component = _construct$1(type, [].concat([
27183
- this
27184
- ], args));
27185
- this._components.push(component);
27186
- // @todo: temporary solution
27187
- if (_instanceof1$2(component, Transform)) this._setTransform(component);
27188
- component._setActive(true, ActiveChangeFlag.All);
27189
- return component;
27190
- };
27191
- /**
27192
- * Get component which match the type.
27193
- * @param type - The type of the component
27194
- * @returns The first component which match type
27195
- */ _proto.getComponent = function getComponent(type) {
27196
- var components = this._components;
27197
- for(var i = 0, n = components.length; i < n; i++){
27198
- var component = components[i];
27199
- if (_instanceof1$2(component, type)) {
27200
- return component;
27157
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
27158
+ var _this_rootBone;
27159
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
27160
+ for(var i = bones.length - 1; i >= 0; i--){
27161
+ var bone = bones[i];
27162
+ var offset = i * 16;
27163
+ if (bone) {
27164
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
27165
+ } else {
27166
+ skinMatrices.set(bindMatrices[i].elements, offset);
27201
27167
  }
27168
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
27202
27169
  }
27203
- return null;
27170
+ this._updateMark = renderer.engine.time.frameCount;
27204
27171
  };
27205
27172
  /**
27206
- * Get components which match the type.
27207
- * @param type - The type of the component
27208
- * @param results - The components which match type
27209
- * @returns The components which match type
27210
- */ _proto.getComponents = function getComponents(type, results) {
27211
- results.length = 0;
27212
- var components = this._components;
27213
- for(var i = 0, n = components.length; i < n; i++){
27214
- var component = components[i];
27215
- if (_instanceof1$2(component, type)) {
27216
- results.push(component);
27173
+ * @internal
27174
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27175
+ // Clone rootBone
27176
+ var rootBone = this.rootBone;
27177
+ if (rootBone) {
27178
+ target.rootBone = CloneUtils.remapEntity(srcRoot, targetRoot, rootBone);
27179
+ }
27180
+ // Clone bones
27181
+ var bones = this.bones;
27182
+ if (bones.length > 0) {
27183
+ var boneCount = bones.length;
27184
+ var destBones = new Array(boneCount);
27185
+ for(var i = 0; i < boneCount; i++){
27186
+ destBones[i] = CloneUtils.remapEntity(srcRoot, targetRoot, bones[i]);
27217
27187
  }
27188
+ target.bones = destBones;
27218
27189
  }
27219
- return results;
27220
- };
27221
- /**
27222
- * Get the components which match the type of the entity and it's children.
27223
- * @param type - The component type
27224
- * @param results - The components collection
27225
- * @returns The components collection which match the type
27226
- */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
27227
- results.length = 0;
27228
- this._getComponentsInChildren(type, results);
27229
- return results;
27230
27190
  };
27231
- _proto.addChild = function addChild(indexOrChild, child) {
27232
- var index;
27233
- if (typeof indexOrChild === "number") {
27234
- index = indexOrChild;
27235
- } else {
27236
- index = undefined;
27237
- child = indexOrChild;
27191
+ _create_class$2(Skin, [
27192
+ {
27193
+ key: "rootBone",
27194
+ get: /**
27195
+ * Root bone.
27196
+ */ function get() {
27197
+ return this._rootBone;
27198
+ },
27199
+ set: function set(value) {
27200
+ if (this._rootBone !== value) {
27201
+ this._updatedManager.dispatch(1, value);
27202
+ this._rootBone = value;
27203
+ }
27204
+ }
27205
+ },
27206
+ {
27207
+ key: "bones",
27208
+ get: /**
27209
+ * Bones of the skin.
27210
+ */ function get() {
27211
+ return this._bones;
27212
+ },
27213
+ set: function set(value) {
27214
+ var bones = this._bones;
27215
+ var _value_length;
27216
+ var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
27217
+ var lastBoneCount = bones.length;
27218
+ bones.length = boneCount;
27219
+ for(var i = 0; i < boneCount; i++){
27220
+ bones[i] = value[i];
27221
+ }
27222
+ if (lastBoneCount !== boneCount) {
27223
+ this._skinMatrices = new Float32Array(boneCount * 16);
27224
+ this._updatedManager.dispatch(0, boneCount);
27225
+ }
27226
+ }
27227
+ },
27228
+ {
27229
+ key: "skeleton",
27230
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
27231
+ var _this_rootBone;
27232
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
27233
+ },
27234
+ set: function set(value) {
27235
+ var rootBone = this._rootBone;
27236
+ if (rootBone) {
27237
+ rootBone.name = value;
27238
+ }
27239
+ }
27238
27240
  }
27239
- child._setParent(this, index);
27240
- };
27241
+ ]);
27242
+ return Skin;
27243
+ }(EngineObject);
27244
+ __decorate$1([
27245
+ deepClone
27246
+ ], Skin.prototype, "inverseBindMatrices", void 0);
27247
+ __decorate$1([
27248
+ ignoreClone
27249
+ ], Skin.prototype, "_skinMatrices", void 0);
27250
+ __decorate$1([
27251
+ ignoreClone
27252
+ ], Skin.prototype, "_updatedManager", void 0);
27253
+ __decorate$1([
27254
+ ignoreClone
27255
+ ], Skin.prototype, "_rootBone", void 0);
27256
+ __decorate$1([
27257
+ ignoreClone
27258
+ ], Skin.prototype, "_bones", void 0);
27259
+ __decorate$1([
27260
+ ignoreClone
27261
+ ], Skin.prototype, "_updateMark", void 0);
27262
+ var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
27263
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
27264
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
27265
+ return SkinUpdateFlag;
27266
+ }({});
27267
+ /**
27268
+ * SkinnedMeshRenderer.
27269
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
27270
+ _inherits$2(SkinnedMeshRenderer, MeshRenderer);
27271
+ function SkinnedMeshRenderer(entity) {
27272
+ var _this;
27273
+ _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new BoundingBox(), _this._jointDataCreateCache = new Vector2(-1, -1);
27274
+ _this._skin = null;
27275
+ var rhi = _this.entity.engine._hardwareRenderer;
27276
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
27277
+ // Limit size to 256 to avoid some problem:
27278
+ // 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!
27279
+ // 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.
27280
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
27281
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
27282
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
27283
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
27284
+ var localBounds = _this._localBounds;
27285
+ // @ts-ignore
27286
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
27287
+ // @ts-ignore
27288
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
27289
+ return _this;
27290
+ }
27291
+ var _proto = SkinnedMeshRenderer.prototype;
27241
27292
  /**
27242
- * Remove child entity.
27243
- * @param child - The child entity which want to be removed
27244
- */ _proto.removeChild = function removeChild(child) {
27245
- if (child._parent !== this) return;
27246
- child._setParent(null);
27293
+ * @internal
27294
+ */ _proto._onDestroy = function _onDestroy() {
27295
+ var _this__jointTexture;
27296
+ MeshRenderer.prototype._onDestroy.call(this);
27297
+ this._jointDataCreateCache = null;
27298
+ this._skin = null;
27299
+ this._blendShapeWeights = null;
27300
+ this._localBounds = null;
27301
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27302
+ this._jointTexture = null;
27247
27303
  };
27248
27304
  /**
27249
- * @deprecated Please use `children` property instead.
27250
- * Find child entity by index.
27251
- * @param index - The index of the child entity
27252
- * @returns The component which be found
27253
- */ _proto.getChild = function getChild(index) {
27254
- return this._children[index];
27305
+ * @internal
27306
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27307
+ MeshRenderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
27308
+ if (this.skin) {
27309
+ target._applySkin(null, target.skin);
27310
+ }
27311
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
27255
27312
  };
27256
- /**
27257
- * Find entity by name.
27258
- * @param name - The name of the entity which want to be found
27259
- * @returns The component which be found
27260
- */ _proto.findByName = function findByName(name) {
27261
- if (name === this.name) {
27262
- return this;
27313
+ _proto._update = function _update(context) {
27314
+ var skin = this.skin;
27315
+ if ((skin == null ? void 0 : skin.bones.length) > 0) {
27316
+ skin._updateSkinMatrices(this);
27263
27317
  }
27264
- var children = this._children;
27265
- for(var i = 0, n = children.length; i < n; i++){
27266
- var target = children[i].findByName(name);
27267
- if (target) {
27268
- return target;
27318
+ var shaderData = this.shaderData;
27319
+ var mesh = this.mesh;
27320
+ var blendShapeManager = mesh._blendShapeManager;
27321
+ blendShapeManager._updateShaderData(shaderData, this);
27322
+ var bones = skin == null ? void 0 : skin.bones;
27323
+ if (bones) {
27324
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
27325
+ var boneCount = bones.length;
27326
+ var boneDataCreateCache = this._jointDataCreateCache;
27327
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
27328
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
27329
+ // directly use max joint count to avoid shader recompile
27330
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
27331
+ if (boneCount > remainUniformJointCount) {
27332
+ var engine = this.engine;
27333
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
27334
+ if (boneCountChange) {
27335
+ var _this__jointTexture;
27336
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27337
+ this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
27338
+ this._jointTexture.filterMode = TextureFilterMode.Point;
27339
+ this._jointTexture.isGCIgnored = true;
27340
+ }
27341
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
27342
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
27343
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
27344
+ } else {
27345
+ 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);
27346
+ }
27347
+ } else {
27348
+ var _this__jointTexture1;
27349
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
27350
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
27351
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
27352
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
27353
+ }
27354
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
27355
+ }
27356
+ if (this._jointTexture) {
27357
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
27269
27358
  }
27270
27359
  }
27271
- return null;
27360
+ MeshRenderer.prototype._update.call(this, context);
27272
27361
  };
27273
27362
  /**
27274
- * Find the entity by path.
27275
- * @param path - The path of the entity eg: /entity
27276
- * @returns The component which be found
27277
- */ _proto.findByPath = function findByPath(path) {
27278
- var splits = path.split("/").filter(Boolean);
27279
- if (!splits.length) {
27280
- return this;
27363
+ * @internal
27364
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
27365
+ var _this_skin;
27366
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
27367
+ if (rootBone) {
27368
+ BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
27369
+ } else {
27370
+ MeshRenderer.prototype._updateBounds.call(this, worldBounds);
27281
27371
  }
27282
- return Entity._findChildByName(this, 0, splits, 0);
27283
- };
27284
- /**
27285
- * Create child entity.
27286
- * @param name - The child entity's name
27287
- * @returns The child entity
27288
- */ _proto.createChild = function createChild(name) {
27289
- var transform = this._transform;
27290
- var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
27291
- child.layer = this.layer;
27292
- child.parent = this;
27293
- return child;
27294
27372
  };
27295
- /**
27296
- * Clear children entities.
27297
- */ _proto.clearChildren = function clearChildren() {
27298
- var children = this._children;
27299
- for(var i = children.length - 1; i >= 0; i--){
27300
- var child = children[i];
27301
- child._parent = null;
27302
- var activeChangeFlag = ActiveChangeFlag.None;
27303
- child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27304
- child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
27305
- activeChangeFlag && child._processInActive(activeChangeFlag);
27306
- Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
27373
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
27374
+ var mesh = this._mesh;
27375
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
27376
+ var lastBlendShapeWeights = this._blendShapeWeights;
27377
+ if (lastBlendShapeWeights) {
27378
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
27379
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
27380
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
27381
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
27382
+ newBlendShapeWeights.set(lastBlendShapeWeights);
27383
+ } else {
27384
+ for(var i = 0; i < newBlendShapeCount; i++){
27385
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
27386
+ }
27387
+ }
27388
+ this._blendShapeWeights = newBlendShapeWeights;
27389
+ }
27390
+ } else {
27391
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
27307
27392
  }
27308
- children.length = 0;
27309
- };
27310
- /**
27311
- * Clone this entity include children and components.
27312
- * @returns Cloned entity
27313
- */ _proto.clone = function clone() {
27314
- var cloneEntity = this._createCloneEntity();
27315
- this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
27316
- return cloneEntity;
27317
- };
27318
- /**
27319
- * Listen for changes in the world pose of this `Entity`.
27320
- * @returns Change flag
27321
- */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
27322
- return this._updateFlagManager.createFlag(BoolUpdateFlag);
27323
27393
  };
27324
- /**
27325
- * @internal
27326
- */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
27327
- this._isTemplate = true;
27328
- this._templateResource = templateResource;
27394
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
27395
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
27329
27396
  };
27330
- _proto._createCloneEntity = function _createCloneEntity() {
27331
- var componentConstructors = Entity._tempComponentConstructors;
27332
- var components = this._components;
27333
- for(var i = 0, n = components.length; i < n; i++){
27334
- componentConstructors[i] = components[i].constructor;
27335
- }
27336
- var cloneEntity = _construct$1(Entity, [].concat([
27337
- this.engine,
27338
- this.name
27339
- ], componentConstructors));
27340
- componentConstructors.length = 0;
27341
- var templateResource = this._templateResource;
27342
- if (templateResource) {
27343
- cloneEntity._templateResource = templateResource;
27344
- templateResource._addReferCount(1);
27345
- }
27346
- cloneEntity.layer = this.layer;
27347
- cloneEntity._isActive = this._isActive;
27348
- var srcChildren = this._children;
27349
- for(var i1 = 0, n1 = srcChildren.length; i1 < n1; i1++){
27350
- cloneEntity.addChild(srcChildren[i1]._createCloneEntity());
27397
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
27398
+ switch(type){
27399
+ case SkinUpdateFlag.BoneCountChanged:
27400
+ var shaderData = this.shaderData;
27401
+ if (value > 0) {
27402
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
27403
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
27404
+ } else {
27405
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
27406
+ }
27407
+ break;
27408
+ case SkinUpdateFlag.RootBoneChanged:
27409
+ this._setTransformEntity(value);
27410
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
27411
+ break;
27351
27412
  }
27352
- return cloneEntity;
27353
27413
  };
27354
- _proto._parseCloneEntity = function _parseCloneEntity(src, target, srcRoot, targetRoot, deepInstanceMap) {
27355
- var srcChildren = src._children;
27356
- var targetChildren = target._children;
27357
- for(var i = 0, n = srcChildren.length; i < n; i++){
27358
- this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot, deepInstanceMap);
27414
+ _proto._applySkin = function _applySkin(lastSkin, value) {
27415
+ var _lastSkin_bones, _value_bones;
27416
+ var _lastSkin_bones_length;
27417
+ var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
27418
+ var _lastSkin_rootBone;
27419
+ var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
27420
+ lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
27421
+ var _value_bones_length;
27422
+ var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
27423
+ var _value_rootBone;
27424
+ var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
27425
+ value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
27426
+ if (lastSkinBoneCount !== skinBoneCount) {
27427
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
27359
27428
  }
27360
- var components = src._components;
27361
- for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
27362
- ComponentCloner.cloneComponent(components[i1], target._components[i1], srcRoot, targetRoot, deepInstanceMap);
27429
+ if (lastRootBone !== rootBone) {
27430
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
27363
27431
  }
27364
27432
  };
27365
- /**
27366
- * Destroy self.
27367
- */ _proto.destroy = function destroy() {
27368
- EngineObject.prototype.destroy.call(this);
27369
- if (!this._destroyed) {
27370
- return;
27371
- }
27433
+ _create_class$2(SkinnedMeshRenderer, [
27434
+ {
27435
+ key: "skin",
27436
+ get: /**
27437
+ * Skin of the SkinnedMeshRenderer.
27438
+ */ function get() {
27439
+ return this._skin;
27440
+ },
27441
+ set: function set(value) {
27442
+ var lastSkin = this._skin;
27443
+ if (lastSkin !== value) {
27444
+ this._applySkin(lastSkin, value);
27445
+ this._skin = value;
27446
+ }
27447
+ }
27448
+ },
27449
+ {
27450
+ key: "blendShapeWeights",
27451
+ get: /**
27452
+ * The weights of the BlendShapes.
27453
+ * @remarks Array index is BlendShape index.
27454
+ */ function get() {
27455
+ this._checkBlendShapeWeightLength();
27456
+ return this._blendShapeWeights;
27457
+ },
27458
+ set: function set(value) {
27459
+ this._checkBlendShapeWeightLength();
27460
+ var blendShapeWeights = this._blendShapeWeights;
27461
+ if (value.length <= blendShapeWeights.length) {
27462
+ blendShapeWeights.set(value);
27463
+ } else {
27464
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
27465
+ blendShapeWeights[i] = value[i];
27466
+ }
27467
+ }
27468
+ }
27469
+ },
27470
+ {
27471
+ key: "localBounds",
27472
+ get: /**
27473
+ * Local bounds.
27474
+ */ function get() {
27475
+ return this._localBounds;
27476
+ },
27477
+ set: function set(value) {
27478
+ if (this._localBounds !== value) {
27479
+ this._localBounds.copyFrom(value);
27480
+ }
27481
+ }
27482
+ },
27483
+ {
27484
+ key: "rootBone",
27485
+ get: /**
27486
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
27487
+ */ function get() {
27488
+ return this.skin.rootBone;
27489
+ },
27490
+ set: function set(value) {
27491
+ this.skin.rootBone = value;
27492
+ }
27493
+ },
27494
+ {
27495
+ key: "bones",
27496
+ get: /**
27497
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
27498
+ */ function get() {
27499
+ return this.skin.bones;
27500
+ },
27501
+ set: function set(value) {
27502
+ this.skin.bones = value;
27503
+ }
27504
+ }
27505
+ ]);
27506
+ return SkinnedMeshRenderer;
27507
+ }(MeshRenderer);
27508
+ // @TODO: different shader type should use different count, not always 48
27509
+ /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
27510
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
27511
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
27512
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
27513
+ __decorate$1([
27514
+ ignoreClone
27515
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
27516
+ __decorate$1([
27517
+ deepClone
27518
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
27519
+ __decorate$1([
27520
+ ignoreClone
27521
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
27522
+ __decorate$1([
27523
+ ignoreClone
27524
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
27525
+ __decorate$1([
27526
+ ignoreClone
27527
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
27528
+ __decorate$1([
27529
+ ignoreClone
27530
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
27531
+ __decorate$1([
27532
+ deepClone
27533
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
27534
+ __decorate$1([
27535
+ ignoreClone
27536
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
27537
+ __decorate$1([
27538
+ ignoreClone
27539
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
27540
+ /**
27541
+ * @internal
27542
+ */ var BasicResources = /*#__PURE__*/ function() {
27543
+ function BasicResources(engine) {
27544
+ this.engine = engine;
27545
+ // prettier-ignore
27546
+ var vertices = new Float32Array([
27547
+ -1,
27548
+ -1,
27549
+ 0,
27550
+ 1,
27551
+ 3,
27552
+ -1,
27553
+ 2,
27554
+ 1,
27555
+ -1,
27556
+ 3,
27557
+ 0,
27558
+ -1
27559
+ ]); // left-top
27560
+ // prettier-ignore
27561
+ var flipYVertices = new Float32Array([
27562
+ 3,
27563
+ -1,
27564
+ 2,
27565
+ 0,
27566
+ -1,
27567
+ -1,
27568
+ 0,
27569
+ 0,
27570
+ -1,
27571
+ 3,
27572
+ 0,
27573
+ 2
27574
+ ]); // left-top
27575
+ var blitMaterial = new Material(engine, Shader.find("blit"));
27576
+ blitMaterial._addReferCount(1);
27577
+ blitMaterial.renderState.depthState.enabled = false;
27578
+ blitMaterial.renderState.depthState.writeEnabled = false;
27579
+ var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
27580
+ blitScreenMaterial._addReferCount(1);
27581
+ blitScreenMaterial.renderState.depthState.enabled = false;
27582
+ blitScreenMaterial.renderState.depthState.writeEnabled = false;
27583
+ this.blitMaterial = blitMaterial;
27584
+ this.blitScreenMaterial = blitScreenMaterial;
27585
+ this.blitMesh = this._createBlitMesh(engine, vertices);
27586
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
27587
+ // Create white and magenta textures
27588
+ var whitePixel = new Uint8Array([
27589
+ 255,
27590
+ 255,
27591
+ 255,
27592
+ 255
27593
+ ]);
27594
+ this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
27595
+ this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
27596
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
27597
+ if (isWebGL2) {
27598
+ this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
27599
+ var whitePixel32 = new Uint32Array([
27600
+ 255,
27601
+ 255,
27602
+ 255,
27603
+ 255
27604
+ ]);
27605
+ this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
27606
+ }
27607
+ this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
27608
+ this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
27609
+ this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
27610
+ this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
27611
+ this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
27612
+ }
27613
+ var _proto = BasicResources.prototype;
27614
+ /**
27615
+ * @internal
27616
+ */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
27617
+ return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
27618
+ };
27619
+ /**
27620
+ * @internal
27621
+ */ _proto._initialize = function _initialize() {
27622
+ var _this = this;
27623
+ return new Promise(function(resolve, reject) {
27624
+ PrefilteredDFG.create(_this.engine).then(function(texture) {
27625
+ _this._prefilteredDFGTexture = texture;
27626
+ resolve(_this);
27627
+ }).catch(reject);
27628
+ });
27629
+ };
27630
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
27631
+ var mesh = new ModelMesh(engine);
27632
+ mesh._addReferCount(1);
27633
+ mesh.setVertexElements([
27634
+ new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
27635
+ ]);
27636
+ var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
27637
+ mesh.setVertexBufferBinding(buffer, 16);
27638
+ mesh.addSubMesh(0, 3, MeshTopology.Triangles);
27639
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
27640
+ _inherits$2(_class, ContentRestorer);
27641
+ function _class() {
27642
+ return ContentRestorer.call(this, mesh) || this;
27643
+ }
27644
+ var _proto = _class.prototype;
27645
+ _proto.restoreContent = function restoreContent() {
27646
+ buffer.setData(buffer.data);
27647
+ };
27648
+ return _class;
27649
+ }(ContentRestorer))());
27650
+ return mesh;
27651
+ };
27652
+ _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
27653
+ var texture;
27654
+ switch(type){
27655
+ case 0:
27656
+ var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
27657
+ texture2D.setPixelBuffer(pixel);
27658
+ texture = texture2D;
27659
+ break;
27660
+ case 2:
27661
+ var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
27662
+ texture2DArray.setPixelBuffer(0, pixel);
27663
+ texture = texture2DArray;
27664
+ break;
27665
+ case 1:
27666
+ var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
27667
+ for(var i = 0; i < 6; i++){
27668
+ textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
27669
+ }
27670
+ texture = textureCube;
27671
+ break;
27672
+ default:
27673
+ throw "Invalid texture type";
27674
+ }
27675
+ texture.isGCIgnored = true;
27676
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
27677
+ _inherits$2(_class, ContentRestorer);
27678
+ function _class() {
27679
+ return ContentRestorer.call(this, texture) || this;
27680
+ }
27681
+ var _proto = _class.prototype;
27682
+ _proto.restoreContent = function restoreContent() {
27683
+ switch(type){
27684
+ case 0:
27685
+ this.resource.setPixelBuffer(pixel);
27686
+ break;
27687
+ case 2:
27688
+ this.resource.setPixelBuffer(0, pixel);
27689
+ break;
27690
+ case 1:
27691
+ for(var i = 0; i < 6; i++){
27692
+ this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
27693
+ }
27694
+ break;
27695
+ }
27696
+ };
27697
+ return _class;
27698
+ }(ContentRestorer))());
27699
+ return texture;
27700
+ };
27701
+ _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
27702
+ var material = new Material(engine, shader);
27703
+ var renderState = material.renderState;
27704
+ var target = renderState.blendState.targetBlendState;
27705
+ target.enabled = true;
27706
+ target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
27707
+ target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
27708
+ target.sourceAlphaBlendFactor = BlendFactor.One;
27709
+ target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
27710
+ target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
27711
+ renderState.depthState.writeEnabled = false;
27712
+ renderState.rasterState.cullMode = CullMode.Off;
27713
+ renderState.renderQueueType = RenderQueueType.Transparent;
27714
+ material.isGCIgnored = true;
27715
+ return material;
27716
+ };
27717
+ _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
27718
+ var material = new Material(engine, Shader.find(shaderName));
27719
+ material.isGCIgnored = true;
27720
+ material.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
27721
+ return material;
27722
+ };
27723
+ _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
27724
+ var material = new Material(engine, Shader.find("SpriteMask"));
27725
+ material.isGCIgnored = true;
27726
+ return material;
27727
+ };
27728
+ BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
27729
+ var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
27730
+ var renderStates;
27731
+ var compareFunction;
27732
+ if (visibleInsideMask) {
27733
+ renderStates = BasicResources._maskReadInsideRenderStates;
27734
+ if (renderStates) {
27735
+ return renderStates;
27736
+ }
27737
+ BasicResources._maskReadInsideRenderStates = renderStates = {};
27738
+ compareFunction = CompareFunction.LessEqual;
27739
+ } else {
27740
+ renderStates = BasicResources._maskReadOutsideRenderStates;
27741
+ if (renderStates) {
27742
+ return renderStates;
27743
+ }
27744
+ BasicResources._maskReadOutsideRenderStates = renderStates = {};
27745
+ compareFunction = CompareFunction.Greater;
27746
+ }
27747
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
27748
+ renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
27749
+ renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
27750
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
27751
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
27752
+ return renderStates;
27753
+ };
27754
+ BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
27755
+ var isIncrement = maskType === RenderQueueMaskType.Increment;
27756
+ var renderStates;
27757
+ var passOperation;
27758
+ if (isIncrement) {
27759
+ renderStates = BasicResources._maskWriteIncrementRenderStates;
27760
+ if (renderStates) {
27761
+ return renderStates;
27762
+ }
27763
+ BasicResources._maskWriteIncrementRenderStates = renderStates = {};
27764
+ passOperation = StencilOperation.IncrementSaturate;
27765
+ } else {
27766
+ renderStates = BasicResources._maskWriteDecrementRenderStates;
27767
+ if (renderStates) {
27768
+ return renderStates;
27769
+ }
27770
+ BasicResources._maskWriteDecrementRenderStates = renderStates = {};
27771
+ passOperation = StencilOperation.DecrementSaturate;
27772
+ }
27773
+ renderStates[RenderStateElementKey.StencilStateEnabled] = true;
27774
+ renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
27775
+ renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
27776
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
27777
+ renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
27778
+ var failStencilOperation = StencilOperation.Keep;
27779
+ renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
27780
+ renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
27781
+ renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
27782
+ renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
27783
+ renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
27784
+ renderStates[RenderStateElementKey.DepthStateEnabled] = false;
27785
+ renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
27786
+ return renderStates;
27787
+ };
27788
+ _create_class$2(BasicResources, [
27789
+ {
27790
+ key: "prefilteredDFGTexture",
27791
+ get: function get() {
27792
+ return this._prefilteredDFGTexture;
27793
+ }
27794
+ }
27795
+ ]);
27796
+ return BasicResources;
27797
+ }();
27798
+ BasicResources._maskReadInsideRenderStates = null;
27799
+ BasicResources._maskReadOutsideRenderStates = null;
27800
+ BasicResources._maskWriteIncrementRenderStates = null;
27801
+ BasicResources._maskWriteDecrementRenderStates = null;
27802
+ function _is_native_reflect_construct$1() {
27803
+ // Since Reflect.construct can't be properly polyfilled, some
27804
+ // implementations (e.g. core-js@2) don't set the correct internal slots.
27805
+ // Those polyfills don't allow us to subclass built-ins, so we need to
27806
+ // use our fallback implementation.
27807
+ try {
27808
+ // If the internal slots aren't set, this throws an error similar to
27809
+ // TypeError: this is not a Boolean object.
27810
+ var result = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
27811
+ } catch (_) {}
27812
+ return (_is_native_reflect_construct$1 = function _is_native_reflect_construct() {
27813
+ return !!result;
27814
+ })();
27815
+ }
27816
+ function _construct$1(Parent, args, Class) {
27817
+ if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
27818
+ else {
27819
+ _construct$1 = function construct(Parent, args, Class) {
27820
+ var a = [
27821
+ null
27822
+ ];
27823
+ a.push.apply(a, args);
27824
+ var Constructor = Function.bind.apply(Parent, a);
27825
+ var instance = new Constructor();
27826
+ if (Class) _set_prototype_of$2(instance, Class.prototype);
27827
+ return instance;
27828
+ };
27829
+ }
27830
+ return _construct$1.apply(null, arguments);
27831
+ }
27832
+ var ComponentCloner = /*#__PURE__*/ function() {
27833
+ function ComponentCloner() {}
27834
+ /**
27835
+ * Clone component.
27836
+ * @param source - Clone source
27837
+ * @param target - Clone target
27838
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
27839
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
27840
+ for(var k in source){
27841
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
27842
+ }
27843
+ if (source._cloneTo) {
27844
+ source._cloneTo(target, srcRoot, targetRoot);
27845
+ }
27846
+ };
27847
+ return ComponentCloner;
27848
+ }();
27849
+ /**
27850
+ * The entity modify flags.
27851
+ */ var EntityModifyFlags = /*#__PURE__*/ function(EntityModifyFlags) {
27852
+ /** The parent changes. */ EntityModifyFlags[EntityModifyFlags["Parent"] = 1] = "Parent";
27853
+ /** The child changes. */ EntityModifyFlags[EntityModifyFlags["Child"] = 2] = "Child";
27854
+ return EntityModifyFlags;
27855
+ }({});
27856
+ /**
27857
+ * Entity, be used as components container.
27858
+ */ var Entity = /*#__PURE__*/ function(EngineObject) {
27859
+ _inherits$2(Entity, EngineObject);
27860
+ function Entity(engine, name) {
27861
+ for(var _len = arguments.length, components = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
27862
+ components[_key - 2] = arguments[_key];
27863
+ }
27864
+ var _this;
27865
+ _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();
27866
+ _this.name = name != null ? name : "Entity";
27867
+ for(var i = 0, n = components.length; i < n; i++){
27868
+ _this.addComponent(components[i]);
27869
+ }
27870
+ !_this._transform && _this.addComponent(Transform);
27871
+ _this._inverseWorldMatFlag = _this.registerWorldChangeFlag();
27872
+ return _this;
27873
+ }
27874
+ var _proto = Entity.prototype;
27875
+ /**
27876
+ * Add component based on the component type.
27877
+ * @param type - The type of the component
27878
+ * @param args - The arguments of the component
27879
+ * @returns The component which has been added
27880
+ */ _proto.addComponent = function addComponent(type) {
27881
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
27882
+ args[_key - 1] = arguments[_key];
27883
+ }
27884
+ ComponentsDependencies._addCheck(this, type);
27885
+ var component = _construct$1(type, [].concat([
27886
+ this
27887
+ ], args));
27888
+ this._components.push(component);
27889
+ // @todo: temporary solution
27890
+ if (_instanceof1$2(component, Transform)) this._setTransform(component);
27891
+ component._setActive(true, ActiveChangeFlag.All);
27892
+ return component;
27893
+ };
27894
+ /**
27895
+ * Get component which match the type.
27896
+ * @param type - The type of the component
27897
+ * @returns The first component which match type
27898
+ */ _proto.getComponent = function getComponent(type) {
27899
+ var components = this._components;
27900
+ for(var i = 0, n = components.length; i < n; i++){
27901
+ var component = components[i];
27902
+ if (_instanceof1$2(component, type)) {
27903
+ return component;
27904
+ }
27905
+ }
27906
+ return null;
27907
+ };
27908
+ /**
27909
+ * Get components which match the type.
27910
+ * @param type - The type of the component
27911
+ * @param results - The components which match type
27912
+ * @returns The components which match type
27913
+ */ _proto.getComponents = function getComponents(type, results) {
27914
+ results.length = 0;
27915
+ var components = this._components;
27916
+ for(var i = 0, n = components.length; i < n; i++){
27917
+ var component = components[i];
27918
+ if (_instanceof1$2(component, type)) {
27919
+ results.push(component);
27920
+ }
27921
+ }
27922
+ return results;
27923
+ };
27924
+ /**
27925
+ * Get the components which match the type of the entity and it's children.
27926
+ * @param type - The component type
27927
+ * @param results - The components collection
27928
+ * @returns The components collection which match the type
27929
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
27930
+ results.length = 0;
27931
+ this._getComponentsInChildren(type, results);
27932
+ return results;
27933
+ };
27934
+ _proto.addChild = function addChild(indexOrChild, child) {
27935
+ var index;
27936
+ if (typeof indexOrChild === "number") {
27937
+ index = indexOrChild;
27938
+ } else {
27939
+ index = undefined;
27940
+ child = indexOrChild;
27941
+ }
27942
+ child._setParent(this, index);
27943
+ };
27944
+ /**
27945
+ * Remove child entity.
27946
+ * @param child - The child entity which want to be removed
27947
+ */ _proto.removeChild = function removeChild(child) {
27948
+ if (child._parent !== this) return;
27949
+ child._setParent(null);
27950
+ };
27951
+ /**
27952
+ * @deprecated Please use `children` property instead.
27953
+ * Find child entity by index.
27954
+ * @param index - The index of the child entity
27955
+ * @returns The component which be found
27956
+ */ _proto.getChild = function getChild(index) {
27957
+ return this._children[index];
27958
+ };
27959
+ /**
27960
+ * Find entity by name.
27961
+ * @param name - The name of the entity which want to be found
27962
+ * @returns The component which be found
27963
+ */ _proto.findByName = function findByName(name) {
27964
+ if (name === this.name) {
27965
+ return this;
27966
+ }
27967
+ var children = this._children;
27968
+ for(var i = 0, n = children.length; i < n; i++){
27969
+ var target = children[i].findByName(name);
27970
+ if (target) {
27971
+ return target;
27972
+ }
27973
+ }
27974
+ return null;
27975
+ };
27976
+ /**
27977
+ * Find the entity by path.
27978
+ * @param path - The path of the entity eg: /entity
27979
+ * @returns The component which be found
27980
+ */ _proto.findByPath = function findByPath(path) {
27981
+ var splits = path.split("/").filter(Boolean);
27982
+ if (!splits.length) {
27983
+ return this;
27984
+ }
27985
+ return Entity._findChildByName(this, 0, splits, 0);
27986
+ };
27987
+ /**
27988
+ * Create child entity.
27989
+ * @param name - The child entity's name
27990
+ * @returns The child entity
27991
+ */ _proto.createChild = function createChild(name) {
27992
+ var transform = this._transform;
27993
+ var child = transform ? new Entity(this.engine, name, transform.constructor) : new Entity(this.engine, name);
27994
+ child.layer = this.layer;
27995
+ child.parent = this;
27996
+ return child;
27997
+ };
27998
+ /**
27999
+ * Clear children entities.
28000
+ */ _proto.clearChildren = function clearChildren() {
28001
+ var children = this._children;
28002
+ for(var i = children.length - 1; i >= 0; i--){
28003
+ var child = children[i];
28004
+ child._parent = null;
28005
+ var activeChangeFlag = ActiveChangeFlag.None;
28006
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
28007
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
28008
+ activeChangeFlag && child._processInActive(activeChangeFlag);
28009
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
28010
+ }
28011
+ children.length = 0;
28012
+ };
28013
+ /**
28014
+ * Clone this entity include children and components.
28015
+ * @returns Cloned entity
28016
+ */ _proto.clone = function clone() {
28017
+ var cloneEntity = this._createCloneEntity();
28018
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
28019
+ return cloneEntity;
28020
+ };
28021
+ /**
28022
+ * Listen for changes in the world pose of this `Entity`.
28023
+ * @returns Change flag
28024
+ */ _proto.registerWorldChangeFlag = function registerWorldChangeFlag() {
28025
+ return this._updateFlagManager.createFlag(BoolUpdateFlag);
28026
+ };
28027
+ /**
28028
+ * @internal
28029
+ */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
28030
+ this._isTemplate = true;
28031
+ this._templateResource = templateResource;
28032
+ };
28033
+ _proto._createCloneEntity = function _createCloneEntity() {
28034
+ var componentConstructors = Entity._tempComponentConstructors;
28035
+ var components = this._components;
28036
+ for(var i = 0, n = components.length; i < n; i++){
28037
+ componentConstructors[i] = components[i].constructor;
28038
+ }
28039
+ var cloneEntity = _construct$1(Entity, [].concat([
28040
+ this.engine,
28041
+ this.name
28042
+ ], componentConstructors));
28043
+ componentConstructors.length = 0;
28044
+ var templateResource = this._templateResource;
28045
+ if (templateResource) {
28046
+ cloneEntity._templateResource = templateResource;
28047
+ templateResource._addReferCount(1);
28048
+ }
28049
+ cloneEntity.layer = this.layer;
28050
+ cloneEntity._isActive = this._isActive;
28051
+ var srcChildren = this._children;
28052
+ for(var i1 = 0, n1 = srcChildren.length; i1 < n1; i1++){
28053
+ cloneEntity.addChild(srcChildren[i1]._createCloneEntity());
28054
+ }
28055
+ return cloneEntity;
28056
+ };
28057
+ _proto._parseCloneEntity = function _parseCloneEntity(src, target, srcRoot, targetRoot, deepInstanceMap) {
28058
+ var srcChildren = src._children;
28059
+ var targetChildren = target._children;
28060
+ for(var i = 0, n = srcChildren.length; i < n; i++){
28061
+ this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot, deepInstanceMap);
28062
+ }
28063
+ var components = src._components;
28064
+ for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
28065
+ ComponentCloner.cloneComponent(components[i1], target._components[i1], srcRoot, targetRoot, deepInstanceMap);
28066
+ }
28067
+ };
28068
+ /**
28069
+ * Destroy self.
28070
+ */ _proto.destroy = function destroy() {
28071
+ EngineObject.prototype.destroy.call(this);
28072
+ if (!this._destroyed) {
28073
+ return;
28074
+ }
27372
28075
  if (this._templateResource) {
27373
28076
  this._isTemplate || this._templateResource._addReferCount(-1);
27374
28077
  this._templateResource = null;
@@ -27632,833 +28335,145 @@
27632
28335
  this._traverseSetOwnerScene(children[i], scene);
27633
28336
  }
27634
28337
  };
27635
- /**
27636
- * @internal
27637
- */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
27638
- inversePath.length = 0;
27639
- while(searchEntity !== rootEntity){
27640
- var parent = searchEntity.parent;
27641
- if (!parent) {
27642
- return false;
27643
- }
27644
- inversePath.push(searchEntity.siblingIndex);
27645
- searchEntity = parent;
27646
- }
27647
- return true;
27648
- };
27649
- /**
27650
- * @internal
27651
- */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
27652
- var entity = rootEntity;
27653
- for(var i = inversePath.length - 1; i >= 0; i--){
27654
- entity = entity.children[inversePath[i]];
27655
- }
27656
- return entity;
27657
- };
27658
- /**
27659
- * @internal
27660
- */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
27661
- var count = children.length - 1;
27662
- for(var i = entity._siblingIndex; i < count; i++){
27663
- var child = children[i + 1];
27664
- children[i] = child;
27665
- child._siblingIndex = i;
27666
- }
27667
- children.length = count;
27668
- entity._siblingIndex = -1;
27669
- };
27670
- /**
27671
- * @internal
27672
- */ Entity._addToChildren = function _addToChildren(children, entity, index) {
27673
- var childCount = children.length;
27674
- children.length = childCount + 1;
27675
- if (index === undefined) {
27676
- children[childCount] = entity;
27677
- entity._siblingIndex = childCount;
27678
- } else {
27679
- if (index < 0 || index > childCount) {
27680
- throw "The index " + index + " is out of child list bounds " + childCount;
27681
- }
27682
- for(var i = childCount; i > index; i--){
27683
- var swapChild = children[i - 1];
27684
- swapChild._siblingIndex = i;
27685
- children[i] = swapChild;
27686
- }
27687
- entity._siblingIndex = index;
27688
- children[index] = entity;
27689
- }
27690
- };
27691
- _create_class$2(Entity, [
27692
- {
27693
- key: "transform",
27694
- get: /**
27695
- * The transform of this entity.
27696
- */ function get() {
27697
- return this._transform;
27698
- }
27699
- },
27700
- {
27701
- key: "isActive",
27702
- get: /**
27703
- * Whether to activate locally.
27704
- */ function get() {
27705
- return this._isActive;
27706
- },
27707
- set: function set(value) {
27708
- if (value !== this._isActive) {
27709
- this._isActive = value;
27710
- if (value) {
27711
- var parent = this._parent;
27712
- var activeChangeFlag = ActiveChangeFlag.None;
27713
- if (this._isRoot && this._scene._isActiveInEngine) {
27714
- activeChangeFlag |= ActiveChangeFlag.All;
27715
- } else {
27716
- (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
27717
- (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
27718
- }
27719
- activeChangeFlag && this._processActive(activeChangeFlag);
27720
- } else {
27721
- var activeChangeFlag1 = ActiveChangeFlag.None;
27722
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
27723
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
27724
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
27725
- }
27726
- }
27727
- }
27728
- },
27729
- {
27730
- key: "isActiveInHierarchy",
27731
- get: /**
27732
- * Whether it is active in the hierarchy.
27733
- */ function get() {
27734
- return this._isActiveInHierarchy;
27735
- }
27736
- },
27737
- {
27738
- key: "parent",
27739
- get: /**
27740
- * The parent entity.
27741
- */ function get() {
27742
- return this._parent;
27743
- },
27744
- set: function set(value) {
27745
- this._setParent(value);
27746
- }
27747
- },
27748
- {
27749
- key: "children",
27750
- get: /**
27751
- * The children entities
27752
- */ function get() {
27753
- return this._children;
27754
- }
27755
- },
27756
- {
27757
- key: "childCount",
27758
- get: /**
27759
- * @deprecated Please use `children.length` property instead.
27760
- * Number of the children entities
27761
- */ function get() {
27762
- return this._children.length;
27763
- }
27764
- },
27765
- {
27766
- key: "scene",
27767
- get: /**
27768
- * The scene the entity belongs to.
27769
- */ function get() {
27770
- return this._scene;
27771
- }
27772
- },
27773
- {
27774
- key: "siblingIndex",
27775
- get: /**
27776
- * The sibling index.
27777
- */ function get() {
27778
- return this._siblingIndex;
27779
- },
27780
- set: function set(value) {
27781
- if (this._siblingIndex === -1) {
27782
- throw "The entity " + this.name + " is not in the hierarchy";
27783
- }
27784
- if (this._isRoot) {
27785
- this._setSiblingIndex(this._scene._rootEntities, value);
27786
- } else {
27787
- var parent = this._parent;
27788
- this._setSiblingIndex(parent._children, value);
27789
- parent._dispatchModify(EntityModifyFlags.Child, parent);
27790
- }
27791
- }
27792
- }
27793
- ]);
27794
- return Entity;
27795
- }(EngineObject);
27796
- /** @internal */ Entity._tempComponentConstructors = [];
27797
- /**
27798
- * Skin used for skinned mesh renderer.
27799
- */ var Skin = /*#__PURE__*/ function(EngineObject) {
27800
- _inherits$2(Skin, EngineObject);
27801
- function Skin(name) {
27802
- var _this;
27803
- _this = EngineObject.call(this, null) || this, _this.name = name, _this.inverseBindMatrices = new Array(), _this._updatedManager = new UpdateFlagManager(), _this._bones = new Array(), _this._updateMark = -1, _this.joints = [];
27804
- return _this;
27805
- }
27806
- var _proto = Skin.prototype;
27807
- /**
27808
- * @internal
27809
- */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
27810
- if (this._updateMark === renderer.engine.time.frameCount) {
27811
- return;
27812
- }
27813
- var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
27814
- var _this_rootBone;
27815
- var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
27816
- for(var i = bones.length - 1; i >= 0; i--){
27817
- var bone = bones[i];
27818
- var offset = i * 16;
27819
- if (bone) {
27820
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
27821
- } else {
27822
- skinMatrices.set(bindMatrices[i].elements, offset);
27823
- }
27824
- Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
27825
- }
27826
- this._updateMark = renderer.engine.time.frameCount;
27827
- };
27828
- /**
27829
- * @internal
27830
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27831
- var paths = new Array();
27832
- // Clone rootBone
27833
- var rootBone = this.rootBone;
27834
- if (rootBone) {
27835
- var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
27836
- target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
27837
- }
27838
- // Clone bones
27839
- var bones = this.bones;
27840
- if (bones.length > 0) {
27841
- var boneCount = bones.length;
27842
- var destBones = new Array(boneCount);
27843
- for(var i = 0; i < boneCount; i++){
27844
- var bone = bones[i];
27845
- var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
27846
- destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
27847
- }
27848
- target.bones = destBones;
27849
- }
27850
- };
27851
- _create_class$2(Skin, [
27852
- {
27853
- key: "rootBone",
27854
- get: /**
27855
- * Root bone.
27856
- */ function get() {
27857
- return this._rootBone;
27858
- },
27859
- set: function set(value) {
27860
- if (this._rootBone !== value) {
27861
- this._updatedManager.dispatch(1, value);
27862
- this._rootBone = value;
27863
- }
27864
- }
27865
- },
27866
- {
27867
- key: "bones",
27868
- get: /**
27869
- * Bones of the skin.
27870
- */ function get() {
27871
- return this._bones;
27872
- },
27873
- set: function set(value) {
27874
- var bones = this._bones;
27875
- var _value_length;
27876
- var boneCount = (_value_length = value == null ? void 0 : value.length) != null ? _value_length : 0;
27877
- var lastBoneCount = bones.length;
27878
- bones.length = boneCount;
27879
- for(var i = 0; i < boneCount; i++){
27880
- bones[i] = value[i];
27881
- }
27882
- if (lastBoneCount !== boneCount) {
27883
- this._skinMatrices = new Float32Array(boneCount * 16);
27884
- this._updatedManager.dispatch(0, boneCount);
27885
- }
27886
- }
27887
- },
27888
- {
27889
- key: "skeleton",
27890
- get: /** @deprecated Please use `rootBone` instead. */ function get() {
27891
- var _this_rootBone;
27892
- return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
27893
- },
27894
- set: function set(value) {
27895
- var rootBone = this._rootBone;
27896
- if (rootBone) {
27897
- rootBone.name = value;
27898
- }
27899
- }
27900
- }
27901
- ]);
27902
- return Skin;
27903
- }(EngineObject);
27904
- __decorate$1([
27905
- deepClone
27906
- ], Skin.prototype, "inverseBindMatrices", void 0);
27907
- __decorate$1([
27908
- ignoreClone
27909
- ], Skin.prototype, "_skinMatrices", void 0);
27910
- __decorate$1([
27911
- ignoreClone
27912
- ], Skin.prototype, "_updatedManager", void 0);
27913
- __decorate$1([
27914
- ignoreClone
27915
- ], Skin.prototype, "_rootBone", void 0);
27916
- __decorate$1([
27917
- ignoreClone
27918
- ], Skin.prototype, "_bones", void 0);
27919
- __decorate$1([
27920
- ignoreClone
27921
- ], Skin.prototype, "_updateMark", void 0);
27922
- var SkinUpdateFlag = /*#__PURE__*/ function(SkinUpdateFlag) {
27923
- SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
27924
- SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
27925
- return SkinUpdateFlag;
27926
- }({});
27927
- /**
27928
- * SkinnedMeshRenderer.
27929
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer) {
27930
- _inherits$2(SkinnedMeshRenderer, MeshRenderer);
27931
- function SkinnedMeshRenderer(entity) {
27932
- var _this;
27933
- _this = MeshRenderer.call(this, entity) || this, _this._localBounds = new BoundingBox(), _this._jointDataCreateCache = new Vector2(-1, -1);
27934
- _this._skin = null;
27935
- var rhi = _this.entity.engine._hardwareRenderer;
27936
- var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
27937
- // Limit size to 256 to avoid some problem:
27938
- // For renderer is "Apple GPU", when uniform is large than 256 the skeleton matrix array access in shader very slow in Safari or WKWebview. This may be a apple bug, Chrome and Firefox is OK!
27939
- // For renderer is "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3011 vs_5_0 ps_5_0, D3011)", compile shader si very slow because of max uniform is 4096.
27940
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
27941
- _this._maxVertexUniformVectors = maxVertexUniformVectors;
27942
- _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_this);
27943
- _this._onSkinUpdated = _this._onSkinUpdated.bind(_this);
27944
- var localBounds = _this._localBounds;
27945
- // @ts-ignore
27946
- localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
27947
- // @ts-ignore
27948
- localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
27949
- return _this;
27950
- }
27951
- var _proto = SkinnedMeshRenderer.prototype;
27952
- /**
27953
- * @internal
27954
- */ _proto._onDestroy = function _onDestroy() {
27955
- var _this__jointTexture;
27956
- MeshRenderer.prototype._onDestroy.call(this);
27957
- this._jointDataCreateCache = null;
27958
- this._skin = null;
27959
- this._blendShapeWeights = null;
27960
- this._localBounds = null;
27961
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27962
- this._jointTexture = null;
27963
- };
27964
- /**
27965
- * @internal
27966
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
27967
- MeshRenderer.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
27968
- if (this.skin) {
27969
- target._applySkin(null, target.skin);
27970
- }
27971
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
27972
- };
27973
- _proto._update = function _update(context) {
27974
- var skin = this.skin;
27975
- if ((skin == null ? void 0 : skin.bones.length) > 0) {
27976
- skin._updateSkinMatrices(this);
27977
- }
27978
- var shaderData = this.shaderData;
27979
- var mesh = this.mesh;
27980
- var blendShapeManager = mesh._blendShapeManager;
27981
- blendShapeManager._updateShaderData(shaderData, this);
27982
- var bones = skin == null ? void 0 : skin.bones;
27983
- if (bones) {
27984
- var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
27985
- var boneCount = bones.length;
27986
- var boneDataCreateCache = this._jointDataCreateCache;
27987
- var boneCountChange = boneCount !== boneDataCreateCache.x;
27988
- if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
27989
- // directly use max joint count to avoid shader recompile
27990
- var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (SkinnedMeshRenderer._baseVertexUniformVectorCount + bsUniformOccupiesCount)) / 4);
27991
- if (boneCount > remainUniformJointCount) {
27992
- var engine = this.engine;
27993
- if (engine._hardwareRenderer.canIUseMoreJoints) {
27994
- if (boneCountChange) {
27995
- var _this__jointTexture;
27996
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
27997
- this._jointTexture = new Texture2D(engine, 4, boneCount, TextureFormat.R32G32B32A32, false, false);
27998
- this._jointTexture.filterMode = TextureFilterMode.Point;
27999
- this._jointTexture.isGCIgnored = true;
28000
- }
28001
- shaderData.disableMacro("RENDERER_JOINTS_NUM");
28002
- shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
28003
- shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
28004
- } else {
28005
- Logger.error("component's joints count(" + boneCount + ") greater than device's MAX_VERTEX_UNIFORM_VECTORS number " + this._maxVertexUniformVectors + ", and don't support jointTexture in this device. suggest joint count less than " + remainUniformJointCount + ".", this);
28006
- }
28007
- } else {
28008
- var _this__jointTexture1;
28009
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
28010
- shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
28011
- shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
28012
- shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
28013
- }
28014
- boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
28015
- }
28016
- if (this._jointTexture) {
28017
- this._jointTexture.setPixelBuffer(skin._skinMatrices);
28018
- }
28019
- }
28020
- MeshRenderer.prototype._update.call(this, context);
28021
- };
28022
- /**
28023
- * @internal
28024
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
28025
- var _this_skin;
28026
- var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
28027
- if (rootBone) {
28028
- BoundingBox.transform(this._localBounds, this._transformEntity.transform.worldMatrix, worldBounds);
28029
- } else {
28030
- MeshRenderer.prototype._updateBounds.call(this, worldBounds);
28031
- }
28032
- };
28033
- _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
28034
- var mesh = this._mesh;
28035
- var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
28036
- var lastBlendShapeWeights = this._blendShapeWeights;
28037
- if (lastBlendShapeWeights) {
28038
- var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
28039
- if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
28040
- var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
28041
- if (newBlendShapeCount > lastBlendShapeWeightsCount) {
28042
- newBlendShapeWeights.set(lastBlendShapeWeights);
28043
- } else {
28044
- for(var i = 0; i < newBlendShapeCount; i++){
28045
- newBlendShapeWeights[i] = lastBlendShapeWeights[i];
28046
- }
28047
- }
28048
- this._blendShapeWeights = newBlendShapeWeights;
28049
- }
28050
- } else {
28051
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
28052
- }
28053
- };
28054
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
28055
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
28056
- };
28057
- _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
28058
- switch(type){
28059
- case SkinUpdateFlag.BoneCountChanged:
28060
- var shaderData = this.shaderData;
28061
- if (value > 0) {
28062
- shaderData.enableMacro("RENDERER_HAS_SKIN");
28063
- shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
28064
- } else {
28065
- shaderData.disableMacro("RENDERER_HAS_SKIN");
28066
- }
28067
- break;
28068
- case SkinUpdateFlag.RootBoneChanged:
28069
- this._setTransformEntity(value);
28070
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
28071
- break;
28072
- }
28073
- };
28074
- _proto._applySkin = function _applySkin(lastSkin, value) {
28075
- var _lastSkin_bones, _value_bones;
28076
- var _lastSkin_bones_length;
28077
- var lastSkinBoneCount = (_lastSkin_bones_length = lastSkin == null ? void 0 : (_lastSkin_bones = lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
28078
- var _lastSkin_rootBone;
28079
- var lastRootBone = (_lastSkin_rootBone = lastSkin == null ? void 0 : lastSkin.rootBone) != null ? _lastSkin_rootBone : this.entity;
28080
- lastSkin == null ? void 0 : lastSkin._updatedManager.removeListener(this._onSkinUpdated);
28081
- var _value_bones_length;
28082
- var skinBoneCount = (_value_bones_length = value == null ? void 0 : (_value_bones = value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
28083
- var _value_rootBone;
28084
- var rootBone = (_value_rootBone = value == null ? void 0 : value.rootBone) != null ? _value_rootBone : this.entity;
28085
- value == null ? void 0 : value._updatedManager.addListener(this._onSkinUpdated);
28086
- if (lastSkinBoneCount !== skinBoneCount) {
28087
- this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
28338
+ /**
28339
+ * @internal
28340
+ */ Entity._removeFromChildren = function _removeFromChildren(children, entity) {
28341
+ var count = children.length - 1;
28342
+ for(var i = entity._siblingIndex; i < count; i++){
28343
+ var child = children[i + 1];
28344
+ children[i] = child;
28345
+ child._siblingIndex = i;
28088
28346
  }
28089
- if (lastRootBone !== rootBone) {
28090
- this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
28347
+ children.length = count;
28348
+ entity._siblingIndex = -1;
28349
+ };
28350
+ /**
28351
+ * @internal
28352
+ */ Entity._addToChildren = function _addToChildren(children, entity, index) {
28353
+ var childCount = children.length;
28354
+ children.length = childCount + 1;
28355
+ if (index === undefined) {
28356
+ children[childCount] = entity;
28357
+ entity._siblingIndex = childCount;
28358
+ } else {
28359
+ if (index < 0 || index > childCount) {
28360
+ throw "The index " + index + " is out of child list bounds " + childCount;
28361
+ }
28362
+ for(var i = childCount; i > index; i--){
28363
+ var swapChild = children[i - 1];
28364
+ swapChild._siblingIndex = i;
28365
+ children[i] = swapChild;
28366
+ }
28367
+ entity._siblingIndex = index;
28368
+ children[index] = entity;
28091
28369
  }
28092
28370
  };
28093
- _create_class$2(SkinnedMeshRenderer, [
28371
+ _create_class$2(Entity, [
28094
28372
  {
28095
- key: "skin",
28373
+ key: "transform",
28096
28374
  get: /**
28097
- * Skin of the SkinnedMeshRenderer.
28375
+ * The transform of this entity.
28098
28376
  */ function get() {
28099
- return this._skin;
28100
- },
28101
- set: function set(value) {
28102
- var lastSkin = this._skin;
28103
- if (lastSkin !== value) {
28104
- this._applySkin(lastSkin, value);
28105
- this._skin = value;
28106
- }
28377
+ return this._transform;
28107
28378
  }
28108
28379
  },
28109
28380
  {
28110
- key: "blendShapeWeights",
28381
+ key: "isActive",
28111
28382
  get: /**
28112
- * The weights of the BlendShapes.
28113
- * @remarks Array index is BlendShape index.
28383
+ * Whether to activate locally.
28114
28384
  */ function get() {
28115
- this._checkBlendShapeWeightLength();
28116
- return this._blendShapeWeights;
28385
+ return this._isActive;
28117
28386
  },
28118
28387
  set: function set(value) {
28119
- this._checkBlendShapeWeightLength();
28120
- var blendShapeWeights = this._blendShapeWeights;
28121
- if (value.length <= blendShapeWeights.length) {
28122
- blendShapeWeights.set(value);
28123
- } else {
28124
- for(var i = 0, n = blendShapeWeights.length; i < n; i++){
28125
- blendShapeWeights[i] = value[i];
28388
+ if (value !== this._isActive) {
28389
+ this._isActive = value;
28390
+ if (value) {
28391
+ var parent = this._parent;
28392
+ var activeChangeFlag = ActiveChangeFlag.None;
28393
+ if (this._isRoot && this._scene._isActiveInEngine) {
28394
+ activeChangeFlag |= ActiveChangeFlag.All;
28395
+ } else {
28396
+ (parent == null ? void 0 : parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
28397
+ (parent == null ? void 0 : parent._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
28398
+ }
28399
+ activeChangeFlag && this._processActive(activeChangeFlag);
28400
+ } else {
28401
+ var activeChangeFlag1 = ActiveChangeFlag.None;
28402
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
28403
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
28404
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
28126
28405
  }
28127
28406
  }
28128
28407
  }
28129
28408
  },
28130
28409
  {
28131
- key: "localBounds",
28410
+ key: "isActiveInHierarchy",
28132
28411
  get: /**
28133
- * Local bounds.
28412
+ * Whether it is active in the hierarchy.
28134
28413
  */ function get() {
28135
- return this._localBounds;
28136
- },
28137
- set: function set(value) {
28138
- if (this._localBounds !== value) {
28139
- this._localBounds.copyFrom(value);
28140
- }
28414
+ return this._isActiveInHierarchy;
28141
28415
  }
28142
28416
  },
28143
28417
  {
28144
- key: "rootBone",
28418
+ key: "parent",
28145
28419
  get: /**
28146
- * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
28420
+ * The parent entity.
28147
28421
  */ function get() {
28148
- return this.skin.rootBone;
28422
+ return this._parent;
28149
28423
  },
28150
28424
  set: function set(value) {
28151
- this.skin.rootBone = value;
28425
+ this._setParent(value);
28152
28426
  }
28153
28427
  },
28154
28428
  {
28155
- key: "bones",
28429
+ key: "children",
28156
28430
  get: /**
28157
- * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
28431
+ * The children entities
28158
28432
  */ function get() {
28159
- return this.skin.bones;
28160
- },
28161
- set: function set(value) {
28162
- this.skin.bones = value;
28163
- }
28164
- }
28165
- ]);
28166
- return SkinnedMeshRenderer;
28167
- }(MeshRenderer);
28168
- // @TODO: different shader type should use different count, not always 48
28169
- /** @internal */ SkinnedMeshRenderer._baseVertexUniformVectorCount = 48;
28170
- SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
28171
- SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
28172
- SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
28173
- __decorate$1([
28174
- ignoreClone
28175
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
28176
- __decorate$1([
28177
- deepClone
28178
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
28179
- __decorate$1([
28180
- ignoreClone
28181
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
28182
- __decorate$1([
28183
- ignoreClone
28184
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
28185
- __decorate$1([
28186
- ignoreClone
28187
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
28188
- __decorate$1([
28189
- ignoreClone
28190
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
28191
- __decorate$1([
28192
- deepClone
28193
- ], SkinnedMeshRenderer.prototype, "_skin", void 0);
28194
- __decorate$1([
28195
- ignoreClone
28196
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
28197
- __decorate$1([
28198
- ignoreClone
28199
- ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
28200
- /**
28201
- * @internal
28202
- */ var BasicResources = /*#__PURE__*/ function() {
28203
- function BasicResources(engine) {
28204
- this.engine = engine;
28205
- // prettier-ignore
28206
- var vertices = new Float32Array([
28207
- -1,
28208
- -1,
28209
- 0,
28210
- 1,
28211
- 3,
28212
- -1,
28213
- 2,
28214
- 1,
28215
- -1,
28216
- 3,
28217
- 0,
28218
- -1
28219
- ]); // left-top
28220
- // prettier-ignore
28221
- var flipYVertices = new Float32Array([
28222
- 3,
28223
- -1,
28224
- 2,
28225
- 0,
28226
- -1,
28227
- -1,
28228
- 0,
28229
- 0,
28230
- -1,
28231
- 3,
28232
- 0,
28233
- 2
28234
- ]); // left-top
28235
- var blitMaterial = new Material(engine, Shader.find("blit"));
28236
- blitMaterial._addReferCount(1);
28237
- blitMaterial.renderState.depthState.enabled = false;
28238
- blitMaterial.renderState.depthState.writeEnabled = false;
28239
- var blitScreenMaterial = new Material(engine, Shader.find("blit-screen"));
28240
- blitScreenMaterial._addReferCount(1);
28241
- blitScreenMaterial.renderState.depthState.enabled = false;
28242
- blitScreenMaterial.renderState.depthState.writeEnabled = false;
28243
- this.blitMaterial = blitMaterial;
28244
- this.blitScreenMaterial = blitScreenMaterial;
28245
- this.blitMesh = this._createBlitMesh(engine, vertices);
28246
- this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
28247
- // Create white and magenta textures
28248
- var whitePixel = new Uint8Array([
28249
- 255,
28250
- 255,
28251
- 255,
28252
- 255
28253
- ]);
28254
- this.whiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R8G8B8A8, whitePixel, true);
28255
- this.whiteTextureCube = this._create1x1Texture(engine, 1, TextureFormat.R8G8B8A8, whitePixel, true);
28256
- var isWebGL2 = engine._hardwareRenderer.isWebGL2;
28257
- if (isWebGL2) {
28258
- this.whiteTexture2DArray = this._create1x1Texture(engine, 2, TextureFormat.R8G8B8A8, whitePixel, true);
28259
- var whitePixel32 = new Uint32Array([
28260
- 255,
28261
- 255,
28262
- 255,
28263
- 255
28264
- ]);
28265
- this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, TextureFormat.R32G32B32A32_UInt, whitePixel32, false);
28266
- }
28267
- this.spriteDefaultMaterial = this._create2DMaterial(engine, Shader.find("Sprite"));
28268
- this.textDefaultMaterial = this._create2DMaterial(engine, Shader.find("Text"));
28269
- this.spriteMaskDefaultMaterial = this._createSpriteMaskMaterial(engine);
28270
- this.meshMagentaMaterial = this._createMagentaMaterial(engine, "unlit");
28271
- this.particleMagentaMaterial = this._createMagentaMaterial(engine, "particle-shader");
28272
- }
28273
- var _proto = BasicResources.prototype;
28274
- /**
28275
- * @internal
28276
- */ _proto._getBlinnPhongMaterial = function _getBlinnPhongMaterial() {
28277
- return this._blinnPhongMaterial || (this._blinnPhongMaterial = new BlinnPhongMaterial(this.engine));
28278
- };
28279
- /**
28280
- * @internal
28281
- */ _proto._initialize = function _initialize() {
28282
- var _this = this;
28283
- return new Promise(function(resolve, reject) {
28284
- PrefilteredDFG.create(_this.engine).then(function(texture) {
28285
- _this._prefilteredDFGTexture = texture;
28286
- resolve(_this);
28287
- }).catch(reject);
28288
- });
28289
- };
28290
- _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
28291
- var mesh = new ModelMesh(engine);
28292
- mesh._addReferCount(1);
28293
- mesh.setVertexElements([
28294
- new VertexElement("POSITION_UV", 0, VertexElementFormat.Vector4, 0)
28295
- ]);
28296
- var buffer = new Buffer(engine, BufferBindFlag.VertexBuffer, vertices, BufferUsage.Static, true);
28297
- mesh.setVertexBufferBinding(buffer, 16);
28298
- mesh.addSubMesh(0, 3, MeshTopology.Triangles);
28299
- engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
28300
- _inherits$2(_class, ContentRestorer);
28301
- function _class() {
28302
- return ContentRestorer.call(this, mesh) || this;
28303
- }
28304
- var _proto = _class.prototype;
28305
- _proto.restoreContent = function restoreContent() {
28306
- buffer.setData(buffer.data);
28307
- };
28308
- return _class;
28309
- }(ContentRestorer))());
28310
- return mesh;
28311
- };
28312
- _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel, isSRGBColorSpace) {
28313
- var texture;
28314
- switch(type){
28315
- case 0:
28316
- var texture2D = new Texture2D(engine, 1, 1, format, false, isSRGBColorSpace);
28317
- texture2D.setPixelBuffer(pixel);
28318
- texture = texture2D;
28319
- break;
28320
- case 2:
28321
- var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false, isSRGBColorSpace);
28322
- texture2DArray.setPixelBuffer(0, pixel);
28323
- texture = texture2DArray;
28324
- break;
28325
- case 1:
28326
- var textureCube = new TextureCube(engine, 1, format, false, isSRGBColorSpace);
28327
- for(var i = 0; i < 6; i++){
28328
- textureCube.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
28329
- }
28330
- texture = textureCube;
28331
- break;
28332
- default:
28333
- throw "Invalid texture type";
28334
- }
28335
- texture.isGCIgnored = true;
28336
- engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
28337
- _inherits$2(_class, ContentRestorer);
28338
- function _class() {
28339
- return ContentRestorer.call(this, texture) || this;
28340
- }
28341
- var _proto = _class.prototype;
28342
- _proto.restoreContent = function restoreContent() {
28343
- switch(type){
28344
- case 0:
28345
- this.resource.setPixelBuffer(pixel);
28346
- break;
28347
- case 2:
28348
- this.resource.setPixelBuffer(0, pixel);
28349
- break;
28350
- case 1:
28351
- for(var i = 0; i < 6; i++){
28352
- this.resource.setPixelBuffer(TextureCubeFace.PositiveX + i, pixel);
28353
- }
28354
- break;
28355
- }
28356
- };
28357
- return _class;
28358
- }(ContentRestorer))());
28359
- return texture;
28360
- };
28361
- _proto._create2DMaterial = function _create2DMaterial(engine, shader) {
28362
- var material = new Material(engine, shader);
28363
- var renderState = material.renderState;
28364
- var target = renderState.blendState.targetBlendState;
28365
- target.enabled = true;
28366
- target.sourceColorBlendFactor = BlendFactor.SourceAlpha;
28367
- target.destinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
28368
- target.sourceAlphaBlendFactor = BlendFactor.One;
28369
- target.destinationAlphaBlendFactor = BlendFactor.OneMinusSourceAlpha;
28370
- target.colorBlendOperation = target.alphaBlendOperation = BlendOperation.Add;
28371
- renderState.depthState.writeEnabled = false;
28372
- renderState.rasterState.cullMode = CullMode.Off;
28373
- renderState.renderQueueType = RenderQueueType.Transparent;
28374
- material.isGCIgnored = true;
28375
- return material;
28376
- };
28377
- _proto._createMagentaMaterial = function _createMagentaMaterial(engine, shaderName) {
28378
- var material = new Material(engine, Shader.find(shaderName));
28379
- material.isGCIgnored = true;
28380
- material.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
28381
- return material;
28382
- };
28383
- _proto._createSpriteMaskMaterial = function _createSpriteMaskMaterial(engine) {
28384
- var material = new Material(engine, Shader.find("SpriteMask"));
28385
- material.isGCIgnored = true;
28386
- return material;
28387
- };
28388
- BasicResources.getMaskInteractionRenderStates = function getMaskInteractionRenderStates(maskInteraction) {
28389
- var visibleInsideMask = maskInteraction === SpriteMaskInteraction.VisibleInsideMask;
28390
- var renderStates;
28391
- var compareFunction;
28392
- if (visibleInsideMask) {
28393
- renderStates = BasicResources._maskReadInsideRenderStates;
28394
- if (renderStates) {
28395
- return renderStates;
28396
- }
28397
- BasicResources._maskReadInsideRenderStates = renderStates = {};
28398
- compareFunction = CompareFunction.LessEqual;
28399
- } else {
28400
- renderStates = BasicResources._maskReadOutsideRenderStates;
28401
- if (renderStates) {
28402
- return renderStates;
28433
+ return this._children;
28403
28434
  }
28404
- BasicResources._maskReadOutsideRenderStates = renderStates = {};
28405
- compareFunction = CompareFunction.Greater;
28406
- }
28407
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
28408
- renderStates[RenderStateElementKey.StencilStateWriteMask] = 0x00;
28409
- renderStates[RenderStateElementKey.StencilStateReferenceValue] = 1;
28410
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = compareFunction;
28411
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = compareFunction;
28412
- return renderStates;
28413
- };
28414
- BasicResources.getMaskTypeRenderStates = function getMaskTypeRenderStates(maskType) {
28415
- var isIncrement = maskType === RenderQueueMaskType.Increment;
28416
- var renderStates;
28417
- var passOperation;
28418
- if (isIncrement) {
28419
- renderStates = BasicResources._maskWriteIncrementRenderStates;
28420
- if (renderStates) {
28421
- return renderStates;
28435
+ },
28436
+ {
28437
+ key: "childCount",
28438
+ get: /**
28439
+ * @deprecated Please use `children.length` property instead.
28440
+ * Number of the children entities
28441
+ */ function get() {
28442
+ return this._children.length;
28422
28443
  }
28423
- BasicResources._maskWriteIncrementRenderStates = renderStates = {};
28424
- passOperation = StencilOperation.IncrementSaturate;
28425
- } else {
28426
- renderStates = BasicResources._maskWriteDecrementRenderStates;
28427
- if (renderStates) {
28428
- return renderStates;
28444
+ },
28445
+ {
28446
+ key: "scene",
28447
+ get: /**
28448
+ * The scene the entity belongs to.
28449
+ */ function get() {
28450
+ return this._scene;
28429
28451
  }
28430
- BasicResources._maskWriteDecrementRenderStates = renderStates = {};
28431
- passOperation = StencilOperation.DecrementSaturate;
28432
- }
28433
- renderStates[RenderStateElementKey.StencilStateEnabled] = true;
28434
- renderStates[RenderStateElementKey.StencilStatePassOperationFront] = passOperation;
28435
- renderStates[RenderStateElementKey.StencilStatePassOperationBack] = passOperation;
28436
- renderStates[RenderStateElementKey.StencilStateCompareFunctionFront] = CompareFunction.Always;
28437
- renderStates[RenderStateElementKey.StencilStateCompareFunctionBack] = CompareFunction.Always;
28438
- var failStencilOperation = StencilOperation.Keep;
28439
- renderStates[RenderStateElementKey.StencilStateFailOperationFront] = failStencilOperation;
28440
- renderStates[RenderStateElementKey.StencilStateFailOperationBack] = failStencilOperation;
28441
- renderStates[RenderStateElementKey.StencilStateZFailOperationFront] = failStencilOperation;
28442
- renderStates[RenderStateElementKey.StencilStateZFailOperationBack] = failStencilOperation;
28443
- renderStates[RenderStateElementKey.BlendStateColorWriteMask0] = ColorWriteMask.None;
28444
- renderStates[RenderStateElementKey.DepthStateEnabled] = false;
28445
- renderStates[RenderStateElementKey.RasterStateCullMode] = CullMode.Off;
28446
- return renderStates;
28447
- };
28448
- _create_class$2(BasicResources, [
28452
+ },
28449
28453
  {
28450
- key: "prefilteredDFGTexture",
28451
- get: function get() {
28452
- return this._prefilteredDFGTexture;
28454
+ key: "siblingIndex",
28455
+ get: /**
28456
+ * The sibling index.
28457
+ */ function get() {
28458
+ return this._siblingIndex;
28459
+ },
28460
+ set: function set(value) {
28461
+ if (this._siblingIndex === -1) {
28462
+ throw "The entity " + this.name + " is not in the hierarchy";
28463
+ }
28464
+ if (this._isRoot) {
28465
+ this._setSiblingIndex(this._scene._rootEntities, value);
28466
+ } else {
28467
+ var parent = this._parent;
28468
+ this._setSiblingIndex(parent._children, value);
28469
+ parent._dispatchModify(EntityModifyFlags.Child, parent);
28470
+ }
28453
28471
  }
28454
28472
  }
28455
28473
  ]);
28456
- return BasicResources;
28457
- }();
28458
- BasicResources._maskReadInsideRenderStates = null;
28459
- BasicResources._maskReadOutsideRenderStates = null;
28460
- BasicResources._maskWriteIncrementRenderStates = null;
28461
- BasicResources._maskWriteDecrementRenderStates = null;
28474
+ return Entity;
28475
+ }(EngineObject);
28476
+ /** @internal */ Entity._tempComponentConstructors = [];
28462
28477
  var ObjectPool = /*#__PURE__*/ function() {
28463
28478
  function ObjectPool(type) {
28464
28479
  this._type = type;
@@ -33735,6 +33750,183 @@
33735
33750
  PointerMethods["onPointerDrop"] = "onPointerDrop";
33736
33751
  return PointerMethods;
33737
33752
  }({});
33753
+ /**
33754
+ * Signal is a typed event mechanism for Galacean Engine.
33755
+ * @typeParam T - Tuple type of the signal arguments
33756
+ */ var Signal = /*#__PURE__*/ function() {
33757
+ function Signal() {
33758
+ this._listeners = new SafeLoopArray();
33759
+ }
33760
+ var _proto = Signal.prototype;
33761
+ _proto.on = function on(fnOrTarget, targetOrMethodName) {
33762
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
33763
+ args[_key - 2] = arguments[_key];
33764
+ }
33765
+ this._addListener.apply(this, [].concat([
33766
+ fnOrTarget,
33767
+ targetOrMethodName,
33768
+ false
33769
+ ], args));
33770
+ };
33771
+ _proto.once = function once(fnOrTarget, targetOrMethodName) {
33772
+ for(var _len = arguments.length, args = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++){
33773
+ args[_key - 2] = arguments[_key];
33774
+ }
33775
+ this._addListener.apply(this, [].concat([
33776
+ fnOrTarget,
33777
+ targetOrMethodName,
33778
+ true
33779
+ ], args));
33780
+ };
33781
+ _proto.off = function off(fnOrTarget, targetOrMethodName) {
33782
+ if (typeof fnOrTarget === "function") {
33783
+ var target = targetOrMethodName != null ? targetOrMethodName : null;
33784
+ this._listeners.findAndRemove(function(listener) {
33785
+ if (listener.fn === fnOrTarget && listener.target === target) {
33786
+ listener.destroyed = true;
33787
+ return true;
33788
+ }
33789
+ return false;
33790
+ });
33791
+ } else {
33792
+ var target1 = fnOrTarget;
33793
+ var methodName = targetOrMethodName;
33794
+ this._listeners.findAndRemove(function(listener) {
33795
+ if (listener.target === target1 && listener.methodName === methodName) {
33796
+ listener.destroyed = true;
33797
+ return true;
33798
+ }
33799
+ return false;
33800
+ });
33801
+ }
33802
+ };
33803
+ /**
33804
+ * Remove all listeners, or all listeners for a specific target.
33805
+ * @param target - If provided, only remove listeners bound to this target
33806
+ */ _proto.removeAll = function removeAll(target) {
33807
+ if (target !== undefined) {
33808
+ this._listeners.findAndRemove(function(listener) {
33809
+ if (listener.target === target) {
33810
+ return listener.destroyed = true;
33811
+ }
33812
+ return false;
33813
+ });
33814
+ } else {
33815
+ this._listeners.findAndRemove(function(listener) {
33816
+ return listener.destroyed = true;
33817
+ });
33818
+ }
33819
+ };
33820
+ /**
33821
+ * Invoke the signal, calling all listeners in order.
33822
+ * @param args - Arguments to pass to each listener
33823
+ */ _proto.invoke = function invoke() {
33824
+ var _this, _loop = function _loop(i, n) {
33825
+ var listener = listeners[i];
33826
+ if (listener.destroyed) return "continue";
33827
+ if (listener.methodName && listener.target.destroyed) {
33828
+ listener.destroyed = true;
33829
+ _this._listeners.findAndRemove(function(l) {
33830
+ return l === listener;
33831
+ });
33832
+ return "continue";
33833
+ }
33834
+ listener.fn.apply(listener.target, args);
33835
+ if (listener.once) {
33836
+ listener.destroyed = true;
33837
+ _this._listeners.findAndRemove(function(l) {
33838
+ return l === listener;
33839
+ });
33840
+ }
33841
+ };
33842
+ for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
33843
+ args[_key] = arguments[_key];
33844
+ }
33845
+ var listeners = this._listeners.getLoopArray();
33846
+ for(var i = 0, n = listeners.length; i < n; i++)_this = this, _loop(i);
33847
+ };
33848
+ /**
33849
+ * @internal
33850
+ * Clone listeners to target signal, remapping entity/component references.
33851
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
33852
+ var listeners = this._listeners.getLoopArray();
33853
+ for(var i = 0, n = listeners.length; i < n; i++){
33854
+ var listener = listeners[i];
33855
+ if (listener.destroyed || !listener.methodName) continue;
33856
+ var clonedTarget = CloneUtils.remapComponent(srcRoot, targetRoot, listener.target);
33857
+ if (clonedTarget) {
33858
+ var clonedArgs = this._cloneArguments(listener.arguments, srcRoot, targetRoot);
33859
+ if (listener.once) {
33860
+ var _target;
33861
+ (_target = target).once.apply(_target, [].concat([
33862
+ clonedTarget,
33863
+ listener.methodName
33864
+ ], clonedArgs));
33865
+ } else {
33866
+ var _target1;
33867
+ (_target1 = target).on.apply(_target1, [].concat([
33868
+ clonedTarget,
33869
+ listener.methodName
33870
+ ], clonedArgs));
33871
+ }
33872
+ }
33873
+ }
33874
+ };
33875
+ _proto._cloneArguments = function _cloneArguments(args, srcRoot, targetRoot) {
33876
+ if (!args || args.length === 0) return [];
33877
+ var len = args.length;
33878
+ var clonedArgs = new Array(len);
33879
+ for(var i = 0; i < len; i++){
33880
+ var arg = args[i];
33881
+ if (_instanceof1$2(arg, Entity)) {
33882
+ clonedArgs[i] = CloneUtils.remapEntity(srcRoot, targetRoot, arg);
33883
+ } else if (_instanceof1$2(arg, Component)) {
33884
+ clonedArgs[i] = CloneUtils.remapComponent(srcRoot, targetRoot, arg);
33885
+ } else {
33886
+ clonedArgs[i] = arg;
33887
+ }
33888
+ }
33889
+ return clonedArgs;
33890
+ };
33891
+ _proto._addListener = function _addListener(fnOrTarget, targetOrMethodName, once) {
33892
+ for(var _len = arguments.length, args = new Array(_len > 3 ? _len - 3 : 0), _key = 3; _key < _len; _key++){
33893
+ args[_key - 3] = arguments[_key];
33894
+ }
33895
+ if (typeof fnOrTarget === "function") {
33896
+ this._listeners.push({
33897
+ fn: fnOrTarget,
33898
+ target: targetOrMethodName != null ? targetOrMethodName : null,
33899
+ once: once
33900
+ });
33901
+ } else {
33902
+ var _target, _target1;
33903
+ var target = fnOrTarget;
33904
+ var methodName = targetOrMethodName;
33905
+ var fn = args.length > 0 ? function fn() {
33906
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
33907
+ signalArgs[_key] = arguments[_key];
33908
+ }
33909
+ return (_target = target)[methodName].apply(_target, [].concat(args, signalArgs));
33910
+ } : function() {
33911
+ for(var _len = arguments.length, signalArgs = new Array(_len), _key = 0; _key < _len; _key++){
33912
+ signalArgs[_key] = arguments[_key];
33913
+ }
33914
+ return (_target1 = target)[methodName].apply(_target1, [].concat(signalArgs));
33915
+ };
33916
+ this._listeners.push({
33917
+ fn: fn,
33918
+ target: target,
33919
+ once: once,
33920
+ methodName: methodName,
33921
+ arguments: args
33922
+ });
33923
+ }
33924
+ };
33925
+ return Signal;
33926
+ }();
33927
+ __decorate$1([
33928
+ ignoreClone
33929
+ ], Signal.prototype, "_listeners", void 0);
33738
33930
  /**
33739
33931
  * Loader abstract class.
33740
33932
  */ var Loader = /*#__PURE__*/ function() {
@@ -43009,6 +43201,7 @@
43009
43201
  CircleShape: CircleShape,
43010
43202
  ClearableObjectPool: ClearableObjectPool,
43011
43203
  CloneManager: CloneManager,
43204
+ CloneUtils: CloneUtils,
43012
43205
  get Collider () { return exports.Collider; },
43013
43206
  ColliderShape: ColliderShape,
43014
43207
  ColliderShapeUpAxis: ColliderShapeUpAxis,
@@ -43165,6 +43358,7 @@
43165
43358
  ShadowCascadesMode: ShadowCascadesMode,
43166
43359
  ShadowResolution: ShadowResolution,
43167
43360
  ShadowType: ShadowType,
43361
+ Signal: Signal,
43168
43362
  get SimpleSpriteAssembler () { return exports.SimpleSpriteAssembler; },
43169
43363
  SizeOverLifetimeModule: SizeOverLifetimeModule,
43170
43364
  Skin: Skin,
@@ -46266,6 +46460,29 @@
46266
46460
  }
46267
46461
  });
46268
46462
  };
46463
+ _proto.parseSignal = function parseSignal(signalRef) {
46464
+ var _this = this;
46465
+ var signal = new Signal();
46466
+ return Promise.all(signalRef.listeners.map(function(listener) {
46467
+ return Promise.all([
46468
+ _this.parseBasicType(listener.target),
46469
+ listener.arguments ? Promise.all(listener.arguments.map(function(a) {
46470
+ return _this.parseBasicType(a);
46471
+ })) : Promise.resolve([])
46472
+ ]).then(function(param) {
46473
+ var target = param[0], resolvedArgs = param[1];
46474
+ if (target) {
46475
+ var _signal;
46476
+ (_signal = signal).on.apply(_signal, [].concat([
46477
+ target,
46478
+ listener.methodName
46479
+ ], resolvedArgs));
46480
+ }
46481
+ });
46482
+ })).then(function() {
46483
+ return signal;
46484
+ });
46485
+ };
46269
46486
  _proto.parseBasicType = function parseBasicType(value, originValue) {
46270
46487
  var _this = this;
46271
46488
  if (Array.isArray(value)) {
@@ -46295,6 +46512,8 @@
46295
46512
  } else if (ReflectionParser._isEntityRef(value)) {
46296
46513
  // entity reference
46297
46514
  return Promise.resolve(this._context.entityMap.get(value.entityId));
46515
+ } else if (ReflectionParser._isSignalRef(value)) {
46516
+ return this.parseSignal(value);
46298
46517
  } else if (originValue) {
46299
46518
  var _this2, _loop = function _loop(key) {
46300
46519
  if (key === "methods") {
@@ -46365,6 +46584,9 @@
46365
46584
  ReflectionParser._isComponentRef = function _isComponentRef(value) {
46366
46585
  return value["ownerId"] !== undefined && value["componentId"] !== undefined;
46367
46586
  };
46587
+ ReflectionParser._isSignalRef = function _isSignalRef(value) {
46588
+ return value["listeners"] !== undefined;
46589
+ };
46368
46590
  ReflectionParser._isMethodObject = function _isMethodObject(value) {
46369
46591
  return Array.isArray(value == null ? void 0 : value.params);
46370
46592
  };
@@ -52704,7 +52926,7 @@
52704
52926
  ], EXT_texture_webp);
52705
52927
 
52706
52928
  //@ts-ignore
52707
- var version = "2.0.0-alpha.14";
52929
+ var version = "2.0.0-alpha.15";
52708
52930
  console.log("Galacean Engine Version: " + version);
52709
52931
  for(var key in CoreObjects){
52710
52932
  Loader.registerClass(key, CoreObjects[key]);
@@ -52777,6 +52999,7 @@
52777
52999
  exports.CircleShape = CircleShape;
52778
53000
  exports.ClearableObjectPool = ClearableObjectPool;
52779
53001
  exports.CloneManager = CloneManager;
53002
+ exports.CloneUtils = CloneUtils;
52780
53003
  exports.ColliderShape = ColliderShape;
52781
53004
  exports.ColliderShapeUpAxis = ColliderShapeUpAxis;
52782
53005
  exports.Collision = Collision;
@@ -52962,6 +53185,7 @@
52962
53185
  exports.ShadowCascadesMode = ShadowCascadesMode;
52963
53186
  exports.ShadowResolution = ShadowResolution;
52964
53187
  exports.ShadowType = ShadowType;
53188
+ exports.Signal = Signal;
52965
53189
  exports.SizeOverLifetimeModule = SizeOverLifetimeModule;
52966
53190
  exports.Skin = Skin;
52967
53191
  exports.SkinnedMeshRenderer = SkinnedMeshRenderer;