@galacean/engine 0.0.0-experimental-stateMachine.0 → 0.0.0-experimental-1.2-xr.0

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;
@@ -8836,6 +8847,7 @@
8836
8847
  var program = this._glProgram;
8837
8848
  var uniformInfos = this._getUniformInfos();
8838
8849
  var attributeInfos = this._getAttributeInfos();
8850
+ var basicResources = this._engine._basicResources;
8839
8851
  uniformInfos.forEach(function(param) {
8840
8852
  var name1 = param.name, size = param.size, type = param.type;
8841
8853
  var shaderUniform = new ShaderUniform(_this._engine);
@@ -8929,16 +8941,16 @@
8929
8941
  var defaultTexture;
8930
8942
  switch(type){
8931
8943
  case gl.SAMPLER_2D:
8932
- defaultTexture = _this._engine._magentaTexture2D;
8944
+ defaultTexture = basicResources.whiteTexture2D;
8933
8945
  break;
8934
8946
  case gl.SAMPLER_CUBE:
8935
- defaultTexture = _this._engine._magentaTextureCube;
8947
+ defaultTexture = basicResources.whiteTextureCube;
8936
8948
  break;
8937
8949
  case gl.UNSIGNED_INT_SAMPLER_2D:
8938
- defaultTexture = _this._engine._uintMagentaTexture2D;
8950
+ defaultTexture = basicResources.uintWhiteTexture2D;
8939
8951
  break;
8940
8952
  case gl.SAMPLER_2D_ARRAY:
8941
- defaultTexture = _this._engine._magentaTexture2DArray;
8953
+ defaultTexture = basicResources.whiteTexture2DArray;
8942
8954
  break;
8943
8955
  case gl.SAMPLER_2D_SHADOW:
8944
8956
  defaultTexture = _this._engine._depthTexture2D;
@@ -10429,7 +10441,7 @@
10429
10441
  return shaderData;
10430
10442
  };
10431
10443
  _proto.cloneTo = function cloneTo(target) {
10432
- CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
10444
+ CloneManager.deepCloneObject(this._macroCollection, target._macroCollection, new Map());
10433
10445
  Object.assign(target._macroMap, this._macroMap);
10434
10446
  var referCount = target._getReferCount();
10435
10447
  var propertyValueMap = this._propertyValueMap;
@@ -11248,14 +11260,15 @@
11248
11260
  }
11249
11261
  this._endLoop(swapFn);
11250
11262
  };
11251
- _proto.forEachAndClean = function forEachAndClean(callbackFn) {
11263
+ _proto.forEachAndClean = function forEachAndClean(callbackFn, swapFn) {
11252
11264
  this._startLoop();
11265
+ var preEnd = this.length;
11253
11266
  var elements = this._elements;
11254
- for(var i = 0, n = this.length; i < n; i++){
11267
+ for(var i = 0, n = preEnd; i < n; i++){
11255
11268
  var element = elements[i];
11256
11269
  element && callbackFn(element);
11257
11270
  }
11258
- this._endLoopAndClear();
11271
+ this._endLoopAndClean(preEnd, elements, swapFn);
11259
11272
  };
11260
11273
  _proto.sort = function sort(compareFn) {
11261
11274
  Utils._quickSort(this._elements, 0, this.length, compareFn);
@@ -11288,9 +11301,17 @@
11288
11301
  this._blankCount = 0;
11289
11302
  }
11290
11303
  };
11291
- _proto._endLoopAndClear = function _endLoopAndClear() {
11304
+ _proto._endLoopAndClean = function _endLoopAndClean(preEnd, elements, swapFn) {
11305
+ var index = 0;
11306
+ for(var i = preEnd, n = this.length; i < n; i++){
11307
+ var element = elements[i];
11308
+ if (!element) continue;
11309
+ elements[index] = element;
11310
+ swapFn(element, index);
11311
+ index++;
11312
+ }
11292
11313
  this._isLooping = false;
11293
- this.length = 0;
11314
+ this.length = index;
11294
11315
  this._blankCount = 0;
11295
11316
  };
11296
11317
  return DisorderedArray;
@@ -15763,269 +15784,769 @@
15763
15784
  (function() {
15764
15785
  PrimitiveMesh._spherePoleIdx = 0;
15765
15786
  })();
15787
+ function _is_native_reflect_construct$1() {
15788
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
15789
+ if (Reflect.construct.sham) return false;
15790
+ if (typeof Proxy === "function") return true;
15791
+ try {
15792
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
15793
+ return true;
15794
+ } catch (e) {
15795
+ return false;
15796
+ }
15797
+ }
15798
+ function _construct$1(Parent, args, Class) {
15799
+ if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
15800
+ else {
15801
+ _construct$1 = function construct(Parent, args, Class) {
15802
+ var a = [
15803
+ null
15804
+ ];
15805
+ a.push.apply(a, args);
15806
+ var Constructor = Function.bind.apply(Parent, a);
15807
+ var instance = new Constructor();
15808
+ if (Class) _set_prototype_of$2(instance, Class.prototype);
15809
+ return instance;
15810
+ };
15811
+ }
15812
+ return _construct$1.apply(null, arguments);
15813
+ }
15766
15814
  /**
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;
15815
+ * Layer, used for bit operations.
15816
+ */ exports.Layer = void 0;
15817
+ (function(Layer) {
15818
+ Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
15819
+ Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
15820
+ Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
15821
+ Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
15822
+ Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
15823
+ Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
15824
+ Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
15825
+ Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
15826
+ Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
15827
+ Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
15828
+ Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
15829
+ Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
15830
+ Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
15831
+ Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
15832
+ Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
15833
+ Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
15834
+ Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
15835
+ Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
15836
+ Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
15837
+ Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
15838
+ Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
15839
+ Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
15840
+ Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
15841
+ Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
15842
+ Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
15843
+ Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
15844
+ Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
15845
+ Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
15846
+ Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
15847
+ Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
15848
+ Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
15849
+ Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
15850
+ Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
15851
+ Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
15852
+ })(exports.Layer || (exports.Layer = {}));
15853
+ var ComponentCloner = /*#__PURE__*/ function() {
15854
+ var ComponentCloner = function ComponentCloner() {};
15855
+ /**
15856
+ * Clone component.
15857
+ * @param source - Clone source
15858
+ * @param target - Clone target
15859
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
15860
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
15861
+ for(var k in source){
15862
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
15863
+ }
15864
+ if (source._cloneTo) {
15865
+ source._cloneTo(target, srcRoot, targetRoot);
15866
+ }
15778
15867
  };
15779
- _inherits$2(Skin, EngineObject1);
15780
- return Skin;
15781
- }(EngineObject);
15868
+ return ComponentCloner;
15869
+ }();
15782
15870
  /**
15783
- * SkinnedMeshRenderer.
15784
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
15785
- var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
15871
+ * Entity, be used as components container.
15872
+ */ var Entity = /*#__PURE__*/ function(EngineObject1) {
15873
+ var Entity = function Entity(engine, name1) {
15786
15874
  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;
15875
+ _this = EngineObject1.call(this, engine) || this;
15876
+ /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
15877
+ /** @internal */ _this._isActiveInHierarchy = false;
15878
+ /** @internal */ _this._isActiveInScene = false;
15879
+ /** @internal */ _this._components = [];
15880
+ /** @internal */ _this._scripts = new DisorderedArray();
15881
+ /** @internal */ _this._children = [];
15882
+ /** @internal */ _this._isRoot = false;
15883
+ /** @internal */ _this._isActive = true;
15884
+ /** @internal */ _this._siblingIndex = -1;
15885
+ /** @internal */ _this._isTemplate = false;
15886
+ _this._parent = null;
15887
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
15888
+ _this._invModelMatrix = new Matrix();
15889
+ _this.name = name1;
15890
+ _this.transform = _this.addComponent(Transform);
15891
+ _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
15804
15892
  return _this;
15805
15893
  };
15806
- _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
15807
- var _proto = SkinnedMeshRenderer.prototype;
15894
+ _inherits$2(Entity, EngineObject1);
15895
+ var _proto = Entity.prototype;
15808
15896
  /**
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);
15897
+ * Add component based on the component type.
15898
+ * @param type - The type of the component
15899
+ * @param args - The arguments of the component
15900
+ * @returns The component which has been added
15901
+ */ _proto.addComponent = function addComponent(type) {
15902
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
15903
+ args[_key - 1] = arguments[_key];
15904
+ }
15905
+ ComponentsDependencies._addCheck(this, type);
15906
+ var component = _construct$1(type, [].concat(this, args));
15907
+ this._components.push(component);
15908
+ component._setActive(true, ActiveChangeFlag.All);
15909
+ return component;
15910
+ };
15911
+ /**
15912
+ * Get component which match the type.
15913
+ * @param type - The type of the component
15914
+ * @returns The first component which match type
15915
+ */ _proto.getComponent = function getComponent(type) {
15916
+ var components = this._components;
15917
+ for(var i = 0, n = components.length; i < n; i++){
15918
+ var component = components[i];
15919
+ if (_instanceof1$2(component, type)) {
15920
+ return component;
15827
15921
  }
15828
15922
  }
15923
+ return null;
15829
15924
  };
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;
15925
+ /**
15926
+ * Get components which match the type.
15927
+ * @param type - The type of the component
15928
+ * @param results - The components which match type
15929
+ * @returns The components which match type
15930
+ */ _proto.getComponents = function getComponents(type, results) {
15931
+ results.length = 0;
15932
+ var components = this._components;
15933
+ for(var i = 0, n = components.length; i < n; i++){
15934
+ var component = components[i];
15935
+ if (_instanceof1$2(component, type)) {
15936
+ results.push(component);
15937
+ }
15837
15938
  }
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
- }
15939
+ return results;
15940
+ };
15941
+ /**
15942
+ * Get the components which match the type of the entity and it's children.
15943
+ * @param type - The component type
15944
+ * @param results - The components collection
15945
+ * @returns The components collection which match the type
15946
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
15947
+ results.length = 0;
15948
+ this._getComponentsInChildren(type, results);
15949
+ return results;
15950
+ };
15951
+ _proto.addChild = function addChild(indexOrChild, child) {
15952
+ var index;
15953
+ if (typeof indexOrChild === "number") {
15954
+ index = indexOrChild;
15955
+ } else {
15956
+ index = undefined;
15957
+ child = indexOrChild;
15958
+ }
15959
+ if (child._isRoot) {
15960
+ child._scene._removeFromEntityList(child);
15961
+ child._isRoot = false;
15962
+ this._addToChildrenList(index, child);
15963
+ child._parent = this;
15964
+ var oldScene = child._scene;
15965
+ var newScene = this._scene;
15966
+ var inActiveChangeFlag = ActiveChangeFlag.None;
15967
+ if (!this._isActiveInHierarchy) {
15968
+ child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
15969
+ }
15970
+ if (child._isActiveInScene) {
15971
+ if (this._isActiveInScene) {
15972
+ // Cross scene should inActive first and then active
15973
+ oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
15869
15974
  } 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);
15975
+ inActiveChangeFlag |= ActiveChangeFlag.Scene;
15875
15976
  }
15876
- jointDataCreateCache.set(jointCount, bsUniformOccupiesCount);
15877
15977
  }
15878
- if (this._jointTexture) {
15879
- this._jointTexture.setPixelBuffer(this._jointMatrices);
15978
+ inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
15979
+ if (child._scene !== newScene) {
15980
+ Entity._traverseSetOwnerScene(child, newScene);
15981
+ }
15982
+ var activeChangeFlag = ActiveChangeFlag.None;
15983
+ if (child._isActive) {
15984
+ if (this._isActiveInHierarchy) {
15985
+ !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15986
+ }
15987
+ if (this._isActiveInScene) {
15988
+ (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
15989
+ }
15880
15990
  }
15991
+ activeChangeFlag && child._processActive(activeChangeFlag);
15992
+ child._setTransformDirty();
15993
+ } else {
15994
+ child._setParent(this, index);
15881
15995
  }
15882
- var layer = entity.layer;
15883
- this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
15884
15996
  };
15885
15997
  /**
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;
15998
+ * Remove child entity.
15999
+ * @param child - The child entity which want to be removed
16000
+ */ _proto.removeChild = function removeChild(child) {
16001
+ child._setParent(null);
15899
16002
  };
15900
16003
  /**
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;
16004
+ * @deprecated Please use `children` property instead.
16005
+ * Find child entity by index.
16006
+ * @param index - The index of the child entity
16007
+ * @returns The component which be found
16008
+ */ _proto.getChild = function getChild(index) {
16009
+ return this._children[index];
16010
+ };
16011
+ /**
16012
+ * Find entity by name.
16013
+ * @param name - The name of the entity which want to be found
16014
+ * @returns The component which be found
16015
+ */ _proto.findByName = function findByName(name1) {
16016
+ if (name1 === this.name) {
16017
+ return this;
15909
16018
  }
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;
16019
+ var children = this._children;
16020
+ for(var i = 0, n = children.length; i < n; i++){
16021
+ var target = children[i].findByName(name1);
16022
+ if (target) {
16023
+ return target;
15919
16024
  }
15920
- target.bones = destBones;
15921
16025
  }
15922
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
16026
+ return null;
15923
16027
  };
15924
16028
  /**
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);
16029
+ * Find the entity by path.
16030
+ * @param path - The path fo the entity eg: /entity
16031
+ * @returns The component which be found
16032
+ */ _proto.findByPath = function findByPath(path) {
16033
+ var splits = path.split("/");
16034
+ var entity = this;
16035
+ for(var i = 0, length = splits.length; i < length; ++i){
16036
+ var split = splits[i];
16037
+ if (split) {
16038
+ entity = Entity._findChildByName(entity, split);
16039
+ if (!entity) {
16040
+ return null;
16041
+ }
16042
+ }
16043
+ }
16044
+ return entity;
15929
16045
  };
15930
16046
  /**
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);
16047
+ * Create child entity.
16048
+ * @param name - The child entity's name
16049
+ * @returns The child entity
16050
+ */ _proto.createChild = function createChild(name1) {
16051
+ var child = new Entity(this.engine, name1);
16052
+ child.layer = this.layer;
16053
+ child.parent = this;
16054
+ return child;
16055
+ };
16056
+ /**
16057
+ * Clear children entities.
16058
+ */ _proto.clearChildren = function clearChildren() {
16059
+ var children = this._children;
16060
+ for(var i = children.length - 1; i >= 0; i--){
16061
+ var child = children[i];
16062
+ child._parent = null;
16063
+ var activeChangeFlag = ActiveChangeFlag.None;
16064
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16065
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
16066
+ activeChangeFlag && child._processInActive(activeChangeFlag);
16067
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
16068
+ }
16069
+ children.length = 0;
16070
+ };
16071
+ /**
16072
+ * Clone this entity include children and components.
16073
+ * @returns Cloned entity
16074
+ */ _proto.clone = function clone() {
16075
+ var cloneEntity = this._createCloneEntity();
16076
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
16077
+ return cloneEntity;
15935
16078
  };
15936
16079
  /**
15937
16080
  * @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);
16081
+ */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
16082
+ this._isTemplate = true;
16083
+ this._templateResource = templateResource;
16084
+ };
16085
+ _proto._createCloneEntity = function _createCloneEntity() {
16086
+ var cloneEntity = new Entity(this._engine, this.name);
16087
+ var templateResource = this._templateResource;
16088
+ if (templateResource) {
16089
+ cloneEntity._templateResource = templateResource;
16090
+ templateResource._addReferCount(1);
16091
+ }
16092
+ cloneEntity.layer = this.layer;
16093
+ cloneEntity._isActive = this._isActive;
16094
+ var cloneTransform = cloneEntity.transform;
16095
+ var _this = this, srcTransform = _this.transform;
16096
+ cloneTransform.position = srcTransform.position;
16097
+ cloneTransform.rotation = srcTransform.rotation;
16098
+ cloneTransform.scale = srcTransform.scale;
16099
+ var srcChildren = this._children;
16100
+ for(var i = 0, n = srcChildren.length; i < n; i++){
16101
+ cloneEntity.addChild(srcChildren[i]._createCloneEntity());
15945
16102
  }
16103
+ return cloneEntity;
15946
16104
  };
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;
16105
+ _proto._parseCloneEntity = function _parseCloneEntity(src, target, srcRoot, targetRoot, deepInstanceMap) {
16106
+ var srcChildren = src._children;
16107
+ var targetChildren = target._children;
16108
+ for(var i = 0, n = srcChildren.length; i < n; i++){
16109
+ this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot, deepInstanceMap);
16110
+ }
16111
+ var components = src._components;
16112
+ for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
16113
+ var sourceComp = components[i1];
16114
+ if (!_instanceof1$2(sourceComp, Transform)) {
16115
+ var targetComp = target.addComponent(sourceComp.constructor);
16116
+ ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot, deepInstanceMap);
15963
16117
  }
16118
+ }
16119
+ };
16120
+ /**
16121
+ * Destroy self.
16122
+ */ _proto.destroy = function destroy() {
16123
+ if (this._destroyed) {
16124
+ return;
16125
+ }
16126
+ EngineObject1.prototype.destroy.call(this);
16127
+ if (this._templateResource) {
16128
+ this._isTemplate || this._templateResource._addReferCount(-1);
16129
+ this._templateResource = null;
16130
+ }
16131
+ var components = this._components;
16132
+ for(var i = components.length - 1; i >= 0; i--){
16133
+ components[i].destroy();
16134
+ }
16135
+ this._components.length = 0;
16136
+ var children = this._children;
16137
+ while(children.length > 0){
16138
+ children[0].destroy();
16139
+ }
16140
+ if (this._isRoot) {
16141
+ this._scene.removeRootEntity(this);
15964
16142
  } else {
15965
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16143
+ this._setParent(null);
15966
16144
  }
16145
+ this.isActive = false;
15967
16146
  };
