@galacean/engine 1.2.0-beta.4 → 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/browser.js CHANGED
@@ -5232,7 +5232,7 @@
5232
5232
  }
5233
5233
  return cloneModes;
5234
5234
  };
5235
- CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode) {
5235
+ CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode, srcRoot, targetRoot, deepInstanceMap) {
5236
5236
  if (cloneMode === CloneMode.Ignore) {
5237
5237
  return;
5238
5238
  }
@@ -5268,22 +5268,33 @@
5268
5268
  targetPropertyA.length = length;
5269
5269
  }
5270
5270
  for(var i = 0; i < length; i++){
5271
- CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode);
5271
+ CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
5272
5272
  }
5273
5273
  break;
5274
5274
  default:
5275
- var _target, _k;
5276
- var targetOProperty = (_target = target)[_k = k] || (_target[_k] = new sourceProperty.constructor());
5277
- var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5278
- for(var _$k in sourceProperty){
5279
- CloneManager.cloneProperty(sourceProperty, targetOProperty, _$k, cloneModes[_$k]);
5280
- }
5281
- // Custom clone
5282
- if (sourceProperty._cloneTo) {
5283
- sourceProperty._cloneTo(targetOProperty);
5275
+ var targetProperty = target[k];
5276
+ // If the target property is undefined, create new instance and keep reference sharing like the source
5277
+ if (!targetProperty) {
5278
+ targetProperty = deepInstanceMap.get(sourceProperty);
5279
+ if (!targetProperty) {
5280
+ targetProperty = new sourceProperty.constructor();
5281
+ deepInstanceMap.set(sourceProperty, targetProperty);
5282
+ }
5283
+ target[k] = targetProperty;
5284
5284
  }
5285
5285
  if (sourceProperty.copyFrom) {
5286
- targetOProperty.copyFrom(sourceProperty);
5286
+ // Custom clone
5287
+ targetProperty.copyFrom(sourceProperty);
5288
+ } else {
5289
+ // Universal clone
5290
+ var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5291
+ for(var _$k in sourceProperty){
5292
+ CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
5293
+ }
5294
+ // Custom incremental clone
5295
+ if (sourceProperty._cloneTo) {
5296
+ sourceProperty._cloneTo(targetProperty, srcRoot, targetRoot);
5297
+ }
5287
5298
  }
5288
5299
  break;
5289
5300
  }
@@ -5292,9 +5303,9 @@
5292
5303
  target[k] = sourceProperty;
5293
5304
  }
5294
5305
  };
5295
- CloneManager.deepCloneObject = function deepCloneObject(source, target) {
5306
+ CloneManager.deepCloneObject = function deepCloneObject(source, target, deepInstanceMap) {
5296
5307
  for(var k in source){
5297
- CloneManager.cloneProperty(source, target, k, CloneMode.Deep);
5308
+ CloneManager.cloneProperty(source, target, k, CloneMode.Deep, null, null, deepInstanceMap);
5298
5309
  }
5299
5310
  };
5300
5311
  return CloneManager;
@@ -10429,7 +10440,7 @@
10429
10440
  return shaderData;
10430
10441
  };
10431
10442
  _proto.cloneTo = function cloneTo(target) {
10432
- CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
10443
+ CloneManager.deepCloneObject(this._macroCollection, target._macroCollection, new Map());
10433
10444
  Object.assign(target._macroMap, this._macroMap);
10434
10445
  var referCount = target._getReferCount();
10435
10446
  var propertyValueMap = this._propertyValueMap;
@@ -15764,266 +15775,735 @@
15764
15775
  PrimitiveMesh._spherePoleIdx = 0;
15765
15776
  })();
