@galacean/engine 1.2.0-beta.4 → 1.2.0-beta.6

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;
@@ -15764,266 +15785,735 @@
15764
15785
  PrimitiveMesh._spherePoleIdx = 0;
15765
15786
  })();
15766
15787
  /**
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;
15788
+ * Layer, used for bit operations.
15789
+ */ exports.Layer = void 0;
15790
+ (function(Layer) {
15791
+ Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
15792
+ Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
15793
+ Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
15794
+ Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
15795
+ Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
15796
+ Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
15797
+ Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
15798
+ Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
15799
+ Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
15800
+ Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
15801
+ Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
15802
+ Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
15803
+ Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
15804
+ Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
15805
+ Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
15806
+ Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
15807
+ Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
15808
+ Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
15809
+ Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
15810
+ Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
15811
+ Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
15812
+ Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
15813
+ Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
15814
+ Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
15815
+ Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
15816
+ Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
15817
+ Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
15818
+ Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
15819
+ Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
15820
+ Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
15821
+ Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
15822
+ Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
15823
+ Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
15824
+ Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
15825
+ })(exports.Layer || (exports.Layer = {}));
15826
+ var ComponentCloner = /*#__PURE__*/ function() {
15827
+ var ComponentCloner = function ComponentCloner() {};
15828
+ /**
15829
+ * Clone component.
15830
+ * @param source - Clone source
15831
+ * @param target - Clone target
15832
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
15833
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
15834
+ for(var k in source){
15835
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
15836
+ }
15837
+ if (source._cloneTo) {
15838
+ source._cloneTo(target, srcRoot, targetRoot);
15839
+ }
15778
15840
  };
15779
- _inherits$2(Skin, EngineObject1);
15780
- return Skin;
15781
- }(EngineObject);
15841
+ return ComponentCloner;
15842
+ }();
15782
15843
  /**
15783
- * SkinnedMeshRenderer.
15784
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
15785
- var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
15844
+ * Entity, be used as components container.
15845
+ */ var Entity = /*#__PURE__*/ function(EngineObject1) {
15846
+ var Entity = function Entity(engine, name1) {
15786
15847
  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;
15848
+ _this = EngineObject1.call(this, engine) || this;
15849
+ /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
15850
+ /** @internal */ _this._isActiveInHierarchy = false;
15851
+ /** @internal */ _this._isActiveInScene = false;
15852
+ /** @internal */ _this._components = [];
15853
+ /** @internal */ _this._scripts = new DisorderedArray();
15854
+ /** @internal */ _this._children = [];
15855
+ /** @internal */ _this._isRoot = false;
15856
+ /** @internal */ _this._isActive = true;
15857
+ /** @internal */ _this._siblingIndex = -1;
15858
+ /** @internal */ _this._isTemplate = false;
15859
+ _this._parent = null;
15860
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
15861
+ _this._invModelMatrix = new Matrix();
15862
+ _this.name = name1;
15863
+ _this.transform = _this.addComponent(Transform);
15864
+ _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
15804
15865
  return _this;
15805
15866
  };
15806
- _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
15807
- var _proto = SkinnedMeshRenderer.prototype;
15867
+ _inherits$2(Entity, EngineObject1);
15868
+ var _proto = Entity.prototype;
15808
15869
  /**
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);
15870
+ * Add component based on the component type.
15871
+ * @param type - The type of the component
15872
+ * @returns The component which has been added
15873
+ */ _proto.addComponent = function addComponent(type) {
15874
+ ComponentsDependencies._addCheck(this, type);
15875
+ var component = new type(this);
15876
+ this._components.push(component);
15877
+ component._setActive(true, ActiveChangeFlag.All);
15878
+ return component;
15879
+ };
15880
+ /**
15881
+ * Get component which match the type.
15882
+ * @param type - The type of the component
15883
+ * @returns The first component which match type
15884
+ */ _proto.getComponent = function getComponent(type) {
15885
+ var components = this._components;
15886
+ for(var i = 0, n = components.length; i < n; i++){
15887
+ var component = components[i];
15888
+ if (_instanceof1$2(component, type)) {
15889
+ return component;
15827
15890
  }
15828
15891
  }
15892
+ return null;
15829
15893
  };
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;
15894
+ /**
15895
+ * Get components which match the type.
15896
+ * @param type - The type of the component
15897
+ * @param results - The components which match type
15898
+ * @returns The components which match type
15899
+ */ _proto.getComponents = function getComponents(type, results) {
15900
+ results.length = 0;
15901
+ var components = this._components;
15902
+ for(var i = 0, n = components.length; i < n; i++){
15903
+ var component = components[i];
15904
+ if (_instanceof1$2(component, type)) {
15905
+ results.push(component);
15906
+ }
15837
15907
  }
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
- }
15908
+ return results;
15909
+ };
15910
+ /**
15911
+ * Get the components which match the type of the entity and it's children.
15912
+ * @param type - The component type
15913
+ * @param results - The components collection
15914
+ * @returns The components collection which match the type
15915
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
15916
+ results.length = 0;
15917
+ this._getComponentsInChildren(type, results);
15918
+ return results;
15919
+ };
15920
+ _proto.addChild = function addChild(indexOrChild, child) {
15921
+ var index;
15922
+ if (typeof indexOrChild === "number") {
15923
+ index = indexOrChild;
15924
+ } else {
15925
+ index = undefined;
15926
+ child = indexOrChild;
15927
+ }
15928
+ if (child._isRoot) {
15929
+ child._scene._removeFromEntityList(child);
15930
+ child._isRoot = false;
15931
+ this._addToChildrenList(index, child);
15932
+ child._parent = this;
15933
+ var oldScene = child._scene;
15934
+ var newScene = this._scene;
15935
+ var inActiveChangeFlag = ActiveChangeFlag.None;
15936
+ if (!this._isActiveInHierarchy) {
15937
+ child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
15938
+ }
15939
+ if (child._isActiveInScene) {
15940
+ if (this._isActiveInScene) {
15941
+ // Cross scene should inActive first and then active
15942
+ oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
15869
15943
  } 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);
15944
+ inActiveChangeFlag |= ActiveChangeFlag.Scene;
15875
15945
  }
15876
- jointDataCreateCache.set(jointCount, bsUniformOccupiesCount);
15877
15946
  }
15878
- if (this._jointTexture) {
15879
- this._jointTexture.setPixelBuffer(this._jointMatrices);
15947
+ inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
15948
+ if (child._scene !== newScene) {
15949
+ Entity._traverseSetOwnerScene(child, newScene);
15950
+ }
15951
+ var activeChangeFlag = ActiveChangeFlag.None;
15952
+ if (child._isActive) {
15953
+ if (this._isActiveInHierarchy) {
15954
+ !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15955
+ }
15956
+ if (this._isActiveInScene) {
15957
+ (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
15958
+ }
15880
15959
  }
15960
+ activeChangeFlag && child._processActive(activeChangeFlag);
15961
+ child._setTransformDirty();
15962
+ } else {
15963
+ child._setParent(this, index);
15881
15964
  }
15882
- var layer = entity.layer;
15883
- this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
15884
15965
  };
15885
15966
  /**
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;
15967
+ * Remove child entity.
15968
+ * @param child - The child entity which want to be removed
15969
+ */ _proto.removeChild = function removeChild(child) {
15970
+ child._setParent(null);
15899
15971
  };
15900
15972
  /**
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;
15973
+ * @deprecated Please use `children` property instead.
15974
+ * Find child entity by index.
15975
+ * @param index - The index of the child entity
15976
+ * @returns The component which be found
15977
+ */ _proto.getChild = function getChild(index) {
15978
+ return this._children[index];
15979
+ };
15980
+ /**
15981
+ * Find entity by name.
15982
+ * @param name - The name of the entity which want to be found
15983
+ * @returns The component which be found
15984
+ */ _proto.findByName = function findByName(name1) {
15985
+ if (name1 === this.name) {
15986
+ return this;
15909
15987
  }
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;
15988
+ var children = this._children;
15989
+ for(var i = 0, n = children.length; i < n; i++){
15990
+ var target = children[i].findByName(name1);
15991
+ if (target) {
15992
+ return target;
15919
15993
  }
15920
- target.bones = destBones;
15921
15994
  }
15922
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
15995
+ return null;
15923
15996
  };
15924
15997
  /**
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);
15998
+ * Find the entity by path.
15999
+ * @param path - The path fo the entity eg: /entity
16000
+ * @returns The component which be found
16001
+ */ _proto.findByPath = function findByPath(path) {
16002
+ var splits = path.split("/");
16003
+ var entity = this;
16004
+ for(var i = 0, length = splits.length; i < length; ++i){
16005
+ var split = splits[i];
16006
+ if (split) {
16007
+ entity = Entity._findChildByName(entity, split);
16008
+ if (!entity) {
16009
+ return null;
16010
+ }
16011
+ }
16012
+ }
16013
+ return entity;
15929
16014
  };
15930
16015
  /**
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);
16016
+ * Create child entity.
16017
+ * @param name - The child entity's name
16018
+ * @returns The child entity
16019
+ */ _proto.createChild = function createChild(name1) {
16020
+ var child = new Entity(this.engine, name1);
16021
+ child.layer = this.layer;
16022
+ child.parent = this;
16023
+ return child;
16024
+ };
16025
+ /**
16026
+ * Clear children entities.
16027
+ */ _proto.clearChildren = function clearChildren() {
16028
+ var children = this._children;
16029
+ for(var i = children.length - 1; i >= 0; i--){
16030
+ var child = children[i];
16031
+ child._parent = null;
16032
+ var activeChangeFlag = ActiveChangeFlag.None;
16033
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16034
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
16035
+ activeChangeFlag && child._processInActive(activeChangeFlag);
16036
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
16037
+ }
16038
+ children.length = 0;
16039
+ };
16040
+ /**
16041
+ * Clone this entity include children and components.
16042
+ * @returns Cloned entity
16043
+ */ _proto.clone = function clone() {
16044
+ var cloneEntity = this._createCloneEntity(this);
16045
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
16046
+ return cloneEntity;
15935
16047
  };
15936
16048
  /**
15937
16049
  * @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);
16050
+ */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
16051
+ this._isTemplate = true;
16052
+ this._templateResource = templateResource;
16053
+ };
16054
+ _proto._createCloneEntity = function _createCloneEntity(srcEntity) {
16055
+ var cloneEntity = new Entity(srcEntity._engine, srcEntity.name);
16056
+ var templateResource = this._templateResource;
16057
+ if (templateResource) {
16058
+ cloneEntity._templateResource = templateResource;
16059
+ templateResource._addReferCount(1);
16060
+ }
16061
+ cloneEntity.layer = srcEntity.layer;
16062
+ cloneEntity._isActive = srcEntity._isActive;
16063
+ var cloneTransform = cloneEntity.transform;
16064
+ var srcTransform = srcEntity.transform;
16065
+ cloneTransform.position = srcTransform.position;
16066
+ cloneTransform.rotation = srcTransform.rotation;
16067
+ cloneTransform.scale = srcTransform.scale;
16068
+ var children = srcEntity._children;
16069
+ for(var i = 0, n = srcEntity._children.length; i < n; i++){
16070
+ cloneEntity.addChild(this._createCloneEntity(children[i]));
15945
16071
  }
16072
+ return cloneEntity;
15946
16073
  };
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;
16074
+ _proto._parseCloneEntity = function _parseCloneEntity(src, target, srcRoot, targetRoot, deepInstanceMap) {
16075
+ var srcChildren = src._children;
16076
+ var targetChildren = target._children;
16077
+ for(var i = 0, n = srcChildren.length; i < n; i++){
16078
+ this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot, deepInstanceMap);
16079
+ }
16080
+ var components = src._components;
16081
+ for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
16082
+ var sourceComp = components[i1];
16083
+ if (!_instanceof1$2(sourceComp, Transform)) {
16084
+ var targetComp = target.addComponent(sourceComp.constructor);
16085
+ ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot, deepInstanceMap);
15963
16086
  }