15968
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
15969
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16147
+ /**
16148
+ * @internal
16149
+ */ _proto._removeComponent = function _removeComponent(component) {
16150
+ ComponentsDependencies._removeCheck(this, component.constructor);
16151
+ var components = this._components;
16152
+ components.splice(components.indexOf(component), 1);
15970
16153
  };
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;
16154
+ /**
16155
+ * @internal
16156
+ */ _proto._addScript = function _addScript(script) {
16157
+ script._entityScriptsIndex = this._scripts.length;
16158
+ this._scripts.add(script);
16159
+ };
16160
+ /**
16161
+ * @internal
16162
+ */ _proto._removeScript = function _removeScript(script) {
16163
+ var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
16164
+ replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
16165
+ script._entityScriptsIndex = -1;
16166
+ };
16167
+ /**
16168
+ * @internal
16169
+ */ _proto._removeFromParent = function _removeFromParent() {
16170
+ var oldParent = this._parent;
16171
+ if (oldParent != null) {
16172
+ var oldSibling = oldParent._children;
16173
+ var index = this._siblingIndex;
16174
+ oldSibling.splice(index, 1);
16175
+ for(var n = oldSibling.length; index < n; index++){
16176
+ oldSibling[index]._siblingIndex--;
15977
16177
  }
15978
- inversePath.push(searchEntity.siblingIndex);
15979
- searchEntity = parent;
16178
+ this._parent = null;
16179
+ this._siblingIndex = -1;
15980
16180
  }
15981
- return true;
15982
16181
  };
15983
16182
  /**
15984
16183
  * @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]];
16184
+ */ _proto._processActive = function _processActive(activeChangeFlag) {
16185
+ if (this._activeChangedComponents) {
16186
+ 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
16187
  }
15990
- return entity;
16188
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16189
+ this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16190
+ this._setActiveComponents(true, activeChangeFlag);
15991
16191
  };
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
- }
16012
- }
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
- }
16025
- }
16026
- },
16027
- {
16028
- key: "rootBone",
16192
+ /**
16193
+ * @internal
16194
+ */ _proto._processInActive = function _processInActive(activeChangeFlag) {
16195
+ if (this._activeChangedComponents) {
16196
+ 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.";
16197
+ }
16198
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16199
+ this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16200
+ this._setActiveComponents(false, activeChangeFlag);
16201
+ };
16202
+ _proto._addToChildrenList = function _addToChildrenList(index, child) {
16203
+ var children = this._children;
16204
+ var childCount = children.length;
16205
+ if (index === undefined) {
16206
+ child._siblingIndex = childCount;
16207
+ children.push(child);
16208
+ } else {
16209
+ if (index < 0 || index > childCount) {
16210
+ throw "The index " + index + " is out of child list bounds " + childCount;
16211
+ }
16212
+ child._siblingIndex = index;
16213
+ children.splice(index, 0, child);
16214
+ for(var i = index + 1, n = childCount + 1; i < n; i++){
16215
+ children[i]._siblingIndex++;
16216
+ }
16217
+ }
16218
+ };
16219
+ _proto._setParent = function _setParent(parent, siblingIndex) {
16220
+ var oldParent = this._parent;
16221
+ if (parent !== oldParent) {
16222
+ this._removeFromParent();
16223
+ this._parent = parent;
16224
+ if (parent) {
16225
+ parent._addToChildrenList(siblingIndex, this);
16226
+ var oldScene = this._scene;
16227
+ var parentScene = parent._scene;
16228
+ var inActiveChangeFlag = ActiveChangeFlag.None;
16229
+ if (!parent._isActiveInHierarchy) {
16230
+ this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
16231
+ }
16232
+ if (parent._isActiveInScene) {
16233
+ // cross scene should inActive first and then active
16234
+ this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16235
+ } else {
16236
+ this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16237
+ }
16238
+ inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
16239
+ if (oldScene !== parentScene) {
16240
+ Entity._traverseSetOwnerScene(this, parentScene);
16241
+ }
16242
+ var activeChangeFlag = ActiveChangeFlag.None;
16243
+ if (this._isActive) {
16244
+ if (parent._isActiveInHierarchy) {
16245
+ !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16246
+ }
16247
+ if (parent._isActiveInScene) {
16248
+ (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16249
+ }
16250
+ }
16251
+ activeChangeFlag && this._processActive(activeChangeFlag);
16252
+ } else {
16253
+ var inActiveChangeFlag1 = ActiveChangeFlag.None;
16254
+ this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16255
+ this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
16256
+ inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
16257
+ if (oldParent) {
16258
+ Entity._traverseSetOwnerScene(this, null);
16259
+ }
16260
+ }
16261
+ this._setTransformDirty();
16262
+ }
16263
+ };
16264
+ _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
16265
+ for(var i = this._components.length - 1; i >= 0; i--){
16266
+ var component = this._components[i];
16267
+ if (_instanceof1$2(component, type)) {
16268
+ results.push(component);
16269
+ }
16270
+ }
16271
+ for(var i1 = this._children.length - 1; i1 >= 0; i1--){
16272
+ this._children[i1]._getComponentsInChildren(type, results);
16273
+ }
16274
+ };
16275
+ _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
16276
+ var activeChangedComponents = this._activeChangedComponents;
16277
+ for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
16278
+ activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
16279
+ }
16280
+ this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
16281
+ this._activeChangedComponents = null;
16282
+ };
16283
+ _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16284
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
16285
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
16286
+ var components = this._components;
16287
+ for(var i = 0, n = components.length; i < n; i++){
16288
+ var component = components[i];
16289
+ (component.enabled || !component._awoken) && activeChangedComponents.push(component);
16290
+ }
16291
+ var children = this._children;
16292
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16293
+ var child = children[i1];
16294
+ child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16295
+ }
16296
+ };
16297
+ _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16298
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
16299
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
16300
+ var components = this._components;
16301
+ for(var i = 0, n = components.length; i < n; i++){
16302
+ var component = components[i];
16303
+ component.enabled && activeChangedComponents.push(component);
16304
+ }
16305
+ var children = this._children;
16306
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16307
+ var child = children[i1];
16308
+ child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16309
+ }
16310
+ };
16311
+ _proto._setTransformDirty = function _setTransformDirty() {
16312
+ if (this.transform) {
16313
+ this.transform._parentChange();
16314
+ } else {
16315
+ for(var i = 0, len = this._children.length; i < len; i++){
16316
+ this._children[i]._setTransformDirty();
16317
+ }
16318
+ }
16319
+ };
16320
+ _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
16321
+ target = Math.min(target, sibling.length - 1);
16322
+ if (target < 0) {
16323
+ throw "Sibling index " + target + " should large than 0";
16324
+ }
16325
+ if (this._siblingIndex !== target) {
16326
+ var oldIndex = this._siblingIndex;
16327
+ if (target < oldIndex) {
16328
+ for(var i = oldIndex; i >= target; i--){
16329
+ var child = i == target ? this : sibling[i - 1];
16330
+ sibling[i] = child;
16331
+ child._siblingIndex = i;
16332
+ }
16333
+ } else {
16334
+ for(var i1 = oldIndex; i1 <= target; i1++){
16335
+ var child1 = i1 == target ? this : sibling[i1 + 1];
16336
+ sibling[i1] = child1;
16337
+ child1._siblingIndex = i1;
16338
+ }
16339
+ }
16340
+ }
16341
+ };
16342
+ /**
16343
+ * @deprecated
16344
+ */ _proto.getInvModelMatrix = function getInvModelMatrix() {
16345
+ if (this._inverseWorldMatFlag.flag) {
16346
+ Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
16347
+ this._inverseWorldMatFlag.flag = false;
16348
+ }
16349
+ return this._invModelMatrix;
16350
+ };
16351
+ /**
16352
+ * @internal
16353
+ */ Entity._findChildByName = function _findChildByName(root, name1) {
16354
+ var children = root._children;
16355
+ for(var i = children.length - 1; i >= 0; i--){
16356
+ var child = children[i];
16357
+ if (child.name === name1) {
16358
+ return child;
16359
+ }
16360
+ }
16361
+ return null;
16362
+ };
16363
+ /**
16364
+ * @internal
16365
+ */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
16366
+ entity._scene = scene;
16367
+ var children = entity._children;
16368
+ for(var i = children.length - 1; i >= 0; i--){
16369
+ this._traverseSetOwnerScene(children[i], scene);
16370
+ }
16371
+ };
16372
+ /**
16373
+ * @internal
16374
+ */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
16375
+ inversePath.length = 0;
16376
+ while(searchEntity !== rootEntity){
16377
+ var parent = searchEntity.parent;
16378
+ if (!parent) {
16379
+ return false;
16380
+ }
16381
+ inversePath.push(searchEntity.siblingIndex);
16382
+ searchEntity = parent;
16383
+ }
16384
+ return true;
16385
+ };
16386
+ /**
16387
+ * @internal
16388
+ */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
16389
+ var entity = rootEntity;
16390
+ for(var i = inversePath.length - 1; i >= 0; i--){
16391
+ entity = entity.children[inversePath[i]];
16392
+ }
16393
+ return entity;
16394
+ };
16395
+ _create_class$2(Entity, [
16396
+ {
16397
+ key: "isActive",
16398
+ get: /**
16399
+ * Whether to activate locally.
16400
+ */ function get() {
16401
+ return this._isActive;
16402
+ },
16403
+ set: function set(value) {
16404
+ if (value !== this._isActive) {
16405
+ this._isActive = value;
16406
+ if (value) {
16407
+ var parent = this._parent;
16408
+ var activeChangeFlag = ActiveChangeFlag.None;
16409
+ if (this._isRoot && this._scene._isActiveInEngine) {
16410
+ activeChangeFlag |= ActiveChangeFlag.All;
16411
+ } else {
16412
+ var _parent, _parent1;
16413
+ ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16414
+ ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16415
+ }
16416
+ activeChangeFlag && this._processActive(activeChangeFlag);
16417
+ } else {
16418
+ var activeChangeFlag1 = ActiveChangeFlag.None;
16419
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16420
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
16421
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
16422
+ }
16423
+ }
16424
+ }
16425
+ },
16426
+ {
16427
+ key: "isActiveInHierarchy",
16428
+ get: /**
16429
+ * Whether it is active in the hierarchy.
16430
+ */ function get() {
16431
+ return this._isActiveInHierarchy;
16432
+ }
16433
+ },
16434
+ {
16435
+ key: "parent",
16436
+ get: /**
16437
+ * The parent entity.
16438
+ */ function get() {
16439
+ return this._parent;
16440
+ },
16441
+ set: function set(value) {
16442
+ this._setParent(value);
16443
+ }
16444
+ },
16445
+ {
16446
+ key: "children",
16447
+ get: /**
16448
+ * The children entities
16449
+ */ function get() {
16450
+ return this._children;
16451
+ }
16452
+ },
16453
+ {
16454
+ key: "childCount",
16455
+ get: /**
16456
+ * @deprecated Please use `children.length` property instead.
16457
+ * Number of the children entities
16458
+ */ function get() {
16459
+ return this._children.length;
16460
+ }
16461
+ },
16462
+ {
16463
+ key: "scene",
16464
+ get: /**
16465
+ * The scene the entity belongs to.
16466
+ */ function get() {
16467
+ return this._scene;
16468
+ }
16469
+ },
16470
+ {
16471
+ key: "siblingIndex",
16472
+ get: /**
16473
+ * The sibling index.
16474
+ */ function get() {
16475
+ return this._siblingIndex;
16476
+ },
16477
+ set: function set(value) {
16478
+ if (this._siblingIndex === -1) {
16479
+ throw "The entity " + this.name + " is not in the hierarchy";
16480
+ }
16481
+ this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
16482
+ }
16483
+ }
16484
+ ]);
16485
+ return Entity;
16486
+ }(EngineObject);
16487
+ /**
16488
+ * Skin used for skinned mesh renderer.
16489
+ */ var Skin = /*#__PURE__*/ function(EngineObject1) {
16490
+ var Skin = function Skin(name1) {
16491
+ var _this;
16492
+ _this = EngineObject1.call(this, null) || this;
16493
+ _this.name = name1;
16494
+ _this.inverseBindMatrices = new Array();
16495
+ _this._updatedManager = new UpdateFlagManager();
16496
+ _this._bones = new Array();
16497
+ _this._updateMark = -1;
16498
+ _this.joints = [];
16499
+ return _this;
16500
+ };
16501
+ _inherits$2(Skin, EngineObject1);
16502
+ var _proto = Skin.prototype;
16503
+ /**
16504
+ * @internal
16505
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
16506
+ if (this._updateMark === renderer.engine.time.frameCount) {
16507
+ return;
16508
+ }
16509
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
16510
+ var _this_rootBone;
16511
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
16512
+ for(var i = bones.length - 1; i >= 0; i--){
16513
+ var bone = bones[i];
16514
+ var offset = i * 16;
16515
+ if (bone) {
16516
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
16517
+ } else {
16518
+ skinMatrices.set(bindMatrices[i].elements, offset);
16519
+ }
16520
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
16521
+ }
16522
+ this._updateMark = renderer.engine.time.frameCount;
16523
+ };
16524
+ /**
16525
+ * @internal
16526
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16527
+ var paths = new Array();
16528
+ // Clone rootBone
16529
+ var rootBone = this.rootBone;
16530
+ if (rootBone) {
16531
+ var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
16532
+ target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
16533
+ }
16534
+ // Clone bones
16535
+ var bones = this.bones;
16536
+ if (bones.length > 0) {
16537
+ var boneCount = bones.length;
16538
+ var destBones = new Array(boneCount);
16539
+ for(var i = 0; i < boneCount; i++){
16540
+ var bone = bones[i];
16541
+ var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
16542
+ destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
16543
+ }
16544
+ target.bones = destBones;
16545
+ }
16546
+ };
16547
+ _create_class$2(Skin, [
16548
+ {
16549
+ key: "rootBone",
16029
16550
  get: /**
16030
16551
  * Root bone.
16031
16552
  */ function get() {
@@ -16033,182 +16554,447 @@
16033
16554
  },
16034
16555
  set: function set(value) {
16035
16556
  if (this._rootBone !== value) {
16036
- this._unRegisterEntityTransformListener();
16557
+ this._updatedManager.dispatch(1, value);
16037
16558
  this._rootBone = value;
16038
- this._registerEntityTransformListener();
16039
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16040
16559
  }
16041
16560
  }
16042
16561
  },
