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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/browser.js CHANGED
@@ -5232,7 +5232,7 @@
5232
5232
  }
5233
5233
  return cloneModes;
5234
5234
  };
5235
- CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode) {
5235
+ CloneManager.cloneProperty = function cloneProperty(source, target, k, cloneMode, srcRoot, targetRoot, deepInstanceMap) {
5236
5236
  if (cloneMode === CloneMode.Ignore) {
5237
5237
  return;
5238
5238
  }
@@ -5268,22 +5268,33 @@
5268
5268
  targetPropertyA.length = length;
5269
5269
  }
5270
5270
  for(var i = 0; i < length; i++){
5271
- CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode);
5271
+ CloneManager.cloneProperty(sourceProperty, targetPropertyA, i, cloneMode, srcRoot, targetRoot, deepInstanceMap);
5272
5272
  }
5273
5273
  break;
5274
5274
  default:
5275
- var _target, _k;
5276
- var targetOProperty = (_target = target)[_k = k] || (_target[_k] = new sourceProperty.constructor());
5277
- var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5278
- for(var _$k in sourceProperty){
5279
- CloneManager.cloneProperty(sourceProperty, targetOProperty, _$k, cloneModes[_$k]);
5280
- }
5281
- // Custom clone
5282
- if (sourceProperty._cloneTo) {
5283
- sourceProperty._cloneTo(targetOProperty);
5275
+ var targetProperty = target[k];
5276
+ // If the target property is undefined, create new instance and keep reference sharing like the source
5277
+ if (!targetProperty) {
5278
+ targetProperty = deepInstanceMap.get(sourceProperty);
5279
+ if (!targetProperty) {
5280
+ targetProperty = new sourceProperty.constructor();
5281
+ deepInstanceMap.set(sourceProperty, targetProperty);
5282
+ }
5283
+ target[k] = targetProperty;
5284
5284
  }
5285
5285
  if (sourceProperty.copyFrom) {
5286
- targetOProperty.copyFrom(sourceProperty);
5286
+ // Custom clone
5287
+ targetProperty.copyFrom(sourceProperty);
5288
+ } else {
5289
+ // Universal clone
5290
+ var cloneModes = CloneManager.getCloneMode(sourceProperty.constructor);
5291
+ for(var _$k in sourceProperty){
5292
+ CloneManager.cloneProperty(sourceProperty, targetProperty, _$k, cloneModes[_$k], srcRoot, targetRoot, deepInstanceMap);
5293
+ }
5294
+ // Custom incremental clone
5295
+ if (sourceProperty._cloneTo) {
5296
+ sourceProperty._cloneTo(targetProperty, srcRoot, targetRoot);
5297
+ }
5287
5298
  }
5288
5299
  break;
5289
5300
  }
@@ -5292,9 +5303,9 @@
5292
5303
  target[k] = sourceProperty;
5293
5304
  }
5294
5305
  };