15766
15777
  /**
15767
- * Mesh skin data, equal glTF skins define
15768
- */ var Skin = /*#__PURE__*/ function(EngineObject1) {
15769
- var Skin = function Skin(name1) {
15770
- var _this;
15771
- _this = EngineObject1.call(this, null) || this;
15772
- _this.name = name1;
15773
- _this._bones = [];
15774
- _this.inverseBindMatrices = []; // inverse bind matrix array
15775
- _this.joints = []; // joints name array, element type: string
15776
- _this.skeleton = "none"; // root bone name
15777
- return _this;
15778
+ * Layer, used for bit operations.
15779
+ */ exports.Layer = void 0;
15780
+ (function(Layer) {
15781
+ Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
15782
+ Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
15783
+ Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
15784
+ Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
15785
+ Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
15786
+ Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
15787
+ Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
15788
+ Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
15789
+ Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
15790
+ Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
15791
+ Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
15792
+ Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
15793
+ Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
15794
+ Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
15795
+ Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
15796
+ Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
15797
+ Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
15798
+ Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
15799
+ Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
15800
+ Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
15801
+ Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
15802
+ Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
15803
+ Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
15804
+ Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
15805
+ Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
15806
+ Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
15807
+ Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
15808
+ Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
15809
+ Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
15810
+ Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
15811
+ Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
15812
+ Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
15813
+ Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
15814
+ Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
15815
+ })(exports.Layer || (exports.Layer = {}));
15816
+ var ComponentCloner = /*#__PURE__*/ function() {
15817
+ var ComponentCloner = function ComponentCloner() {};
15818
+ /**
15819
+ * Clone component.
15820
+ * @param source - Clone source
15821
+ * @param target - Clone target
15822
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
15823
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
15824
+ for(var k in source){
15825
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
15826
+ }
15827
+ if (source._cloneTo) {
15828
+ source._cloneTo(target, srcRoot, targetRoot);
15829
+ }
15778
15830
  };
15779
- _inherits$2(Skin, EngineObject1);
15780
- return Skin;
15781
- }(EngineObject);
15831
+ return ComponentCloner;
15832
+ }();
15782
15833
  /**
15783
- * SkinnedMeshRenderer.
15784
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
15785
- var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
15834
+ * Entity, be used as components container.
15835
+ */ var Entity = /*#__PURE__*/ function(EngineObject1) {
15836
+ var Entity = function Entity(engine, name1) {
15786
15837
  var _this;
15787
- _this = MeshRenderer1.call(this, entity) || this;
15788
- _this._localBounds = new BoundingBox();
15789
- _this._jointDataCreateCache = new Vector2(-1, -1);
15790
- _this._skin = null;
15791
- var rhi = _this.entity.engine._hardwareRenderer;
15792
- var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
15793
- // Limit size to 256 to avoid some problem:
15794
- // 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!
15795
- // 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.
15796
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
15797
- _this._maxVertexUniformVectors = maxVertexUniformVectors;
15798
- _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
15799
- var localBounds = _this._localBounds;
15800
- // @ts-ignore
15801
- localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
15802
- // @ts-ignore
15803
- localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
15838
+ _this = EngineObject1.call(this, engine) || this;
15839
+ /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
15840
+ /** @internal */ _this._isActiveInHierarchy = false;
15841
+ /** @internal */ _this._isActiveInScene = false;
15842
+ /** @internal */ _this._components = [];
15843
+ /** @internal */ _this._scripts = new DisorderedArray();
15844
+ /** @internal */ _this._children = [];
15845
+ /** @internal */ _this._isRoot = false;
15846
+ /** @internal */ _this._isActive = true;
15847
+ /** @internal */ _this._siblingIndex = -1;
15848
+ /** @internal */ _this._isTemplate = false;
15849
+ _this._parent = null;
15850
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
15851
+ _this._invModelMatrix = new Matrix();
15852
+ _this.name = name1;
15853
+ _this.transform = _this.addComponent(Transform);
15854
+ _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
15804
15855
  return _this;
15805
15856
  };
15806
- _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
15807
- var _proto = SkinnedMeshRenderer.prototype;
15857
+ _inherits$2(Entity, EngineObject1);
15858
+ var _proto = Entity.prototype;
15808
15859
  /**
15809
- * @internal
15810
- */ _proto.update = function update() {
15811
- var _this = this, skin = _this._skin, bones = _this._bones;
15812
- if (skin && bones) {
15813
- // @todo: can optimize when share skin
15814
- var jointMatrices = this._jointMatrices;
15815
- var bindMatrices = skin.inverseBindMatrices;
15816
- var _this__rootBone;
15817
- var worldToLocal = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this.entity).getInvModelMatrix();
15818
- for(var i = bones.length - 1; i >= 0; i--){
15819
- var bone = bones[i];
15820
- var offset = i * 16;
15821
- if (bone) {
15822
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, jointMatrices, offset);
15823
- } else {
15824
- jointMatrices.set(bindMatrices[i].elements, offset);
15825
- }
15826
- Utils._floatMatrixMultiply(worldToLocal, jointMatrices, offset, jointMatrices, offset);
15860
+ * Add component based on the component type.
15861
+ * @param type - The type of the component
15862
+ * @returns The component which has been added
15863
+ */ _proto.addComponent = function addComponent(type) {
15864
+ ComponentsDependencies._addCheck(this, type);
15865
+ var component = new type(this);
15866
+ this._components.push(component);
15867
+ component._setActive(true, ActiveChangeFlag.All);
15868
+ return component;
15869
+ };
15870
+ /**
15871
+ * Get component which match the type.
15872
+ * @param type - The type of the component
15873
+ * @returns The first component which match type
15874
+ */ _proto.getComponent = function getComponent(type) {
15875
+ var components = this._components;
15876
+ for(var i = 0, n = components.length; i < n; i++){
15877
+ var component = components[i];
15878
+ if (_instanceof1$2(component, type)) {
15879
+ return component;
15827
15880
  }
15828
15881
  }
15882
+ return null;
15829
15883
  };
15830
- _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
15831
- var entity = this.entity;
15832
- var _this__rootBone;
15833
- var worldMatrix = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : entity).transform.worldMatrix;
15834
- if (onlyMVP) {
15835
- this._updateMVPShaderData(context, worldMatrix);
15836
- return;
15884
+ /**
15885
+ * Get components which match the type.
15886
+ * @param type - The type of the component
15887
+ * @param results - The components which match type
15888
+ * @returns The components which match type
15889
+ */ _proto.getComponents = function getComponents(type, results) {
15890
+ results.length = 0;
15891
+ var components = this._components;
15892
+ for(var i = 0, n = components.length; i < n; i++){
15893
+ var component = components[i];
15894
+ if (_instanceof1$2(component, type)) {
15895
+ results.push(component);
15896
+ }
15837
15897
  }
15838
- this._updateTransformShaderData(context, worldMatrix);
15839
- var shaderData = this.shaderData;
15840
- var mesh = this.mesh;
15841
- var blendShapeManager = mesh._blendShapeManager;
15842
- blendShapeManager._updateShaderData(shaderData, this);
15843
- var bones = this._bones;
15844
- if (bones) {
15845
- var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
15846
- var jointCount = bones.length;
15847
- var jointDataCreateCache = this._jointDataCreateCache;
15848
- var jointCountChange = jointCount !== jointDataCreateCache.x;
15849
- if (jointCountChange || bsUniformOccupiesCount !== jointDataCreateCache.y) {
15850
- // directly use max joint count to avoid shader recompile
15851
- // @TODO: different shader type should use different count, not always 44
15852
- var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
15853
- if (jointCount > remainUniformJointCount) {
15854
- var engine = this.engine;
15855
- if (engine._hardwareRenderer.canIUseMoreJoints) {
15856
- if (jointCountChange) {
15857
- var _this__jointTexture;
15858
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
15859
- this._jointTexture = new Texture2D(engine, 4, jointCount, exports.TextureFormat.R32G32B32A32, false);
15860
- this._jointTexture.filterMode = exports.TextureFilterMode.Point;
15861
- this._jointTexture.isGCIgnored = true;
15862
- }
15863
- shaderData.disableMacro("RENDERER_JOINTS_NUM");
15864
- shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
15865
- shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
15866
- } else {
15867
- 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);
15868
- }
15898
+ return results;
15899
+ };
15900
+ /**
15901
+ * Get the components which match the type of the entity and it's children.
15902
+ * @param type - The component type
15903
+ * @param results - The components collection
15904
+ * @returns The components collection which match the type
15905
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
15906
+ results.length = 0;
15907
+ this._getComponentsInChildren(type, results);
15908
+ return results;
15909
+ };
15910
+ _proto.addChild = function addChild(indexOrChild, child) {
15911
+ var index;
15912
+ if (typeof indexOrChild === "number") {
15913
+ index = indexOrChild;
15914
+ } else {
15915
+ index = undefined;
15916
+ child = indexOrChild;
15917
+ }
15918
+ if (child._isRoot) {
15919
+ child._scene._removeFromEntityList(child);
15920
+ child._isRoot = false;
15921
+ this._addToChildrenList(index, child);
15922
+ child._parent = this;
15923
+ var oldScene = child._scene;
15924
+ var newScene = this._scene;
15925
+ var inActiveChangeFlag = ActiveChangeFlag.None;
15926
+ if (!this._isActiveInHierarchy) {
15927
+ child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
15928
+ }
15929
+ if (child._isActiveInScene) {
15930
+ if (this._isActiveInScene) {
15931
+ // Cross scene should inActive first and then active
15932
+ oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
15869
15933
  } else {
15870
- var _this__jointTexture1;
15871
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
15872
- shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
15873
- shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
15874
- shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, this._jointMatrices);
15934
+ inActiveChangeFlag |= ActiveChangeFlag.Scene;
15875
15935
  }
15876
- jointDataCreateCache.set(jointCount, bsUniformOccupiesCount);
15877
15936
  }
15878
- if (this._jointTexture) {
15879
- this._jointTexture.setPixelBuffer(this._jointMatrices);
15937
+ inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
15938
+ if (child._scene !== newScene) {
15939
+ Entity._traverseSetOwnerScene(child, newScene);
15940
+ }
15941
+ var activeChangeFlag = ActiveChangeFlag.None;
15942
+ if (child._isActive) {
15943
+ if (this._isActiveInHierarchy) {
15944
+ !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15945
+ }
15946
+ if (this._isActiveInScene) {
15947
+ (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
15948
+ }
15880
15949
  }
15950
+ activeChangeFlag && child._processActive(activeChangeFlag);
15951
+ child._setTransformDirty();
15952
+ } else {
15953
+ child._setParent(this, index);
15881
15954
  }
15882
- var layer = entity.layer;
15883
- this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
15884
15955
  };
15885
15956
  /**
15886
- * @internal
15887
- */ _proto._onDestroy = function _onDestroy() {
15888
- var _this__jointTexture;
15889
- MeshRenderer1.prototype._onDestroy.call(this);
15890
- this._rootBone = null;
15891
- this._jointDataCreateCache = null;
15892
- this._skin = null;
15893
- this._blendShapeWeights = null;
15894
- this._localBounds = null;
15895
- this._jointMatrices = null;
15896
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
15897
- this._jointTexture = null;
15898
- this._bones = null;
15957
+ * Remove child entity.
15958
+ * @param child - The child entity which want to be removed
15959
+ */ _proto.removeChild = function removeChild(child) {
15960
+ child._setParent(null);
15899
15961
  };
15900
15962
  /**
15901
- * @internal
15902
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
15903
- MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
15904
- var paths = new Array();
15905
- // Clone rootBone
15906
- if (this.rootBone) {
15907
- var success = this._getEntityHierarchyPath(srcRoot, this.rootBone, paths);
15908
- target.rootBone = success ? this._getEntityByHierarchyPath(targetRoot, paths) : this.rootBone;
15963
+ * @deprecated Please use `children` property instead.
15964
+ * Find child entity by index.
15965
+ * @param index - The index of the child entity
15966
+ * @returns The component which be found
15967
+ */ _proto.getChild = function getChild(index) {
15968
+ return this._children[index];
15969
+ };
15970
+ /**
15971
+ * Find entity by name.
15972
+ * @param name - The name of the entity which want to be found
15973
+ * @returns The component which be found
15974
+ */ _proto.findByName = function findByName(name1) {
15975
+ if (name1 === this.name) {
15976
+ return this;
15909
15977
  }
15910
- // Clone bones
15911
- var bones = this._bones;
15912
- if (bones) {
15913
- var boneCount = bones.length;
15914
- var destBones = new Array(boneCount);
15915
- for(var i = 0; i < boneCount; i++){
15916
- var bone = bones[i];
15917
- var success1 = this._getEntityHierarchyPath(srcRoot, bone, paths);
15918
- destBones[i] = success1 ? this._getEntityByHierarchyPath(targetRoot, paths) : bone;
15978
+ var children = this._children;
15979
+ for(var i = 0, n = children.length; i < n; i++){
15980
+ var target = children[i].findByName(name1);
15981
+ if (target) {
15982
+ return target;
15919
15983
  }
15920
- target.bones = destBones;
15921
15984
  }
15922
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
15985
+ return null;
15923
15986
  };
15924
15987
  /**
15925
- * @internal
15926
- */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
15927
- var _this__rootBone;
15928
- ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this._entity).transform._updateFlagManager.addListener(this._onTransformChanged);
15988
+ * Find the entity by path.
15989
+ * @param path - The path fo the entity eg: /entity
15990
+ * @returns The component which be found
15991
+ */ _proto.findByPath = function findByPath(path) {
15992
+ var splits = path.split("/");
15993
+ var entity = this;
15994
+ for(var i = 0, length = splits.length; i < length; ++i){
15995
+ var split = splits[i];
15996
+ if (split) {
15997
+ entity = Entity._findChildByName(entity, split);
15998
+ if (!entity) {
15999
+ return null;
16000
+ }
16001
+ }
16002
+ }
16003
+ return entity;
15929
16004
  };
15930
16005
  /**
15931
- * @internal
15932
- */ _proto._unRegisterEntityTransformListener = function _unRegisterEntityTransformListener() {
15933
- var _this__rootBone;
15934
- ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this._entity).transform._updateFlagManager.removeListener(this._onTransformChanged);
16006
+ * Create child entity.
16007
+ * @param name - The child entity's name
16008
+ * @returns The child entity
16009
+ */ _proto.createChild = function createChild(name1) {
16010
+ var child = new Entity(this.engine, name1);
16011
+ child.layer = this.layer;
16012
+ child.parent = this;
16013
+ return child;
16014
+ };
16015
+ /**
16016
+ * Clear children entities.
16017
+ */ _proto.clearChildren = function clearChildren() {
16018
+ var children = this._children;
16019
+ for(var i = children.length - 1; i >= 0; i--){
16020
+ var child = children[i];
16021
+ child._parent = null;
16022
+ var activeChangeFlag = ActiveChangeFlag.None;
16023
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16024
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
16025
+ activeChangeFlag && child._processInActive(activeChangeFlag);
16026
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
16027
+ }
16028
+ children.length = 0;
16029
+ };
16030
+ /**
16031
+ * Clone this entity include children and components.
16032
+ * @returns Cloned entity
16033
+ */ _proto.clone = function clone() {
16034
+ var cloneEntity = this._createCloneEntity(this);
16035
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
16036
+ return cloneEntity;
15935
16037
  };
15936
16038
  /**
15937
16039
  * @internal
15938
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
15939
- if (this._rootBone) {
15940
- var localBounds = this._localBounds;
15941
- var worldMatrix = this._rootBone.transform.worldMatrix;
15942
- BoundingBox.transform(localBounds, worldMatrix, worldBounds);
15943
- } else {
15944
- MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
16040
+ */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
16041
+ this._isTemplate = true;
16042
+ this._templateResource = templateResource;
16043
+ };
16044
+ _proto._createCloneEntity = function _createCloneEntity(srcEntity) {
16045
+ var cloneEntity = new Entity(srcEntity._engine, srcEntity.name);
16046
+ var templateResource = this._templateResource;
16047
+ if (templateResource) {
16048
+ cloneEntity._templateResource = templateResource;
16049
+ templateResource._addReferCount(1);
16050
+ }
16051
+ cloneEntity.layer = srcEntity.layer;
16052
+ cloneEntity._isActive = srcEntity._isActive;
16053
+ var cloneTransform = cloneEntity.transform;
16054
+ var srcTransform = srcEntity.transform;
16055
+ cloneTransform.position = srcTransform.position;
16056
+ cloneTransform.rotation = srcTransform.rotation;
16057
+ cloneTransform.scale = srcTransform.scale;
16058
+ var children = srcEntity._children;
16059
+ for(var i = 0, n = srcEntity._children.length; i < n; i++){
16060
+ cloneEntity.addChild(this._createCloneEntity(children[i]));
15945
16061
  }
16062
+ return cloneEntity;
15946
16063
  };
15947
- _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
15948
- var mesh = this._mesh;
15949
- var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
15950
- var lastBlendShapeWeights = this._blendShapeWeights;
15951
- if (lastBlendShapeWeights) {
15952
- var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
15953
- if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
15954
- var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
15955
- if (newBlendShapeCount > lastBlendShapeWeightsCount) {
15956
- newBlendShapeWeights.set(lastBlendShapeWeights);
15957
- } else {
15958
- for(var i = 0; i < newBlendShapeCount; i++){
15959
- newBlendShapeWeights[i] = lastBlendShapeWeights[i];
15960
- }
15961
- }
15962
- this._blendShapeWeights = newBlendShapeWeights;
16064
+ _proto._parseCloneEntity = function _parseCloneEntity(src, target, srcRoot, targetRoot, deepInstanceMap) {
16065
+ var srcChildren = src._children;
16066
+ var targetChildren = target._children;
16067
+ for(var i = 0, n = srcChildren.length; i < n; i++){
16068
+ this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot, deepInstanceMap);
16069
+ }
16070
+ var components = src._components;
16071
+ for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
16072
+ var sourceComp = components[i1];
16073
+ if (!_instanceof1$2(sourceComp, Transform)) {
16074
+ var targetComp = target.addComponent(sourceComp.constructor);
16075
+ ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot, deepInstanceMap);
15963
16076
  }
16077
+ }
16078
+ };
16079
+ /**
16080
+ * Destroy self.
16081
+ */ _proto.destroy = function destroy() {
16082
+ if (this._destroyed) {
16083
+ return;
16084
+ }
16085
+ EngineObject1.prototype.destroy.call(this);
16086
+ if (this._templateResource) {
16087
+ this._isTemplate || this._templateResource._addReferCount(-1);
16088
+ this._templateResource = null;
16089
+ }
16090
+ var components = this._components;
16091
+ for(var i = components.length - 1; i >= 0; i--){
16092
+ components[i].destroy();
16093
+ }
16094
+ this._components.length = 0;
16095
+ var children = this._children;
16096
+ while(children.length > 0){
16097
+ children[0].destroy();
16098
+ }
16099
+ if (this._isRoot) {
16100
+ this._scene.removeRootEntity(this);
15964
16101
  } else {
15965
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16102
+ this._setParent(null);
15966
16103
  }
16104
+ this.isActive = false;
15967
16105
  };
15968
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
15969
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16106
+ /**
16107
+ * @internal
16108
+ */ _proto._removeComponent = function _removeComponent(component) {
16109
+ ComponentsDependencies._removeCheck(this, component.constructor);
16110
+ var components = this._components;
16111
+ components.splice(components.indexOf(component), 1);
15970
16112
  };
15971
- _proto._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
15972
- inversePath.length = 0;
15973
- while(searchEntity !== rootEntity){
15974
- var parent = searchEntity.parent;
15975
- if (!parent) {
15976
- return false;
16113
+ /**
16114
+ * @internal
16115
+ */ _proto._addScript = function _addScript(script) {
16116
+ script._entityScriptsIndex = this._scripts.length;
16117
+ this._scripts.add(script);
16118
+ };
16119
+ /**
16120
+ * @internal
16121
+ */ _proto._removeScript = function _removeScript(script) {
16122
+ var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
16123
+ replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
16124
+ script._entityScriptsIndex = -1;
16125
+ };
16126
+ /**
16127
+ * @internal
16128
+ */ _proto._removeFromParent = function _removeFromParent() {
16129
+ var oldParent = this._parent;
16130
+ if (oldParent != null) {
16131
+ var oldSibling = oldParent._children;
16132
+ var index = this._siblingIndex;
16133
+ oldSibling.splice(index, 1);
16134
+ for(var n = oldSibling.length; index < n; index++){
16135
+ oldSibling[index]._siblingIndex--;
15977
16136
  }
15978
- inversePath.push(searchEntity.siblingIndex);
15979
- searchEntity = parent;
16137
+ this._parent = null;
16138
+ this._siblingIndex = -1;
15980
16139
  }
15981
- return true;
15982
16140
  };
15983
16141
  /**
15984
16142
  * @internal
15985
- */ _proto._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
15986
- var entity = rootEntity;
15987
- for(var i = inversePath.length - 1; i >= 0; i--){
15988
- entity = entity.children[inversePath[i]];
16143
+ */ _proto._processActive = function _processActive(activeChangeFlag) {
16144
+ if (this._activeChangedComponents) {
16145
+ 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.";
15989
16146
  }
15990
- return entity;
16147
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16148
+ this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16149
+ this._setActiveComponents(true, activeChangeFlag);
15991
16150
  };
15992
- _create_class$2(SkinnedMeshRenderer, [
15993
- {
15994
- key: "blendShapeWeights",
15995
- get: /**
15996
- * The weights of the BlendShapes.
15997
- * @remarks Array index is BlendShape index.
15998
- */ function get() {
15999
- this._checkBlendShapeWeightLength();
16000
- return this._blendShapeWeights;
16001
- },
16002
- set: function set(value) {
16003
- this._checkBlendShapeWeightLength();
16004
- var blendShapeWeights = this._blendShapeWeights;
16005
- if (value.length <= blendShapeWeights.length) {
16006
- blendShapeWeights.set(value);
16007
- } else {
16008
- for(var i = 0, n = blendShapeWeights.length; i < n; i++){
16009
- blendShapeWeights[i] = value[i];
16010
- }
16011
- }
16151
+ /**
16152
+ * @internal
16153
+ */ _proto._processInActive = function _processInActive(activeChangeFlag) {
16154
+ if (this._activeChangedComponents) {
16155
+ 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.";
16156
+ }
16157
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16158
+ this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16159
+ this._setActiveComponents(false, activeChangeFlag);
16160
+ };
16161
+ _proto._addToChildrenList = function _addToChildrenList(index, child) {
16162
+ var children = this._children;
16163
+ var childCount = children.length;
16164
+ if (index === undefined) {
16165
+ child._siblingIndex = childCount;
16166
+ children.push(child);
16167
+ } else {
16168
+ if (index < 0 || index > childCount) {
16169
+ throw "The index " + index + " is out of child list bounds " + childCount;
16012
16170
  }
16013
- },
16014
- {
16015
- key: "localBounds",
16016
- get: /**
16017
- * Local bounds.
16018
- */ function get() {
16019
- return this._localBounds;
16020
- },
16021
- set: function set(value) {
16022
- if (this._localBounds !== value) {
16023
- this._localBounds.copyFrom(value);
16024
- }
16171
+ child._siblingIndex = index;
16172
+ children.splice(index, 0, child);
16173
+ for(var i = index + 1, n = childCount + 1; i < n; i++){
16174
+ children[i]._siblingIndex++;
16025
16175
  }
16026
- },
16176
+ }
16177
+ };
16178
+ _proto._setParent = function _setParent(parent, siblingIndex) {
16179
+ var oldParent = this._parent;
16180
+ if (parent !== oldParent) {
16181
+ this._removeFromParent();
16182
+ this._parent = parent;
16183
+ if (parent) {
16184
+ parent._addToChildrenList(siblingIndex, this);
16185
+ var oldScene = this._scene;
16186
+ var parentScene = parent._scene;
16187
+ var inActiveChangeFlag = ActiveChangeFlag.None;
16188
+ if (!parent._isActiveInHierarchy) {
16189
+ this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
16190
+ }
16191
+ if (parent._isActiveInScene) {
16192
+ // cross scene should inActive first and then active
16193
+ this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16194
+ } else {
16195
+ this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16196
+ }
16197
+ inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
16198
+ if (oldScene !== parentScene) {
16199
+ Entity._traverseSetOwnerScene(this, parentScene);
16200
+ }
16201
+ var activeChangeFlag = ActiveChangeFlag.None;
16202
+ if (this._isActive) {
16203
+ if (parent._isActiveInHierarchy) {
16204
+ !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16205
+ }
16206
+ if (parent._isActiveInScene) {
16207
+ (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16208
+ }
16209
+ }
16210
+ activeChangeFlag && this._processActive(activeChangeFlag);
16211
+ } else {
16212
+ var inActiveChangeFlag1 = ActiveChangeFlag.None;
16213
+ this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16214
+ this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
16215
+ inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
16216
+ if (oldParent) {
16217
+ Entity._traverseSetOwnerScene(this, null);
16218
+ }
16219
+ }
16220
+ this._setTransformDirty();
16221
+ }
16222
+ };
16223
+ _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
16224
+ for(var i = this._components.length - 1; i >= 0; i--){
16225
+ var component = this._components[i];
16226
+ if (_instanceof1$2(component, type)) {
16227
+ results.push(component);
16228
+ }
16229
+ }
16230
+ for(var i1 = this._children.length - 1; i1 >= 0; i1--){
16231
+ this._children[i1]._getComponentsInChildren(type, results);
16232
+ }
16233
+ };
16234
+ _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
16235
+ var activeChangedComponents = this._activeChangedComponents;
16236
+ for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
16237
+ activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
16238
+ }
16239
+ this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
16240
+ this._activeChangedComponents = null;
16241
+ };
16242
+ _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16243
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
16244
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
16245
+ var components = this._components;
16246
+ for(var i = 0, n = components.length; i < n; i++){
16247
+ var component = components[i];
16248
+ (component.enabled || !component._awoken) && activeChangedComponents.push(component);
16249
+ }
16250
+ var children = this._children;
16251
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16252
+ var child = children[i1];
16253
+ child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16254
+ }
16255
+ };
16256
+ _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16257
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
16258
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
16259
+ var components = this._components;
16260
+ for(var i = 0, n = components.length; i < n; i++){
16261
+ var component = components[i];
16262
+ component.enabled && activeChangedComponents.push(component);
16263
+ }
16264
+ var children = this._children;
16265
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16266
+ var child = children[i1];
16267
+ child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16268
+ }
16269
+ };
16270
+ _proto._setTransformDirty = function _setTransformDirty() {
16271
+ if (this.transform) {
16272
+ this.transform._parentChange();
16273
+ } else {
16274
+ for(var i = 0, len = this._children.length; i < len; i++){
16275
+ this._children[i]._setTransformDirty();
16276
+ }
16277
+ }
16278
+ };
16279
+ _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
16280
+ target = Math.min(target, sibling.length - 1);
16281
+ if (target < 0) {
16282
+ throw "Sibling index " + target + " should large than 0";
16283
+ }
16284
+ if (this._siblingIndex !== target) {
16285
+ var oldIndex = this._siblingIndex;
16286
+ if (target < oldIndex) {
16287
+ for(var i = oldIndex; i >= target; i--){
16288
+ var child = i == target ? this : sibling[i - 1];
16289
+ sibling[i] = child;
16290
+ child._siblingIndex = i;
16291
+ }
16292
+ } else {
16293
+ for(var i1 = oldIndex; i1 <= target; i1++){
16294
+ var child1 = i1 == target ? this : sibling[i1 + 1];
16295
+ sibling[i1] = child1;
16296
+ child1._siblingIndex = i1;
16297
+ }
16298
+ }
16299
+ }
16300
+ };
16301
+ /**
16302
+ * @deprecated
16303
+ */ _proto.getInvModelMatrix = function getInvModelMatrix() {
16304
+ if (this._inverseWorldMatFlag.flag) {
16305
+ Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
16306
+ this._inverseWorldMatFlag.flag = false;
16307
+ }
16308
+ return this._invModelMatrix;
16309
+ };
16310
+ /**
16311
+ * @internal
16312
+ */ Entity._findChildByName = function _findChildByName(root, name1) {
16313
+ var children = root._children;
16314
+ for(var i = children.length - 1; i >= 0; i--){
16315
+ var child = children[i];
16316
+ if (child.name === name1) {
16317
+ return child;
16318
+ }
16319
+ }
16320
+ return null;
16321
+ };
16322
+ /**
16323
+ * @internal
16324
+ */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
16325
+ entity._scene = scene;
16326
+ var children = entity._children;
16327
+ for(var i = children.length - 1; i >= 0; i--){
16328
+ this._traverseSetOwnerScene(children[i], scene);
16329
+ }
16330
+ };
16331
+ /**
16332
+ * @internal
16333
+ */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
16334
+ inversePath.length = 0;
16335
+ while(searchEntity !== rootEntity){
16336
+ var parent = searchEntity.parent;
16337
+ if (!parent) {
16338
+ return false;
16339
+ }
16340
+ inversePath.push(searchEntity.siblingIndex);
16341
+ searchEntity = parent;
16342
+ }
16343
+ return true;
16344
+ };
16345
+ /**
16346
+ * @internal
16347
+ */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
16348
+ var entity = rootEntity;
16349
+ for(var i = inversePath.length - 1; i >= 0; i--){
16350
+ entity = entity.children[inversePath[i]];
16351
+ }
16352
+ return entity;
16353
+ };
16354
+ _create_class$2(Entity, [
16355
+ {
16356
+ key: "isActive",
16357
+ get: /**
16358
+ * Whether to activate locally.
16359
+ */ function get() {
16360
+ return this._isActive;
16361
+ },
16362
+ set: function set(value) {
16363
+ if (value !== this._isActive) {
16364
+ this._isActive = value;
16365
+ if (value) {
16366
+ var parent = this._parent;
16367
+ var activeChangeFlag = ActiveChangeFlag.None;
16368
+ if (this._isRoot && this._scene._isActiveInEngine) {
16369
+ activeChangeFlag |= ActiveChangeFlag.All;
16370
+ } else {
16371
+ var _parent, _parent1;
16372
+ ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16373
+ ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16374
+ }
16375
+ activeChangeFlag && this._processActive(activeChangeFlag);
16376
+ } else {
16377
+ var activeChangeFlag1 = ActiveChangeFlag.None;
16378
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16379
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
16380
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
16381
+ }
16382
+ }
16383
+ }
16384
+ },
16385
+ {
16386
+ key: "isActiveInHierarchy",
16387
+ get: /**
16388
+ * Whether it is active in the hierarchy.
16389
+ */ function get() {
16390
+ return this._isActiveInHierarchy;
16391
+ }
16392
+ },
16393
+ {
16394
+ key: "parent",
16395
+ get: /**
16396
+ * The parent entity.
16397
+ */ function get() {
16398
+ return this._parent;
16399
+ },
16400
+ set: function set(value) {
16401
+ this._setParent(value);
16402
+ }
16403
+ },
16404
+ {
16405
+ key: "children",
16406
+ get: /**
16407
+ * The children entities
16408
+ */ function get() {
16409
+ return this._children;
16410
+ }
16411
+ },
16412
+ {
16413
+ key: "childCount",
16414
+ get: /**
16415
+ * @deprecated Please use `children.length` property instead.
16416
+ * Number of the children entities
16417
+ */ function get() {
16418
+ return this._children.length;
16419
+ }
16420
+ },
16421
+ {
16422
+ key: "scene",
16423
+ get: /**
16424
+ * The scene the entity belongs to.
16425
+ */ function get() {
16426
+ return this._scene;
16427
+ }
16428
+ },
16429
+ {
16430
+ key: "siblingIndex",
16431
+ get: /**
16432
+ * The sibling index.
16433
+ */ function get() {
16434
+ return this._siblingIndex;
16435
+ },
16436
+ set: function set(value) {
16437
+ if (this._siblingIndex === -1) {
16438
+ throw "The entity " + this.name + " is not in the hierarchy";
16439
+ }
16440
+ this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
16441
+ }
16442
+ }
16443
+ ]);
16444
+ return Entity;
16445
+ }(EngineObject);
16446
+ /**
16447
+ * Skin used for skinned mesh renderer.
16448
+ */ var Skin = /*#__PURE__*/ function(EngineObject1) {
16449
+ var Skin = function Skin(name1) {
16450
+ var _this;
16451
+ _this = EngineObject1.call(this, null) || this;
16452
+ _this.name = name1;
16453
+ _this.inverseBindMatrices = new Array();
16454
+ _this._updatedManager = new UpdateFlagManager();
16455
+ _this._bones = new Array();
16456
+ _this._updateMark = -1;
16457
+ _this.joints = [];
16458
+ return _this;
16459
+ };
16460
+ _inherits$2(Skin, EngineObject1);
16461
+ var _proto = Skin.prototype;
16462
+ /**
16463
+ * @internal
16464
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
16465
+ if (this._updateMark === renderer.engine.time.frameCount) {
16466
+ return;
16467
+ }
16468
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
16469
+ var _this_rootBone;
16470
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
16471
+ for(var i = bones.length - 1; i >= 0; i--){
16472
+ var bone = bones[i];
16473
+ var offset = i * 16;
16474
+ if (bone) {
16475
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
16476
+ } else {
16477
+ skinMatrices.set(bindMatrices[i].elements, offset);
16478
+ }
16479
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
16480
+ }
16481
+ this._updateMark = renderer.engine.time.frameCount;
16482
+ };
16483
+ /**
16484
+ * @internal
16485
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16486
+ var paths = new Array();
16487
+ // Clone rootBone
16488
+ var rootBone = this.rootBone;
16489
+ if (rootBone) {
16490
+ var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
16491
+ target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
16492
+ }
16493
+ // Clone bones
16494
+ var bones = this.bones;
16495
+ if (bones.length > 0) {
16496
+ var boneCount = bones.length;
16497
+ var destBones = new Array(boneCount);
16498
+ for(var i = 0; i < boneCount; i++){
16499
+ var bone = bones[i];
16500
+ var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
16501
+ destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
16502
+ }
16503
+ target.bones = destBones;
16504
+ }
16505
+ };
16506
+ _create_class$2(Skin, [
16027
16507
  {
16028
16508
  key: "rootBone",
16029
16509
  get: /**
@@ -16033,205 +16513,470 @@
16033
16513
  },
16034
16514
  set: function set(value) {
16035
16515
  if (this._rootBone !== value) {
16036
- this._unRegisterEntityTransformListener();
16516
+ this._updatedManager.dispatch(1, value);
16037
16517
  this._rootBone = value;
16038
- this._registerEntityTransformListener();
16039
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16040
16518
  }
16041
16519
  }
16042
16520
  },
16043
16521
  {
16044
16522
  key: "bones",
16045
16523
  get: /**
16046
- * Bones of the SkinnedMeshRenderer.
16524
+ * Bones of the skin.
16047
16525
  */ function get() {
16048
16526
  return this._bones;
16049
16527
  },
16050
16528
  set: function set(value) {
16051
- if (this._bones !== value) {
16052
- var _this__bones, _value;
16053
- var _this__bones_length;
16054
- var lastBoneCount = (_this__bones_length = (_this__bones = this._bones) == null ? void 0 : _this__bones.length) != null ? _this__bones_length : 0;
16055
- var _value_length;
16056
- var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
16057
- if (lastBoneCount !== boneCount) {
16058
- var shaderData = this.shaderData;
16059
- if (boneCount > 0) {
16060
- this._jointMatrices = new Float32Array(boneCount * 16);
16061
- shaderData.enableMacro("RENDERER_HAS_SKIN");
16062
- shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, boneCount);
16063
- } else {
16064
- this._jointMatrices = null;
16065
- shaderData.disableMacro("RENDERER_HAS_SKIN");
16066
- }
16067
- }
16068
- this._bones = value;
16529
+ var _value;
16530
+ var bones = this._bones;
16531
+ var _value_length;
16532
+ var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
16533
+ var lastBoneCount = bones.length;
16534
+ bones.length = boneCount;
16535
+ for(var i = 0; i < boneCount; i++){
16536
+ bones[i] = value[i];
16537
+ }
16538
+ if (lastBoneCount !== boneCount) {
16539
+ this._skinMatrices = new Float32Array(boneCount * 16);
16540
+ this._updatedManager.dispatch(0, boneCount);
16069
16541
  }
16070
16542
  }
16071
16543
  },
16072
16544
  {
16073
- key: "skin",
16074
- get: /**
16075
- * @deprecated
16076
- * Skin Object.
16077
- *
16078
- * If you want get `skeleton`, use {@link SkinnedMeshRenderer.rootBone} instead.
16079
- * If you want get `bones`, use {@link SkinnedMeshRenderer.bones} instead.
16080
- * `inverseBindMatrices` will migrate to mesh in the future.
16081
- *
16082
- * @remarks `rootBone` and `bones` will not update when `skin` changed.
16083
- */ function get() {
16084
- return this._skin;
16545
+ key: "skeleton",
16546
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
16547
+ var _this_rootBone;
16548
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
16085
16549
  },
16086
16550
  set: function set(value) {
16087
- this._skin = value;
16551
+ var rootBone = this._rootBone;
16552
+ if (rootBone) {
16553
+ rootBone.name = value;
16554
+ }
16088
16555
  }
16089
16556
  }
16090
16557
  ]);