16043
16562
  {
16044
16563
  key: "bones",
16045
16564
  get: /**
16046
- * Bones of the SkinnedMeshRenderer.
16565
+ * Bones of the skin.
16047
16566
  */ function get() {
16048
16567
  return this._bones;
16049
16568
  },
16050
16569
  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;
16570
+ var _value;
16571
+ var bones = this._bones;
16572
+ var _value_length;
16573
+ var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
16574
+ var lastBoneCount = bones.length;
16575
+ bones.length = boneCount;
16576
+ for(var i = 0; i < boneCount; i++){
16577
+ bones[i] = value[i];
16578
+ }
16579
+ if (lastBoneCount !== boneCount) {
16580
+ this._skinMatrices = new Float32Array(boneCount * 16);
16581
+ this._updatedManager.dispatch(0, boneCount);
16069
16582
  }
16070
16583
  }
16071
16584
  },
16072
16585
  {
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;
16586
+ key: "skeleton",
16587
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
16588
+ var _this_rootBone;
16589
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
16085
16590
  },
16086
16591
  set: function set(value) {
16087
- this._skin = value;
16592
+ var rootBone = this._rootBone;
16593
+ if (rootBone) {
16594
+ rootBone.name = value;
16595
+ }
16088
16596
  }
16089
16597
  }
16090
16598
  ]);
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
- })();
16599
+ return Skin;
16600
+ }(EngineObject);
16102
16601
  __decorate$1([
16103
16602
  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);
16603
+ ], Skin.prototype, "inverseBindMatrices", void 0);
16111
16604
  __decorate$1([
16112
16605
  ignoreClone
16113
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16114
- __decorate$1([
16115
- ignoreClone
16116
- ], SkinnedMeshRenderer.prototype, "_rootBone", void 0);
16117
- __decorate$1([
16118
- ignoreClone
16119
- ], SkinnedMeshRenderer.prototype, "_jointMatrices", void 0);
16606
+ ], Skin.prototype, "_skinMatrices", void 0);
16120
16607
  __decorate$1([
16121
16608
  ignoreClone
16122
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16609
+ ], Skin.prototype, "_updatedManager", void 0);
16123
16610
  __decorate$1([
16124
16611
  ignoreClone
16125
- ], SkinnedMeshRenderer.prototype, "_bones", void 0);
16612
+ ], Skin.prototype, "_rootBone", void 0);
16126
16613
  __decorate$1([
16127
16614
  ignoreClone
16128
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16615
+ ], Skin.prototype, "_bones", void 0);
16129
16616
  __decorate$1([
16130
16617
  ignoreClone
16131
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16618
+ ], Skin.prototype, "_updateMark", void 0);
16619
+ var SkinUpdateFlag;
16620
+ (function(SkinUpdateFlag) {
16621
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
16622
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
16623
+ })(SkinUpdateFlag || (SkinUpdateFlag = {}));
16132
16624
  /**
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;
16625
+ * SkinnedMeshRenderer.
16626
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
16627
+ var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
16628
+ var _this;
16629
+ _this = MeshRenderer1.call(this, entity) || this;
16630
+ _this._localBounds = new BoundingBox();
16631
+ _this._jointDataCreateCache = new Vector2(-1, -1);
16632
+ _this._skin = null;
16633
+ var rhi = _this.entity.engine._hardwareRenderer;
16634
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
16635
+ // Limit size to 256 to avoid some problem:
16636
+ // 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!
16637
+ // 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.
16638
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
16639
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
16640
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
16641
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_assert_this_initialized(_this));
16642
+ var localBounds = _this._localBounds;
16643
+ // @ts-ignore
16644
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
16645
+ // @ts-ignore
16646
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
16647
+ return _this;
16139
16648
  };
16140
- var _proto = ClassPool.prototype;
16649
+ _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
16650
+ var _proto = SkinnedMeshRenderer.prototype;
16141
16651
  /**
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];
16652
+ * @internal
16653
+ */ _proto.update = function update() {
16654
+ var _skin;
16655
+ var skin = this._skin;
16656
+ if (((_skin = skin) == null ? void 0 : _skin.bones.length) > 0) {
16657
+ skin._updateSkinMatrices(this);
16152
16658
  }
16153
16659
  };
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();
16660
+ _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
16661
+ var _skin, _skin1;
16662
+ var _this = this, entity = _this.entity, skin = _this.skin;
16663
+ var _skin_rootBone;
16664
+ var worldMatrix = ((_skin_rootBone = (_skin = skin) == null ? void 0 : _skin.rootBone) != null ? _skin_rootBone : entity).transform.worldMatrix;
16665
+ if (onlyMVP) {
16666
+ this._updateMVPShaderData(context, worldMatrix);
16667
+ return;
16163
16668
  }
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);
16669
+ this._updateTransformShaderData(context, worldMatrix);
16670
+ var shaderData = this.shaderData;
16671
+ var mesh = this.mesh;
16672
+ var blendShapeManager = mesh._blendShapeManager;
16673
+ blendShapeManager._updateShaderData(shaderData, this);
16674
+ var bones = (_skin1 = skin) == null ? void 0 : _skin1.bones;
16675
+ if (bones) {
16676
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
16677
+ var boneCount = bones.length;
16678
+ var boneDataCreateCache = this._jointDataCreateCache;
16679
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
16680
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
16681
+ // directly use max joint count to avoid shader recompile
16682
+ // @TODO: different shader type should use different count, not always 44
16683
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
16684
+ if (boneCount > remainUniformJointCount) {
16685
+ var engine = this.engine;
16686
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
16687
+ if (boneCountChange) {
16688
+ var _this__jointTexture;
16689
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16690
+ this._jointTexture = new Texture2D(engine, 4, boneCount, exports.TextureFormat.R32G32B32A32, false);
16691
+ this._jointTexture.filterMode = exports.TextureFilterMode.Point;
16692
+ this._jointTexture.isGCIgnored = true;
16693
+ }
16694
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
16695
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
16696
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
16697
+ } else {
16698
+ 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);
16699
+ }
16700
+ } else {
16701
+ var _this__jointTexture1;
16702
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
16703
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
16704
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
16705
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
16706
+ }
16707
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
16708
+ }
16709
+ if (this._jointTexture) {
16710
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
16191
16711
  }
16192
- } else {
16193
- this._drawSubElement(element, camera);
16194
16712
  }
16713
+ var layer = entity.layer;
16714
+ this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
16195
16715
  };
16196
16716
  /**
16197
16717
  * @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
- }
16718
+ */ _proto._onDestroy = function _onDestroy() {
16719
+ var _this__jointTexture;
16720
+ MeshRenderer1.prototype._onDestroy.call(this);
16721
+ this._jointDataCreateCache = null;
16722
+ this._skin = null;
16723
+ this._blendShapeWeights = null;
16724
+ this._localBounds = null;
16725
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16726
+ this._jointTexture = null;
16207
16727
  };