16087
+ }
16088
+ };
16089
+ /**
16090
+ * Destroy self.
16091
+ */ _proto.destroy = function destroy() {
16092
+ if (this._destroyed) {
16093
+ return;
16094
+ }
16095
+ EngineObject1.prototype.destroy.call(this);
16096
+ if (this._templateResource) {
16097
+ this._isTemplate || this._templateResource._addReferCount(-1);
16098
+ this._templateResource = null;
16099
+ }
16100
+ var components = this._components;
16101
+ for(var i = components.length - 1; i >= 0; i--){
16102
+ components[i].destroy();
16103
+ }
16104
+ this._components.length = 0;
16105
+ var children = this._children;
16106
+ while(children.length > 0){
16107
+ children[0].destroy();
16108
+ }
16109
+ if (this._isRoot) {
16110
+ this._scene.removeRootEntity(this);
15964
16111
  } else {
15965
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16112
+ this._setParent(null);
15966
16113
  }
16114
+ this.isActive = false;
15967
16115
  };
15968
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
15969
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16116
+ /**
16117
+ * @internal
16118
+ */ _proto._removeComponent = function _removeComponent(component) {
16119
+ ComponentsDependencies._removeCheck(this, component.constructor);
16120
+ var components = this._components;
16121
+ components.splice(components.indexOf(component), 1);
15970
16122
  };
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;
16123
+ /**
16124
+ * @internal
16125
+ */ _proto._addScript = function _addScript(script) {
16126
+ script._entityScriptsIndex = this._scripts.length;
16127
+ this._scripts.add(script);
16128
+ };
16129
+ /**
16130
+ * @internal
16131
+ */ _proto._removeScript = function _removeScript(script) {
16132
+ var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
16133
+ replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
16134
+ script._entityScriptsIndex = -1;
16135
+ };
16136
+ /**
16137
+ * @internal
16138
+ */ _proto._removeFromParent = function _removeFromParent() {
16139
+ var oldParent = this._parent;
16140
+ if (oldParent != null) {
16141
+ var oldSibling = oldParent._children;
16142
+ var index = this._siblingIndex;
16143
+ oldSibling.splice(index, 1);
16144
+ for(var n = oldSibling.length; index < n; index++){
16145
+ oldSibling[index]._siblingIndex--;
15977
16146
  }
15978
- inversePath.push(searchEntity.siblingIndex);
15979
- searchEntity = parent;
16147
+ this._parent = null;
16148
+ this._siblingIndex = -1;
15980
16149
  }
15981
- return true;
15982
16150
  };
