@galacean/engine-core 1.2.0-beta.3 → 1.2.0-beta.5

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.
@@ -255,7 +255,7 @@ function _instanceof(left, right) {
255
255
  }
256
256
  return cloneModes;
257
257
  };
258
- CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode) {
258
+ CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode, srcRoot, targetRoot, deepInstanceMap) {
259
259
  if (cloneMode === CloneMode.Ignore) {
260
260
  return;
261
261
  }
@@ -291,22 +291,33 @@ function _instanceof(left, right) {
291
291
  targetPropertyA.length = length;
292
292
  }
293
293
  for(var i = 0; i < length; i++){
294
- CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode);
294
+ CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
295
295
  }
296
296
  break;
297
297
  default:
298
- var _target, _k;
299
- var targetOProperty = (_target = target)[_k = k] || (_target[_k] = new sourceProperty.constructor());
300
- var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
301
- for(var _$k in sourceProperty){
302
- CloneManager.cloneProperty(sourceProperty, targetOProperty, _$k, cloneModes[_$k]);
303
- }
304
- // Custom clone
305
- if (sourceProperty._cloneTo) {
306
- sourceProperty._cloneTo(targetOProperty);
298
+ var targetProperty = target[k];
299
+ // If the target property is undefined, create new instance and keep reference sharing like the source
300
+ if (!targetProperty) {
301
+ targetProperty = deepInstanceMap.get(sourceProperty);
302
+ if (!targetProperty) {
303
+ targetProperty = new sourceProperty.constructor();
304
+ deepInstanceMap.set(sourceProperty, targetProperty);
305
+ }
306
+ target[k] = targetProperty;
307
307
  }
308
308
  if (sourceProperty.copyFrom) {
309
- targetOProperty.copyFrom(sourceProperty);
309
+ // Custom clone
310
+ targetProperty.copyFrom(sourceProperty);
311
+ } else {
312
+ // Universal clone
313
+ var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
314
+ for(var _$k in sourceProperty){
315
+ CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
316
+ }
317
+ // Custom incremental clone
318
+ if (sourceProperty._cloneTo) {
319
+ sourceProperty._cloneTo(targetProperty, srcRoot, targetRoot);
320
+ }
310
321
  }
311
322
  break;
312
323
  }
@@ -315,9 +326,9 @@ function _instanceof(left, right) {
315
326
  target[k] = sourceProperty;
316
327
  }
317
328
  };