16208
- _proto.flush = function flush(camera) {
16209
- var batchedQueue = this._batchedQueue;
16210
- if (batchedQueue.length === 0) {
16211
- return;
16728
+ /**
16729
+ * @internal
16730
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16731
+ MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
16732
+ if (this.skin) {
16733
+ target._applySkin(null, target.skin);
16734
+ }
16735
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
16736
+ };
16737
+ /**
16738
+ * @internal
16739
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
16740
+ var _this_skin;
16741
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
16742
+ if (rootBone) {
16743
+ BoundingBox.transform(this._localBounds, rootBone.transform.worldMatrix, worldBounds);
16744
+ } else {
16745
+ MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
16746
+ }
16747
+ };
16748
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
16749
+ var mesh = this._mesh;
16750
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
16751
+ var lastBlendShapeWeights = this._blendShapeWeights;
16752
+ if (lastBlendShapeWeights) {
16753
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
16754
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
16755
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
16756
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
16757
+ newBlendShapeWeights.set(lastBlendShapeWeights);
16758
+ } else {
16759
+ for(var i = 0; i < newBlendShapeCount; i++){
16760
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
16761
+ }
16762
+ }
16763
+ this._blendShapeWeights = newBlendShapeWeights;
16764
+ }
16765
+ } else {
16766
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16767
+ }
16768
+ };
16769
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
16770
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16771
+ };
16772
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
16773
+ switch(type){
16774
+ case SkinUpdateFlag.BoneCountChanged:
16775
+ var shaderData = this.shaderData;
16776
+ if (value > 0) {
16777
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
16778
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
16779
+ } else {
16780
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
16781
+ }
16782
+ break;
16783
+ case SkinUpdateFlag.RootBoneChanged:
16784
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16785
+ break;
16786
+ }
16787
+ };
16788
+ _proto._applySkin = function _applySkin(lastSkin, value) {
16789
+ var _lastSkin_bones, _lastSkin, _lastSkin1, _lastSkin2, _value_bones, _value, _value1, _value2;
16790
+ var _lastSkin_bones_length;
16791
+ 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;
16792
+ var _lastSkin_rootBone;
16793
+ var lastRootBone = (_lastSkin_rootBone = (_lastSkin1 = lastSkin) == null ? void 0 : _lastSkin1.rootBone) != null ? _lastSkin_rootBone : this.entity;
16794
+ (_lastSkin2 = lastSkin) == null ? void 0 : _lastSkin2._updatedManager.removeListener(this._onSkinUpdated);
16795
+ var _value_bones_length;
16796
+ 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;
16797
+ var _value_rootBone;
16798
+ var rootBone = (_value_rootBone = (_value1 = value) == null ? void 0 : _value1.rootBone) != null ? _value_rootBone : this.entity;
16799
+ (_value2 = value) == null ? void 0 : _value2._updatedManager.addListener(this._onSkinUpdated);
16800
+ if (lastSkinBoneCount !== skinBoneCount) {
16801
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
16802
+ }
16803
+ if (lastRootBone !== rootBone) {
16804
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
16805
+ }
16806
+ };
16807
+ _create_class$2(SkinnedMeshRenderer, [
16808
+ {
16809
+ key: "skin",
16810
+ get: /**
16811
+ * Skin of the SkinnedMeshRenderer.
16812
+ */ function get() {
16813
+ return this._skin;
16814
+ },
16815
+ set: function set(value) {
16816
+ var lastSkin = this._skin;
16817
+ if (lastSkin !== value) {
16818
+ this._applySkin(lastSkin, value);
16819
+ this._skin = value;
16820
+ }
16821
+ }
16822
+ },
16823
+ {
16824
+ key: "blendShapeWeights",
16825
+ get: /**
16826
+ * The weights of the BlendShapes.
16827
+ * @remarks Array index is BlendShape index.
16828
+ */ function get() {
16829
+ this._checkBlendShapeWeightLength();
16830
+ return this._blendShapeWeights;
16831
+ },
16832
+ set: function set(value) {
16833
+ this._checkBlendShapeWeightLength();
16834
+ var blendShapeWeights = this._blendShapeWeights;
16835
+ if (value.length <= blendShapeWeights.length) {
16836
+ blendShapeWeights.set(value);
16837
+ } else {
16838
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
16839
+ blendShapeWeights[i] = value[i];
16840
+ }
16841
+ }
16842
+ }
16843
+ },
16844
+ {
16845
+ key: "localBounds",
16846
+ get: /**
16847
+ * Local bounds.
16848
+ */ function get() {
16849
+ return this._localBounds;
16850
+ },
16851
+ set: function set(value) {
16852
+ if (this._localBounds !== value) {
16853
+ this._localBounds.copyFrom(value);
16854
+ }
16855
+ }
16856
+ },
16857
+ {
16858
+ key: "rootBone",
16859
+ get: /**
16860
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
16861
+ */ function get() {
16862
+ return this.skin.rootBone;
16863
+ },
16864
+ set: function set(value) {
16865
+ this.skin.rootBone = value;
16866
+ }
16867
+ },
16868
+ {
16869
+ key: "bones",
16870
+ get: /**
16871
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
16872
+ */ function get() {
16873
+ return this.skin.bones;
16874
+ },
16875
+ set: function set(value) {
16876
+ this.skin.bones = value;
16877
+ }
16878
+ }
16879
+ ]);
16880
+ return SkinnedMeshRenderer;
16881
+ }(MeshRenderer);
16882
+ (function() {
16883
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
16884
+ })();
16885
+ (function() {
16886
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
16887
+ })();
16888
+ (function() {
16889
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
16890
+ })();
16891
+ __decorate$1([
16892
+ ignoreClone
16893
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16894
+ __decorate$1([
16895
+ deepClone
16896
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
16897
+ __decorate$1([
16898
+ ignoreClone
16899
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
16900
+ __decorate$1([
16901
+ ignoreClone
16902
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
16903
+ __decorate$1([
16904
+ ignoreClone
16905
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16906
+ __decorate$1([
16907
+ ignoreClone
16908
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16909
+ __decorate$1([
16910
+ deepClone
16911
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
16912
+ __decorate$1([
16913
+ ignoreClone
16914
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16915
+ __decorate$1([
16916
+ ignoreClone
16917
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
16918
+ /**
16919
+ * Class pool utils.
16920
+ */ var ClassPool = /*#__PURE__*/ function() {
16921
+ var ClassPool = function ClassPool(type) {
16922
+ this._elementPoolIndex = 0;
16923
+ this._elementPool = [];
16924
+ this._type = type;
16925
+ };
16926
+ var _proto = ClassPool.prototype;
16927
+ /**
16928
+ * Get element from pool.
16929
+ */ _proto.getFromPool = function getFromPool() {
16930
+ var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
16931
+ this._elementPoolIndex++;
16932
+ if (pool.length === index) {
16933
+ var element = new this._type();
16934
+ pool.push(element);
16935
+ return element;
16936
+ } else {
16937
+ return pool[index];
16938
+ }
16939
+ };
16940
+ /**
16941
+ * Reset pool.
16942
+ */ _proto.resetPool = function resetPool() {
16943
+ this._elementPoolIndex = 0;
16944
+ };
16945
+ _proto.garbageCollection = function garbageCollection() {
16946
+ var _this = this, pool = _this._elementPool;
16947
+ for(var i = pool.length - 1; i >= 0; i--){
16948
+ pool[i].dispose && pool[i].dispose();
16949
+ }
16950
+ };
16951
+ return ClassPool;
16952
+ }();
16953
+ var Basic2DBatcher = /*#__PURE__*/ function() {
16954
+ var Basic2DBatcher = function Basic2DBatcher(engine) {
16955
+ /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
16956
+ /** @internal */ this._batchedQueue = [];
16957
+ /** @internal */ this._meshes = [];
16958
+ /** @internal */ this._meshCount = 1;
16959
+ /** @internal */ this._vertexBuffers = [];
16960
+ /** @internal */ this._indiceBuffers = [];
16961
+ /** @internal */ this._flushId = 0;
16962
+ /** @internal */ this._vertexCount = 0;
16963
+ /** @internal */ this._elementCount = 0;
16964
+ this._engine = engine;
16965
+ this._initMeshes(engine);
16966
+ };
16967
+ var _proto = Basic2DBatcher.prototype;
16968
+ _proto.drawElement = function drawElement(element, camera) {
16969
+ var data = element.data;
16970
+ if (data.multiRenderData) {
16971
+ var charsData = data.charsData;
16972
+ var pool = camera.engine._renderElementPool;
16973
+ for(var i = 0, n = charsData.length; i < n; ++i){
16974
+ var charRenderElement = pool.getFromPool();
16975
+ charRenderElement.set(charsData[i], element.shaderPasses);
16976
+ this._drawSubElement(charRenderElement, camera);
16977
+ }
16978
+ } else {
16979
+ this._drawSubElement(element, camera);
16980
+ }
16981
+ };
16982
+ /**
16983
+ * @internal
16984
+ * Standalone for canvas 2d renderer plugin.
16985
+ */ _proto._initMeshes = function _initMeshes(engine) {
16986
+ var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
16987
+ this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
16988
+ this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
16989
+ var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
16990
+ for(var i = 0; i < _meshCount; i++){
16991
+ _meshes[i] = this._createMesh(engine, i);
16992
+ }
16993
+ };
16994
+ _proto.flush = function flush(camera) {
16995
+ var batchedQueue = this._batchedQueue;
16996
+ if (batchedQueue.length === 0) {
16997
+ return;
16212
16998
  }
16213
16999
  this._updateData(this._engine);
16214
17000
  this.drawBatches(camera);
@@ -18757,7 +19543,7 @@
18757
19543
  */ _proto.cloneTo = function cloneTo(target) {
18758
19544
  target.shader = this.shader;
18759
19545
  this.shaderData.cloneTo(target.shaderData);
18760
- CloneManager.deepCloneObject(this.renderStates, target.renderStates);
19546
+ CloneManager.deepCloneObject(this.renderStates, target.renderStates, new Map());
18761
19547
  };
18762
19548
  _proto._addReferCount = function _addReferCount(value) {
18763
19549
  if (this._destroyed) return;
@@ -19470,1087 +20256,516 @@
19470
20256
  }
19471
20257
  }
19472
20258
  },
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();
20407
- }
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;
20259
+ {
20260
+ key: "clearCoatRoughness",
20261
+ get: /**
20262
+ * The clearCoat layer roughness, default 0.
20263
+ */ function get() {
20264
+ return this.shaderData.getFloat(PBRBaseMaterial._clearCoatRoughnessProp);
20265
+ },
20266
+ set: function set(value) {
20267
+ this.shaderData.setFloat(PBRBaseMaterial._clearCoatRoughnessProp, value);
20268
+ }
20269
+ },
20270
+ {
20271
+ key: "clearCoatRoughnessTexture",
20272
+ get: /**
20273
+ * The clearCoat layer roughness texture.
20274
+ */ function get() {
20275
+ return this.shaderData.getTexture(PBRBaseMaterial._clearCoatRoughnessTextureProp);
20276
+ },
20277
+ set: function set(value) {
20278
+ this.shaderData.setTexture(PBRBaseMaterial._clearCoatRoughnessTextureProp, value);
20279
+ if (value) {
20280
+ this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
20281
+ } else {
20282
+ this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE");
20422
20283
  }
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;
20284
+ }
20285
+ },
20286
+ {
20287
+ key: "clearCoatNormalTexture",
20288
+ get: /**
20289
+ * The clearCoat normal map texture.
20290
+ */ function get() {
20291
+ return this.shaderData.getTexture(PBRBaseMaterial._clearCoatNormalTextureProp);
20292
+ },
20293
+ set: function set(value) {
20294
+ this.shaderData.setTexture(PBRBaseMaterial._clearCoatNormalTextureProp, value);
20295
+ if (value) {
20296
+ this.shaderData.enableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
20297
+ } else {
20298
+ this.shaderData.disableMacro("MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE");
20428
20299
  }
20429
20300
  }
20430
20301
  }
20431
- };
20302
+ ]);
20303
+ return PBRBaseMaterial;
20304
+ }(BaseMaterial);
20305
+ (function() {
20306
+ PBRBaseMaterial._occlusionTextureIntensityProp = ShaderProperty.getByName("material_OcclusionIntensity");
20307
+ })();
20308
+ (function() {
20309
+ PBRBaseMaterial._occlusionTextureCoordProp = ShaderProperty.getByName("material_OcclusionTextureCoord");
20310
+ })();
20311
+ (function() {
20312
+ PBRBaseMaterial._occlusionTextureProp = ShaderProperty.getByName("material_OcclusionTexture");
20313
+ })();
20314
+ (function() {
20315
+ PBRBaseMaterial._clearCoatProp = ShaderProperty.getByName("material_ClearCoat");
20316
+ })();
20317
+ (function() {
20318
+ PBRBaseMaterial._clearCoatTextureProp = ShaderProperty.getByName("material_ClearCoatTexture");
20319
+ })();
20320
+ (function() {
20321
+ PBRBaseMaterial._clearCoatRoughnessProp = ShaderProperty.getByName("material_ClearCoatRoughness");
20322
+ })();
20323
+ (function() {
20324
+ PBRBaseMaterial._clearCoatRoughnessTextureProp = ShaderProperty.getByName("material_ClearCoatRoughnessTexture");
20325
+ })();
20326
+ (function() {
20327
+ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material_ClearCoatNormalTexture");
20328
+ })();
20329
+ /**
20330
+ * PBR (Metallic-Roughness Workflow) Material.
20331
+ */ var PBRMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
20332
+ _inherits$2(PBRMaterial, PBRBaseMaterial1);
20333
+ function PBRMaterial(engine) {
20334
+ var _this;
20335
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr")) || this;
20336
+ _this._anisotropyRotation = 0;
20337
+ var shaderData = _this.shaderData;
20338
+ shaderData.setFloat(PBRMaterial._metallicProp, 1);
20339
+ shaderData.setFloat(PBRMaterial._roughnessProp, 1);
20340
+ shaderData.setFloat(PBRMaterial._iorProp, 1.5);
20341
+ shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0));
20342
+ return _this;
20343
+ }
20344
+ var _proto = PBRMaterial.prototype;
20432
20345
  /**
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;
20346
+ * @inheritdoc
20347
+ */ _proto.clone = function clone() {
20348
+ var dest = new PBRMaterial(this._engine);
20349
+ this.cloneTo(dest);
20350
+ return dest;
20440
20351
  };
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;
20352
+ _create_class$2(PBRMaterial, [
20353
+ {
20354
+ key: "ior",
20355
+ get: /**
20356
+ * Index Of Refraction.
20357
+ * @defaultValue `1.5`
20358
+ */ function get() {
20359
+ return this.shaderData.getFloat(PBRMaterial._iorProp);
20360
+ },
20361
+ set: function set(v) {
20362
+ this.shaderData.setFloat(PBRMaterial._iorProp, Math.max(v, 0));
20449
20363
  }
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, [
20364
+ },
20463
20365
  {
20464
- key: "isActive",
20366
+ key: "metallic",
20465
20367
  get: /**
20466
- * Whether to activate locally.
20368
+ * Metallic.
20369
+ * @defaultValue `1.0`
20467
20370
  */ function get() {
20468
- return this._isActive;
20371
+ return this.shaderData.getFloat(PBRMaterial._metallicProp);
20469
20372
  },
20470
20373
  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);
20374
+ this.shaderData.setFloat(PBRMaterial._metallicProp, value);
20375
+ }
20376
+ },
20377
+ {
20378
+ key: "roughness",
20379
+ get: /**
20380
+ * Roughness. default 1.0.
20381
+ * @defaultValue `1.0`
20382
+ */ function get() {
20383
+ return this.shaderData.getFloat(PBRMaterial._roughnessProp);
20384
+ },
20385
+ set: function set(value) {
20386
+ this.shaderData.setFloat(PBRMaterial._roughnessProp, value);
20387
+ }
20388
+ },
20389
+ {
20390
+ key: "roughnessMetallicTexture",
20391
+ get: /**
20392
+ * Roughness metallic texture.
20393
+ * @remarks G channel is roughness, B channel is metallic
20394
+ */ function get() {
20395
+ return this.shaderData.getTexture(PBRMaterial._roughnessMetallicTextureProp);
20396
+ },
20397
+ set: function set(value) {
20398
+ this.shaderData.setTexture(PBRMaterial._roughnessMetallicTextureProp, value);
20399
+ if (value) {
20400
+ this.shaderData.enableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
20401
+ } else {
20402
+ this.shaderData.disableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
20403
+ }
20404
+ }
20405
+ },
20406
+ {
20407
+ key: "anisotropy",
20408
+ get: /**
20409
+ * The strength of anisotropy, when anisotropyTexture is present, this value is multiplied by the blue channel.
20410
+ * @defaultValue `0`
20411
+ */ function get() {
20412
+ return this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp).z;
20413
+ },
20414
+ set: function set(value) {
20415
+ var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
20416
+ if (!!anisotropyInfo.z !== !!value) {
20417
+ if (value === 0) {
20418
+ this.shaderData.disableMacro("MATERIAL_ENABLE_ANISOTROPY");
20484
20419
  } else {
20485
- var activeChangeFlag1 = ActiveChangeFlag.None;
20486
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
20487
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
20488
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
20420
+ this.shaderData.enableMacro("MATERIAL_ENABLE_ANISOTROPY");
20489
20421
  }
20490
20422
  }
20423
+ anisotropyInfo.z = value;
20491
20424
  }
20492
20425
  },
20493
20426
  {
20494
- key: "isActiveInHierarchy",
20427
+ key: "anisotropyRotation",
20495
20428
  get: /**
20496
- * Whether it is active in the hierarchy.
20429
+ * The rotation of the anisotropy in tangent, bitangent space, value in degrees.
20430
+ * @defaultValue `0`
20497
20431
  */ function get() {
20498
- return this._isActiveInHierarchy;
20432
+ return this._anisotropyRotation;
20433
+ },
20434
+ set: function set(value) {
20435
+ if (this._anisotropyRotation !== value) {
20436
+ this._anisotropyRotation = value;
20437
+ var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
20438
+ var rad = MathUtil.degreeToRadFactor * value;
20439
+ anisotropyInfo.x = Math.cos(rad);
20440
+ anisotropyInfo.y = Math.sin(rad);
20441
+ }
20499
20442
  }
20500
20443
  },
20501
20444
  {
20502
- key: "parent",
20445
+ key: "anisotropyTexture",
20503
20446
  get: /**
20504
- * The parent entity.
20447
+ * The anisotropy texture.
20448
+ * @remarks
20449
+ * Red and green channels represent the anisotropy direction in [-1, 1] tangent, bitangent space, to be rotated by anisotropyRotation.
20450
+ * The blue channel contains strength as [0, 1] to be multiplied by anisotropy.
20505
20451
  */ function get() {
20506
- return this._parent;
20452
+ return this.shaderData.getTexture(PBRMaterial._anisotropyTextureProp);
20507
20453
  },
20508
20454
  set: function set(value) {
20509
- this._setParent(value);
20455
+ this.shaderData.setTexture(PBRMaterial._anisotropyTextureProp, value);
20456
+ if (value) {
20457
+ this.shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
20458
+ } else {
20459
+ this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
20460
+ }
20461
+ }
20462
+ }
20463
+ ]);
20464
+ return PBRMaterial;
20465
+ }(PBRBaseMaterial);
20466
+ (function() {
20467
+ PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
20468
+ })();
20469
+ (function() {
20470
+ PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
20471
+ })();
20472
+ (function() {
20473
+ PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
20474
+ })();
20475
+ (function() {
20476
+ PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
20477
+ })();
20478
+ (function() {
20479
+ PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
20480
+ })();
20481
+ (function() {
20482
+ PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
20483
+ })();
20484
+ /**
20485
+ * PBR (Specular-Glossiness Workflow) Material.
20486
+ */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
20487
+ _inherits$2(PBRSpecularMaterial, PBRBaseMaterial1);
20488
+ function PBRSpecularMaterial(engine) {
20489
+ var _this;
20490
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
20491
+ _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new Color(1, 1, 1, 1));
20492
+ _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
20493
+ return _this;
20494
+ }
20495
+ var _proto = PBRSpecularMaterial.prototype;
20496
+ /**
20497
+ * @inheritdoc
20498
+ */ _proto.clone = function clone() {
20499
+ var dest = new PBRSpecularMaterial(this._engine);
20500
+ this.cloneTo(dest);
20501
+ return dest;
20502
+ };
20503
+ _create_class$2(PBRSpecularMaterial, [
20504
+ {
20505
+ key: "specularColor",
20506
+ get: /**
20507
+ * Specular color.
20508
+ */ function get() {
20509
+ return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20510
+ },
20511
+ set: function set(value) {
20512
+ var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20513
+ if (value !== specularColor) {
20514
+ specularColor.copyFrom(value);
20515
+ }
20510
20516
  }
20511
20517
  },
20512
20518
  {
20513
- key: "children",
20519
+ key: "glossiness",
20514
20520
  get: /**
20515
- * The children entities
20521
+ * Glossiness.
20516
20522
  */ function get() {
20517
- return this._children;
20523
+ return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
20524
+ },
20525
+ set: function set(value) {
20526
+ this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
20518
20527
  }
20519
20528
  },
20520
20529
  {
20521
- key: "childCount",
20530
+ key: "specularGlossinessTexture",
20522
20531
  get: /**
20523
- * @deprecated Please use `children.length` property instead.
20524
- * Number of the children entities
20532
+ * Specular glossiness texture.
20533
+ * @remarks RGB is specular, A is glossiness
20525
20534
  */ function get() {
20526
- return this._children.length;
20535
+ return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
20536
+ },
20537
+ set: function set(value) {
20538
+ this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
20539
+ if (value) {
20540
+ this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20541
+ } else {
20542
+ this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20543
+ }
20544
+ }
20545
+ }
20546
+ ]);
20547
+ return PBRSpecularMaterial;
20548
+ }(PBRBaseMaterial);
20549
+ (function() {
20550
+ PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
20551
+ })();
20552
+ (function() {
20553
+ PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
20554
+ })();
20555
+ (function() {
20556
+ PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
20557
+ })();
20558
+ (function() {
20559
+ PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
20560
+ })();
20561
+ /**
20562
+ * Unlit Material.
20563
+ */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
20564
+ _inherits$2(UnlitMaterial, BaseMaterial1);
20565
+ function UnlitMaterial(engine) {
20566
+ var _this;
20567
+ _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
20568
+ var shaderData = _this.shaderData;
20569
+ shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
20570
+ shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
20571
+ shaderData.setColor(UnlitMaterial._baseColorProp, new Color(1, 1, 1, 1));
20572
+ shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new Vector4(1, 1, 0, 0));
20573
+ return _this;
20574
+ }
20575
+ var _proto = UnlitMaterial.prototype;
20576
+ /**
20577
+ * @inheritdoc
20578
+ */ _proto.clone = function clone() {
20579
+ var dest = new UnlitMaterial(this._engine);
20580
+ this.cloneTo(dest);
20581
+ return dest;
20582
+ };
20583
+ _create_class$2(UnlitMaterial, [
20584
+ {
20585
+ key: "baseColor",
20586
+ get: /**
20587
+ * Base color.
20588
+ */ function get() {
20589
+ return this.shaderData.getColor(UnlitMaterial._baseColorProp);
20590
+ },
20591
+ set: function set(value) {
20592
+ var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
20593
+ if (value !== baseColor) {
20594
+ baseColor.copyFrom(value);
20595
+ }
20527
20596
  }
20528
20597
  },
20529
20598
  {
20530
- key: "scene",
20599
+ key: "baseTexture",
20531
20600
  get: /**
20532
- * The scene the entity belongs to.
20601
+ * Base texture.
20533
20602
  */ function get() {
20534
- return this._scene;
20603
+ return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
20604
+ },
20605
+ set: function set(value) {
20606
+ this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
20607
+ if (value) {
20608
+ this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
20609
+ } else {
20610
+ this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
20611
+ }
20535
20612
  }
20536
20613
  },
20537
20614
  {
20538
- key: "siblingIndex",
20615
+ key: "tilingOffset",
20539
20616
  get: /**
20540
- * The sibling index.
20617
+ * Tiling and offset of main textures.
20541
20618
  */ function get() {
20542
- return this._siblingIndex;
20619
+ return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20543
20620
  },
20544
20621
  set: function set(value) {
20545
- if (this._siblingIndex === -1) {
20546
- throw "The entity " + this.name + " is not in the hierarchy";
20622
+ var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20623
+ if (value !== tilingOffset) {
20624
+ tilingOffset.copyFrom(value);
20547
20625
  }
20548
- this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
20549
20626
  }
20550
20627
  }
20551
20628
  ]);
20552
- return Entity;
20553
- }(EngineObject);
20629
+ return UnlitMaterial;
20630
+ }(BaseMaterial);
20631
+ /**
20632
+ * @internal
20633
+ */ var BasicResources = /*#__PURE__*/ function() {
20634
+ var BasicResources = function BasicResources(engine) {
20635
+ // prettier-ignore
20636
+ var vertices = new Float32Array([
20637
+ -1,
20638
+ -1,
20639
+ 0,
20640
+ 1,
20641
+ 1,
20642
+ -1,
20643
+ 1,
20644
+ 1,
20645
+ -1,
20646
+ 1,
20647
+ 0,
20648
+ 0,
20649
+ 1,
20650
+ 1,
20651
+ 1,
20652
+ 0
20653
+ ]); // right-top
20654
+ // prettier-ignore
20655
+ var flipYVertices = new Float32Array([
20656
+ 1,
20657
+ -1,
20658
+ 1,
20659
+ 0,
20660
+ -1,
20661
+ -1,
20662
+ 0,
20663
+ 0,
20664
+ 1,
20665
+ 1,
20666
+ 1,
20667
+ 1,
20668
+ -1,
20669
+ 1,
20670
+ 0,
20671
+ 1
20672
+ ]); // left-top
20673
+ var blitMaterial = new Material(engine, Shader.find("blit"));
20674
+ blitMaterial._addReferCount(1);
20675
+ blitMaterial.renderState.depthState.enabled = false;
20676
+ blitMaterial.renderState.depthState.writeEnabled = false;
20677
+ this.blitMesh = this._createBlitMesh(engine, vertices);
20678
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
20679
+ this.blitMaterial = blitMaterial;
20680
+ // Create white and magenta textures
20681
+ var whitePixel = new Uint8Array([
20682
+ 255,
20683
+ 255,
20684
+ 255,
20685
+ 255
20686
+ ]);
20687
+ this.whiteTexture2D = this._create1x1Texture(engine, 0, exports.TextureFormat.R8G8B8A8, whitePixel);
20688
+ this.whiteTextureCube = this._create1x1Texture(engine, 1, exports.TextureFormat.R8G8B8A8, whitePixel);
20689
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
20690
+ if (isWebGL2) {
20691
+ this.whiteTexture2DArray = this._create1x1Texture(engine, 2, exports.TextureFormat.R8G8B8A8, whitePixel);
20692
+ var whitePixel32 = new Uint32Array([
20693
+ 255,
20694
+ 255,
20695
+ 255,
20696
+ 255
20697
+ ]);
20698
+ this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, exports.TextureFormat.R32G32B32A32_UInt, whitePixel32);
20699
+ }
20700
+ };
20701
+ var _proto = BasicResources.prototype;
20702
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
20703
+ var mesh = new ModelMesh(engine);
20704
+ mesh._addReferCount(1);
20705
+ mesh.setVertexElements([
20706
+ new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
20707
+ ]);
20708
+ mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
20709
+ mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
20710
+ return mesh;
20711
+ };
20712
+ _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel) {
20713
+ var texture;
20714
+ switch(type){
20715
+ case 0:
20716
+ var texture2D = new Texture2D(engine, 1, 1, format, false);
20717
+ texture2D.setPixelBuffer(pixel);
20718
+ texture = texture2D;
20719
+ break;
20720
+ case 2:
20721
+ var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false);
20722
+ texture2DArray.setPixelBuffer(0, pixel);
20723
+ texture = texture2DArray;
20724
+ break;
20725
+ case 1:
20726
+ var textureCube = new TextureCube(engine, 1, format, false);
20727
+ for(var i = 0; i < 6; i++){
20728
+ textureCube.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, pixel);
20729
+ }
20730
+ texture = textureCube;
20731
+ break;
20732
+ default:
20733
+ throw "Invalid texture type";
20734
+ }
20735
+ texture.isGCIgnored = true;
20736
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
20737
+ var _class = function _class() {
20738
+ return ContentRestorer.call(this, texture);
20739
+ };
20740
+ _inherits$2(_class, ContentRestorer);
20741
+ var _proto = _class.prototype;
20742
+ _proto.restoreContent = function restoreContent() {
20743
+ switch(type){
20744
+ case 0:
20745
+ this.resource.setPixelBuffer(pixel);
20746
+ break;
20747
+ case 2:
20748
+ this.resource.setPixelBuffer(0, pixel);
20749
+ break;
20750
+ case 1:
20751
+ for(var i = 0; i < 6; i++){
20752
+ this.resource.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, pixel);
20753
+ }
20754
+ break;
20755
+ }
20756
+ };
20757
+ return _class;
20758
+ }(ContentRestorer))());
20759
+ return texture;
20760
+ };
20761
+ return BasicResources;
20762
+ }();
20763
+ var TextureType;
20764
+ (function(TextureType) {
20765
+ TextureType[TextureType["Texture2D"] = 0] = "Texture2D";
20766
+ TextureType[TextureType["TextureCube"] = 1] = "TextureCube";
20767
+ TextureType[TextureType["Texture2DArray"] = 2] = "Texture2DArray";
20768
+ })(TextureType || (TextureType = {}));
20554
20769
  /**
20555
20770
  * @internal
20556
20771
  * Rendering context.
@@ -21330,17 +21545,33 @@
21330
21545
  };
21331
21546
  /**
21332
21547
  * @internal
21333
- */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(assetURL, value) {
21334
- var _this__subAssetPromiseCallbacks_assetURL;
21335
- (_this__subAssetPromiseCallbacks_assetURL = this._subAssetPromiseCallbacks[assetURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetURL.resolve(value);
21336
- delete this._subAssetPromiseCallbacks[assetURL];
21548
+ */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(assetBaseURL, assetSubPath, value) {
21549
+ var _this__subAssetPromiseCallbacks_assetBaseURL;
21550
+ var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
21551
+ if (subPromiseCallback) {
21552
+ // Already resolved
21553
+ subPromiseCallback.resolve(value);
21554
+ } else {
21555
+ var _this__subAssetPromiseCallbacks, _assetBaseURL;
21556
+ ((_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
21557
+ resolve: value
21558
+ };
21559
+ }
21337
21560
  };
21338
21561
  /**
21339
21562
  * @internal
21340
- */ _proto._onSubAssetFail = function _onSubAssetFail(assetURL, value) {
21341
- var _this__subAssetPromiseCallbacks_assetURL;
21342
- (_this__subAssetPromiseCallbacks_assetURL = this._subAssetPromiseCallbacks[assetURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetURL.reject(value);
21343
- delete this._subAssetPromiseCallbacks[assetURL];
21563
+ */ _proto._onSubAssetFail = function _onSubAssetFail(assetBaseURL, assetSubPath, value) {
21564
+ var _this__subAssetPromiseCallbacks_assetBaseURL;
21565
+ var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
21566
+ if (subPromiseCallback) {
21567
+ // Already rejected
21568
+ subPromiseCallback.reject(value);
21569
+ } else {
21570
+ var _this__subAssetPromiseCallbacks, _assetBaseURL;
21571
+ ((_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
21572
+ reject: value
21573
+ };
21574
+ }
21344
21575
  };
21345
21576
  /**
21346
21577
  * @internal
@@ -21485,8 +21716,21 @@
21485
21716
  if (!loader) {
21486
21717
  throw "loader not found: " + item.type;
21487
21718
  }
21488
- // Load asset
21719
+ // Check sub asset
21720
+ if (queryPath) {
21721
+ // Check whether load main asset
21722
+ var mainPromise = loadingPromises[assetBaseURL] || this._loadMainAsset(loader, item, assetBaseURL);
21723
+ mainPromise.catch(function(e) {
21724
+ _this._onSubAssetFail(assetBaseURL, queryPath, e);
21725
+ });
21726
+ return this._createSubAssetPromiseCallback(assetBaseURL, assetURL, queryPath);
21727
+ }
21728
+ return this._loadMainAsset(loader, item, assetBaseURL);
21729
+ };
21730
+ _proto._loadMainAsset = function _loadMainAsset(loader, item, assetBaseURL) {
21731
+ var _this = this;
21489
21732
  item.url = assetBaseURL;
21733
+ var loadingPromises = this._loadingPromises;
21490
21734
  var promise = loader.load(item, this);
21491
21735
  loadingPromises[assetBaseURL] = promise;
21492
21736
  promise.then(function(resource) {
@@ -21494,32 +21738,46 @@
21494
21738
  _this._addAsset(assetBaseURL, resource);
21495
21739
  }
21496
21740
  delete loadingPromises[assetBaseURL];
21741
+ _this._releaseSubAssetPromiseCallback(assetBaseURL);
21497
21742
  }, function() {
21498
- return delete loadingPromises[assetBaseURL];
21743
+ delete loadingPromises[assetBaseURL];
21744
+ _this._releaseSubAssetPromiseCallback(assetBaseURL);
21499
21745
  });
21500
- if (queryPath) {
21501
- var subPromise = new AssetPromise(function(resolve, reject) {
21502
- _this._pushSubAssetPromiseCallback(assetURL, resolve, reject);
21503
- });
21504
- loadingPromises[assetURL] = subPromise;
21505
- subPromise.then(function() {
21746
+ return promise;
21747
+ };
21748
+ _proto._createSubAssetPromiseCallback = function _createSubAssetPromiseCallback(assetBaseURL, assetURL, assetSubPath) {
21749
+ var _this = this;
21750
+ var _this__subAssetPromiseCallbacks_assetBaseURL, _subPromiseCallback, _subPromiseCallback1;
21751
+ var loadingPromises = this._loadingPromises;
21752
+ var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
21753
+ var resolvedValue = (_subPromiseCallback = subPromiseCallback) == null ? void 0 : _subPromiseCallback.resolve;
21754
+ var rejectedValue = (_subPromiseCallback1 = subPromiseCallback) == null ? void 0 : _subPromiseCallback1.reject;
21755
+ var promise = new AssetPromise(function(resolve, reject) {
21756
+ if (resolvedValue) {
21757
+ // Already resolved
21758
+ resolve(resolvedValue);
21759
+ } else if (rejectedValue) {
21760
+ // Already rejected
21761
+ reject(rejectedValue);
21762
+ } else {
21763
+ var _this__subAssetPromiseCallbacks, _assetBaseURL;
21764
+ // Pending
21765
+ loadingPromises[assetURL] = promise;
21766
+ ((_this__subAssetPromiseCallbacks = _this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
21767
+ resolve: resolve,
21768
+ reject: reject
21769
+ };
21770
+ }
21771
+ });
21772
+ if (!resolvedValue && !rejectedValue) {
21773
+ promise.then(function() {
21506
21774
  delete loadingPromises[assetURL];
21507
21775
  }, function() {
21508
21776
  return delete loadingPromises[assetURL];
21509
21777
  });
21510
- promise.catch(function(e) {
21511
- _this._onSubAssetFail(assetURL, e);
21512
- });
21513
- return subPromise;
21514
21778
  }
21515
21779
  return promise;
21516
21780
  };
21517
- _proto._pushSubAssetPromiseCallback = function _pushSubAssetPromiseCallback(assetURL, resolve, reject) {
21518
- this._subAssetPromiseCallbacks[assetURL] = {
21519
- resolve: resolve,
21520
- reject: reject
21521
- };
21522
- };
21523
21781
  _proto._gc = function _gc(forceDestroy) {
21524
21782
  var objects = Utils.objectValues(this._referResourcePool);
21525
21783
  for(var i = 0, n = objects.length; i < n; i++){
@@ -21576,6 +21834,9 @@
21576
21834
  });
21577
21835
  return result;
21578
21836
  };
21837
+ _proto._releaseSubAssetPromiseCallback = function _releaseSubAssetPromiseCallback(assetBaseURL) {
21838
+ delete this._subAssetPromiseCallbacks[assetBaseURL];
21839
+ };
21579
21840
  /**
21580
21841
  * @internal
21581
21842
  * @beta Just for internal editor, not recommended for developers.
@@ -25000,7 +25261,6 @@
25000
25261
  _this.xrManager = new XRManager();
25001
25262
  _this.xrManager._initialize(_assert_this_initialized(_this), xrDevice);
25002
25263
  }
25003
- _this._initMagentaTextures(hardwareRenderer);
25004
25264
  if (!hardwareRenderer.canIUse(exports.GLCapabilityType.depthTexture)) {
25005
25265
  _this._macroCollection.enable(Engine._noDepthTextureMacro);
25006
25266
  } else {
@@ -25236,99 +25496,6 @@
25236
25496
  };
25237
25497
  /**
25238
25498
  * @internal
25239
- * Standalone for CanvasRenderer plugin.
25240
- */ _proto._initMagentaTextures = function _initMagentaTextures(hardwareRenderer) {
25241
- var whitePixel = new Uint8Array([
25242
- 255,
25243
- 255,
25244
- 255,
25245
- 255
25246
- ]);
25247
- var whiteTexture2D = new Texture2D(this, 1, 1, exports.TextureFormat.R8G8B8A8, false);
25248
- whiteTexture2D.setPixelBuffer(whitePixel);
25249
- whiteTexture2D.isGCIgnored = true;
25250
- var magentaPixel = new Uint8Array([
25251
- 255,
25252
- 0,
25253
- 255,
25254
- 255
25255
- ]);
25256
- var magentaTexture2D = new Texture2D(this, 1, 1, exports.TextureFormat.R8G8B8A8, false);
25257
- magentaTexture2D.setPixelBuffer(magentaPixel);
25258
- magentaTexture2D.isGCIgnored = true;
25259
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25260
- var _class = function _class() {
25261
- return ContentRestorer.call(this, magentaTexture2D);
25262
- };
25263
- _inherits$2(_class, ContentRestorer);
25264
- var _proto = _class.prototype;
25265
- _proto.restoreContent = function restoreContent() {
25266
- this.resource.setPixelBuffer(magentaPixel);
25267
- };
25268
- return _class;
25269
- }(ContentRestorer))());
25270
- var magentaTextureCube = new TextureCube(this, 1, exports.TextureFormat.R8G8B8A8, false);
25271
- for(var i = 0; i < 6; i++){
25272
- magentaTextureCube.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, magentaPixel);
25273
- }
25274
- magentaTextureCube.isGCIgnored = true;
25275
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25276
- var _class = function _class() {
25277
- return ContentRestorer.call(this, magentaTextureCube);
25278
- };
25279
- _inherits$2(_class, ContentRestorer);
25280
- var _proto = _class.prototype;
25281
- _proto.restoreContent = function restoreContent() {
25282
- for(var i = 0; i < 6; i++){
25283
- this.resource.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, magentaPixel);
25284
- }
25285
- };
25286
- return _class;
25287
- }(ContentRestorer))());
25288
- this._whiteTexture2D = whiteTexture2D;
25289
- this._magentaTexture2D = magentaTexture2D;
25290
- this._magentaTextureCube = magentaTextureCube;
25291
- if (hardwareRenderer.isWebGL2) {
25292
- var magentaPixel32 = new Uint32Array([
25293
- 255,
25294
- 0,
25295
- 255,
25296
- 255
25297
- ]);
25298
- var uintMagentaTexture2D = new Texture2D(this, 1, 1, exports.TextureFormat.R32G32B32A32_UInt, false);
25299
- uintMagentaTexture2D.setPixelBuffer(magentaPixel32);
25300
- uintMagentaTexture2D.isGCIgnored = true;
25301
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25302
- var _class = function _class() {
25303
- return ContentRestorer.call(this, uintMagentaTexture2D);
25304
- };
25305
- _inherits$2(_class, ContentRestorer);
25306
- var _proto = _class.prototype;
25307
- _proto.restoreContent = function restoreContent() {
25308
- this.resource.setPixelBuffer(magentaPixel32);
25309
- };
25310
- return _class;
25311
- }(ContentRestorer))());
25312
- var magentaTexture2DArray = new Texture2DArray(this, 1, 1, 1, exports.TextureFormat.R8G8B8A8, false);
25313
- magentaTexture2DArray.setPixelBuffer(0, magentaPixel);
25314
- magentaTexture2DArray.isGCIgnored = true;
25315
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25316
- var _class = function _class() {
25317
- return ContentRestorer.call(this, magentaTexture2DArray);
25318
- };
25319
- _inherits$2(_class, ContentRestorer);
25320
- var _proto = _class.prototype;
25321
- _proto.restoreContent = function restoreContent() {
25322
- this.resource.setPixelBuffer(0, magentaPixel);
25323
- };
25324
- return _class;
25325
- }(ContentRestorer))());
25326
- this._uintMagentaTexture2D = uintMagentaTexture2D;
25327
- this._magentaTexture2DArray = magentaTexture2DArray;
25328
- }
25329
- };
25330
- /**
25331
- * @internal
25332
25499
  */ _proto._pendingGC = function _pendingGC() {
25333
25500
  if (this._frameInProcess) {
25334
25501
  this._waitingGC = true;
@@ -25962,6 +26129,8 @@
25962
26129
  script._started = true;
25963
26130
  _this.removeOnStartScript(script);
25964
26131
  script.onStart();
26132
+ }, function(element, index) {
26133
+ element._onStartIndex = index;
25965
26134
  });