15983
16151
  /**
15984
16152
  * @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]];
16153
+ */ _proto._processActive = function _processActive(activeChangeFlag) {
16154
+ if (this._activeChangedComponents) {
16155
+ 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
16156
  }
15990
- return entity;
16157
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16158
+ this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16159
+ this._setActiveComponents(true, activeChangeFlag);
15991
16160
  };
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
- }
16161
+ /**
16162
+ * @internal
16163
+ */ _proto._processInActive = function _processInActive(activeChangeFlag) {
16164
+ if (this._activeChangedComponents) {
16165
+ 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.";
16166
+ }
16167
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16168
+ this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16169
+ this._setActiveComponents(false, activeChangeFlag);
16170
+ };
16171
+ _proto._addToChildrenList = function _addToChildrenList(index, child) {
16172
+ var children = this._children;
16173
+ var childCount = children.length;
16174
+ if (index === undefined) {
16175
+ child._siblingIndex = childCount;
16176
+ children.push(child);
16177
+ } else {
16178
+ if (index < 0 || index > childCount) {
16179
+ throw "The index " + index + " is out of child list bounds " + childCount;
16012
16180
  }
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);
16181
+ child._siblingIndex = index;
16182
+ children.splice(index, 0, child);
16183
+ for(var i = index + 1, n = childCount + 1; i < n; i++){
16184
+ children[i]._siblingIndex++;
16185
+ }
16186
+ }
16187
+ };
16188
+ _proto._setParent = function _setParent(parent, siblingIndex) {
16189
+ var oldParent = this._parent;
16190
+ if (parent !== oldParent) {
16191
+ this._removeFromParent();
16192
+ this._parent = parent;
16193
+ if (parent) {
16194
+ parent._addToChildrenList(siblingIndex, this);
16195
+ var oldScene = this._scene;
16196
+ var parentScene = parent._scene;
16197
+ var inActiveChangeFlag = ActiveChangeFlag.None;
16198
+ if (!parent._isActiveInHierarchy) {
16199
+ this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
16200
+ }
16201
+ if (parent._isActiveInScene) {
16202
+ // cross scene should inActive first and then active
16203
+ this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16204
+ } else {
16205
+ this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16206
+ }
16207
+ inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
16208
+ if (oldScene !== parentScene) {
16209
+ Entity._traverseSetOwnerScene(this, parentScene);
16210
+ }
16211
+ var activeChangeFlag = ActiveChangeFlag.None;
16212
+ if (this._isActive) {
16213
+ if (parent._isActiveInHierarchy) {
16214
+ !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16215
+ }
16216
+ if (parent._isActiveInScene) {
16217
+ (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16218
+ }
16219
+ }
16220
+ activeChangeFlag && this._processActive(activeChangeFlag);
16221
+ } else {
16222
+ var inActiveChangeFlag1 = ActiveChangeFlag.None;
16223
+ this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16224
+ this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
16225
+ inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
16226
+ if (oldParent) {
16227
+ Entity._traverseSetOwnerScene(this, null);
16228
+ }
16229
+ }
16230
+ this._setTransformDirty();
16231
+ }
16232
+ };
16233
+ _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
16234
+ for(var i = this._components.length - 1; i >= 0; i--){
16235
+ var component = this._components[i];
16236
+ if (_instanceof1$2(component, type)) {
16237
+ results.push(component);
16238
+ }
16239
+ }
16240
+ for(var i1 = this._children.length - 1; i1 >= 0; i1--){
16241
+ this._children[i1]._getComponentsInChildren(type, results);
16242
+ }
16243
+ };
16244
+ _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
16245
+ var activeChangedComponents = this._activeChangedComponents;
16246
+ for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
16247
+ activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
16248
+ }
16249
+ this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
16250
+ this._activeChangedComponents = null;
16251
+ };
16252
+ _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16253
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
16254
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
16255
+ var components = this._components;
16256
+ for(var i = 0, n = components.length; i < n; i++){
16257
+ var component = components[i];
16258
+ (component.enabled || !component._awoken) && activeChangedComponents.push(component);
16259
+ }
16260
+ var children = this._children;
16261
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16262
+ var child = children[i1];
16263
+ child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16264
+ }
16265
+ };
16266
+ _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16267
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
16268
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
16269
+ var components = this._components;
16270
+ for(var i = 0, n = components.length; i < n; i++){
16271
+ var component = components[i];
16272
+ component.enabled && activeChangedComponents.push(component);
16273
+ }
16274
+ var children = this._children;
16275
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16276
+ var child = children[i1];
16277
+ child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16278
+ }
16279
+ };
16280
+ _proto._setTransformDirty = function _setTransformDirty() {
16281
+ if (this.transform) {
16282
+ this.transform._parentChange();
16283
+ } else {
16284
+ for(var i = 0, len = this._children.length; i < len; i++){
16285
+ this._children[i]._setTransformDirty();
16286
+ }
16287
+ }
16288
+ };
16289
+ _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
16290
+ target = Math.min(target, sibling.length - 1);
16291
+ if (target < 0) {
16292
+ throw "Sibling index " + target + " should large than 0";
16293
+ }
16294
+ if (this._siblingIndex !== target) {
16295
+ var oldIndex = this._siblingIndex;
16296
+ if (target < oldIndex) {
16297
+ for(var i = oldIndex; i >= target; i--){
16298
+ var child = i == target ? this : sibling[i - 1];
16299
+ sibling[i] = child;
16300
+ child._siblingIndex = i;
16301
+ }
16302
+ } else {
16303
+ for(var i1 = oldIndex; i1 <= target; i1++){
16304
+ var child1 = i1 == target ? this : sibling[i1 + 1];
16305
+ sibling[i1] = child1;
16306
+ child1._siblingIndex = i1;
16307
+ }
16308
+ }
16309
+ }
16310
+ };
16311
+ /**
16312
+ * @deprecated
16313
+ */ _proto.getInvModelMatrix = function getInvModelMatrix() {
16314
+ if (this._inverseWorldMatFlag.flag) {
16315
+ Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
16316
+ this._inverseWorldMatFlag.flag = false;
16317
+ }
16318
+ return this._invModelMatrix;
16319
+ };
16320
+ /**
16321
+ * @internal
16322
+ */ Entity._findChildByName = function _findChildByName(root, name1) {
16323
+ var children = root._children;
16324
+ for(var i = children.length - 1; i >= 0; i--){
16325
+ var child = children[i];
16326
+ if (child.name === name1) {
16327
+ return child;
16328
+ }
16329
+ }
16330
+ return null;
16331
+ };
16332
+ /**
16333
+ * @internal
16334
+ */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
16335
+ entity._scene = scene;
16336
+ var children = entity._children;
16337
+ for(var i = children.length - 1; i >= 0; i--){
16338
+ this._traverseSetOwnerScene(children[i], scene);
16339
+ }
16340
+ };
16341
+ /**
16342
+ * @internal
16343
+ */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
16344
+ inversePath.length = 0;
16345
+ while(searchEntity !== rootEntity){
16346
+ var parent = searchEntity.parent;
16347
+ if (!parent) {
16348
+ return false;
16349
+ }
16350
+ inversePath.push(searchEntity.siblingIndex);
16351
+ searchEntity = parent;
16352
+ }
16353
+ return true;
16354
+ };
16355
+ /**
16356
+ * @internal
16357
+ */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
16358
+ var entity = rootEntity;
16359
+ for(var i = inversePath.length - 1; i >= 0; i--){
16360
+ entity = entity.children[inversePath[i]];
16361
+ }
16362
+ return entity;
16363
+ };
16364
+ _create_class$2(Entity, [
16365
+ {
16366
+ key: "isActive",
16367
+ get: /**
16368
+ * Whether to activate locally.
16369
+ */ function get() {
16370
+ return this._isActive;
16371
+ },
16372
+ set: function set(value) {
16373
+ if (value !== this._isActive) {
16374
+ this._isActive = value;
16375
+ if (value) {
16376
+ var parent = this._parent;
16377
+ var activeChangeFlag = ActiveChangeFlag.None;
16378
+ if (this._isRoot && this._scene._isActiveInEngine) {
16379
+ activeChangeFlag |= ActiveChangeFlag.All;
16380
+ } else {
16381
+ var _parent, _parent1;
16382
+ ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16383
+ ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16384
+ }
16385
+ activeChangeFlag && this._processActive(activeChangeFlag);
16386
+ } else {
16387
+ var activeChangeFlag1 = ActiveChangeFlag.None;
16388
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16389
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
16390
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
16391
+ }
16024
16392
  }
16025
16393
  }
16026
16394
  },
16395
+ {
16396
+ key: "isActiveInHierarchy",
16397
+ get: /**
16398
+ * Whether it is active in the hierarchy.
16399
+ */ function get() {
16400
+ return this._isActiveInHierarchy;
16401
+ }
16402
+ },
16403
+ {
16404
+ key: "parent",
16405
+ get: /**
16406
+ * The parent entity.
16407
+ */ function get() {
16408
+ return this._parent;
16409
+ },
16410
+ set: function set(value) {
16411
+ this._setParent(value);
16412
+ }
16413
+ },
16414
+ {
16415
+ key: "children",
16416
+ get: /**
16417
+ * The children entities
16418
+ */ function get() {
16419
+ return this._children;
16420
+ }
16421
+ },
16422
+ {
16423
+ key: "childCount",
16424
+ get: /**
16425
+ * @deprecated Please use `children.length` property instead.
16426
+ * Number of the children entities
16427
+ */ function get() {
16428
+ return this._children.length;
16429
+ }
16430
+ },
16431
+ {
16432
+ key: "scene",
16433
+ get: /**
16434
+ * The scene the entity belongs to.
16435
+ */ function get() {
16436
+ return this._scene;
16437
+ }
16438
+ },
16439
+ {
16440
+ key: "siblingIndex",
16441
+ get: /**
16442
+ * The sibling index.
16443
+ */ function get() {
16444
+ return this._siblingIndex;
16445
+ },
16446
+ set: function set(value) {
16447
+ if (this._siblingIndex === -1) {
16448
+ throw "The entity " + this.name + " is not in the hierarchy";
16449
+ }
16450
+ this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
16451
+ }
16452
+ }
16453
+ ]);
16454
+ return Entity;
16455
+ }(EngineObject);
16456
+ /**
16457
+ * Skin used for skinned mesh renderer.
16458
+ */ var Skin = /*#__PURE__*/ function(EngineObject1) {
16459
+ var Skin = function Skin(name1) {
16460
+ var _this;
16461
+ _this = EngineObject1.call(this, null) || this;
16462
+ _this.name = name1;
16463
+ _this.inverseBindMatrices = new Array();
16464
+ _this._updatedManager = new UpdateFlagManager();
16465
+ _this._bones = new Array();
16466
+ _this._updateMark = -1;
16467
+ _this.joints = [];
16468
+ return _this;
16469
+ };
16470
+ _inherits$2(Skin, EngineObject1);
16471
+ var _proto = Skin.prototype;
16472
+ /**
16473
+ * @internal
16474
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
16475
+ if (this._updateMark === renderer.engine.time.frameCount) {
16476
+ return;
16477
+ }
16478
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
16479
+ var _this_rootBone;
16480
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
16481
+ for(var i = bones.length - 1; i >= 0; i--){
16482
+ var bone = bones[i];
16483
+ var offset = i * 16;
16484
+ if (bone) {
16485
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
16486
+ } else {
16487
+ skinMatrices.set(bindMatrices[i].elements, offset);
16488
+ }
16489
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
16490
+ }
16491
+ this._updateMark = renderer.engine.time.frameCount;
16492
+ };
16493
+ /**
16494
+ * @internal
16495
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16496
+ var paths = new Array();
16497
+ // Clone rootBone
16498
+ var rootBone = this.rootBone;
16499
+ if (rootBone) {
16500
+ var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
16501
+ target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
16502
+ }
16503
+ // Clone bones
16504
+ var bones = this.bones;
16505
+ if (bones.length > 0) {
16506
+ var boneCount = bones.length;
16507
+ var destBones = new Array(boneCount);
16508
+ for(var i = 0; i < boneCount; i++){
16509
+ var bone = bones[i];
16510
+ var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
16511
+ destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
16512
+ }
16513
+ target.bones = destBones;
16514
+ }
16515
+ };
16516
+ _create_class$2(Skin, [
16027
16517
  {
16028
16518
  key: "rootBone",
16029
16519
  get: /**
@@ -16033,203 +16523,468 @@
16033
16523
  },
16034
16524
  set: function set(value) {
16035
16525
  if (this._rootBone !== value) {
16036
- this._unRegisterEntityTransformListener();
16526
+ this._updatedManager.dispatch(1, value);
16037
16527
  this._rootBone = value;
16038
- this._registerEntityTransformListener();
16039
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16040
16528
  }
16041
16529
  }
16042
16530
  },
16043
16531
  {
16044
16532
  key: "bones",
16045
16533
  get: /**
16046
- * Bones of the SkinnedMeshRenderer.
16534
+ * Bones of the skin.
16047
16535
  */ function get() {
16048
16536
  return this._bones;
16049
16537
  },
16050
16538
  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;
16539
+ var _value;
16540
+ var bones = this._bones;
16541
+ var _value_length;
16542
+ var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
16543
+ var lastBoneCount = bones.length;
16544
+ bones.length = boneCount;
16545
+ for(var i = 0; i < boneCount; i++){
16546
+ bones[i] = value[i];
16547
+ }
16548
+ if (lastBoneCount !== boneCount) {
16549
+ this._skinMatrices = new Float32Array(boneCount * 16);
16550
+ this._updatedManager.dispatch(0, boneCount);
16069
16551
  }
16070
16552
  }
