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