25966
26135
  }
25967
26136
  };
@@ -28875,7 +29044,7 @@
28875
29044
  depthOnlyPass.onConfig(camera);
28876
29045
  depthOnlyPass.onRender(context, cullingResults);
28877
29046
  } else {
28878
- camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._whiteTexture2D);
29047
+ camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
28879
29048
  }
28880
29049
  // Check if need to create internal color texture
28881
29050
  var independentCanvasEnabled = camera.independentCanvasEnabled;
@@ -31575,69 +31744,13 @@
31575
31744
  _proto.dispose = function dispose() {};
31576
31745
  return AnimationEventHandler;
31577
31746
  }();
31578
- /**
31579
- * Condition that is used to determine if a transition must be taken.
31580
- */ var AnimatorCondition = function AnimatorCondition() {};
31581
31747
  /**
31582
31748
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.
31583
- */ var AnimatorStateTransition = /*#__PURE__*/ function() {
31584
- var AnimatorStateTransition = function AnimatorStateTransition() {
31585
- /** The duration of the transition. This is represented in normalized time. */ this.duration = 0;
31586
- /** The time at which the destination state will start. This is represented in normalized time. */ this.offset = 0;
31587
- /** ExitTime represents the exact time at which the transition can take effect. This is represented in normalized time. */ this.exitTime = 1;
31588
- /** Mutes the transition. The transition will never occur. */ this.mute = false;
31589
- /** Is the transition destination the exit of the current state machine. */ this.isExit = false;
31590
- this._conditions = [];
31591
- this._solo = false;
31592
- };
31593
- var _proto = AnimatorStateTransition.prototype;
31594
- _proto.addCondition = function addCondition(param, parameter, threshold) {
31595
- if (typeof param === "object") {
31596
- this._conditions.push(param);
31597
- return param;
31598
- } else {
31599
- var condition = new AnimatorCondition();
31600
- condition.mode = param;
31601
- condition.parameter = parameter;
31602
- condition.threshold = threshold;
31603
- this._conditions.push(condition);
31604
- return condition;
31605
- }
31606
- };
31607
- /**
31608
- * Remove a condition from the transition.
31609
- * @param condition - The condition to remove
31610
- */ _proto.removeCondition = function removeCondition(condition) {
31611
- var index = this._conditions.indexOf(condition);
31612
- index !== -1 && this._conditions.splice(index, 1);
31613
- };
31614
- _create_class$2(AnimatorStateTransition, [
31615
- {
31616
- key: "solo",
31617
- get: /** Mutes all other transitions in the source state. */ function get() {
31618
- return this._solo;
31619
- },
31620
- set: function set(value) {
31621
- if (this._solo === value) return;
31622
- this._solo = value;
31623
- if (value) {
31624
- this._srcState && this._srcState._updateSoloTransition(true);
31625
- } else {
31626
- this._srcState && this._srcState._updateSoloTransition();
31627
- }
31628
- }
31629
- },
31630
- {
31631
- key: "conditions",
31632
- get: /**
31633
- * The conditions in the transition.
31634
- */ function get() {
31635
- return this._conditions;
31636
- }
31637
- }
31638
- ]);
31639
- return AnimatorStateTransition;
31640
- }();
31749
+ */ var AnimatorStateTransition = function AnimatorStateTransition() {
31750
+ /** The duration of the transition. This is represented in normalized time. */ this.duration = 0;
31751
+ /** The time at which the destination state will start. This is represented in normalized time. */ this.offset = 0;
31752
+ /** ExitTime represents the exact time at which the transition can take effect. This is represented in normalized time. */ this.exitTime = 1;
31753
+ };
31641
31754
  /**
31642
31755
  * Animation wrap mode.
31643
31756
  */ exports.WrapMode = void 0;
