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