318
- CloneManager.deepCloneObject = function deepCloneObject(source, target) {
329
+ CloneManager.deepCloneObject = function deepCloneObject(source, target, deepInstanceMap) {
319
330
  for(var k in source){
320
- CloneManager.cloneProperty(source, target, k, CloneMode.Deep);
331
+ CloneManager.cloneProperty(source, target, k, CloneMode.Deep, null, null, deepInstanceMap);
321
332
  }
322
333
  };
323
334
  return CloneManager;
@@ -4941,7 +4952,8 @@ __decorate([
4941
4952
  }
4942
4953
  var shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
4943
4954
  if (shaderMap[shaderInfo.name]) {
4944
- throw 'Shader named "' + shaderInfo.name + '" already exists.';
4955
+ console.error('Shader named "' + shaderInfo.name + '" already exists.');
4956
+ return;
4945
4957
  }
4946
4958
  var subShaderList = shaderInfo.subShaders.map(function(subShaderInfo) {
4947
4959
  var passList = subShaderInfo.passes.map(function(passInfo) {
@@ -4980,7 +4992,8 @@ __decorate([
4980
4992
  return shader;
4981
4993
  } else {
4982
4994
  if (shaderMap[nameOrShaderSource]) {
4983
- throw 'Shader named "' + nameOrShaderSource + '" already exists.';
4995
+ console.error('Shader named "' + nameOrShaderSource + '" already exists.');
4996
+ return;
4984
4997
  }
4985
4998
  if (typeof vertexSourceOrShaderPassesOrSubShaders === "string") {
4986
4999
  var shaderPass = new ShaderPass(vertexSourceOrShaderPassesOrSubShaders, fragmentSource);
@@ -5579,7 +5592,7 @@ var GraphicsResource = /*#__PURE__*/ function(ReferResource1) {
5579
5592
  return shaderData;
5580
5593
  };
5581
5594
  _proto.cloneTo = function cloneTo(target) {
5582
- CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
5595
+ CloneManager.deepCloneObject(this._macroCollection, target._macroCollection, new Map());
5583
5596
  Object.assign(target._macroMap, this._macroMap);
5584
5597
  var referCount = target._getReferCount();
5585
5598
  var propertyValueMap = this._propertyValueMap;
@@ -10959,454 +10972,1191 @@ var PrimitiveType;
10959
10972
  })();
10960
10973
 
10961
10974
  /**
10962
- * Mesh skin data, equal glTF skins define
10963
- */ var Skin = /*#__PURE__*/ function(EngineObject1) {
10964
- _inherits(Skin, EngineObject1);
10965
- function Skin(name) {
10966
- var _this;
10967
- _this = EngineObject1.call(this, null) || this;
10968
- _this.name = name;
10969
- _this._bones = [];
10970
- _this.inverseBindMatrices = []; // inverse bind matrix array
10971
- _this.joints = []; // joints name array, element type: string
10972
- _this.skeleton = "none"; // root bone name
10973
- return _this;
10974
- }
10975
- return Skin;
10976
- }(EngineObject);
10975
+ * Layer, used for bit operations.
10976
+ */ exports.Layer = void 0;
10977
+ (function(Layer) {
10978
+ Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
10979
+ Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
10980
+ Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
10981
+ Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
10982
+ Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
10983
+ Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
10984
+ Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
10985
+ Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
10986
+ Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
10987
+ Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
10988
+ Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
10989
+ Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
10990
+ Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
10991
+ Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
10992
+ Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
10993
+ Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
10994
+ Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
10995
+ Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
10996
+ Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
10997
+ Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
10998
+ Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
10999
+ Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
11000
+ Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
11001
+ Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
11002
+ Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
11003
+ Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
11004
+ Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
11005
+ Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
11006
+ Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
11007
+ Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
11008
+ Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
11009
+ Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
11010
+ Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
11011
+ Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
11012
+ })(exports.Layer || (exports.Layer = {}));
11013
+
11014
+ var ComponentCloner = /*#__PURE__*/ function() {
11015
+ function ComponentCloner() {}
11016
+ /**
11017
+ * Clone component.
11018
+ * @param source - Clone source
11019
+ * @param target - Clone target
11020
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
11021
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
11022
+ for(var k in source){
11023
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
11024
+ }
11025
+ if (source._cloneTo) {
11026
+ source._cloneTo(target, srcRoot, targetRoot);
11027
+ }
11028
+ };
11029
+ return ComponentCloner;
11030
+ }();
10977
11031
 
10978
11032
  /**
10979
- * SkinnedMeshRenderer.
10980
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
10981
- _inherits(SkinnedMeshRenderer, MeshRenderer1);
10982
- function SkinnedMeshRenderer(entity) {
11033
+ * Entity, be used as components container.
11034
+ */ var Entity = /*#__PURE__*/ function(EngineObject1) {
11035
+ _inherits(Entity, EngineObject1);
11036
+ function Entity(engine, name) {
10983
11037
  var _this;
10984
- _this = MeshRenderer1.call(this, entity) || this;
10985
- _this._localBounds = new miniprogram.BoundingBox();
10986
- _this._jointDataCreateCache = new miniprogram.Vector2(-1, -1);
10987
- _this._skin = null;
10988
- var rhi = _this.entity.engine._hardwareRenderer;
10989
- var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
10990
- // Limit size to 256 to avoid some problem:
10991
- // 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!
10992
- // 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.
10993
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
10994
- _this._maxVertexUniformVectors = maxVertexUniformVectors;
10995
- _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
10996
- var localBounds = _this._localBounds;
10997
- // @ts-ignore
10998
- localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
10999
- // @ts-ignore
11000
- localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
11038
+ _this = EngineObject1.call(this, engine) || this;
11039
+ /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
11040
+ /** @internal */ _this._isActiveInHierarchy = false;
11041
+ /** @internal */ _this._isActiveInScene = false;
11042
+ /** @internal */ _this._components = [];
11043
+ /** @internal */ _this._scripts = new DisorderedArray();
11044
+ /** @internal */ _this._children = [];
11045
+ /** @internal */ _this._isRoot = false;
11046
+ /** @internal */ _this._isActive = true;
11047
+ /** @internal */ _this._siblingIndex = -1;
11048
+ /** @internal */ _this._isTemplate = false;
11049
+ _this._parent = null;
11050
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
11051
+ _this._invModelMatrix = new miniprogram.Matrix();
11052
+ _this.name = name;
11053
+ _this.transform = _this.addComponent(Transform);
11054
+ _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
11001
11055
  return _this;
11002
11056
  }
11003
- var _proto = SkinnedMeshRenderer.prototype;
11057
+ var _proto = Entity.prototype;
11004
11058
  /**
11005
- * @internal
11006
- */ _proto.update = function update() {
11007
- var _this = this, skin = _this._skin, bones = _this._bones;
11008
- if (skin && bones) {
11009
- // @todo: can optimize when share skin
11010
- var jointMatrices = this._jointMatrices;
11011
- var bindMatrices = skin.inverseBindMatrices;
11012
- var _this__rootBone;
11013
- var worldToLocal = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this.entity).getInvModelMatrix();
11014
- for(var i = bones.length - 1; i >= 0; i--){
11015
- var bone = bones[i];
11016
- var offset = i * 16;
11017
- if (bone) {
11018
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, jointMatrices, offset);
11019
- } else {
11020
- jointMatrices.set(bindMatrices[i].elements, offset);
11021
- }
11022
- Utils._floatMatrixMultiply(worldToLocal, jointMatrices, offset, jointMatrices, offset);
11059
+ * Add component based on the component type.
11060
+ * @param type - The type of the component
11061
+ * @returns The component which has been added
11062
+ */ _proto.addComponent = function addComponent(type) {
11063
+ ComponentsDependencies._addCheck(this, type);
11064
+ var component = new type(this);
11065
+ this._components.push(component);
11066
+ component._setActive(true, ActiveChangeFlag.All);
11067
+ return component;
11068
+ };
11069
+ /**
11070
+ * Get component which match the type.
11071
+ * @param type - The type of the component
11072
+ * @returns The first component which match type
11073
+ */ _proto.getComponent = function getComponent(type) {
11074
+ var components = this._components;
11075
+ for(var i = 0, n = components.length; i < n; i++){
11076
+ var component = components[i];
11077
+ if (_instanceof(component, type)) {
11078
+ return component;
11023
11079
  }
11024
11080
  }
11081
+ return null;
11025
11082
  };
11026
- _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
11027
- var entity = this.entity;
11028
- var _this__rootBone;
11029
- var worldMatrix = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : entity).transform.worldMatrix;
11030
- if (onlyMVP) {
11031
- this._updateMVPShaderData(context, worldMatrix);
11032
- return;
11083
+ /**
11084
+ * Get components which match the type.
11085
+ * @param type - The type of the component
11086
+ * @param results - The components which match type
11087
+ * @returns The components which match type
11088
+ */ _proto.getComponents = function getComponents(type, results) {
11089
+ results.length = 0;
11090
+ var components = this._components;
11091
+ for(var i = 0, n = components.length; i < n; i++){
11092
+ var component = components[i];
11093
+ if (_instanceof(component, type)) {
11094
+ results.push(component);
11095
+ }
11033
11096
  }
11034
- this._updateTransformShaderData(context, worldMatrix);
11035
- var shaderData = this.shaderData;
11036
- var mesh = this.mesh;
11037
- var blendShapeManager = mesh._blendShapeManager;
11038
- blendShapeManager._updateShaderData(shaderData, this);
11039
- var bones = this._bones;
11040
- if (bones) {
11041
- var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
11042
- var jointCount = bones.length;
11043
- var jointDataCreateCache = this._jointDataCreateCache;
11044
- var jointCountChange = jointCount !== jointDataCreateCache.x;
11045
- if (jointCountChange || bsUniformOccupiesCount !== jointDataCreateCache.y) {
11046
- // directly use max joint count to avoid shader recompile
11047
- // @TODO: different shader type should use different count, not always 44
11048
- var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
11049
- if (jointCount > remainUniformJointCount) {
11050
- var engine = this.engine;
11051
- if (engine._hardwareRenderer.canIUseMoreJoints) {
11052
- if (jointCountChange) {
11053
- var _this__jointTexture;
11054
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
11055
- this._jointTexture = new Texture2D(engine, 4, jointCount, exports.TextureFormat.R32G32B32A32, false);
11056
- this._jointTexture.filterMode = exports.TextureFilterMode.Point;
11057
- this._jointTexture.isGCIgnored = true;
11058
- }
11059
- shaderData.disableMacro("RENDERER_JOINTS_NUM");
11060
- shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
11061
- shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
11062
- } else {
11063
- Logger.error("component's joints count(" + jointCount + ") 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);
11064
- }
11097
+ return results;
11098
+ };
11099
+ /**
11100
+ * Get the components which match the type of the entity and it's children.
11101
+ * @param type - The component type
11102
+ * @param results - The components collection
11103
+ * @returns The components collection which match the type
11104
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
11105
+ results.length = 0;
11106
+ this._getComponentsInChildren(type, results);
11107
+ return results;
11108
+ };
11109
+ _proto.addChild = function addChild(indexOrChild, child) {
11110
+ var index;
11111
+ if (typeof indexOrChild === "number") {
11112
+ index = indexOrChild;
11113
+ } else {
11114
+ index = undefined;
11115
+ child = indexOrChild;
11116
+ }
11117
+ if (child._isRoot) {
11118
+ child._scene._removeFromEntityList(child);
11119
+ child._isRoot = false;
11120
+ this._addToChildrenList(index, child);
11121
+ child._parent = this;
11122
+ var oldScene = child._scene;
11123
+ var newScene = this._scene;
11124
+ var inActiveChangeFlag = ActiveChangeFlag.None;
11125
+ if (!this._isActiveInHierarchy) {
11126
+ child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
11127
+ }
11128
+ if (child._isActiveInScene) {
11129
+ if (this._isActiveInScene) {
11130
+ // Cross scene should inActive first and then active
11131
+ oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
11065
11132
  } else {
11066
- var _this__jointTexture1;
11067
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
11068
- shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
11069
- shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
11070
- shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, this._jointMatrices);
11133
+ inActiveChangeFlag |= ActiveChangeFlag.Scene;
11071
11134
  }
11072
- jointDataCreateCache.set(jointCount, bsUniformOccupiesCount);
11073
11135
  }
11074
- if (this._jointTexture) {
11075
- this._jointTexture.setPixelBuffer(this._jointMatrices);
11136
+ inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
11137
+ if (child._scene !== newScene) {
11138
+ Entity._traverseSetOwnerScene(child, newScene);
11139
+ }
11140
+ var activeChangeFlag = ActiveChangeFlag.None;
11141
+ if (child._isActive) {
11142
+ if (this._isActiveInHierarchy) {
11143
+ !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
11144
+ }
11145
+ if (this._isActiveInScene) {
11146
+ (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
11147
+ }
11076
11148
  }
11149
+ activeChangeFlag && child._processActive(activeChangeFlag);
11150
+ child._setTransformDirty();
11151
+ } else {
11152
+ child._setParent(this, index);
11077
11153
  }
11078
- var layer = entity.layer;
11079
- this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
11080
11154
  };
11081
11155
  /**
11082
- * @internal
11083
- */ _proto._onDestroy = function _onDestroy() {
11084
- var _this__jointTexture;
11085
- MeshRenderer1.prototype._onDestroy.call(this);
11086
- this._rootBone = null;
11087
- this._jointDataCreateCache = null;
11088
- this._skin = null;
11089
- this._blendShapeWeights = null;
11090
- this._localBounds = null;
11091
- this._jointMatrices = null;
11092
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
11093
- this._jointTexture = null;
11094
- this._bones = null;
11156
+ * Remove child entity.
11157
+ * @param child - The child entity which want to be removed
11158
+ */ _proto.removeChild = function removeChild(child) {
11159
+ child._setParent(null);
11095
11160
  };
11096
11161
  /**
11097
- * @internal
11098
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
11099
- MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
11100
- var paths = new Array();
11101
- // Clone rootBone
11102
- if (this.rootBone) {
11103
- var success = this._getEntityHierarchyPath(srcRoot, this.rootBone, paths);
11104
- target.rootBone = success ? this._getEntityByHierarchyPath(targetRoot, paths) : this.rootBone;
11162
+ * @deprecated Please use `children` property instead.
11163
+ * Find child entity by index.
11164
+ * @param index - The index of the child entity
11165
+ * @returns The component which be found
11166
+ */ _proto.getChild = function getChild(index) {
11167
+ return this._children[index];
11168
+ };
11169
+ /**
11170
+ * Find entity by name.
11171
+ * @param name - The name of the entity which want to be found
11172
+ * @returns The component which be found
11173
+ */ _proto.findByName = function findByName(name) {
11174
+ if (name === this.name) {
11175
+ return this;
11105
11176
  }
11106
- // Clone bones
11107
- var bones = this._bones;
11108
- if (bones) {
11109
- var boneCount = bones.length;
11110
- var destBones = new Array(boneCount);
11111
- for(var i = 0; i < boneCount; i++){
11112
- var bone = bones[i];
11113
- var success1 = this._getEntityHierarchyPath(srcRoot, bone, paths);
11114
- destBones[i] = success1 ? this._getEntityByHierarchyPath(targetRoot, paths) : bone;
11177
+ var children = this._children;
11178
+ for(var i = 0, n = children.length; i < n; i++){
11179
+ var target = children[i].findByName(name);
11180
+ if (target) {
11181
+ return target;
11115
11182
  }
11116
- target.bones = destBones;
11117
11183
  }
11118
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
11184
+ return null;
11119
11185
  };
11120
11186
  /**
11121
- * @internal
11122
- */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
11123
- var _this__rootBone;
11124
- ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this._entity).transform._updateFlagManager.addListener(this._onTransformChanged);
11187
+ * Find the entity by path.
11188
+ * @param path - The path fo the entity eg: /entity
11189
+ * @returns The component which be found
11190
+ */ _proto.findByPath = function findByPath(path) {
11191
+ var splits = path.split("/");
11192
+ var entity = this;
11193
+ for(var i = 0, length = splits.length; i < length; ++i){
11194
+ var split = splits[i];
11195
+ if (split) {
11196
+ entity = Entity._findChildByName(entity, split);
11197
+ if (!entity) {
11198
+ return null;
11199
+ }
11200
+ }
11201
+ }
11202
+ return entity;
11125
11203
  };
11126
11204
  /**
11127
- * @internal
11128
- */ _proto._unRegisterEntityTransformListener = function _unRegisterEntityTransformListener() {
11129
- var _this__rootBone;
11130
- ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this._entity).transform._updateFlagManager.removeListener(this._onTransformChanged);
11205
+ * Create child entity.
11206
+ * @param name - The child entity's name
11207
+ * @returns The child entity
11208
+ */ _proto.createChild = function createChild(name) {
11209
+ var child = new Entity(this.engine, name);
11210
+ child.layer = this.layer;
11211
+ child.parent = this;
11212
+ return child;
11213
+ };
11214
+ /**
11215
+ * Clear children entities.
11216
+ */ _proto.clearChildren = function clearChildren() {
11217
+ var children = this._children;
11218
+ for(var i = children.length - 1; i >= 0; i--){
11219
+ var child = children[i];
11220
+ child._parent = null;
11221
+ var activeChangeFlag = ActiveChangeFlag.None;
11222
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
11223
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
11224
+ activeChangeFlag && child._processInActive(activeChangeFlag);
11225
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
11226
+ }
11227
+ children.length = 0;
11228
+ };
11229
+ /**
11230
+ * Clone this entity include children and components.
11231
+ * @returns Cloned entity
11232
+ */ _proto.clone = function clone() {
11233
+ var cloneEntity = this._createCloneEntity(this);
11234
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
11235
+ return cloneEntity;
11131
11236
  };
11132
11237
  /**
11133
11238
  * @internal
11134
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
11135
- if (this._rootBone) {
11136
- var localBounds = this._localBounds;
11137
- var worldMatrix = this._rootBone.transform.worldMatrix;
11138
- miniprogram.BoundingBox.transform(localBounds, worldMatrix, worldBounds);
11139
- } else {
11140
- MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
11239
+ */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
11240
+ this._isTemplate = true;
11241
+ this._templateResource = templateResource;
11242
+ };
11243
+ _proto._createCloneEntity = function _createCloneEntity(srcEntity) {
11244
+ var cloneEntity = new Entity(srcEntity._engine, srcEntity.name);
11245
+ var templateResource = this._templateResource;
11246
+ if (templateResource) {
11247
+ cloneEntity._templateResource = templateResource;
11248
+ templateResource._addReferCount(1);
11249
+ }
11250
+ cloneEntity.layer = srcEntity.layer;
11251
+ cloneEntity._isActive = srcEntity._isActive;
11252
+ var cloneTransform = cloneEntity.transform;
11253
+ var srcTransform = srcEntity.transform;
11254
+ cloneTransform.position = srcTransform.position;
11255
+ cloneTransform.rotation = srcTransform.rotation;
11256
+ cloneTransform.scale = srcTransform.scale;
11257
+ var children = srcEntity._children;
11258
+ for(var i = 0, n = srcEntity._children.length; i < n; i++){
11259
+ cloneEntity.addChild(this._createCloneEntity(children[i]));
11141
11260
  }
11261
+ return cloneEntity;
11142
11262
  };
11143
- _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
11144
- var mesh = this._mesh;
11145
- var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
11146
- var lastBlendShapeWeights = this._blendShapeWeights;
11147
- if (lastBlendShapeWeights) {
11148
- var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
11149
- if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
11150
- var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
11151
- if (newBlendShapeCount > lastBlendShapeWeightsCount) {
11152
- newBlendShapeWeights.set(lastBlendShapeWeights);
11153
- } else {
11154
- for(var i = 0; i < newBlendShapeCount; i++){
11155
- newBlendShapeWeights[i] = lastBlendShapeWeights[i];
11156
- }
11157
- }
11158
- this._blendShapeWeights = newBlendShapeWeights;
11263
+ _proto._parseCloneEntity = function _parseCloneEntity(src, target, srcRoot, targetRoot, deepInstanceMap) {
11264
+ var srcChildren = src._children;
11265
+ var targetChildren = target._children;
11266
+ for(var i = 0, n = srcChildren.length; i < n; i++){
11267
+ this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot, deepInstanceMap);
11268
+ }
11269
+ var components = src._components;
11270
+ for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
11271
+ var sourceComp = components[i1];
11272
+ if (!_instanceof(sourceComp, Transform)) {
11273
+ var targetComp = target.addComponent(sourceComp.constructor);
11274
+ ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot, deepInstanceMap);
11159
11275
  }
11276
+ }
11277
+ };
11278
+ /**
11279
+ * Destroy self.
11280
+ */ _proto.destroy = function destroy() {
11281
+ if (this._destroyed) {
11282
+ return;
11283
+ }
11284
+ EngineObject1.prototype.destroy.call(this);
11285
+ if (this._templateResource) {
11286
+ this._isTemplate || this._templateResource._addReferCount(-1);
11287
+ this._templateResource = null;
11288
+ }
11289
+ var components = this._components;
11290
+ for(var i = components.length - 1; i >= 0; i--){
11291
+ components[i].destroy();
11292
+ }
11293
+ this._components.length = 0;
11294
+ var children = this._children;
11295
+ while(children.length > 0){
11296
+ children[0].destroy();
11297
+ }
11298
+ if (this._isRoot) {
11299
+ this._scene.removeRootEntity(this);
11160
11300
  } else {
11161
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
11301
+ this._setParent(null);
11162
11302
  }
11303
+ this.isActive = false;
11163
11304
  };
11164
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
11165
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11305
+ /**
11306
+ * @internal
11307
+ */ _proto._removeComponent = function _removeComponent(component) {
11308
+ ComponentsDependencies._removeCheck(this, component.constructor);
11309
+ var components = this._components;
11310
+ components.splice(components.indexOf(component), 1);
11166
11311
  };
11167
- _proto._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
11168
- inversePath.length = 0;
11169
- while(searchEntity !== rootEntity){
11170
- var parent = searchEntity.parent;
11171
- if (!parent) {
11172
- return false;
11312
+ /**
11313
+ * @internal
11314
+ */ _proto._addScript = function _addScript(script) {
11315
+ script._entityScriptsIndex = this._scripts.length;
11316
+ this._scripts.add(script);
11317
+ };
11318
+ /**
11319
+ * @internal
11320
+ */ _proto._removeScript = function _removeScript(script) {
11321
+ var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
11322
+ replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
11323
+ script._entityScriptsIndex = -1;
11324
+ };
11325
+ /**
11326
+ * @internal
11327
+ */ _proto._removeFromParent = function _removeFromParent() {
11328
+ var oldParent = this._parent;
11329
+ if (oldParent != null) {
11330
+ var oldSibling = oldParent._children;
11331
+ var index = this._siblingIndex;
11332
+ oldSibling.splice(index, 1);
11333
+ for(var n = oldSibling.length; index < n; index++){
11334
+ oldSibling[index]._siblingIndex--;
11173
11335
  }
11174
- inversePath.push(searchEntity.siblingIndex);
11175
- searchEntity = parent;
11336
+ this._parent = null;
11337
+ this._siblingIndex = -1;
11176
11338
  }
11177
- return true;
11178
11339
  };
11179
11340
  /**
11180
11341
  * @internal
11181
- */ _proto._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
11182
- var entity = rootEntity;
11183
- for(var i = inversePath.length - 1; i >= 0; i--){
11184
- entity = entity.children[inversePath[i]];
11342
+ */ _proto._processActive = function _processActive(activeChangeFlag) {
11343
+ if (this._activeChangedComponents) {
11344
+ throw "Note: can't set the 'main inActive entity' active in hierarchy, if the operation is in main inActive entity or it's children script's onDisable Event.";
11185
11345
  }
11186
- return entity;
11346
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
11347
+ this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
11348
+ this._setActiveComponents(true, activeChangeFlag);
11187
11349
  };
11188
- _create_class(SkinnedMeshRenderer, [
11189
- {
11190
- key: "blendShapeWeights",
11191
- get: /**
11192
- * The weights of the BlendShapes.
11193
- * @remarks Array index is BlendShape index.
11194
- */ function get() {
11195
- this._checkBlendShapeWeightLength();
11196
- return this._blendShapeWeights;
11197
- },
11198
- set: function set(value) {
11199
- this._checkBlendShapeWeightLength();
11200
- var blendShapeWeights = this._blendShapeWeights;
11201
- if (value.length <= blendShapeWeights.length) {
11202
- blendShapeWeights.set(value);
11203
- } else {
11204
- for(var i = 0, n = blendShapeWeights.length; i < n; i++){
11205
- blendShapeWeights[i] = value[i];
11206
- }
11207
- }
11350
+ /**
11351
+ * @internal
11352
+ */ _proto._processInActive = function _processInActive(activeChangeFlag) {
11353
+ if (this._activeChangedComponents) {
11354
+ throw "Note: can't set the 'main active entity' inActive in hierarchy, if the operation is in main active entity or it's children script's onEnable Event.";
11355
+ }
11356
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
11357
+ this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
11358
+ this._setActiveComponents(false, activeChangeFlag);
11359
+ };
11360
+ _proto._addToChildrenList = function _addToChildrenList(index, child) {
11361
+ var children = this._children;
11362
+ var childCount = children.length;
11363
+ if (index === undefined) {
11364
+ child._siblingIndex = childCount;
11365
+ children.push(child);
11366
+ } else {
11367
+ if (index < 0 || index > childCount) {
11368
+ throw "The index " + index + " is out of child list bounds " + childCount;
11208
11369
  }
11209
- },
11210
- {
11211
- key: "localBounds",
11212
- get: /**
11213
- * Local bounds.
11214
- */ function get() {
11215
- return this._localBounds;
11216
- },
11217
- set: function set(value) {
11218
- if (this._localBounds !== value) {
11219
- this._localBounds.copyFrom(value);
11220
- }
11370
+ child._siblingIndex = index;
11371
+ children.splice(index, 0, child);
11372
+ for(var i = index + 1, n = childCount + 1; i < n; i++){
11373
+ children[i]._siblingIndex++;
11221
11374
  }
11222
- },
11223
- {
11224
- key: "rootBone",
11225
- get: /**
11226
- * Root bone.
11227
- */ function get() {
11228
- return this._rootBone;
11229
- },
11230
- set: function set(value) {
11231
- if (this._rootBone !== value) {
11232
- this._unRegisterEntityTransformListener();
11233
- this._rootBone = value;
11234
- this._registerEntityTransformListener();
11235
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11375
+ }
11376
+ };
11377
+ _proto._setParent = function _setParent(parent, siblingIndex) {
11378
+ var oldParent = this._parent;
11379
+ if (parent !== oldParent) {
11380
+ this._removeFromParent();
11381
+ this._parent = parent;
11382
+ if (parent) {
11383
+ parent._addToChildrenList(siblingIndex, this);
11384
+ var oldScene = this._scene;
11385
+ var parentScene = parent._scene;
11386
+ var inActiveChangeFlag = ActiveChangeFlag.None;
11387
+ if (!parent._isActiveInHierarchy) {
11388
+ this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
11389
+ }
11390
+ if (parent._isActiveInScene) {
11391
+ // cross scene should inActive first and then active
11392
+ this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
11393
+ } else {
11394
+ this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
11395
+ }
11396
+ inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
11397
+ if (oldScene !== parentScene) {
11398
+ Entity._traverseSetOwnerScene(this, parentScene);
11399
+ }
11400
+ var activeChangeFlag = ActiveChangeFlag.None;
11401
+ if (this._isActive) {
11402
+ if (parent._isActiveInHierarchy) {
11403
+ !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
11404
+ }
11405
+ if (parent._isActiveInScene) {
11406
+ (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
11407
+ }
11408
+ }
11409
+ activeChangeFlag && this._processActive(activeChangeFlag);
11410
+ } else {
11411
+ var inActiveChangeFlag1 = ActiveChangeFlag.None;
11412
+ this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
11413
+ this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
11414
+ inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
11415
+ if (oldParent) {
11416
+ Entity._traverseSetOwnerScene(this, null);
11236
11417
  }
11237
11418
  }
11238
- },
11419
+ this._setTransformDirty();
11420
+ }
11421
+ };
11422
+ _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
11423
+ for(var i = this._components.length - 1; i >= 0; i--){
11424
+ var component = this._components[i];
11425
+ if (_instanceof(component, type)) {
11426
+ results.push(component);
11427
+ }
11428
+ }
11429
+ for(var i1 = this._children.length - 1; i1 >= 0; i1--){
11430
+ this._children[i1]._getComponentsInChildren(type, results);
11431
+ }
11432
+ };
11433
+ _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
11434
+ var activeChangedComponents = this._activeChangedComponents;
11435
+ for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
11436
+ activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
11437
+ }
11438
+ this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
11439
+ this._activeChangedComponents = null;
11440
+ };
11441
+ _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
11442
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
11443
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
11444
+ var components = this._components;
11445
+ for(var i = 0, n = components.length; i < n; i++){
11446
+ var component = components[i];
11447
+ (component.enabled || !component._awoken) && activeChangedComponents.push(component);
11448
+ }
11449
+ var children = this._children;
11450
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
11451
+ var child = children[i1];
11452
+ child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
11453
+ }
11454
+ };
11455
+ _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
11456
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
11457
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
11458
+ var components = this._components;
11459
+ for(var i = 0, n = components.length; i < n; i++){
11460
+ var component = components[i];
11461
+ component.enabled && activeChangedComponents.push(component);
11462
+ }
11463
+ var children = this._children;
11464
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
11465
+ var child = children[i1];
11466
+ child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
11467
+ }
11468
+ };
11469
+ _proto._setTransformDirty = function _setTransformDirty() {
11470
+ if (this.transform) {
11471
+ this.transform._parentChange();
11472
+ } else {
11473
+ for(var i = 0, len = this._children.length; i < len; i++){
11474
+ this._children[i]._setTransformDirty();
11475
+ }
11476
+ }
11477
+ };
11478
+ _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
11479
+ target = Math.min(target, sibling.length - 1);
11480
+ if (target < 0) {
11481
+ throw "Sibling index " + target + " should large than 0";
11482
+ }
11483
+ if (this._siblingIndex !== target) {
11484
+ var oldIndex = this._siblingIndex;
11485
+ if (target < oldIndex) {
11486
+ for(var i = oldIndex; i >= target; i--){
11487
+ var child = i == target ? this : sibling[i - 1];
11488
+ sibling[i] = child;
11489
+ child._siblingIndex = i;
11490
+ }
11491
+ } else {
11492
+ for(var i1 = oldIndex; i1 <= target; i1++){
11493
+ var child1 = i1 == target ? this : sibling[i1 + 1];
11494
+ sibling[i1] = child1;
11495
+ child1._siblingIndex = i1;
11496
+ }
11497
+ }
11498
+ }
11499
+ };
11500
+ /**
11501
+ * @deprecated
11502
+ */ _proto.getInvModelMatrix = function getInvModelMatrix() {
11503
+ if (this._inverseWorldMatFlag.flag) {
11504
+ miniprogram.Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
11505
+ this._inverseWorldMatFlag.flag = false;
11506
+ }
11507
+ return this._invModelMatrix;
11508
+ };
11509
+ /**
11510
+ * @internal
11511
+ */ Entity._findChildByName = function _findChildByName(root, name) {
11512
+ var children = root._children;
11513
+ for(var i = children.length - 1; i >= 0; i--){
11514
+ var child = children[i];
11515
+ if (child.name === name) {
11516
+ return child;
11517
+ }
11518
+ }
11519
+ return null;
11520
+ };
11521
+ /**
11522
+ * @internal
11523
+ */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
11524
+ entity._scene = scene;
11525
+ var children = entity._children;
11526
+ for(var i = children.length - 1; i >= 0; i--){
11527
+ this._traverseSetOwnerScene(children[i], scene);
11528
+ }
11529
+ };
11530
+ /**
11531
+ * @internal
11532
+ */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
11533
+ inversePath.length = 0;
11534
+ while(searchEntity !== rootEntity){
11535
+ var parent = searchEntity.parent;
11536
+ if (!parent) {
11537
+ return false;
11538
+ }
11539
+ inversePath.push(searchEntity.siblingIndex);
11540
+ searchEntity = parent;
11541
+ }
11542
+ return true;
11543
+ };
11544
+ /**
11545
+ * @internal
11546
+ */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
11547
+ var entity = rootEntity;
11548
+ for(var i = inversePath.length - 1; i >= 0; i--){
11549
+ entity = entity.children[inversePath[i]];
11550
+ }
11551
+ return entity;
11552
+ };
11553
+ _create_class(Entity, [
11239
11554
  {
11240
- key: "bones",
11555
+ key: "isActive",
11241
11556
  get: /**
11242
- * Bones of the SkinnedMeshRenderer.
11557
+ * Whether to activate locally.
11243
11558
  */ function get() {
11244
- return this._bones;
11559
+ return this._isActive;
11245
11560
  },
11246
11561
  set: function set(value) {
11247
- if (this._bones !== value) {
11248
- var _this__bones, _value;
11249
- var _this__bones_length;
11250
- var lastBoneCount = (_this__bones_length = (_this__bones = this._bones) == null ? void 0 : _this__bones.length) != null ? _this__bones_length : 0;
11251
- var _value_length;
11252
- var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
11253
- if (lastBoneCount !== boneCount) {
11254
- var shaderData = this.shaderData;
11255
- if (boneCount > 0) {
11256
- this._jointMatrices = new Float32Array(boneCount * 16);
11257
- shaderData.enableMacro("RENDERER_HAS_SKIN");
11258
- shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, boneCount);
11562
+ if (value !== this._isActive) {
11563
+ this._isActive = value;
11564
+ if (value) {
11565
+ var parent = this._parent;
11566
+ var activeChangeFlag = ActiveChangeFlag.None;
11567
+ if (this._isRoot && this._scene._isActiveInEngine) {
11568
+ activeChangeFlag |= ActiveChangeFlag.All;
11259
11569
  } else {
11260
- this._jointMatrices = null;
11261
- shaderData.disableMacro("RENDERER_HAS_SKIN");
11570
+ var _parent, _parent1;
11571
+ ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
11572
+ ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
11262
11573
  }
11574
+ activeChangeFlag && this._processActive(activeChangeFlag);
11575
+ } else {
11576
+ var activeChangeFlag1 = ActiveChangeFlag.None;
11577
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
11578
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
11579
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
11263
11580
  }
11264
- this._bones = value;
11265
11581
  }
11266
11582
  }
11267
11583
  },
11268
11584
  {
11269
- key: "skin",
11585
+ key: "isActiveInHierarchy",
11270
11586
  get: /**
11271
- * @deprecated
11272
- * Skin Object.
11273
- *
11274
- * If you want get `skeleton`, use {@link SkinnedMeshRenderer.rootBone} instead.
11275
- * If you want get `bones`, use {@link SkinnedMeshRenderer.bones} instead.
11276
- * `inverseBindMatrices` will migrate to mesh in the future.
11277
- *
11278
- * @remarks `rootBone` and `bones` will not update when `skin` changed.
11587
+ * Whether it is active in the hierarchy.
11279
11588
  */ function get() {
11280
- return this._skin;
11589
+ return this._isActiveInHierarchy;
11590
+ }
11591
+ },
11592
+ {
11593
+ key: "parent",
11594
+ get: /**
11595
+ * The parent entity.
11596
+ */ function get() {
11597
+ return this._parent;
11281
11598
  },
11282
11599
  set: function set(value) {
11283
- this._skin = value;
11600
+ this._setParent(value);
11284
11601
  }
11285
- }
11286
- ]);
11287
- return SkinnedMeshRenderer;
11288
- }(MeshRenderer);
11289
- (function() {
11290
- SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
11291
- })();
11292
- (function() {
11293
- SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
11294
- })();
11295
- (function() {
11296
- SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
11297
- })();
11298
- __decorate([
11299
- deepClone
11300
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
11301
- __decorate([
11302
- ignoreClone
11303
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
11304
- __decorate([
11305
- ignoreClone
11306
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
11307
- __decorate([
11308
- ignoreClone
11309
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
11310
- __decorate([
11311
- ignoreClone
11312
- ], SkinnedMeshRenderer.prototype, "_rootBone", void 0);
11602
+ },
11603
+ {
11604
+ key: "children",
11605
+ get: /**
11606
+ * The children entities
11607
+ */ function get() {
11608
+ return this._children;
11609
+ }
11610
+ },
11611
+ {
11612
+ key: "childCount",
11613
+ get: /**
11614
+ * @deprecated Please use `children.length` property instead.
11615
+ * Number of the children entities
11616
+ */ function get() {
11617
+ return this._children.length;
11618
+ }
11619
+ },
11620
+ {
11621
+ key: "scene",
11622
+ get: /**
11623
+ * The scene the entity belongs to.
11624
+ */ function get() {
11625
+ return this._scene;
11626
+ }
11627
+ },
11628
+ {
11629
+ key: "siblingIndex",
11630
+ get: /**
11631
+ * The sibling index.
11632
+ */ function get() {
11633
+ return this._siblingIndex;
11634
+ },
11635
+ set: function set(value) {
11636
+ if (this._siblingIndex === -1) {
11637
+ throw "The entity " + this.name + " is not in the hierarchy";
11638
+ }
11639
+ this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
11640
+ }
11641
+ }
11642
+ ]);
11643
+ return Entity;
11644
+ }(EngineObject);
11645
+
11646
+ /**
11647
+ * Skin used for skinned mesh renderer.
11648
+ */ var Skin = /*#__PURE__*/ function(EngineObject1) {
11649
+ _inherits(Skin, EngineObject1);
11650
+ function Skin(name) {
11651
+ var _this;
11652
+ _this = EngineObject1.call(this, null) || this;
11653
+ _this.name = name;
11654
+ _this.inverseBindMatrices = new Array();
11655
+ _this._updatedManager = new UpdateFlagManager();
11656
+ _this._bones = new Array();
11657
+ _this._updateMark = -1;
11658
+ _this.joints = [];
11659
+ return _this;
11660
+ }
11661
+ var _proto = Skin.prototype;
11662
+ /**
11663
+ * @internal
11664
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
11665
+ if (this._updateMark === renderer.engine.time.frameCount) {
11666
+ return;
11667
+ }
11668
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
11669
+ var _this_rootBone;
11670
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
11671
+ for(var i = bones.length - 1; i >= 0; i--){
11672
+ var bone = bones[i];
11673
+ var offset = i * 16;
11674
+ if (bone) {
11675
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
11676
+ } else {
11677
+ skinMatrices.set(bindMatrices[i].elements, offset);
11678
+ }
11679
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
11680
+ }
11681
+ this._updateMark = renderer.engine.time.frameCount;
11682
+ };
11683
+ /**
11684
+ * @internal
11685
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
11686
+ var paths = new Array();
11687
+ // Clone rootBone
11688
+ var rootBone = this.rootBone;
11689
+ if (rootBone) {
11690
+ var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
11691
+ target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
11692
+ }
11693
+ // Clone bones
11694
+ var bones = this.bones;
11695
+ if (bones.length > 0) {
11696
+ var boneCount = bones.length;
11697
+ var destBones = new Array(boneCount);
11698
+ for(var i = 0; i < boneCount; i++){
11699
+ var bone = bones[i];
11700
+ var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
11701
+ destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
11702
+ }
11703
+ target.bones = destBones;
11704
+ }
11705
+ };
11706
+ _create_class(Skin, [
11707
+ {
11708
+ key: "rootBone",
11709
+ get: /**
11710
+ * Root bone.
11711
+ */ function get() {
11712
+ return this._rootBone;
11713
+ },
11714
+ set: function set(value) {
11715
+ if (this._rootBone !== value) {
11716
+ this._updatedManager.dispatch(1, value);
11717
+ this._rootBone = value;
11718
+ }
11719
+ }
11720
+ },
11721
+ {
11722
+ key: "bones",
11723
+ get: /**
11724
+ * Bones of the skin.
11725
+ */ function get() {
11726
+ return this._bones;
11727
+ },
11728
+ set: function set(value) {
11729
+ var _value;
11730
+ var bones = this._bones;
11731
+ var _value_length;
11732
+ var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
11733
+ var lastBoneCount = bones.length;
11734
+ bones.length = boneCount;
11735
+ for(var i = 0; i < boneCount; i++){
11736
+ bones[i] = value[i];
11737
+ }
11738
+ if (lastBoneCount !== boneCount) {
11739
+ this._skinMatrices = new Float32Array(boneCount * 16);
11740
+ this._updatedManager.dispatch(0, boneCount);
11741
+ }
11742
+ }
11743
+ },
11744
+ {
11745
+ key: "skeleton",
11746
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
11747
+ var _this_rootBone;
11748
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
11749
+ },
11750
+ set: function set(value) {
11751
+ var rootBone = this._rootBone;
11752
+ if (rootBone) {
11753
+ rootBone.name = value;
11754
+ }
11755
+ }
11756
+ }
11757
+ ]);
11758
+ return Skin;
11759
+ }(EngineObject);
11760
+ __decorate([
11761
+ deepClone
11762
+ ], Skin.prototype, "inverseBindMatrices", void 0);
11313
11763
  __decorate([
11314
11764
  ignoreClone
11315
- ], SkinnedMeshRenderer.prototype, "_jointMatrices", void 0);
11765
+ ], Skin.prototype, "_skinMatrices", void 0);
11316
11766
  __decorate([
11317
11767
  ignoreClone
11318
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
11768
+ ], Skin.prototype, "_updatedManager", void 0);
11319
11769
  __decorate([
11320
11770
  ignoreClone
11321
- ], SkinnedMeshRenderer.prototype, "_bones", void 0);
11771
+ ], Skin.prototype, "_rootBone", void 0);
11322
11772
  __decorate([
11323
11773
  ignoreClone
11324
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
11774
+ ], Skin.prototype, "_bones", void 0);
11325
11775
  __decorate([
11326
11776
  ignoreClone
11327
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
11777
+ ], Skin.prototype, "_updateMark", void 0);
11778
+ var SkinUpdateFlag;
11779
+ (function(SkinUpdateFlag) {
11780
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
11781
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
11782
+ })(SkinUpdateFlag || (SkinUpdateFlag = {}));
11328
11783
 
11329
11784
  /**
11330
- * Class pool utils.
11331
- */ var ClassPool = /*#__PURE__*/ function() {
11332
- function ClassPool(type) {
11333
- this._elementPoolIndex = 0;
11334
- this._elementPool = [];
11335
- this._type = type;
11785
+ * SkinnedMeshRenderer.
11786
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
11787
+ _inherits(SkinnedMeshRenderer, MeshRenderer1);
11788
+ function SkinnedMeshRenderer(entity) {
11789
+ var _this;
11790
+ _this = MeshRenderer1.call(this, entity) || this;
11791
+ _this._localBounds = new miniprogram.BoundingBox();
11792
+ _this._jointDataCreateCache = new miniprogram.Vector2(-1, -1);
11793
+ _this._skin = null;
11794
+ var rhi = _this.entity.engine._hardwareRenderer;
11795
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
11796
+ // Limit size to 256 to avoid some problem:
11797
+ // 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!
11798
+ // 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.
11799
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
11800
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
11801
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
11802
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_assert_this_initialized(_this));
11803
+ var localBounds = _this._localBounds;
11804
+ // @ts-ignore
11805
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
11806
+ // @ts-ignore
11807
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
11808
+ return _this;
11336
11809
  }
11337
- var _proto = ClassPool.prototype;
11810
+ var _proto = SkinnedMeshRenderer.prototype;
11338
11811
  /**
11339
- * Get element from pool.
11340
- */ _proto.getFromPool = function getFromPool() {
11341
- var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
11342
- this._elementPoolIndex++;
11343
- if (pool.length === index) {
11344
- var element = new this._type();
11345
- pool.push(element);
11346
- return element;
11347
- } else {
11348
- return pool[index];
11812
+ * @internal
11813
+ */ _proto.update = function update() {
11814
+ var _skin;
11815
+ var skin = this._skin;
11816
+ if (((_skin = skin) == null ? void 0 : _skin.bones.length) > 0) {
11817
+ skin._updateSkinMatrices(this);
11349
11818
  }
11350
11819
  };
11351
- /**
11352
- * Reset pool.
11353
- */ _proto.resetPool = function resetPool() {
11354
- this._elementPoolIndex = 0;
11355
- };
11356
- _proto.garbageCollection = function garbageCollection() {
11357
- var _this = this, pool = _this._elementPool;
11358
- for(var i = pool.length - 1; i >= 0; i--){
11359
- pool[i].dispose && pool[i].dispose();
11820
+ _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
11821
+ var _skin, _skin1;
11822
+ var _this = this, entity = _this.entity, skin = _this.skin;
11823
+ var _skin_rootBone;
11824
+ var worldMatrix = ((_skin_rootBone = (_skin = skin) == null ? void 0 : _skin.rootBone) != null ? _skin_rootBone : entity).transform.worldMatrix;
11825
+ if (onlyMVP) {
11826
+ this._updateMVPShaderData(context, worldMatrix);
11827
+ return;
11360
11828
  }
11361
- };
11362
- return ClassPool;
11363
- }();
11364
-
11365
- var Basic2DBatcher = /*#__PURE__*/ function() {
11366
- function Basic2DBatcher(engine) {
11367
- /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
11368
- /** @internal */ this._batchedQueue = [];
11369
- /** @internal */ this._meshes = [];
11370
- /** @internal */ this._meshCount = 1;
11371
- /** @internal */ this._vertexBuffers = [];
11372
- /** @internal */ this._indiceBuffers = [];
11373
- /** @internal */ this._flushId = 0;
11374
- /** @internal */ this._vertexCount = 0;
11375
- /** @internal */ this._elementCount = 0;
11376
- this._engine = engine;
11377
- this._initMeshes(engine);
11378
- }
11379
- var _proto = Basic2DBatcher.prototype;
11380
- _proto.drawElement = function drawElement(element, camera) {
11381
- var data = element.data;
11382
- if (data.multiRenderData) {
11383
- var charsData = data.charsData;
11384
- var pool = camera.engine._renderElementPool;
11385
- for(var i = 0, n = charsData.length; i < n; ++i){
11386
- var charRenderElement = pool.getFromPool();
11387
- charRenderElement.set(charsData[i], element.shaderPasses);
11388
- this._drawSubElement(charRenderElement, camera);
11829
+ this._updateTransformShaderData(context, worldMatrix);
11830
+ var shaderData = this.shaderData;
11831
+ var mesh = this.mesh;
11832
+ var blendShapeManager = mesh._blendShapeManager;
11833
+ blendShapeManager._updateShaderData(shaderData, this);
11834
+ var bones = (_skin1 = skin) == null ? void 0 : _skin1.bones;
11835
+ if (bones) {
11836
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
11837
+ var boneCount = bones.length;
11838
+ var boneDataCreateCache = this._jointDataCreateCache;
11839
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
11840
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
11841
+ // directly use max joint count to avoid shader recompile
11842
+ // @TODO: different shader type should use different count, not always 44
11843
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
11844
+ if (boneCount > remainUniformJointCount) {
11845
+ var engine = this.engine;
11846
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
11847
+ if (boneCountChange) {
11848
+ var _this__jointTexture;
11849
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
11850
+ this._jointTexture = new Texture2D(engine, 4, boneCount, exports.TextureFormat.R32G32B32A32, false);
11851
+ this._jointTexture.filterMode = exports.TextureFilterMode.Point;
11852
+ this._jointTexture.isGCIgnored = true;
11853
+ }
11854
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
11855
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
11856
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
11857
+ } else {
11858
+ 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);
11859
+ }
11860
+ } else {
11861
+ var _this__jointTexture1;
11862
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
11863
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
11864
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
11865
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
11866
+ }
11867
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
11868
+ }
11869
+ if (this._jointTexture) {
11870
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
11389
11871
  }
11390
- } else {
11391
- this._drawSubElement(element, camera);
11392
11872
  }
11873
+ var layer = entity.layer;
11874
+ this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
11393
11875
  };
11394
11876
  /**
11395
11877
  * @internal
11396
- * Standalone for canvas 2d renderer plugin.
11397
- */ _proto._initMeshes = function _initMeshes(engine) {
11398
- var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
11399
- this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
11400
- this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
11401
- var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
11402
- for(var i = 0; i < _meshCount; i++){
11403
- _meshes[i] = this._createMesh(engine, i);
11404
- }
11878
+ */ _proto._onDestroy = function _onDestroy() {
11879
+ var _this__jointTexture;
11880
+ MeshRenderer1.prototype._onDestroy.call(this);
11881
+ this._jointDataCreateCache = null;
11882
+ this._skin = null;
11883
+ this._blendShapeWeights = null;
11884
+ this._localBounds = null;
11885
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
11886
+ this._jointTexture = null;
11405
11887
  };
11406
- _proto.flush = function flush(camera) {
11407
- var batchedQueue = this._batchedQueue;
11408
- if (batchedQueue.length === 0) {
11409
- return;
11888
+ /**
11889
+ * @internal
11890
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
11891
+ MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
11892
+ if (this.skin) {
11893
+ target._applySkin(null, target.skin);
11894
+ }
11895
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
11896
+ };
11897
+ /**
11898
+ * @internal
11899
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
11900
+ var _this_skin;
11901
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
11902
+ if (rootBone) {
11903
+ miniprogram.BoundingBox.transform(this._localBounds, rootBone.transform.worldMatrix, worldBounds);
11904
+ } else {
11905
+ MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
11906
+ }
11907
+ };
11908
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
11909
+ var mesh = this._mesh;
11910
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
11911
+ var lastBlendShapeWeights = this._blendShapeWeights;
11912
+ if (lastBlendShapeWeights) {
11913
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
11914
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
11915
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
11916
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
11917
+ newBlendShapeWeights.set(lastBlendShapeWeights);
11918
+ } else {
11919
+ for(var i = 0; i < newBlendShapeCount; i++){
11920
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
11921
+ }
11922
+ }
11923
+ this._blendShapeWeights = newBlendShapeWeights;
11924
+ }
11925
+ } else {
11926
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
11927
+ }
11928
+ };
11929
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
11930
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11931
+ };
11932
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
11933
+ switch(type){
11934
+ case SkinUpdateFlag.BoneCountChanged:
11935
+ var shaderData = this.shaderData;
11936
+ if (value > 0) {
11937
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
11938
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
11939
+ } else {
11940
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
11941
+ }
11942
+ break;
11943
+ case SkinUpdateFlag.RootBoneChanged:
11944
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11945
+ break;
11946
+ }
11947
+ };
11948
+ _proto._applySkin = function _applySkin(lastSkin, value) {
11949
+ var _lastSkin_bones, _lastSkin, _lastSkin1, _lastSkin2, _value_bones, _value, _value1, _value2;
11950
+ var _lastSkin_bones_length;
11951
+ var lastSkinBoneCount = (_lastSkin_bones_length = (_lastSkin = lastSkin) == null ? void 0 : (_lastSkin_bones = _lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
11952
+ var _lastSkin_rootBone;
11953
+ var lastRootBone = (_lastSkin_rootBone = (_lastSkin1 = lastSkin) == null ? void 0 : _lastSkin1.rootBone) != null ? _lastSkin_rootBone : this.entity;
11954
+ (_lastSkin2 = lastSkin) == null ? void 0 : _lastSkin2._updatedManager.removeListener(this._onSkinUpdated);
11955
+ var _value_bones_length;
11956
+ var skinBoneCount = (_value_bones_length = (_value = value) == null ? void 0 : (_value_bones = _value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
11957
+ var _value_rootBone;
11958
+ var rootBone = (_value_rootBone = (_value1 = value) == null ? void 0 : _value1.rootBone) != null ? _value_rootBone : this.entity;
11959
+ (_value2 = value) == null ? void 0 : _value2._updatedManager.addListener(this._onSkinUpdated);
11960
+ if (lastSkinBoneCount !== skinBoneCount) {
11961
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
11962
+ }
11963
+ if (lastRootBone !== rootBone) {
11964
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
11965
+ }
11966
+ };
11967
+ _create_class(SkinnedMeshRenderer, [
11968
+ {
11969
+ key: "skin",
11970
+ get: /**
11971
+ * Skin of the SkinnedMeshRenderer.
11972
+ */ function get() {
11973
+ return this._skin;
11974
+ },
11975
+ set: function set(value) {
11976
+ var lastSkin = this._skin;
11977
+ if (lastSkin !== value) {
11978
+ this._applySkin(lastSkin, value);
11979
+ this._skin = value;
11980
+ }
11981
+ }
11982
+ },
11983
+ {
11984
+ key: "blendShapeWeights",
11985
+ get: /**
11986
+ * The weights of the BlendShapes.
11987
+ * @remarks Array index is BlendShape index.
11988
+ */ function get() {
11989
+ this._checkBlendShapeWeightLength();
11990
+ return this._blendShapeWeights;
11991
+ },
11992
+ set: function set(value) {
11993
+ this._checkBlendShapeWeightLength();
11994
+ var blendShapeWeights = this._blendShapeWeights;
11995
+ if (value.length <= blendShapeWeights.length) {
11996
+ blendShapeWeights.set(value);
11997
+ } else {
11998
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
11999
+ blendShapeWeights[i] = value[i];
12000
+ }
12001
+ }
12002
+ }
12003
+ },
12004
+ {
12005
+ key: "localBounds",
12006
+ get: /**
12007
+ * Local bounds.
12008
+ */ function get() {
12009
+ return this._localBounds;
12010
+ },
12011
+ set: function set(value) {
12012
+ if (this._localBounds !== value) {
12013
+ this._localBounds.copyFrom(value);
12014
+ }
12015
+ }
12016
+ },
12017
+ {
12018
+ key: "rootBone",
12019
+ get: /**
12020
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
12021
+ */ function get() {
12022
+ return this.skin.rootBone;
12023
+ },
12024
+ set: function set(value) {
12025
+ this.skin.rootBone = value;
12026
+ }
12027
+ },
12028
+ {
12029
+ key: "bones",
12030
+ get: /**
12031
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
12032
+ */ function get() {
12033
+ return this.skin.bones;
12034
+ },
12035
+ set: function set(value) {
12036
+ this.skin.bones = value;
12037
+ }
12038
+ }
12039
+ ]);
12040
+ return SkinnedMeshRenderer;
12041
+ }(MeshRenderer);
12042
+ (function() {
12043
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
12044
+ })();
12045
+ (function() {
12046
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
12047
+ })();
12048
+ (function() {
12049
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
12050
+ })();
12051
+ __decorate([
12052
+ ignoreClone
12053
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
12054
+ __decorate([
12055
+ deepClone
12056
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
12057
+ __decorate([
12058
+ ignoreClone
12059
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
12060
+ __decorate([
12061
+ ignoreClone
12062
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
12063
+ __decorate([
12064
+ ignoreClone
12065
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
12066
+ __decorate([
12067
+ ignoreClone
12068
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
12069
+ __decorate([
12070
+ deepClone
12071
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
12072
+ __decorate([
12073
+ ignoreClone
12074
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
12075
+ __decorate([
12076
+ ignoreClone
12077
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
12078
+
12079
+ /**
12080
+ * Class pool utils.
12081
+ */ var ClassPool = /*#__PURE__*/ function() {
12082
+ function ClassPool(type) {
12083
+ this._elementPoolIndex = 0;
12084
+ this._elementPool = [];
12085
+ this._type = type;
12086
+ }
12087
+ var _proto = ClassPool.prototype;
12088
+ /**
12089
+ * Get element from pool.
12090
+ */ _proto.getFromPool = function getFromPool() {
12091
+ var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
12092
+ this._elementPoolIndex++;
12093
+ if (pool.length === index) {
12094
+ var element = new this._type();
12095
+ pool.push(element);
12096
+ return element;
12097
+ } else {
12098
+ return pool[index];
12099
+ }
12100
+ };
12101
+ /**
12102
+ * Reset pool.
12103
+ */ _proto.resetPool = function resetPool() {
12104
+ this._elementPoolIndex = 0;
12105
+ };
12106
+ _proto.garbageCollection = function garbageCollection() {
12107
+ var _this = this, pool = _this._elementPool;
12108
+ for(var i = pool.length - 1; i >= 0; i--){
12109
+ pool[i].dispose && pool[i].dispose();
12110
+ }
12111
+ };
12112
+ return ClassPool;
12113
+ }();
12114
+
12115
+ var Basic2DBatcher = /*#__PURE__*/ function() {
12116
+ function Basic2DBatcher(engine) {
12117
+ /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
12118
+ /** @internal */ this._batchedQueue = [];
12119
+ /** @internal */ this._meshes = [];
12120
+ /** @internal */ this._meshCount = 1;
12121
+ /** @internal */ this._vertexBuffers = [];
12122
+ /** @internal */ this._indiceBuffers = [];
12123
+ /** @internal */ this._flushId = 0;
12124
+ /** @internal */ this._vertexCount = 0;
12125
+ /** @internal */ this._elementCount = 0;
12126
+ this._engine = engine;
12127
+ this._initMeshes(engine);
12128
+ }
12129
+ var _proto = Basic2DBatcher.prototype;
12130
+ _proto.drawElement = function drawElement(element, camera) {
12131
+ var data = element.data;
12132
+ if (data.multiRenderData) {
12133
+ var charsData = data.charsData;
12134
+ var pool = camera.engine._renderElementPool;
12135
+ for(var i = 0, n = charsData.length; i < n; ++i){
12136
+ var charRenderElement = pool.getFromPool();
12137
+ charRenderElement.set(charsData[i], element.shaderPasses);
12138
+ this._drawSubElement(charRenderElement, camera);
12139
+ }
12140
+ } else {
12141
+ this._drawSubElement(element, camera);
12142
+ }
12143
+ };
12144
+ /**
12145
+ * @internal
12146
+ * Standalone for canvas 2d renderer plugin.
12147
+ */ _proto._initMeshes = function _initMeshes(engine) {
12148
+ var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
12149
+ this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
12150
+ this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
12151
+ var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
12152
+ for(var i = 0; i < _meshCount; i++){
12153
+ _meshes[i] = this._createMesh(engine, i);
12154
+ }
12155
+ };
12156
+ _proto.flush = function flush(camera) {
12157
+ var batchedQueue = this._batchedQueue;
12158
+ if (batchedQueue.length === 0) {
12159
+ return;
11410
12160
  }
11411
12161
  this._updateData(this._engine);
11412
12162
  this.drawBatches(camera);
@@ -13969,7 +14719,7 @@ var DirtyFlag;
13969
14719
  */ _proto.cloneTo = function cloneTo(target) {
13970
14720
  target.shader = this.shader;
13971
14721
  this.shaderData.cloneTo(target.shaderData);
13972
- CloneManager.deepCloneObject(this.renderStates, target.renderStates);
14722
+ CloneManager.deepCloneObject(this.renderStates, target.renderStates, new Map());
13973
14723
  };
13974
14724
  _proto._addReferCount = function _addReferCount(value) {
13975
14725
  if (this._destroyed) return;
@@ -14876,904 +15626,255 @@ var BaseMaterial = /*#__PURE__*/ function(Material1) {
14876
15626
  key: "anisotropyTexture",
14877
15627
  get: /**
14878
15628
  * The anisotropy texture.
14879
- * @remarks
14880
- * Red and green channels represent the anisotropy direction in [-1, 1] tangent, bitangent space, to be rotated by anisotropyRotation.
14881
- * The blue channel contains strength as [0, 1] to be multiplied by anisotropy.
14882
- */ function get() {
14883
- return this.shaderData.getTexture(PBRMaterial._anisotropyTextureProp);
14884
- },
14885
- set: function set(value) {
14886
- this.shaderData.setTexture(PBRMaterial._anisotropyTextureProp, value);
14887
- if (value) {
14888
- this.shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
14889
- } else {
14890
- this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
14891
- }
14892
- }
14893
- }
14894
- ]);
14895
- return PBRMaterial;
14896
- }(PBRBaseMaterial);
14897
- (function() {
14898
- PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
14899
- })();
14900
- (function() {
14901
- PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
14902
- })();
14903
- (function() {
14904
- PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
14905
- })();
14906
- (function() {
14907
- PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
14908
- })();
14909
- (function() {
14910
- PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
14911
- })();
14912
- (function() {
14913
- PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
14914
- })();
14915
-
14916
- /**
14917
- * PBR (Specular-Glossiness Workflow) Material.
14918
- */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
14919
- _inherits(PBRSpecularMaterial, PBRBaseMaterial1);
14920
- function PBRSpecularMaterial(engine) {
14921
- var _this;
14922
- _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
14923
- _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new miniprogram.Color(1, 1, 1, 1));
14924
- _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
14925
- return _this;
14926
- }
14927
- var _proto = PBRSpecularMaterial.prototype;
14928
- /**
14929
- * @inheritdoc
14930
- */ _proto.clone = function clone() {
14931
- var dest = new PBRSpecularMaterial(this._engine);
14932
- this.cloneTo(dest);
14933
- return dest;
14934
- };
14935
- _create_class(PBRSpecularMaterial, [
14936
- {
14937
- key: "specularColor",
14938
- get: /**
14939
- * Specular color.
14940
- */ function get() {
14941
- return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
14942
- },
14943
- set: function set(value) {
14944
- var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
14945
- if (value !== specularColor) {
14946
- specularColor.copyFrom(value);
14947
- }
14948
- }
14949
- },
14950
- {
14951
- key: "glossiness",
14952
- get: /**
14953
- * Glossiness.
14954
- */ function get() {
14955
- return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
14956
- },
14957
- set: function set(value) {
14958
- this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
14959
- }
14960
- },
14961
- {
14962
- key: "specularGlossinessTexture",
14963
- get: /**
14964
- * Specular glossiness texture.
14965
- * @remarks RGB is specular, A is glossiness
14966
- */ function get() {
14967
- return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
14968
- },
14969
- set: function set(value) {
14970
- this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
14971
- if (value) {
14972
- this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
14973
- } else {
14974
- this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
14975
- }
14976
- }
14977
- }
14978
- ]);
14979
- return PBRSpecularMaterial;
14980
- }(PBRBaseMaterial);
14981
- (function() {
14982
- PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
14983
- })();
14984
- (function() {
14985
- PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
14986
- })();
14987
- (function() {
14988
- PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
14989
- })();
14990
- (function() {
14991
- PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
14992
- })();
14993
-
14994
- /**
14995
- * Unlit Material.
14996
- */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
14997
- _inherits(UnlitMaterial, BaseMaterial1);
14998
- function UnlitMaterial(engine) {
14999
- var _this;
15000
- _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
15001
- var shaderData = _this.shaderData;
15002
- shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
15003
- shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
15004
- shaderData.setColor(UnlitMaterial._baseColorProp, new miniprogram.Color(1, 1, 1, 1));
15005
- shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new miniprogram.Vector4(1, 1, 0, 0));
15006
- return _this;
15007
- }
15008
- var _proto = UnlitMaterial.prototype;
15009
- /**
15010
- * @inheritdoc
15011
- */ _proto.clone = function clone() {
15012
- var dest = new UnlitMaterial(this._engine);
15013
- this.cloneTo(dest);
15014
- return dest;
15015
- };
15016
- _create_class(UnlitMaterial, [
15017
- {
15018
- key: "baseColor",
15019
- get: /**
15020
- * Base color.
15021
- */ function get() {
15022
- return this.shaderData.getColor(UnlitMaterial._baseColorProp);
15023
- },
15024
- set: function set(value) {
15025
- var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
15026
- if (value !== baseColor) {
15027
- baseColor.copyFrom(value);
15028
- }
15029
- }
15030
- },
15031
- {
15032
- key: "baseTexture",
15033
- get: /**
15034
- * Base texture.
15035
- */ function get() {
15036
- return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
15037
- },
15038
- set: function set(value) {
15039
- this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
15040
- if (value) {
15041
- this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
15042
- } else {
15043
- this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
15044
- }
15045
- }
15046
- },
15047
- {
15048
- key: "tilingOffset",
15049
- get: /**
15050
- * Tiling and offset of main textures.
15051
- */ function get() {
15052
- return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
15053
- },
15054
- set: function set(value) {
15055
- var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
15056
- if (value !== tilingOffset) {
15057
- tilingOffset.copyFrom(value);
15058
- }
15059
- }
15060
- }
15061
- ]);
15062
- return UnlitMaterial;
15063
- }(BaseMaterial);
15064
-
15065
- /**
15066
- * @internal
15067
- */ var BasicResources = /*#__PURE__*/ function() {
15068
- function BasicResources(engine) {
15069
- // prettier-ignore
15070
- var vertices = new Float32Array([
15071
- -1,
15072
- -1,
15073
- 0,
15074
- 1,
15075
- 1,
15076
- -1,
15077
- 1,
15078
- 1,
15079
- -1,
15080
- 1,
15081
- 0,
15082
- 0,
15083
- 1,
15084
- 1,
15085
- 1,
15086
- 0
15087
- ]); // right-top
15088
- // prettier-ignore
15089
- var flipYVertices = new Float32Array([
15090
- 1,
15091
- -1,
15092
- 1,
15093
- 0,
15094
- -1,
15095
- -1,
15096
- 0,
15097
- 0,
15098
- 1,
15099
- 1,
15100
- 1,
15101
- 1,
15102
- -1,
15103
- 1,
15104
- 0,
15105
- 1
15106
- ]); // left-top
15107
- var blitMaterial = new Material(engine, Shader.find("blit"));
15108
- blitMaterial._addReferCount(1);
15109
- blitMaterial.renderState.depthState.enabled = false;
15110
- blitMaterial.renderState.depthState.writeEnabled = false;
15111
- this.blitMesh = this._createBlitMesh(engine, vertices);
15112
- this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
15113
- this.blitMaterial = blitMaterial;
15114
- }
15115
- var _proto = BasicResources.prototype;
15116
- _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
15117
- var mesh = new ModelMesh(engine);
15118
- mesh._addReferCount(1);
15119
- mesh.setVertexElements([
15120
- new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
15121
- ]);
15122
- mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
15123
- mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
15124
- return mesh;
15125
- };
15126
- return BasicResources;
15127
- }();
15128
-
15129
- /**
15130
- * Layer, used for bit operations.
15131
- */ exports.Layer = void 0;
15132
- (function(Layer) {
15133
- Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
15134
- Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
15135
- Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
15136
- Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
15137
- Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
15138
- Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
15139
- Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
15140
- Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
15141
- Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
15142
- Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
15143
- Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
15144
- Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
15145
- Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
15146
- Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
15147
- Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
15148
- Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
15149
- Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
15150
- Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
15151
- Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
15152
- Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
15153
- Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
15154
- Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
15155
- Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
15156
- Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
15157
- Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
15158
- Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
15159
- Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
15160
- Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
15161
- Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
15162
- Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
15163
- Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
15164
- Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
15165
- Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
15166
- Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
15167
- })(exports.Layer || (exports.Layer = {}));
15168
-
15169
- var ComponentCloner = /*#__PURE__*/ function() {
15170
- function ComponentCloner() {}
15171
- /**
15172
- * Clone component.
15173
- * @param source - Clone source
15174
- * @param target - Clone target
15175
- */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot) {
15176
- var cloneModes = CloneManager.getCloneMode(source.constructor);
15177
- for(var k in source){
15178
- CloneManager.cloneProperty(source, target, k, cloneModes[k]);
15179
- }
15180
- if (source._cloneTo) {
15181
- source._cloneTo(target, srcRoot, targetRoot);
15182
- }
15183
- };
15184
- return ComponentCloner;
15185
- }();
15186
-
15187
- /**
15188
- * Entity, be used as components container.
15189
- */ var Entity = /*#__PURE__*/ function(EngineObject1) {
15190
- _inherits(Entity, EngineObject1);
15191
- function Entity(engine, name) {
15192
- var _this;
15193
- _this = EngineObject1.call(this, engine) || this;
15194
- /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
15195
- /** @internal */ _this._isActiveInHierarchy = false;
15196
- /** @internal */ _this._isActiveInScene = false;
15197
- /** @internal */ _this._components = [];
15198
- /** @internal */ _this._scripts = new DisorderedArray();
15199
- /** @internal */ _this._children = [];
15200
- /** @internal */ _this._isRoot = false;
15201
- /** @internal */ _this._isActive = true;
15202
- /** @internal */ _this._siblingIndex = -1;
15203
- /** @internal */ _this._isTemplate = false;
15204
- _this._parent = null;
15205
- //--------------------------------------------------------------deprecated----------------------------------------------------------------
15206
- _this._invModelMatrix = new miniprogram.Matrix();
15207
- _this.name = name;
15208
- _this.transform = _this.addComponent(Transform);
15209
- _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
15210
- return _this;
15211
- }
15212
- var _proto = Entity.prototype;
15213
- /**
15214
- * Add component based on the component type.
15215
- * @param type - The type of the component
15216
- * @returns The component which has been added
15217
- */ _proto.addComponent = function addComponent(type) {
15218
- ComponentsDependencies._addCheck(this, type);
15219
- var component = new type(this);
15220
- this._components.push(component);
15221
- component._setActive(true, ActiveChangeFlag.All);
15222
- return component;
15223
- };
15224
- /**
15225
- * Get component which match the type.
15226
- * @param type - The type of the component
15227
- * @returns The first component which match type
15228
- */ _proto.getComponent = function getComponent(type) {
15229
- var components = this._components;
15230
- for(var i = 0, n = components.length; i < n; i++){
15231
- var component = components[i];
15232
- if (_instanceof(component, type)) {
15233
- return component;
15234
- }
15235
- }
15236
- return null;
15237
- };
15238
- /**
15239
- * Get components which match the type.
15240
- * @param type - The type of the component
15241
- * @param results - The components which match type
15242
- * @returns The components which match type
15243
- */ _proto.getComponents = function getComponents(type, results) {
15244
- results.length = 0;
15245
- var components = this._components;
15246
- for(var i = 0, n = components.length; i < n; i++){
15247
- var component = components[i];
15248
- if (_instanceof(component, type)) {
15249
- results.push(component);
15250
- }
15251
- }
15252
- return results;
15253
- };
15254
- /**
15255
- * Get the components which match the type of the entity and it's children.
15256
- * @param type - The component type
15257
- * @param results - The components collection
15258
- * @returns The components collection which match the type
15259
- */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
15260
- results.length = 0;
15261
- this._getComponentsInChildren(type, results);
15262
- return results;
15263
- };
15264
- _proto.addChild = function addChild(indexOrChild, child) {
15265
- var index;
15266
- if (typeof indexOrChild === "number") {
15267
- index = indexOrChild;
15268
- } else {
15269
- index = undefined;
15270
- child = indexOrChild;
15271
- }
15272
- if (child._isRoot) {
15273
- child._scene._removeFromEntityList(child);
15274
- child._isRoot = false;
15275
- this._addToChildrenList(index, child);
15276
- child._parent = this;
15277
- var oldScene = child._scene;
15278
- var newScene = this._scene;
15279
- var inActiveChangeFlag = ActiveChangeFlag.None;
15280
- if (!this._isActiveInHierarchy) {
15281
- child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
15282
- }
15283
- if (child._isActiveInScene) {
15284
- if (this._isActiveInScene) {
15285
- // Cross scene should inActive first and then active
15286
- oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
15287
- } else {
15288
- inActiveChangeFlag |= ActiveChangeFlag.Scene;
15289
- }
15290
- }
15291
- inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
15292
- if (child._scene !== newScene) {
15293
- Entity._traverseSetOwnerScene(child, newScene);
15294
- }
15295
- var activeChangeFlag = ActiveChangeFlag.None;
15296
- if (child._isActive) {
15297
- if (this._isActiveInHierarchy) {
15298
- !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15299
- }
15300
- if (this._isActiveInScene) {
15301
- (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
15302
- }
15303
- }
15304
- activeChangeFlag && child._processActive(activeChangeFlag);
15305
- child._setTransformDirty();
15306
- } else {
15307
- child._setParent(this, index);
15308
- }
15309
- };
15310
- /**
15311
- * Remove child entity.
15312
- * @param child - The child entity which want to be removed
15313
- */ _proto.removeChild = function removeChild(child) {
15314
- child._setParent(null);
15315
- };
15316
- /**
15317
- * @deprecated Please use `children` property instead.
15318
- * Find child entity by index.
15319
- * @param index - The index of the child entity
15320
- * @returns The component which be found
15321
- */ _proto.getChild = function getChild(index) {
15322
- return this._children[index];
15323
- };
15324
- /**
15325
- * Find entity by name.
15326
- * @param name - The name of the entity which want to be found
15327
- * @returns The component which be found
15328
- */ _proto.findByName = function findByName(name) {
15329
- if (name === this.name) {
15330
- return this;
15331
- }
15332
- var children = this._children;
15333
- for(var i = 0, n = children.length; i < n; i++){
15334
- var target = children[i].findByName(name);
15335
- if (target) {
15336
- return target;
15337
- }
15338
- }
15339
- return null;
15340
- };
15341
- /**
15342
- * Find the entity by path.
15343
- * @param path - The path fo the entity eg: /entity
15344
- * @returns The component which be found
15345
- */ _proto.findByPath = function findByPath(path) {
15346
- var splits = path.split("/");
15347
- var entity = this;
15348
- for(var i = 0, length = splits.length; i < length; ++i){
15349
- var split = splits[i];
15350
- if (split) {
15351
- entity = Entity._findChildByName(entity, split);
15352
- if (!entity) {
15353
- return null;
15354
- }
15355
- }
15356
- }
15357
- return entity;
15358
- };
15359
- /**
15360
- * Create child entity.
15361
- * @param name - The child entity's name
15362
- * @returns The child entity
15363
- */ _proto.createChild = function createChild(name) {
15364
- var child = new Entity(this.engine, name);
15365
- child.layer = this.layer;
15366
- child.parent = this;
15367
- return child;
15368
- };
15369
- /**
15370
- * Clear children entities.
15371
- */ _proto.clearChildren = function clearChildren() {
15372
- var children = this._children;
15373
- for(var i = children.length - 1; i >= 0; i--){
15374
- var child = children[i];
15375
- child._parent = null;
15376
- var activeChangeFlag = ActiveChangeFlag.None;
15377
- child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15378
- child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
15379
- activeChangeFlag && child._processInActive(activeChangeFlag);
15380
- Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
15381
- }
15382
- children.length = 0;
15383
- };
15384
- /**
15385
- * Clone.
15386
- * @returns Cloned entity
15387
- */ _proto.clone = function clone() {
15388
- var cloneEntity = this._createCloneEntity(this);
15389
- this._parseCloneEntity(this, cloneEntity, this, cloneEntity);
15390
- return cloneEntity;
15391
- };
15392
- /**
15393
- * @internal
15394
- */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
15395
- this._isTemplate = true;
15396
- this._templateResource = templateResource;
15397
- };
15398
- _proto._createCloneEntity = function _createCloneEntity(srcEntity) {
15399
- var cloneEntity = new Entity(srcEntity._engine, srcEntity.name);
15400
- var templateResource = this._templateResource;
15401
- if (templateResource) {
15402
- cloneEntity._templateResource = templateResource;
15403
- templateResource._addReferCount(1);
15404
- }
15405
- cloneEntity.layer = srcEntity.layer;
15406
- cloneEntity._isActive = srcEntity._isActive;
15407
- var cloneTransform = cloneEntity.transform;
15408
- var srcTransform = srcEntity.transform;
15409
- cloneTransform.position = srcTransform.position;
15410
- cloneTransform.rotation = srcTransform.rotation;
15411
- cloneTransform.scale = srcTransform.scale;
15412
- var children = srcEntity._children;
15413
- for(var i = 0, n = srcEntity._children.length; i < n; i++){
15414
- cloneEntity.addChild(this._createCloneEntity(children[i]));
15415
- }
15416
- return cloneEntity;
15417
- };
15418
- _proto._parseCloneEntity = function _parseCloneEntity(srcEntity, targetEntity, srcRoot, targetRoot) {
15419
- var srcChildren = srcEntity._children;
15420
- var targetChildren = targetEntity._children;
15421
- for(var i = 0, n = srcChildren.length; i < n; i++){
15422
- this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot);
15423
- }
15424
- var components = srcEntity._components;
15425
- for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
15426
- var sourceComp = components[i1];
15427
- if (!_instanceof(sourceComp, Transform)) {
15428
- var targetComp = targetEntity.addComponent(sourceComp.constructor);
15429
- ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot);
15430
- }
15431
- }
15432
- };
15433
- /**
15434
- * Destroy self.
15435
- */ _proto.destroy = function destroy() {
15436
- if (this._destroyed) {
15437
- return;
15438
- }
15439
- EngineObject1.prototype.destroy.call(this);
15440
- if (this._templateResource) {
15441
- this._isTemplate || this._templateResource._addReferCount(-1);
15442
- this._templateResource = null;
15443
- }
15444
- var components = this._components;
15445
- for(var i = components.length - 1; i >= 0; i--){
15446
- components[i].destroy();
15447
- }
15448
- this._components.length = 0;
15449
- var children = this._children;
15450
- while(children.length > 0){
15451
- children[0].destroy();
15452
- }
15453
- if (this._isRoot) {
15454
- this._scene.removeRootEntity(this);
15455
- } else {
15456
- this._setParent(null);
15457
- }
15458
- this.isActive = false;
15459
- };
15460
- /**
15461
- * @internal
15462
- */ _proto._removeComponent = function _removeComponent(component) {
15463
- ComponentsDependencies._removeCheck(this, component.constructor);
15464
- var components = this._components;
15465
- components.splice(components.indexOf(component), 1);
15466
- };
15467
- /**
15468
- * @internal
15469
- */ _proto._addScript = function _addScript(script) {
15470
- script._entityScriptsIndex = this._scripts.length;
15471
- this._scripts.add(script);
15472
- };
15473
- /**
15474
- * @internal
15475
- */ _proto._removeScript = function _removeScript(script) {
15476
- var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
15477
- replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
15478
- script._entityScriptsIndex = -1;
15479
- };
15480
- /**
15481
- * @internal
15482
- */ _proto._removeFromParent = function _removeFromParent() {
15483
- var oldParent = this._parent;
15484
- if (oldParent != null) {
15485
- var oldSibling = oldParent._children;
15486
- var index = this._siblingIndex;
15487
- oldSibling.splice(index, 1);
15488
- for(var n = oldSibling.length; index < n; index++){
15489
- oldSibling[index]._siblingIndex--;
15490
- }
15491
- this._parent = null;
15492
- this._siblingIndex = -1;
15493
- }
15494
- };
15495
- /**
15496
- * @internal
15497
- */ _proto._processActive = function _processActive(activeChangeFlag) {
15498
- if (this._activeChangedComponents) {
15499
- throw "Note: can't set the 'main inActive entity' active in hierarchy, if the operation is in main inActive entity or it's children script's onDisable Event.";
15500
- }
15501
- this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
15502
- this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
15503
- this._setActiveComponents(true, activeChangeFlag);
15504
- };
15505
- /**
15506
- * @internal
15507
- */ _proto._processInActive = function _processInActive(activeChangeFlag) {
15508
- if (this._activeChangedComponents) {
15509
- throw "Note: can't set the 'main active entity' inActive in hierarchy, if the operation is in main active entity or it's children script's onEnable Event.";
15510
- }
15511
- this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
15512
- this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
15513
- this._setActiveComponents(false, activeChangeFlag);
15514
- };
15515
- _proto._addToChildrenList = function _addToChildrenList(index, child) {
15516
- var children = this._children;
15517
- var childCount = children.length;
15518
- if (index === undefined) {
15519
- child._siblingIndex = childCount;
15520
- children.push(child);
15521
- } else {
15522
- if (index < 0 || index > childCount) {
15523
- throw "The index " + index + " is out of child list bounds " + childCount;
15524
- }
15525
- child._siblingIndex = index;
15526
- children.splice(index, 0, child);
15527
- for(var i = index + 1, n = childCount + 1; i < n; i++){
15528
- children[i]._siblingIndex++;
15529
- }
15530
- }
15531
- };
15532
- _proto._setParent = function _setParent(parent, siblingIndex) {
15533
- var oldParent = this._parent;
15534
- if (parent !== oldParent) {
15535
- this._removeFromParent();
15536
- this._parent = parent;
15537
- if (parent) {
15538
- parent._addToChildrenList(siblingIndex, this);
15539
- var oldScene = this._scene;
15540
- var parentScene = parent._scene;
15541
- var inActiveChangeFlag = ActiveChangeFlag.None;
15542
- if (!parent._isActiveInHierarchy) {
15543
- this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
15544
- }
15545
- if (parent._isActiveInScene) {
15546
- // cross scene should inActive first and then active
15547
- this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
15548
- } else {
15549
- this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
15550
- }
15551
- inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
15552
- if (oldScene !== parentScene) {
15553
- Entity._traverseSetOwnerScene(this, parentScene);
15554
- }
15555
- var activeChangeFlag = ActiveChangeFlag.None;
15556
- if (this._isActive) {
15557
- if (parent._isActiveInHierarchy) {
15558
- !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15559
- }
15560
- if (parent._isActiveInScene) {
15561
- (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
15562
- }
15563
- }
15564
- activeChangeFlag && this._processActive(activeChangeFlag);
15565
- } else {
15566
- var inActiveChangeFlag1 = ActiveChangeFlag.None;
15567
- this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
15568
- this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
15569
- inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
15570
- if (oldParent) {
15571
- Entity._traverseSetOwnerScene(this, null);
15572
- }
15573
- }
15574
- this._setTransformDirty();
15575
- }
15576
- };
15577
- _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
15578
- for(var i = this._components.length - 1; i >= 0; i--){
15579
- var component = this._components[i];
15580
- if (_instanceof(component, type)) {
15581
- results.push(component);
15582
- }
15583
- }
15584
- for(var i1 = this._children.length - 1; i1 >= 0; i1--){
15585
- this._children[i1]._getComponentsInChildren(type, results);
15586
- }
15587
- };
15588
- _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
15589
- var activeChangedComponents = this._activeChangedComponents;
15590
- for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
15591
- activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
15592
- }
15593
- this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
15594
- this._activeChangedComponents = null;
15595
- };
15596
- _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
15597
- activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
15598
- activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
15599
- var components = this._components;
15600
- for(var i = 0, n = components.length; i < n; i++){
15601
- var component = components[i];
15602
- (component.enabled || !component._awoken) && activeChangedComponents.push(component);
15603
- }
15604
- var children = this._children;
15605
- for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
15606
- var child = children[i1];
15607
- child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
15608
- }
15609
- };
15610
- _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
15611
- activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
15612
- activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
15613
- var components = this._components;
15614
- for(var i = 0, n = components.length; i < n; i++){
15615
- var component = components[i];
15616
- component.enabled && activeChangedComponents.push(component);
15617
- }
15618
- var children = this._children;
15619
- for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
15620
- var child = children[i1];
15621
- child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
15622
- }
15623
- };
15624
- _proto._setTransformDirty = function _setTransformDirty() {
15625
- if (this.transform) {
15626
- this.transform._parentChange();
15627
- } else {
15628
- for(var i = 0, len = this._children.length; i < len; i++){
15629
- this._children[i]._setTransformDirty();
15630
- }
15631
- }
15632
- };
15633
- _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
15634
- target = Math.min(target, sibling.length - 1);
15635
- if (target < 0) {
15636
- throw "Sibling index " + target + " should large than 0";
15637
- }
15638
- if (this._siblingIndex !== target) {
15639
- var oldIndex = this._siblingIndex;
15640
- if (target < oldIndex) {
15641
- for(var i = oldIndex; i >= target; i--){
15642
- var child = i == target ? this : sibling[i - 1];
15643
- sibling[i] = child;
15644
- child._siblingIndex = i;
15645
- }
15646
- } else {
15647
- for(var i1 = oldIndex; i1 <= target; i1++){
15648
- var child1 = i1 == target ? this : sibling[i1 + 1];
15649
- sibling[i1] = child1;
15650
- child1._siblingIndex = i1;
15651
- }
15652
- }
15653
- }
15654
- };
15655
- /**
15656
- * @deprecated
15657
- */ _proto.getInvModelMatrix = function getInvModelMatrix() {
15658
- if (this._inverseWorldMatFlag.flag) {
15659
- miniprogram.Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
15660
- this._inverseWorldMatFlag.flag = false;
15661
- }
15662
- return this._invModelMatrix;
15663
- };
15664
- /**
15665
- * @internal
15666
- */ Entity._findChildByName = function _findChildByName(root, name) {
15667
- var children = root._children;
15668
- for(var i = children.length - 1; i >= 0; i--){
15669
- var child = children[i];
15670
- if (child.name === name) {
15671
- return child;
15672
- }
15673
- }
15674
- return null;
15675
- };
15676
- /**
15677
- * @internal
15678
- */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
15679
- entity._scene = scene;
15680
- var children = entity._children;
15681
- for(var i = children.length - 1; i >= 0; i--){
15682
- this._traverseSetOwnerScene(children[i], scene);
15683
- }
15684
- };
15685
- _create_class(Entity, [
15686
- {
15687
- key: "isActive",
15688
- get: /**
15689
- * Whether to activate locally.
15629
+ * @remarks
15630
+ * Red and green channels represent the anisotropy direction in [-1, 1] tangent, bitangent space, to be rotated by anisotropyRotation.
15631
+ * The blue channel contains strength as [0, 1] to be multiplied by anisotropy.
15690
15632
  */ function get() {
15691
- return this._isActive;
15633
+ return this.shaderData.getTexture(PBRMaterial._anisotropyTextureProp);
15692
15634
  },
15693
15635
  set: function set(value) {
15694
- if (value !== this._isActive) {
15695
- this._isActive = value;
15696
- if (value) {
15697
- var parent = this._parent;
15698
- var activeChangeFlag = ActiveChangeFlag.None;
15699
- if (this._isRoot && this._scene._isActiveInEngine) {
15700
- activeChangeFlag |= ActiveChangeFlag.All;
15701
- } else {
15702
- var _parent, _parent1;
15703
- ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15704
- ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
15705
- }
15706
- activeChangeFlag && this._processActive(activeChangeFlag);
15707
- } else {
15708
- var activeChangeFlag1 = ActiveChangeFlag.None;
15709
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
15710
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
15711
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
15712
- }
15636
+ this.shaderData.setTexture(PBRMaterial._anisotropyTextureProp, value);
15637
+ if (value) {
15638
+ this.shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
15639
+ } else {
15640
+ this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
15713
15641
  }
15714
15642
  }
15715
- },
15643
+ }
15644
+ ]);
15645
+ return PBRMaterial;
15646
+ }(PBRBaseMaterial);
15647
+ (function() {
15648
+ PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
15649
+ })();
15650
+ (function() {
15651
+ PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
15652
+ })();
15653
+ (function() {
15654
+ PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
15655
+ })();
15656
+ (function() {
15657
+ PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
15658
+ })();
15659
+ (function() {
15660
+ PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
15661
+ })();
15662
+ (function() {
15663
+ PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
15664
+ })();
15665
+
15666
+ /**
15667
+ * PBR (Specular-Glossiness Workflow) Material.
15668
+ */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
15669
+ _inherits(PBRSpecularMaterial, PBRBaseMaterial1);
15670
+ function PBRSpecularMaterial(engine) {
15671
+ var _this;
15672
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
15673
+ _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new miniprogram.Color(1, 1, 1, 1));
15674
+ _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
15675
+ return _this;
15676
+ }
15677
+ var _proto = PBRSpecularMaterial.prototype;
15678
+ /**
15679
+ * @inheritdoc
15680
+ */ _proto.clone = function clone() {
15681
+ var dest = new PBRSpecularMaterial(this._engine);
15682
+ this.cloneTo(dest);
15683
+ return dest;
15684
+ };
15685
+ _create_class(PBRSpecularMaterial, [
15716
15686
  {
15717
- key: "isActiveInHierarchy",
15687
+ key: "specularColor",
15718
15688
  get: /**
15719
- * Whether it is active in the hierarchy.
15689
+ * Specular color.
15720
15690
  */ function get() {
15721
- return this._isActiveInHierarchy;
15691
+ return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
15692
+ },
15693
+ set: function set(value) {
15694
+ var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
15695
+ if (value !== specularColor) {
15696
+ specularColor.copyFrom(value);
15697
+ }
15722
15698
  }
15723
15699
  },
15724
15700
  {
15725
- key: "parent",
15701
+ key: "glossiness",
15726
15702
  get: /**
15727
- * The parent entity.
15703
+ * Glossiness.
15728
15704
  */ function get() {
15729
- return this._parent;
15705
+ return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
15730
15706
  },
15731
15707
  set: function set(value) {
15732
- this._setParent(value);
15708
+ this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
15733
15709
  }
15734
15710
  },
15735
15711
  {
15736
- key: "children",
15712
+ key: "specularGlossinessTexture",
15737
15713
  get: /**
15738
- * The children entities
15714
+ * Specular glossiness texture.
15715
+ * @remarks RGB is specular, A is glossiness
15739
15716
  */ function get() {
15740
- return this._children;
15717
+ return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
15718
+ },
15719
+ set: function set(value) {
15720
+ this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
15721
+ if (value) {
15722
+ this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
15723
+ } else {
15724
+ this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
15725
+ }
15741
15726
  }
15742
- },
15727
+ }
15728
+ ]);
15729
+ return PBRSpecularMaterial;
15730
+ }(PBRBaseMaterial);
15731
+ (function() {
15732
+ PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
15733
+ })();
15734
+ (function() {
15735
+ PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
15736
+ })();
15737
+ (function() {
15738
+ PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
15739
+ })();
15740
+ (function() {
15741
+ PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
15742
+ })();
15743
+
15744
+ /**
15745
+ * Unlit Material.
15746
+ */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
15747
+ _inherits(UnlitMaterial, BaseMaterial1);
15748
+ function UnlitMaterial(engine) {
15749
+ var _this;
15750
+ _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
15751
+ var shaderData = _this.shaderData;
15752
+ shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
15753
+ shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
15754
+ shaderData.setColor(UnlitMaterial._baseColorProp, new miniprogram.Color(1, 1, 1, 1));
15755
+ shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new miniprogram.Vector4(1, 1, 0, 0));
15756
+ return _this;
15757
+ }
15758
+ var _proto = UnlitMaterial.prototype;
15759
+ /**
15760
+ * @inheritdoc
15761
+ */ _proto.clone = function clone() {
15762
+ var dest = new UnlitMaterial(this._engine);
15763
+ this.cloneTo(dest);
15764
+ return dest;
15765
+ };
15766
+ _create_class(UnlitMaterial, [
15743
15767
  {
15744
- key: "childCount",
15768
+ key: "baseColor",
15745
15769
  get: /**
15746
- * @deprecated Please use `children.length` property instead.
15747
- * Number of the children entities
15770
+ * Base color.
15748
15771
  */ function get() {
15749
- return this._children.length;
15772
+ return this.shaderData.getColor(UnlitMaterial._baseColorProp);
15773
+ },
15774
+ set: function set(value) {
15775
+ var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
15776
+ if (value !== baseColor) {
15777
+ baseColor.copyFrom(value);
15778
+ }
15750
15779
  }
15751
15780
  },
15752
15781
  {
15753
- key: "scene",
15782
+ key: "baseTexture",
15754
15783
  get: /**
15755
- * The scene the entity belongs to.
15784
+ * Base texture.
15756
15785
  */ function get() {
15757
- return this._scene;
15786
+ return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
15787
+ },
15788
+ set: function set(value) {
15789
+ this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
15790
+ if (value) {
15791
+ this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
15792
+ } else {
15793
+ this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
15794
+ }
15758
15795
  }
15759
15796
  },
15760
15797
  {
15761
- key: "siblingIndex",
15798
+ key: "tilingOffset",
15762
15799
  get: /**
15763
- * The sibling index.
15800
+ * Tiling and offset of main textures.
15764
15801
  */ function get() {
15765
- return this._siblingIndex;
15802
+ return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
15766
15803
  },
15767
15804
  set: function set(value) {
15768
- if (this._siblingIndex === -1) {
15769
- throw "The entity " + this.name + " is not in the hierarchy";
15805
+ var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
15806
+ if (value !== tilingOffset) {
15807
+ tilingOffset.copyFrom(value);
15770
15808
  }
15771
- this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
15772
15809
  }
15773
15810
  }
15774
15811
  ]);
15775
- return Entity;
15776
- }(EngineObject);
15812
+ return UnlitMaterial;
15813
+ }(BaseMaterial);
15814
+
15815
+ /**
15816
+ * @internal
15817
+ */ var BasicResources = /*#__PURE__*/ function() {
15818
+ function BasicResources(engine) {
15819
+ // prettier-ignore
15820
+ var vertices = new Float32Array([
15821
+ -1,
15822
+ -1,
15823
+ 0,
15824
+ 1,
15825
+ 1,
15826
+ -1,
15827
+ 1,
15828
+ 1,
15829
+ -1,
15830
+ 1,
15831
+ 0,
15832
+ 0,
15833
+ 1,
15834
+ 1,
15835
+ 1,
15836
+ 0
15837
+ ]); // right-top
15838
+ // prettier-ignore
15839
+ var flipYVertices = new Float32Array([
15840
+ 1,
15841
+ -1,
15842
+ 1,
15843
+ 0,
15844
+ -1,
15845
+ -1,
15846
+ 0,
15847
+ 0,
15848
+ 1,
15849
+ 1,
15850
+ 1,
15851
+ 1,
15852
+ -1,
15853
+ 1,
15854
+ 0,
15855
+ 1
15856
+ ]); // left-top
15857
+ var blitMaterial = new Material(engine, Shader.find("blit"));
15858
+ blitMaterial._addReferCount(1);
15859
+ blitMaterial.renderState.depthState.enabled = false;
15860
+ blitMaterial.renderState.depthState.writeEnabled = false;
15861
+ this.blitMesh = this._createBlitMesh(engine, vertices);
15862
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
15863
+ this.blitMaterial = blitMaterial;
15864
+ }
15865
+ var _proto = BasicResources.prototype;
15866
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
15867
+ var mesh = new ModelMesh(engine);
15868
+ mesh._addReferCount(1);
15869
+ mesh.setVertexElements([
15870
+ new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
15871
+ ]);
15872
+ mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
15873
+ mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
15874
+ return mesh;
15875
+ };
15876
+ return BasicResources;
15877
+ }();
15777
15878
 
15778
15879
  /**
15779
15880
  * @internal
@@ -22127,9 +22228,10 @@ __decorate([
22127
22228
  */ _proto._updateShaderData = function _updateShaderData(shaderData) {
22128
22229
  var _this = this, spotLight = _this._spotLights, pointLight = _this._pointLights, directLight = _this._directLights;
22129
22230
  var _this1 = this, spotData = _this1._spotData, pointData = _this1._pointData, directData = _this1._directData;
22130
- var spotLightCount = spotLight.length;
22131
- var pointLightCount = pointLight.length;
22132
- var directLightCount = directLight.length;
22231
+ var maxLight = LightManager._maxLight;
22232
+ var spotLightCount = Math.min(spotLight.length, maxLight);
22233
+ var pointLightCount = Math.min(pointLight.length, maxLight);
22234
+ var directLightCount = Math.min(directLight.length, maxLight);
22133
22235
  for(var i = 0; i < spotLightCount; i++){
22134
22236
  spotLight.get(i)._appendData(i, spotData);
22135
22237
  }
@@ -27235,20 +27337,19 @@ exports.AnimatorLayerBlendingMode = void 0;
27235
27337
  var relativePath = curve.relativePath;
27236
27338
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
27237
27339
  if (targetEntity) {
27238
- var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _propertyPath;
27239
- var propertyPath = "" + curve.typeIndex + "." + curve.property;
27340
+ var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
27240
27341
  var component = curve.typeIndex > 0 ? targetEntity.getComponents(curve.type, AnimationCurveOwner._components)[curve.typeIndex] : targetEntity.getComponent(curve.type);
27241
27342
  if (!component) {
27242
27343
  continue;
27243
27344
  }
27244
27345
  var property = curve.property;
27245
- var instanceId = targetEntity.instanceId;
27346
+ var instanceId = component.instanceId;
27246
27347
  // Get owner
27247
27348
  var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
27248
27349
  var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity, component));
27249
27350
  // Get layer owner
27250
27351
  var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
27251
- var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_propertyPath = propertyPath] || (_layerPropertyOwners[_propertyPath] = curve._createCurveLayerOwner(owner));
27352
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
27252
27353
  if (mask && mask.pathMasks.length) {
27253
27354
  var _mask_getPathMask;
27254
27355
  var _mask_getPathMask_active;