@@ -31709,15 +31822,6 @@
31709
31822
  this.curveLayerOwner = [];
31710
31823
  this.eventHandlers = [];
31711
31824
  };
31712
- exports.AnimatorConditionMode = void 0;
31713
- (function(AnimatorConditionMode) {
31714
- AnimatorConditionMode[AnimatorConditionMode["If"] = 0] = "If";
31715
- AnimatorConditionMode[AnimatorConditionMode["IfNot"] = 1] = "IfNot";
31716
- AnimatorConditionMode[AnimatorConditionMode["Greater"] = 2] = "Greater";
31717
- AnimatorConditionMode[AnimatorConditionMode["Less"] = 3] = "Less";
31718
- AnimatorConditionMode[AnimatorConditionMode["Equals"] = 4] = "Equals";
31719
- AnimatorConditionMode[AnimatorConditionMode["NotEquals"] = 5] = "NotEquals";
31720
- })(exports.AnimatorConditionMode || (exports.AnimatorConditionMode = {}));
31721
31825
  /**
31722
31826
  * The controller of the animation system.
31723
31827
  */ var Animator = /*#__PURE__*/ function(Component1) {
@@ -31770,29 +31874,26 @@
31770
31874
  animatorLayerData.srcPlayData.reset(state, animatorStateData, state._getDuration() * normalizedTimeOffset);
31771
31875
  this.update(0);
31772
31876
  };