5295
- CloneManager.deepCloneObject = function deepCloneObject(source, target) {
5306
+ CloneManager.deepCloneObject = function deepCloneObject(source, target, deepInstanceMap) {
5296
5307
  for(var k in source){
5297
- CloneManager.cloneProperty(source, target, k, CloneMode.Deep);
5308
+ CloneManager.cloneProperty(source, target, k, CloneMode.Deep, null, null, deepInstanceMap);
5298
5309
  }
5299
5310
  };
5300
5311
  return CloneManager;
@@ -8836,6 +8847,7 @@
8836
8847
  var program = this._glProgram;
8837
8848
  var uniformInfos = this._getUniformInfos();
8838
8849
  var attributeInfos = this._getAttributeInfos();
8850
+ var basicResources = this._engine._basicResources;
8839
8851
  uniformInfos.forEach(function(param) {
8840
8852
  var name1 = param.name, size = param.size, type = param.type;
8841
8853
  var shaderUniform = new ShaderUniform(_this._engine);
@@ -8929,16 +8941,16 @@
8929
8941
  var defaultTexture;
8930
8942
  switch(type){
8931
8943
  case gl.SAMPLER_2D:
8932
- defaultTexture = _this._engine._magentaTexture2D;
8944
+ defaultTexture = basicResources.whiteTexture2D;
8933
8945
  break;
8934
8946
  case gl.SAMPLER_CUBE:
8935
- defaultTexture = _this._engine._magentaTextureCube;
8947
+ defaultTexture = basicResources.whiteTextureCube;
8936
8948
  break;
8937
8949
  case gl.UNSIGNED_INT_SAMPLER_2D:
8938
- defaultTexture = _this._engine._uintMagentaTexture2D;
8950
+ defaultTexture = basicResources.uintWhiteTexture2D;
8939
8951
  break;
8940
8952
  case gl.SAMPLER_2D_ARRAY:
8941
- defaultTexture = _this._engine._magentaTexture2DArray;
8953
+ defaultTexture = basicResources.whiteTexture2DArray;
8942
8954
  break;
8943
8955
  case gl.SAMPLER_2D_SHADOW:
8944
8956
  defaultTexture = _this._engine._depthTexture2D;
@@ -9794,7 +9806,8 @@
9794
9806
  }
9795
9807
  var shaderInfo = Shader._shaderLab.parseShader(nameOrShaderSource);
9796
9808
  if (shaderMap[shaderInfo.name]) {
9797
- throw 'Shader named "' + shaderInfo.name + '" already exists.';
9809
+ console.error('Shader named "' + shaderInfo.name + '" already exists.');
9810
+ return;
9798
9811
  }
9799
9812
  var subShaderList = shaderInfo.subShaders.map(function(subShaderInfo) {
9800
9813
  var passList = subShaderInfo.passes.map(function(passInfo) {
@@ -9833,7 +9846,8 @@
9833
9846
  return shader;
9834
9847
  } else {
9835
9848
  if (shaderMap[nameOrShaderSource]) {
9836
- throw 'Shader named "' + nameOrShaderSource + '" already exists.';
9849
+ console.error('Shader named "' + nameOrShaderSource + '" already exists.');
9850
+ return;
9837
9851
  }
9838
9852
  if (typeof vertexSourceOrShaderPassesOrSubShaders === "string") {
9839
9853
  var shaderPass = new ShaderPass(vertexSourceOrShaderPassesOrSubShaders, fragmentSource);
@@ -10427,7 +10441,7 @@
10427
10441
  return shaderData;
10428
10442
  };
10429
10443
  _proto.cloneTo = function cloneTo(target) {
10430
- CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
10444
+ CloneManager.deepCloneObject(this._macroCollection, target._macroCollection, new Map());
10431
10445
  Object.assign(target._macroMap, this._macroMap);
10432
10446
  var referCount = target._getReferCount();
10433
10447
  var propertyValueMap = this._propertyValueMap;
@@ -11246,14 +11260,15 @@
11246
11260
  }
11247
11261
  this._endLoop(swapFn);
11248
11262
  };
11249
- _proto.forEachAndClean = function forEachAndClean(callbackFn) {
11263
+ _proto.forEachAndClean = function forEachAndClean(callbackFn, swapFn) {
11250
11264
  this._startLoop();
11265
+ var preEnd = this.length;
11251
11266
  var elements = this._elements;
11252
- for(var i = 0, n = this.length; i < n; i++){
11267
+ for(var i = 0, n = preEnd; i < n; i++){
11253
11268
  var element = elements[i];
11254
11269
  element && callbackFn(element);
11255
11270
  }
11256
- this._endLoopAndClear();
11271
+ this._endLoopAndClean(preEnd, elements, swapFn);
11257
11272
  };
11258
11273
  _proto.sort = function sort(compareFn) {
11259
11274
  Utils._quickSort(this._elements, 0, this.length, compareFn);
@@ -11286,9 +11301,17 @@
11286
11301
  this._blankCount = 0;
11287
11302
  }
11288
11303
  };
11289
- _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
+ }
11290
11313
  this._isLooping = false;
11291
- this.length = 0;
11314
+ this.length = index;
11292
11315
  this._blankCount = 0;
11293
11316
  };
11294
11317
  return DisorderedArray;
@@ -15761,267 +15784,767 @@
15761
15784
  (function() {
15762
15785
  PrimitiveMesh._spherePoleIdx = 0;
15763
15786
  })();
15787
+ function _is_native_reflect_construct$1() {
15788
+ if (typeof Reflect === "undefined" || !Reflect.construct) return false;
15789
+ if (Reflect.construct.sham) return false;
15790
+ if (typeof Proxy === "function") return true;
15791
+ try {
15792
+ Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function() {}));
15793
+ return true;
15794
+ } catch (e) {
15795
+ return false;
15796
+ }
15797
+ }
15798
+ function _construct$1(Parent, args, Class) {
15799
+ if (_is_native_reflect_construct$1()) _construct$1 = Reflect.construct;
15800
+ else {
15801
+ _construct$1 = function construct(Parent, args, Class) {
15802
+ var a = [
15803
+ null
15804
+ ];
15805
+ a.push.apply(a, args);
15806
+ var Constructor = Function.bind.apply(Parent, a);
15807
+ var instance = new Constructor();
15808
+ if (Class) _set_prototype_of$2(instance, Class.prototype);
15809
+ return instance;
15810
+ };
15811
+ }
15812
+ return _construct$1.apply(null, arguments);
15813
+ }
15764
15814
  /**
15765
- * Mesh skin data, equal glTF skins define
15766
- */ var Skin = /*#__PURE__*/ function(EngineObject1) {
15767
- var Skin = function Skin(name1) {
15768
- var _this;
15769
- _this = EngineObject1.call(this, null) || this;
15770
- _this.name = name1;
15771
- _this._bones = [];
15772
- _this.inverseBindMatrices = []; // inverse bind matrix array
15773
- _this.joints = []; // joints name array, element type: string
15774
- _this.skeleton = "none"; // root bone name
15775
- return _this;
15815
+ * Layer, used for bit operations.
15816
+ */ exports.Layer = void 0;
15817
+ (function(Layer) {
15818
+ Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
15819
+ Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
15820
+ Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
15821
+ Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
15822
+ Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
15823
+ Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
15824
+ Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
15825
+ Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
15826
+ Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
15827
+ Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
15828
+ Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
15829
+ Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
15830
+ Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
15831
+ Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
15832
+ Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
15833
+ Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
15834
+ Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
15835
+ Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
15836
+ Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
15837
+ Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
15838
+ Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
15839
+ Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
15840
+ Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
15841
+ Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
15842
+ Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
15843
+ Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
15844
+ Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
15845
+ Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
15846
+ Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
15847
+ Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
15848
+ Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
15849
+ Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
15850
+ Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
15851
+ Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
15852
+ })(exports.Layer || (exports.Layer = {}));
15853
+ var ComponentCloner = /*#__PURE__*/ function() {
15854
+ var ComponentCloner = function ComponentCloner() {};
15855
+ /**
15856
+ * Clone component.
15857
+ * @param source - Clone source
15858
+ * @param target - Clone target
15859
+ */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot, deepInstanceMap) {
15860
+ var cloneModes = CloneManager.getCloneMode(source.constructor);
15861
+ for(var k in source){
15862
+ CloneManager.cloneProperty(source, target, k, cloneModes[k], srcRoot, targetRoot, deepInstanceMap);
15863
+ }
15864
+ if (source._cloneTo) {
15865
+ source._cloneTo(target, srcRoot, targetRoot);
15866
+ }
15776
15867
  };
15777
- _inherits$2(Skin, EngineObject1);
15778
- return Skin;
15779
- }(EngineObject);
15868
+ return ComponentCloner;
15869
+ }();
15780
15870
  /**
15781
- * SkinnedMeshRenderer.
15782
- */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
15783
- var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
15871
+ * Entity, be used as components container.
15872
+ */ var Entity = /*#__PURE__*/ function(EngineObject1) {
15873
+ var Entity = function Entity(engine, name1) {
15784
15874
  var _this;
15785
- _this = MeshRenderer1.call(this, entity) || this;
15786
- _this._localBounds = new BoundingBox();
15787
- _this._jointDataCreateCache = new Vector2(-1, -1);
15788
- _this._skin = null;
15789
- var rhi = _this.entity.engine._hardwareRenderer;
15790
- var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
15791
- // Limit size to 256 to avoid some problem:
15792
- // 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!
15793
- // 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.
15794
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
15795
- _this._maxVertexUniformVectors = maxVertexUniformVectors;
15796
- _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
15797
- var localBounds = _this._localBounds;
15798
- // @ts-ignore
15799
- localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
15800
- // @ts-ignore
15801
- localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
15875
+ _this = EngineObject1.call(this, engine) || this;
15876
+ /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
15877
+ /** @internal */ _this._isActiveInHierarchy = false;
15878
+ /** @internal */ _this._isActiveInScene = false;
15879
+ /** @internal */ _this._components = [];
15880
+ /** @internal */ _this._scripts = new DisorderedArray();
15881
+ /** @internal */ _this._children = [];
15882
+ /** @internal */ _this._isRoot = false;
15883
+ /** @internal */ _this._isActive = true;
15884
+ /** @internal */ _this._siblingIndex = -1;
15885
+ /** @internal */ _this._isTemplate = false;
15886
+ _this._parent = null;
15887
+ //--------------------------------------------------------------deprecated----------------------------------------------------------------
15888
+ _this._invModelMatrix = new Matrix();
15889
+ _this.name = name1;
15890
+ _this.transform = _this.addComponent(Transform);
15891
+ _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
15802
15892
  return _this;
15803
15893
  };
15804
- _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
15805
- var _proto = SkinnedMeshRenderer.prototype;
15894
+ _inherits$2(Entity, EngineObject1);
15895
+ var _proto = Entity.prototype;
15806
15896
  /**
15807
- * @internal
15808
- */ _proto.update = function update() {
15809
- var _this = this, skin = _this._skin, bones = _this._bones;
15810
- if (skin && bones) {
15811
- // @todo: can optimize when share skin
15812
- var jointMatrices = this._jointMatrices;
15813
- var bindMatrices = skin.inverseBindMatrices;
15814
- var _this__rootBone;
15815
- var worldToLocal = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this.entity).getInvModelMatrix();
15816
- for(var i = bones.length - 1; i >= 0; i--){
15817
- var bone = bones[i];
15818
- var offset = i * 16;
15819
- if (bone) {
15820
- Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, jointMatrices, offset);
15821
- } else {
15822
- jointMatrices.set(bindMatrices[i].elements, offset);
15823
- }
15824
- Utils._floatMatrixMultiply(worldToLocal, jointMatrices, offset, jointMatrices, offset);
15897
+ * Add component based on the component type.
15898
+ * @param type - The type of the component
15899
+ * @param args - The arguments of the component
15900
+ * @returns The component which has been added
15901
+ */ _proto.addComponent = function addComponent(type) {
15902
+ for(var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++){
15903
+ args[_key - 1] = arguments[_key];
15904
+ }
15905
+ ComponentsDependencies._addCheck(this, type);
15906
+ var component = _construct$1(type, [].concat(this, args));
15907
+ this._components.push(component);
15908
+ component._setActive(true, ActiveChangeFlag.All);
15909
+ return component;
15910
+ };
15911
+ /**
15912
+ * Get component which match the type.
15913
+ * @param type - The type of the component
15914
+ * @returns The first component which match type
15915
+ */ _proto.getComponent = function getComponent(type) {
15916
+ var components = this._components;
15917
+ for(var i = 0, n = components.length; i < n; i++){
15918
+ var component = components[i];
15919
+ if (_instanceof1$2(component, type)) {
15920
+ return component;
15825
15921
  }
15826
15922
  }
15923
+ return null;
15827
15924
  };
15828
- _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
15829
- var entity = this.entity;
15830
- var _this__rootBone;
15831
- var worldMatrix = ((_this__rootBone = this._rootBone) != null ? _this__rootBone : entity).transform.worldMatrix;
15832
- if (onlyMVP) {
15833
- this._updateMVPShaderData(context, worldMatrix);
15834
- return;
15925
+ /**
15926
+ * Get components which match the type.
15927
+ * @param type - The type of the component
15928
+ * @param results - The components which match type
15929
+ * @returns The components which match type
15930
+ */ _proto.getComponents = function getComponents(type, results) {
15931
+ results.length = 0;
15932
+ var components = this._components;
15933
+ for(var i = 0, n = components.length; i < n; i++){
15934
+ var component = components[i];
15935
+ if (_instanceof1$2(component, type)) {
15936
+ results.push(component);
15937
+ }
15835
15938
  }
15836
- this._updateTransformShaderData(context, worldMatrix);
15837
- var shaderData = this.shaderData;
15838
- var mesh = this.mesh;
15839
- var blendShapeManager = mesh._blendShapeManager;
15840
- blendShapeManager._updateShaderData(shaderData, this);
15841
- var bones = this._bones;
15842
- if (bones) {
15843
- var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
15844
- var jointCount = bones.length;
15845
- var jointDataCreateCache = this._jointDataCreateCache;
15846
- var jointCountChange = jointCount !== jointDataCreateCache.x;
15847
- if (jointCountChange || bsUniformOccupiesCount !== jointDataCreateCache.y) {
15848
- // directly use max joint count to avoid shader recompile
15849
- // @TODO: different shader type should use different count, not always 44
15850
- var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
15851
- if (jointCount > remainUniformJointCount) {
15852
- var engine = this.engine;
15853
- if (engine._hardwareRenderer.canIUseMoreJoints) {
15854
- if (jointCountChange) {
15855
- var _this__jointTexture;
15856
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
15857
- this._jointTexture = new Texture2D(engine, 4, jointCount, exports.TextureFormat.R32G32B32A32, false);
15858
- this._jointTexture.filterMode = exports.TextureFilterMode.Point;
15859
- this._jointTexture.isGCIgnored = true;
15860
- }
15861
- shaderData.disableMacro("RENDERER_JOINTS_NUM");
15862
- shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
15863
- shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
15864
- } else {
15865
- 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);
15866
- }
15939
+ return results;
15940
+ };
15941
+ /**
15942
+ * Get the components which match the type of the entity and it's children.
15943
+ * @param type - The component type
15944
+ * @param results - The components collection
15945
+ * @returns The components collection which match the type
15946
+ */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
15947
+ results.length = 0;
15948
+ this._getComponentsInChildren(type, results);
15949
+ return results;
15950
+ };
15951
+ _proto.addChild = function addChild(indexOrChild, child) {
15952
+ var index;
15953
+ if (typeof indexOrChild === "number") {
15954
+ index = indexOrChild;
15955
+ } else {
15956
+ index = undefined;
15957
+ child = indexOrChild;
15958
+ }
15959
+ if (child._isRoot) {
15960
+ child._scene._removeFromEntityList(child);
15961
+ child._isRoot = false;
15962
+ this._addToChildrenList(index, child);
15963
+ child._parent = this;
15964
+ var oldScene = child._scene;
15965
+ var newScene = this._scene;
15966
+ var inActiveChangeFlag = ActiveChangeFlag.None;
15967
+ if (!this._isActiveInHierarchy) {
15968
+ child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
15969
+ }
15970
+ if (child._isActiveInScene) {
15971
+ if (this._isActiveInScene) {
15972
+ // Cross scene should inActive first and then active
15973
+ oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
15867
15974
  } else {
15868
- var _this__jointTexture1;
15869
- (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
15870
- shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
15871
- shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
15872
- shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, this._jointMatrices);
15975
+ inActiveChangeFlag |= ActiveChangeFlag.Scene;
15873
15976
  }
15874
- jointDataCreateCache.set(jointCount, bsUniformOccupiesCount);
15875
15977
  }
15876
- if (this._jointTexture) {
15877
- this._jointTexture.setPixelBuffer(this._jointMatrices);
15978
+ inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
15979
+ if (child._scene !== newScene) {
15980
+ Entity._traverseSetOwnerScene(child, newScene);
15981
+ }
15982
+ var activeChangeFlag = ActiveChangeFlag.None;
15983
+ if (child._isActive) {
15984
+ if (this._isActiveInHierarchy) {
15985
+ !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
15986
+ }
15987
+ if (this._isActiveInScene) {
15988
+ (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
15989
+ }
15878
15990
  }
15991
+ activeChangeFlag && child._processActive(activeChangeFlag);
15992
+ child._setTransformDirty();
15993
+ } else {
15994
+ child._setParent(this, index);
15879
15995
  }
15880
- var layer = entity.layer;
15881
- this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
15882
15996
  };
15883
15997
  /**
15884
- * @internal
15885
- */ _proto._onDestroy = function _onDestroy() {
15886
- var _this__jointTexture;
15887
- MeshRenderer1.prototype._onDestroy.call(this);
15888
- this._rootBone = null;
15889
- this._jointDataCreateCache = null;
15890
- this._skin = null;
15891
- this._blendShapeWeights = null;
15892
- this._localBounds = null;
15893
- this._jointMatrices = null;
15894
- (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
15895
- this._jointTexture = null;
15896
- this._bones = null;
15998
+ * Remove child entity.
15999
+ * @param child - The child entity which want to be removed
16000
+ */ _proto.removeChild = function removeChild(child) {
16001
+ child._setParent(null);
15897
16002
  };
15898
16003
  /**
15899
- * @internal
15900
- */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
15901
- MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
15902
- var paths = new Array();
15903
- // Clone rootBone
15904
- if (this.rootBone) {
15905
- var success = this._getEntityHierarchyPath(srcRoot, this.rootBone, paths);
15906
- target.rootBone = success ? this._getEntityByHierarchyPath(targetRoot, paths) : this.rootBone;
16004
+ * @deprecated Please use `children` property instead.
16005
+ * Find child entity by index.
16006
+ * @param index - The index of the child entity
16007
+ * @returns The component which be found
16008
+ */ _proto.getChild = function getChild(index) {
16009
+ return this._children[index];
16010
+ };
16011
+ /**
16012
+ * Find entity by name.
16013
+ * @param name - The name of the entity which want to be found
16014
+ * @returns The component which be found
16015
+ */ _proto.findByName = function findByName(name1) {
16016
+ if (name1 === this.name) {
16017
+ return this;
15907
16018
  }
15908
- // Clone bones
15909
- var bones = this._bones;
15910
- if (bones) {
15911
- var boneCount = bones.length;
15912
- var destBones = new Array(boneCount);
15913
- for(var i = 0; i < boneCount; i++){
15914
- var bone = bones[i];
15915
- var success1 = this._getEntityHierarchyPath(srcRoot, bone, paths);
15916
- destBones[i] = success1 ? this._getEntityByHierarchyPath(targetRoot, paths) : bone;
16019
+ var children = this._children;
16020
+ for(var i = 0, n = children.length; i < n; i++){
16021
+ var target = children[i].findByName(name1);
16022
+ if (target) {
16023
+ return target;
15917
16024
  }
15918
- target.bones = destBones;
15919
16025
  }
15920
- this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
16026
+ return null;
15921
16027
  };
15922
16028
  /**
15923
- * @internal
15924
- */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
15925
- var _this__rootBone;
15926
- ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this._entity).transform._updateFlagManager.addListener(this._onTransformChanged);
16029
+ * Find the entity by path.
16030
+ * @param path - The path fo the entity eg: /entity
16031
+ * @returns The component which be found
16032
+ */ _proto.findByPath = function findByPath(path) {
16033
+ var splits = path.split("/");
16034
+ var entity = this;
16035
+ for(var i = 0, length = splits.length; i < length; ++i){
16036
+ var split = splits[i];
16037
+ if (split) {
16038
+ entity = Entity._findChildByName(entity, split);
16039
+ if (!entity) {
16040
+ return null;
16041
+ }
16042
+ }
16043
+ }
16044
+ return entity;
15927
16045
  };
15928
16046
  /**
15929
- * @internal
15930
- */ _proto._unRegisterEntityTransformListener = function _unRegisterEntityTransformListener() {
15931
- var _this__rootBone;
15932
- ((_this__rootBone = this._rootBone) != null ? _this__rootBone : this._entity).transform._updateFlagManager.removeListener(this._onTransformChanged);
16047
+ * Create child entity.
16048
+ * @param name - The child entity's name
16049
+ * @returns The child entity
16050
+ */ _proto.createChild = function createChild(name1) {
16051
+ var child = new Entity(this.engine, name1);
16052
+ child.layer = this.layer;
16053
+ child.parent = this;
16054
+ return child;
16055
+ };
16056
+ /**
16057
+ * Clear children entities.
16058
+ */ _proto.clearChildren = function clearChildren() {
16059
+ var children = this._children;
16060
+ for(var i = children.length - 1; i >= 0; i--){
16061
+ var child = children[i];
16062
+ child._parent = null;
16063
+ var activeChangeFlag = ActiveChangeFlag.None;
16064
+ child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16065
+ child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
16066
+ activeChangeFlag && child._processInActive(activeChangeFlag);
16067
+ Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
16068
+ }
16069
+ children.length = 0;
16070
+ };
16071
+ /**
16072
+ * Clone this entity include children and components.
16073
+ * @returns Cloned entity
16074
+ */ _proto.clone = function clone() {
16075
+ var cloneEntity = this._createCloneEntity();
16076
+ this._parseCloneEntity(this, cloneEntity, this, cloneEntity, new Map());
16077
+ return cloneEntity;
15933
16078
  };
15934
16079
  /**
15935
16080
  * @internal
15936
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
15937
- if (this._rootBone) {
15938
- var localBounds = this._localBounds;
15939
- var worldMatrix = this._rootBone.transform.worldMatrix;
15940
- BoundingBox.transform(localBounds, worldMatrix, worldBounds);
15941
- } else {
15942
- MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
16081
+ */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
16082
+ this._isTemplate = true;
16083
+ this._templateResource = templateResource;
16084
+ };
16085
+ _proto._createCloneEntity = function _createCloneEntity() {
16086
+ var cloneEntity = new Entity(this._engine, this.name);
16087
+ var templateResource = this._templateResource;
16088
+ if (templateResource) {
16089
+ cloneEntity._templateResource = templateResource;
16090
+ templateResource._addReferCount(1);
16091
+ }
16092
+ cloneEntity.layer = this.layer;
16093
+ cloneEntity._isActive = this._isActive;
16094
+ var cloneTransform = cloneEntity.transform;
16095
+ var _this = this, srcTransform = _this.transform;
16096
+ cloneTransform.position = srcTransform.position;
16097
+ cloneTransform.rotation = srcTransform.rotation;
16098
+ cloneTransform.scale = srcTransform.scale;
16099
+ var srcChildren = this._children;
16100
+ for(var i = 0, n = srcChildren.length; i < n; i++){
16101
+ cloneEntity.addChild(srcChildren[i]._createCloneEntity());
15943
16102
  }
16103
+ return cloneEntity;
15944
16104
  };
15945
- _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
15946
- var mesh = this._mesh;
15947
- var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
15948
- var lastBlendShapeWeights = this._blendShapeWeights;
15949
- if (lastBlendShapeWeights) {
15950
- var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
15951
- if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
15952
- var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
15953
- if (newBlendShapeCount > lastBlendShapeWeightsCount) {
15954
- newBlendShapeWeights.set(lastBlendShapeWeights);
15955
- } else {
15956
- for(var i = 0; i < newBlendShapeCount; i++){
15957
- newBlendShapeWeights[i] = lastBlendShapeWeights[i];
15958
- }
15959
- }
15960
- this._blendShapeWeights = newBlendShapeWeights;
16105
+ _proto._parseCloneEntity = function _parseCloneEntity(src, target, srcRoot, targetRoot, deepInstanceMap) {
16106
+ var srcChildren = src._children;
16107
+ var targetChildren = target._children;
16108
+ for(var i = 0, n = srcChildren.length; i < n; i++){
16109
+ this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot, deepInstanceMap);
16110
+ }
16111
+ var components = src._components;
16112
+ for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
16113
+ var sourceComp = components[i1];
16114
+ if (!_instanceof1$2(sourceComp, Transform)) {
16115
+ var targetComp = target.addComponent(sourceComp.constructor);
16116
+ ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot, deepInstanceMap);
15961
16117
  }
16118
+ }
16119
+ };
16120
+ /**
16121
+ * Destroy self.
16122
+ */ _proto.destroy = function destroy() {
16123
+ if (this._destroyed) {
16124
+ return;
16125
+ }
16126
+ EngineObject1.prototype.destroy.call(this);
16127
+ if (this._templateResource) {
16128
+ this._isTemplate || this._templateResource._addReferCount(-1);
16129
+ this._templateResource = null;
16130
+ }
16131
+ var components = this._components;
16132
+ for(var i = components.length - 1; i >= 0; i--){
16133
+ components[i].destroy();
16134
+ }
16135
+ this._components.length = 0;
16136
+ var children = this._children;
16137
+ while(children.length > 0){
16138
+ children[0].destroy();
16139
+ }
16140
+ if (this._isRoot) {
16141
+ this._scene.removeRootEntity(this);
15962
16142
  } else {
15963
- this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16143
+ this._setParent(null);
15964
16144
  }
16145
+ this.isActive = false;
15965
16146
  };
15966
- _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
15967
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16147
+ /**
16148
+ * @internal
16149
+ */ _proto._removeComponent = function _removeComponent(component) {
16150
+ ComponentsDependencies._removeCheck(this, component.constructor);
16151
+ var components = this._components;
16152
+ components.splice(components.indexOf(component), 1);
15968
16153
  };
15969
- _proto._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
15970
- inversePath.length = 0;
15971
- while(searchEntity !== rootEntity){
15972
- var parent = searchEntity.parent;
15973
- if (!parent) {
15974
- return false;
16154
+ /**
16155
+ * @internal
16156
+ */ _proto._addScript = function _addScript(script) {
16157
+ script._entityScriptsIndex = this._scripts.length;
16158
+ this._scripts.add(script);
16159
+ };
16160
+ /**
16161
+ * @internal
16162
+ */ _proto._removeScript = function _removeScript(script) {
16163
+ var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
16164
+ replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
16165
+ script._entityScriptsIndex = -1;
16166
+ };
16167
+ /**
16168
+ * @internal
16169
+ */ _proto._removeFromParent = function _removeFromParent() {
16170
+ var oldParent = this._parent;
16171
+ if (oldParent != null) {
16172
+ var oldSibling = oldParent._children;
16173
+ var index = this._siblingIndex;
16174
+ oldSibling.splice(index, 1);
16175
+ for(var n = oldSibling.length; index < n; index++){
16176
+ oldSibling[index]._siblingIndex--;
15975
16177
  }
15976
- inversePath.push(searchEntity.siblingIndex);
15977
- searchEntity = parent;
16178
+ this._parent = null;
16179
+ this._siblingIndex = -1;
15978
16180
  }
15979
- return true;
15980
16181
  };
15981
16182
  /**
15982
16183
  * @internal
15983
- */ _proto._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
15984
- var entity = rootEntity;
15985
- for(var i = inversePath.length - 1; i >= 0; i--){
15986
- entity = entity.children[inversePath[i]];
16184
+ */ _proto._processActive = function _processActive(activeChangeFlag) {
16185
+ if (this._activeChangedComponents) {
16186
+ throw "Note: can't set the 'main inActive entity' active in hierarchy, if the operation is in main inActive entity or it's children script's onDisable Event.";
15987
16187
  }
15988
- return entity;
16188
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16189
+ this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16190
+ this._setActiveComponents(true, activeChangeFlag);
15989
16191
  };
15990
- _create_class$2(SkinnedMeshRenderer, [
15991
- {
15992
- key: "blendShapeWeights",
15993
- get: /**
15994
- * The weights of the BlendShapes.
15995
- * @remarks Array index is BlendShape index.
15996
- */ function get() {
15997
- this._checkBlendShapeWeightLength();
15998
- return this._blendShapeWeights;
15999
- },
16000
- set: function set(value) {
16001
- this._checkBlendShapeWeightLength();
16002
- var blendShapeWeights = this._blendShapeWeights;
16003
- if (value.length <= blendShapeWeights.length) {
16004
- blendShapeWeights.set(value);
16005
- } else {
16006
- for(var i = 0, n = blendShapeWeights.length; i < n; i++){
16007
- blendShapeWeights[i] = value[i];
16008
- }
16009
- }
16010
- }
16011
- },
16012
- {
16013
- key: "localBounds",
16014
- get: /**
16015
- * Local bounds.
16016
- */ function get() {
16017
- return this._localBounds;
16018
- },
16019
- set: function set(value) {
16020
- if (this._localBounds !== value) {
16021
- this._localBounds.copyFrom(value);
16022
- }
16023
- }
16024
- },
16192
+ /**
16193
+ * @internal
16194
+ */ _proto._processInActive = function _processInActive(activeChangeFlag) {
16195
+ if (this._activeChangedComponents) {
16196
+ throw "Note: can't set the 'main active entity' inActive in hierarchy, if the operation is in main active entity or it's children script's onEnable Event.";
16197
+ }
16198
+ this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
16199
+ this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
16200
+ this._setActiveComponents(false, activeChangeFlag);
16201
+ };
16202
+ _proto._addToChildrenList = function _addToChildrenList(index, child) {
16203
+ var children = this._children;
16204
+ var childCount = children.length;
16205
+ if (index === undefined) {
16206
+ child._siblingIndex = childCount;
16207
+ children.push(child);
16208
+ } else {
16209
+ if (index < 0 || index > childCount) {
16210
+ throw "The index " + index + " is out of child list bounds " + childCount;
16211
+ }
16212
+ child._siblingIndex = index;
16213
+ children.splice(index, 0, child);
16214
+ for(var i = index + 1, n = childCount + 1; i < n; i++){
16215
+ children[i]._siblingIndex++;
16216
+ }
16217
+ }
16218
+ };
16219
+ _proto._setParent = function _setParent(parent, siblingIndex) {
16220
+ var oldParent = this._parent;
16221
+ if (parent !== oldParent) {
16222
+ this._removeFromParent();
16223
+ this._parent = parent;
16224
+ if (parent) {
16225
+ parent._addToChildrenList(siblingIndex, this);
16226
+ var oldScene = this._scene;
16227
+ var parentScene = parent._scene;
16228
+ var inActiveChangeFlag = ActiveChangeFlag.None;
16229
+ if (!parent._isActiveInHierarchy) {
16230
+ this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
16231
+ }
16232
+ if (parent._isActiveInScene) {
16233
+ // cross scene should inActive first and then active
16234
+ this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16235
+ } else {
16236
+ this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
16237
+ }
16238
+ inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
16239
+ if (oldScene !== parentScene) {
16240
+ Entity._traverseSetOwnerScene(this, parentScene);
16241
+ }
16242
+ var activeChangeFlag = ActiveChangeFlag.None;
16243
+ if (this._isActive) {
16244
+ if (parent._isActiveInHierarchy) {
16245
+ !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16246
+ }
16247
+ if (parent._isActiveInScene) {
16248
+ (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16249
+ }
16250
+ }
16251
+ activeChangeFlag && this._processActive(activeChangeFlag);
16252
+ } else {
16253
+ var inActiveChangeFlag1 = ActiveChangeFlag.None;
16254
+ this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16255
+ this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
16256
+ inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
16257
+ if (oldParent) {
16258
+ Entity._traverseSetOwnerScene(this, null);
16259
+ }
16260
+ }
16261
+ this._setTransformDirty();
16262
+ }
16263
+ };
16264
+ _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
16265
+ for(var i = this._components.length - 1; i >= 0; i--){
16266
+ var component = this._components[i];
16267
+ if (_instanceof1$2(component, type)) {
16268
+ results.push(component);
16269
+ }
16270
+ }
16271
+ for(var i1 = this._children.length - 1; i1 >= 0; i1--){
16272
+ this._children[i1]._getComponentsInChildren(type, results);
16273
+ }
16274
+ };
16275
+ _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
16276
+ var activeChangedComponents = this._activeChangedComponents;
16277
+ for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
16278
+ activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
16279
+ }
16280
+ this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
16281
+ this._activeChangedComponents = null;
16282
+ };
16283
+ _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16284
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
16285
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
16286
+ var components = this._components;
16287
+ for(var i = 0, n = components.length; i < n; i++){
16288
+ var component = components[i];
16289
+ (component.enabled || !component._awoken) && activeChangedComponents.push(component);
16290
+ }
16291
+ var children = this._children;
16292
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16293
+ var child = children[i1];
16294
+ child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16295
+ }
16296
+ };
16297
+ _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
16298
+ activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
16299
+ activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
16300
+ var components = this._components;
16301
+ for(var i = 0, n = components.length; i < n; i++){
16302
+ var component = components[i];
16303
+ component.enabled && activeChangedComponents.push(component);
16304
+ }
16305
+ var children = this._children;
16306
+ for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
16307
+ var child = children[i1];
16308
+ child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
16309
+ }
16310
+ };
16311
+ _proto._setTransformDirty = function _setTransformDirty() {
16312
+ if (this.transform) {
16313
+ this.transform._parentChange();
16314
+ } else {
16315
+ for(var i = 0, len = this._children.length; i < len; i++){
16316
+ this._children[i]._setTransformDirty();
16317
+ }
16318
+ }
16319
+ };
16320
+ _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
16321
+ target = Math.min(target, sibling.length - 1);
16322
+ if (target < 0) {
16323
+ throw "Sibling index " + target + " should large than 0";
16324
+ }
16325
+ if (this._siblingIndex !== target) {
16326
+ var oldIndex = this._siblingIndex;
16327
+ if (target < oldIndex) {
16328
+ for(var i = oldIndex; i >= target; i--){
16329
+ var child = i == target ? this : sibling[i - 1];
16330
+ sibling[i] = child;
16331
+ child._siblingIndex = i;
16332
+ }
16333
+ } else {
16334
+ for(var i1 = oldIndex; i1 <= target; i1++){
16335
+ var child1 = i1 == target ? this : sibling[i1 + 1];
16336
+ sibling[i1] = child1;
16337
+ child1._siblingIndex = i1;
16338
+ }
16339
+ }
16340
+ }
16341
+ };
16342
+ /**
16343
+ * @deprecated
16344
+ */ _proto.getInvModelMatrix = function getInvModelMatrix() {
16345
+ if (this._inverseWorldMatFlag.flag) {
16346
+ Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
16347
+ this._inverseWorldMatFlag.flag = false;
16348
+ }
16349
+ return this._invModelMatrix;
16350
+ };
16351
+ /**
16352
+ * @internal
16353
+ */ Entity._findChildByName = function _findChildByName(root, name1) {
16354
+ var children = root._children;
16355
+ for(var i = children.length - 1; i >= 0; i--){
16356
+ var child = children[i];
16357
+ if (child.name === name1) {
16358
+ return child;
16359
+ }
16360
+ }
16361
+ return null;
16362
+ };
16363
+ /**
16364
+ * @internal
16365
+ */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
16366
+ entity._scene = scene;
16367
+ var children = entity._children;
16368
+ for(var i = children.length - 1; i >= 0; i--){
16369
+ this._traverseSetOwnerScene(children[i], scene);
16370
+ }
16371
+ };
16372
+ /**
16373
+ * @internal
16374
+ */ Entity._getEntityHierarchyPath = function _getEntityHierarchyPath(rootEntity, searchEntity, inversePath) {
16375
+ inversePath.length = 0;
16376
+ while(searchEntity !== rootEntity){
16377
+ var parent = searchEntity.parent;
16378
+ if (!parent) {
16379
+ return false;
16380
+ }
16381
+ inversePath.push(searchEntity.siblingIndex);
16382
+ searchEntity = parent;
16383
+ }
16384
+ return true;
16385
+ };
16386
+ /**
16387
+ * @internal
16388
+ */ Entity._getEntityByHierarchyPath = function _getEntityByHierarchyPath(rootEntity, inversePath) {
16389
+ var entity = rootEntity;
16390
+ for(var i = inversePath.length - 1; i >= 0; i--){
16391
+ entity = entity.children[inversePath[i]];
16392
+ }
16393
+ return entity;
16394
+ };
16395
+ _create_class$2(Entity, [
16396
+ {
16397
+ key: "isActive",
16398
+ get: /**
16399
+ * Whether to activate locally.
16400
+ */ function get() {
16401
+ return this._isActive;
16402
+ },
16403
+ set: function set(value) {
16404
+ if (value !== this._isActive) {
16405
+ this._isActive = value;
16406
+ if (value) {
16407
+ var parent = this._parent;
16408
+ var activeChangeFlag = ActiveChangeFlag.None;
16409
+ if (this._isRoot && this._scene._isActiveInEngine) {
16410
+ activeChangeFlag |= ActiveChangeFlag.All;
16411
+ } else {
16412
+ var _parent, _parent1;
16413
+ ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
16414
+ ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
16415
+ }
16416
+ activeChangeFlag && this._processActive(activeChangeFlag);
16417
+ } else {
16418
+ var activeChangeFlag1 = ActiveChangeFlag.None;
16419
+ this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
16420
+ this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
16421
+ activeChangeFlag1 && this._processInActive(activeChangeFlag1);
16422
+ }
16423
+ }
16424
+ }
16425
+ },
16426
+ {
16427
+ key: "isActiveInHierarchy",
16428
+ get: /**
16429
+ * Whether it is active in the hierarchy.
16430
+ */ function get() {
16431
+ return this._isActiveInHierarchy;
16432
+ }
16433
+ },
16434
+ {
16435
+ key: "parent",
16436
+ get: /**
16437
+ * The parent entity.
16438
+ */ function get() {
16439
+ return this._parent;
16440
+ },
16441
+ set: function set(value) {
16442
+ this._setParent(value);
16443
+ }
16444
+ },
16445
+ {
16446
+ key: "children",
16447
+ get: /**
16448
+ * The children entities
16449
+ */ function get() {
16450
+ return this._children;
16451
+ }
16452
+ },
16453
+ {
16454
+ key: "childCount",
16455
+ get: /**
16456
+ * @deprecated Please use `children.length` property instead.
16457
+ * Number of the children entities
16458
+ */ function get() {
16459
+ return this._children.length;
16460
+ }
16461
+ },
16462
+ {
16463
+ key: "scene",
16464
+ get: /**
16465
+ * The scene the entity belongs to.
16466
+ */ function get() {
16467
+ return this._scene;
16468
+ }
16469
+ },
16470
+ {
16471
+ key: "siblingIndex",
16472
+ get: /**
16473
+ * The sibling index.
16474
+ */ function get() {
16475
+ return this._siblingIndex;
16476
+ },
16477
+ set: function set(value) {
16478
+ if (this._siblingIndex === -1) {
16479
+ throw "The entity " + this.name + " is not in the hierarchy";
16480
+ }
16481
+ this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
16482
+ }
16483
+ }
16484
+ ]);
16485
+ return Entity;
16486
+ }(EngineObject);
16487
+ /**
16488
+ * Skin used for skinned mesh renderer.
16489
+ */ var Skin = /*#__PURE__*/ function(EngineObject1) {
16490
+ var Skin = function Skin(name1) {
16491
+ var _this;
16492
+ _this = EngineObject1.call(this, null) || this;
16493
+ _this.name = name1;
16494
+ _this.inverseBindMatrices = new Array();
16495
+ _this._updatedManager = new UpdateFlagManager();
16496
+ _this._bones = new Array();
16497
+ _this._updateMark = -1;
16498
+ _this.joints = [];
16499
+ return _this;
16500
+ };
16501
+ _inherits$2(Skin, EngineObject1);
16502
+ var _proto = Skin.prototype;
16503
+ /**
16504
+ * @internal
16505
+ */ _proto._updateSkinMatrices = function _updateSkinMatrices(renderer) {
16506
+ if (this._updateMark === renderer.engine.time.frameCount) {
16507
+ return;
16508
+ }
16509
+ var _this = this, bones = _this.bones, bindMatrices = _this.inverseBindMatrices, skinMatrices = _this._skinMatrices;
16510
+ var _this_rootBone;
16511
+ var worldToLocal = ((_this_rootBone = this.rootBone) != null ? _this_rootBone : renderer.entity).getInvModelMatrix();
16512
+ for(var i = bones.length - 1; i >= 0; i--){
16513
+ var bone = bones[i];
16514
+ var offset = i * 16;
16515
+ if (bone) {
16516
+ Utils._floatMatrixMultiply(bone.transform.worldMatrix, bindMatrices[i].elements, 0, skinMatrices, offset);
16517
+ } else {
16518
+ skinMatrices.set(bindMatrices[i].elements, offset);
16519
+ }
16520
+ Utils._floatMatrixMultiply(worldToLocal, skinMatrices, offset, skinMatrices, offset);
16521
+ }
16522
+ this._updateMark = renderer.engine.time.frameCount;
16523
+ };
16524
+ /**
16525
+ * @internal
16526
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16527
+ var paths = new Array();
16528
+ // Clone rootBone
16529
+ var rootBone = this.rootBone;
16530
+ if (rootBone) {
16531
+ var success = Entity._getEntityHierarchyPath(srcRoot, rootBone, paths);
16532
+ target.rootBone = success ? Entity._getEntityByHierarchyPath(targetRoot, paths) : rootBone;
16533
+ }
16534
+ // Clone bones
16535
+ var bones = this.bones;
16536
+ if (bones.length > 0) {
16537
+ var boneCount = bones.length;
16538
+ var destBones = new Array(boneCount);
16539
+ for(var i = 0; i < boneCount; i++){
16540
+ var bone = bones[i];
16541
+ var success1 = Entity._getEntityHierarchyPath(srcRoot, bone, paths);
16542
+ destBones[i] = success1 ? Entity._getEntityByHierarchyPath(targetRoot, paths) : bone;
16543
+ }
16544
+ target.bones = destBones;
16545
+ }
16546
+ };
16547
+ _create_class$2(Skin, [
16025
16548
  {
16026
16549
  key: "rootBone",
16027
16550
  get: /**
@@ -16031,176 +16554,441 @@
16031
16554
  },
16032
16555
  set: function set(value) {
16033
16556
  if (this._rootBone !== value) {
16034
- this._unRegisterEntityTransformListener();
16557
+ this._updatedManager.dispatch(1, value);
16035
16558
  this._rootBone = value;
16036
- this._registerEntityTransformListener();
16037
- this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16038
16559
  }
16039
16560
  }
16040
16561
  },
16041
16562
  {
16042
16563
  key: "bones",
16043
16564
  get: /**
16044
- * Bones of the SkinnedMeshRenderer.
16565
+ * Bones of the skin.
16045
16566
  */ function get() {
16046
16567
  return this._bones;
16047
16568
  },
16048
16569
  set: function set(value) {
16049
- if (this._bones !== value) {
16050
- var _this__bones, _value;
16051
- var _this__bones_length;
16052
- var lastBoneCount = (_this__bones_length = (_this__bones = this._bones) == null ? void 0 : _this__bones.length) != null ? _this__bones_length : 0;
16053
- var _value_length;
16054
- var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
16055
- if (lastBoneCount !== boneCount) {
16056
- var shaderData = this.shaderData;
16057
- if (boneCount > 0) {
16058
- this._jointMatrices = new Float32Array(boneCount * 16);
16059
- shaderData.enableMacro("RENDERER_HAS_SKIN");
16060
- shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, boneCount);
16061
- } else {
16062
- this._jointMatrices = null;
16063
- shaderData.disableMacro("RENDERER_HAS_SKIN");
16064
- }
16065
- }
16066
- this._bones = value;
16570
+ var _value;
16571
+ var bones = this._bones;
16572
+ var _value_length;
16573
+ var boneCount = (_value_length = (_value = value) == null ? void 0 : _value.length) != null ? _value_length : 0;
16574
+ var lastBoneCount = bones.length;
16575
+ bones.length = boneCount;
16576
+ for(var i = 0; i < boneCount; i++){
16577
+ bones[i] = value[i];
16578
+ }
16579
+ if (lastBoneCount !== boneCount) {
16580
+ this._skinMatrices = new Float32Array(boneCount * 16);
16581
+ this._updatedManager.dispatch(0, boneCount);
16067
16582
  }
16068
16583
  }
16069
16584
  },
16070
16585
  {
16071
- key: "skin",
16072
- get: /**
16073
- * @deprecated
16074
- * Skin Object.
16075
- *
16076
- * If you want get `skeleton`, use {@link SkinnedMeshRenderer.rootBone} instead.
16077
- * If you want get `bones`, use {@link SkinnedMeshRenderer.bones} instead.
16078
- * `inverseBindMatrices` will migrate to mesh in the future.
16079
- *
16080
- * @remarks `rootBone` and `bones` will not update when `skin` changed.
16081
- */ function get() {
16082
- return this._skin;
16586
+ key: "skeleton",
16587
+ get: /** @deprecated Please use `rootBone` instead. */ function get() {
16588
+ var _this_rootBone;
16589
+ return (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.name;
16083
16590
  },
16084
16591
  set: function set(value) {
16085
- this._skin = value;
16592
+ var rootBone = this._rootBone;
16593
+ if (rootBone) {
16594
+ rootBone.name = value;
16595
+ }
16086
16596
  }
16087
16597
  }
16088
16598
  ]);
16089
- return SkinnedMeshRenderer;
16090
- }(MeshRenderer);
16091
- (function() {
16092
- SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
16093
- })();
16094
- (function() {
16095
- SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
16096
- })();
16097
- (function() {
16098
- SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
16099
- })();
16599
+ return Skin;
16600
+ }(EngineObject);
16100
16601
  __decorate$1([
16101
16602
  deepClone
16102
- ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
16603
+ ], Skin.prototype, "inverseBindMatrices", void 0);
16103
16604
  __decorate$1([
16104
16605
  ignoreClone
16105
- ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
16106
- __decorate$1([
16107
- ignoreClone
16108
- ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
16109
- __decorate$1([
16110
- ignoreClone
16111
- ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16112
- __decorate$1([
16113
- ignoreClone
16114
- ], SkinnedMeshRenderer.prototype, "_rootBone", void 0);
16115
- __decorate$1([
16116
- ignoreClone
16117
- ], SkinnedMeshRenderer.prototype, "_jointMatrices", void 0);
16606
+ ], Skin.prototype, "_skinMatrices", void 0);
16118
16607
  __decorate$1([
16119
16608
  ignoreClone
16120
- ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16609
+ ], Skin.prototype, "_updatedManager", void 0);
16121
16610
  __decorate$1([
16122
16611
  ignoreClone
16123
- ], SkinnedMeshRenderer.prototype, "_bones", void 0);
16612
+ ], Skin.prototype, "_rootBone", void 0);
16124
16613
  __decorate$1([
16125
16614
  ignoreClone
16126
- ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16615
+ ], Skin.prototype, "_bones", void 0);
16127
16616
  __decorate$1([
16128
16617
  ignoreClone
16129
- ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16618
+ ], Skin.prototype, "_updateMark", void 0);
16619
+ var SkinUpdateFlag;
16620
+ (function(SkinUpdateFlag) {
16621
+ SkinUpdateFlag[SkinUpdateFlag["BoneCountChanged"] = 0] = "BoneCountChanged";
16622
+ SkinUpdateFlag[SkinUpdateFlag["RootBoneChanged"] = 1] = "RootBoneChanged";
16623
+ })(SkinUpdateFlag || (SkinUpdateFlag = {}));
16130
16624
  /**
16131
- * Class pool utils.
16132
- */ var ClassPool = /*#__PURE__*/ function() {
16133
- var ClassPool = function ClassPool(type) {
16134
- this._elementPoolIndex = 0;
16135
- this._elementPool = [];
16136
- this._type = type;
16625
+ * SkinnedMeshRenderer.
16626
+ */ var SkinnedMeshRenderer = /*#__PURE__*/ function(MeshRenderer1) {
16627
+ var SkinnedMeshRenderer = function SkinnedMeshRenderer(entity) {
16628
+ var _this;
16629
+ _this = MeshRenderer1.call(this, entity) || this;
16630
+ _this._localBounds = new BoundingBox();
16631
+ _this._jointDataCreateCache = new Vector2(-1, -1);
16632
+ _this._skin = null;
16633
+ var rhi = _this.entity.engine._hardwareRenderer;
16634
+ var maxVertexUniformVectors = rhi.renderStates.getParameter(rhi.gl.MAX_VERTEX_UNIFORM_VECTORS);
16635
+ // Limit size to 256 to avoid some problem:
16636
+ // For renderer is "Apple GPU", when uniform is large than 256 the skeleton matrix array access in shader very slow in Safari or WKWebview. This may be a apple bug, Chrome and Firefox is OK!
16637
+ // For renderer is "ANGLE (AMD, AMD Radeon(TM) Graphics Direct3011 vs_5_0 ps_5_0, D3011)", compile shader si very slow because of max uniform is 4096.
16638
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
16639
+ _this._maxVertexUniformVectors = maxVertexUniformVectors;
16640
+ _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
16641
+ _this._onSkinUpdated = _this._onSkinUpdated.bind(_assert_this_initialized(_this));
16642
+ var localBounds = _this._localBounds;
16643
+ // @ts-ignore
16644
+ localBounds.min._onValueChanged = _this._onLocalBoundsChanged;
16645
+ // @ts-ignore
16646
+ localBounds.max._onValueChanged = _this._onLocalBoundsChanged;
16647
+ return _this;
16137
16648
  };
16138
- var _proto = ClassPool.prototype;
16649
+ _inherits$2(SkinnedMeshRenderer, MeshRenderer1);
16650
+ var _proto = SkinnedMeshRenderer.prototype;
16139
16651
  /**
16140
- * Get element from pool.
16141
- */ _proto.getFromPool = function getFromPool() {
16142
- var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
16143
- this._elementPoolIndex++;
16144
- if (pool.length === index) {
16145
- var element = new this._type();
16146
- pool.push(element);
16147
- return element;
16148
- } else {
16149
- return pool[index];
16652
+ * @internal
16653
+ */ _proto.update = function update() {
16654
+ var _skin;
16655
+ var skin = this._skin;
16656
+ if (((_skin = skin) == null ? void 0 : _skin.bones.length) > 0) {
16657
+ skin._updateSkinMatrices(this);
16150
16658
  }
16151
16659
  };
16152
- /**
16153
- * Reset pool.
16154
- */ _proto.resetPool = function resetPool() {
16155
- this._elementPoolIndex = 0;
16156
- };
16157
- _proto.garbageCollection = function garbageCollection() {
16158
- var _this = this, pool = _this._elementPool;
16159
- for(var i = pool.length - 1; i >= 0; i--){
16160
- pool[i].dispose && pool[i].dispose();
16660
+ _proto._updateShaderData = function _updateShaderData(context, onlyMVP) {
16661
+ var _skin, _skin1;
16662
+ var _this = this, entity = _this.entity, skin = _this.skin;
16663
+ var _skin_rootBone;
16664
+ var worldMatrix = ((_skin_rootBone = (_skin = skin) == null ? void 0 : _skin.rootBone) != null ? _skin_rootBone : entity).transform.worldMatrix;
16665
+ if (onlyMVP) {
16666
+ this._updateMVPShaderData(context, worldMatrix);
16667
+ return;
16668
+ }
16669
+ this._updateTransformShaderData(context, worldMatrix);
16670
+ var shaderData = this.shaderData;
16671
+ var mesh = this.mesh;
16672
+ var blendShapeManager = mesh._blendShapeManager;
16673
+ blendShapeManager._updateShaderData(shaderData, this);
16674
+ var bones = (_skin1 = skin) == null ? void 0 : _skin1.bones;
16675
+ if (bones) {
16676
+ var bsUniformOccupiesCount = blendShapeManager._uniformOccupiesCount;
16677
+ var boneCount = bones.length;
16678
+ var boneDataCreateCache = this._jointDataCreateCache;
16679
+ var boneCountChange = boneCount !== boneDataCreateCache.x;
16680
+ if (boneCountChange || bsUniformOccupiesCount !== boneDataCreateCache.y) {
16681
+ // directly use max joint count to avoid shader recompile
16682
+ // @TODO: different shader type should use different count, not always 44
16683
+ var remainUniformJointCount = Math.ceil((this._maxVertexUniformVectors - (44 + bsUniformOccupiesCount)) / 4);
16684
+ if (boneCount > remainUniformJointCount) {
16685
+ var engine = this.engine;
16686
+ if (engine._hardwareRenderer.canIUseMoreJoints) {
16687
+ if (boneCountChange) {
16688
+ var _this__jointTexture;
16689
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16690
+ this._jointTexture = new Texture2D(engine, 4, boneCount, exports.TextureFormat.R32G32B32A32, false);
16691
+ this._jointTexture.filterMode = exports.TextureFilterMode.Point;
16692
+ this._jointTexture.isGCIgnored = true;
16693
+ }
16694
+ shaderData.disableMacro("RENDERER_JOINTS_NUM");
16695
+ shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
16696
+ shaderData.setTexture(SkinnedMeshRenderer._jointSamplerProperty, this._jointTexture);
16697
+ } else {
16698
+ Logger.error("component's joints count(" + boneCount + ") greater than device's MAX_VERTEX_UNIFORM_VECTORS number " + this._maxVertexUniformVectors + ", and don't support jointTexture in this device. suggest joint count less than " + remainUniformJointCount + ".", this);
16699
+ }
16700
+ } else {
16701
+ var _this__jointTexture1;
16702
+ (_this__jointTexture1 = this._jointTexture) == null ? void 0 : _this__jointTexture1.destroy();
16703
+ shaderData.disableMacro("RENDERER_USE_JOINT_TEXTURE");
16704
+ shaderData.enableMacro("RENDERER_JOINTS_NUM", remainUniformJointCount.toString());
16705
+ shaderData.setFloatArray(SkinnedMeshRenderer._jointMatrixProperty, skin._skinMatrices);
16706
+ }
16707
+ boneDataCreateCache.set(boneCount, bsUniformOccupiesCount);
16708
+ }
16709
+ if (this._jointTexture) {
16710
+ this._jointTexture.setPixelBuffer(skin._skinMatrices);
16711
+ }
16161
16712
  }
16713
+ var layer = entity.layer;
16714
+ this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
16162
16715
  };
16163
- return ClassPool;
16164
- }();
16165
- var Basic2DBatcher = /*#__PURE__*/ function() {
16166
- var Basic2DBatcher = function Basic2DBatcher(engine) {
16167
- /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
16168
- /** @internal */ this._batchedQueue = [];
16169
- /** @internal */ this._meshes = [];
16170
- /** @internal */ this._meshCount = 1;
16171
- /** @internal */ this._vertexBuffers = [];
16172
- /** @internal */ this._indiceBuffers = [];
16173
- /** @internal */ this._flushId = 0;
16174
- /** @internal */ this._vertexCount = 0;
16175
- /** @internal */ this._elementCount = 0;
16176
- this._engine = engine;
16177
- this._initMeshes(engine);
16716
+ /**
16717
+ * @internal
16718
+ */ _proto._onDestroy = function _onDestroy() {
16719
+ var _this__jointTexture;
16720
+ MeshRenderer1.prototype._onDestroy.call(this);
16721
+ this._jointDataCreateCache = null;
16722
+ this._skin = null;
16723
+ this._blendShapeWeights = null;
16724
+ this._localBounds = null;
16725
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
16726
+ this._jointTexture = null;
16178
16727
  };
16179
- var _proto = Basic2DBatcher.prototype;
16180
- _proto.drawElement = function drawElement(element, camera) {
16181
- var data = element.data;
16182
- if (data.multiRenderData) {
16183
- var charsData = data.charsData;
16184
- var pool = camera.engine._renderElementPool;
16185
- for(var i = 0, n = charsData.length; i < n; ++i){
16186
- var charRenderElement = pool.getFromPool();
16187
- charRenderElement.set(charsData[i], element.shaderPasses);
16188
- this._drawSubElement(charRenderElement, camera);
16189
- }
16190
- } else {
16191
- this._drawSubElement(element, camera);
16728
+ /**
16729
+ * @internal
16730
+ */ _proto._cloneTo = function _cloneTo(target, srcRoot, targetRoot) {
16731
+ MeshRenderer1.prototype._cloneTo.call(this, target, srcRoot, targetRoot);
16732
+ if (this.skin) {
16733
+ target._applySkin(null, target.skin);
16192
16734
  }
16735
+ this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
16193
16736
  };
16194
16737
  /**
16195
16738
  * @internal
16196
- * Standalone for canvas 2d renderer plugin.
16197
- */ _proto._initMeshes = function _initMeshes(engine) {
16198
- var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
16199
- this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
16200
- this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
16201
- var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
16202
- for(var i = 0; i < _meshCount; i++){
16203
- _meshes[i] = this._createMesh(engine, i);
16739
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
16740
+ var _this_skin;
16741
+ var rootBone = (_this_skin = this.skin) == null ? void 0 : _this_skin.rootBone;
16742
+ if (rootBone) {
16743
+ BoundingBox.transform(this._localBounds, rootBone.transform.worldMatrix, worldBounds);
16744
+ } else {
16745
+ MeshRenderer1.prototype._updateBounds.call(this, worldBounds);
16746
+ }
16747
+ };
16748
+ _proto._checkBlendShapeWeightLength = function _checkBlendShapeWeightLength() {
16749
+ var mesh = this._mesh;
16750
+ var newBlendShapeCount = mesh ? mesh.blendShapeCount : 0;
16751
+ var lastBlendShapeWeights = this._blendShapeWeights;
16752
+ if (lastBlendShapeWeights) {
16753
+ var lastBlendShapeWeightsCount = lastBlendShapeWeights.length;
16754
+ if (lastBlendShapeWeightsCount !== newBlendShapeCount) {
16755
+ var newBlendShapeWeights = new Float32Array(newBlendShapeCount);
16756
+ if (newBlendShapeCount > lastBlendShapeWeightsCount) {
16757
+ newBlendShapeWeights.set(lastBlendShapeWeights);
16758
+ } else {
16759
+ for(var i = 0; i < newBlendShapeCount; i++){
16760
+ newBlendShapeWeights[i] = lastBlendShapeWeights[i];
16761
+ }
16762
+ }
16763
+ this._blendShapeWeights = newBlendShapeWeights;
16764
+ }
16765
+ } else {
16766
+ this._blendShapeWeights = new Float32Array(newBlendShapeCount);
16767
+ }
16768
+ };
16769
+ _proto._onLocalBoundsChanged = function _onLocalBoundsChanged() {
16770
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16771
+ };
16772
+ _proto._onSkinUpdated = function _onSkinUpdated(type, value) {
16773
+ switch(type){
16774
+ case SkinUpdateFlag.BoneCountChanged:
16775
+ var shaderData = this.shaderData;
16776
+ if (value > 0) {
16777
+ shaderData.enableMacro("RENDERER_HAS_SKIN");
16778
+ shaderData.setInt(SkinnedMeshRenderer._jointCountProperty, value);
16779
+ } else {
16780
+ shaderData.disableMacro("RENDERER_HAS_SKIN");
16781
+ }
16782
+ break;
16783
+ case SkinUpdateFlag.RootBoneChanged:
16784
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16785
+ break;
16786
+ }
16787
+ };
16788
+ _proto._applySkin = function _applySkin(lastSkin, value) {
16789
+ var _lastSkin_bones, _lastSkin, _lastSkin1, _lastSkin2, _value_bones, _value, _value1, _value2;
16790
+ var _lastSkin_bones_length;
16791
+ var lastSkinBoneCount = (_lastSkin_bones_length = (_lastSkin = lastSkin) == null ? void 0 : (_lastSkin_bones = _lastSkin.bones) == null ? void 0 : _lastSkin_bones.length) != null ? _lastSkin_bones_length : 0;
16792
+ var _lastSkin_rootBone;
16793
+ var lastRootBone = (_lastSkin_rootBone = (_lastSkin1 = lastSkin) == null ? void 0 : _lastSkin1.rootBone) != null ? _lastSkin_rootBone : this.entity;
16794
+ (_lastSkin2 = lastSkin) == null ? void 0 : _lastSkin2._updatedManager.removeListener(this._onSkinUpdated);
16795
+ var _value_bones_length;
16796
+ var skinBoneCount = (_value_bones_length = (_value = value) == null ? void 0 : (_value_bones = _value.bones) == null ? void 0 : _value_bones.length) != null ? _value_bones_length : 0;
16797
+ var _value_rootBone;
16798
+ var rootBone = (_value_rootBone = (_value1 = value) == null ? void 0 : _value1.rootBone) != null ? _value_rootBone : this.entity;
16799
+ (_value2 = value) == null ? void 0 : _value2._updatedManager.addListener(this._onSkinUpdated);
16800
+ if (lastSkinBoneCount !== skinBoneCount) {
16801
+ this._onSkinUpdated(SkinUpdateFlag.BoneCountChanged, skinBoneCount);
16802
+ }
16803
+ if (lastRootBone !== rootBone) {
16804
+ this._onSkinUpdated(SkinUpdateFlag.RootBoneChanged, rootBone);
16805
+ }
16806
+ };
16807
+ _create_class$2(SkinnedMeshRenderer, [
16808
+ {
16809
+ key: "skin",
16810
+ get: /**
16811
+ * Skin of the SkinnedMeshRenderer.
16812
+ */ function get() {
16813
+ return this._skin;
16814
+ },
16815
+ set: function set(value) {
16816
+ var lastSkin = this._skin;
16817
+ if (lastSkin !== value) {
16818
+ this._applySkin(lastSkin, value);
16819
+ this._skin = value;
16820
+ }
16821
+ }
16822
+ },
16823
+ {
16824
+ key: "blendShapeWeights",
16825
+ get: /**
16826
+ * The weights of the BlendShapes.
16827
+ * @remarks Array index is BlendShape index.
16828
+ */ function get() {
16829
+ this._checkBlendShapeWeightLength();
16830
+ return this._blendShapeWeights;
16831
+ },
16832
+ set: function set(value) {
16833
+ this._checkBlendShapeWeightLength();
16834
+ var blendShapeWeights = this._blendShapeWeights;
16835
+ if (value.length <= blendShapeWeights.length) {
16836
+ blendShapeWeights.set(value);
16837
+ } else {
16838
+ for(var i = 0, n = blendShapeWeights.length; i < n; i++){
16839
+ blendShapeWeights[i] = value[i];
16840
+ }
16841
+ }
16842
+ }
16843
+ },
16844
+ {
16845
+ key: "localBounds",
16846
+ get: /**
16847
+ * Local bounds.
16848
+ */ function get() {
16849
+ return this._localBounds;
16850
+ },
16851
+ set: function set(value) {
16852
+ if (this._localBounds !== value) {
16853
+ this._localBounds.copyFrom(value);
16854
+ }
16855
+ }
16856
+ },
16857
+ {
16858
+ key: "rootBone",
16859
+ get: /**
16860
+ * @deprecated use {@link SkinnedMeshRenderer.skin.rootBone} instead.
16861
+ */ function get() {
16862
+ return this.skin.rootBone;
16863
+ },
16864
+ set: function set(value) {
16865
+ this.skin.rootBone = value;
16866
+ }
16867
+ },
16868
+ {
16869
+ key: "bones",
16870
+ get: /**
16871
+ * @deprecated use {@link SkinnedMeshRenderer.skin.bones} instead.
16872
+ */ function get() {
16873
+ return this.skin.bones;
16874
+ },
16875
+ set: function set(value) {
16876
+ this.skin.bones = value;
16877
+ }
16878
+ }
16879
+ ]);
16880
+ return SkinnedMeshRenderer;
16881
+ }(MeshRenderer);
16882
+ (function() {
16883
+ SkinnedMeshRenderer._jointCountProperty = ShaderProperty.getByName("renderer_JointCount");
16884
+ })();
16885
+ (function() {
16886
+ SkinnedMeshRenderer._jointSamplerProperty = ShaderProperty.getByName("renderer_JointSampler");
16887
+ })();
16888
+ (function() {
16889
+ SkinnedMeshRenderer._jointMatrixProperty = ShaderProperty.getByName("renderer_JointMatrix");
16890
+ })();
16891
+ __decorate$1([
16892
+ ignoreClone
16893
+ ], SkinnedMeshRenderer.prototype, "_condensedBlendShapeWeights", void 0);
16894
+ __decorate$1([
16895
+ deepClone
16896
+ ], SkinnedMeshRenderer.prototype, "_localBounds", void 0);
16897
+ __decorate$1([
16898
+ ignoreClone
16899
+ ], SkinnedMeshRenderer.prototype, "_jointDataCreateCache", void 0);
16900
+ __decorate$1([
16901
+ ignoreClone
16902
+ ], SkinnedMeshRenderer.prototype, "_blendShapeWeights", void 0);
16903
+ __decorate$1([
16904
+ ignoreClone
16905
+ ], SkinnedMeshRenderer.prototype, "_maxVertexUniformVectors", void 0);
16906
+ __decorate$1([
16907
+ ignoreClone
16908
+ ], SkinnedMeshRenderer.prototype, "_jointTexture", void 0);
16909
+ __decorate$1([
16910
+ deepClone
16911
+ ], SkinnedMeshRenderer.prototype, "_skin", void 0);
16912
+ __decorate$1([
16913
+ ignoreClone
16914
+ ], SkinnedMeshRenderer.prototype, "_onLocalBoundsChanged", null);
16915
+ __decorate$1([
16916
+ ignoreClone
16917
+ ], SkinnedMeshRenderer.prototype, "_onSkinUpdated", null);
16918
+ /**
16919
+ * Class pool utils.
16920
+ */ var ClassPool = /*#__PURE__*/ function() {
16921
+ var ClassPool = function ClassPool(type) {
16922
+ this._elementPoolIndex = 0;
16923
+ this._elementPool = [];
16924
+ this._type = type;
16925
+ };
16926
+ var _proto = ClassPool.prototype;
16927
+ /**
16928
+ * Get element from pool.
16929
+ */ _proto.getFromPool = function getFromPool() {
16930
+ var _this = this, index = _this._elementPoolIndex, pool = _this._elementPool;
16931
+ this._elementPoolIndex++;
16932
+ if (pool.length === index) {
16933
+ var element = new this._type();
16934
+ pool.push(element);
16935
+ return element;
16936
+ } else {
16937
+ return pool[index];
16938
+ }
16939
+ };
16940
+ /**
16941
+ * Reset pool.
16942
+ */ _proto.resetPool = function resetPool() {
16943
+ this._elementPoolIndex = 0;
16944
+ };
16945
+ _proto.garbageCollection = function garbageCollection() {
16946
+ var _this = this, pool = _this._elementPool;
16947
+ for(var i = pool.length - 1; i >= 0; i--){
16948
+ pool[i].dispose && pool[i].dispose();
16949
+ }
16950
+ };
16951
+ return ClassPool;
16952
+ }();
16953
+ var Basic2DBatcher = /*#__PURE__*/ function() {
16954
+ var Basic2DBatcher = function Basic2DBatcher(engine) {
16955
+ /** @internal */ this._subMeshPool = new ClassPool(SubMesh);
16956
+ /** @internal */ this._batchedQueue = [];
16957
+ /** @internal */ this._meshes = [];
16958
+ /** @internal */ this._meshCount = 1;
16959
+ /** @internal */ this._vertexBuffers = [];
16960
+ /** @internal */ this._indiceBuffers = [];
16961
+ /** @internal */ this._flushId = 0;
16962
+ /** @internal */ this._vertexCount = 0;
16963
+ /** @internal */ this._elementCount = 0;
16964
+ this._engine = engine;
16965
+ this._initMeshes(engine);
16966
+ };
16967
+ var _proto = Basic2DBatcher.prototype;
16968
+ _proto.drawElement = function drawElement(element, camera) {
16969
+ var data = element.data;
16970
+ if (data.multiRenderData) {
16971
+ var charsData = data.charsData;
16972
+ var pool = camera.engine._renderElementPool;
16973
+ for(var i = 0, n = charsData.length; i < n; ++i){
16974
+ var charRenderElement = pool.getFromPool();
16975
+ charRenderElement.set(charsData[i], element.shaderPasses);
16976
+ this._drawSubElement(charRenderElement, camera);
16977
+ }
16978
+ } else {
16979
+ this._drawSubElement(element, camera);
16980
+ }
16981
+ };
16982
+ /**
16983
+ * @internal
16984
+ * Standalone for canvas 2d renderer plugin.
16985
+ */ _proto._initMeshes = function _initMeshes(engine) {
16986
+ var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
16987
+ this._vertices = new Float32Array(MAX_VERTEX_COUNT * 9);
16988
+ this._indices = new Uint16Array(MAX_VERTEX_COUNT * 3);
16989
+ var _this = this, _meshes = _this._meshes, _meshCount = _this._meshCount;
16990
+ for(var i = 0; i < _meshCount; i++){
16991
+ _meshes[i] = this._createMesh(engine, i);
16204
16992
  }
16205
16993
  };
16206
16994
  _proto.flush = function flush(camera) {
@@ -18755,7 +19543,7 @@
18755
19543
  */ _proto.cloneTo = function cloneTo(target) {
18756
19544
  target.shader = this.shader;
18757
19545
  this.shaderData.cloneTo(target.shaderData);
18758
- CloneManager.deepCloneObject(this.renderStates, target.renderStates);
19546
+ CloneManager.deepCloneObject(this.renderStates, target.renderStates, new Map());
18759
19547
  };
18760
19548
  _proto._addReferCount = function _addReferCount(value) {
18761
19549
  if (this._destroyed) return;
@@ -19668,887 +20456,316 @@
19668
20456
  if (value) {
19669
20457
  this.shaderData.enableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
19670
20458
  } else {
19671
- this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
19672
- }
19673
- }
19674
- }
19675
- ]);
19676
- return PBRMaterial;
19677
- }(PBRBaseMaterial);
19678
- (function() {
19679
- PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
19680
- })();
19681
- (function() {
19682
- PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
19683
- })();
19684
- (function() {
19685
- PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
19686
- })();
19687
- (function() {
19688
- PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
19689
- })();
19690
- (function() {
19691
- PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
19692
- })();
19693
- (function() {
19694
- PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
19695
- })();
19696
- /**
19697
- * PBR (Specular-Glossiness Workflow) Material.
19698
- */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
19699
- _inherits$2(PBRSpecularMaterial, PBRBaseMaterial1);
19700
- function PBRSpecularMaterial(engine) {
19701
- var _this;
19702
- _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
19703
- _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new Color(1, 1, 1, 1));
19704
- _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
19705
- return _this;
19706
- }
19707
- var _proto = PBRSpecularMaterial.prototype;
19708
- /**
19709
- * @inheritdoc
19710
- */ _proto.clone = function clone() {
19711
- var dest = new PBRSpecularMaterial(this._engine);
19712
- this.cloneTo(dest);
19713
- return dest;
19714
- };
19715
- _create_class$2(PBRSpecularMaterial, [
19716
- {
19717
- key: "specularColor",
19718
- get: /**
19719
- * Specular color.
19720
- */ function get() {
19721
- return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
19722
- },
19723
- set: function set(value) {
19724
- var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
19725
- if (value !== specularColor) {
19726
- specularColor.copyFrom(value);
19727
- }
19728
- }
19729
- },
19730
- {
19731
- key: "glossiness",
19732
- get: /**
19733
- * Glossiness.
19734
- */ function get() {
19735
- return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
19736
- },
19737
- set: function set(value) {
19738
- this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
19739
- }
19740
- },
19741
- {
19742
- key: "specularGlossinessTexture",
19743
- get: /**
19744
- * Specular glossiness texture.
19745
- * @remarks RGB is specular, A is glossiness
19746
- */ function get() {
19747
- return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
19748
- },
19749
- set: function set(value) {
19750
- this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
19751
- if (value) {
19752
- this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
19753
- } else {
19754
- this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
19755
- }
19756
- }
19757
- }
19758
- ]);
19759
- return PBRSpecularMaterial;
19760
- }(PBRBaseMaterial);
19761
- (function() {
19762
- PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
19763
- })();
19764
- (function() {
19765
- PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
19766
- })();
19767
- (function() {
19768
- PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
19769
- })();
19770
- (function() {
19771
- PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
19772
- })();
19773
- /**
19774
- * Unlit Material.
19775
- */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
19776
- _inherits$2(UnlitMaterial, BaseMaterial1);
19777
- function UnlitMaterial(engine) {
19778
- var _this;
19779
- _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
19780
- var shaderData = _this.shaderData;
19781
- shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
19782
- shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
19783
- shaderData.setColor(UnlitMaterial._baseColorProp, new Color(1, 1, 1, 1));
19784
- shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new Vector4(1, 1, 0, 0));
19785
- return _this;
19786
- }
19787
- var _proto = UnlitMaterial.prototype;
19788
- /**
19789
- * @inheritdoc
19790
- */ _proto.clone = function clone() {
19791
- var dest = new UnlitMaterial(this._engine);
19792
- this.cloneTo(dest);
19793
- return dest;
19794
- };
19795
- _create_class$2(UnlitMaterial, [
19796
- {
19797
- key: "baseColor",
19798
- get: /**
19799
- * Base color.
19800
- */ function get() {
19801
- return this.shaderData.getColor(UnlitMaterial._baseColorProp);
19802
- },
19803
- set: function set(value) {
19804
- var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
19805
- if (value !== baseColor) {
19806
- baseColor.copyFrom(value);
19807
- }
19808
- }
19809
- },
19810
- {
19811
- key: "baseTexture",
19812
- get: /**
19813
- * Base texture.
19814
- */ function get() {
19815
- return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
19816
- },
19817
- set: function set(value) {
19818
- this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
19819
- if (value) {
19820
- this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
19821
- } else {
19822
- this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
19823
- }
19824
- }
19825
- },
19826
- {
19827
- key: "tilingOffset",
19828
- get: /**
19829
- * Tiling and offset of main textures.
19830
- */ function get() {
19831
- return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
19832
- },
19833
- set: function set(value) {
19834
- var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
19835
- if (value !== tilingOffset) {
19836
- tilingOffset.copyFrom(value);
19837
- }
19838
- }
19839
- }
19840
- ]);
19841
- return UnlitMaterial;
19842
- }(BaseMaterial);
19843
- /**
19844
- * @internal
19845
- */ var BasicResources = /*#__PURE__*/ function() {
19846
- var BasicResources = function BasicResources(engine) {
19847
- // prettier-ignore
19848
- var vertices = new Float32Array([
19849
- -1,
19850
- -1,
19851
- 0,
19852
- 1,
19853
- 1,
19854
- -1,
19855
- 1,
19856
- 1,
19857
- -1,
19858
- 1,
19859
- 0,
19860
- 0,
19861
- 1,
19862
- 1,
19863
- 1,
19864
- 0
19865
- ]); // right-top
19866
- // prettier-ignore
19867
- var flipYVertices = new Float32Array([
19868
- 1,
19869
- -1,
19870
- 1,
19871
- 0,
19872
- -1,
19873
- -1,
19874
- 0,
19875
- 0,
19876
- 1,
19877
- 1,
19878
- 1,
19879
- 1,
19880
- -1,
19881
- 1,
19882
- 0,
19883
- 1
19884
- ]); // left-top
19885
- var blitMaterial = new Material(engine, Shader.find("blit"));
19886
- blitMaterial._addReferCount(1);
19887
- blitMaterial.renderState.depthState.enabled = false;
19888
- blitMaterial.renderState.depthState.writeEnabled = false;
19889
- this.blitMesh = this._createBlitMesh(engine, vertices);
19890
- this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
19891
- this.blitMaterial = blitMaterial;
19892
- };
19893
- var _proto = BasicResources.prototype;
19894
- _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
19895
- var mesh = new ModelMesh(engine);
19896
- mesh._addReferCount(1);
19897
- mesh.setVertexElements([
19898
- new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
19899
- ]);
19900
- mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
19901
- mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
19902
- return mesh;
19903
- };
19904
- return BasicResources;
19905
- }();
19906
- /**
19907
- * Layer, used for bit operations.
19908
- */ exports.Layer = void 0;
19909
- (function(Layer) {
19910
- Layer[Layer[/** Layer 0. */ "Layer0"] = 0x1] = "Layer0";
19911
- Layer[Layer[/** Layer 1. */ "Layer1"] = 0x2] = "Layer1";
19912
- Layer[Layer[/** Layer 2. */ "Layer2"] = 0x4] = "Layer2";
19913
- Layer[Layer[/** Layer 3. */ "Layer3"] = 0x8] = "Layer3";
19914
- Layer[Layer[/** Layer 4. */ "Layer4"] = 0x10] = "Layer4";
19915
- Layer[Layer[/** Layer 5. */ "Layer5"] = 0x20] = "Layer5";
19916
- Layer[Layer[/** Layer 6. */ "Layer6"] = 0x40] = "Layer6";
19917
- Layer[Layer[/** Layer 7. */ "Layer7"] = 0x80] = "Layer7";
19918
- Layer[Layer[/** Layer 8. */ "Layer8"] = 0x100] = "Layer8";
19919
- Layer[Layer[/** Layer 9. */ "Layer9"] = 0x200] = "Layer9";
19920
- Layer[Layer[/** Layer 10. */ "Layer10"] = 0x400] = "Layer10";
19921
- Layer[Layer[/** Layer 11. */ "Layer11"] = 0x800] = "Layer11";
19922
- Layer[Layer[/** Layer 12. */ "Layer12"] = 0x1000] = "Layer12";
19923
- Layer[Layer[/** Layer 13. */ "Layer13"] = 0x2000] = "Layer13";
19924
- Layer[Layer[/** Layer 14. */ "Layer14"] = 0x4000] = "Layer14";
19925
- Layer[Layer[/** Layer 15. */ "Layer15"] = 0x8000] = "Layer15";
19926
- Layer[Layer[/** Layer 16. */ "Layer16"] = 0x10000] = "Layer16";
19927
- Layer[Layer[/** Layer 17. */ "Layer17"] = 0x20000] = "Layer17";
19928
- Layer[Layer[/** Layer 18. */ "Layer18"] = 0x40000] = "Layer18";
19929
- Layer[Layer[/** Layer 19. */ "Layer19"] = 0x80000] = "Layer19";
19930
- Layer[Layer[/** Layer 20. */ "Layer20"] = 0x100000] = "Layer20";
19931
- Layer[Layer[/** Layer 21. */ "Layer21"] = 0x200000] = "Layer21";
19932
- Layer[Layer[/** Layer 22. */ "Layer22"] = 0x400000] = "Layer22";
19933
- Layer[Layer[/** Layer 23. */ "Layer23"] = 0x800000] = "Layer23";
19934
- Layer[Layer[/** Layer 24. */ "Layer24"] = 0x1000000] = "Layer24";
19935
- Layer[Layer[/** Layer 25. */ "Layer25"] = 0x2000000] = "Layer25";
19936
- Layer[Layer[/** Layer 26. */ "Layer26"] = 0x4000000] = "Layer26";
19937
- Layer[Layer[/** Layer 27. */ "Layer27"] = 0x8000000] = "Layer27";
19938
- Layer[Layer[/** Layer 28. */ "Layer28"] = 0x10000000] = "Layer28";
19939
- Layer[Layer[/** Layer 29. */ "Layer29"] = 0x20000000] = "Layer29";
19940
- Layer[Layer[/** Layer 30. */ "Layer30"] = 0x40000000] = "Layer30";
19941
- Layer[Layer[/** Layer 31. */ "Layer31"] = 0x80000000] = "Layer31";
19942
- Layer[Layer[/** All layers. */ "Everything"] = 0xffffffff] = "Everything";
19943
- Layer[Layer[/** None layer. */ "Nothing"] = 0x0] = "Nothing";
19944
- })(exports.Layer || (exports.Layer = {}));
19945
- var ComponentCloner = /*#__PURE__*/ function() {
19946
- var ComponentCloner = function ComponentCloner() {};
19947
- /**
19948
- * Clone component.
19949
- * @param source - Clone source
19950
- * @param target - Clone target
19951
- */ ComponentCloner.cloneComponent = function cloneComponent(source, target, srcRoot, targetRoot) {
19952
- var cloneModes = CloneManager.getCloneMode(source.constructor);
19953
- for(var k in source){
19954
- CloneManager.cloneProperty(source, target, k, cloneModes[k]);
19955
- }
19956
- if (source._cloneTo) {
19957
- source._cloneTo(target, srcRoot, targetRoot);
19958
- }
19959
- };
19960
- return ComponentCloner;
19961
- }();
19962
- /**
19963
- * Entity, be used as components container.
19964
- */ var Entity = /*#__PURE__*/ function(EngineObject1) {
19965
- var Entity = function Entity(engine, name1) {
19966
- var _this;
19967
- _this = EngineObject1.call(this, engine) || this;
19968
- /** The layer the entity belongs to. */ _this.layer = exports.Layer.Layer0;
19969
- /** @internal */ _this._isActiveInHierarchy = false;
19970
- /** @internal */ _this._isActiveInScene = false;
19971
- /** @internal */ _this._components = [];
19972
- /** @internal */ _this._scripts = new DisorderedArray();
19973
- /** @internal */ _this._children = [];
19974
- /** @internal */ _this._isRoot = false;
19975
- /** @internal */ _this._isActive = true;
19976
- /** @internal */ _this._siblingIndex = -1;
19977
- /** @internal */ _this._isTemplate = false;
19978
- _this._parent = null;
19979
- //--------------------------------------------------------------deprecated----------------------------------------------------------------
19980
- _this._invModelMatrix = new Matrix();
19981
- _this.name = name1;
19982
- _this.transform = _this.addComponent(Transform);
19983
- _this._inverseWorldMatFlag = _this.transform.registerWorldChangeFlag();
19984
- return _this;
19985
- };
19986
- _inherits$2(Entity, EngineObject1);
19987
- var _proto = Entity.prototype;
19988
- /**
19989
- * Add component based on the component type.
19990
- * @param type - The type of the component
19991
- * @returns The component which has been added
19992
- */ _proto.addComponent = function addComponent(type) {
19993
- ComponentsDependencies._addCheck(this, type);
19994
- var component = new type(this);
19995
- this._components.push(component);
19996
- component._setActive(true, ActiveChangeFlag.All);
19997
- return component;
19998
- };
19999
- /**
20000
- * Get component which match the type.
20001
- * @param type - The type of the component
20002
- * @returns The first component which match type
20003
- */ _proto.getComponent = function getComponent(type) {
20004
- var components = this._components;
20005
- for(var i = 0, n = components.length; i < n; i++){
20006
- var component = components[i];
20007
- if (_instanceof1$2(component, type)) {
20008
- return component;
20009
- }
20010
- }
20011
- return null;
20012
- };
20013
- /**
20014
- * Get components which match the type.
20015
- * @param type - The type of the component
20016
- * @param results - The components which match type
20017
- * @returns The components which match type
20018
- */ _proto.getComponents = function getComponents(type, results) {
20019
- results.length = 0;
20020
- var components = this._components;
20021
- for(var i = 0, n = components.length; i < n; i++){
20022
- var component = components[i];
20023
- if (_instanceof1$2(component, type)) {
20024
- results.push(component);
20025
- }
20026
- }
20027
- return results;
20028
- };
20029
- /**
20030
- * Get the components which match the type of the entity and it's children.
20031
- * @param type - The component type
20032
- * @param results - The components collection
20033
- * @returns The components collection which match the type
20034
- */ _proto.getComponentsIncludeChildren = function getComponentsIncludeChildren(type, results) {
20035
- results.length = 0;
20036
- this._getComponentsInChildren(type, results);
20037
- return results;
20038
- };
20039
- _proto.addChild = function addChild(indexOrChild, child) {
20040
- var index;
20041
- if (typeof indexOrChild === "number") {
20042
- index = indexOrChild;
20043
- } else {
20044
- index = undefined;
20045
- child = indexOrChild;
20046
- }
20047
- if (child._isRoot) {
20048
- child._scene._removeFromEntityList(child);
20049
- child._isRoot = false;
20050
- this._addToChildrenList(index, child);
20051
- child._parent = this;
20052
- var oldScene = child._scene;
20053
- var newScene = this._scene;
20054
- var inActiveChangeFlag = ActiveChangeFlag.None;
20055
- if (!this._isActiveInHierarchy) {
20056
- child._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
20057
- }
20058
- if (child._isActiveInScene) {
20059
- if (this._isActiveInScene) {
20060
- // Cross scene should inActive first and then active
20061
- oldScene !== newScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
20062
- } else {
20063
- inActiveChangeFlag |= ActiveChangeFlag.Scene;
20064
- }
20065
- }
20066
- inActiveChangeFlag && child._processInActive(inActiveChangeFlag);
20067
- if (child._scene !== newScene) {
20068
- Entity._traverseSetOwnerScene(child, newScene);
20069
- }
20070
- var activeChangeFlag = ActiveChangeFlag.None;
20071
- if (child._isActive) {
20072
- if (this._isActiveInHierarchy) {
20073
- !child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20074
- }
20075
- if (this._isActiveInScene) {
20076
- (!child._isActiveInScene || oldScene !== newScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
20077
- }
20078
- }
20079
- activeChangeFlag && child._processActive(activeChangeFlag);
20080
- child._setTransformDirty();
20081
- } else {
20082
- child._setParent(this, index);
20083
- }
20084
- };
20085
- /**
20086
- * Remove child entity.
20087
- * @param child - The child entity which want to be removed
20088
- */ _proto.removeChild = function removeChild(child) {
20089
- child._setParent(null);
20090
- };
20091
- /**
20092
- * @deprecated Please use `children` property instead.
20093
- * Find child entity by index.
20094
- * @param index - The index of the child entity
20095
- * @returns The component which be found
20096
- */ _proto.getChild = function getChild(index) {
20097
- return this._children[index];
20098
- };
20099
- /**
20100
- * Find entity by name.
20101
- * @param name - The name of the entity which want to be found
20102
- * @returns The component which be found
20103
- */ _proto.findByName = function findByName(name1) {
20104
- if (name1 === this.name) {
20105
- return this;
20106
- }
20107
- var children = this._children;
20108
- for(var i = 0, n = children.length; i < n; i++){
20109
- var target = children[i].findByName(name1);
20110
- if (target) {
20111
- return target;
20112
- }
20113
- }
20114
- return null;
20115
- };
20116
- /**
20117
- * Find the entity by path.
20118
- * @param path - The path fo the entity eg: /entity
20119
- * @returns The component which be found
20120
- */ _proto.findByPath = function findByPath(path) {
20121
- var splits = path.split("/");
20122
- var entity = this;
20123
- for(var i = 0, length = splits.length; i < length; ++i){
20124
- var split = splits[i];
20125
- if (split) {
20126
- entity = Entity._findChildByName(entity, split);
20127
- if (!entity) {
20128
- return null;
20129
- }
20130
- }
20131
- }
20132
- return entity;
20133
- };
20134
- /**
20135
- * Create child entity.
20136
- * @param name - The child entity's name
20137
- * @returns The child entity
20138
- */ _proto.createChild = function createChild(name1) {
20139
- var child = new Entity(this.engine, name1);
20140
- child.layer = this.layer;
20141
- child.parent = this;
20142
- return child;
20143
- };
20144
- /**
20145
- * Clear children entities.
20146
- */ _proto.clearChildren = function clearChildren() {
20147
- var children = this._children;
20148
- for(var i = children.length - 1; i >= 0; i--){
20149
- var child = children[i];
20150
- child._parent = null;
20151
- var activeChangeFlag = ActiveChangeFlag.None;
20152
- child._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20153
- child._isActiveInScene && (activeChangeFlag |= ActiveChangeFlag.Scene);
20154
- activeChangeFlag && child._processInActive(activeChangeFlag);
20155
- Entity._traverseSetOwnerScene(child, null); // Must after child._processInActive().
20156
- }
20157
- children.length = 0;
20158
- };
20159
- /**
20160
- * Clone.
20161
- * @returns Cloned entity
20162
- */ _proto.clone = function clone() {
20163
- var cloneEntity = this._createCloneEntity(this);
20164
- this._parseCloneEntity(this, cloneEntity, this, cloneEntity);
20165
- return cloneEntity;
20166
- };
20167
- /**
20168
- * @internal
20169
- */ _proto._markAsTemplate = function _markAsTemplate(templateResource) {
20170
- this._isTemplate = true;
20171
- this._templateResource = templateResource;
20172
- };
20173
- _proto._createCloneEntity = function _createCloneEntity(srcEntity) {
20174
- var cloneEntity = new Entity(srcEntity._engine, srcEntity.name);
20175
- var templateResource = this._templateResource;
20176
- if (templateResource) {
20177
- cloneEntity._templateResource = templateResource;
20178
- templateResource._addReferCount(1);
20179
- }
20180
- cloneEntity.layer = srcEntity.layer;
20181
- cloneEntity._isActive = srcEntity._isActive;
20182
- var cloneTransform = cloneEntity.transform;
20183
- var srcTransform = srcEntity.transform;
20184
- cloneTransform.position = srcTransform.position;
20185
- cloneTransform.rotation = srcTransform.rotation;
20186
- cloneTransform.scale = srcTransform.scale;
20187
- var children = srcEntity._children;
20188
- for(var i = 0, n = srcEntity._children.length; i < n; i++){
20189
- cloneEntity.addChild(this._createCloneEntity(children[i]));
20190
- }
20191
- return cloneEntity;
20192
- };
20193
- _proto._parseCloneEntity = function _parseCloneEntity(srcEntity, targetEntity, srcRoot, targetRoot) {
20194
- var srcChildren = srcEntity._children;
20195
- var targetChildren = targetEntity._children;
20196
- for(var i = 0, n = srcChildren.length; i < n; i++){
20197
- this._parseCloneEntity(srcChildren[i], targetChildren[i], srcRoot, targetRoot);
20198
- }
20199
- var components = srcEntity._components;
20200
- for(var i1 = 0, n1 = components.length; i1 < n1; i1++){
20201
- var sourceComp = components[i1];
20202
- if (!_instanceof1$2(sourceComp, Transform)) {
20203
- var targetComp = targetEntity.addComponent(sourceComp.constructor);
20204
- ComponentCloner.cloneComponent(sourceComp, targetComp, srcRoot, targetRoot);
20205
- }
20206
- }
20207
- };
20208
- /**
20209
- * Destroy self.
20210
- */ _proto.destroy = function destroy() {
20211
- if (this._destroyed) {
20212
- return;
20213
- }
20214
- EngineObject1.prototype.destroy.call(this);
20215
- if (this._templateResource) {
20216
- this._isTemplate || this._templateResource._addReferCount(-1);
20217
- this._templateResource = null;
20218
- }
20219
- var components = this._components;
20220
- for(var i = components.length - 1; i >= 0; i--){
20221
- components[i].destroy();
20222
- }
20223
- this._components.length = 0;
20224
- var children = this._children;
20225
- while(children.length > 0){
20226
- children[0].destroy();
20227
- }
20228
- if (this._isRoot) {
20229
- this._scene.removeRootEntity(this);
20230
- } else {
20231
- this._setParent(null);
20232
- }
20233
- this.isActive = false;
20234
- };
20235
- /**
20236
- * @internal
20237
- */ _proto._removeComponent = function _removeComponent(component) {
20238
- ComponentsDependencies._removeCheck(this, component.constructor);
20239
- var components = this._components;
20240
- components.splice(components.indexOf(component), 1);
20241
- };
20242
- /**
20243
- * @internal
20244
- */ _proto._addScript = function _addScript(script) {
20245
- script._entityScriptsIndex = this._scripts.length;
20246
- this._scripts.add(script);
20247
- };
20248
- /**
20249
- * @internal
20250
- */ _proto._removeScript = function _removeScript(script) {
20251
- var replaced = this._scripts.deleteByIndex(script._entityScriptsIndex);
20252
- replaced && (replaced._entityScriptsIndex = script._entityScriptsIndex);
20253
- script._entityScriptsIndex = -1;
20254
- };
20255
- /**
20256
- * @internal
20257
- */ _proto._removeFromParent = function _removeFromParent() {
20258
- var oldParent = this._parent;
20259
- if (oldParent != null) {
20260
- var oldSibling = oldParent._children;
20261
- var index = this._siblingIndex;
20262
- oldSibling.splice(index, 1);
20263
- for(var n = oldSibling.length; index < n; index++){
20264
- oldSibling[index]._siblingIndex--;
20265
- }
20266
- this._parent = null;
20267
- this._siblingIndex = -1;
20268
- }
20269
- };
20270
- /**
20271
- * @internal
20272
- */ _proto._processActive = function _processActive(activeChangeFlag) {
20273
- if (this._activeChangedComponents) {
20274
- 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.";
20275
- }
20276
- this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
20277
- this._setActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
20278
- this._setActiveComponents(true, activeChangeFlag);
20279
- };
20280
- /**
20281
- * @internal
20282
- */ _proto._processInActive = function _processInActive(activeChangeFlag) {
20283
- if (this._activeChangedComponents) {
20284
- 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.";
20285
- }
20286
- this._activeChangedComponents = this._scene._componentsManager.getActiveChangedTempList();
20287
- this._setInActiveInHierarchy(this._activeChangedComponents, activeChangeFlag);
20288
- this._setActiveComponents(false, activeChangeFlag);
20289
- };
20290
- _proto._addToChildrenList = function _addToChildrenList(index, child) {
20291
- var children = this._children;
20292
- var childCount = children.length;
20293
- if (index === undefined) {
20294
- child._siblingIndex = childCount;
20295
- children.push(child);
20296
- } else {
20297
- if (index < 0 || index > childCount) {
20298
- throw "The index " + index + " is out of child list bounds " + childCount;
20299
- }
20300
- child._siblingIndex = index;
20301
- children.splice(index, 0, child);
20302
- for(var i = index + 1, n = childCount + 1; i < n; i++){
20303
- children[i]._siblingIndex++;
20304
- }
20305
- }
20306
- };
20307
- _proto._setParent = function _setParent(parent, siblingIndex) {
20308
- var oldParent = this._parent;
20309
- if (parent !== oldParent) {
20310
- this._removeFromParent();
20311
- this._parent = parent;
20312
- if (parent) {
20313
- parent._addToChildrenList(siblingIndex, this);
20314
- var oldScene = this._scene;
20315
- var parentScene = parent._scene;
20316
- var inActiveChangeFlag = ActiveChangeFlag.None;
20317
- if (!parent._isActiveInHierarchy) {
20318
- this._isActiveInHierarchy && (inActiveChangeFlag |= ActiveChangeFlag.Hierarchy);
20319
- }
20320
- if (parent._isActiveInScene) {
20321
- // cross scene should inActive first and then active
20322
- this._isActiveInScene && oldScene !== parentScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
20323
- } else {
20324
- this._isActiveInScene && (inActiveChangeFlag |= ActiveChangeFlag.Scene);
20325
- }
20326
- inActiveChangeFlag && this._processInActive(inActiveChangeFlag);
20327
- if (oldScene !== parentScene) {
20328
- Entity._traverseSetOwnerScene(this, parentScene);
20329
- }
20330
- var activeChangeFlag = ActiveChangeFlag.None;
20331
- if (this._isActive) {
20332
- if (parent._isActiveInHierarchy) {
20333
- !this._isActiveInHierarchy && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20334
- }
20335
- if (parent._isActiveInScene) {
20336
- (!this._isActiveInScene || oldScene !== parentScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
20337
- }
20338
- }
20339
- activeChangeFlag && this._processActive(activeChangeFlag);
20340
- } else {
20341
- var inActiveChangeFlag1 = ActiveChangeFlag.None;
20342
- this._isActiveInHierarchy && (inActiveChangeFlag1 |= ActiveChangeFlag.Hierarchy);
20343
- this._isActiveInScene && (inActiveChangeFlag1 |= ActiveChangeFlag.Scene);
20344
- inActiveChangeFlag1 && this._processInActive(inActiveChangeFlag1);
20345
- if (oldParent) {
20346
- Entity._traverseSetOwnerScene(this, null);
20347
- }
20348
- }
20349
- this._setTransformDirty();
20350
- }
20351
- };
20352
- _proto._getComponentsInChildren = function _getComponentsInChildren(type, results) {
20353
- for(var i = this._components.length - 1; i >= 0; i--){
20354
- var component = this._components[i];
20355
- if (_instanceof1$2(component, type)) {
20356
- results.push(component);
20357
- }
20358
- }
20359
- for(var i1 = this._children.length - 1; i1 >= 0; i1--){
20360
- this._children[i1]._getComponentsInChildren(type, results);
20361
- }
20362
- };
20363
- _proto._setActiveComponents = function _setActiveComponents(isActive, activeChangeFlag) {
20364
- var activeChangedComponents = this._activeChangedComponents;
20365
- for(var i = 0, length = activeChangedComponents.length; i < length; ++i){
20366
- activeChangedComponents[i]._setActive(isActive, activeChangeFlag);
20367
- }
20368
- this._scene._componentsManager.putActiveChangedTempList(activeChangedComponents);
20369
- this._activeChangedComponents = null;
20370
- };
20371
- _proto._setActiveInHierarchy = function _setActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
20372
- activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = true);
20373
- activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = true);
20374
- var components = this._components;
20375
- for(var i = 0, n = components.length; i < n; i++){
20376
- var component = components[i];
20377
- (component.enabled || !component._awoken) && activeChangedComponents.push(component);
20378
- }
20379
- var children = this._children;
20380
- for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
20381
- var child = children[i1];
20382
- child.isActive && child._setActiveInHierarchy(activeChangedComponents, activeChangeFlag);
20383
- }
20384
- };
20385
- _proto._setInActiveInHierarchy = function _setInActiveInHierarchy(activeChangedComponents, activeChangeFlag) {
20386
- activeChangeFlag & ActiveChangeFlag.Hierarchy && (this._isActiveInHierarchy = false);
20387
- activeChangeFlag & ActiveChangeFlag.Scene && (this._isActiveInScene = false);
20388
- var components = this._components;
20389
- for(var i = 0, n = components.length; i < n; i++){
20390
- var component = components[i];
20391
- component.enabled && activeChangedComponents.push(component);
20392
- }
20393
- var children = this._children;
20394
- for(var i1 = 0, n1 = children.length; i1 < n1; i1++){
20395
- var child = children[i1];
20396
- child.isActive && child._setInActiveInHierarchy(activeChangedComponents, activeChangeFlag);
20397
- }
20398
- };
20399
- _proto._setTransformDirty = function _setTransformDirty() {
20400
- if (this.transform) {
20401
- this.transform._parentChange();
20402
- } else {
20403
- for(var i = 0, len = this._children.length; i < len; i++){
20404
- this._children[i]._setTransformDirty();
20405
- }
20406
- }
20407
- };
20408
- _proto._setSiblingIndex = function _setSiblingIndex(sibling, target) {
20409
- target = Math.min(target, sibling.length - 1);
20410
- if (target < 0) {
20411
- throw "Sibling index " + target + " should large than 0";
20412
- }
20413
- if (this._siblingIndex !== target) {
20414
- var oldIndex = this._siblingIndex;
20415
- if (target < oldIndex) {
20416
- for(var i = oldIndex; i >= target; i--){
20417
- var child = i == target ? this : sibling[i - 1];
20418
- sibling[i] = child;
20419
- child._siblingIndex = i;
20420
- }
20421
- } else {
20422
- for(var i1 = oldIndex; i1 <= target; i1++){
20423
- var child1 = i1 == target ? this : sibling[i1 + 1];
20424
- sibling[i1] = child1;
20425
- child1._siblingIndex = i1;
20426
- }
20427
- }
20428
- }
20429
- };
20430
- /**
20431
- * @deprecated
20432
- */ _proto.getInvModelMatrix = function getInvModelMatrix() {
20433
- if (this._inverseWorldMatFlag.flag) {
20434
- Matrix.invert(this.transform.worldMatrix, this._invModelMatrix);
20435
- this._inverseWorldMatFlag.flag = false;
20436
- }
20437
- return this._invModelMatrix;
20438
- };
20439
- /**
20440
- * @internal
20441
- */ Entity._findChildByName = function _findChildByName(root, name1) {
20442
- var children = root._children;
20443
- for(var i = children.length - 1; i >= 0; i--){
20444
- var child = children[i];
20445
- if (child.name === name1) {
20446
- return child;
20447
- }
20448
- }
20449
- return null;
20450
- };
20451
- /**
20452
- * @internal
20453
- */ Entity._traverseSetOwnerScene = function _traverseSetOwnerScene(entity, scene) {
20454
- entity._scene = scene;
20455
- var children = entity._children;
20456
- for(var i = children.length - 1; i >= 0; i--){
20457
- this._traverseSetOwnerScene(children[i], scene);
20459
+ this.shaderData.disableMacro("MATERIAL_HAS_ANISOTROPY_TEXTURE");
20460
+ }
20461
+ }
20458
20462
  }
20463
+ ]);
20464
+ return PBRMaterial;
20465
+ }(PBRBaseMaterial);
20466
+ (function() {
20467
+ PBRMaterial._metallicProp = ShaderProperty.getByName("material_Metal");
20468
+ })();
20469
+ (function() {
20470
+ PBRMaterial._roughnessProp = ShaderProperty.getByName("material_Roughness");
20471
+ })();
20472
+ (function() {
20473
+ PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
20474
+ })();
20475
+ (function() {
20476
+ PBRMaterial._iorProp = ShaderProperty.getByName("material_IOR");
20477
+ })();
20478
+ (function() {
20479
+ PBRMaterial._anisotropyInfoProp = ShaderProperty.getByName("material_AnisotropyInfo");
20480
+ })();
20481
+ (function() {
20482
+ PBRMaterial._anisotropyTextureProp = ShaderProperty.getByName("material_AnisotropyTexture");
20483
+ })();
20484
+ /**
20485
+ * PBR (Specular-Glossiness Workflow) Material.
20486
+ */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial1) {
20487
+ _inherits$2(PBRSpecularMaterial, PBRBaseMaterial1);
20488
+ function PBRSpecularMaterial(engine) {
20489
+ var _this;
20490
+ _this = PBRBaseMaterial1.call(this, engine, Shader.find("pbr-specular")) || this;
20491
+ _this.shaderData.setColor(PBRSpecularMaterial._specularColorProp, new Color(1, 1, 1, 1));
20492
+ _this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, 1.0);
20493
+ return _this;
20494
+ }
20495
+ var _proto = PBRSpecularMaterial.prototype;
20496
+ /**
20497
+ * @inheritdoc
20498
+ */ _proto.clone = function clone() {
20499
+ var dest = new PBRSpecularMaterial(this._engine);
20500
+ this.cloneTo(dest);
20501
+ return dest;
20459
20502
  };
20460
- _create_class$2(Entity, [
20503
+ _create_class$2(PBRSpecularMaterial, [
20461
20504
  {
20462
- key: "isActive",
20505
+ key: "specularColor",
20463
20506
  get: /**
20464
- * Whether to activate locally.
20507
+ * Specular color.
20465
20508
  */ function get() {
20466
- return this._isActive;
20509
+ return this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20467
20510
  },
20468
20511
  set: function set(value) {
20469
- if (value !== this._isActive) {
20470
- this._isActive = value;
20471
- if (value) {
20472
- var parent = this._parent;
20473
- var activeChangeFlag = ActiveChangeFlag.None;
20474
- if (this._isRoot && this._scene._isActiveInEngine) {
20475
- activeChangeFlag |= ActiveChangeFlag.All;
20476
- } else {
20477
- var _parent, _parent1;
20478
- ((_parent = parent) == null ? void 0 : _parent._isActiveInHierarchy) && (activeChangeFlag |= ActiveChangeFlag.Hierarchy);
20479
- ((_parent1 = parent) == null ? void 0 : _parent1._isActiveInScene) && (activeChangeFlag |= ActiveChangeFlag.Scene);
20480
- }
20481
- activeChangeFlag && this._processActive(activeChangeFlag);
20482
- } else {
20483
- var activeChangeFlag1 = ActiveChangeFlag.None;
20484
- this._isActiveInHierarchy && (activeChangeFlag1 |= ActiveChangeFlag.Hierarchy);
20485
- this._isActiveInScene && (activeChangeFlag1 |= ActiveChangeFlag.Scene);
20486
- activeChangeFlag1 && this._processInActive(activeChangeFlag1);
20487
- }
20512
+ var specularColor = this.shaderData.getColor(PBRSpecularMaterial._specularColorProp);
20513
+ if (value !== specularColor) {
20514
+ specularColor.copyFrom(value);
20488
20515
  }
20489
20516
  }
20490
20517
  },
20491
20518
  {
20492
- key: "isActiveInHierarchy",
20493
- get: /**
20494
- * Whether it is active in the hierarchy.
20495
- */ function get() {
20496
- return this._isActiveInHierarchy;
20497
- }
20498
- },
20499
- {
20500
- key: "parent",
20519
+ key: "glossiness",
20501
20520
  get: /**
20502
- * The parent entity.
20521
+ * Glossiness.
20503
20522
  */ function get() {
20504
- return this._parent;
20523
+ return this.shaderData.getFloat(PBRSpecularMaterial._glossinessProp);
20505
20524
  },
20506
20525
  set: function set(value) {
20507
- this._setParent(value);
20526
+ this.shaderData.setFloat(PBRSpecularMaterial._glossinessProp, value);
20508
20527
  }
20509
20528
  },
20510
20529
  {
20511
- key: "children",
20530
+ key: "specularGlossinessTexture",
20512
20531
  get: /**
20513
- * The children entities
20532
+ * Specular glossiness texture.
20533
+ * @remarks RGB is specular, A is glossiness
20514
20534
  */ function get() {
20515
- return this._children;
20535
+ return this.shaderData.getTexture(PBRSpecularMaterial._specularGlossinessTextureProp);
20536
+ },
20537
+ set: function set(value) {
20538
+ this.shaderData.setTexture(PBRSpecularMaterial._specularGlossinessTextureProp, value);
20539
+ if (value) {
20540
+ this.shaderData.enableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20541
+ } else {
20542
+ this.shaderData.disableMacro(PBRSpecularMaterial._specularGlossinessTextureMacro);
20543
+ }
20516
20544
  }
20517
- },
20545
+ }
20546
+ ]);
20547
+ return PBRSpecularMaterial;
20548
+ }(PBRBaseMaterial);
20549
+ (function() {
20550
+ PBRSpecularMaterial._specularColorProp = ShaderProperty.getByName("material_PBRSpecularColor");
20551
+ })();
20552
+ (function() {
20553
+ PBRSpecularMaterial._glossinessProp = ShaderProperty.getByName("material_Glossiness");
20554
+ })();
20555
+ (function() {
20556
+ PBRSpecularMaterial._specularGlossinessTextureProp = ShaderProperty.getByName("material_SpecularGlossinessTexture");
20557
+ })();
20558
+ (function() {
20559
+ PBRSpecularMaterial._specularGlossinessTextureMacro = ShaderMacro.getByName("MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE");
20560
+ })();
20561
+ /**
20562
+ * Unlit Material.
20563
+ */ var UnlitMaterial = /*#__PURE__*/ function(BaseMaterial1) {
20564
+ _inherits$2(UnlitMaterial, BaseMaterial1);
20565
+ function UnlitMaterial(engine) {
20566
+ var _this;
20567
+ _this = BaseMaterial1.call(this, engine, Shader.find("unlit")) || this;
20568
+ var shaderData = _this.shaderData;
20569
+ shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
20570
+ shaderData.enableMacro("MATERIAL_NEED_TILING_OFFSET");
20571
+ shaderData.setColor(UnlitMaterial._baseColorProp, new Color(1, 1, 1, 1));
20572
+ shaderData.setVector4(UnlitMaterial._tilingOffsetProp, new Vector4(1, 1, 0, 0));
20573
+ return _this;
20574
+ }
20575
+ var _proto = UnlitMaterial.prototype;
20576
+ /**
20577
+ * @inheritdoc
20578
+ */ _proto.clone = function clone() {
20579
+ var dest = new UnlitMaterial(this._engine);
20580
+ this.cloneTo(dest);
20581
+ return dest;
20582
+ };
20583
+ _create_class$2(UnlitMaterial, [
20518
20584
  {
20519
- key: "childCount",
20585
+ key: "baseColor",
20520
20586
  get: /**
20521
- * @deprecated Please use `children.length` property instead.
20522
- * Number of the children entities
20587
+ * Base color.
20523
20588
  */ function get() {
20524
- return this._children.length;
20589
+ return this.shaderData.getColor(UnlitMaterial._baseColorProp);
20590
+ },
20591
+ set: function set(value) {
20592
+ var baseColor = this.shaderData.getColor(UnlitMaterial._baseColorProp);
20593
+ if (value !== baseColor) {
20594
+ baseColor.copyFrom(value);
20595
+ }
20525
20596
  }
20526
20597
  },
20527
20598
  {
20528
- key: "scene",
20599
+ key: "baseTexture",
20529
20600
  get: /**
20530
- * The scene the entity belongs to.
20601
+ * Base texture.
20531
20602
  */ function get() {
20532
- return this._scene;
20603
+ return this.shaderData.getTexture(UnlitMaterial._baseTextureProp);
20604
+ },
20605
+ set: function set(value) {
20606
+ this.shaderData.setTexture(UnlitMaterial._baseTextureProp, value);
20607
+ if (value) {
20608
+ this.shaderData.enableMacro(UnlitMaterial._baseTextureMacro);
20609
+ } else {
20610
+ this.shaderData.disableMacro(UnlitMaterial._baseTextureMacro);
20611
+ }
20533
20612
  }
20534
20613
  },
20535
20614
  {
20536
- key: "siblingIndex",
20615
+ key: "tilingOffset",
20537
20616
  get: /**
20538
- * The sibling index.
20617
+ * Tiling and offset of main textures.
20539
20618
  */ function get() {
20540
- return this._siblingIndex;
20619
+ return this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20541
20620
  },
20542
20621
  set: function set(value) {
20543
- if (this._siblingIndex === -1) {
20544
- throw "The entity " + this.name + " is not in the hierarchy";
20622
+ var tilingOffset = this.shaderData.getVector4(UnlitMaterial._tilingOffsetProp);
20623
+ if (value !== tilingOffset) {
20624
+ tilingOffset.copyFrom(value);
20545
20625
  }
20546
- this._setSiblingIndex(this._isRoot ? this._scene._rootEntities : this._parent._children, value);
20547
20626
  }
20548
20627
  }
20549
20628
  ]);
20550
- return Entity;
20551
- }(EngineObject);
20629
+ return UnlitMaterial;
20630
+ }(BaseMaterial);
20631
+ /**
20632
+ * @internal
20633
+ */ var BasicResources = /*#__PURE__*/ function() {
20634
+ var BasicResources = function BasicResources(engine) {
20635
+ // prettier-ignore
20636
+ var vertices = new Float32Array([
20637
+ -1,
20638
+ -1,
20639
+ 0,
20640
+ 1,
20641
+ 1,
20642
+ -1,
20643
+ 1,
20644
+ 1,
20645
+ -1,
20646
+ 1,
20647
+ 0,
20648
+ 0,
20649
+ 1,
20650
+ 1,
20651
+ 1,
20652
+ 0
20653
+ ]); // right-top
20654
+ // prettier-ignore
20655
+ var flipYVertices = new Float32Array([
20656
+ 1,
20657
+ -1,
20658
+ 1,
20659
+ 0,
20660
+ -1,
20661
+ -1,
20662
+ 0,
20663
+ 0,
20664
+ 1,
20665
+ 1,
20666
+ 1,
20667
+ 1,
20668
+ -1,
20669
+ 1,
20670
+ 0,
20671
+ 1
20672
+ ]); // left-top
20673
+ var blitMaterial = new Material(engine, Shader.find("blit"));
20674
+ blitMaterial._addReferCount(1);
20675
+ blitMaterial.renderState.depthState.enabled = false;
20676
+ blitMaterial.renderState.depthState.writeEnabled = false;
20677
+ this.blitMesh = this._createBlitMesh(engine, vertices);
20678
+ this.flipYBlitMesh = this._createBlitMesh(engine, flipYVertices);
20679
+ this.blitMaterial = blitMaterial;
20680
+ // Create white and magenta textures
20681
+ var whitePixel = new Uint8Array([
20682
+ 255,
20683
+ 255,
20684
+ 255,
20685
+ 255
20686
+ ]);
20687
+ this.whiteTexture2D = this._create1x1Texture(engine, 0, exports.TextureFormat.R8G8B8A8, whitePixel);
20688
+ this.whiteTextureCube = this._create1x1Texture(engine, 1, exports.TextureFormat.R8G8B8A8, whitePixel);
20689
+ var isWebGL2 = engine._hardwareRenderer.isWebGL2;
20690
+ if (isWebGL2) {
20691
+ this.whiteTexture2DArray = this._create1x1Texture(engine, 2, exports.TextureFormat.R8G8B8A8, whitePixel);
20692
+ var whitePixel32 = new Uint32Array([
20693
+ 255,
20694
+ 255,
20695
+ 255,
20696
+ 255
20697
+ ]);
20698
+ this.uintWhiteTexture2D = this._create1x1Texture(engine, 0, exports.TextureFormat.R32G32B32A32_UInt, whitePixel32);
20699
+ }
20700
+ };
20701
+ var _proto = BasicResources.prototype;
20702
+ _proto._createBlitMesh = function _createBlitMesh(engine, vertices) {
20703
+ var mesh = new ModelMesh(engine);
20704
+ mesh._addReferCount(1);
20705
+ mesh.setVertexElements([
20706
+ new VertexElement("POSITION_UV", 0, exports.VertexElementFormat.Vector4, 0)
20707
+ ]);
20708
+ mesh.setVertexBufferBinding(new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices, exports.BufferUsage.Static), 16);
20709
+ mesh.addSubMesh(0, 4, exports.MeshTopology.TriangleStrip);
20710
+ return mesh;
20711
+ };
20712
+ _proto._create1x1Texture = function _create1x1Texture(engine, type, format, pixel) {
20713
+ var texture;
20714
+ switch(type){
20715
+ case 0:
20716
+ var texture2D = new Texture2D(engine, 1, 1, format, false);
20717
+ texture2D.setPixelBuffer(pixel);
20718
+ texture = texture2D;
20719
+ break;
20720
+ case 2:
20721
+ var texture2DArray = new Texture2DArray(engine, 1, 1, 1, format, false);
20722
+ texture2DArray.setPixelBuffer(0, pixel);
20723
+ texture = texture2DArray;
20724
+ break;
20725
+ case 1:
20726
+ var textureCube = new TextureCube(engine, 1, format, false);
20727
+ for(var i = 0; i < 6; i++){
20728
+ textureCube.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, pixel);
20729
+ }
20730
+ texture = textureCube;
20731
+ break;
20732
+ default:
20733
+ throw "Invalid texture type";
20734
+ }
20735
+ texture.isGCIgnored = true;
20736
+ engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
20737
+ var _class = function _class() {
20738
+ return ContentRestorer.call(this, texture);
20739
+ };
20740
+ _inherits$2(_class, ContentRestorer);
20741
+ var _proto = _class.prototype;
20742
+ _proto.restoreContent = function restoreContent() {
20743
+ switch(type){
20744
+ case 0:
20745
+ this.resource.setPixelBuffer(pixel);
20746
+ break;
20747
+ case 2:
20748
+ this.resource.setPixelBuffer(0, pixel);
20749
+ break;
20750
+ case 1:
20751
+ for(var i = 0; i < 6; i++){
20752
+ this.resource.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, pixel);
20753
+ }
20754
+ break;
20755
+ }
20756
+ };
20757
+ return _class;
20758
+ }(ContentRestorer))());
20759
+ return texture;
20760
+ };
20761
+ return BasicResources;
20762
+ }();
20763
+ var TextureType;
20764
+ (function(TextureType) {
20765
+ TextureType[TextureType["Texture2D"] = 0] = "Texture2D";
20766
+ TextureType[TextureType["TextureCube"] = 1] = "TextureCube";
20767
+ TextureType[TextureType["Texture2DArray"] = 2] = "Texture2DArray";
20768
+ })(TextureType || (TextureType = {}));
20552
20769
  /**
20553
20770
  * @internal
20554
20771
  * Rendering context.
@@ -20852,8 +21069,6 @@
20852
21069
  AssetType[/** 2D Texture. */ "Texture2D"] = "Texture2D";