16071
16553
  },
16072
16554
  {
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;
16555
+ key: "skeleton",
16556
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
16557
+ var _this_rootBone;
16558
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
16085
16559
  },
16086
16560
  set: function set(value) {
16087
- this._skin = value;
16561
+ var rootBone = this._rootBone;
16562
+ if (rootBone) {
16563
+ rootBone.name = value;
16564
+ }
16088
16565
  }
16089
16566
  }
16090
16567
  ]);
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
- })();
16568
+ return Skin;
16569
+ }(EngineObject);
16102
16570
  __decorate$1([
16103
16571
  deepClone
16104
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
16105
- __decorate$1([
16106
- ignoreClone
16107
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
16108
- __decorate$1([
16109
- ignoreClone
16110
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
16111
- __decorate$1([
16112
- ignoreClone
16113
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16114
- __decorate$1([
16115
- ignoreClone
16116
- ], SkinnedMeshRenderer.prototype, "_rootBone", void 0);
16572
+ ], Skin.prototype, "inverseBindMatrices", void 0);
16117
16573
  __decorate$1([
16118
16574
  ignoreClone
16119
- ], SkinnedMeshRenderer.prototype, "_jointMatrices", void 0);
16575
+ ], Skin.prototype, "_skinMatrices", void 0);
16120
16576
  __decorate$1([
16121
16577
  ignoreClone
16122
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16578
+ ], Skin.prototype, "_updatedManager", void 0);
16123
16579
  __decorate$1([
16124
16580
  ignoreClone
16125
- ], SkinnedMeshRenderer.prototype, "_bones", void 0);
16581
+ ], Skin.prototype, "_rootBone", void 0);
16126
16582
  __decorate$1([
16127
16583
  ignoreClone
16128
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16584
+ ], Skin.prototype, "_bones", void 0);
16129
16585
  __decorate$1([
16130
16586
  ignoreClone
16131
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16587
+ ], Skin.prototype, "_updateMark", void 0);
16588
+ var SkinUpdateFlag;
16589
+ (function(SkinUpdateFlag) {
16590
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
16591
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
16592
+ })(SkinUpdateFlag || (SkinUpdateFlag = {}));
16132
16593
  /**
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;
16594
+ * SkinnedMeshRenderer.
16595
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
16596
+ var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
16597
+ var _this;
16598
+ _this = MeshRenderer1.call(this, entity) || this;
16599
+ _this._localBounds = new BoundingBox();
16600
+ _this._jointDataCreateCache = new Vector2(-1, -1);
16601
+ _this._skin = null;
16602
+ var rhi = _this.entity.engine._hardwareRenderer;
16603
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
16604
+ // Limit size to 256 to avoid some problem:
16605
+ // 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!
16606
+ // 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.
16607
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
16608
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
16609
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
16610
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_assert_this_initialized(_this));
16611
+ var localBounds = _this._localBounds;
16612
+ // @ts-ignore
16613
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
16614
+ // @ts-ignore
16615
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
16616
+ return _this;
16139
16617
  };
16140
- var _proto = ClassPool.prototype;
16618
+ _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
16619
+ var _proto = SkinnedMeshRenderer.prototype;
16141
16620
  /**
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];
16621
+ * @internal
16622
+ */ _proto.update = function update() {
16623
+ var _skin;
16624
+ var skin = this._skin;
16625
+ if (((_skin = skin) == null ? void 0 : _skin.bones.length) > 0) {
16626
+ skin._updateSkinMatrices(this);
16152
16627
  }
16153
16628
  };
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();
16629
+ _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
16630
+ var _skin, _skin1;
16631
+ var _this = this, entity = _this.entity, skin = _this.skin;
16632
+ var _skin_rootBone;
16633
+ var worldMatrix = ((_skin_rootBone = (_skin = skin) == null ? void 0 : _skin.rootBone) != null ? _skin_rootBone : entity).transform.worldMatrix;
16634
+ if (onlyMVP) {
16635
+ this._updateMVPShaderData(context, worldMatrix);
16636
+ return;
16163
16637
  }
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);
16638
+ this._updateTransformShaderData(context, worldMatrix);
16639
+ var shaderData = this.shaderData;
16640
+ var mesh = this.mesh;
16641
+ var blendShapeManager = mesh._blendShapeManager;
16642
+ blendShapeManager._updateShaderData(shaderData, this);
16643
+ var bones = (_skin1 = skin) == null ? void 0 : _skin1.bones;
16644
+ if (bones) {
16645
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
16646
+ var boneCount = bones.length;
16647
+ var boneDataCreateCache = this._jointDataCreateCache;
16648
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
16649
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
16650
+ // directly use max joint count to avoid shader recompile
16651
+ // @TODO: different shader type should use different count, not always 44
16652
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
16653
+ if (boneCount > remainUniformJointCount) {
16654
+ var engine = this.engine;
16655
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
16656
+ if (boneCountChange) {
16657
+ var _this__jointTexture;
16658
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16659
+ this._jointTexture = new Texture2D(engine, 4, boneCount, exports.TextureFormat.R32G32B32A32, false);
16660
+ this._jointTexture.filterMode = exports.TextureFilterMode.Point;
16661
+ this._jointTexture.isGCIgnored = true;
16662
+ }
16663
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
16664
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
16665
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
16666
+ } else {
16667
+ 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);
16668
+ }
16669
+ } else {
16670
+ var _this__jointTexture1;
16671
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
16672
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
16673
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
16674
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
16675
+ }
16676
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
16677
+ }
16678
+ if (this._jointTexture) {
16679
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
16191
16680
  }
16192
- } else {
16193
- this._drawSubElement(element, camera);
16194
16681
  }
16682
+ var layer = entity.layer;
16683
+ this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
16195
16684
  };
16196
16685
  /**
16197
16686
  * @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
- }
16687
+ */ _proto._onDestroy = function _onDestroy() {
16688
+ var _this__jointTexture;
16689
+ MeshRenderer1.prototype._onDestroy.call(this);
16690
+ this._jointDataCreateCache = null;
16691
+ this._skin = null;
16692
+ this._blendShapeWeights = null;
16693
+ this._localBounds = null;
16694
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16695
+ this._jointTexture = null;
16207
16696
  };