31773
- _proto.crossFade = function crossFade(stateNameOrTransition, normalizedTransitionDurationOrLayerIndex, layerIndex, normalizedTimeOffset) {
31877
+ /**
31878
+ * Create a cross fade from the current state to another state.
31879
+ * @param stateName - The state name
31880
+ * @param normalizedTransitionDuration - The duration of the transition (normalized)
31881
+ * @param layerIndex - The layer index(default -1). If layer is -1, play the first state with the given state name
31882
+ * @param normalizedTimeOffset - The time offset between 0 and 1(default 0)
31883
+ */ _proto.crossFade = function crossFade(stateName, normalizedTransitionDuration, layerIndex, normalizedTimeOffset) {
31774
31884
  if (layerIndex === void 0) layerIndex = -1;
31775
31885
  if (normalizedTimeOffset === void 0) normalizedTimeOffset = 0;
31776
- var state;
31777
- var playLayerIndex;
31778
- var normalizedTransitionDuration;
31779
- var transition;
31780
- if (typeof stateNameOrTransition === "string") {
31781
- var info = this._getAnimatorStateInfo(stateNameOrTransition, layerIndex);
31782
- state = info.state;
31783
- playLayerIndex = info.layerIndex;
31784
- normalizedTransitionDuration = normalizedTransitionDurationOrLayerIndex;
31785
- var manuallyTransition = this._getAnimatorLayerData(playLayerIndex).manuallyTransition;
31786
- manuallyTransition.duration = normalizedTransitionDuration;
31787
- manuallyTransition.offset = normalizedTimeOffset;
31788
- manuallyTransition.destinationState = state;
31789
- transition = manuallyTransition;
31790
- } else {
31791
- state = stateNameOrTransition.destinationState;
31792
- playLayerIndex = normalizedTransitionDurationOrLayerIndex != null ? normalizedTransitionDurationOrLayerIndex : this._getAnimatorStateInfo(state.name, playLayerIndex).layerIndex;
31793
- transition = stateNameOrTransition;
31886
+ var _this__controllerUpdateFlag;
31887
+ if ((_this__controllerUpdateFlag = this._controllerUpdateFlag) == null ? void 0 : _this__controllerUpdateFlag.flag) {
31888
+ this._reset();
31794
31889
  }
31795
- if (this._crossFadeByTransition(transition, playLayerIndex)) {
31890
+ this._playFrameCount = this.engine.time.frameCount;
31891
+ var _this__getAnimatorStateInfo = this._getAnimatorStateInfo(stateName, layerIndex), state = _this__getAnimatorStateInfo.state, playLayerIndex = _this__getAnimatorStateInfo.layerIndex;
31892
+ var manuallyTransition = this._getAnimatorLayerData(playLayerIndex).manuallyTransition;
31893
+ manuallyTransition.duration = normalizedTransitionDuration;
31894
+ manuallyTransition.offset = normalizedTimeOffset;
31895
+ manuallyTransition.destinationState = state;
31896
+ if (this._crossFadeByTransition(manuallyTransition, playLayerIndex)) {
31796
31897
  this.update(0);
31797
31898
  }
31798
31899
  };
@@ -31819,7 +31920,7 @@
31819
31920
  return;
31820
31921
  }
31821
31922
  if ((_this__controllerUpdateFlag = this._controllerUpdateFlag) == null ? void 0 : _this__controllerUpdateFlag.flag) {
31822
- this._checkEntryState();
31923
+ this._checkAutoPlay();
31823
31924
  return;
31824
31925
  }
31825
31926
  this._updateMark++;
@@ -31847,31 +31948,9 @@
31847
31948
  return this._getAnimatorStateInfo(stateName, layerIndex).state;
31848
31949
  };
31849
31950
  /**
31850
- * Get the layer by name.
31851
- * @param name - The layer's name.
31852
- */ _proto.findLayerByName = function findLayerByName(name1) {
31853
- return this._animatorController._layersMap[name1];
31854
- };
31855
- /**
31856
- * Get the parameter by name.
31857
- * @param name - The name of the parameter
31858
- */ _proto.getParameter = function getParameter(name1) {
31859
- return this._animatorController._parametersMap[name1] || null;
31860
- };
31861
- /**
31862
- * Set the value of the given parameter.
31863
- * @param name - The name of the parameter
31864
- */ _proto.setParameter = function setParameter(name1, value) {
31865
- var controller = this._animatorController;
31866
- var parameter = controller._parametersMap[name1];
31867
- if (parameter) {
31868
- parameter.value = value;
31869
- }
31870
- };
31871
- /**
31872
31951
  * @internal
31873
31952
  */ _proto._onEnable = function _onEnable() {
31874
- this.animatorController && this._checkEntryState();
31953
+ this.animatorController && this._checkAutoPlay();
31875
31954
  this._entity.getComponentsIncludeChildren(exports.Renderer, this._controlledRenderers);
31876
31955
  };
31877
31956
  /**
@@ -32062,8 +32141,7 @@
32062
32141
  return animatorLayerData;
32063
32142
  };
32064
32143
  _proto._updateLayer = function _updateLayer(layerIndex, firstLayer, deltaTime, aniUpdate) {
32065
- var _this__animatorController_layers_layerIndex = this._animatorController.layers[layerIndex], blendingMode = _this__animatorController_layers_layerIndex.blendingMode, weight = _this__animatorController_layers_layerIndex.weight, stateMachine = _this__animatorController_layers_layerIndex.stateMachine;
32066
- if (!stateMachine) return;
32144
+ var _this__animatorController_layers_layerIndex = this._animatorController.layers[layerIndex], blendingMode = _this__animatorController_layers_layerIndex.blendingMode, weight = _this__animatorController_layers_layerIndex.weight;
32067
32145
  var layerData = this._animatorLayersData[layerIndex];
32068
32146
  var srcPlayData = layerData.srcPlayData, destPlayData = layerData.destPlayData;
32069
32147
  var additive = blendingMode === exports.AnimatorLayerBlendingMode.Additive;
@@ -32088,7 +32166,6 @@
32088
32166
  var state = playData.state, lastPlayState = playData.playState, lastClipTime = playData.clipTime;
32089
32167
  var transitions = state.transitions;
32090
32168
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
32091
- var anyStateTransitions = this.layers[layerIndex].stateMachine.anyStateTransitions;
32092
32169
  var speed = state.speed * this.speed;
32093
32170
  playData.frameTime += speed * delta;
32094
32171
  playData.update(speed < 0);
@@ -32121,10 +32198,10 @@
32121
32198
  } else {
32122
32199
  this._callAnimatorScriptOnUpdate(state, layerIndex);
32123
32200
  }
32124
- if (transitions.length || anyStateTransitions.length) {
32201
+ if (transitions.length) {
32125
32202
  var layerState = layerData.layerState;
32126
32203
  if (layerState !== LayerState.CrossFading && layerState !== LayerState.FixedCrossFading) {
32127
- this._checkTransition(playData, transitions, anyStateTransitions, layerIndex, lastClipTime, clipTime);
32204
+ this._checkTransition(playData, transitions, layerIndex, lastClipTime, clipTime);
32128
32205
  }
32129
32206
  }
32130
32207
  };
@@ -32270,61 +32347,43 @@
32270
32347
  }
32271
32348
  }
32272
32349
  };
32273
- _proto._checkTransition = function _checkTransition(playState, transitions, anyStateTransitions, layerIndex, lastClipTime, clipTime) {
32350
+ _proto._checkTransition = function _checkTransition(playState, transitions, layerIndex, lastClipTime, clipTime) {
32274
32351
  var state = playState.state;
32275
32352
  var clipDuration = state.clip.length;
32276
- var targetTransition = null;
32277
32353
  if (this.speed * state.speed >= 0) {
32278
32354
  if (clipTime < lastClipTime) {
32279
- targetTransition = this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipEndTime * clipDuration);
32280
- if (!targetTransition) {
32281
- playState.currentTransitionIndex = 0;
32282
- targetTransition = this._checkSubTransition(playState, transitions, layerIndex, state.clipStartTime * clipDuration, clipTime);
32283
- }
32355
+ this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipEndTime * clipDuration);
32356
+ playState.currentTransitionIndex = 0;
32357
+ this._checkSubTransition(playState, transitions, layerIndex, state.clipStartTime * clipDuration, clipTime);
32284
32358
  } else {
32285
- targetTransition = this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32359
+ this._checkSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32286
32360
  }
32287
32361
  } else {
32288
32362
  if (clipTime > lastClipTime) {
32289
- targetTransition = this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipStartTime * clipDuration);
32290
- if (!targetTransition) {
32291
- playState.currentTransitionIndex = transitions.length - 1;
32292
- targetTransition = this._checkBackwardsSubTransition(playState, transitions, layerIndex, clipTime, state.clipEndTime * clipDuration);
32293
- }
32363
+ this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, state.clipStartTime * clipDuration);
32364
+ playState.currentTransitionIndex = transitions.length - 1;
32365
+ this._checkBackwardsSubTransition(playState, transitions, layerIndex, clipTime, state.clipEndTime * clipDuration);
32294
32366
  } else {
32295
- targetTransition = this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32296
- }
32297
- }
32298
- if (!targetTransition) {
32299
- for(var i = 0, n = anyStateTransitions.length; i < n; ++i){
32300
- var transition = anyStateTransitions[i];
32301
- if (this._checkConditions(state, transition)) {
32302
- this._crossFadeByTransition(transition, layerIndex);
32303
- break;
32304
- }
32367
+ this._checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, clipTime);
32305
32368
  }
32306
32369
  }
32307
32370
  };
32308
32371
  _proto._checkSubTransition = function _checkSubTransition(playState, transitions, layerIndex, lastClipTime, curClipTime) {
32309
- var state = playState.state;
32310
32372
  var transitionIndex = playState.currentTransitionIndex;
32311
- var duration = state._getDuration();
32373
+ var duration = playState.state._getDuration();
32312
32374
  for(var n = transitions.length; transitionIndex < n; transitionIndex++){
32313
32375
  var transition = transitions[transitionIndex];
32314
32376
  var exitTime = transition.exitTime * duration;
32315
32377
  if (exitTime > curClipTime) {
32316
32378
  break;
32317
32379
  }
32318
- if (exitTime >= lastClipTime && this._checkConditions(state, transition)) {
32380
+ if (exitTime >= lastClipTime) {
32381
+ this._crossFadeByTransition(transition, layerIndex);
32319
32382
  playState.currentTransitionIndex = Math.min(transitionIndex + 1, n - 1);
32320
- this._applyTransition(transition, layerIndex);
32321
- return transition;
32322
32383
  }
32323
32384
  }
32324
- return null;
32325
32385
  };
32326
32386
  _proto._checkBackwardsSubTransition = function _checkBackwardsSubTransition(playState, transitions, layerIndex, lastClipTime, curClipTime) {
32327
- var state = playState.state;
32328
32387
  var transitionIndex = playState.currentTransitionIndex;
32329
32388
  var duration = playState.state._getDuration();
32330
32389
  for(; transitionIndex >= 0; transitionIndex--){
@@ -32333,76 +32392,14 @@
32333
32392
  if (exitTime < curClipTime) {
32334
32393
  break;
32335
32394
  }
32336
- if (exitTime <= lastClipTime && this._checkConditions(state, transition)) {
32395
+ if (exitTime <= lastClipTime) {
32396
+ this._crossFadeByTransition(transition, layerIndex);
32337
32397
  playState.currentTransitionIndex = Math.max(transitionIndex - 1, 0);
32338
- this._applyTransition(transition, layerIndex);
32339
- return transition;
32340
32398
  }
32341
32399
  }
32342
- return null;
32343
- };
32344
- _proto._applyTransition = function _applyTransition(transition, layerIndex) {
32345
- if (transition.isExit) {
32346
- this._checkEntryState();
32347
- return;
32348
- }
32349
- this._crossFadeByTransition(transition, layerIndex);
32350
- };
32351
- _proto._checkConditions = function _checkConditions(state, transition) {
32352
- var mute = transition.mute, conditions = transition.conditions, solo = transition.solo;
32353
- if (mute) return false;
32354
- if (state && state._hasSoloTransition && !solo) return false;
32355
- var allPass = true;
32356
- for(var i = 0, n = conditions.length; i < n; ++i){
32357
- var pass = false;
32358
- var _conditions_i = conditions[i], mode = _conditions_i.mode, name1 = _conditions_i.parameter, threshold = _conditions_i.threshold;
32359
- var parameter = this.getParameter(name1);
32360
- switch(mode){
32361
- case exports.AnimatorConditionMode.Equals:
32362
- if (parameter.value === threshold) {
32363
- pass = true;
32364
- }
32365
- break;
32366
- case exports.AnimatorConditionMode.Greater:
32367
- if (parameter.value > threshold) {
32368
- pass = true;
32369
- }
32370
- break;
32371
- case exports.AnimatorConditionMode.Less:
32372
- if (parameter.value < threshold) {
32373
- pass = true;
32374
- }
32375
- break;
32376
- case exports.AnimatorConditionMode.NotEquals:
32377
- if (parameter.value !== threshold) {
32378
- pass = true;
32379
- }
32380
- break;
32381
- case exports.AnimatorConditionMode.If:
32382
- if (parameter.value === true) {
32383
- pass = true;
32384
- }
32385
- break;
32386
- case exports.AnimatorConditionMode.IfNot:
32387
- if (parameter.value === false) {
32388
- pass = true;
32389
- }
32390
- break;
32391
- }
32392
- if (!pass) {
32393
- allPass = false;
32394
- break;
32395
- }
32396
- }
32397
- return allPass;
32398
32400
  };
32399
32401
  _proto._crossFadeByTransition = function _crossFadeByTransition(transition, layerIndex) {
32400
- var _this__controllerUpdateFlag;
32401
32402
  var crossState = transition.destinationState;
32402
- if ((_this__controllerUpdateFlag = this._controllerUpdateFlag) == null ? void 0 : _this__controllerUpdateFlag.flag) {
32403
- this._reset();
32404
- }
32405
- this._playFrameCount = this.engine.time.frameCount;
32406
32403
  if (!crossState) {
32407
32404
  return false;
32408
32405
  }
@@ -32513,24 +32510,13 @@
32513
32510
  scripts[i].onStateExit(this, state, layerIndex);
32514
32511
  }
32515
32512
  };
32516
- _proto._checkEntryState = function _checkEntryState() {
32513
+ _proto._checkAutoPlay = function _checkAutoPlay() {
32517
32514
  var layers = this._animatorController.layers;
32518
32515
  for(var i = 0, n = layers.length; i < n; ++i){
32516
+ var _stateMachine;
32519
32517
  var stateMachine = layers[i].stateMachine;
32520
- if (!stateMachine) continue;
32521
- var entryTransitions = stateMachine._entryTransitions;
32522
- var length = entryTransitions.length;
32523
- if (length) {
32524
- for(var j = 0, m = length; j < m; j++){
32525
- var transition = entryTransitions[j];
32526
- if (this._checkConditions(null, transition)) {
32527
- this.crossFade(transition, i);
32528
- break;
32529
- }
32530
- }
32531
- } else {
32532
- var defaultState = stateMachine.defaultState;
32533
- defaultState && this.play(defaultState.name, i);
32518
+ if ((_stateMachine = stateMachine) == null ? void 0 : _stateMachine.defaultState) {
32519
+ this.play(stateMachine.defaultState.name, i);
32534
32520
  }
32535
32521
  }
32536
32522
  };
@@ -32556,22 +32542,6 @@
32556
32542
  this._animatorController = animatorController;
32557
32543
  }
32558
32544
  }
32559
- },
32560
- {
32561
- key: "layers",
32562
- get: /**
32563
- * The layers in the animator's controller.
32564
- */ function get() {
32565
- return this._animatorController._layers;
32566
- }
32567
- },
32568
- {
32569
- key: "parameters",
32570
- get: /**
32571
- * The parameters in the animator's controller.
32572
- */ function get() {
32573
- return this._animatorController._parameters;
32574
- }
32575
32545
  }
32576
32546
  ]);
32577
32547
  return Animator;
@@ -32600,44 +32570,15 @@
32600
32570
  __decorate$1([
32601
32571
  ignoreClone
32602
32572
  ], Animator.prototype, "_controlledRenderers", void 0);
32603
- /**
32604
- * Used to communicate between scripting and the controller, parameters can be set in scripting and used by the controller.
32605
- */ var AnimatorControllerParameter = function AnimatorControllerParameter() {};
32606
32573
  /**
32607
32574
  * Store the data for Animator playback.
32608
32575
  */ var AnimatorController = /*#__PURE__*/ function() {
32609
32576
  var AnimatorController = function AnimatorController() {
32610
- /** @internal */ this._parameters = [];
32611
- /** @internal */ this._parametersMap = {};
32612
- /** @internal */ this._layers = [];
32613
- /** @internal */ this._layersMap = {};
32614
32577
  this._updateFlagManager = new UpdateFlagManager();
32578
+ this._layers = [];
32579
+ this._layersMap = {};
32615
32580
  };
32616
32581
  var _proto = AnimatorController.prototype;
32617
- _proto.addParameter = function addParameter(param, defaultValue) {
32618
- if (typeof param === "string") {
32619
- var parameter = new AnimatorControllerParameter();
32620
- parameter.name = param;
32621
- parameter.value = defaultValue;
32622
- this._parametersMap[param] = parameter;
32623
- this._parameters.push(parameter);
32624
- return parameter;
32625
- } else {
32626
- this._parametersMap[param.name] = param;
32627
- this._parameters.push(param);
32628
- return param;
32629
- }
32630
- };
32631
- /**
32632
- * Remove a parameter from the controller.
32633
- * @param parameter - The parameter
32634
- */ _proto.removeParameter = function removeParameter(parameter) {
32635
- var index = this._parameters.indexOf(parameter);
32636
- if (index !== -1) {
32637
- this._parameters.splice(index, 1);
32638
- delete this._parametersMap[parameter.name];
32639
- }
32640
- };
32641
32582
  /**
32642
32583
  * Get the layer by name.
32643
32584
  * @param name - The layer's name.
@@ -32683,14 +32624,6 @@
32683
32624
  */ function get() {
32684
32625
  return this._layers;
32685
32626
  }
32686
- },
32687
- {
32688
- key: "parameters",
32689
- get: /**
32690
- * The parameters in the controller.
32691
- */ function get() {
32692
- return this._parameters;
32693
- }
32694
32627
  }
32695
32628
  ]);
32696
32629
  return AnimatorController;
@@ -32749,22 +32682,16 @@
32749
32682
  this./** @internal */ _onStateUpdateScripts = [];
32750
32683
  this./** @internal */ _onStateExitScripts = [];
32751
32684
  this./** @internal */ _updateFlagManager = new UpdateFlagManager();
32752
- this./** @internal */ _hasSoloTransition = false;
32753
32685
  this._clipStartTime = 0;
32754
32686
  this._clipEndTime = 1;
32755
32687
  this._transitions = [];
32756
32688
  this._onClipChanged = this._onClipChanged.bind(this);
32757
32689
  };
32758
32690
  var _proto = AnimatorState.prototype;
32759
- _proto.addTransition = function addTransition(transitionOrAnimatorState) {
32760
- var transition;
32761
- if (_instanceof1$2(transitionOrAnimatorState, AnimatorState)) {
32762
- transition = new AnimatorStateTransition();
32763
- transition.destinationState = transitionOrAnimatorState;
32764
- } else {
32765
- transition = transitionOrAnimatorState;
32766
- }
32767
- transition._srcState = this;
32691
+ /**
32692
+ * Add an outgoing transition to the destination state.
32693
+ * @param transition - The transition
32694
+ */ _proto.addTransition = function addTransition(transition) {
32768
32695
  var transitions = this._transitions;
32769
32696
  var count = transitions.length;
32770
32697
  var time = transition.exitTime;
@@ -32776,10 +32703,6 @@
32776
32703
  while(--index >= 0 && time < transitions[index].exitTime);
32777
32704
  transitions.splice(index + 1, 0, transition);
32778
32705
  }
32779
- if (transition.solo) {
32780
- !this._hasSoloTransition && this._updateSoloTransition(true);
32781
- }
32782
- return transition;
32783
32706
  };