20853
21070
  AssetType[/** Cube Texture. */ "TextureCube"] = "TextureCube";
20854
21071
  AssetType[/** Material. */ "Material"] = "Material";
20855
- AssetType[/** Shader */ "Shader"] = "Shader";
20856
- AssetType[/** Shader Chunk */ "ShaderChunk"] = "ShaderChunk";
20857
21072
  AssetType[/** Mesh. */ "Mesh"] = "Mesh";
20858
21073
  AssetType[/** AnimationClip. */ "AnimationClip"] = "AnimationClip";
20859
21074
  AssetType[/** AnimatorController. */ "AnimatorController"] = "AnimatorController";
@@ -21330,17 +21545,33 @@
21330
21545
  };
21331
21546
  /**
21332
21547
  * @internal
21333
- */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(assetURL, value) {
21334
- var _this__subAssetPromiseCallbacks_assetURL;
21335
- (_this__subAssetPromiseCallbacks_assetURL = this._subAssetPromiseCallbacks[assetURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetURL.resolve(value);
21336
- delete this._subAssetPromiseCallbacks[assetURL];
21548
+ */ _proto._onSubAssetSuccess = function _onSubAssetSuccess(assetBaseURL, assetSubPath, value) {
21549
+ var _this__subAssetPromiseCallbacks_assetBaseURL;
21550
+ var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
21551
+ if (subPromiseCallback) {
21552
+ // Already resolved
21553
+ subPromiseCallback.resolve(value);
21554
+ } else {
21555
+ var _this__subAssetPromiseCallbacks, _assetBaseURL;
21556
+ ((_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
21557
+ resolve: value
21558
+ };
21559
+ }
21337
21560
  };
21338
21561
  /**
21339
21562
  * @internal
21340
- */ _proto._onSubAssetFail = function _onSubAssetFail(assetURL, value) {
21341
- var _this__subAssetPromiseCallbacks_assetURL;
21342
- (_this__subAssetPromiseCallbacks_assetURL = this._subAssetPromiseCallbacks[assetURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetURL.reject(value);
21343
- delete this._subAssetPromiseCallbacks[assetURL];
21563
+ */ _proto._onSubAssetFail = function _onSubAssetFail(assetBaseURL, assetSubPath, value) {
21564
+ var _this__subAssetPromiseCallbacks_assetBaseURL;
21565
+ var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
21566
+ if (subPromiseCallback) {
21567
+ // Already rejected
21568
+ subPromiseCallback.reject(value);
21569
+ } else {
21570
+ var _this__subAssetPromiseCallbacks, _assetBaseURL;
21571
+ ((_this__subAssetPromiseCallbacks = this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
21572
+ reject: value
21573
+ };
21574
+ }
21344
21575
  };
21345
21576
  /**
21346
21577
  * @internal
@@ -21485,8 +21716,21 @@
21485
21716
  if (!loader) {
21486
21717
  throw "loader not found: " + item.type;
21487
21718
  }
21488
- // Load asset
21719
+ // Check sub asset
21720
+ if (queryPath) {
21721
+ // Check whether load main asset
21722
+ var mainPromise = loadingPromises[assetBaseURL] || this._loadMainAsset(loader, item, assetBaseURL);
21723
+ mainPromise.catch(function(e) {
21724
+ _this._onSubAssetFail(assetBaseURL, queryPath, e);
21725
+ });
21726
+ return this._createSubAssetPromiseCallback(assetBaseURL, assetURL, queryPath);
21727
+ }
21728
+ return this._loadMainAsset(loader, item, assetBaseURL);
21729
+ };
21730
+ _proto._loadMainAsset = function _loadMainAsset(loader, item, assetBaseURL) {
21731
+ var _this = this;
21489
21732
  item.url = assetBaseURL;
21733
+ var loadingPromises = this._loadingPromises;
21490
21734
  var promise = loader.load(item, this);
21491
21735
  loadingPromises[assetBaseURL] = promise;
21492
21736
  promise.then(function(resource) {
@@ -21494,32 +21738,46 @@
21494
21738
  _this._addAsset(assetBaseURL, resource);
21495
21739
  }
21496
21740
  delete loadingPromises[assetBaseURL];
21741
+ _this._releaseSubAssetPromiseCallback(assetBaseURL);
21497
21742
  }, function() {
21498
- return delete loadingPromises[assetBaseURL];
21743
+ delete loadingPromises[assetBaseURL];
21744
+ _this._releaseSubAssetPromiseCallback(assetBaseURL);
21499
21745
  });
21500
- if (queryPath) {
21501
- var subPromise = new AssetPromise(function(resolve, reject) {
21502
- _this._pushSubAssetPromiseCallback(assetURL, resolve, reject);
21503
- });
21504
- loadingPromises[assetURL] = subPromise;
21505
- subPromise.then(function() {
21746
+ return promise;
21747
+ };
21748
+ _proto._createSubAssetPromiseCallback = function _createSubAssetPromiseCallback(assetBaseURL, assetURL, assetSubPath) {
21749
+ var _this = this;
21750
+ var _this__subAssetPromiseCallbacks_assetBaseURL, _subPromiseCallback, _subPromiseCallback1;
21751
+ var loadingPromises = this._loadingPromises;
21752
+ var subPromiseCallback = (_this__subAssetPromiseCallbacks_assetBaseURL = this._subAssetPromiseCallbacks[assetBaseURL]) == null ? void 0 : _this__subAssetPromiseCallbacks_assetBaseURL[assetSubPath];
21753
+ var resolvedValue = (_subPromiseCallback = subPromiseCallback) == null ? void 0 : _subPromiseCallback.resolve;
21754
+ var rejectedValue = (_subPromiseCallback1 = subPromiseCallback) == null ? void 0 : _subPromiseCallback1.reject;
21755
+ var promise = new AssetPromise(function(resolve, reject) {
21756
+ if (resolvedValue) {
21757
+ // Already resolved
21758
+ resolve(resolvedValue);
21759
+ } else if (rejectedValue) {
21760
+ // Already rejected
21761
+ reject(rejectedValue);
21762
+ } else {
21763
+ var _this__subAssetPromiseCallbacks, _assetBaseURL;
21764
+ // Pending
21765
+ loadingPromises[assetURL] = promise;
21766
+ ((_this__subAssetPromiseCallbacks = _this._subAssetPromiseCallbacks)[_assetBaseURL = assetBaseURL] || (_this__subAssetPromiseCallbacks[_assetBaseURL] = {}))[assetSubPath] = {
21767
+ resolve: resolve,
21768
+ reject: reject
21769
+ };
21770
+ }
21771
+ });
21772
+ if (!resolvedValue && !rejectedValue) {
21773
+ promise.then(function() {
21506
21774
  delete loadingPromises[assetURL];
21507
21775
  }, function() {
21508
21776
  return delete loadingPromises[assetURL];
21509
21777
  });
21510
- promise.catch(function(e) {
21511
- _this._onSubAssetFail(assetURL, e);
21512
- });
21513
- return subPromise;
21514
21778
  }
21515
21779
  return promise;
21516
21780
  };
21517
- _proto._pushSubAssetPromiseCallback = function _pushSubAssetPromiseCallback(assetURL, resolve, reject) {
21518
- this._subAssetPromiseCallbacks[assetURL] = {
21519
- resolve: resolve,
21520
- reject: reject
21521
- };
21522
- };
21523
21781
  _proto._gc = function _gc(forceDestroy) {
21524
21782
  var objects = Utils.objectValues(this._referResourcePool);
21525
21783
  for(var i = 0, n = objects.length; i < n; i++){
@@ -21576,6 +21834,9 @@
21576
21834
  });
21577
21835
  return result;
21578
21836
  };
21837
+ _proto._releaseSubAssetPromiseCallback = function _releaseSubAssetPromiseCallback(assetBaseURL) {
21838
+ delete this._subAssetPromiseCallbacks[assetBaseURL];
21839
+ };
21579
21840
  /**
21580
21841
  * @internal
21581
21842
  * @beta Just for internal editor, not recommended for developers.
@@ -25000,7 +25261,6 @@
25000
25261
  _this.xrManager = new XRManager();
25001
25262
  _this.xrManager._initialize(_assert_this_initialized(_this), xrDevice);
25002
25263
  }
25003
- _this._initMagentaTextures(hardwareRenderer);
25004
25264
  if (!hardwareRenderer.canIUse(exports.GLCapabilityType.depthTexture)) {
25005
25265
  _this._macroCollection.enable(Engine._noDepthTextureMacro);
25006
25266
  } else {
@@ -25236,99 +25496,6 @@
25236
25496
  };
25237
25497
  /**
25238
25498
  * @internal
25239
- * Standalone for CanvasRenderer plugin.
25240
- */ _proto._initMagentaTextures = function _initMagentaTextures(hardwareRenderer) {
25241
- var whitePixel = new Uint8Array([
25242
- 255,
25243
- 255,
25244
- 255,
25245
- 255
25246
- ]);
25247
- var whiteTexture2D = new Texture2D(this, 1, 1, exports.TextureFormat.R8G8B8A8, false);
25248
- whiteTexture2D.setPixelBuffer(whitePixel);
25249
- whiteTexture2D.isGCIgnored = true;
25250
- var magentaPixel = new Uint8Array([
25251
- 255,
25252
- 0,
25253
- 255,
25254
- 255
25255
- ]);
25256
- var magentaTexture2D = new Texture2D(this, 1, 1, exports.TextureFormat.R8G8B8A8, false);
25257
- magentaTexture2D.setPixelBuffer(magentaPixel);
25258
- magentaTexture2D.isGCIgnored = true;
25259
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25260
- var _class = function _class() {
25261
- return ContentRestorer.call(this, magentaTexture2D);
25262
- };
25263
- _inherits$2(_class, ContentRestorer);
25264
- var _proto = _class.prototype;
25265
- _proto.restoreContent = function restoreContent() {
25266
- this.resource.setPixelBuffer(magentaPixel);
25267
- };
25268
- return _class;
25269
- }(ContentRestorer))());
25270
- var magentaTextureCube = new TextureCube(this, 1, exports.TextureFormat.R8G8B8A8, false);
25271
- for(var i = 0; i < 6; i++){
25272
- magentaTextureCube.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, magentaPixel);
25273
- }
25274
- magentaTextureCube.isGCIgnored = true;
25275
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25276
- var _class = function _class() {
25277
- return ContentRestorer.call(this, magentaTextureCube);
25278
- };
25279
- _inherits$2(_class, ContentRestorer);
25280
- var _proto = _class.prototype;
25281
- _proto.restoreContent = function restoreContent() {
25282
- for(var i = 0; i < 6; i++){
25283
- this.resource.setPixelBuffer(exports.TextureCubeFace.PositiveX + i, magentaPixel);
25284
- }
25285
- };
25286
- return _class;
25287
- }(ContentRestorer))());
25288
- this._whiteTexture2D = whiteTexture2D;
25289
- this._magentaTexture2D = magentaTexture2D;
25290
- this._magentaTextureCube = magentaTextureCube;
25291
- if (hardwareRenderer.isWebGL2) {
25292
- var magentaPixel32 = new Uint32Array([
25293
- 255,
25294
- 0,
25295
- 255,
25296
- 255
25297
- ]);
25298
- var uintMagentaTexture2D = new Texture2D(this, 1, 1, exports.TextureFormat.R32G32B32A32_UInt, false);
25299
- uintMagentaTexture2D.setPixelBuffer(magentaPixel32);
25300
- uintMagentaTexture2D.isGCIgnored = true;
25301
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25302
- var _class = function _class() {
25303
- return ContentRestorer.call(this, uintMagentaTexture2D);
25304
- };
25305
- _inherits$2(_class, ContentRestorer);
25306
- var _proto = _class.prototype;
25307
- _proto.restoreContent = function restoreContent() {
25308
- this.resource.setPixelBuffer(magentaPixel32);
25309
- };
25310
- return _class;
25311
- }(ContentRestorer))());
25312
- var magentaTexture2DArray = new Texture2DArray(this, 1, 1, 1, exports.TextureFormat.R8G8B8A8, false);
25313
- magentaTexture2DArray.setPixelBuffer(0, magentaPixel);
25314
- magentaTexture2DArray.isGCIgnored = true;
25315
- this.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
25316
- var _class = function _class() {
25317
- return ContentRestorer.call(this, magentaTexture2DArray);
25318
- };
25319
- _inherits$2(_class, ContentRestorer);
25320
- var _proto = _class.prototype;
25321
- _proto.restoreContent = function restoreContent() {
25322
- this.resource.setPixelBuffer(0, magentaPixel);
25323
- };
25324
- return _class;
25325
- }(ContentRestorer))());
25326
- this._uintMagentaTexture2D = uintMagentaTexture2D;
25327
- this._magentaTexture2DArray = magentaTexture2DArray;
25328
- }
25329
- };
25330
- /**
25331
- * @internal
25332
25499
  */ _proto._pendingGC = function _pendingGC() {
25333
25500
  if (this._frameInProcess) {
25334
25501
  this._waitingGC = true;
@@ -25962,6 +26129,8 @@
25962
26129
  script._started = true;
25963
26130
  _this.removeOnStartScript(script);
25964
26131
  script.onStart();
26132
+ }, function(element, index) {
26133
+ element._onStartIndex = index;
25965
26134
  });