16208
- _proto.flush = function flush(camera) {
16209
- var batchedQueue = this._batchedQueue;
16210
- if (batchedQueue.length === 0) {
16211
- return;
16212
- }
16213
- this._updateData(this._engine);
16214
- this.drawBatches(camera);
16215
- if (!Basic2DBatcher._canUploadSameBuffer) {
16216
- this._flushId++;
16697
+ /**
16698
+ * @internal
16699
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16700
+ MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
16701
+ if (this.skin) {
16702
+ target._applySkin(null, target.skin);
16217
16703
  }
16218
- batchedQueue.length = 0;
16219
- this._subMeshPool.resetPool();
16220
- this._vertexCount = 0;
16221
- this._elementCount = 0;
16704
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
16222
16705
  };
16223
- _proto.clear = function clear() {
16224
- this._flushId = 0;
16225
- this._vertexCount = 0;
16226
- this._elementCount = 0;
16227
- this._batchedQueue.length = 0;
16706
+ /**
16707
+ * @internal
16708
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
16709
+ var _this_skin;
16710
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
16711
+ if (rootBone) {
16712
+ BoundingBox.transform(this._localBounds, rootBone.transform.worldMatrix, worldBounds);
16713
+ } else {
16714
+ MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
16715
+ }
16228
16716
  };
16229
- _proto.destroy = function destroy() {
16230
- this._batchedQueue = null;
16231
- var _this = this, meshes = _this._meshes, vertexBuffers = _this._vertexBuffers, indiceBuffers = _this._indiceBuffers;
16232
- for(var i = 0, n = meshes.length; i < n; ++i){
16717
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
16718
+ var mesh = this._mesh;
16719
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
16720
+ var lastBlendShapeWeights = this._blendShapeWeights;
16721
+ if (lastBlendShapeWeights) {
16722
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
16723
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
16724
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
16725
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
16726
+ newBlendShapeWeights.set(lastBlendShapeWeights);
16727
+ } else {
16728
+ for(var i = 0; i < newBlendShapeCount; i++){
16729
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
16730
+ }
16731
+ }
16732
+ this._blendShapeWeights = newBlendShapeWeights;
16733
+ }
16734
+ } else {
16735
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16736
+ }
16737
+ };
16738
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
16739
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16740
+ };
16741
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
16742
+ switch(type){
16743
+ case SkinUpdateFlag.BoneCountChanged:
16744
+ var shaderData = this.shaderData;
16745
+ if (value > 0) {
16746
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
16747
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
16748
+ } else {
16749
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
16750
+ }
16751
+ break;
16752
+ case SkinUpdateFlag.RootBoneChanged:
16753
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16754
+ break;
16755
+ }
16756
+ };
16757
+ _proto._applySkin = function _applySkin(lastSkin, value) {
16758
+ var _lastSkin_bones, _lastSkin, _lastSkin1, _lastSkin2, _value_bones, _value, _value1, _value2;
16759
+ var _lastSkin_bones_length;
16760
+ 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;
16761
+ var _lastSkin_rootBone;
16762
+ var lastRootBone = (_lastSkin_rootBone = (_lastSkin1 = lastSkin) == null ? void 0 : _lastSkin1.rootBone) != null ? _lastSkin_rootBone : this.entity;
16763
+ (_lastSkin2 = lastSkin) == null ? void 0 : _lastSkin2._updatedManager.removeListener(this._onSkinUpdated);
16764
+ var _value_bones_length;
16765
+ 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;
16766
+ var _value_rootBone;
16767
+ var rootBone = (_value_rootBone = (_value1 = value) == null ? void 0 : _value1.rootBone) != null ? _value_rootBone : this.entity;
16768
+ (_value2 = value) == null ? void 0 : _value2._updatedManager.addListener(this._onSkinUpdated);
16769
+ if (lastSkinBoneCount !== skinBoneCount) {
16770
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
16771
+ }
16772
+ if (lastRootBone !== rootBone) {
16773
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
16774
+ }
16775
+ };
16776
+ _create_class$2(SkinnedMeshRenderer, [
16777
+ {
16778
+ key: "skin",
16779
+ get: /**
16780
+ * Skin of the SkinnedMeshRenderer.
16781
+ */ function get() {
16782
+ return this._skin;
16783
+ },
16784
+ set: function set(value) {
16785
+ var lastSkin = this._skin;
16786
+ if (lastSkin !== value) {
16787
+ this._applySkin(lastSkin, value);
16788
+ this._skin = value;
16789
+ }
16790
+ }
16791
+ },
16792
+ {
16793
+ key: "blendShapeWeights",
16794
+ get: /**
16795
+ * The weights of the BlendShapes.
16796
+ * @remarks Array index is BlendShape index.
16797
+ */ function get() {
16798
+ this._checkBlendShapeWeightLength();
16799
+ return this._blendShapeWeights;
16800
+ },
16801
+ set: function set(value) {
16802
+ this._checkBlendShapeWeightLength();
16803
+ var blendShapeWeights = this._blendShapeWeights;
16804
+ if (value.length <= blendShapeWeights.length) {
16805
+ blendShapeWeights.set(value);
16806
+ } else {
16807
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
16808
+ blendShapeWeights[i] = value[i];
16809
+ }
16810
+ }
16811
+ }
16812
+ },
16813
+ {
16814
+ key: "localBounds",
16815
+ get: /**
16816
+ * Local bounds.
16817
+ */ function get() {
16818
+ return this._localBounds;
16819
+ },
16820
+ set: function set(value) {
16821
+ if (this._localBounds !== value) {
16822
+ this._localBounds.copyFrom(value);
16823
+ }
16824
+ }
16825
+ },
16826
+ {
16827
+ key: "rootBone",
16828
+ get: /**
16829
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
16830
+ */ function get() {
16831
+ return this.skin.rootBone;
16832
+ },
16833
+ set: function set(value) {
16834
+ this.skin.rootBone = value;
16835
+ }
16836
+ },
16837
+ {
16838
+ key: "bones",
16839
+ get: /**
16840
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
16841
+ */ function get() {
16842
+ return this.skin.bones;
16843
+ },
16844
+ set: function set(value) {
16845
+ this.skin.bones = value;
16846
+ }
16847
+ }
16848
+ ]);
16849
+ return SkinnedMeshRenderer;
16850
+ }(MeshRenderer);
16851
+ (function() {
16852
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
16853
+ })();
16854
+ (function() {
16855
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
16856
+ })();
16857
+ (function() {
16858
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
16859
+ })();
16860
+ __decorate$1([
16861
+ ignoreClone
16862
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16863
+ __decorate$1([
16864
+ deepClone
16865
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
16866
+ __decorate$1([
16867
+ ignoreClone
16868
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
16869
+ __decorate$1([
16870
+ ignoreClone
16871
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
16872
+ __decorate$1([
16873
+ ignoreClone
16874
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16875
+ __decorate$1([
16876
+ ignoreClone
16877
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16878
+ __decorate$1([
16879
+ deepClone
16880
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
16881
+ __decorate$1([
16882
+ ignoreClone
16883
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16884
+ __decorate$1([
16885
+ ignoreClone
16886
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
16887
+ /**
16888
+ * Class pool utils.
16889
+ */ var ClassPool = /*#__PURE__*/ function() {
16890
+ var ClassPool = function ClassPool(type) {
16891
+ this._elementPoolIndex = 0;
16892
+ this._elementPool = [];
16893
+ this._type = type;
16894
+ };
16895
+ var _proto = ClassPool.prototype;
16896
+ /**
16897
+ * Get element from pool.
16898
+ */ _proto.getFromPool = function getFromPool() {
16899
+ var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
16900
+ this._elementPoolIndex++;
16901
+ if (pool.length === index) {
16902
+ var element = new this._type();
16903
+ pool.push(element);
16904
+ return element;
16905
+ } else {
16906
+ return pool[index];
16907
+ }
16908
+ };
16909
+ /**
16910
+ * Reset pool.
16911
+ */ _proto.resetPool = function resetPool() {
16912
+ this._elementPoolIndex = 0;
16913
+ };
16914
+ _proto.garbageCollection = function garbageCollection() {
16915
+ var _this = this, pool = _this._elementPool;
16916
+ for(var i = pool.length - 1; i >= 0; i--){
16917
+ pool[i].dispose && pool[i].dispose();
16918
+ }
16919
+ };
16920
+ return ClassPool;
16921
+ }();
16922
+ var Basic2DBatcher = /*#__PURE__*/ function() {
16923
+ var Basic2DBatcher = function Basic2DBatcher(engine) {
16924
+ /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
16925
+ /** @internal */ this._batchedQueue = [];
16926
+ /** @internal */ this._meshes = [];
16927
+ /** @internal */ this._meshCount = 1;
16928
+ /** @internal */ this._vertexBuffers = [];
16929
+ /** @internal */ this._indiceBuffers = [];
16930
+ /** @internal */ this._flushId = 0;
16931
+ /** @internal */ this._vertexCount = 0;
16932
+ /** @internal */ this._elementCount = 0;
16933
+ this._engine = engine;
16934
+ this._initMeshes(engine);
16935
+ };
16936
+ var _proto = Basic2DBatcher.prototype;
16937
+ _proto.drawElement = function drawElement(element, camera) {
16938
+ var data = element.data;
16939
+ if (data.multiRenderData) {
16940
+ var charsData = data.charsData;
16941
+ var pool = camera.engine._renderElementPool;
16942
+ for(var i = 0, n = charsData.length; i < n; ++i){
16943
+ var charRenderElement = pool.getFromPool();
16944
+ charRenderElement.set(charsData[i], element.shaderPasses);
16945
+ this._drawSubElement(charRenderElement, camera);
16946
+ }
16947
+ } else {
16948
+ this._drawSubElement(element, camera);
16949
+ }
16950
+ };
16951
+ /**
16952
+ * @internal
16953
+ * Standalone for canvas 2d renderer plugin.
16954
+ */ _proto._initMeshes = function _initMeshes(engine) {
16955
+ var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
16956
+ this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
16957
+ this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
16958
+ var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
16959
+ for(var i = 0; i < _meshCount; i++){
16960
+ _meshes[i] = this._createMesh(engine, i);
16961
+ }
16962
+ };
16963
+ _proto.flush = function flush(camera) {
16964
+ var batchedQueue = this._batchedQueue;
16965
+ if (batchedQueue.length === 0) {
16966
+ return;
16967
+ }
16968
+ this._updateData(this._engine);
16969
+ this.drawBatches(camera);
16970
+ if (!Basic2DBatcher._canUploadSameBuffer) {
16971
+ this._flushId++;
16972
+ }
16973
+ batchedQueue.length = 0;
16974
+ this._subMeshPool.resetPool();
16975
+ this._vertexCount = 0;
16976
+ this._elementCount = 0;
16977
+ };
16978
+ _proto.clear = function clear() {
16979
+ this._flushId = 0;
16980
+ this._vertexCount = 0;
16981
+ this._elementCount = 0;
16982
+ this._batchedQueue.length = 0;
16983
+ };
16984
+ _proto.destroy = function destroy() {
16985
+ this._batchedQueue = null;
16986
+ var _this = this, meshes = _this._meshes, vertexBuffers = _this._vertexBuffers, indiceBuffers = _this._indiceBuffers;
16987
+ for(var i = 0, n = meshes.length; i < n; ++i){
16233
16988
  var mesh = meshes[i];
16234
16989
  mesh._addReferCount(-1);
16235
16990
  mesh.destroy();
@@ -18757,7 +19512,7 @@
18757
19512
  */ _proto.cloneTo = function cloneTo(target) {
18758
19513
  target.shader = this.shader;
18759
19514
  this.shaderData.cloneTo(target.shaderData);
18760
- CloneManager.deepCloneObject(this.renderStates, target.renderStates);
19515
+ CloneManager.deepCloneObject(this.renderStates, target.renderStates, new Map());
18761
19516
  };
18762
19517
  _proto._addReferCount = function _addReferCount(value) {
18763
19518
  if (this._destroyed) return;
@@ -19513,1044 +20268,473 @@
19513
20268
  }
19514
20269
  }
19515
20270
  }
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;
20422
- }
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;
20428
- }
20429
- }
20430
- }
20431
- };
20432
- /**
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;
20440
- };
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;
20449
- }
20450
- }
20451
- return null;
20452
- };
20271
+ ]);
20272
+ return PBRBaseMaterial;
20273
+ }(BaseMaterial);
20274
+ (function() {
20275
+ PBRBaseMaterial._occlusionTextureIntensityProp = ShaderProperty.getByName("material_OcclusionIntensity");
20276
+ })();
20277
+ (function() {
20278
+ PBRBaseMaterial._occlusionTextureCoordProp = ShaderProperty.getByName("material_OcclusionTextureCoord");
20279
+ })();
20280
+ (function() {
20281
+ PBRBaseMaterial._occlusionTextureProp = ShaderProperty.getByName("material_OcclusionTexture");
20282
+ })();
20283
+ (function() {
20284
+ PBRBaseMaterial._clearCoatProp = ShaderProperty.getByName("material_ClearCoat");
20285
+ })();
20286
+ (function() {
20287
+ PBRBaseMaterial._clearCoatTextureProp = ShaderProperty.getByName("material_ClearCoatTexture");
20288
+ })();
20289
+ (function() {
20290
+ PBRBaseMaterial._clearCoatRoughnessProp = ShaderProperty.getByName("material_ClearCoatRoughness");
20291
+ })();
20292
+ (function() {
20293
+ PBRBaseMaterial._clearCoatRoughnessTextureProp = ShaderProperty.getByName("material_ClearCoatRoughnessTexture");
20294
+ })();
20295
+ (function() {
20296
+ PBRBaseMaterial._clearCoatNormalTextureProp = ShaderProperty.getByName("material_ClearCoatNormalTexture");
20297
+ })();
20298
+ /**
20299
+ * PBR (Metallic-Roughness Workflow) Material.
20300
+ */ var PBRMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
20301
+ _inherits$2(PBRMaterial, PBRBaseMaterial1);
20302
+ function PBRMaterial(engine) {
20303
+ var _this;
20304
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr")) || this;
20305
+ _this._anisotropyRotation = 0;
20306
+ var shaderData = _this.shaderData;
20307
+ shaderData.setFloat(PBRMaterial._metallicProp, 1);
20308
+ shaderData.setFloat(PBRMaterial._roughnessProp, 1);
20309
+ shaderData.setFloat(PBRMaterial._iorProp, 1.5);
20310
+ shaderData.setVector3(PBRMaterial._anisotropyInfoProp, new Vector3(1, 0, 0));
20311
+ return _this;
20312
+ }
20313
+ var _proto = PBRMaterial.prototype;
20453
20314
  /**
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
- }
20315
+ * @inheritdoc
20316
+ */ _proto.clone = function clone() {
20317
+ var dest = new PBRMaterial(this._engine);
20318
+ this.cloneTo(dest);
20319
+ return dest;
20461
20320
  };
20462
- _create_class$2(Entity, [
20321
+ _create_class$2(PBRMaterial, [
20463
20322
  {
20464
- key: "isActive",
20323
+ key: "ior",
20465
20324
  get: /**
20466
- * Whether to activate locally.
20325
+ * Index Of Refraction.
20326
+ * @defaultValue `1.5`
20467
20327
  */ function get() {
20468
- return this._isActive;
20328
+ return this.shaderData.getFloat(PBRMaterial._iorProp);
20329
+ },
20330
+ set: function set(v) {
20331
+ this.shaderData.setFloat(PBRMaterial._iorProp, Math.max(v, 0));
20332
+ }
20333
+ },
20334
+ {
20335
+ key: "metallic",
20336
+ get: /**
20337
+ * Metallic.
20338
+ * @defaultValue `1.0`
20339
+ */ function get() {
20340
+ return this.shaderData.getFloat(PBRMaterial._metallicProp);
20469
20341
  },
20470
20342
  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);
20343
+ this.shaderData.setFloat(PBRMaterial._metallicProp, value);
20344
+ }
20345
+ },
20346
+ {
20347
+ key: "roughness",
20348
+ get: /**
20349
+ * Roughness. default 1.0.
20350
+ * @defaultValue `1.0`
20351
+ */ function get() {
20352
+ return this.shaderData.getFloat(PBRMaterial._roughnessProp);
20353
+ },
20354
+ set: function set(value) {
20355
+ this.shaderData.setFloat(PBRMaterial._roughnessProp, value);
20356
+ }
20357
+ },
20358
+ {
20359
+ key: "roughnessMetallicTexture",
20360
+ get: /**
20361
+ * Roughness metallic texture.
20362
+ * @remarks G channel is roughness, B channel is metallic
20363
+ */ function get() {
20364
+ return this.shaderData.getTexture(PBRMaterial._roughnessMetallicTextureProp);
20365
+ },
20366
+ set: function set(value) {
20367
+ this.shaderData.setTexture(PBRMaterial._roughnessMetallicTextureProp, value);
20368
+ if (value) {
20369
+ this.shaderData.enableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
20370
+ } else {
20371
+ this.shaderData.disableMacro("MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE");
20372
+ }
20373
+ }
20374
+ },
20375
+ {
20376
+ key: "anisotropy",
20377
+ get: /**
20378
+ * The strength of anisotropy, when anisotropyTexture is present, this value is multiplied by the blue channel.
20379
+ * @defaultValue `0`
20380
+ */ function get() {
20381
+ return this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp).z;
20382
+ },
20383
+ set: function set(value) {
20384
+ var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
20385
+ if (!!anisotropyInfo.z !== !!value) {
20386
+ if (value === 0) {
20387
+ this.shaderData.disableMacro("MATERIAL_ENABLE_ANISOTROPY");
20484
20388
  } else {
20485
- var activeChangeFlag1 = ActiveChangeFlag.None;
20486
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
20487
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
20488
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
20389
+ this.shaderData.enableMacro("MATERIAL_ENABLE_ANISOTROPY");
20489
20390
  }
20490
20391
  }
20392
+ anisotropyInfo.z = value;
20491
20393
  }
20492
20394
  },
20493
20395
  {
20494
- key: "isActiveInHierarchy",
20396
+ key: "anisotropyRotation",
20495
20397
  get: /**
20496
- * Whether it is active in the hierarchy.
20398
+ * The rotation of the anisotropy in tangent, bitangent space, value in degrees.
20399
+ * @defaultValue `0`
20497
20400
  */ function get() {
20498
- return this._isActiveInHierarchy;
20401
+ return this._anisotropyRotation;
20402
+ },
20403
+ set: function set(value) {
20404
+ if (this._anisotropyRotation !== value) {
20405
+ this._anisotropyRotation = value;
20406
+ var anisotropyInfo = this.shaderData.getVector3(PBRMaterial._anisotropyInfoProp);
20407
+ var rad = MathUtil.degreeToRadFactor * value;
20408
+ anisotropyInfo.x = Math.cos(rad);
20409
+ anisotropyInfo.y = Math.sin(rad);
20410
+ }
20499
20411
  }
20500
20412
  },
20501
20413
  {
20502
- key: "parent",
20414
+ key: "anisotropyTexture",
20503
20415
  get: /**
20504
- * The parent entity.
20416
+ * The anisotropy texture.
20417
+ * @remarks
20418
+ * Red and green channels represent the anisotropy direction in [-1, 1] tangent, bitangent space, to be rotated by anisotropyRotation.
20419
+ * The blue channel contains strength as [0, 1] to be multiplied by anisotropy.
20505
20420
  */ function get() {
20506
- return this._parent;
20421
+ return this.shaderData.getTexture(PBRMaterial._anisotropyTextureProp);
20507
20422
  },
20508
20423
  set: function set(value) {
20509
- this._setParent(value);
20424
+ this.shaderData.setTexture(PBRMaterial._anisotropyTextureProp, value);
20425
+ if (value) {
20426
+ this.shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
20427
+ } else {
20428
+ this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
20429
+ }
20430
+ }
20431
+ }
20432
+ ]);
20433
+ return PBRMaterial;
20434
+ }(PBRBaseMaterial);
20435
+ (function() {
20436
+ PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
20437
+ })();
20438
+ (function() {
20439
+ PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
20440
+ })();
20441
+ (function() {
20442
+ PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
20443
+ })();
20444
+ (function() {
20445
+ PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
20446
+ })();
20447
+ (function() {
20448
+ PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
20449
+ })();
20450
+ (function() {
20451
+ PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
20452
+ })();
20453
+ /**
20454
+ * PBR (Specular-Glossiness Workflow) Material.
20455
+ */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
20456
+ _inherits$2(PBRSpecularMaterial, PBRBaseMaterial1);
20457
+ function PBRSpecularMaterial(engine) {
20458
+ var _this;
20459
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
20460
+ _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new Color(1, 1, 1, 1));
20461
+ _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
20462
+ return _this;
20463
+ }
20464
+ var _proto = PBRSpecularMaterial.prototype;
20465
+ /**
20466
+ * @inheritdoc
20467
+ */ _proto.clone = function clone() {
20468
+ var dest = new PBRSpecularMaterial(this._engine);
20469
+ this.cloneTo(dest);
20470
+ return dest;
20471
+ };
20472
+ _create_class$2(PBRSpecularMaterial, [
20473
+ {
20474
+ key: "specularColor",
20475
+ get: /**
20476
+ * Specular color.
20477
+ */ function get() {
20478
+ return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20479
+ },
20480
+ set: function set(value) {
20481
+ var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20482
+ if (value !== specularColor) {
20483
+ specularColor.copyFrom(value);
20484
+ }
20510
20485
  }
20511
20486
  },
20512
20487
  {
20513
- key: "children",
20488
+ key: "glossiness",
20514
20489
  get: /**
20515
- * The children entities
20490
+ * Glossiness.
20516
20491
  */ function get() {
20517
- return this._children;
20492
+ return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
20493
+ },
20494
+ set: function set(value) {
20495
+ this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
20518
20496
  }
20519
20497
  },
20520
20498
  {
20521
- key: "childCount",
20499
+ key: "specularGlossinessTexture",
20522
20500
  get: /**
20523
- * @deprecated Please use `children.length` property instead.
20524
- * Number of the children entities
20501
+ * Specular glossiness texture.
20502
+ * @remarks RGB is specular, A is glossiness
20525
20503
  */ function get() {
20526
- return this._children.length;
20504
+ return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
20505
+ },
20506
+ set: function set(value) {
20507
+ this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
20508
+ if (value) {
20509
+ this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20510
+ } else {
20511
+ this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20512
+ }
20513
+ }
20514
+ }
20515
+ ]);
20516
+ return PBRSpecularMaterial;
20517
+ }(PBRBaseMaterial);
20518
+ (function() {
20519
+ PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
20520
+ })();
20521
+ (function() {
20522
+ PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
20523
+ })();
20524
+ (function() {
20525
+ PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
20526
+ })();
20527
+ (function() {
20528
+ PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
20529
+ })();
20530
+ /**
20531
+ * Unlit Material.
20532
+ */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
20533
+ _inherits$2(UnlitMaterial, BaseMaterial1);
20534
+ function UnlitMaterial(engine) {
20535
+ var _this;
20536
+ _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
20537
+ var shaderData = _this.shaderData;
20538
+ shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
20539
+ shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
20540
+ shaderData.setColor(UnlitMaterial._baseColorProp, new Color(1, 1, 1, 1));
20541
+ shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new Vector4(1, 1, 0, 0));
20542
+ return _this;
20543
+ }
20544
+ var _proto = UnlitMaterial.prototype;
20545
+ /**
20546
+ * @inheritdoc
20547
+ */ _proto.clone = function clone() {
20548
+ var dest = new UnlitMaterial(this._engine);
20549
+ this.cloneTo(dest);
20550
+ return dest;
20551
+ };
20552
+ _create_class$2(UnlitMaterial, [
20553
+ {
20554
+ key: "baseColor",
20555
+ get: /**
20556
+ * Base color.
20557
+ */ function get() {
20558
+ return this.shaderData.getColor(UnlitMaterial._baseColorProp);
20559
+ },
20560
+ set: function set(value) {
20561
+ var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
20562
+ if (value !== baseColor) {
20563
+ baseColor.copyFrom(value);
20564
+ }
20527
20565
  }
20528
20566
  },
20529
20567
  {
20530
- key: "scene",
20568
+ key: "baseTexture",
20531
20569
  get: /**
20532
- * The scene the entity belongs to.
20570
+ * Base texture.
20533
20571
  */ function get() {
20534
- return this._scene;
20572
+ return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
20573
+ },
20574
+ set: function set(value) {
20575
+ this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
20576
+ if (value) {
20577
+ this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
20578
+ } else {
20579
+ this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
20580
+ }
20535
20581
  }
20536
20582
  },
20537
20583
  {
20538
- key: "siblingIndex",
20584
+ key: "tilingOffset",
20539
20585
  get: /**
20540
- * The sibling index.
20586
+ * Tiling and offset of main textures.
20541
20587
  */ function get() {
20542
- return this._siblingIndex;
20588
+ return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20543
20589
  },
20544
20590
  set: function set(value) {
20545
- if (this._siblingIndex === -1) {
20546
- throw "The entity " + this.name + " is not in the hierarchy";
20591
+ var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20592
+ if (value !== tilingOffset) {
20593
+ tilingOffset.copyFrom(value);
20547
20594
  }
20548
- this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
20549
20595
  }
20550
20596
  }
20551
20597
  ]);
20552
- return Entity;
20553
- }(EngineObject);
20598
+ return UnlitMaterial;
20599
+ }(BaseMaterial);
20600
+ /**
20601
+ * @internal
20602
+ */ var BasicResources = /*#__PURE__*/ function() {
20603
+ var BasicResources = function BasicResources(engine) {
20604
+ // prettier-ignore
20605
+ var vertices = new Float32Array([
20606
+ -1,
20607
+ -1,
20608
+ 0,
20609
+ 1,
20610
+ 1,
20611
+ -1,
20612
+ 1,
20613
+ 1,
20614
+ -1,
20615
+ 1,
20616
+ 0,
20617
+ 0,
20618
+ 1,
20619
+ 1,
20620
+ 1,
20621
+ 0
20622
+ ]); // right-top
20623
+ // prettier-ignore
20624
+ var flipYVertices = new Float32Array([
20625
+ 1,
20626
+ -1,
20627
+ 1,
20628
+ 0,
20629
+ -1,
20630
+ -1,
20631
+ 0,
20632
+ 0,
20633
+ 1,
20634
+ 1,
20635
+ 1,
20636
+ 1,
20637
+ -1,
20638
+ 1,
20639
+ 0,
20640
+ 1
20641
+ ]); // left-top
20642
+ var blitMaterial = new Material(engine, Shader.find("blit"));
20643
+ blitMaterial._addReferCount(1);
20644
+ blitMaterial.renderState.depthState.enabled = false;
20645
+ blitMaterial.renderState.depthState.writeEnabled = false;
20646
+ this.blitMesh = this._createBlitMesh(engine, vertices);
20647
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
20648
+ this.blitMaterial = blitMaterial;
20649
+ // Create white and magenta textures
20650
+ var whitePixel = new Uint8Array([
20651
+ 255,
20652
+ 255,
20653
+ 255,
20654
+ 255
20655
+ ]);
20656
+ this.whiteTexture2D = this._create1x1Texture(engine, 0, exports.TextureFormat.R8G8B8A8, whitePixel);
20657
+ this.whiteTextureCube = this._create1x1Texture(engine, 1, exports.TextureFormat.R8G8B8A8, whitePixel);
20658
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
20659
+ if (isWebGL2) {
20660
+ this.whiteTexture2DArray = this._create1x1Texture(engine, 2, exports.TextureFormat.R8G8B8A8, whitePixel);
20661
+ var whitePixel32 = new Uint32Array([
20662
+ 255,
20663
+ 255,
20664
+ 255,
20665
+ 255
20666
+ ]);
20667
+ this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, exports.TextureFormat.R32G32B32A32_UInt, whitePixel32);
20668
+ }
20669
+ };
20670
+ var _proto = BasicResources.prototype;
20671
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
20672
+ var mesh = new ModelMesh(engine);
20673
+ mesh._addReferCount(1);
20674
+ mesh.setVertexElements([
20675
+ new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
20676
+ ]);
20677
+ mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
20678
+ mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
20679
+ return mesh;
20680
+ };
20681
+ _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel) {
20682
+ var texture;
20683
+ switch(type){
20684
+ case 0:
20685
+ var texture2D = new Texture2D(engine, 1, 1, format, false);
20686
+ texture2D.setPixelBuffer(pixel);
20687
+ texture = texture2D;
20688
+ break;
20689
+ case 2:
20690
+ var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false);
20691
+ texture2DArray.setPixelBuffer(0, pixel);
20692
+ texture = texture2DArray;
20693
+ break;
20694
+ case 1:
20695
+ var textureCube = new TextureCube(engine, 1, format, false);
20696
+ for(var i = 0; i < 6; i++){
20697
+ textureCube.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, pixel);
20698
+ }
20699
+ texture = textureCube;
20700
+ break;
20701
+ default:
20702
+ throw "Invalid texture type";
20703
+ }
20704
+ texture.isGCIgnored = true;
20705
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
20706
+ var _class = function _class() {
20707
+ return ContentRestorer.call(this, texture);
20708
+ };
20709
+ _inherits$2(_class, ContentRestorer);
20710
+ var _proto = _class.prototype;
20711
+ _proto.restoreContent = function restoreContent() {
20712
+ switch(type){
20713
+ case 0:
20714
+ this.resource.setPixelBuffer(pixel);
20715
+ break;
20716
+ case 2:
20717
+ this.resource.setPixelBuffer(0, pixel);
20718
+ break;
20719
+ case 1:
20720
+ for(var i = 0; i < 6; i++){
20721
+ this.resource.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, pixel);
20722
+ }
20723
+ break;
20724
+ }
20725
+ };
20726
+ return _class;
20727
+ }(ContentRestorer))());
20728
+ return texture;
20729
+ };
20730
+ return BasicResources;
20731
+ }();
20732
+ var TextureType;
20733
+ (function(TextureType) {
20734
+ TextureType[TextureType["Texture2D"] = 0] = "Texture2D";
20735
+ TextureType[TextureType["TextureCube"] = 1] = "TextureCube";
20736
+ TextureType[TextureType["Texture2DArray"] = 2] = "Texture2DArray";
20737
+ })(TextureType || (TextureType = {}));
20554
20738
  /**
20555
20739
  * @internal
20556
20740
  * Rendering context.
@@ -25000,7 +25184,6 @@
25000
25184
  _this.xrManager = new XRManager();
25001
25185
  _this.xrManager._initialize(_assert_this_initialized(_this), xrDevice);
25002
25186
  }
25003
- _this._initMagentaTextures(hardwareRenderer);
25004
25187
  if (!hardwareRenderer.canIUse(exports.GLCapabilityType.depthTexture)) {
25005
25188
  _this._macroCollection.enable(Engine._noDepthTextureMacro);
25006
25189
  } else {
@@ -25236,99 +25419,6 @@
25236
25419
  };
25237
25420
  /**
25238
25421
  * @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
25422
  */ _proto._pendingGC = function _pendingGC() {
25333
25423
  if (this._frameInProcess) {
25334
25424
  this._waitingGC = true;
@@ -25962,6 +26052,8 @@
25962
26052
  script._started = true;
25963
26053
  _this.removeOnStartScript(script);
25964
26054
  script.onStart();
26055
+ }, function(element, index) {
26056
+ element._onStartIndex = index;
25965
26057
  });