32784
32707
  /**
32785
32708
  * Remove a transition from the state.
@@ -32787,7 +32710,6 @@
32787
32710
  */ _proto.removeTransition = function removeTransition(transition) {
32788
32711
  var index = this._transitions.indexOf(transition);
32789
32712
  index !== -1 && this._transitions.splice(index, 1);
32790
- this._updateSoloTransition();
32791
32713
  };
32792
32714
  /**
32793
32715
  * Adds a state machine script class of type T to the AnimatorState.
@@ -32842,21 +32764,6 @@
32842
32764
  */ _proto._onClipChanged = function _onClipChanged() {
32843
32765
  this._updateFlagManager.dispatch();
32844
32766
  };
32845
- /**
32846
- * @internal
32847
- */ _proto._updateSoloTransition = function _updateSoloTransition(hasSolo) {
32848
- if (hasSolo !== undefined) {
32849
- this._hasSoloTransition = hasSolo;
32850
- } else {
32851
- this._hasSoloTransition = false;
32852
- for(var i = 0, n = this.transitions.length; i < n; ++i){
32853
- if (this.transitions[i].solo) {
32854
- this._hasSoloTransition = true;
32855
- return;
32856
- }
32857
- }
32858
- }
32859
- };
32860
32767
  _create_class$2(AnimatorState, [
32861
32768
  {
32862
32769
  key: "transitions",
@@ -32887,26 +32794,10 @@
32887
32794
  clip && clip._updateFlagManager.addListener(this._onClipChanged);
32888
32795
  }
32889
32796
  },
32890
- {
32891
- key: "startTime",
32892
- get: /**
32893
- * The start time of this state's clip
32894
- */ function get() {
32895
- return this._clip.length * this._clipStartTime;
32896
- }
32897
- },
32898
- {
32899
- key: "endTime",
32900
- get: /**
32901
- * The end time of this state's clip
32902
- */ function get() {
32903
- return this._clip.length * this._clipEndTime;
32904
- }
32905
- },
32906
32797
  {
32907
32798
  key: "clipStartTime",
32908
32799
  get: /**
32909
- * The normalized start time of the clip, the range is 0 to 1, default is 0.
32800
+ * The start time of the clip, the range is 0 to 1, default is 0.
32910
32801
  */ function get() {
32911
32802
  return this._clipStartTime;
32912
32803
  },
@@ -32917,7 +32808,7 @@
32917
32808
  {
32918
32809
  key: "clipEndTime",
32919
32810
  get: /**
32920
- * The normalized end time of the clip, the range is 0 to 1, default is 1.
32811
+ * The end time of the clip, the range is 0 to 1, default is 1.
32921
32812
  */ function get() {
32922
32813
  return this._clipEndTime;
32923
32814
  },
@@ -32933,8 +32824,6 @@
32933
32824
  */ var AnimatorStateMachine = /*#__PURE__*/ function() {
32934
32825
  var AnimatorStateMachine = function AnimatorStateMachine() {
32935
32826
  /** The list of states. */ this.states = [];
32936
- /** @internal */ this._entryTransitions = [];
32937
- /** @internal */ this._anyStateTransitions = [];
32938
32827
  /** @internal */ this._statesMap = {};
32939
32828
  };
32940
32829
  var _proto = AnimatorStateMachine.prototype;
@@ -32983,62 +32872,17 @@
32983
32872
  }
32984
32873
  return name1;
32985
32874
  };
32986
- _proto.addEntryStateTransition = function addEntryStateTransition(transitionOrAnimatorState) {
32987
- var transition;
32988
- if (_instanceof1$2(transitionOrAnimatorState, AnimatorState)) {
32989
- transition = new AnimatorStateTransition();
32990
- transition.destinationState = transitionOrAnimatorState;
32991
- } else {
32992
- transition = transitionOrAnimatorState;
32993
- }
32994
- this._entryTransitions.push(transition);
32995
- return transition;
32996
- };
32997
- /**
32998
- * Remove an entry transition.
32999
- * @param transition - The transition
33000
- */ _proto.removeEntryStateTransition = function removeEntryStateTransition(transition) {
33001
- var index = this._entryTransitions.indexOf(transition);
33002
- index !== -1 && this._entryTransitions.splice(index, 1);
33003
- };
33004
- _proto.addAnyStateTransition = function addAnyStateTransition(transitionOrAnimatorState) {
33005
- var transition;
33006
- if (_instanceof1$2(transitionOrAnimatorState, AnimatorState)) {
33007
- transition = new AnimatorStateTransition();
33008
- transition.destinationState = transitionOrAnimatorState;
33009
- } else {
33010
- transition = transitionOrAnimatorState;
33011
- }
33012
- this._anyStateTransitions.push(transition);
33013
- return transition;
33014
- };
33015
- /**
33016
- * Remove an any transition.
33017
- * @param transition - The transition
33018
- */ _proto.removeAnyStateTransition = function removeAnyStateTransition(transition) {
33019
- var index = this._anyStateTransitions.indexOf(transition);
33020
- index !== -1 && this._anyStateTransitions.splice(index, 1);
33021
- };
33022
- _create_class$2(AnimatorStateMachine, [
33023
- {
33024
- key: "entryTransitions",
33025
- get: /**
33026
- * The list of entry transitions in the state machine.
33027
- */ function get() {
33028
- return this._entryTransitions;
33029
- }
33030
- },
33031
- {
33032
- key: "anyStateTransitions",
33033
- get: /**
33034
- * The list of AnyState transitions.
33035
- */ function get() {
33036
- return this._anyStateTransitions;
33037
- }
33038
- }
33039
- ]);
33040
32875
  return AnimatorStateMachine;
33041
32876
  }();
32877
+ exports.AnimatorConditionMode = void 0;
32878
+ (function(AnimatorConditionMode) {
32879
+ AnimatorConditionMode[AnimatorConditionMode["If"] = 0] = "If";
32880
+ AnimatorConditionMode[AnimatorConditionMode["IfNot"] = 1] = "IfNot";
32881
+ AnimatorConditionMode[AnimatorConditionMode["Greater"] = 2] = "Greater";
32882
+ AnimatorConditionMode[AnimatorConditionMode["Less"] = 3] = "Less";
32883
+ AnimatorConditionMode[AnimatorConditionMode["Equals"] = 4] = "Equals";
32884
+ AnimatorConditionMode[AnimatorConditionMode["NotEquals"] = 5] = "NotEquals";
32885
+ })(exports.AnimatorConditionMode || (exports.AnimatorConditionMode = {}));
33042
32886
  /**
33043
32887
  * Keyframe.
33044
32888
  * @typeParam V - Type of Keyframe value
@@ -40654,15 +40498,15 @@
40654
40498
  for(var i = 0, length = item.length; i < length; i++){
40655
40499
  var mesh = item[i];
40656
40500
  // @ts-ignore
40657
- _this.resourceManager._onSubAssetSuccess(url + "?q=" + glTFResourceKey + "[" + index + "][" + i + "]", mesh);
40501
+ _this.resourceManager._onSubAssetSuccess(url, glTFResourceKey + "[" + index + "][" + i + "]", mesh);
40658
40502
  }
40659
40503
  } else {
40660
40504
  // @ts-ignore
40661
- _this.resourceManager._onSubAssetSuccess(url + "?q=" + glTFResourceKey + "[" + index + "]", item);
40505
+ _this.resourceManager._onSubAssetSuccess(url, "" + glTFResourceKey + (index === undefined ? "" : "[" + index + "]"), item);
40662
40506
  var _this_glTF_scene;
40663
40507
  if (type === 2 && ((_this_glTF_scene = _this.glTF.scene) != null ? _this_glTF_scene : 0) === index) {
40664
40508
  // @ts-ignore
40665
- _this.resourceManager._onSubAssetSuccess("" + url + "?q=defaultSceneRoot", item);
40509
+ _this.resourceManager._onSubAssetSuccess(url, "defaultSceneRoot", item);
40666
40510
  }
40667
40511
  }
40668
40512
  });
@@ -43083,7 +42927,7 @@
43083
42927
  var sceneExtensions = sceneInfo.extensions;
43084
42928
  var engine = glTFResource.engine;
43085
42929
  var isDefaultScene = scene === index;
43086
- var sceneNodes = sceneInfo.nodes;
42930
+ var sceneNodes = sceneInfo.nodes || [];
43087
42931
  var sceneRoot;
43088
42932
  if (sceneNodes.length === 1) {
43089
42933
  sceneRoot = context.get(exports.GLTFParserType.Entity, sceneNodes[0]);
@@ -43165,25 +43009,32 @@
43165
43009
  camera.enabled = false;
43166
43010
  };
43167
43011
  _proto._createRenderer = function _createRenderer(context, entityInfo, entity) {
43168
- var _loop = function _loop(i) {
43169
- var glTFPrimitive = glTFMeshPrimitives[i];
43170
- var materialIndex = glTFPrimitive.material;
43171
- promises.push(Promise.all([
43172
- context.get(exports.GLTFParserType.Mesh, meshID),
43173
- skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
43174
- materialIndex !== undefined && context.get(exports.GLTFParserType.Material, materialIndex)
43175
- ]).then(function(param) {
43176
- var meshes = param[0], skin = param[1], material = param[2];
43012
+ var _this = this;
43013
+ var meshID = entityInfo.mesh, skinID = entityInfo.skin;
43014
+ var glTFMesh = context.glTF.meshes[meshID];
43015
+ var glTFMeshPrimitives = glTFMesh.primitives;
43016
+ var rendererCount = glTFMeshPrimitives.length;
43017
+ var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
43018
+ var materialPromises = new Array(rendererCount);
43019
+ for(var i = 0; i < rendererCount; i++){
43020
+ var _glTFMeshPrimitives_i_material;
43021
+ materialPromises[i] = context.get(exports.GLTFParserType.Material, (_glTFMeshPrimitives_i_material = glTFMeshPrimitives[i].material) != null ? _glTFMeshPrimitives_i_material : -1);
43022
+ }
43023
+ return Promise.all([
43024
+ context.get(exports.GLTFParserType.Mesh, meshID),
43025
+ skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
43026
+ Promise.all(materialPromises)
43027
+ ]).then(function(param) {
43028
+ var _loop = function _loop(i) {
43029
+ var material = materials[i] || exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine);
43030
+ var glTFPrimitive = glTFMeshPrimitives[i];
43177
43031
  var mesh = meshes[i];
43178
- var renderer;
43179
- material || (material = exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
43032
+ var renderer = void 0;
43180
43033
  if (skin || blendShapeWeights) {
43181
43034
  var skinRenderer = entity.addComponent(SkinnedMeshRenderer);
43182
43035
  skinRenderer.mesh = mesh;
43183
43036
  if (skin) {
43184
- skinRenderer.rootBone = skin._rootBone;
43185
- skinRenderer.bones = skin._bones;
43186
- _this._computeLocalBounds(skinRenderer, mesh, skin._bones, skin._rootBone, skin.inverseBindMatrices);
43037
+ _this._computeLocalBounds(skinRenderer, mesh, skin.bones, skin.rootBone, skin.inverseBindMatrices);
43187
43038
  skinRenderer.skin = skin;
43188
43039
  }
43189
43040
  if (blendShapeWeights) {
@@ -43202,17 +43053,10 @@
43202
43053
  }
43203
43054
  });
43204
43055
  GLTFParser.executeExtensionsAdditiveAndParse(glTFPrimitive.extensions, context, renderer, glTFPrimitive);
43205
- }));
43206
- };
43207
- var _this = this;
43208
- var glTFMeshes = context.glTF.meshes;
43209
- var meshID = entityInfo.mesh, skinID = entityInfo.skin;
43210
- var glTFMesh = glTFMeshes[meshID];
43211
- var glTFMeshPrimitives = glTFMesh.primitives;
43212
- var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
43213
- var promises = new Array();
43214
- for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
43215
- return Promise.all(promises);
43056
+ };
43057
+ var meshes = param[0], skin = param[1], materials = param[2];
43058
+ for(var i = 0; i < rendererCount; i++)_loop(i);
43059
+ });
43216
43060
  };
43217
43061
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
43218
43062
  var rootBoneIndex = bones.indexOf(rootBone);
@@ -43265,7 +43109,7 @@
43265
43109
  var jointCount = joints.length;
43266
43110
  var skin = new Skin(name);
43267
43111
  skin.inverseBindMatrices.length = jointCount;
43268
- skin._bones.length = jointCount;
43112
+ var bones = new Array(jointCount);
43269
43113
  // parse IBM
43270
43114
  var accessor = glTF.accessors[inverseBindMatrices];
43271
43115
  var skinPromise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
@@ -43277,21 +43121,20 @@
43277
43121
  skin.inverseBindMatrices[i] = inverseBindMatrix;
43278
43122
  // Get bones
43279
43123
  var bone = entities[joints[i]];
43280
- skin._bones[i] = bone;
43124
+ bones[i] = bone;
43281
43125
  skin.joints[i] = bone.name;
43282
- // Get skeleton
43283
- if (skeleton !== undefined) {
43284
- var rootBone = entities[skeleton];
43285
- skin._rootBone = rootBone;
43286
- skin.skeleton = rootBone.name;
43126
+ }
43127
+ skin.bones = bones;
43128
+ // Get skeleton
43129
+ if (skeleton !== undefined) {
43130
+ var rootBone = entities[skeleton];
43131
+ skin.rootBone = rootBone;
43132
+ } else {
43133
+ var rootBone1 = _this._findSkeletonRootBone(joints, entities);
43134
+ if (rootBone1) {
43135
+ skin.rootBone = rootBone1;
43287
43136
  } else {
43288
- var rootBone1 = _this._findSkeletonRootBone(joints, entities);
43289
- if (rootBone1) {
43290
- skin._rootBone = rootBone1;
43291
- skin.skeleton = rootBone1.name;
43292
- } else {
43293
- throw "Failed to find skeleton root bone.";
43294
- }
43137
+ throw "Failed to find skeleton root bone.";
43295
43138
  }
43296
43139
  }
43297
43140
  return skin;
@@ -44906,6 +44749,8 @@
44906
44749
  scene.background.texture = texture;
44907
44750
  });
44908
44751
  promises.push(backgroundPromise);
44752
+ var _background_textureFillMode;
44753
+ scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
44909
44754
  }
44910
44755
  break;
44911
44756
  }
@@ -45320,7 +45165,7 @@
45320
45165
  ], KHR_materials_anisotropy);
45321
45166
 
45322
45167
  //@ts-ignore
45323
- var version = "0.0.0-experimental-stateMachine.0";
45168
+ var version = "0.0.0-experimental-1.2-xr.0";
45324
45169
  console.log("Galacean engine version: " + version);
45325
45170
  for(var key in CoreObjects){
45326
45171
  Loader.registerClass(key, CoreObjects[key]);