16091
- return SkinnedMeshRenderer;
16092
- }(MeshRenderer);
16093
- (function() {
16094
- SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
16095
- })();
16096
- (function() {
16097
- SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
16098
- })();
16099
- (function() {
16100
- SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
16101
- })();
16558
+ return Skin;
16559
+ }(EngineObject);
16102
16560
  __decorate$1([
16103
16561
  deepClone
16104
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
16105
- __decorate$1([
16106
- ignoreClone
16107
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
16108
- __decorate$1([
16109
- ignoreClone
16110
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
16111
- __decorate$1([
16112
- ignoreClone
16113
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16562
+ ], Skin.prototype, "inverseBindMatrices", void 0);
16114
16563
  __decorate$1([
16115
16564
  ignoreClone
16116
- ], SkinnedMeshRenderer.prototype, "_rootBone", void 0);
16565
+ ], Skin.prototype, "_skinMatrices", void 0);
16117
16566
  __decorate$1([
16118
16567
  ignoreClone
16119
- ], SkinnedMeshRenderer.prototype, "_jointMatrices", void 0);
16568
+ ], Skin.prototype, "_updatedManager", void 0);
16120
16569
  __decorate$1([
16121
16570
  ignoreClone
16122
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16123
- __decorate$1([
16124
- ignoreClone
16125
- ], SkinnedMeshRenderer.prototype, "_bones", void 0);
16571
+ ], Skin.prototype, "_rootBone", void 0);
16126
16572
  __decorate$1([
16127
16573
  ignoreClone
16128
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16574
+ ], Skin.prototype, "_bones", void 0);
16129
16575
  __decorate$1([
16130
16576
  ignoreClone
16131
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16577
+ ], Skin.prototype, "_updateMark", void 0);
16578
+ var SkinUpdateFlag;
16579
+ (function(SkinUpdateFlag) {
16580
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
16581
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
16582
+ })(SkinUpdateFlag || (SkinUpdateFlag = {}));
16132
16583
  /**
16133
- * Class pool utils.
16134
- */ var ClassPool = /*#__PURE__*/ function() {
16135
- var ClassPool = function ClassPool(type) {
16136
- this._elementPoolIndex = 0;
16137
- this._elementPool = [];
16138
- this._type = type;
16584
+ * SkinnedMeshRenderer.
16585
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
16586
+ var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
16587
+ var _this;
16588
+ _this = MeshRenderer1.call(this, entity) || this;
16589
+ _this._localBounds = new BoundingBox();
16590
+ _this._jointDataCreateCache = new Vector2(-1, -1);
16591
+ _this._skin = null;
16592
+ var rhi = _this.entity.engine._hardwareRenderer;
16593
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
16594
+ // Limit size to 256 to avoid some problem:
16595
+ // 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!
16596
+ // 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.
16597
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
16598
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
16599
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
16600
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_assert_this_initialized(_this));
16601
+ var localBounds = _this._localBounds;
16602
+ // @ts-ignore
16603
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
16604
+ // @ts-ignore
16605
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
16606
+ return _this;
16139
16607
  };
16140
- var _proto = ClassPool.prototype;
16608
+ _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
16609
+ var _proto = SkinnedMeshRenderer.prototype;
16141
16610
  /**
16142
- * Get element from pool.
16143
- */ _proto.getFromPool = function getFromPool() {
16144
- var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
16145
- this._elementPoolIndex++;
16146
- if (pool.length === index) {
16147
- var element = new this._type();
16148
- pool.push(element);
16149
- return element;
16150
- } else {
16151
- return pool[index];
16611
+ * @internal
16612
+ */ _proto.update = function update() {
16613
+ var _skin;
16614
+ var skin = this._skin;
16615
+ if (((_skin = skin) == null ? void 0 : _skin.bones.length) > 0) {
16616
+ skin._updateSkinMatrices(this);
16152
16617
  }
16153
16618
  };
16154
- /**
16155
- * Reset pool.
16156
- */ _proto.resetPool = function resetPool() {
16157
- this._elementPoolIndex = 0;
16158
- };
16159
- _proto.garbageCollection = function garbageCollection() {
16160
- var _this = this, pool = _this._elementPool;
16161
- for(var i = pool.length - 1; i >= 0; i--){
16162
- pool[i].dispose && pool[i].dispose();
16619
+ _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
16620
+ var _skin, _skin1;
16621
+ var _this = this, entity = _this.entity, skin = _this.skin;
16622
+ var _skin_rootBone;
16623
+ var worldMatrix = ((_skin_rootBone = (_skin = skin) == null ? void 0 : _skin.rootBone) != null ? _skin_rootBone : entity).transform.worldMatrix;
16624
+ if (onlyMVP) {
16625
+ this._updateMVPShaderData(context, worldMatrix);
16626
+ return;
16163
16627
  }
16164
- };
16165
- return ClassPool;
16166
- }();
16167
- var Basic2DBatcher = /*#__PURE__*/ function() {
16168
- var Basic2DBatcher = function Basic2DBatcher(engine) {
16169
- /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
16170
- /** @internal */ this._batchedQueue = [];
16171
- /** @internal */ this._meshes = [];
16172
- /** @internal */ this._meshCount = 1;
16173
- /** @internal */ this._vertexBuffers = [];
16174
- /** @internal */ this._indiceBuffers = [];
16175
- /** @internal */ this._flushId = 0;
16176
- /** @internal */ this._vertexCount = 0;
16177
- /** @internal */ this._elementCount = 0;
16178
- this._engine = engine;
16179
- this._initMeshes(engine);
16180
- };
16181
- var _proto = Basic2DBatcher.prototype;
16182
- _proto.drawElement = function drawElement(element, camera) {
16183
- var data = element.data;
16184
- if (data.multiRenderData) {
16185
- var charsData = data.charsData;
16186
- var pool = camera.engine._renderElementPool;
16187
- for(var i = 0, n = charsData.length; i < n; ++i){
16188
- var charRenderElement = pool.getFromPool();
16189
- charRenderElement.set(charsData[i], element.shaderPasses);
16190
- this._drawSubElement(charRenderElement, camera);
16628
+ this._updateTransformShaderData(context, worldMatrix);
16629
+ var shaderData = this.shaderData;
16630
+ var mesh = this.mesh;
16631
+ var blendShapeManager = mesh._blendShapeManager;
16632
+ blendShapeManager._updateShaderData(shaderData, this);
16633
+ var bones = (_skin1 = skin) == null ? void 0 : _skin1.bones;
16634
+ if (bones) {
16635
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
16636
+ var boneCount = bones.length;
16637
+ var boneDataCreateCache = this._jointDataCreateCache;
16638
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
16639
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
16640
+ // directly use max joint count to avoid shader recompile
16641
+ // @TODO: different shader type should use different count, not always 44
16642
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
16643
+ if (boneCount > remainUniformJointCount) {
16644
+ var engine = this.engine;
16645
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
16646
+ if (boneCountChange) {
16647
+ var _this__jointTexture;
16648
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16649
+ this._jointTexture = new Texture2D(engine, 4, boneCount, exports.TextureFormat.R32G32B32A32, false);
16650
+ this._jointTexture.filterMode = exports.TextureFilterMode.Point;
16651
+ this._jointTexture.isGCIgnored = true;
16652
+ }
16653
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
16654
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
16655
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
16656
+ } else {
16657
+ 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);
16658
+ }
16659
+ } else {
16660
+ var _this__jointTexture1;
16661
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
16662
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
16663
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
16664
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
16665
+ }
16666
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
16667
+ }
16668
+ if (this._jointTexture) {
16669
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
16191
16670
  }
16192
- } else {
16193
- this._drawSubElement(element, camera);
16194
16671
  }
16672
+ var layer = entity.layer;
16673
+ this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
16195
16674
  };
16196
16675
  /**
16197
16676
  * @internal
16198
- * Standalone for canvas 2d renderer plugin.
16199
- */ _proto._initMeshes = function _initMeshes(engine) {
16200
- var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
16201
- this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
16202
- this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
16203
- var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
16204
- for(var i = 0; i < _meshCount; i++){
16205
- _meshes[i] = this._createMesh(engine, i);
16206
- }
16677
+ */ _proto._onDestroy = function _onDestroy() {
16678
+ var _this__jointTexture;
16679
+ MeshRenderer1.prototype._onDestroy.call(this);
16680
+ this._jointDataCreateCache = null;
16681
+ this._skin = null;
16682
+ this._blendShapeWeights = null;
16683
+ this._localBounds = null;
16684
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16685
+ this._jointTexture = null;
16207
16686
  };
16208
- _proto.flush = function flush(camera) {
16209
- var batchedQueue = this._batchedQueue;
16210
- if (batchedQueue.length === 0) {
16211
- return;
16212
- }
16213
- this._updateData(this._engine);
16214
- this.drawBatches(camera);
16215
- if (!Basic2DBatcher._canUploadSameBuffer) {
16216
- this._flushId++;
16687
+ /**
16688
+ * @internal
16689
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16690
+ MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
16691
+ if (this.skin) {
16692
+ target._applySkin(null, target.skin);
16217
16693
  }
16218
- batchedQueue.length = 0;
16219
- this._subMeshPool.resetPool();
16220
- this._vertexCount = 0;
16221
- this._elementCount = 0;
16694
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
16222
16695
  };
16223
- _proto.clear = function clear() {
16224
- this._flushId = 0;
16225
- this._vertexCount = 0;
16226
- this._elementCount = 0;
16227
- this._batchedQueue.length = 0;
16696
+ /**
16697
+ * @internal
16698
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
16699
+ var _this_skin;
16700
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
16701
+ if (rootBone) {
16702
+ BoundingBox.transform(this._localBounds, rootBone.transform.worldMatrix, worldBounds);
16703
+ } else {
16704
+ MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
16705
+ }
16228
16706
  };
16229
- _proto.destroy = function destroy() {
16230
- this._batchedQueue = null;
16231
- var _this = this, meshes = _this._meshes, vertexBuffers = _this._vertexBuffers, indiceBuffers = _this._indiceBuffers;
16232
- for(var i = 0, n = meshes.length; i < n; ++i){
16233
- var mesh = meshes[i];
16234
- mesh._addReferCount(-1);
16707
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
16708
+ var mesh = this._mesh;
16709
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
16710
+ var lastBlendShapeWeights = this._blendShapeWeights;
16711
+ if (lastBlendShapeWeights) {
16712
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
16713
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
16714
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
16715
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
16716
+ newBlendShapeWeights.set(lastBlendShapeWeights);
16717
+ } else {
16718
+ for(var i = 0; i < newBlendShapeCount; i++){
16719
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
16720
+ }
16721
+ }
16722
+ this._blendShapeWeights = newBlendShapeWeights;
16723
+ }
16724
+ } else {
16725
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16726
+ }
16727
+ };
16728
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
16729
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16730
+ };
16731
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
16732
+ switch(type){
16733
+ case SkinUpdateFlag.BoneCountChanged:
16734
+ var shaderData = this.shaderData;
16735
+ if (value > 0) {
16736
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
16737
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
16738
+ } else {
16739
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
16740
+ }
16741
+ break;
16742
+ case SkinUpdateFlag.RootBoneChanged:
16743
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16744
+ break;
16745
+ }
16746
+ };
16747
+ _proto._applySkin = function _applySkin(lastSkin, value) {
16748
+ var _lastSkin_bones, _lastSkin, _lastSkin1, _lastSkin2, _value_bones, _value, _value1, _value2;
16749
+ var _lastSkin_bones_length;
16750
+ 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;
16751
+ var _lastSkin_rootBone;
16752
+ var lastRootBone = (_lastSkin_rootBone = (_lastSkin1 = lastSkin) == null ? void 0 : _lastSkin1.rootBone) != null ? _lastSkin_rootBone : this.entity;
16753
+ (_lastSkin2 = lastSkin) == null ? void 0 : _lastSkin2._updatedManager.removeListener(this._onSkinUpdated);
16754
+ var _value_bones_length;
16755
+ 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;
16756
+ var _value_rootBone;
16757
+ var rootBone = (_value_rootBone = (_value1 = value) == null ? void 0 : _value1.rootBone) != null ? _value_rootBone : this.entity;
16758
+ (_value2 = value) == null ? void 0 : _value2._updatedManager.addListener(this._onSkinUpdated);
16759
+ if (lastSkinBoneCount !== skinBoneCount) {
16760
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
16761
+ }
16762
+ if (lastRootBone !== rootBone) {
16763
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
16764
+ }
16765
+ };
16766
+ _create_class$2(SkinnedMeshRenderer, [
16767
+ {
16768
+ key: "skin",
16769
+ get: /**
16770
+ * Skin of the SkinnedMeshRenderer.
16771
+ */ function get() {
16772
+ return this._skin;
16773
+ },
16774
+ set: function set(value) {
16775
+ var lastSkin = this._skin;
16776
+ if (lastSkin !== value) {
16777
+ this._applySkin(lastSkin, value);
16778
+ this._skin = value;
16779
+ }
16780
+ }
16781
+ },
16782
+ {
16783
+ key: "blendShapeWeights",
16784
+ get: /**
16785
+ * The weights of the BlendShapes.
16786
+ * @remarks Array index is BlendShape index.
16787
+ */ function get() {
16788
+ this._checkBlendShapeWeightLength();
16789
+ return this._blendShapeWeights;
16790
+ },
16791
+ set: function set(value) {
16792
+ this._checkBlendShapeWeightLength();
16793
+ var blendShapeWeights = this._blendShapeWeights;
16794
+ if (value.length <= blendShapeWeights.length) {
16795
+ blendShapeWeights.set(value);
16796
+ } else {
16797
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
16798
+ blendShapeWeights[i] = value[i];
16799
+ }
16800
+ }
16801
+ }
16802
+ },
16803
+ {
16804
+ key: "localBounds",
16805
+ get: /**
16806
+ * Local bounds.
16807
+ */ function get() {
16808
+ return this._localBounds;
16809
+ },
16810
+ set: function set(value) {
16811
+ if (this._localBounds !== value) {
16812
+ this._localBounds.copyFrom(value);
16813
+ }
16814
+ }
16815
+ },
16816
+ {
16817
+ key: "rootBone",
16818
+ get: /**
16819
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
16820
+ */ function get() {
16821
+ return this.skin.rootBone;
16822
+ },
16823
+ set: function set(value) {
16824
+ this.skin.rootBone = value;
16825
+ }
16826
+ },
16827
+ {
16828
+ key: "bones",
16829
+ get: /**
16830
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
16831
+ */ function get() {
16832
+ return this.skin.bones;
16833
+ },
16834
+ set: function set(value) {
16835
+ this.skin.bones = value;
16836
+ }
16837
+ }
16838
+ ]);
16839
+ return SkinnedMeshRenderer;
16840
+ }(MeshRenderer);
16841
+ (function() {
16842
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
16843
+ })();
16844
+ (function() {
16845
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
16846
+ })();
16847
+ (function() {
16848
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
16849
+ })();
16850
+ __decorate$1([
16851
+ ignoreClone
16852
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16853
+ __decorate$1([
16854
+ deepClone
16855
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
16856
+ __decorate$1([
16857
+ ignoreClone
16858
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
16859
+ __decorate$1([
16860
+ ignoreClone
16861
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
16862
+ __decorate$1([
16863
+ ignoreClone
16864
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16865
+ __decorate$1([
16866
+ ignoreClone
16867
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16868
+ __decorate$1([
16869
+ deepClone
16870
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
16871
+ __decorate$1([
16872
+ ignoreClone
16873
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16874
+ __decorate$1([
16875
+ ignoreClone
16876
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
16877
+ /**
16878
+ * Class pool utils.
16879
+ */ var ClassPool = /*#__PURE__*/ function() {
16880
+ var ClassPool = function ClassPool(type) {
16881
+ this._elementPoolIndex = 0;
16882
+ this._elementPool = [];
16883
+ this._type = type;
16884
+ };
16885
+ var _proto = ClassPool.prototype;
16886
+ /**
16887
+ * Get element from pool.
16888
+ */ _proto.getFromPool = function getFromPool() {
16889
+ var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
16890
+ this._elementPoolIndex++;
16891
+ if (pool.length === index) {
16892
+ var element = new this._type();
16893
+ pool.push(element);
16894
+ return element;
16895
+ } else {
16896
+ return pool[index];
16897
+ }
16898
+ };
16899
+ /**
16900
+ * Reset pool.
16901
+ */ _proto.resetPool = function resetPool() {
16902
+ this._elementPoolIndex = 0;
16903
+ };
16904
+ _proto.garbageCollection = function garbageCollection() {
16905
+ var _this = this, pool = _this._elementPool;
16906
+ for(var i = pool.length - 1; i >= 0; i--){
16907
+ pool[i].dispose && pool[i].dispose();
16908
+ }
16909
+ };
16910
+ return ClassPool;
16911
+ }();
16912
+ var Basic2DBatcher = /*#__PURE__*/ function() {
16913
+ var Basic2DBatcher = function Basic2DBatcher(engine) {
16914
+ /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
16915
+ /** @internal */ this._batchedQueue = [];
16916
+ /** @internal */ this._meshes = [];
16917
+ /** @internal */ this._meshCount = 1;
16918
+ /** @internal */ this._vertexBuffers = [];
16919
+ /** @internal */ this._indiceBuffers = [];
16920
+ /** @internal */ this._flushId = 0;
16921
+ /** @internal */ this._vertexCount = 0;
16922
+ /** @internal */ this._elementCount = 0;
16923
+ this._engine = engine;
16924
+ this._initMeshes(engine);
16925
+ };
16926
+ var _proto = Basic2DBatcher.prototype;
16927
+ _proto.drawElement = function drawElement(element, camera) {
16928
+ var data = element.data;
16929
+ if (data.multiRenderData) {
16930
+ var charsData = data.charsData;
16931
+ var pool = camera.engine._renderElementPool;
16932
+ for(var i = 0, n = charsData.length; i < n; ++i){
16933
+ var charRenderElement = pool.getFromPool();
16934
+ charRenderElement.set(charsData[i], element.shaderPasses);
16935
+ this._drawSubElement(charRenderElement, camera);
16936
+ }
16937
+ } else {
16938
+ this._drawSubElement(element, camera);
16939
+ }
16940
+ };
16941
+ /**
16942
+ * @internal
16943
+ * Standalone for canvas 2d renderer plugin.
16944
+ */ _proto._initMeshes = function _initMeshes(engine) {
16945
+ var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
16946
+ this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
16947
+ this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
16948
+ var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
16949
+ for(var i = 0; i < _meshCount; i++){
16950
+ _meshes[i] = this._createMesh(engine, i);
16951
+ }
16952
+ };
16953
+ _proto.flush = function flush(camera) {
16954
+ var batchedQueue = this._batchedQueue;
16955
+ if (batchedQueue.length === 0) {
16956
+ return;
16957
+ }
16958
+ this._updateData(this._engine);
16959
+ this.drawBatches(camera);
16960
+ if (!Basic2DBatcher._canUploadSameBuffer) {
16961
+ this._flushId++;
16962
+ }
16963
+ batchedQueue.length = 0;
16964
+ this._subMeshPool.resetPool();
16965
+ this._vertexCount = 0;
16966
+ this._elementCount = 0;
16967
+ };
16968
+ _proto.clear = function clear() {
16969
+ this._flushId = 0;
16970
+ this._vertexCount = 0;
16971
+ this._elementCount = 0;
16972
+ this._batchedQueue.length = 0;
16973
+ };
16974
+ _proto.destroy = function destroy() {
16975
+ this._batchedQueue = null;
16976
+ var _this = this, meshes = _this._meshes, vertexBuffers = _this._vertexBuffers, indiceBuffers = _this._indiceBuffers;
16977
+ for(var i = 0, n = meshes.length; i < n; ++i){
16978
+ var mesh = meshes[i];
16979
+ mesh._addReferCount(-1);
16235
16980
  mesh.destroy();
16236
16981
  }
16237
16982
  this._meshes = null;
@@ -18757,7 +19502,7 @@
18757
19502
  */ _proto.cloneTo = function cloneTo(target) {
18758
19503
  target.shader = this.shader;
18759
19504
  this.shaderData.cloneTo(target.shaderData);
18760
- CloneManager.deepCloneObject(this.renderStates, target.renderStates);
19505
+ CloneManager.deepCloneObject(this.renderStates, target.renderStates, new Map());
18761
19506
  };
18762
19507
  _proto._addReferCount = function _addReferCount(value) {
18763
19508
  if (this._destroyed) return;
@@ -19454,1103 +20199,457 @@
19454
20199
  this.shaderData.setFloat(PBRBaseMaterial._clearCoatProp, value);
19455
20200
  }
19456
20201
  },
19457
- {
19458
- key: "clearCoatTexture",
19459
- get: /**
19460
- * The clearCoat layer intensity texture.
19461
- */ function get() {
19462
- return this.shaderData.getTexture(PBRBaseMaterial._clearCoatTextureProp);
19463
- },
19464
- set: function set(value) {
19465
- this.shaderData.setTexture(PBRBaseMaterial._clearCoatTextureProp, value);
19466
- if (value) {
19467
- this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_TEXTURE");
19468
- } else {
19469
- this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_TEXTURE");
19470
- }
19471
- }
19472
- },
19473
- {
19474
- key: "clearCoatRoughness",
19475
- get: /**
19476
- * The clearCoat layer roughness, default 0.
19477
- */ function get() {
19478
- return this.shaderData.getFloat(PBRBaseMaterial._clearCoatRoughnessProp);
19479
- },
19480
- set: function set(value) {
19481
- this.shaderData.setFloat(PBRBaseMaterial._clearCoatRoughnessProp, value);
19482
- }
19483
- },
19484
- {
19485
- key: "clearCoatRoughnessTexture",
19486
- get: /**
19487
- * The clearCoat layer roughness texture.
19488
- */ function get() {
19489
- return this.shaderData.getTexture(PBRBaseMaterial._clearCoatRoughnessTextureProp);
19490
- },
19491
- set: function set(value) {
19492
- this.shaderData.setTexture(PBRBaseMaterial._clearCoatRoughnessTextureProp, value);
19493
- if (value) {
19494
- this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
19495
- } else {
19496
- this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
19497
- }
19498
- }
19499
- },
19500
- {
19501
- key: "clearCoatNormalTexture",
19502
- get: /**
19503
- * The clearCoat normal map texture.
19504
- */ function get() {
19505
- return this.shaderData.getTexture(PBRBaseMaterial._clearCoatNormalTextureProp);
19506
- },
19507
- set: function set(value) {
19508
- this.shaderData.setTexture(PBRBaseMaterial._clearCoatNormalTextureProp, value);
19509
- if (value) {
19510
- this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
19511
- } else {
19512
- this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
19513
- }
19514
- }
19515
- }
19516
- ]);
19517
- return PBRBaseMaterial;
19518
- }(BaseMaterial);
19519
- (function() {
19520
- PBRBaseMaterial._occlusionTextureIntensityProp = ShaderProperty.getByName("material_OcclusionIntensity");
19521
- })();
19522
- (function() {
19523
- PBRBaseMaterial._occlusionTextureCoordProp = ShaderProperty.getByName("material_OcclusionTextureCoord");
19524
- })();
19525
- (function() {
19526
- PBRBaseMaterial._occlusionTextureProp = ShaderProperty.getByName("material_OcclusionTexture");
19527
- })();
19528
- (function() {
19529
- PBRBaseMaterial._clearCoatProp = ShaderProperty.getByName("material_ClearCoat");
19530
- })();
19531
- (function() {
19532
- PBRBaseMaterial._clearCoatTextureProp = ShaderProperty.getByName("material_ClearCoatTexture");
19533
- })();
19534
- (function() {
19535
- PBRBaseMaterial._clearCoatRoughnessProp = ShaderProperty.getByName("material_ClearCoatRoughness");
19536
- })();
19537
- (function() {
19538
- PBRBaseMaterial._clearCoatRoughnessTextureProp = ShaderProperty.getByName("material_ClearCoatRoughnessTexture");
19539
- })();
19540
- (function() {
19541
- PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material_ClearCoatNormalTexture");
19542
- })();
19543
- /**
19544
- * PBR (Metallic-Roughness Workflow) Material.
19545
- */ var PBRMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
19546
- _inherits$2(PBRMaterial, PBRBaseMaterial1);
19547
- function PBRMaterial(engine) {
19548
- var _this;
19549
- _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr")) || this;
19550
- _this._anisotropyRotation = 0;
19551
- var shaderData = _this.shaderData;
19552
- shaderData.setFloat(PBRMaterial._metallicProp, 1);
19553
- shaderData.setFloat(PBRMaterial._roughnessProp, 1);
19554
- shaderData.setFloat(PBRMaterial._iorProp, 1.5);
19555
- shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0));
19556
- return _this;
19557
- }
19558
- var _proto = PBRMaterial.prototype;
19559
- /**
19560
- * @inheritdoc
19561
- */ _proto.clone = function clone() {
19562
- var dest = new PBRMaterial(this._engine);
19563
- this.cloneTo(dest);
19564
- return dest;
19565
- };
19566
- _create_class$2(PBRMaterial, [
19567
- {
19568
- key: "ior",
19569
- get: /**
19570
- * Index Of Refraction.
19571
- * @defaultValue `1.5`
19572
- */ function get() {
19573
- return this.shaderData.getFloat(PBRMaterial._iorProp);
19574
- },
19575
- set: function set(v) {
19576
- this.shaderData.setFloat(PBRMaterial._iorProp, Math.max(v, 0));
19577
- }
19578
- },
19579
- {
19580
- key: "metallic",
19581
- get: /**
19582
- * Metallic.
19583
- * @defaultValue `1.0`
19584
- */ function get() {
19585
- return this.shaderData.getFloat(PBRMaterial._metallicProp);
19586
- },
19587
- set: function set(value) {
19588
- this.shaderData.setFloat(PBRMaterial._metallicProp, value);
19589
- }
19590
- },
19591
- {
19592
- key: "roughness",
19593
- get: /**
19594
- * Roughness. default 1.0.
19595
- * @defaultValue `1.0`
19596
- */ function get() {
19597
- return this.shaderData.getFloat(PBRMaterial._roughnessProp);
19598
- },
19599
- set: function set(value) {
19600
- this.shaderData.setFloat(PBRMaterial._roughnessProp, value);
19601
- }
19602
- },
19603
- {
19604
- key: "roughnessMetallicTexture",
19605
- get: /**
19606
- * Roughness metallic texture.
19607
- * @remarks G channel is roughness, B channel is metallic
19608
- */ function get() {
19609
- return this.shaderData.getTexture(PBRMaterial._roughnessMetallicTextureProp);
19610
- },
19611
- set: function set(value) {
19612
- this.shaderData.setTexture(PBRMaterial._roughnessMetallicTextureProp, value);
19613
- if (value) {
19614
- this.shaderData.enableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
19615
- } else {
19616
- this.shaderData.disableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
19617
- }
19618
- }
19619
- },
19620
- {
19621
- key: "anisotropy",
19622
- get: /**
19623
- * The strength of anisotropy, when anisotropyTexture is present, this value is multiplied by the blue channel.
19624
- * @defaultValue `0`
19625
- */ function get() {
19626
- return this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp).z;
19627
- },
19628
- set: function set(value) {
19629
- var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
19630
- if (!!anisotropyInfo.z !== !!value) {
19631
- if (value === 0) {
19632
- this.shaderData.disableMacro("MATERIAL_ENABLE_ANISOTROPY");
19633
- } else {
19634
- this.shaderData.enableMacro("MATERIAL_ENABLE_ANISOTROPY");
19635
- }
19636
- }
19637
- anisotropyInfo.z = value;
19638
- }
19639
- },
19640
- {
19641
- key: "anisotropyRotation",
19642
- get: /**
19643
- * The rotation of the anisotropy in tangent, bitangent space, value in degrees.
19644
- * @defaultValue `0`
19645
- */ function get() {
19646
- return this._anisotropyRotation;
19647
- },
19648
- set: function set(value) {
19649
- if (this._anisotropyRotation !== value) {
19650
- this._anisotropyRotation = value;
19651
- var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
19652
- var rad = MathUtil.degreeToRadFactor * value;
19653
- anisotropyInfo.x = Math.cos(rad);
19654
- anisotropyInfo.y = Math.sin(rad);
19655
- }
19656
- }
19657
- },
19658
- {
19659
- key: "anisotropyTexture",
19660
- get: /**
19661
- * The anisotropy texture.
19662
- * @remarks
19663
- * Red and green channels represent the anisotropy direction in [-1, 1] tangent, bitangent space, to be rotated by anisotropyRotation.
19664
- * The blue channel contains strength as [0, 1] to be multiplied by anisotropy.
19665
- */ function get() {
19666
- return this.shaderData.getTexture(PBRMaterial._anisotropyTextureProp);
19667
- },
19668
- set: function set(value) {
19669
- this.shaderData.setTexture(PBRMaterial._anisotropyTextureProp, value);
19670
- if (value) {
19671
- this.shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
19672
- } else {
19673
- this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
19674
- }
19675
- }
19676
- }
19677
- ]);
19678
- return PBRMaterial;
19679
- }(PBRBaseMaterial);
19680
- (function() {
19681
- PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
19682
- })();
19683
- (function() {
19684
- PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
19685
- })();
19686
- (function() {
19687
- PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
19688
- })();
19689
- (function() {
19690
- PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
19691
- })();
19692
- (function() {
19693
- PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
19694
- })();
19695
- (function() {
19696
- PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
19697
- })();
19698
- /**
19699
- * PBR (Specular-Glossiness Workflow) Material.
19700
- */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
19701
- _inherits$2(PBRSpecularMaterial, PBRBaseMaterial1);
19702
- function PBRSpecularMaterial(engine) {
19703
- var _this;
19704
- _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
19705
- _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new Color(1, 1, 1, 1));
19706
- _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
19707
- return _this;
19708
- }
19709
- var _proto = PBRSpecularMaterial.prototype;
19710
- /**
19711
- * @inheritdoc
19712
- */ _proto.clone = function clone() {
19713
- var dest = new PBRSpecularMaterial(this._engine);
19714
- this.cloneTo(dest);
19715
- return dest;
19716
- };
19717
- _create_class$2(PBRSpecularMaterial, [
19718
- {
19719
- key: "specularColor",
19720
- get: /**
19721
- * Specular color.
19722
- */ function get() {
19723
- return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
19724
- },
19725
- set: function set(value) {
19726
- var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
19727
- if (value !== specularColor) {
19728
- specularColor.copyFrom(value);
19729
- }
19730
- }
19731
- },
19732
- {
19733
- key: "glossiness",
19734
- get: /**
19735
- * Glossiness.
19736
- */ function get() {
19737
- return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
19738
- },
19739
- set: function set(value) {
19740
- this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
19741
- }
19742
- },
19743
- {
19744
- key: "specularGlossinessTexture",
19745
- get: /**
19746
- * Specular glossiness texture.
19747
- * @remarks RGB is specular, A is glossiness
19748
- */ function get() {
19749
- return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
19750
- },
19751
- set: function set(value) {
19752
- this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
19753
- if (value) {
19754
- this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
19755
- } else {
19756
- this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
19757
- }
19758
- }
19759
- }
19760
- ]);
19761
- return PBRSpecularMaterial;
19762
- }(PBRBaseMaterial);
19763
- (function() {
19764
- PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
19765
- })();
19766
- (function() {
19767
- PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
19768
- })();
19769
- (function() {
19770
- PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
19771
- })();
19772
- (function() {
19773
- PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
19774
- })();
19775
- /**
19776
- * Unlit Material.
19777
- */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
19778
- _inherits$2(UnlitMaterial, BaseMaterial1);
19779
- function UnlitMaterial(engine) {
19780
- var _this;
19781
- _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
19782
- var shaderData = _this.shaderData;
19783
- shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
19784
- shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
19785
- shaderData.setColor(UnlitMaterial._baseColorProp, new Color(1, 1, 1, 1));
19786
- shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new Vector4(1, 1, 0, 0));
19787
- return _this;
19788
- }
19789
- var _proto = UnlitMaterial.prototype;
19790
- /**
19791
- * @inheritdoc
19792
- */ _proto.clone = function clone() {
19793
- var dest = new UnlitMaterial(this._engine);
19794
- this.cloneTo(dest);
19795
- return dest;
19796
- };
19797
- _create_class$2(UnlitMaterial, [
19798
- {
19799
- key: "baseColor",
19800
- get: /**
19801
- * Base color.
19802
- */ function get() {
19803
- return this.shaderData.getColor(UnlitMaterial._baseColorProp);
19804
- },
19805
- set: function set(value) {
19806
- var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
19807
- if (value !== baseColor) {
19808
- baseColor.copyFrom(value);
19809
- }
19810
- }
19811
- },
19812
- {
19813
- key: "baseTexture",
19814
- get: /**
19815
- * Base texture.
19816
- */ function get() {
19817
- return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
19818
- },
19819
- set: function set(value) {
19820
- this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
19821
- if (value) {
19822
- this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
19823
- } else {
19824
- this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
19825
- }
19826
- }
19827
- },
19828
- {
19829
- key: "tilingOffset",
19830
- get: /**
19831
- * Tiling and offset of main textures.
19832
- */ function get() {
19833
- return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
19834
- },
19835
- set: function set(value) {
19836
- var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
19837
- if (value !== tilingOffset) {
19838
- tilingOffset.copyFrom(value);
19839
- }
19840
- }
19841
- }
19842
- ]);
19843
- return UnlitMaterial;
19844
- }(BaseMaterial);
19845
- /**
19846
- * @internal
19847
- */ var BasicResources = /*#__PURE__*/ function() {
19848
- var BasicResources = function BasicResources(engine) {
19849
- // prettier-ignore
19850
- var vertices = new Float32Array([
19851
- -1,
19852
- -1,
19853
- 0,
19854
- 1,
19855
- 1,
19856
- -1,
19857
- 1,
19858
- 1,
19859
- -1,
19860
- 1,
19861
- 0,
19862
- 0,
19863
- 1,
19864
- 1,
19865
- 1,
19866
- 0
19867
- ]); // right-top
19868
- // prettier-ignore
19869
- var flipYVertices = new Float32Array([
19870
- 1,
19871
- -1,
19872
- 1,
19873
- 0,
19874
- -1,
19875
- -1,
19876
- 0,
19877
- 0,
19878
- 1,
19879
- 1,
19880
- 1,
19881
- 1,
19882
- -1,
19883
- 1,
19884
- 0,
19885
- 1
19886
- ]); // left-top
19887
- var blitMaterial = new Material(engine, Shader.find("blit"));
19888
- blitMaterial._addReferCount(1);
19889
- blitMaterial.renderState.depthState.enabled = false;
19890
- blitMaterial.renderState.depthState.writeEnabled = false;
19891
- this.blitMesh = this._createBlitMesh(engine, vertices);
19892
- this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
19893
- this.blitMaterial = blitMaterial;
19894
- };
19895
- var _proto = BasicResources.prototype;
19896
- _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
19897
- var mesh = new ModelMesh(engine);
19898
- mesh._addReferCount(1);
19899
- mesh.setVertexElements([
19900
- new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
19901
- ]);
19902
- mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
19903
- mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
19904
- return mesh;
19905
- };
19906
- return BasicResources;
19907
- }();
19908
- /**
19909
- * Layer, used for bit operations.
19910
- */ exports.Layer = void 0;
19911
- (function(Layer) {
19912
- Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
19913
- Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
19914
- Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
19915
- Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
19916
- Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
19917
- Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
19918
- Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
19919
- Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
19920
- Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
19921
- Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
19922
- Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
19923
- Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
19924
- Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
19925
- Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
19926
- Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
19927
- Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
19928
- Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
19929
- Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
19930
- Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
19931
- Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
19932
- Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
19933
- Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
19934
- Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
19935
- Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
19936
- Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
19937
- Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
19938
- Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
19939
- Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
19940
- Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
19941
- Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
19942
- Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
19943
- Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
19944
- Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
19945
- Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
19946
- })(exports.Layer || (exports.Layer = {}));
19947
- var ComponentCloner = /*#__PURE__*/ function() {
19948
- var ComponentCloner = function ComponentCloner() {};
19949
- /**
19950
- * Clone component.
19951
- * @param source - Clone source
19952
- * @param target - Clone target
19953
- */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot) {
19954
- var cloneModes = CloneManager.getCloneMode(source.constructor);
19955
- for(var k in source){
19956
- CloneManager.cloneProperty(source, target, k, cloneModes[k]);
19957
- }
19958
- if (source._cloneTo) {
19959
- source._cloneTo(target, srcRoot, targetRoot);
19960
- }
19961
- };
19962
- return ComponentCloner;
19963
- }();
19964
- /**
19965
- * Entity, be used as components container.
19966
- */ var Entity = /*#__PURE__*/ function(EngineObject1) {
19967
- var Entity = function Entity(engine, name1) {
19968
- var _this;
19969
- _this = EngineObject1.call(this, engine) || this;
19970
- /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
19971
- /** @internal */ _this._isActiveInHierarchy = false;
19972
- /** @internal */ _this._isActiveInScene = false;
19973
- /** @internal */ _this._components = [];
19974
- /** @internal */ _this._scripts = new DisorderedArray();
19975
- /** @internal */ _this._children = [];
19976
- /** @internal */ _this._isRoot = false;
19977
- /** @internal */ _this._isActive = true;
19978
- /** @internal */ _this._siblingIndex = -1;
19979
- /** @internal */ _this._isTemplate = false;
19980
- _this._parent = null;
19981
- //--------------------------------------------------------------deprecated----------------------------------------------------------------
19982
- _this._invModelMatrix = new Matrix();
19983
- _this.name = name1;
19984
- _this.transform = _this.addComponent(Transform);
19985
- _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
19986
- return _this;
19987
- };
19988
- _inherits$2(Entity, EngineObject1);
19989
- var _proto = Entity.prototype;
19990
- /**
19991
- * Add component based on the component type.
19992
- * @param type - The type of the component
19993
- * @returns The component which has been added
19994
- */ _proto.addComponent = function addComponent(type) {
19995
- ComponentsDependencies._addCheck(this, type);
19996
- var component = new type(this);
19997
- this._components.push(component);
19998
- component._setActive(true, ActiveChangeFlag.All);
19999
- return component;
20000
- };
20001
- /**
20002
- * Get component which match the type.
20003
- * @param type - The type of the component
20004
- * @returns The first component which match type
20005
- */ _proto.getComponent = function getComponent(type) {
20006
- var components = this._components;
20007
- for(var i = 0, n = components.length; i < n; i++){
20008
- var component = components[i];
20009
- if (_instanceof1$2(component, type)) {
20010
- return component;
20011
- }
20012
- }
20013
- return null;
20014
- };
20015
- /**
20016
- * Get components which match the type.
20017
- * @param type - The type of the component
20018
- * @param results - The components which match type
20019
- * @returns The components which match type
20020
- */ _proto.getComponents = function getComponents(type, results) {
20021
- results.length = 0;
20022
- var components = this._components;
20023
- for(var i = 0, n = components.length; i < n; i++){
20024
- var component = components[i];
20025
- if (_instanceof1$2(component, type)) {
20026
- results.push(component);
20027
- }
20028
- }
20029
- return results;
20030
- };
20031
- /**
20032
- * Get the components which match the type of the entity and it's children.
20033
- * @param type - The component type
20034
- * @param results - The components collection
20035
- * @returns The components collection which match the type
20036
- */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
20037
- results.length = 0;
20038
- this._getComponentsInChildren(type, results);
20039
- return results;
20040
- };
20041
- _proto.addChild = function addChild(indexOrChild, child) {
20042
- var index;
20043
- if (typeof indexOrChild === "number") {
20044
- index = indexOrChild;
20045
- } else {
20046
- index = undefined;
20047
- child = indexOrChild;
20048
- }
20049
- if (child._isRoot) {
20050
- child._scene._removeFromEntityList(child);
20051
- child._isRoot = false;
20052
- this._addToChildrenList(index, child);
20053
- child._parent = this;
20054
- var oldScene = child._scene;
20055
- var newScene = this._scene;
20056
- var inActiveChangeFlag = ActiveChangeFlag.None;
20057
- if (!this._isActiveInHierarchy) {
20058
- child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
20059
- }
20060
- if (child._isActiveInScene) {
20061
- if (this._isActiveInScene) {
20062
- // Cross scene should inActive first and then active
20063
- oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
20064
- } else {
20065
- inActiveChangeFlag |= ActiveChangeFlag.Scene;
20066
- }
20067
- }
20068
- inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
20069
- if (child._scene !== newScene) {
20070
- Entity._traverseSetOwnerScene(child, newScene);
20071
- }
20072
- var activeChangeFlag = ActiveChangeFlag.None;
20073
- if (child._isActive) {
20074
- if (this._isActiveInHierarchy) {
20075
- !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20076
- }
20077
- if (this._isActiveInScene) {
20078
- (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
20079
- }
20080
- }
20081
- activeChangeFlag && child._processActive(activeChangeFlag);
20082
- child._setTransformDirty();
20083
- } else {
20084
- child._setParent(this, index);
20085
- }
20086
- };
20087
- /**
20088
- * Remove child entity.
20089
- * @param child - The child entity which want to be removed
20090
- */ _proto.removeChild = function removeChild(child) {
20091
- child._setParent(null);
20092
- };
20093
- /**
20094
- * @deprecated Please use `children` property instead.
20095
- * Find child entity by index.
20096
- * @param index - The index of the child entity
20097
- * @returns The component which be found
20098
- */ _proto.getChild = function getChild(index) {
20099
- return this._children[index];
20100
- };
20101
- /**
20102
- * Find entity by name.
20103
- * @param name - The name of the entity which want to be found
20104
- * @returns The component which be found
20105
- */ _proto.findByName = function findByName(name1) {
20106
- if (name1 === this.name) {
20107
- return this;
20108
- }
20109
- var children = this._children;
20110
- for(var i = 0, n = children.length; i < n; i++){
20111
- var target = children[i].findByName(name1);
20112
- if (target) {
20113
- return target;
20114
- }
20115
- }
20116
- return null;
20117
- };
20118
- /**
20119
- * Find the entity by path.
20120
- * @param path - The path fo the entity eg: /entity
20121
- * @returns The component which be found
20122
- */ _proto.findByPath = function findByPath(path) {
20123
- var splits = path.split("/");
20124
- var entity = this;
20125
- for(var i = 0, length = splits.length; i < length; ++i){
20126
- var split = splits[i];
20127
- if (split) {
20128
- entity = Entity._findChildByName(entity, split);
20129
- if (!entity) {
20130
- return null;
20131
- }
20132
- }
20133
- }
20134
- return entity;
20135
- };
20136
- /**
20137
- * Create child entity.
20138
- * @param name - The child entity's name
20139
- * @returns The child entity
20140
- */ _proto.createChild = function createChild(name1) {
20141
- var child = new Entity(this.engine, name1);
20142
- child.layer = this.layer;
20143
- child.parent = this;
20144
- return child;
20145
- };
20146
- /**
20147
- * Clear children entities.
20148
- */ _proto.clearChildren = function clearChildren() {
20149
- var children = this._children;
20150
- for(var i = children.length - 1; i >= 0; i--){
20151
- var child = children[i];
20152
- child._parent = null;
20153
- var activeChangeFlag = ActiveChangeFlag.None;
20154
- child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20155
- child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
20156
- activeChangeFlag && child._processInActive(activeChangeFlag);
20157
- Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
20158
- }
20159
- children.length = 0;
20160
- };
20161
- /**
20162
- * Clone.
20163
- * @returns Cloned entity
20164
- */ _proto.clone = function clone() {
20165
- var cloneEntity = this._createCloneEntity(this);
20166
- this._parseCloneEntity(this, cloneEntity, this, cloneEntity);
20167
- return cloneEntity;
20168
- };
20169
- /**
20170
- * @internal
20171
- */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
20172
- this._isTemplate = true;
20173
- this._templateResource = templateResource;
20174
- };
20175
- _proto._createCloneEntity = function _createCloneEntity(srcEntity) {
20176
- var cloneEntity = new Entity(srcEntity._engine, srcEntity.name);
20177
- var templateResource = this._templateResource;
20178
- if (templateResource) {
20179
- cloneEntity._templateResource = templateResource;
20180
- templateResource._addReferCount(1);
20181
- }
20182
- cloneEntity.layer = srcEntity.layer;
20183
- cloneEntity._isActive = srcEntity._isActive;
20184
- var cloneTransform = cloneEntity.transform;
20185
- var srcTransform = srcEntity.transform;
20186
- cloneTransform.position = srcTransform.position;
20187
- cloneTransform.rotation = srcTransform.rotation;
20188
- cloneTransform.scale = srcTransform.scale;
20189
- var children = srcEntity._children;
20190
- for(var i = 0, n = srcEntity._children.length; i < n; i++){
20191
- cloneEntity.addChild(this._createCloneEntity(children[i]));
20192
- }
20193
- return cloneEntity;
20194
- };
20195
- _proto._parseCloneEntity = function _parseCloneEntity(srcEntity, targetEntity, srcRoot, targetRoot) {
20196
- var srcChildren = srcEntity._children;
20197
- var targetChildren = targetEntity._children;
20198
- for(var i = 0, n = srcChildren.length; i < n; i++){
20199
- this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot);
20200
- }
20201
- var components = srcEntity._components;
20202
- for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
20203
- var sourceComp = components[i1];
20204
- if (!_instanceof1$2(sourceComp, Transform)) {
20205
- var targetComp = targetEntity.addComponent(sourceComp.constructor);
20206
- ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot);
20207
- }
20208
- }
20209
- };
20210
- /**
20211
- * Destroy self.
20212
- */ _proto.destroy = function destroy() {
20213
- if (this._destroyed) {
20214
- return;
20215
- }
20216
- EngineObject1.prototype.destroy.call(this);
20217
- if (this._templateResource) {
20218
- this._isTemplate || this._templateResource._addReferCount(-1);
20219
- this._templateResource = null;
20220
- }
20221
- var components = this._components;
20222
- for(var i = components.length - 1; i >= 0; i--){
20223
- components[i].destroy();
20224
- }
20225
- this._components.length = 0;
20226
- var children = this._children;
20227
- while(children.length > 0){
20228
- children[0].destroy();
20229
- }
20230
- if (this._isRoot) {
20231
- this._scene.removeRootEntity(this);
20232
- } else {
20233
- this._setParent(null);
20234
- }
20235
- this.isActive = false;
20236
- };
20237
- /**
20238
- * @internal
20239
- */ _proto._removeComponent = function _removeComponent(component) {
20240
- ComponentsDependencies._removeCheck(this, component.constructor);
20241
- var components = this._components;
20242
- components.splice(components.indexOf(component), 1);
20243
- };
20244
- /**
20245
- * @internal
20246
- */ _proto._addScript = function _addScript(script) {
20247
- script._entityScriptsIndex = this._scripts.length;
20248
- this._scripts.add(script);
20249
- };
20250
- /**
20251
- * @internal
20252
- */ _proto._removeScript = function _removeScript(script) {
20253
- var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
20254
- replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
20255
- script._entityScriptsIndex = -1;
20256
- };
20257
- /**
20258
- * @internal
20259
- */ _proto._removeFromParent = function _removeFromParent() {
20260
- var oldParent = this._parent;
20261
- if (oldParent != null) {
20262
- var oldSibling = oldParent._children;
20263
- var index = this._siblingIndex;
20264
- oldSibling.splice(index, 1);
20265
- for(var n = oldSibling.length; index < n; index++){
20266
- oldSibling[index]._siblingIndex--;
20267
- }
20268
- this._parent = null;
20269
- this._siblingIndex = -1;
20270
- }
20271
- };
20272
- /**
20273
- * @internal
20274
- */ _proto._processActive = function _processActive(activeChangeFlag) {
20275
- if (this._activeChangedComponents) {
20276
- 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.";
20277
- }
20278
- this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
20279
- this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
20280
- this._setActiveComponents(true, activeChangeFlag);
20281
- };
20282
- /**
20283
- * @internal
20284
- */ _proto._processInActive = function _processInActive(activeChangeFlag) {
20285
- if (this._activeChangedComponents) {
20286
- 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.";
20287
- }
20288
- this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
20289
- this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
20290
- this._setActiveComponents(false, activeChangeFlag);
20291
- };
20292
- _proto._addToChildrenList = function _addToChildrenList(index, child) {
20293
- var children = this._children;
20294
- var childCount = children.length;
20295
- if (index === undefined) {
20296
- child._siblingIndex = childCount;
20297
- children.push(child);
20298
- } else {
20299
- if (index < 0 || index > childCount) {
20300
- throw "The index " + index + " is out of child list bounds " + childCount;
20301
- }
20302
- child._siblingIndex = index;
20303
- children.splice(index, 0, child);
20304
- for(var i = index + 1, n = childCount + 1; i < n; i++){
20305
- children[i]._siblingIndex++;
20306
- }
20307
- }
20308
- };
20309
- _proto._setParent = function _setParent(parent, siblingIndex) {
20310
- var oldParent = this._parent;
20311
- if (parent !== oldParent) {
20312
- this._removeFromParent();
20313
- this._parent = parent;
20314
- if (parent) {
20315
- parent._addToChildrenList(siblingIndex, this);
20316
- var oldScene = this._scene;
20317
- var parentScene = parent._scene;
20318
- var inActiveChangeFlag = ActiveChangeFlag.None;
20319
- if (!parent._isActiveInHierarchy) {
20320
- this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
20321
- }
20322
- if (parent._isActiveInScene) {
20323
- // cross scene should inActive first and then active
20324
- this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
20325
- } else {
20326
- this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
20327
- }
20328
- inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
20329
- if (oldScene !== parentScene) {
20330
- Entity._traverseSetOwnerScene(this, parentScene);
20331
- }
20332
- var activeChangeFlag = ActiveChangeFlag.None;
20333
- if (this._isActive) {
20334
- if (parent._isActiveInHierarchy) {
20335
- !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20336
- }
20337
- if (parent._isActiveInScene) {
20338
- (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
20339
- }
20340
- }
20341
- activeChangeFlag && this._processActive(activeChangeFlag);
20342
- } else {
20343
- var inActiveChangeFlag1 = ActiveChangeFlag.None;
20344
- this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
20345
- this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
20346
- inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
20347
- if (oldParent) {
20348
- Entity._traverseSetOwnerScene(this, null);
20349
- }
20350
- }
20351
- this._setTransformDirty();
20352
- }
20353
- };
20354
- _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
20355
- for(var i = this._components.length - 1; i >= 0; i--){
20356
- var component = this._components[i];
20357
- if (_instanceof1$2(component, type)) {
20358
- results.push(component);
20359
- }
20360
- }
20361
- for(var i1 = this._children.length - 1; i1 >= 0; i1--){
20362
- this._children[i1]._getComponentsInChildren(type, results);
20363
- }
20364
- };
20365
- _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
20366
- var activeChangedComponents = this._activeChangedComponents;
20367
- for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
20368
- activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
20369
- }
20370
- this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
20371
- this._activeChangedComponents = null;
20372
- };
20373
- _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
20374
- activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
20375
- activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
20376
- var components = this._components;
20377
- for(var i = 0, n = components.length; i < n; i++){
20378
- var component = components[i];
20379
- (component.enabled || !component._awoken) && activeChangedComponents.push(component);
20380
- }
20381
- var children = this._children;
20382
- for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
20383
- var child = children[i1];
20384
- child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
20385
- }
20386
- };
20387
- _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
20388
- activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
20389
- activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
20390
- var components = this._components;
20391
- for(var i = 0, n = components.length; i < n; i++){
20392
- var component = components[i];
20393
- component.enabled && activeChangedComponents.push(component);
20394
- }
20395
- var children = this._children;
20396
- for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
20397
- var child = children[i1];
20398
- child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
20399
- }
20400
- };
20401
- _proto._setTransformDirty = function _setTransformDirty() {
20402
- if (this.transform) {
20403
- this.transform._parentChange();
20404
- } else {
20405
- for(var i = 0, len = this._children.length; i < len; i++){
20406
- this._children[i]._setTransformDirty();
20202
+ {
20203
+ key: "clearCoatTexture",
20204
+ get: /**
20205
+ * The clearCoat layer intensity texture.
20206
+ */ function get() {
20207
+ return this.shaderData.getTexture(PBRBaseMaterial._clearCoatTextureProp);
20208
+ },
20209
+ set: function set(value) {
20210
+ this.shaderData.setTexture(PBRBaseMaterial._clearCoatTextureProp, value);
20211
+ if (value) {
20212
+ this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_TEXTURE");
20213
+ } else {
20214
+ this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_TEXTURE");
20215
+ }
20407
20216
  }
20408
- }
20409
- };
20410
- _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
20411
- target = Math.min(target, sibling.length - 1);
20412
- if (target < 0) {
20413
- throw "Sibling index " + target + " should large than 0";
20414
- }
20415
- if (this._siblingIndex !== target) {
20416
- var oldIndex = this._siblingIndex;
20417
- if (target < oldIndex) {
20418
- for(var i = oldIndex; i >= target; i--){
20419
- var child = i == target ? this : sibling[i - 1];
20420
- sibling[i] = child;
20421
- child._siblingIndex = i;
20217
+ },
20218
+ {
20219
+ key: "clearCoatRoughness",
20220
+ get: /**
20221
+ * The clearCoat layer roughness, default 0.
20222
+ */ function get() {
20223
+ return this.shaderData.getFloat(PBRBaseMaterial._clearCoatRoughnessProp);
20224
+ },
20225
+ set: function set(value) {
20226
+ this.shaderData.setFloat(PBRBaseMaterial._clearCoatRoughnessProp, value);
20227
+ }
20228
+ },
20229
+ {
20230
+ key: "clearCoatRoughnessTexture",
20231
+ get: /**
20232
+ * The clearCoat layer roughness texture.
20233
+ */ function get() {
20234
+ return this.shaderData.getTexture(PBRBaseMaterial._clearCoatRoughnessTextureProp);
20235
+ },
20236
+ set: function set(value) {
20237
+ this.shaderData.setTexture(PBRBaseMaterial._clearCoatRoughnessTextureProp, value);
20238
+ if (value) {
20239
+ this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
20240
+ } else {
20241
+ this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
20422
20242
  }
20423
- } else {
20424
- for(var i1 = oldIndex; i1 <= target; i1++){
20425
- var child1 = i1 == target ? this : sibling[i1 + 1];
20426
- sibling[i1] = child1;
20427
- child1._siblingIndex = i1;
20243
+ }
20244
+ },
20245
+ {
20246
+ key: "clearCoatNormalTexture",
20247
+ get: /**
20248
+ * The clearCoat normal map texture.
20249
+ */ function get() {
20250
+ return this.shaderData.getTexture(PBRBaseMaterial._clearCoatNormalTextureProp);
20251
+ },
20252
+ set: function set(value) {
20253
+ this.shaderData.setTexture(PBRBaseMaterial._clearCoatNormalTextureProp, value);
20254
+ if (value) {
20255
+ this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
20256
+ } else {
20257
+ this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
20428
20258
  }
20429
20259
  }
20430
20260
  }
20431
- };
20261
+ ]);
20262
+ return PBRBaseMaterial;
20263
+ }(BaseMaterial);
20264
+ (function() {
20265
+ PBRBaseMaterial._occlusionTextureIntensityProp = ShaderProperty.getByName("material_OcclusionIntensity");
20266
+ })();
20267
+ (function() {
20268
+ PBRBaseMaterial._occlusionTextureCoordProp = ShaderProperty.getByName("material_OcclusionTextureCoord");
20269
+ })();
20270
+ (function() {
20271
+ PBRBaseMaterial._occlusionTextureProp = ShaderProperty.getByName("material_OcclusionTexture");
20272
+ })();
20273
+ (function() {
20274
+ PBRBaseMaterial._clearCoatProp = ShaderProperty.getByName("material_ClearCoat");
20275
+ })();
20276
+ (function() {
20277
+ PBRBaseMaterial._clearCoatTextureProp = ShaderProperty.getByName("material_ClearCoatTexture");
20278
+ })();
20279
+ (function() {
20280
+ PBRBaseMaterial._clearCoatRoughnessProp = ShaderProperty.getByName("material_ClearCoatRoughness");
20281
+ })();
20282
+ (function() {
20283
+ PBRBaseMaterial._clearCoatRoughnessTextureProp = ShaderProperty.getByName("material_ClearCoatRoughnessTexture");
20284
+ })();
20285
+ (function() {
20286
+ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material_ClearCoatNormalTexture");
20287
+ })();
20288
+ /**
20289
+ * PBR (Metallic-Roughness Workflow) Material.
20290
+ */ var PBRMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
20291
+ _inherits$2(PBRMaterial, PBRBaseMaterial1);
20292
+ function PBRMaterial(engine) {
20293
+ var _this;
20294
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr")) || this;
20295
+ _this._anisotropyRotation = 0;
20296
+ var shaderData = _this.shaderData;
20297
+ shaderData.setFloat(PBRMaterial._metallicProp, 1);
20298
+ shaderData.setFloat(PBRMaterial._roughnessProp, 1);
20299
+ shaderData.setFloat(PBRMaterial._iorProp, 1.5);
20300
+ shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0));
20301
+ return _this;
20302
+ }
20303
+ var _proto = PBRMaterial.prototype;
20432
20304
  /**
20433
- * @deprecated
20434
- */ _proto.getInvModelMatrix = function getInvModelMatrix() {
20435
- if (this._inverseWorldMatFlag.flag) {
20436
- Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
20437
- this._inverseWorldMatFlag.flag = false;
20438
- }
20439
- return this._invModelMatrix;
20305
+ * @inheritdoc
20306
+ */ _proto.clone = function clone() {
20307
+ var dest = new PBRMaterial(this._engine);
20308
+ this.cloneTo(dest);
20309
+ return dest;
20440
20310
  };
20441
- /**
20442
- * @internal
20443
- */ Entity._findChildByName = function _findChildByName(root, name1) {
20444
- var children = root._children;
20445
- for(var i = children.length - 1; i >= 0; i--){
20446
- var child = children[i];
20447
- if (child.name === name1) {
20448
- return child;
20311
+ _create_class$2(PBRMaterial, [
20312
+ {
20313
+ key: "ior",
20314
+ get: /**
20315
+ * Index Of Refraction.
20316
+ * @defaultValue `1.5`
20317
+ */ function get() {
20318
+ return this.shaderData.getFloat(PBRMaterial._iorProp);
20319
+ },
20320
+ set: function set(v) {
20321
+ this.shaderData.setFloat(PBRMaterial._iorProp, Math.max(v, 0));
20449
20322
  }
20450
- }
20451
- return null;
20452
- };
20453
- /**
20454
- * @internal
20455
- */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
20456
- entity._scene = scene;
20457
- var children = entity._children;
20458
- for(var i = children.length - 1; i >= 0; i--){
20459
- this._traverseSetOwnerScene(children[i], scene);
20460
- }
20461
- };
20462
- _create_class$2(Entity, [
20323
+ },
20463
20324
  {
20464
- key: "isActive",
20325
+ key: "metallic",
20465
20326
  get: /**
20466
- * Whether to activate locally.
20327
+ * Metallic.
20328
+ * @defaultValue `1.0`
20467
20329
  */ function get() {
20468
- return this._isActive;
20330
+ return this.shaderData.getFloat(PBRMaterial._metallicProp);
20469
20331
  },
20470
20332
  set: function set(value) {
20471
- if (value !== this._isActive) {
20472
- this._isActive = value;
20473
- if (value) {
20474
- var parent = this._parent;
20475
- var activeChangeFlag = ActiveChangeFlag.None;
20476
- if (this._isRoot && this._scene._isActiveInEngine) {
20477
- activeChangeFlag |= ActiveChangeFlag.All;
20478
- } else {
20479
- var _parent, _parent1;
20480
- ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20481
- ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
20482
- }
20483
- activeChangeFlag && this._processActive(activeChangeFlag);
20333
+ this.shaderData.setFloat(PBRMaterial._metallicProp, value);
20334
+ }
20335
+ },
20336
+ {
20337
+ key: "roughness",
20338
+ get: /**
20339
+ * Roughness. default 1.0.
20340
+ * @defaultValue `1.0`
20341
+ */ function get() {
20342
+ return this.shaderData.getFloat(PBRMaterial._roughnessProp);
20343
+ },
20344
+ set: function set(value) {
20345
+ this.shaderData.setFloat(PBRMaterial._roughnessProp, value);
20346
+ }
20347
+ },
20348
+ {
20349
+ key: "roughnessMetallicTexture",
20350
+ get: /**
20351
+ * Roughness metallic texture.
20352
+ * @remarks G channel is roughness, B channel is metallic
20353
+ */ function get() {
20354
+ return this.shaderData.getTexture(PBRMaterial._roughnessMetallicTextureProp);
20355
+ },
20356
+ set: function set(value) {
20357
+ this.shaderData.setTexture(PBRMaterial._roughnessMetallicTextureProp, value);
20358
+ if (value) {
20359
+ this.shaderData.enableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
20360
+ } else {
20361
+ this.shaderData.disableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
20362
+ }
20363
+ }
20364
+ },
20365
+ {
20366
+ key: "anisotropy",
20367
+ get: /**
20368
+ * The strength of anisotropy, when anisotropyTexture is present, this value is multiplied by the blue channel.
20369
+ * @defaultValue `0`
20370
+ */ function get() {
20371
+ return this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp).z;
20372
+ },
20373
+ set: function set(value) {
20374
+ var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
20375
+ if (!!anisotropyInfo.z !== !!value) {
20376
+ if (value === 0) {
20377
+ this.shaderData.disableMacro("MATERIAL_ENABLE_ANISOTROPY");
20484
20378
  } else {
20485
- var activeChangeFlag1 = ActiveChangeFlag.None;
20486
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
20487
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
20488
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
20379
+ this.shaderData.enableMacro("MATERIAL_ENABLE_ANISOTROPY");
20489
20380
  }
20490
20381
  }
20382
+ anisotropyInfo.z = value;
20491
20383
  }
20492
20384
  },
20493
20385
  {
20494
- key: "isActiveInHierarchy",
20386
+ key: "anisotropyRotation",
20495
20387
  get: /**
20496
- * Whether it is active in the hierarchy.
20388
+ * The rotation of the anisotropy in tangent, bitangent space, value in degrees.
20389
+ * @defaultValue `0`
20497
20390
  */ function get() {
20498
- return this._isActiveInHierarchy;
20391
+ return this._anisotropyRotation;
20392
+ },
20393
+ set: function set(value) {
20394
+ if (this._anisotropyRotation !== value) {
20395
+ this._anisotropyRotation = value;
20396
+ var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
20397
+ var rad = MathUtil.degreeToRadFactor * value;
20398
+ anisotropyInfo.x = Math.cos(rad);
20399
+ anisotropyInfo.y = Math.sin(rad);
20400
+ }
20499
20401
  }
20500
20402
  },
20501
20403
  {
20502
- key: "parent",
20404
+ key: "anisotropyTexture",
20503
20405
  get: /**
20504
- * The parent entity.
20406
+ * The anisotropy texture.
20407
+ * @remarks
20408
+ * Red and green channels represent the anisotropy direction in [-1, 1] tangent, bitangent space, to be rotated by anisotropyRotation.
20409
+ * The blue channel contains strength as [0, 1] to be multiplied by anisotropy.
20505
20410
  */ function get() {
20506
- return this._parent;
20411
+ return this.shaderData.getTexture(PBRMaterial._anisotropyTextureProp);
20507
20412
  },
20508
20413
  set: function set(value) {
20509
- this._setParent(value);
20414
+ this.shaderData.setTexture(PBRMaterial._anisotropyTextureProp, value);
20415
+ if (value) {
20416
+ this.shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
20417
+ } else {
20418
+ this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
20419
+ }
20420
+ }
20421
+ }
20422
+ ]);
20423
+ return PBRMaterial;
20424
+ }(PBRBaseMaterial);
20425
+ (function() {
20426
+ PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
20427
+ })();
20428
+ (function() {
20429
+ PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
20430
+ })();
20431
+ (function() {
20432
+ PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
20433
+ })();
20434
+ (function() {
20435
+ PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
20436
+ })();
20437
+ (function() {
20438
+ PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
20439
+ })();
20440
+ (function() {
20441
+ PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
20442
+ })();
20443
+ /**
20444
+ * PBR (Specular-Glossiness Workflow) Material.
20445
+ */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
20446
+ _inherits$2(PBRSpecularMaterial, PBRBaseMaterial1);
20447
+ function PBRSpecularMaterial(engine) {
20448
+ var _this;
20449
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
20450
+ _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new Color(1, 1, 1, 1));
20451
+ _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
20452
+ return _this;
20453
+ }
20454
+ var _proto = PBRSpecularMaterial.prototype;
20455
+ /**
20456
+ * @inheritdoc
20457
+ */ _proto.clone = function clone() {
20458
+ var dest = new PBRSpecularMaterial(this._engine);
20459
+ this.cloneTo(dest);
20460
+ return dest;
20461
+ };
20462
+ _create_class$2(PBRSpecularMaterial, [
20463
+ {
20464
+ key: "specularColor",
20465
+ get: /**
20466
+ * Specular color.
20467
+ */ function get() {
20468
+ return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20469
+ },
20470
+ set: function set(value) {
20471
+ var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20472
+ if (value !== specularColor) {
20473
+ specularColor.copyFrom(value);
20474
+ }
20510
20475
  }
20511
20476
  },
20512
20477
  {
20513
- key: "children",
20478
+ key: "glossiness",
20514
20479
  get: /**
20515
- * The children entities
20480
+ * Glossiness.
20516
20481
  */ function get() {
20517
- return this._children;
20482
+ return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
20483
+ },
20484
+ set: function set(value) {
20485
+ this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
20518
20486
  }
20519
20487
  },
20520
20488
  {
20521
- key: "childCount",
20489
+ key: "specularGlossinessTexture",
20522
20490
  get: /**
20523
- * @deprecated Please use `children.length` property instead.
20524
- * Number of the children entities
20491
+ * Specular glossiness texture.
20492
+ * @remarks RGB is specular, A is glossiness
20525
20493
  */ function get() {
20526
- return this._children.length;
20494
+ return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
20495
+ },
20496
+ set: function set(value) {
20497
+ this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
20498
+ if (value) {
20499
+ this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20500
+ } else {
20501
+ this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20502
+ }
20503
+ }
20504
+ }
20505
+ ]);
20506
+ return PBRSpecularMaterial;
20507
+ }(PBRBaseMaterial);
20508
+ (function() {
20509
+ PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
20510
+ })();
20511
+ (function() {
20512
+ PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
20513
+ })();
20514
+ (function() {
20515
+ PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
20516
+ })();
20517
+ (function() {
20518
+ PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
20519
+ })();
20520
+ /**
20521
+ * Unlit Material.
20522
+ */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
20523
+ _inherits$2(UnlitMaterial, BaseMaterial1);
20524
+ function UnlitMaterial(engine) {
20525
+ var _this;
20526
+ _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
20527
+ var shaderData = _this.shaderData;
20528
+ shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
20529
+ shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
20530
+ shaderData.setColor(UnlitMaterial._baseColorProp, new Color(1, 1, 1, 1));
20531
+ shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new Vector4(1, 1, 0, 0));
20532
+ return _this;
20533
+ }
20534
+ var _proto = UnlitMaterial.prototype;
20535
+ /**
20536
+ * @inheritdoc
20537
+ */ _proto.clone = function clone() {
20538
+ var dest = new UnlitMaterial(this._engine);
20539
+ this.cloneTo(dest);
20540
+ return dest;
20541
+ };
20542
+ _create_class$2(UnlitMaterial, [
20543
+ {
20544
+ key: "baseColor",
20545
+ get: /**
20546
+ * Base color.
20547
+ */ function get() {
20548
+ return this.shaderData.getColor(UnlitMaterial._baseColorProp);
20549
+ },
20550
+ set: function set(value) {
20551
+ var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
20552
+ if (value !== baseColor) {
20553
+ baseColor.copyFrom(value);
20554
+ }
20527
20555
  }
20528
20556
  },
20529
20557
  {
20530
- key: "scene",
20558
+ key: "baseTexture",
20531
20559
  get: /**
20532
- * The scene the entity belongs to.
20560
+ * Base texture.
20533
20561
  */ function get() {
20534
- return this._scene;
20562
+ return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
20563
+ },
20564
+ set: function set(value) {
20565
+ this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
20566
+ if (value) {
20567
+ this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
20568
+ } else {
20569
+ this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
20570
+ }
20535
20571
  }
20536
20572
  },
20537
20573
  {
20538
- key: "siblingIndex",
20574
+ key: "tilingOffset",
20539
20575
  get: /**
20540
- * The sibling index.
20576
+ * Tiling and offset of main textures.
20541
20577
  */ function get() {
20542
- return this._siblingIndex;
20578
+ return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20543
20579
  },
20544
20580
  set: function set(value) {
20545
- if (this._siblingIndex === -1) {
20546
- throw "The entity " + this.name + " is not in the hierarchy";
20581
+ var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20582
+ if (value !== tilingOffset) {
20583
+ tilingOffset.copyFrom(value);
20547
20584
  }
20548
- this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
20549
20585
  }
20550
20586
  }
20551
20587
  ]);
20552
- return Entity;
20553
- }(EngineObject);
20588
+ return UnlitMaterial;
20589
+ }(BaseMaterial);
20590
+ /**
20591
+ * @internal
20592
+ */ var BasicResources = /*#__PURE__*/ function() {
20593
+ var BasicResources = function BasicResources(engine) {
20594
+ // prettier-ignore
20595
+ var vertices = new Float32Array([
20596
+ -1,
20597
+ -1,
20598
+ 0,
20599
+ 1,
20600
+ 1,
20601
+ -1,
20602
+ 1,
20603
+ 1,
20604
+ -1,
20605
+ 1,
20606
+ 0,
20607
+ 0,
20608
+ 1,
20609
+ 1,
20610
+ 1,
20611
+ 0
20612
+ ]); // right-top
20613
+ // prettier-ignore
20614
+ var flipYVertices = new Float32Array([
20615
+ 1,
20616
+ -1,
20617
+ 1,
20618
+ 0,
20619
+ -1,
20620
+ -1,
20621
+ 0,
20622
+ 0,
20623
+ 1,
20624
+ 1,
20625
+ 1,
20626
+ 1,
20627
+ -1,
20628
+ 1,
20629
+ 0,
20630
+ 1
20631
+ ]); // left-top
20632
+ var blitMaterial = new Material(engine, Shader.find("blit"));
20633
+ blitMaterial._addReferCount(1);
20634
+ blitMaterial.renderState.depthState.enabled = false;
20635
+ blitMaterial.renderState.depthState.writeEnabled = false;
20636
+ this.blitMesh = this._createBlitMesh(engine, vertices);
20637
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
20638
+ this.blitMaterial = blitMaterial;
20639
+ };
20640
+ var _proto = BasicResources.prototype;
20641
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
20642
+ var mesh = new ModelMesh(engine);
20643
+ mesh._addReferCount(1);
20644
+ mesh.setVertexElements([
20645
+ new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
20646
+ ]);
20647
+ mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
20648
+ mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
20649
+ return mesh;
20650
+ };
20651
+ return BasicResources;
20652
+ }();
20554
20653
  /**
20555
20654
  * @internal
20556
20655
  * Rendering context.
@@ -42840,25 +42939,31 @@
42840
42939
  camera.enabled = false;
42841
42940
  };
42842
42941
  _proto._createRenderer = function _createRenderer(context, entityInfo, entity) {
42843
- var _loop = function _loop(i) {
42844
- var glTFPrimitive = glTFMeshPrimitives[i];
42845
- var materialIndex = glTFPrimitive.material;
42846
- promises.push(Promise.all([
42847
- context.get(exports.GLTFParserType.Mesh, meshID),
42848
- skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
42849
- materialIndex !== undefined && context.get(exports.GLTFParserType.Material, materialIndex)
42850
- ]).then(function(param) {
42851
- var meshes = param[0], skin = param[1], material = param[2];
42942
+ var _this = this;
42943
+ var meshID = entityInfo.mesh, skinID = entityInfo.skin;
42944
+ var glTFMesh = context.glTF.meshes[meshID];
42945
+ var glTFMeshPrimitives = glTFMesh.primitives;
42946
+ var rendererCount = glTFMeshPrimitives.length;
42947
+ var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
42948
+ var materialPromises = new Array(rendererCount);
42949
+ for(var i = 0; i < rendererCount; i++){
42950
+ materialPromises[i] = context.get(exports.GLTFParserType.Material, glTFMeshPrimitives[i].material);
42951
+ }
42952
+ return Promise.all([
42953
+ context.get(exports.GLTFParserType.Mesh, meshID),
42954
+ skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
42955
+ Promise.all(materialPromises)
42956
+ ]).then(function(param) {
42957
+ var _loop = function _loop(i) {
42958
+ var material = materials[i] || exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine);
42959
+ var glTFPrimitive = glTFMeshPrimitives[i];
42852
42960
  var mesh = meshes[i];
42853
- var renderer;
42854
- material || (material = exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
42961
+ var renderer = void 0;
42855
42962
  if (skin || blendShapeWeights) {
42856
42963
  var skinRenderer = entity.addComponent(SkinnedMeshRenderer);
42857
42964
  skinRenderer.mesh = mesh;
42858
42965
  if (skin) {
42859
- skinRenderer.rootBone = skin._rootBone;
42860
- skinRenderer.bones = skin._bones;
42861
- _this._computeLocalBounds(skinRenderer, mesh, skin._bones, skin._rootBone, skin.inverseBindMatrices);
42966
+ _this._computeLocalBounds(skinRenderer, mesh, skin.bones, skin.rootBone, skin.inverseBindMatrices);
42862
42967
  skinRenderer.skin = skin;
42863
42968
  }
42864
42969
  if (blendShapeWeights) {
@@ -42877,17 +42982,10 @@
42877
42982
  }
42878
42983
  });
42879
42984
  GLTFParser.executeExtensionsAdditiveAndParse(glTFPrimitive.extensions, context, renderer, glTFPrimitive);
42880
- }));
42881
- };
42882
- var _this = this;
42883
- var glTFMeshes = context.glTF.meshes;
42884
- var meshID = entityInfo.mesh, skinID = entityInfo.skin;
42885
- var glTFMesh = glTFMeshes[meshID];
42886
- var glTFMeshPrimitives = glTFMesh.primitives;
42887
- var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
42888
- var promises = new Array();
42889
- for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
42890
- return Promise.all(promises);
42985
+ };
42986
+ var meshes = param[0], skin = param[1], materials = param[2];
42987
+ for(var i = 0; i < rendererCount; i++)_loop(i);
42988
+ });
42891
42989
  };
42892
42990
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
42893
42991
  var rootBoneIndex = bones.indexOf(rootBone);
@@ -42940,7 +43038,7 @@
42940
43038
  var jointCount = joints.length;
42941
43039
  var skin = new Skin(name);
42942
43040
  skin.inverseBindMatrices.length = jointCount;
42943
- skin._bones.length = jointCount;
43041
+ var bones = new Array(jointCount);
42944
43042
  // parse IBM
42945
43043
  var accessor = glTF.accessors[inverseBindMatrices];
42946
43044
  var skinPromise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
@@ -42952,21 +43050,20 @@
42952
43050
  skin.inverseBindMatrices[i] = inverseBindMatrix;
42953
43051
  // Get bones
42954
43052
  var bone = entities[joints[i]];
42955
- skin._bones[i] = bone;
43053
+ bones[i] = bone;
42956
43054
  skin.joints[i] = bone.name;
42957
- // Get skeleton
42958
- if (skeleton !== undefined) {
42959
- var rootBone = entities[skeleton];
42960
- skin._rootBone = rootBone;
42961
- skin.skeleton = rootBone.name;
43055
+ }
43056
+ skin.bones = bones;
43057
+ // Get skeleton
43058
+ if (skeleton !== undefined) {
43059
+ var rootBone = entities[skeleton];
43060
+ skin.rootBone = rootBone;
43061
+ } else {
43062
+ var rootBone1 = _this._findSkeletonRootBone(joints, entities);
43063
+ if (rootBone1) {
43064
+ skin.rootBone = rootBone1;
42962
43065
  } else {
42963
- var rootBone1 = _this._findSkeletonRootBone(joints, entities);
42964
- if (rootBone1) {
42965
- skin._rootBone = rootBone1;
42966
- skin.skeleton = rootBone1.name;
42967
- } else {
42968
- throw "Failed to find skeleton root bone.";
42969
- }
43066
+ throw "Failed to find skeleton root bone.";
42970
43067
  }
42971
43068
  }
42972
43069
  return skin;
@@ -44995,7 +45092,7 @@
44995
45092
  ], KHR_materials_anisotropy);
44996
45093
 
44997
45094
  //@ts-ignore
44998
- var version = "1.2.0-beta.4";
45095
+ var version = "1.2.0-beta.5";
44999
45096
  console.log("Galacean engine version: " + version);
45000
45097
  for(var key in CoreObjects){
45001
45098
  Loader.registerClass(key, CoreObjects[key]);