25966
26058
  }
25967
26059
  };
@@ -28875,7 +28967,7 @@
28875
28967
  depthOnlyPass.onConfig(camera);
28876
28968
  depthOnlyPass.onRender(context, cullingResults);
28877
28969
  } else {
28878
- camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._whiteTexture2D);
28970
+ camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
28879
28971
  }
28880
28972
  // Check if need to create internal color texture
28881
28973
  var independentCanvasEnabled = camera.independentCanvasEnabled;
@@ -42840,25 +42932,32 @@
42840
42932
  camera.enabled = false;
42841
42933
  };
42842
42934
  _proto._createRenderer = function _createRenderer(context, entityInfo, entity) {
42843
- var _loop = function _loop(i) {
42844
- var glTFPrimitive = glTFMeshPrimitives[i];
42845
- var materialIndex = glTFPrimitive.material;
42846
- promises.push(Promise.all([
42847
- context.get(exports.GLTFParserType.Mesh, meshID),
42848
- skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
42849
- materialIndex !== undefined && context.get(exports.GLTFParserType.Material, materialIndex)
42850
- ]).then(function(param) {
42851
- var meshes = param[0], skin = param[1], material = param[2];
42935
+ var _this = this;
42936
+ var meshID = entityInfo.mesh, skinID = entityInfo.skin;
42937
+ var glTFMesh = context.glTF.meshes[meshID];
42938
+ var glTFMeshPrimitives = glTFMesh.primitives;
42939
+ var rendererCount = glTFMeshPrimitives.length;
42940
+ var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
42941
+ var materialPromises = new Array(rendererCount);
42942
+ for(var i = 0; i < rendererCount; i++){
42943
+ var _glTFMeshPrimitives_i_material;
42944
+ materialPromises[i] = context.get(exports.GLTFParserType.Material, (_glTFMeshPrimitives_i_material = glTFMeshPrimitives[i].material) != null ? _glTFMeshPrimitives_i_material : -1);
42945
+ }
42946
+ return Promise.all([
42947
+ context.get(exports.GLTFParserType.Mesh, meshID),
42948
+ skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
42949
+ Promise.all(materialPromises)
42950
+ ]).then(function(param) {
42951
+ var _loop = function _loop(i) {
42952
+ var material = materials[i] || exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine);
42953
+ var glTFPrimitive = glTFMeshPrimitives[i];
42852
42954
  var mesh = meshes[i];
42853
- var renderer;
42854
- material || (material = exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
42955
+ var renderer = void 0;
42855
42956
  if (skin || blendShapeWeights) {
42856
42957
  var skinRenderer = entity.addComponent(SkinnedMeshRenderer);
42857
42958
  skinRenderer.mesh = mesh;
42858
42959
  if (skin) {
42859
- skinRenderer.rootBone = skin._rootBone;
42860
- skinRenderer.bones = skin._bones;
42861
- _this._computeLocalBounds(skinRenderer, mesh, skin._bones, skin._rootBone, skin.inverseBindMatrices);
42960
+ _this._computeLocalBounds(skinRenderer, mesh, skin.bones, skin.rootBone, skin.inverseBindMatrices);
42862
42961
  skinRenderer.skin = skin;
42863
42962
  }
42864
42963
  if (blendShapeWeights) {
@@ -42877,17 +42976,10 @@
42877
42976
  }
42878
42977
  });
42879
42978
  GLTFParser.executeExtensionsAdditiveAndParse(glTFPrimitive.extensions, context, renderer, glTFPrimitive);
42880
- }));
42881
- };
42882
- var _this = this;
42883
- var glTFMeshes = context.glTF.meshes;
42884
- var meshID = entityInfo.mesh, skinID = entityInfo.skin;
42885
- var glTFMesh = glTFMeshes[meshID];
42886
- var glTFMeshPrimitives = glTFMesh.primitives;
42887
- var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
42888
- var promises = new Array();
42889
- for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
42890
- return Promise.all(promises);
42979
+ };
42980
+ var meshes = param[0], skin = param[1], materials = param[2];
42981
+ for(var i = 0; i < rendererCount; i++)_loop(i);
42982
+ });
42891
42983
  };