25966
26135
  }
25967
26136
  };
@@ -26804,9 +26973,10 @@
26804
26973
  */ _proto._updateShaderData = function _updateShaderData(shaderData) {
26805
26974
  var _this = this, spotLight = _this._spotLights, pointLight = _this._pointLights, directLight = _this._directLights;
26806
26975
  var _this1 = this, spotData = _this1._spotData, pointData = _this1._pointData, directData = _this1._directData;
26807
- var spotLightCount = spotLight.length;
26808
- var pointLightCount = pointLight.length;
26809
- var directLightCount = directLight.length;
26976
+ var maxLight = LightManager._maxLight;
26977
+ var spotLightCount = Math.min(spotLight.length, maxLight);
26978
+ var pointLightCount = Math.min(pointLight.length, maxLight);
26979
+ var directLightCount = Math.min(directLight.length, maxLight);
26810
26980
  for(var i = 0; i < spotLightCount; i++){
26811
26981
  spotLight.get(i)._appendData(i, spotData);
26812
26982
  }
@@ -28874,7 +29044,7 @@
28874
29044
  depthOnlyPass.onConfig(camera);
28875
29045
  depthOnlyPass.onRender(context, cullingResults);
28876
29046
  } else {
28877
- camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._whiteTexture2D);
29047
+ camera.shaderData.setTexture(exports.Camera._cameraDepthTextureProperty, engine._basicResources.whiteTexture2D);
28878
29048
  }