42892
42984
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
42893
42985
  var rootBoneIndex = bones.indexOf(rootBone);
@@ -42940,7 +43032,7 @@
42940
43032
  var jointCount = joints.length;
42941
43033
  var skin = new Skin(name);
42942
43034
  skin.inverseBindMatrices.length = jointCount;
42943
- skin._bones.length = jointCount;
43035
+ var bones = new Array(jointCount);
42944
43036
  // parse IBM
42945
43037
  var accessor = glTF.accessors[inverseBindMatrices];
42946
43038
  var skinPromise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
@@ -42952,21 +43044,20 @@
42952
43044
  skin.inverseBindMatrices[i] = inverseBindMatrix;
42953
43045
  // Get bones
42954
43046
  var bone = entities[joints[i]];
42955
- skin._bones[i] = bone;
43047
+ bones[i] = bone;
42956
43048
  skin.joints[i] = bone.name;
42957
- // Get skeleton
42958
- if (skeleton !== undefined) {
42959
- var rootBone = entities[skeleton];
42960
- skin._rootBone = rootBone;
42961
- skin.skeleton = rootBone.name;
43049
+ }
43050
+ skin.bones = bones;
43051
+ // Get skeleton
43052
+ if (skeleton !== undefined) {
43053
+ var rootBone = entities[skeleton];
43054
+ skin.rootBone = rootBone;
43055
+ } else {
43056
+ var rootBone1 = _this._findSkeletonRootBone(joints, entities);
43057
+ if (rootBone1) {
43058
+ skin.rootBone = rootBone1;
42962
43059
  } else {
42963
- var rootBone1 = _this._findSkeletonRootBone(joints, entities);
42964
- if (rootBone1) {
42965
- skin._rootBone = rootBone1;
42966
- skin.skeleton = rootBone1.name;
42967
- } else {
42968
- throw "Failed to find skeleton root bone.";
42969
- }
43060
+ throw "Failed to find skeleton root bone.";
42970
43061
  }
42971
43062
  }
42972
43063
  return skin;
@@ -44995,7 +45086,7 @@
44995
45086
  ], KHR_materials_anisotropy);
44996
45087
 
44997
45088
  //@ts-ignore
44998
- var version = "1.2.0-beta.4";
45089
+ var version = "1.2.0-beta.6";
44999
45090
  console.log("Galacean engine version: " + version);
45000
45091
  for(var key in CoreObjects){
45001
45092
  Loader.registerClass(key, CoreObjects[key]);