28879
29049
  // Check if need to create internal color texture
28880
29050
  var independentCanvasEnabled = camera.independentCanvasEnabled;
@@ -31854,20 +32024,19 @@
31854
32024
  var relativePath = curve.relativePath;
31855
32025
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
31856
32026
  if (targetEntity) {
31857
- var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _propertyPath;
31858
- var propertyPath = "" + curve.typeIndex + "." + curve.property;
32027
+ var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
31859
32028
  var component = curve.typeIndex > 0 ? targetEntity.getComponents(curve.type, AnimationCurveOwner._components)[curve.typeIndex] : targetEntity.getComponent(curve.type);
31860
32029
  if (!component) {
31861
32030
  continue;
31862
32031
  }
31863
32032
  var property = curve.property;
31864
- var instanceId = targetEntity.instanceId;
32033
+ var instanceId = component.instanceId;
31865
32034
  // Get owner
31866
32035
  var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
31867
32036
  var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity, component));
31868
32037
  // Get layer owner
31869
32038
  var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
31870
- var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_propertyPath = propertyPath] || (_layerPropertyOwners[_propertyPath] = curve._createCurveLayerOwner(owner));
32039
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
31871
32040
  if (mask && mask.pathMasks.length) {
31872
32041
  var _mask_getPathMask;
31873
32042
  var _mask_getPathMask_active;
@@ -40214,6 +40383,7 @@
40214
40383
  this.resourceManager = resourceManager;
40215
40384
  this.params = params;
40216
40385
  this.accessorBufferCache = {};
40386
+ this.needAnimatorController = false;
40217
40387
  this._resourceCache = new Map();
40218
40388
  this._progress = {
40219
40389
  taskDetail: {},
@@ -40241,16 +40411,15 @@
40241
40411
  return Promise.resolve(null);
40242
40412
  }
40243
40413
  var cache = this._resourceCache;
40244
- var isOnlyOne = type === 0 || type === 1;
40245
- var cacheKey = isOnlyOne || index === undefined ? "" + type : type + ":" + index;
40414
+ var cacheKey = index === undefined ? "" + type : type + ":" + index;
40246
40415
  var resource = cache.get(cacheKey);
40247
40416
  if (resource) {
40248
40417
  return resource;
40249
40418
  }
40250
- if (isOnlyOne) {
40251
- resource = parser.parse(this);
40252
- } else {
40253
- var glTFItems = this.glTF[glTFSchemaMap[type]];
40419
+ var glTFSchemaKey = glTFSchemaMap[type];
40420
+ var isSubAsset = !!glTFResourceMap[type];
40421
+ if (glTFSchemaKey) {
40422
+ var glTFItems = this.glTF[glTFSchemaKey];
40254
40423
  if (glTFItems && (index === undefined || glTFItems[index])) {
40255
40424
  if (index === undefined) {
40256
40425
  resource = type === 8 ? glTFItems.map(function(_, index) {
@@ -40260,11 +40429,14 @@
40260
40429
  }));
40261
40430
  } else {
40262
40431
  resource = parser.parse(this, index);
40263
- this._handleSubAsset(resource, type, index);
40432
+ isSubAsset && this._handleSubAsset(resource, type, index);
40264
40433
  }
40265
40434
  } else {
40266
40435
  resource = Promise.resolve(null);
40267
40436
  }
40437
+ } else {
40438
+ resource = parser.parse(this, index);
40439
+ isSubAsset && this._handleSubAsset(resource, type, index);
40268
40440
  }
40269
40441
  cache.set(cacheKey, resource);
40270
40442
  return resource;
@@ -40273,6 +40445,7 @@
40273
40445
  var _this = this;
40274
40446
  var promise = this.get(0).then(function(json) {
40275
40447
  _this.glTF = json;
40448
+ _this.needAnimatorController = !!(json.skins || json.animations);
40276
40449
  return Promise.all([
40277
40450
  _this.get(1),
40278
40451
  _this.get(5),
@@ -40280,11 +40453,14 @@
40280
40453
  _this.get(7),
40281
40454
  _this.get(9),
40282
40455
  _this.get(10),
40456
+ _this.get(11),
40283
40457
  _this.get(2)
40284
40458
  ]).then(function() {
40285
40459
  var glTFResource = _this.glTFResource;
40286
- if (glTFResource.skins || glTFResource.animations) {
40287
- _this._createAnimator(_this, glTFResource.animations);
40460
+ var animatorController = glTFResource.animatorController;
40461
+ if (animatorController) {
40462
+ var animator = glTFResource._defaultSceneRoot.addComponent(Animator);
40463
+ animator.animatorController = animatorController;
40288
40464
  }
40289
40465
  _this.resourceManager.addContentRestorer(_this.contentRestorer);
40290
40466
  return glTFResource;
@@ -40303,53 +40479,34 @@
40303
40479
  _this._setTaskCompleteProgress(++task.loaded, task.total);
40304
40480
  });
40305
40481
  };
40306
- _proto._createAnimator = function _createAnimator(context, animations) {
40307
- var defaultSceneRoot = context.glTFResource.defaultSceneRoot;
40308
- var animator = defaultSceneRoot.addComponent(Animator);
40309
- var animatorController = new AnimatorController();
40310
- var layer = new AnimatorControllerLayer("layer");
40311
- var animatorStateMachine = new AnimatorStateMachine();
40312
- animatorController.addLayer(layer);
40313
- animator.animatorController = animatorController;
40314
- layer.stateMachine = animatorStateMachine;
40315
- if (animations) {
40316
- for(var i = 0; i < animations.length; i++){
40317
- var animationClip = animations[i];
40318
- var name = animationClip.name;
40319
- var uniqueName = animatorStateMachine.makeUniqueStateName(name);
40320
- if (uniqueName !== name) {
40321
- console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
40322
- }
40323
- var animatorState = animatorStateMachine.addState(uniqueName);
40324
- animatorState.clip = animationClip;
40325
- }
40326
- }
40327
- };
40328
40482
  _proto._handleSubAsset = function _handleSubAsset(resource, type, index) {
40329
40483
  var _this = this;
40330
40484
  var glTFResourceKey = glTFResourceMap[type];
40331
- if (!glTFResourceKey) return;
40332
40485
  if (type === 8) {
40333
40486
  var _this_glTFResource, _glTFResourceKey;
40334
40487
  ((_this_glTFResource = this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = resource;
40335
40488
  } else {
40336
40489
  var url = this.glTFResource.url;
40337
40490
  resource.then(function(item) {
40338
- var _this_glTFResource, _glTFResourceKey;
40339
- ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
40491
+ if (index == undefined) {
40492
+ _this.glTFResource[glTFResourceKey] = item;
40493
+ } else {
40494
+ var _this_glTFResource, _glTFResourceKey;
40495
+ ((_this_glTFResource = _this.glTFResource)[_glTFResourceKey = glTFResourceKey] || (_this_glTFResource[_glTFResourceKey] = []))[index] = item;
40496
+ }
40340
40497
  if (type === 7) {
40341
40498
  for(var i = 0, length = item.length; i < length; i++){
40342
40499
  var mesh = item[i];
40343
40500
  // @ts-ignore
40344
- _this.resourceManager._onSubAssetSuccess(url + "?q=" + glTFResourceKey + "[" + index + "][" + i + "]", mesh);
40501
+ _this.resourceManager._onSubAssetSuccess(url, glTFResourceKey + "[" + index + "][" + i + "]", mesh);
40345
40502
  }
40346
40503
  } else {
40347
40504
  // @ts-ignore
40348
- _this.resourceManager._onSubAssetSuccess(url + "?q=" + glTFResourceKey + "[" + index + "]", item);
40505
+ _this.resourceManager._onSubAssetSuccess(url, "" + glTFResourceKey + (index === undefined ? "" : "[" + index + "]"), item);
40349
40506
  var _this_glTF_scene;
40350
40507
  if (type === 2 && ((_this_glTF_scene = _this.glTF.scene) != null ? _this_glTF_scene : 0) === index) {
40351
40508
  // @ts-ignore
40352
- _this.resourceManager._onSubAssetSuccess("" + url + "?q=defaultSceneRoot", item);
40509
+ _this.resourceManager._onSubAssetSuccess(url, "defaultSceneRoot", item);
40353
40510
  }
40354
40511
  }
40355
40512
  });
@@ -40384,11 +40541,12 @@
40384
40541
  GLTFParserType[GLTFParserType["Entity"] = 8] = "Entity";
40385
40542
  GLTFParserType[GLTFParserType["Skin"] = 9] = "Skin";
40386
40543
  GLTFParserType[GLTFParserType["Animation"] = 10] = "Animation";
40544
+ GLTFParserType[GLTFParserType["AnimatorController"] = 11] = "AnimatorController";
40387
40545
  })(exports.GLTFParserType || (exports.GLTFParserType = {}));
40388
40546
  var _obj;
40389
40547
  var glTFSchemaMap = (_obj = {}, _obj[2] = "scenes", _obj[3] = "buffers", _obj[5] = "textures", _obj[6] = "materials", _obj[7] = "meshes", _obj[8] = "nodes", _obj[9] = "skins", _obj[10] = "animations", _obj[4] = "bufferViews", _obj);
40390
40548
  var _obj1;
40391
- var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1);
40549
+ var glTFResourceMap = (_obj1 = {}, _obj1[2] = "_sceneRoots", _obj1[5] = "textures", _obj1[6] = "materials", _obj1[7] = "meshes", _obj1[8] = "entities", _obj1[9] = "skins", _obj1[10] = "animations", _obj1[11] = "animatorController", _obj1);
40392
40550
  function registerGLTFParser(pipeline) {
40393
40551
  return function(Parser) {
40394
40552
  var parser = new Parser();
@@ -42769,7 +42927,7 @@
42769
42927
  var sceneExtensions = sceneInfo.extensions;
42770
42928
  var engine = glTFResource.engine;
42771
42929
  var isDefaultScene = scene === index;
42772
- var sceneNodes = sceneInfo.nodes;
42930
+ var sceneNodes = sceneInfo.nodes || [];
42773
42931
  var sceneRoot;
42774
42932
  if (sceneNodes.length === 1) {
42775
42933
  sceneRoot = context.get(exports.GLTFParserType.Entity, sceneNodes[0]);
@@ -42851,25 +43009,32 @@
42851
43009
  camera.enabled = false;
42852
43010
  };
42853
43011
  _proto._createRenderer = function _createRenderer(context, entityInfo, entity) {
42854
- var _loop = function _loop(i) {
42855
- var glTFPrimitive = glTFMeshPrimitives[i];
42856
- var materialIndex = glTFPrimitive.material;
42857
- promises.push(Promise.all([
42858
- context.get(exports.GLTFParserType.Mesh, meshID),
42859
- skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
42860
- materialIndex !== undefined && context.get(exports.GLTFParserType.Material, materialIndex)
42861
- ]).then(function(param) {
42862
- var meshes = param[0], skin = param[1], material = param[2];
43012
+ var _this = this;
43013
+ var meshID = entityInfo.mesh, skinID = entityInfo.skin;
43014
+ var glTFMesh = context.glTF.meshes[meshID];
43015
+ var glTFMeshPrimitives = glTFMesh.primitives;
43016
+ var rendererCount = glTFMeshPrimitives.length;
43017
+ var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
43018
+ var materialPromises = new Array(rendererCount);
43019
+ for(var i = 0; i < rendererCount; i++){
43020
+ var _glTFMeshPrimitives_i_material;
43021
+ materialPromises[i] = context.get(exports.GLTFParserType.Material, (_glTFMeshPrimitives_i_material = glTFMeshPrimitives[i].material) != null ? _glTFMeshPrimitives_i_material : -1);
43022
+ }
43023
+ return Promise.all([
43024
+ context.get(exports.GLTFParserType.Mesh, meshID),
43025
+ skinID !== undefined && context.get(exports.GLTFParserType.Skin, skinID),
43026
+ Promise.all(materialPromises)
43027
+ ]).then(function(param) {
43028
+ var _loop = function _loop(i) {
43029
+ var material = materials[i] || exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine);
43030
+ var glTFPrimitive = glTFMeshPrimitives[i];
42863
43031
  var mesh = meshes[i];
42864
- var renderer;
42865
- material || (material = exports.GLTFMaterialParser._getDefaultMaterial(context.glTFResource.engine));
43032
+ var renderer = void 0;
42866
43033
  if (skin || blendShapeWeights) {
42867
43034
  var skinRenderer = entity.addComponent(SkinnedMeshRenderer);
42868
43035
  skinRenderer.mesh = mesh;
42869
43036
  if (skin) {
42870
- skinRenderer.rootBone = skin._rootBone;
42871
- skinRenderer.bones = skin._bones;
42872
- _this._computeLocalBounds(skinRenderer, mesh, skin._bones, skin._rootBone, skin.inverseBindMatrices);
43037
+ _this._computeLocalBounds(skinRenderer, mesh, skin.bones, skin.rootBone, skin.inverseBindMatrices);
42873
43038
  skinRenderer.skin = skin;
42874
43039
  }
42875
43040
  if (blendShapeWeights) {
@@ -42888,17 +43053,10 @@
42888
43053
  }
42889
43054
  });
42890
43055
  GLTFParser.executeExtensionsAdditiveAndParse(glTFPrimitive.extensions, context, renderer, glTFPrimitive);
42891
- }));
42892
- };
42893
- var _this = this;
42894
- var glTFMeshes = context.glTF.meshes;
42895
- var meshID = entityInfo.mesh, skinID = entityInfo.skin;
42896
- var glTFMesh = glTFMeshes[meshID];
42897
- var glTFMeshPrimitives = glTFMesh.primitives;
42898
- var blendShapeWeights = entityInfo.weights || glTFMesh.weights;
42899
- var promises = new Array();
42900
- for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
42901
- return Promise.all(promises);
43056
+ };
43057
+ var meshes = param[0], skin = param[1], materials = param[2];
43058
+ for(var i = 0; i < rendererCount; i++)_loop(i);
43059
+ });
42902
43060
  };
42903
43061
  _proto._computeLocalBounds = function _computeLocalBounds(skinnedMeshRenderer, mesh, bones, rootBone, inverseBindMatrices) {
42904
43062
  var rootBoneIndex = bones.indexOf(rootBone);
@@ -42951,7 +43109,7 @@
42951
43109
  var jointCount = joints.length;
42952
43110
  var skin = new Skin(name);
42953
43111
  skin.inverseBindMatrices.length = jointCount;
42954
- skin._bones.length = jointCount;
43112
+ var bones = new Array(jointCount);
42955
43113
  // parse IBM
42956
43114
  var accessor = glTF.accessors[inverseBindMatrices];
42957
43115
  var skinPromise = GLTFUtils.getAccessorBuffer(context, glTF.bufferViews, accessor).then(function(bufferInfo) {
@@ -42963,21 +43121,20 @@
42963
43121
  skin.inverseBindMatrices[i] = inverseBindMatrix;
42964
43122
  // Get bones
42965
43123
  var bone = entities[joints[i]];
42966
- skin._bones[i] = bone;
43124
+ bones[i] = bone;
42967
43125
  skin.joints[i] = bone.name;
42968
- // Get skeleton
42969
- if (skeleton !== undefined) {
42970
- var rootBone = entities[skeleton];
42971
- skin._rootBone = rootBone;
42972
- skin.skeleton = rootBone.name;
43126
+ }
43127
+ skin.bones = bones;
43128
+ // Get skeleton
43129
+ if (skeleton !== undefined) {
43130
+ var rootBone = entities[skeleton];
43131
+ skin.rootBone = rootBone;
43132
+ } else {
43133
+ var rootBone1 = _this._findSkeletonRootBone(joints, entities);
43134
+ if (rootBone1) {
43135
+ skin.rootBone = rootBone1;
42973
43136
  } else {
42974
- var rootBone1 = _this._findSkeletonRootBone(joints, entities);
42975
- if (rootBone1) {
42976
- skin._rootBone = rootBone1;
42977
- skin.skeleton = rootBone1.name;
42978
- } else {
42979
- throw "Failed to find skeleton root bone.";
42980
- }
43137
+ throw "Failed to find skeleton root bone.";
42981
43138
  }
42982
43139
  }
42983
43140
  return skin;
@@ -43141,6 +43298,47 @@
43141
43298
  exports.GLTFBufferViewParser = __decorate([
43142
43299
  registerGLTFParser(exports.GLTFParserType.BufferView)
43143
43300
  ], exports.GLTFBufferViewParser);
43301
+ exports.GLTFAnimatorControllerParser = /*#__PURE__*/ function(GLTFParser1) {
43302
+ var GLTFAnimatorControllerParser = function GLTFAnimatorControllerParser() {
43303
+ return GLTFParser1.apply(this, arguments);
43304
+ };
43305
+ _inherits(GLTFAnimatorControllerParser, GLTFParser1);
43306
+ var _proto = GLTFAnimatorControllerParser.prototype;
43307
+ _proto.parse = function parse(context) {
43308
+ var _this = this;
43309
+ if (!context.needAnimatorController) {
43310
+ return Promise.resolve(null);
43311
+ }
43312
+ return context.get(exports.GLTFParserType.Animation).then(function(animations) {
43313
+ var animatorController = _this._createAnimatorController(animations);
43314
+ return Promise.resolve(animatorController);
43315
+ });
43316
+ };
43317
+ _proto._createAnimatorController = function _createAnimatorController(animations) {
43318
+ var animatorController = new AnimatorController();
43319
+ var layer = new AnimatorControllerLayer("layer");
43320
+ var animatorStateMachine = new AnimatorStateMachine();
43321
+ animatorController.addLayer(layer);
43322
+ layer.stateMachine = animatorStateMachine;
43323
+ if (animations) {
43324
+ for(var i = 0; i < animations.length; i++){
43325
+ var animationClip = animations[i];
43326
+ var name = animationClip.name;
43327
+ var uniqueName = animatorStateMachine.makeUniqueStateName(name);
43328
+ if (uniqueName !== name) {
43329
+ console.warn("AnimatorState name is existed, name: " + name + " reset to " + uniqueName);
43330
+ }
43331
+ var animatorState = animatorStateMachine.addState(uniqueName);
43332
+ animatorState.clip = animationClip;
43333
+ }
43334
+ }
43335
+ return animatorController;
43336
+ };
43337
+ return GLTFAnimatorControllerParser;
43338
+ }(GLTFParser);
43339
+ exports.GLTFAnimatorControllerParser = __decorate([
43340
+ registerGLTFParser(exports.GLTFParserType.AnimatorController)
43341
+ ], exports.GLTFAnimatorControllerParser);
43144
43342
  // Source: https://github.com/zeux/meshoptimizer/blob/master/js/meshopt_decoder.js
43145
43343
  var MeshoptDecoder = function() {
43146
43344
  var unpack = function unpack(data) {
@@ -43546,15 +43744,20 @@
43546
43744
  var dataRGBA = new Uint8Array(4 * width * height);
43547
43745
  var offset = 0, pos = 0;
43548
43746
  var ptrEnd = 4 * scanLineWidth;
43549
- var rgbeStart = new Uint8Array(4);
43550
43747
  var scanLineBuffer = new Uint8Array(ptrEnd);
43551
43748
  var numScanLines = height; // read in each successive scanLine
43552
43749
  while(numScanLines > 0 && pos < byteLength){
43553
- rgbeStart[0] = buffer[pos++];
43554
- rgbeStart[1] = buffer[pos++];
43555
- rgbeStart[2] = buffer[pos++];
43556
- rgbeStart[3] = buffer[pos++];
43557
- if (2 != rgbeStart[0] || 2 != rgbeStart[1] || (rgbeStart[2] << 8 | rgbeStart[3]) != scanLineWidth) {
43750
+ var a = buffer[pos++];
43751
+ var b = buffer[pos++];
43752
+ var c = buffer[pos++];
43753
+ var d = buffer[pos++];
43754
+ if (a != 2 || b != 2 || c & 0x80 || width < 8 || width > 32767) {
43755
+ // this file is not run length encoded
43756
+ // read values sequentially
43757
+ return buffer;
43758
+ }
43759
+ if ((c << 8 | d) != scanLineWidth) {
43760
+ // eslint-disable-next-line no-throw-literal
43558
43761
  throw "HDR Bad header format, wrong scan line width";
43559
43762
  }
43560
43763
  // read each of the four channels for the scanline into the buffer
@@ -43980,72 +44183,59 @@
43980
44183
  _this.request(item.url, _extends({}, item, {
43981
44184
  type: "json"
43982
44185
  })).then(function(materialSchema) {
44186
+ var _loop = function _loop(key) {
44187
+ var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
44188
+ switch(type){
44189
+ case "Vector2":
44190
+ materialShaderData.setVector2(key, new Vector2(value.x, value.y));
44191
+ break;
44192
+ case "Vector3":
44193
+ materialShaderData.setVector3(key, new Vector3(value.x, value.y, value.z));
44194
+ break;
44195
+ case "Vector4":
44196
+ materialShaderData.setVector4(key, new Vector4(value.x, value.y, value.z, value.w));
44197
+ break;
44198
+ case "Color":
44199
+ materialShaderData.setColor(key, new Color(value.r, value.g, value.b, value.a));
44200
+ break;
44201
+ case "Float":
44202
+ materialShaderData.setFloat(key, value);
44203
+ break;
44204
+ case "Texture":
44205
+ texturePromises.push(resourceManager.getResourceByRef(value).then(function(texture) {
44206
+ materialShaderData.setTexture(key, texture);
44207
+ }));
44208
+ break;
44209
+ case "Boolean":
44210
+ materialShaderData.setInt(key, value ? 1 : 0);
44211
+ break;
44212
+ case "Integer":
44213
+ materialShaderData.setInt(key, Number(value));
44214
+ break;
44215
+ }
44216
+ };
43983
44217
  var engine = resourceManager.engine;
43984
- var shaderRef = materialSchema.shaderRef, shader = materialSchema.shader;
43985
- if (shaderRef) {
43986
- resolve(resourceManager // @ts-ignore
43987
- .getResourceByRef(shaderRef).then(function(shaderObject) {
43988
- return _this.getMaterialByShader(materialSchema, shaderObject, engine);
43989
- }));
43990
- } else {
43991
- // compatible with 1.2-pre version material schema
43992
- var shaderObject = Shader.find(shader);
43993
- resolve(_this.getMaterialByShader(materialSchema, shaderObject, engine));
44218
+ var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
44219
+ var material = new Material(engine, Shader.find(shader));
44220
+ material.name = name;
44221
+ var texturePromises = new Array();
44222
+ var materialShaderData = material.shaderData;
44223
+ for(var key in shaderData)_loop(key);
44224
+ for(var i = 0, length = macros.length; i < length; i++){
44225
+ var _macros_i = macros[i], name1 = _macros_i.name, value = _macros_i.value;
44226
+ if (value == undefined) {
44227
+ materialShaderData.enableMacro(name1);
44228
+ } else {
44229
+ materialShaderData.enableMacro(name1, value);
44230
+ }
43994
44231
  }
44232
+ parseProperty(material, "renderState", renderState);
44233
+ return Promise.all(texturePromises).then(function() {
44234
+ resolve(material);
44235
+ });
43995
44236
  }).catch(reject);
43996
44237
  });
43997
44238
  };
43998
- _proto.getMaterialByShader = function getMaterialByShader(materialSchema, shader, engine) {
43999
- var _loop = function _loop(key) {
44000
- var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
44001
- switch(type){
44002
- case "Vector2":
44003
- materialShaderData.setVector2(key, new Vector2(value.x, value.y));
44004
- break;
44005
- case "Vector3":
44006
- materialShaderData.setVector3(key, new Vector3(value.x, value.y, value.z));
44007
- break;
44008
- case "Vector4":
44009
- materialShaderData.setVector4(key, new Vector4(value.x, value.y, value.z, value.w));
44010
- break;
44011
- case "Color":
44012
- materialShaderData.setColor(key, new Color(value.r, value.g, value.b, value.a));
44013
- break;
44014
- case "Float":
44015
- materialShaderData.setFloat(key, value);
44016
- break;
44017
- case "Texture":
44018
- texturePromises.push(engine.resourceManager.getResourceByRef(value).then(function(texture) {
44019
- materialShaderData.setTexture(key, texture);
44020
- }));
44021
- break;
44022
- case "Boolean":
44023
- materialShaderData.setInt(key, value ? 1 : 0);
44024
- break;
44025
- case "Integer":
44026
- materialShaderData.setInt(key, Number(value));
44027
- break;
44028
- }
44029
- };
44030
- var name = materialSchema.name, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
44031
- var material = new Material(engine, shader);
44032
- material.name = name;
44033
- var texturePromises = new Array();
44034
- var materialShaderData = material.shaderData;
44035
- for(var key in shaderData)_loop(key);
44036
- for(var i = 0, length = macros.length; i < length; i++){
44037
- var _macros_i = macros[i], name1 = _macros_i.name, value = _macros_i.value;
44038
- if (value == undefined) {
44039
- materialShaderData.enableMacro(name1);
44040
- } else {
44041
- materialShaderData.enableMacro(name1, value);
44042
- }
44043
- }
44044
- parseProperty(material, "renderState", renderState);
44045
- return Promise.all(texturePromises).then(function() {
44046
- return material;
44047
- });
44048
- };
44049
44239
  return MaterialLoader;
44050
44240
  }(Loader);
44051
44241
  MaterialLoader = __decorate([
@@ -44484,104 +44674,6 @@
44484
44674
  ""
44485
44675
  ])
44486
44676
  ], TextureCubeLoader);
44487
- var ShaderLoader = /*#__PURE__*/ function(Loader1) {
44488
- var ShaderLoader = function ShaderLoader() {
44489
- return Loader1.apply(this, arguments);
44490
- };
44491
- _inherits(ShaderLoader, Loader1);
44492
- var _proto = ShaderLoader.prototype;
44493
- _proto.load = function load(item, resourceManager) {
44494
- var _this = this;
44495
- return this.request(item.url, _extends({}, item, {
44496
- type: "text"
44497
- })).then(function(code) {
44498
- var builtinShader = _this.getBuiltinShader(code);
44499
- if (builtinShader) {
44500
- return Shader.find(builtinShader);
44501
- }
44502
- var matches = code.matchAll(/^[ \t]*#include +"([^$\\"]+)"/gm);
44503
- return Promise.all(Array.from(matches).map(function(m) {
44504
- var path = m[1];
44505
- if (path) {
44506
- // @ts-ignore
44507
- var resource = resourceManager._virtualPathMap[path];
44508
- if (!resource) return;
44509
- return resourceManager.load({
44510
- type: exports.AssetType.ShaderChunk,
44511
- url: resource,
44512
- params: {
44513
- includeKey: path
44514
- }
44515
- });
44516
- }
44517
- })).then(function() {
44518
- return Shader.create(code);
44519
- });
44520
- });
44521
- };
44522
- _proto.getBuiltinShader = function getBuiltinShader(code) {
44523
- var match = code.match(/^\s*\/\/\s*@builtin\s+(\w+)/);
44524
- if (match && match[1]) return match[1];
44525
- };
44526
- return ShaderLoader;
44527
- }(Loader);
44528
- ShaderLoader = __decorate([
44529
- resourceLoader(exports.AssetType.Shader, [
44530
- "gs",
44531
- "gsl"
44532
- ], false)
44533
- ], ShaderLoader);
44534
- var ShaderChunkLoader = /*#__PURE__*/ function(Loader1) {
44535
- var ShaderChunkLoader = function ShaderChunkLoader() {
44536
- return Loader1.apply(this, arguments);
44537
- };
44538
- _inherits(ShaderChunkLoader, Loader1);
44539
- var _proto = ShaderChunkLoader.prototype;
44540
- _proto.load = function load(item, resourceManager) {
44541
- return this.request(item.url, _extends({}, item, {
44542
- type: "text"
44543
- })).then(/*#__PURE__*/ _async_to_generator(function(code) {
44544
- var includeKey, matches;
44545
- return __generator(this, function(_state) {
44546
- switch(_state.label){
44547
- case 0:
44548
- includeKey = item.params.includeKey;
44549
- ShaderFactory.registerInclude(includeKey, code);
44550
- matches = code.matchAll(/^[ \t]*#include +"([^$\\"]+)"/gm);
44551
- return [
44552
- 4,
44553
- Promise.all(Array.from(matches).map(function(m) {
44554
- var path = m[1];
44555
- if (path) {
44556
- // @ts-ignore
44557
- var resource = resourceManager._virtualPathMap[path];
44558
- if (!resource) return;
44559
- return resourceManager.load({
44560
- type: exports.AssetType.ShaderChunk,
44561
- url: resource,
44562
- params: {
44563
- includeKey: path
44564
- }
44565
- });
44566
- }
44567
- }))
44568
- ];
44569
- case 1:
44570
- _state.sent();
44571
- return [
44572
- 2
44573
- ];
44574
- }
44575
- });
44576
- }));
44577
- };
44578
- return ShaderChunkLoader;
44579
- }(Loader);
44580
- ShaderChunkLoader = __decorate([
44581
- resourceLoader(exports.AssetType.ShaderChunk, [
44582
- "glsl"
44583
- ], false)
44584
- ], ShaderChunkLoader);
44585
44677
  var SceneLoader = /*#__PURE__*/ function(Loader1) {
44586
44678
  var SceneLoader = function SceneLoader() {
44587
44679
  return Loader1.apply(this, arguments);
@@ -44657,6 +44749,8 @@
44657
44749
  scene.background.texture = texture;
44658
44750
  });
44659
44751
  promises.push(backgroundPromise);
44752
+ var _background_textureFillMode;
44753
+ scene.background.textureFillMode = (_background_textureFillMode = background.textureFillMode) != null ? _background_textureFillMode : scene.background.textureFillMode;
44660
44754
  }
44661
44755
  break;
44662
44756
  }
@@ -45071,7 +45165,7 @@
45071
45165
  ], KHR_materials_anisotropy);
45072
45166
 
45073
45167
  //@ts-ignore
45074
- var version = "0.0.0-experimental-shaderlab.2";
45168
+ var version = "0.0.0-experimental-1.2-xr.0";
45075
45169
  console.log("Galacean engine version: " + version);
45076
45170
  for(var key in CoreObjects){
45077
45171
  Loader.registerClass(key, CoreObjects[key]);