@galacean/engine 1.0.0-beta.1 → 1.0.0-beta.11

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
@@ -5533,7 +5533,9 @@
5533
5533
  */ _proto._addToResourceManager = function _addToResourceManager(path) {
5534
5534
  this._engine.resourceManager._addAsset(path, this);
5535
5535
  };
5536
- _proto._onDestroy = function _onDestroy() {
5536
+ /**
5537
+ * @internal
5538
+ */ _proto._onDestroy = function _onDestroy() {
5537
5539
  EngineObject.prototype._onDestroy.call(this);
5538
5540
  this._engine.resourceManager._deleteReferResource(this);
5539
5541
  var refCount = this._getReferCount();
@@ -5657,7 +5659,9 @@
5657
5659
  };
5658
5660
  _inherits$2(GraphicsResource, ReferResource);
5659
5661
  var _proto = GraphicsResource.prototype;
5660
- _proto._onDestroy = function _onDestroy() {
5662
+ /**
5663
+ * @internal
5664
+ */ _proto._onDestroy = function _onDestroy() {
5661
5665
  ReferResource.prototype._onDestroy.call(this);
5662
5666
  this.engine.resourceManager._deleteGraphicResource(this);
5663
5667
  };
@@ -5734,7 +5738,9 @@
5734
5738
  platformTexture.depthCompareFunction = this._depthCompareFunction;
5735
5739
  platformTexture.setUseDepthCompareMode(this._useDepthCompareMode);
5736
5740
  };
5737
- _proto._onDestroy = function _onDestroy() {
5741
+ /**
5742
+ * @internal
5743
+ */ _proto._onDestroy = function _onDestroy() {
5738
5744
  GraphicsResource.prototype._onDestroy.call(this);
5739
5745
  this._platformTexture.destroy();
5740
5746
  this._platformTexture = null;
@@ -5882,9 +5888,11 @@
5882
5888
  renderTexture
5883
5889
  ];
5884
5890
  for(var i = 0, n = colorTextures.length; i < n; i++){
5885
- if (colorTextures[i]._isDepthTexture) {
5891
+ var colorTexture = colorTextures[i];
5892
+ if (colorTexture._isDepthTexture) {
5886
5893
  throw "Render texture can't use depth format.";
5887
5894
  }
5895
+ colorTexture._addReferCount(1);
5888
5896
  }
5889
5897
  _this._colorTextures = colorTextures;
5890
5898
  } else {
@@ -5895,6 +5903,7 @@
5895
5903
  throw "Depth texture must use depth format.";
5896
5904
  }
5897
5905
  _this._depthTexture = depth;
5906
+ _this._depthTexture._addReferCount(1);
5898
5907
  }
5899
5908
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
5900
5909
  return _this;
@@ -5921,10 +5930,18 @@
5921
5930
  this._depthTexture && this._depthTexture.generateMipmaps();
5922
5931
  }
5923
5932
  };
5924
- _proto._onDestroy = function _onDestroy() {
5933
+ /**
5934
+ * @internal
5935
+ */ _proto._onDestroy = function _onDestroy() {
5936
+ var _this__depthTexture;
5925
5937
  GraphicsResource.prototype._onDestroy.call(this);
5926
5938
  this._platformRenderTarget.destroy();
5927
- this._colorTextures.length = 0;
5939
+ var _this = this, colorTextures = _this._colorTextures;
5940
+ for(var i = 0, n = colorTextures.length; i < n; i++){
5941
+ colorTextures[i]._addReferCount(-1);
5942
+ }
5943
+ colorTextures.length = 0;
5944
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addReferCount(-1);
5928
5945
  this._depthTexture = null;
5929
5946
  this._depth = null;
5930
5947
  };
@@ -6295,7 +6312,9 @@
6295
6312
  _proto.getCharInfo = function getCharInfo(char) {
6296
6313
  return this._charInfoMap[char.charCodeAt(0)];
6297
6314
  };
6298
- _proto._onDestroy = function _onDestroy() {
6315
+ /**
6316
+ * @internal
6317
+ */ _proto._onDestroy = function _onDestroy() {
6299
6318
  ReferResource.prototype._onDestroy.call(this);
6300
6319
  this.texture.destroy();
6301
6320
  this.texture = null;
@@ -6798,6 +6817,7 @@
6798
6817
  var fontAtlas = new FontAtlas(engine);
6799
6818
  var texture = new Texture2D(engine, 256, 256);
6800
6819
  fontAtlas.texture = texture;
6820
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
6801
6821
  this._fontAtlases.push(fontAtlas);
6802
6822
  var nativeFontString = this.nativeFontString;
6803
6823
  engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
@@ -6853,7 +6873,9 @@
6853
6873
  subFontMap[key] = subFont;
6854
6874
  return subFont;
6855
6875
  };
6856
- _proto._onDestroy = function _onDestroy() {
6876
+ /**
6877
+ * @internal
6878
+ */ _proto._onDestroy = function _onDestroy() {
6857
6879
  ReferResource.prototype._onDestroy.call(this);
6858
6880
  var subFontMap = this._subFontMap;
6859
6881
  for(var k in subFontMap){
@@ -7094,6 +7116,29 @@
7094
7116
  * @remarks The release principle is that it is not referenced by the components, including direct and indirect reference.
7095
7117
  */ _proto.gc = function gc() {
7096
7118
  this._gc(false);
7119
+ var engine = this.engine;
7120
+ engine._renderElementPool.garbageCollection();
7121
+ engine._meshRenderDataPool.garbageCollection();
7122
+ engine._spriteRenderDataPool.garbageCollection();
7123
+ engine._spriteMaskRenderDataPool.garbageCollection();
7124
+ engine._textRenderDataPool.garbageCollection();
7125
+ var _componentsManager = engine._componentsManager, _lightManager = engine._lightManager;
7126
+ _componentsManager._renderers.garbageCollection();
7127
+ // @ts-ignore
7128
+ _componentsManager._onStartScripts.garbageCollection();
7129
+ // @ts-ignore
7130
+ _componentsManager._onUpdateScripts.garbageCollection();
7131
+ // @ts-ignore
7132
+ _componentsManager._onLateUpdateScripts.garbageCollection();
7133
+ // @ts-ignore
7134
+ _componentsManager._onPhysicsUpdateScripts.garbageCollection();
7135
+ // @ts-ignore
7136
+ _componentsManager._onUpdateAnimations.garbageCollection();
7137
+ // @ts-ignore
7138
+ _componentsManager._onUpdateRenderers.garbageCollection();
7139
+ _lightManager._spotLights.garbageCollection();
7140
+ _lightManager._pointLights.garbageCollection();
7141
+ _lightManager._directLights.garbageCollection();
7097
7142
  };
7098
7143
  /**
7099
7144
  * Add content restorer.
@@ -8060,7 +8105,9 @@
8060
8105
  }
8061
8106
  }
8062
8107
  };
8063
- _proto._onDestroy = function _onDestroy() {
8108
+ /**
8109
+ * @internal
8110
+ */ _proto._onDestroy = function _onDestroy() {
8064
8111
  EngineObject.prototype._onDestroy.call(this);
8065
8112
  this._entity._removeComponent(this);
8066
8113
  if (this._entity.isActiveInHierarchy) {
@@ -9508,6 +9555,11 @@
9508
9555
  * @returns Cloned entity
9509
9556
  */ _proto.clone = function clone() {
9510
9557
  var cloneEntity = new Entity(this._engine, this.name);
9558
+ var _this = this, hookResource = _this._hookResource;
9559
+ if (hookResource) {
9560
+ cloneEntity._hookResource = hookResource;
9561
+ hookResource._addReferCount(1);
9562
+ }
9511
9563
  cloneEntity._isActive = this._isActive;
9512
9564
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
9513
9565
  var children = this._children;
@@ -9532,6 +9584,10 @@
9532
9584
  return;
9533
9585
  }
9534
9586
  EngineObject.prototype.destroy.call(this);
9587
+ if (this._hookResource) {
9588
+ this._hookResource._addReferCount(-1);
9589
+ this._hookResource = null;
9590
+ }
9535
9591
  var components = this._components;
9536
9592
  for(var i = components.length - 1; i >= 0; i--){
9537
9593
  components[i].destroy();
@@ -10055,14 +10111,14 @@
10055
10111
  Keys[Keys[/** Tab or ⇥. */ "Tab"] = 63] = "Tab";
10056
10112
  Keys[Keys[/** Japanese: 変換 (henkan). */ "Convert"] = 64] = "Convert";
10057
10113
  Keys[Keys[/** Japanese: カタカナ/ひらがな/ローマ字 (katakana/hiragana/romaji). */ "KanaMode"] = 65] = "KanaMode";
10058
- Keys[Keys[/**
10059
- * Korean: HangulMode 한/영 (han/yeong).
10060
- * Japanese (Mac keyboard): かな (kana).
10061
- * */ "Lang1"] = 66] = "Lang1";
10062
10114
  Keys[Keys[/**
10063
- * Korean: Hanja 한자 (hanja).
10064
- * Japanese (Mac keyboard): 英数 (eisu).
10065
- */ "Lang2"] = 67] = "Lang2";
10115
+ * Korean: HangulMode 한/영 (han/yeong).
10116
+ * Japanese (Mac keyboard): かな (kana).
10117
+ * */ "Lang1"] = 66] = "Lang1";
10118
+ Keys[Keys[/**
10119
+ * Korean: Hanja 한자 (hanja).
10120
+ * Japanese (Mac keyboard): 英数 (eisu).
10121
+ */ "Lang2"] = 67] = "Lang2";
10066
10122
  Keys[Keys[/** Japanese (word-processing keyboard): Katakana. */ "Lang3"] = 68] = "Lang3";
10067
10123
  Keys[Keys[/** Japanese (word-processing keyboard): Hiragana. */ "Lang4"] = 69] = "Lang4";
10068
10124
  Keys[Keys[/** Japanese (word-processing keyboard): Zenkaku/Hankaku. */ "Lang5"] = 70] = "Lang5";
@@ -10079,46 +10135,46 @@
10079
10135
  Keys[Keys[/** → */ "ArrowRight"] = 81] = "ArrowRight";
10080
10136
  Keys[Keys[/** ↑ */ "ArrowUp"] = 82] = "ArrowUp";
10081
10137
  Keys[Keys[/** On the Mac, the "NumLock" code should be used for the numpad Clear key. */ "NumLock"] = 83] = "NumLock";
10082
- Keys[Keys[/**
10083
- * 0 Ins on a keyboard.
10084
- * 0 on a phone or remote control.
10085
- * */ "Numpad0"] = 84] = "Numpad0";
10086
10138
  Keys[Keys[/**
10087
- * 1 End on a keyboard.
10088
- * 1 or 1 QZ on a phone or remote control.
10089
- */ "Numpad1"] = 85] = "Numpad1";
10139
+ * 0 Ins on a keyboard.
10140
+ * 0 on a phone or remote control.
10141
+ * */ "Numpad0"] = 84] = "Numpad0";
10142
+ Keys[Keys[/**
10143
+ * 1 End on a keyboard.
10144
+ * 1 or 1 QZ on a phone or remote control.
10145
+ */ "Numpad1"] = 85] = "Numpad1";
10090
10146
  Keys[Keys[/**
10091
- * 2 ↓ on a keyboard.
10092
- * 2 ABC on a phone or remote control.
10093
- */ "Numpad2"] = 86] = "Numpad2";
10147
+ * 2 ↓ on a keyboard.
10148
+ * 2 ABC on a phone or remote control.
10149
+ */ "Numpad2"] = 86] = "Numpad2";
10094
10150
  Keys[Keys[/**
10095
- * 3 PgDn on a keyboard.
10096
- * 3 DEF on a phone or remote control.
10097
- */ "Numpad3"] = 87] = "Numpad3";
10151
+ * 3 PgDn on a keyboard.
10152
+ * 3 DEF on a phone or remote control.
10153
+ */ "Numpad3"] = 87] = "Numpad3";
10098
10154
  Keys[Keys[/**
10099
- * 4 ← on a keyboard.
10100
- * 4 GHI on a phone or remote control.
10101
- */ "Numpad4"] = 88] = "Numpad4";
10155
+ * 4 ← on a keyboard.
10156
+ * 4 GHI on a phone or remote control.
10157
+ */ "Numpad4"] = 88] = "Numpad4";
10102
10158
  Keys[Keys[/**
10103
- * 5 on a keyboard.
10104
- * 5 JKL on a phone or remote control.
10105
- */ "Numpad5"] = 89] = "Numpad5";
10159
+ * 5 on a keyboard.
10160
+ * 5 JKL on a phone or remote control.
10161
+ */ "Numpad5"] = 89] = "Numpad5";
10106
10162
  Keys[Keys[/**
10107
- * 6 → on a keyboard.
10108
- * 6 MNO on a phone or remote control.
10109
- */ "Numpad6"] = 90] = "Numpad6";
10163
+ * 6 → on a keyboard.
10164
+ * 6 MNO on a phone or remote control.
10165
+ */ "Numpad6"] = 90] = "Numpad6";
10110
10166
  Keys[Keys[/**
10111
- * 7 Home on a keyboard.
10112
- * 7 PQRS or 7 PRS on a phone or remote control.
10113
- */ "Numpad7"] = 91] = "Numpad7";
10167
+ * 7 Home on a keyboard.
10168
+ * 7 PQRS or 7 PRS on a phone or remote control.
10169
+ */ "Numpad7"] = 91] = "Numpad7";
10114
10170
  Keys[Keys[/**
10115
- * 8 ↑ on a keyboard.
10116
- * 8 TUV on a phone or remote control.
10117
- */ "Numpad8"] = 92] = "Numpad8";
10171
+ * 8 ↑ on a keyboard.
10172
+ * 8 TUV on a phone or remote control.
10173
+ */ "Numpad8"] = 92] = "Numpad8";
10118
10174
  Keys[Keys[/**
10119
- * 9 PgUp on a keyboard.
10120
- * 9 WXYZ or 9 WXY on a phone or remote control.
10121
- */ "Numpad9"] = 93] = "Numpad9";
10175
+ * 9 PgUp on a keyboard.
10176
+ * 9 WXYZ or 9 WXY on a phone or remote control.
10177
+ */ "Numpad9"] = 93] = "Numpad9";
10122
10178
  Keys[Keys[/** + */ "NumpadAdd"] = 94] = "NumpadAdd";
10123
10179
  Keys[Keys[/** Found on the Microsoft Natural Keyboard. */ "NumpadBackspace"] = 95] = "NumpadBackspace";
10124
10180
  Keys[Keys[/** C or AC (All Clear). Also for use with numpads that have a Clear key that is separate from the NumLock key. On the Mac, the numpad Clear key should always be encoded as "NumLock". */ "NumpadClear"] = 96] = "NumpadClear";
@@ -10134,16 +10190,16 @@
10134
10190
  Keys[Keys[/** MR Replace the current entry with the value stored in memory. */ "NumpadMemoryRecall"] = 106] = "NumpadMemoryRecall";
10135
10191
  Keys[Keys[/** MS Replace the value stored in memory with the current entry. */ "NumpadMemoryStore"] = 107] = "NumpadMemoryStore";
10136
10192
  Keys[Keys[/** M- Subtract current entry from the value stored in memory. */ "NumpadMemorySubtract"] = 108] = "NumpadMemorySubtract";
10137
- Keys[Keys[/**
10138
- * * on a keyboard. For use with numpads that provide mathematical operations (+, -, * and /).
10139
- * Use "NumpadStar" for the * key on phones and remote controls.
10140
- */ "NumpadMultiply"] = 109] = "NumpadMultiply";
10193
+ Keys[Keys[/**
10194
+ * * on a keyboard. For use with numpads that provide mathematical operations (+, -, * and /).
10195
+ * Use "NumpadStar" for the * key on phones and remote controls.
10196
+ */ "NumpadMultiply"] = 109] = "NumpadMultiply";
10141
10197
  Keys[Keys[/** ( Found on the Microsoft Natural Keyboard. */ "NumpadParenLeft"] = 110] = "NumpadParenLeft";
10142
10198
  Keys[Keys[/** ) Found on the Microsoft Natural Keyboard. */ "NumpadParenRight"] = 111] = "NumpadParenRight";
10143
10199
  Keys[Keys[/**
10144
- * * on a phone or remote control device. This key is typically found below the 7 key and to the left of the 0 key.
10145
- * Use "NumpadMultiply" for the * key on numeric keypads.
10146
- */ "NumpadStar"] = 112] = "NumpadStar";
10200
+ * * on a phone or remote control device. This key is typically found below the 7 key and to the left of the 0 key.
10201
+ * Use "NumpadMultiply" for the * key on numeric keypads.
10202
+ */ "NumpadStar"] = 112] = "NumpadStar";
10147
10203
  Keys[Keys[/** - */ "NumpadSubtract"] = 113] = "NumpadSubtract";
10148
10204
  Keys[Keys[/** Esc or ⎋. */ "Escape"] = 114] = "Escape";
10149
10205
  Keys[Keys[/** F1 */ "F1"] = 115] = "F1";
@@ -10809,7 +10865,9 @@
10809
10865
  */ _proto._onDisable = function _onDisable() {
10810
10866
  this.engine.physicsManager._removeCollider(this);
10811
10867
  };
10812
- _proto._onDestroy = function _onDestroy() {
10868
+ /**
10869
+ * @internal
10870
+ */ _proto._onDestroy = function _onDestroy() {
10813
10871
  Component.prototype._onDestroy.call(this);
10814
10872
  this.clearShapes();
10815
10873
  this._nativeCollider.destroy();
@@ -12633,7 +12691,10 @@
12633
12691
  };
12634
12692
  _inherits$2(Light, Component);
12635
12693
  var _proto = Light.prototype;
12636
- _proto._getLightColor = function _getLightColor() {
12694
+ /**
12695
+ * Light Color, include intensity.
12696
+ * @internal
12697
+ */ _proto._getLightIntensityColor = function _getLightIntensityColor() {
12637
12698
  this._lightColor.r = this.color.r * this.intensity;
12638
12699
  this._lightColor.g = this.color.g * this.intensity;
12639
12700
  this._lightColor.b = this.color.b * this.intensity;
@@ -12702,15 +12763,21 @@
12702
12763
  var cullingMaskStart = lightIndex * 2;
12703
12764
  var colorStart = lightIndex * 3;
12704
12765
  var directionStart = lightIndex * 3;
12705
- var lightColor = this._getLightColor();
12766
+ var lightColor = this._getLightIntensityColor();
12706
12767
  var direction = this.direction;
12707
12768
  var data = DirectLight._combinedData;
12708
12769
  var cullingMask = this.cullingMask;
12709
12770
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
12710
12771
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
12711
- data.color[colorStart] = lightColor.r;
12712
- data.color[colorStart + 1] = lightColor.g;
12713
- data.color[colorStart + 2] = lightColor.b;
12772
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
12773
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
12774
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
12775
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
12776
+ } else {
12777
+ data.color[colorStart] = lightColor.r;
12778
+ data.color[colorStart + 1] = lightColor.g;
12779
+ data.color[colorStart + 2] = lightColor.b;
12780
+ }
12714
12781
  data.direction[directionStart] = direction.x;
12715
12782
  data.direction[directionStart + 1] = direction.y;
12716
12783
  data.direction[directionStart + 2] = direction.z;
@@ -12798,15 +12865,21 @@
12798
12865
  var colorStart = lightIndex * 3;
12799
12866
  var positionStart = lightIndex * 3;
12800
12867
  var distanceStart = lightIndex;
12801
- var lightColor = this._getLightColor();
12868
+ var lightColor = this._getLightIntensityColor();
12802
12869
  var lightPosition = this.position;
12803
12870
  var data = PointLight._combinedData;
12804
12871
  var cullingMask = this.cullingMask;
12805
12872
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
12806
12873
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
12807
- data.color[colorStart] = lightColor.r;
12808
- data.color[colorStart + 1] = lightColor.g;
12809
- data.color[colorStart + 2] = lightColor.b;
12874
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
12875
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
12876
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
12877
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
12878
+ } else {
12879
+ data.color[colorStart] = lightColor.r;
12880
+ data.color[colorStart + 1] = lightColor.g;
12881
+ data.color[colorStart + 2] = lightColor.b;
12882
+ }
12810
12883
  data.position[positionStart] = lightPosition.x;
12811
12884
  data.position[positionStart + 1] = lightPosition.y;
12812
12885
  data.position[positionStart + 2] = lightPosition.z;
@@ -12898,16 +12971,22 @@
12898
12971
  var distanceStart = lightIndex;
12899
12972
  var penumbraCosStart = lightIndex;
12900
12973
  var angleCosStart = lightIndex;
12901
- var color = this._getLightColor();
12974
+ var lightColor = this._getLightIntensityColor();
12902
12975
  var position = this.position;
12903
12976
  var direction = this.direction;
12904
12977
  var data = SpotLight._combinedData;
12905
12978
  var cullingMask = this.cullingMask;
12906
12979
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
12907
12980
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
12908
- data.color[colorStart] = color.r;
12909
- data.color[colorStart + 1] = color.g;
12910
- data.color[colorStart + 2] = color.b;
12981
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
12982
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
12983
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
12984
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
12985
+ } else {
12986
+ data.color[colorStart] = lightColor.r;
12987
+ data.color[colorStart + 1] = lightColor.g;
12988
+ data.color[colorStart + 2] = lightColor.b;
12989
+ }
12911
12990
  data.position[positionStart] = position.x;
12912
12991
  data.position[positionStart + 1] = position.y;
12913
12992
  data.position[positionStart + 2] = position.z;
@@ -13544,6 +13623,7 @@
13544
13623
  _proto.cloneTo = function cloneTo(target) {
13545
13624
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
13546
13625
  Object.assign(target._macroMap, this._macroMap);
13626
+ var referCount = target._getReferCount();
13547
13627
  var propertyValueMap = this._propertyValueMap;
13548
13628
  var targetPropertyValueMap = target._propertyValueMap;
13549
13629
  var keys = Object.keys(propertyValueMap);
@@ -13555,6 +13635,7 @@
13555
13635
  targetPropertyValueMap[k] = property;
13556
13636
  } else if (_instanceof1$2(property, Texture)) {
13557
13637
  targetPropertyValueMap[k] = property;
13638
+ referCount > 0 && property._addReferCount(referCount);
13558
13639
  } else if (_instanceof1$2(property, Array) || _instanceof1$2(property, Float32Array) || _instanceof1$2(property, Int32Array)) {
13559
13640
  targetPropertyValueMap[k] = property.slice();
13560
13641
  } else {
@@ -14097,9 +14178,9 @@
14097
14178
  var Material = function Material(engine, shader) {
14098
14179
  var _this;
14099
14180
  _this = ReferResource.call(this, engine) || this;
14100
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Material);
14101
14181
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
14102
14182
  ;
14183
+ _this._shaderData = new ShaderData(ShaderDataGroup.Material);
14103
14184
  _this.shader = shader;
14104
14185
  return _this;
14105
14186
  };
@@ -14124,7 +14205,23 @@
14124
14205
  ReferResource.prototype._addReferCount.call(this, value);
14125
14206
  this.shaderData._addReferCount(value);
14126
14207
  };
14208
+ /**
14209
+ * @override
14210
+ */ _proto._onDestroy = function _onDestroy() {
14211
+ this._shader = null;
14212
+ this._shaderData = null;
14213
+ this._renderStates.length = 0;
14214
+ this._renderStates = null;
14215
+ };
14127
14216
  _create_class$3(Material, [
14217
+ {
14218
+ key: "shaderData",
14219
+ get: /**
14220
+ * Shader data.
14221
+ */ function get() {
14222
+ return this._shaderData;
14223
+ }
14224
+ },
14128
14225
  {
14129
14226
  key: "shader",
14130
14227
  get: /**
@@ -14196,6 +14293,12 @@
14196
14293
  */ _proto.resetPool = function resetPool() {
14197
14294
  this._elementPoolIndex = 0;
14198
14295
  };
14296
+ _proto.garbageCollection = function garbageCollection() {
14297
+ var _this = this, pool = _this._elementPool;
14298
+ for(var i = pool.length - 1; i >= 0; i--){
14299
+ pool[i].dispose && pool[i].dispose();
14300
+ }
14301
+ };
14199
14302
  return ClassPool;
14200
14303
  }();
14201
14304
  var RenderData = function RenderData() {};
@@ -14213,6 +14316,9 @@
14213
14316
  this.mesh = mesh;
14214
14317
  this.subMesh = subMesh;
14215
14318
  };
14319
+ _proto.dispose = function dispose() {
14320
+ this.component = this.material = this.mesh = this.subMesh = null;
14321
+ };
14216
14322
  return MeshRenderData;
14217
14323
  }(RenderData);
14218
14324
  /**
@@ -14234,9 +14340,9 @@
14234
14340
  }
14235
14341
  var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // eslint-disable-line
14236
14342
  var common = "#define GLSLIFY 1\n#define PI 3.14159265359\n#define RECIPROCAL_PI 0.31830988618\n#define EPSILON 1e-6\n#define LOG2 1.442695\n#define saturate( a ) clamp( a, 0.0, 1.0 )\nfloat pow2(float x){return x*x;}vec4 RGBMToLinear(vec4 value,float maxRange){return vec4(value.rgb*value.a*maxRange,1.0);}vec4 gammaToLinear(vec4 srgbIn){return vec4(pow(srgbIn.rgb,vec3(2.2)),srgbIn.a);}vec4 linearToGamma(vec4 linearIn){return vec4(pow(linearIn.rgb,vec3(1.0/2.2)),linearIn.a);}\n#ifdef GRAPHICS_API_WEBGL2\n#define INVERSE_MAT(mat) inverse(mat)\n#else\nmat2 inverseMat(mat2 m){return mat2(m[1][1],-m[0][1],-m[1][0],m[0][0])/(m[0][0]*m[1][1]-m[0][1]*m[1][0]);}mat3 inverseMat(mat3 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2];float a10=m[1][0],a11=m[1][1],a12=m[1][2];float a20=m[2][0],a21=m[2][1],a22=m[2][2];float b01=a22*a11-a12*a21;float b11=-a22*a10+a12*a20;float b21=a21*a10-a11*a20;float det=a00*b01+a01*b11+a02*b21;return mat3(b01,(-a22*a01+a02*a21),(a12*a01-a02*a11),b11,(a22*a00-a02*a20),(-a12*a00+a02*a10),b21,(-a21*a00+a01*a20),(a11*a00-a01*a10))/det;}mat4 inverseMat(mat4 m){float a00=m[0][0],a01=m[0][1],a02=m[0][2],a03=m[0][3],a10=m[1][0],a11=m[1][1],a12=m[1][2],a13=m[1][3],a20=m[2][0],a21=m[2][1],a22=m[2][2],a23=m[2][3],a30=m[3][0],a31=m[3][1],a32=m[3][2],a33=m[3][3],b00=a00*a11-a01*a10,b01=a00*a12-a02*a10,b02=a00*a13-a03*a10,b03=a01*a12-a02*a11,b04=a01*a13-a03*a11,b05=a02*a13-a03*a12,b06=a20*a31-a21*a30,b07=a20*a32-a22*a30,b08=a20*a33-a23*a30,b09=a21*a32-a22*a31,b10=a21*a33-a23*a31,b11=a22*a33-a23*a32,det=b00*b11-b01*b10+b02*b09+b03*b08-b04*b07+b05*b06;return mat4(a11*b11-a12*b10+a13*b09,a02*b10-a01*b11-a03*b09,a31*b05-a32*b04+a33*b03,a22*b04-a21*b05-a23*b03,a12*b08-a10*b11-a13*b07,a00*b11-a02*b08+a03*b07,a32*b02-a30*b05-a33*b01,a20*b05-a22*b02+a23*b01,a10*b10-a11*b08+a13*b06,a01*b08-a00*b10-a03*b06,a30*b04-a31*b02+a33*b00,a21*b02-a20*b04-a23*b00,a11*b07-a10*b09-a12*b06,a00*b09-a01*b07+a02*b06,a31*b01-a30*b03-a32*b00,a20*b03-a21*b01+a22*b00)/det;}\n#define INVERSE_MAT(mat) inverseMat(mat)\n#endif\n"; // eslint-disable-line
14237
- var common_vert = "#define GLSLIFY 1\nattribute vec3 POSITION;\n#ifdef RENDERER_HAS_UV\nattribute vec2 TEXCOORD_0;\n#endif\n#ifdef RENDERER_HAS_UV1\nattribute vec2 TEXCOORD_1;\n#endif\n#ifdef RENDERER_HAS_SKIN\nattribute vec4 JOINTS_0;attribute vec4 WEIGHTS_0;\n#ifdef RENDERER_USE_JOINT_TEXTURE\nuniform sampler2D renderer_JointSampler;uniform float renderer_JointCount;mat4 getJointMatrix(sampler2D smp,float index){float base=index/renderer_JointCount;float hf=0.5/renderer_JointCount;float v=base+hf;vec4 m0=texture2D(smp,vec2(0.125,v));vec4 m1=texture2D(smp,vec2(0.375,v));vec4 m2=texture2D(smp,vec2(0.625,v));vec4 m3=texture2D(smp,vec2(0.875,v));return mat4(m0,m1,m2,m3);}\n#else\nuniform mat4 renderer_JointMatrix[RENDERER_JOINTS_NUM];\n#endif\n#endif\n#ifdef RENDERER_HAS_VERTEXCOLOR\nattribute vec4 COLOR_0;\n#endif\n#include <transform_declare>\n#include <camera_declare>\nuniform vec4 material_TilingOffset;\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nattribute vec3 NORMAL;\n#endif\n#ifdef RENDERER_HAS_TANGENT\nattribute vec4 TANGENT;\n#endif\n#endif\n"; // eslint-disable-line
14343
+ var common_vert = "#define GLSLIFY 1\nattribute vec3 POSITION;\n#ifdef RENDERER_HAS_UV\nattribute vec2 TEXCOORD_0;\n#endif\n#ifdef RENDERER_HAS_UV1\nattribute vec2 TEXCOORD_1;\n#endif\n#ifdef RENDERER_HAS_SKIN\nattribute vec4 JOINTS_0;attribute vec4 WEIGHTS_0;\n#ifdef RENDERER_USE_JOINT_TEXTURE\nuniform sampler2D renderer_JointSampler;uniform float renderer_JointCount;mat4 getJointMatrix(sampler2D smp,float index){float base=index/renderer_JointCount;float hf=0.5/renderer_JointCount;float v=base+hf;vec4 m0=texture2D(smp,vec2(0.125,v));vec4 m1=texture2D(smp,vec2(0.375,v));vec4 m2=texture2D(smp,vec2(0.625,v));vec4 m3=texture2D(smp,vec2(0.875,v));return mat4(m0,m1,m2,m3);}\n#else\nuniform mat4 renderer_JointMatrix[RENDERER_JOINTS_NUM];\n#endif\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nattribute vec4 COLOR_0;\n#endif\n#include <transform_declare>\n#include <camera_declare>\nuniform vec4 material_TilingOffset;\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nattribute vec3 NORMAL;\n#endif\n#ifdef RENDERER_HAS_TANGENT\nattribute vec4 TANGENT;\n#endif\n#endif\n"; // eslint-disable-line
14238
14344
  var transform_declare = "#define GLSLIFY 1\nuniform mat4 renderer_LocalMat;uniform mat4 renderer_ModelMat;uniform mat4 camera_ViewMat;uniform mat4 camera_ProjMat;uniform mat4 renderer_MVMat;uniform mat4 renderer_MVPMat;uniform mat4 renderer_NormalMat;"; // eslint-disable-line
14239
- var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
14345
+ var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
14240
14346
  var FogFragmentDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvarying vec3 v_positionVS;uniform vec4 scene_FogColor;uniform vec4 scene_FogParams;float ComputeFogIntensity(float fogDepth){\n#if SCENE_FOG_MODE == 1\nreturn clamp(fogDepth*scene_FogParams.x+scene_FogParams.y,0.0,1.0);\n#elif SCENE_FOG_MODE == 2\nreturn clamp(exp2(-fogDepth*scene_FogParams.z),0.0,1.0);\n#elif SCENE_FOG_MODE == 3\nfloat factor=fogDepth*scene_FogParams.w;return clamp(exp2(-factor*factor),0.0,1.0);\n#endif\n}\n#endif\n"; // eslint-disable-line
14241
14347
  var FogVertexDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvarying vec3 v_positionVS;\n#endif\n"; // eslint-disable-line
14242
14348
  var normal_share = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nvarying vec3 v_normal;\n#if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nvarying mat3 v_TBN;\n#endif\n#endif\n#endif\n"; // eslint-disable-line
@@ -14246,7 +14352,7 @@
14246
14352
  var begin_position_vert = "#define GLSLIFY 1\nvec4 position=vec4(POSITION,1.0);"; // eslint-disable-line
14247
14353
  var blendShape_input = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nuniform mediump sampler2DArray renderer_BlendShapeTexture;uniform ivec3 renderer_BlendShapeTextureInfo;uniform float renderer_BlendShapeWeights[RENDERER_BLENDSHAPE_COUNT];\n#else\nattribute vec3 POSITION_BS0;attribute vec3 POSITION_BS1;\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\nattribute vec3 NORMAL_BS0;attribute vec3 NORMAL_BS1;attribute vec3 TANGENT_BS0;attribute vec3 TANGENT_BS1;uniform float renderer_BlendShapeWeights[2];\n#else\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\nattribute vec3 POSITION_BS2;attribute vec3 POSITION_BS3;\n#ifdef RENDERER_BLENDSHAPE_HAS_NORMAL\nattribute vec3 NORMAL_BS0;attribute vec3 NORMAL_BS1;attribute vec3 NORMAL_BS2;attribute vec3 NORMAL_BS3;\n#endif\n#ifdef RENDERER_BLENDSHAPE_HAS_TANGENT\nattribute vec3 TANGENT_BS0;attribute vec3 TANGENT_BS1;attribute vec3 TANGENT_BS2;attribute vec3 TANGENT_BS3;\n#endif\nuniform float renderer_BlendShapeWeights[4];\n#else\nattribute vec3 POSITION_BS2;attribute vec3 POSITION_BS3;attribute vec3 POSITION_BS4;attribute vec3 POSITION_BS5;attribute vec3 POSITION_BS6;attribute vec3 POSITION_BS7;uniform float renderer_BlendShapeWeights[8];\n#endif\n#endif\n#endif\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nvec3 getBlendShapeVertexElement(int blendShapeIndex,int vertexElementIndex){int y=vertexElementIndex/renderer_BlendShapeTextureInfo.y;int x=vertexElementIndex-y*renderer_BlendShapeTextureInfo.y;ivec3 uv=ivec3(x,y,blendShapeIndex);return texelFetch(renderer_BlendShapeTexture,uv,0).xyz;}\n#endif\n#endif\n"; // eslint-disable-line
14248
14354
  var blendShape_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifdef RENDERER_BLENDSHAPE_USE_TEXTURE\nint vertexOffset=gl_VertexID*renderer_BlendShapeTextureInfo.x;for(int i=0;i<RENDERER_BLENDSHAPE_COUNT;i++){int vertexElementOffset=vertexOffset;float weight=renderer_BlendShapeWeights[i];position.xyz+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#ifndef MATERIAL_OMIT_NORMAL\n#if defined( RENDERER_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_NORMAL )\nvertexElementOffset+=1;normal+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#endif\n#if defined( RENDERER_HAS_TANGENT ) && defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nvertexElementOffset+=1;tangent.xyz+=getBlendShapeVertexElement(i,vertexElementOffset)*weight;\n#endif\n#endif\n}\n#else\nposition.xyz+=POSITION_BS0*renderer_BlendShapeWeights[0];position.xyz+=POSITION_BS1*renderer_BlendShapeWeights[1];\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nnormal+=NORMAL_BS0*renderer_BlendShapeWeights[0];normal+=NORMAL_BS1*renderer_BlendShapeWeights[1];\n#endif\n#if defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\ntangent.xyz+=TANGENT_BS0*renderer_BlendShapeWeights[0];tangent.xyz+=TANGENT_BS1*renderer_BlendShapeWeights[1];\n#endif\n#endif\n#else\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) || defined( RENDERER_BLENDSHAPE_HAS_TANGENT )\n#ifndef MATERIAL_OMIT_NORMAL\nposition.xyz+=POSITION_BS2*renderer_BlendShapeWeights[2];position.xyz+=POSITION_BS3*renderer_BlendShapeWeights[3];\n#if defined( RENDERER_BLENDSHAPE_HAS_NORMAL ) && defined( RENDERER_HAS_NORMAL )\nnormal+=NORMAL_BS0*renderer_BlendShapeWeights[0];normal+=NORMAL_BS1*renderer_BlendShapeWeights[1];normal+=NORMAL_BS2*renderer_BlendShapeWeights[2];normal+=NORMAL_BS3*renderer_BlendShapeWeights[3];\n#endif\n#if defined(RENDERER_BLENDSHAPE_HAS_TANGENT) && defined( RENDERER_HAS_TANGENT ) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\ntangent.xyz+=TANGENT_BS0*renderer_BlendShapeWeights[0];tangent.xyz+=TANGENT_BS1*renderer_BlendShapeWeights[1];tangent.xyz+=TANGENT_BS2*renderer_BlendShapeWeights[2];tangent.xyz+=TANGENT_BS3*renderer_BlendShapeWeights[3];\n#endif\n#endif\n#else\nposition.xyz+=POSITION_BS2*renderer_BlendShapeWeights[2];position.xyz+=POSITION_BS3*renderer_BlendShapeWeights[3];position.xyz+=POSITION_BS4*renderer_BlendShapeWeights[4];position.xyz+=POSITION_BS5*renderer_BlendShapeWeights[5];position.xyz+=POSITION_BS6*renderer_BlendShapeWeights[6];position.xyz+=POSITION_BS7*renderer_BlendShapeWeights[7];\n#endif\n#endif\n#endif\n#endif\n"; // eslint-disable-line
14249
- var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
14355
+ var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
14250
14356
  var FogVertex = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvec4 positionVS=renderer_MVMat*position;v_positionVS=positionVS.xyz/positionVS.w;\n#endif\n"; // eslint-disable-line
14251
14357
  var normal_vert = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef RENDERER_HAS_NORMAL\nv_normal=normalize(mat3(renderer_NormalMat)*normal);\n#if defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nvec3 normalW=normalize(mat3(renderer_NormalMat)*normal.xyz);vec3 tangentW=normalize(mat3(renderer_NormalMat)*tangent.xyz);vec3 bitangentW=cross(normalW,tangentW)*tangent.w;v_TBN=mat3(tangentW,bitangentW,normalW);\n#endif\n#endif\n#endif\n"; // eslint-disable-line
14252
14358
  var position_vert = "#define GLSLIFY 1\ngl_Position=renderer_MVPMat*position;"; // eslint-disable-line
@@ -14256,9 +14362,9 @@
14256
14362
  var FogFragment = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nfloat fogIntensity=ComputeFogIntensity(length(v_positionVS));gl_FragColor.rgb=mix(scene_FogColor.rgb,gl_FragColor.rgb,fogIntensity);\n#endif\n"; // eslint-disable-line
14257
14363
  var light_frag_define = "#define GLSLIFY 1\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nstruct DirectLight{vec3 color;vec3 direction;};uniform ivec2 scene_DirectLightCullingMask[SCENE_DIRECT_LIGHT_COUNT];uniform vec3 scene_DirectLightColor[SCENE_DIRECT_LIGHT_COUNT];uniform vec3 scene_DirectLightDirection[SCENE_DIRECT_LIGHT_COUNT];\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nstruct PointLight{vec3 color;vec3 position;float distance;};uniform ivec2 scene_PointLightCullingMask[SCENE_POINT_LIGHT_COUNT];uniform vec3 scene_PointLightColor[SCENE_POINT_LIGHT_COUNT];uniform vec3 scene_PointLightPosition[SCENE_POINT_LIGHT_COUNT];uniform float scene_PointLightDistance[SCENE_POINT_LIGHT_COUNT];\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nstruct SpotLight{vec3 color;vec3 position;vec3 direction;float distance;float angleCos;float penumbraCos;};uniform ivec2 scene_SpotLightCullingMask[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightColor[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightPosition[SCENE_SPOT_LIGHT_COUNT];uniform vec3 scene_SpotLightDirection[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightDistance[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightAngleCos[SCENE_SPOT_LIGHT_COUNT];uniform float scene_SpotLightPenumbraCos[SCENE_SPOT_LIGHT_COUNT];\n#endif\nstruct EnvMapLight{vec3 diffuse;float mipMapLevel;float diffuseIntensity;float specularIntensity;};uniform EnvMapLight scene_EnvMapLight;uniform ivec4 renderer_Layer;\n#ifdef SCENE_USE_SH\nuniform vec3 scene_EnvSH[9];\n#endif\n#ifdef SCENE_USE_SPECULAR_ENV\nuniform samplerCube scene_EnvSpecularSampler;\n#endif\n#ifndef GRAPHICS_API_WEBGL2\nbool isBitSet(float value,float mask,float bitIndex){return mod(floor(value/pow(2.0,bitIndex)),2.0)==1.0&&mod(floor(mask/pow(2.0,bitIndex)),2.0)==1.0;}\n#endif\nbool isRendererCulledByLight(ivec2 rendererLayer,ivec2 lightCullingMask){\n#ifdef GRAPHICS_API_WEBGL2\nreturn!((rendererLayer.x&lightCullingMask.x)!=0||(rendererLayer.y&lightCullingMask.y)!=0);\n#else\nfor(int i=0;i<16;i++){if(isBitSet(float(rendererLayer.x),float(lightCullingMask.x),float(i))||isBitSet(float(rendererLayer.y),float(lightCullingMask.y),float(i))){return false;}}return true;\n#endif\n}"; // eslint-disable-line
14258
14364
  var mobile_material_frag = "#define GLSLIFY 1\nuniform vec4 material_EmissiveColor;uniform vec4 material_BaseColor;uniform vec4 material_SpecularColor;uniform float material_Shininess;uniform float material_NormalIntensity;uniform float material_AlphaCutoff;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nuniform sampler2D material_SpecularTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n"; // eslint-disable-line
14259
- var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_HAS_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
14365
+ var begin_mobile_frag = "#define GLSLIFY 1\nvec4 ambient=vec4(0.0);vec4 emission=material_EmissiveColor;vec4 diffuse=material_BaseColor;vec4 specular=material_SpecularColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveTextureColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveTextureColor=gammaToLinear(emissiveTextureColor);\n#endif\nemission*=emissiveTextureColor;\n#endif\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 diffuseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\ndiffuseTextureColor=gammaToLinear(diffuseTextureColor);\n#endif\ndiffuse*=diffuseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\ndiffuse*=v_color;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_TEXTURE\nvec4 specularTextureColor=texture2D(material_SpecularTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularTextureColor=gammaToLinear(specularTextureColor);\n#endif\nspecular*=specularTextureColor;\n#endif\nambient=vec4(scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity,1.0)*diffuse;"; // eslint-disable-line
14260
14366
  var begin_viewdir_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\nvec3 V=normalize(camera_Position-v_pos);\n#endif\n"; // eslint-disable-line
14261
- var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN();vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv);\n#else\nvec3 N=getNormal();\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();int sunIndex=int(scene_ShadowInfo.z);\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==sunIndex){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
14367
+ var mobile_blinnphong_frag = "#define GLSLIFY 1\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nmat3 tbn=getTBN(gl_FrontFacing);vec3 N=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,gl_FrontFacing);\n#else\nvec3 N=getNormal(gl_FrontFacing);\n#endif\nvec3 lightDiffuse=vec3(0.0,0.0,0.0);vec3 lightSpecular=vec3(0.0,0.0,0.0);float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();int sunIndex=int(scene_ShadowInfo.z);\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==sunIndex){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];float d=max(dot(N,-directionalLight.direction),0.0);lightDiffuse+=directionalLight.color*d;vec3 halfDir=normalize(V-directionalLight.direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess);lightSpecular+=directionalLight.color*s;}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];vec3 direction=v_pos-pointLight.position;float dist=length(direction);direction/=dist;float decay=clamp(1.0-pow(dist/pointLight.distance,4.0),0.0,1.0);float d=max(dot(N,-direction),0.0)*decay;lightDiffuse+=pointLight.color*d;vec3 halfDir=normalize(V-direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decay;lightSpecular+=pointLight.color*s;}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];vec3 direction=spotLight.position-v_pos;float lightDistance=length(direction);direction/=lightDistance;float angleCos=dot(direction,-spotLight.direction);float decay=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayTotal=decay*spotEffect;float d=max(dot(N,direction),0.0)*decayTotal;lightDiffuse+=spotLight.color*d;vec3 halfDir=normalize(V+direction);float s=pow(clamp(dot(N,halfDir),0.0,1.0),material_Shininess)*decayTotal;lightSpecular+=spotLight.color*s;}\n#endif\ndiffuse*=vec4(lightDiffuse,1.0);specular*=vec4(lightSpecular,1.0);\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(diffuse.a<material_AlphaCutoff){discard;}\n#endif\n"; // eslint-disable-line
14262
14368
  var noise_cellular = "#define GLSLIFY 1\n#include <noise_cellular_2D>\n#include <noise_cellular_3D>\n#include <noise_cellular_2x2>\n#include <noise_cellular_2x2x2>\n"; // eslint-disable-line
14263
14369
  var noise_cellular_2D = "#define GLSLIFY 1\nvec2 cellular(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec3 oi=vec3(-1.0,0.0,1.0);vec3 of=vec3(-0.5,0.5,1.5);vec3 px=permute(Pi.x+oi);vec3 p=permute(px.x+Pi.y+oi);vec3 ox=fract(p*K)-Ko;vec3 oy=mod7(floor(p*K))*K-Ko;vec3 dx=Pf.x+0.5+jitter*ox;vec3 dy=Pf.y-of+jitter*oy;vec3 d1=dx*dx+dy*dy;p=permute(px.y+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-0.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d2=dx*dx+dy*dy;p=permute(px.z+Pi.y+oi);ox=fract(p*K)-Ko;oy=mod7(floor(p*K))*K-Ko;dx=Pf.x-1.5+jitter*ox;dy=Pf.y-of+jitter*oy;vec3 d3=dx*dx+dy*dy;vec3 d1a=min(d1,d2);d2=max(d1,d2);d2=min(d2,d3);d1=min(d1a,d2);d2=max(d1a,d2);d1.xy=(d1.x<d1.y)? d1.xy : d1.yx;d1.xz=(d1.x<d1.z)? d1.xz : d1.zx;d1.yz=min(d1.yz,d2.yz);d1.y=min(d1.y,d1.z);d1.y=min(d1.y,d2.x);return sqrt(d1.xy);}"; // eslint-disable-line
14264
14370
  var noise_cellular_2x2 = "#define GLSLIFY 1\nvec2 cellular2x2(vec2 P){vec2 Pi=mod289(floor(P));vec2 Pf=fract(P);vec4 Pfx=Pf.x+vec4(-0.5,-1.5,-0.5,-1.5);vec4 Pfy=Pf.y+vec4(-0.5,-0.5,-1.5,-1.5);vec4 p=permute(Pi.x+vec4(0.0,1.0,0.0,1.0));p=permute(p+Pi.y+vec4(0.0,0.0,1.0,1.0));vec4 ox=mod7(p)*K+Kd2;vec4 oy=mod7(floor(p*K))*K+Kd2;vec4 dx=Pfx+jitter1*ox;vec4 dy=Pfy+jitter1*oy;vec4 d=dx*dx+dy*dy;d.xy=(d.x<d.y)? d.xy : d.yx;d.xz=(d.x<d.z)? d.xz : d.zx;d.xw=(d.x<d.w)? d.xw : d.wx;d.y=min(d.y,d.z);d.y=min(d.y,d.w);return sqrt(d.xy);}"; // eslint-disable-line
@@ -14275,12 +14381,12 @@
14275
14381
  var noise_simplex_3D = "#define GLSLIFY 1\nfloat simplex(vec3 v){const vec2 C=vec2(1.0/6.0,1.0/3.0);const vec4 D=vec4(0.0,0.5,1.0,2.0);vec3 i=floor(v+dot(v,C.yyy));vec3 x0=v-i+dot(i,C.xxx);vec3 g=step(x0.yzx,x0.xyz);vec3 l=1.0-g;vec3 i1=min(g.xyz,l.zxy);vec3 i2=max(g.xyz,l.zxy);vec3 x1=x0-i1+C.xxx;vec3 x2=x0-i2+C.yyy;vec3 x3=x0-D.yyy;i=mod289(i);vec4 p=permute(permute(permute(i.z+vec4(0.0,i1.z,i2.z,1.0))+i.y+vec4(0.0,i1.y,i2.y,1.0))+i.x+vec4(0.0,i1.x,i2.x,1.0));float n_=0.142857142857;vec3 ns=n_*D.wyz-D.xzx;vec4 j=p-49.0*floor(p*ns.z*ns.z);vec4 x_=floor(j*ns.z);vec4 y_=floor(j-7.0*x_);vec4 x=x_*ns.x+ns.yyyy;vec4 y=y_*ns.x+ns.yyyy;vec4 h=1.0-abs(x)-abs(y);vec4 b0=vec4(x.xy,y.xy);vec4 b1=vec4(x.zw,y.zw);vec4 s0=floor(b0)*2.0+1.0;vec4 s1=floor(b1)*2.0+1.0;vec4 sh=-step(h,vec4(0.0));vec4 a0=b0.xzyw+s0.xzyw*sh.xxyy;vec4 a1=b1.xzyw+s1.xzyw*sh.zzww;vec3 p0=vec3(a0.xy,h.x);vec3 p1=vec3(a0.zw,h.y);vec3 p2=vec3(a1.xy,h.z);vec3 p3=vec3(a1.zw,h.w);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;vec4 m=max(0.6-vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);m=m*m;return 42.0*dot(m*m,vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3)));}"; // eslint-disable-line
14276
14382
  var noise_simplex_3D_grad = "#define GLSLIFY 1\nfloat simplex(vec3 v,out vec3 gradient){const vec2 C=vec2(1.0/6.0,1.0/3.0);const vec4 D=vec4(0.0,0.5,1.0,2.0);vec3 i=floor(v+dot(v,C.yyy));vec3 x0=v-i+dot(i,C.xxx);vec3 g=step(x0.yzx,x0.xyz);vec3 l=1.0-g;vec3 i1=min(g.xyz,l.zxy);vec3 i2=max(g.xyz,l.zxy);vec3 x1=x0-i1+C.xxx;vec3 x2=x0-i2+C.yyy;vec3 x3=x0-D.yyy;i=mod289(i);vec4 p=permute(permute(permute(i.z+vec4(0.0,i1.z,i2.z,1.0))+i.y+vec4(0.0,i1.y,i2.y,1.0))+i.x+vec4(0.0,i1.x,i2.x,1.0));float n_=0.142857142857;vec3 ns=n_*D.wyz-D.xzx;vec4 j=p-49.0*floor(p*ns.z*ns.z);vec4 x_=floor(j*ns.z);vec4 y_=floor(j-7.0*x_);vec4 x=x_*ns.x+ns.yyyy;vec4 y=y_*ns.x+ns.yyyy;vec4 h=1.0-abs(x)-abs(y);vec4 b0=vec4(x.xy,y.xy);vec4 b1=vec4(x.zw,y.zw);vec4 s0=floor(b0)*2.0+1.0;vec4 s1=floor(b1)*2.0+1.0;vec4 sh=-step(h,vec4(0.0));vec4 a0=b0.xzyw+s0.xzyw*sh.xxyy;vec4 a1=b1.xzyw+s1.xzyw*sh.zzww;vec3 p0=vec3(a0.xy,h.x);vec3 p1=vec3(a0.zw,h.y);vec3 p2=vec3(a1.xy,h.z);vec3 p3=vec3(a1.zw,h.w);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;vec4 m=max(0.6-vec4(dot(x0,x0),dot(x1,x1),dot(x2,x2),dot(x3,x3)),0.0);vec4 m2=m*m;vec4 m4=m2*m2;vec4 pdotx=vec4(dot(p0,x0),dot(p1,x1),dot(p2,x2),dot(p3,x3));vec4 temp=m2*m*pdotx;gradient=-8.0*(temp.x*x0+temp.y*x1+temp.z*x2+temp.w*x3);gradient+=m4.x*p0+m4.y*p1+m4.z*p2+m4.w*p3;gradient*=42.0;return 42.0*dot(m4,pdotx);}"; // eslint-disable-line
14277
14383
  var noise_simplex_4D = "#define GLSLIFY 1\nvec4 grad4(float j,vec4 ip){const vec4 ones=vec4(1.0,1.0,1.0,-1.0);vec4 p,s;p.xyz=floor(fract(vec3(j)*ip.xyz)*7.0)*ip.z-1.0;p.w=1.5-dot(abs(p.xyz),ones.xyz);s=vec4(lessThan(p,vec4(0.0)));p.xyz=p.xyz+(s.xyz*2.0-1.0)*s.www;return p;}\n#define F4 0.309016994374947451\nfloat simplex(vec4 v){const vec4 C=vec4(0.138196601125011,0.276393202250021,0.414589803375032,-0.447213595499958);vec4 i=floor(v+dot(v,vec4(F4)));vec4 x0=v-i+dot(i,C.xxxx);vec4 i0;vec3 isX=step(x0.yzw,x0.xxx);vec3 isYZ=step(x0.zww,x0.yyz);i0.x=isX.x+isX.y+isX.z;i0.yzw=1.0-isX;i0.y+=isYZ.x+isYZ.y;i0.zw+=1.0-isYZ.xy;i0.z+=isYZ.z;i0.w+=1.0-isYZ.z;vec4 i3=clamp(i0,0.0,1.0);vec4 i2=clamp(i0-1.0,0.0,1.0);vec4 i1=clamp(i0-2.0,0.0,1.0);vec4 x1=x0-i1+C.xxxx;vec4 x2=x0-i2+C.yyyy;vec4 x3=x0-i3+C.zzzz;vec4 x4=x0+C.wwww;i=mod289(i);float j0=permute(permute(permute(permute(i.w)+i.z)+i.y)+i.x);vec4 j1=permute(permute(permute(permute(i.w+vec4(i1.w,i2.w,i3.w,1.0))+i.z+vec4(i1.z,i2.z,i3.z,1.0))+i.y+vec4(i1.y,i2.y,i3.y,1.0))+i.x+vec4(i1.x,i2.x,i3.x,1.0));vec4 ip=vec4(1.0/294.0,1.0/49.0,1.0/7.0,0.0);vec4 p0=grad4(j0,ip);vec4 p1=grad4(j1.x,ip);vec4 p2=grad4(j1.y,ip);vec4 p3=grad4(j1.z,ip);vec4 p4=grad4(j1.w,ip);vec4 norm=taylorInvSqrt(vec4(dot(p0,p0),dot(p1,p1),dot(p2,p2),dot(p3,p3)));p0*=norm.x;p1*=norm.y;p2*=norm.z;p3*=norm.w;p4*=taylorInvSqrt(dot(p4,p4));vec3 m0=max(0.6-vec3(dot(x0,x0),dot(x1,x1),dot(x2,x2)),0.0);vec2 m1=max(0.6-vec2(dot(x3,x3),dot(x4,x4)),0.0);m0=m0*m0;m1=m1*m1;return 49.0*(dot(m0*m0,vec3(dot(p0,x0),dot(p1,x1),dot(p2,x2)))+dot(m1*m1,vec2(dot(p3,x3),dot(p4,x4))));}"; // eslint-disable-line
14278
- var pbr_frag_define = "#define GLSLIFY 1\nuniform float material_AlphaCutoff;uniform vec4 material_BaseColor;uniform float material_Metal;uniform float material_Roughness;uniform vec3 material_PBRSpecularColor;uniform float material_Glossiness;uniform vec3 material_EmissiveColor;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\n#endif\nuniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D MATERIAL_HAS_EMISSIVETEXTURE;\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nuniform sampler2D material_RoughnessMetallicTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nuniform sampler2D material_SpecularGlossinessTexture;\n#endif\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nuniform sampler2D material_OcclusionTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nuniform sampler2D material_ClearCoatTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nuniform sampler2D material_ClearCoatRoughnessTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\nuniform sampler2D material_ClearCoatNormalTexture;\n#endif\nstruct ReflectedLight{vec3 directDiffuse;vec3 directSpecular;vec3 indirectDiffuse;vec3 indirectSpecular;};struct Geometry{vec3 position;vec3 normal;vec3 viewDir;float dotNV;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatNormal;float clearCoatDotNV;\n#endif\n};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
14279
- var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return 0.04+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn 0.04;\n#endif\n}void initGeometry(out Geometry geometry){geometry.position=v_pos;geometry.viewDir=normalize(camera_Position-v_pos);\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE)\nmat3 tbn=getTBN();\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv);\n#else\ngeometry.normal=getNormal();\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv);\n#else\ngeometry.clearCoatNormal=getNormal();\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n}void initMaterial(out Material material,const in Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_HAS_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(0.04),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
14384
+ var pbr_frag_define = "#define GLSLIFY 1\nuniform float material_AlphaCutoff;uniform vec4 material_BaseColor;uniform float material_Metal;uniform float material_Roughness;uniform float material_IOR;uniform vec3 material_PBRSpecularColor;uniform float material_Glossiness;uniform vec3 material_EmissiveColor;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nuniform float material_ClearCoat;uniform float material_ClearCoatRoughness;\n#endif\nuniform float material_NormalIntensity;uniform float material_OcclusionIntensity;uniform float material_OcclusionTextureCoord;\n#ifdef MATERIAL_HAS_BASETEXTURE\nuniform sampler2D material_BaseTexture;\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\nuniform sampler2D material_NormalTexture;\n#endif\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nuniform sampler2D material_EmissiveTexture;\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nuniform sampler2D material_RoughnessMetallicTexture;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nuniform sampler2D material_SpecularGlossinessTexture;\n#endif\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nuniform sampler2D material_OcclusionTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nuniform sampler2D material_ClearCoatTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nuniform sampler2D material_ClearCoatRoughnessTexture;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\nuniform sampler2D material_ClearCoatNormalTexture;\n#endif\nstruct ReflectedLight{vec3 directDiffuse;vec3 directSpecular;vec3 indirectDiffuse;vec3 indirectSpecular;};struct Geometry{vec3 position;vec3 normal;vec3 viewDir;float dotNV;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatNormal;float clearCoatDotNV;\n#endif\n};struct Material{vec3 diffuseColor;float roughness;vec3 specularColor;float opacity;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoat;float clearCoatRoughness;\n#endif\n};"; // eslint-disable-line
14385
+ var pbr_helper = "#define GLSLIFY 1\n#include <normal_get>\nfloat computeSpecularOcclusion(float ambientOcclusion,float roughness,float dotNV){return saturate(pow(dotNV+ambientOcclusion,exp2(-16.0*roughness-1.0))-1.0+ambientOcclusion);}float getAARoughnessFactor(vec3 normal){\n#ifdef HAS_DERIVATIVES\nvec3 dxy=max(abs(dFdx(normal)),abs(dFdy(normal)));return 0.04+max(max(dxy.x,dxy.y),dxy.z);\n#else\nreturn 0.04;\n#endif\n}void initGeometry(out Geometry geometry,bool isFrontFacing){geometry.position=v_pos;geometry.viewDir=normalize(camera_Position-v_pos);\n#if defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE)\nmat3 tbn=getTBN(isFrontFacing);\n#endif\n#ifdef MATERIAL_HAS_NORMALTEXTURE\ngeometry.normal=getNormalByNormalTexture(tbn,material_NormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.normal=getNormal(isFrontFacing);\n#endif\ngeometry.dotNV=saturate(dot(geometry.normal,geometry.viewDir));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\n#ifdef MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE\ngeometry.clearCoatNormal=getNormalByNormalTexture(tbn,material_ClearCoatNormalTexture,material_NormalIntensity,v_uv,isFrontFacing);\n#else\ngeometry.clearCoatNormal=getNormal(isFrontFacing);\n#endif\ngeometry.clearCoatDotNV=saturate(dot(geometry.clearCoatNormal,geometry.viewDir));\n#endif\n}void initMaterial(out Material material,const in Geometry geometry){vec4 baseColor=material_BaseColor;float metal=material_Metal;float roughness=material_Roughness;vec3 specularColor=material_PBRSpecularColor;float glossiness=material_Glossiness;float alphaCutoff=material_AlphaCutoff;float F0=pow2((material_IOR-1.0)/(material_IOR+1.0));\n#ifdef MATERIAL_HAS_BASETEXTURE\nvec4 baseTextureColor=texture2D(material_BaseTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nbaseTextureColor=gammaToLinear(baseTextureColor);\n#endif\nbaseColor*=baseTextureColor;\n#endif\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nbaseColor*=v_color;\n#endif\n#ifdef MATERIAL_IS_ALPHA_CUTOFF\nif(baseColor.a<alphaCutoff){discard;}\n#endif\n#ifdef MATERIAL_HAS_ROUGHNESS_METALLIC_TEXTURE\nvec4 metalRoughMapColor=texture2D(material_RoughnessMetallicTexture,v_uv);roughness*=metalRoughMapColor.g;metal*=metalRoughMapColor.b;\n#endif\n#ifdef MATERIAL_HAS_SPECULAR_GLOSSINESS_TEXTURE\nvec4 specularGlossinessColor=texture2D(material_SpecularGlossinessTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nspecularGlossinessColor=gammaToLinear(specularGlossinessColor);\n#endif\nspecularColor*=specularGlossinessColor.rgb;glossiness*=specularGlossinessColor.a;\n#endif\n#ifdef IS_METALLIC_WORKFLOW\nmaterial.diffuseColor=baseColor.rgb*(1.0-metal);material.specularColor=mix(vec3(F0),baseColor.rgb,metal);material.roughness=roughness;\n#else\nfloat specularStrength=max(max(specularColor.r,specularColor.g),specularColor.b);material.diffuseColor=baseColor.rgb*(1.0-specularStrength);material.specularColor=specularColor;material.roughness=1.0-glossiness;\n#endif\nmaterial.roughness=max(material.roughness,getAARoughnessFactor(geometry.normal));\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nmaterial.clearCoat=material_ClearCoat;material.clearCoatRoughness=material_ClearCoatRoughness;\n#ifdef MATERIAL_HAS_CLEAR_COAT_TEXTURE\nmaterial.clearCoat*=texture2D(material_ClearCoatTexture,v_uv).r;\n#endif\n#ifdef MATERIAL_HAS_CLEAR_COAT_ROUGHNESS_TEXTURE\nmaterial.clearCoatRoughness*=texture2D(material_ClearCoatRoughnessTexture,v_uv).g;\n#endif\nmaterial.clearCoat=saturate(material.clearCoat);material.clearCoatRoughness=max(material.clearCoatRoughness,getAARoughnessFactor(geometry.clearCoatNormal));\n#endif\n#ifdef MATERIAL_IS_TRANSPARENT\nmaterial.opacity=baseColor.a;\n#else\nmaterial.opacity=1.0;\n#endif\n}\n#include <brdf>\n#include <direct_irradiance_frag_define>\n#include <ibl_frag_define>\n"; // eslint-disable-line
14280
14386
  var brdf = "#define GLSLIFY 1\nfloat F_Schlick(float dotLH){return 0.04+0.96*(pow(1.0-dotLH,5.0));}vec3 F_Schlick(vec3 specularColor,float dotLH){float fresnel=exp2((-5.55473*dotLH-6.98316)*dotLH);return(1.0-specularColor)*fresnel+specularColor;}float G_GGX_SmithCorrelated(float alpha,float dotNL,float dotNV){float a2=pow2(alpha);float gv=dotNL*sqrt(a2+(1.0-a2)*pow2(dotNV));float gl=dotNV*sqrt(a2+(1.0-a2)*pow2(dotNL));return 0.5/max(gv+gl,EPSILON);}float D_GGX(float alpha,float dotNH){float a2=pow2(alpha);float denom=pow2(dotNH)*(a2-1.0)+1.0;return RECIPROCAL_PI*a2/pow2(denom);}vec3 BRDF_Specular_GGX(vec3 incidentDirection,vec3 viewDir,vec3 normal,vec3 specularColor,float roughness){float alpha=pow2(roughness);vec3 halfDir=normalize(incidentDirection+viewDir);float dotNL=saturate(dot(normal,incidentDirection));float dotNV=saturate(dot(normal,viewDir));float dotNH=saturate(dot(normal,halfDir));float dotLH=saturate(dot(incidentDirection,halfDir));vec3 F=F_Schlick(specularColor,dotLH);float G=G_GGX_SmithCorrelated(alpha,dotNL,dotNV);float D=D_GGX(alpha,dotNH);return F*(G*D);}vec3 BRDF_Diffuse_Lambert(vec3 diffuseColor){return RECIPROCAL_PI*diffuseColor;}"; // eslint-disable-line
14281
14387
  var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragmentDeclaration>\nvoid addDirectRadiance(vec3 incidentDirection,vec3 color,Geometry geometry,Material material,inout ReflectedLight reflectedLight){float attenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nfloat clearCoatDotNL=saturate(dot(geometry.clearCoatNormal,incidentDirection));vec3 clearCoatIrradiance=clearCoatDotNL*color;reflectedLight.directSpecular+=material.clearCoat*clearCoatIrradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.clearCoatNormal,vec3(0.04),material.clearCoatRoughness);attenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nfloat dotNL=saturate(dot(geometry.normal,incidentDirection));vec3 irradiance=dotNL*color*PI;reflectedLight.directSpecular+=attenuation*irradiance*BRDF_Specular_GGX(incidentDirection,geometry.viewDir,geometry.normal,material.specularColor,material.roughness);reflectedLight.directDiffuse+=attenuation*irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);}\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nvoid addDirectionalDirectLightRadiance(DirectLight directionalLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 color=directionalLight.color;vec3 direction=-directionalLight.direction;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nvoid addPointDirectLightRadiance(PointLight pointLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=pointLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);vec3 color=pointLight.color;color*=clamp(1.0-pow(lightDistance/pointLight.distance,4.0),0.0,1.0);addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nvoid addSpotDirectLightRadiance(SpotLight spotLight,Geometry geometry,Material material,inout ReflectedLight reflectedLight){vec3 lVector=spotLight.position-geometry.position;vec3 direction=normalize(lVector);float lightDistance=length(lVector);float angleCos=dot(direction,-spotLight.direction);float spotEffect=smoothstep(spotLight.penumbraCos,spotLight.angleCos,angleCos);float decayEffect=clamp(1.0-pow(lightDistance/spotLight.distance,4.0),0.0,1.0);vec3 color=spotLight.color;color*=spotEffect*decayEffect;addDirectRadiance(direction,color,geometry,material,reflectedLight);}\n#endif\nvoid addTotalDirectRadiance(Geometry geometry,Material material,inout ReflectedLight reflectedLight){float shadowAttenuation=1.0;\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nshadowAttenuation=1.0;\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nshadowAttenuation*=sampleShadowMap();int sunIndex=int(scene_ShadowInfo.z);\n#endif\nDirectLight directionalLight;for(int i=0;i<SCENE_DIRECT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_DirectLightCullingMask[i]))continue;directionalLight.color=scene_DirectLightColor[i];\n#ifdef SCENE_IS_CALCULATE_SHADOWS\nif(i==sunIndex){directionalLight.color*=shadowAttenuation;}\n#endif\ndirectionalLight.direction=scene_DirectLightDirection[i];addDirectionalDirectLightRadiance(directionalLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_POINT_LIGHT_COUNT\nPointLight pointLight;for(int i=0;i<SCENE_POINT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_PointLightCullingMask[i]))continue;pointLight.color=scene_PointLightColor[i];pointLight.position=scene_PointLightPosition[i];pointLight.distance=scene_PointLightDistance[i];addPointDirectLightRadiance(pointLight,geometry,material,reflectedLight);}\n#endif\n#ifdef SCENE_SPOT_LIGHT_COUNT\nSpotLight spotLight;for(int i=0;i<SCENE_SPOT_LIGHT_COUNT;i++){if(isRendererCulledByLight(renderer_Layer.xy,scene_SpotLightCullingMask[i]))continue;spotLight.color=scene_SpotLightColor[i];spotLight.position=scene_SpotLightPosition[i];spotLight.direction=scene_SpotLightDirection[i];spotLight.distance=scene_SpotLightDistance[i];spotLight.angleCos=scene_SpotLightAngleCos[i];spotLight.penumbraCos=scene_SpotLightPenumbraCos[i];addSpotDirectLightRadiance(spotLight,geometry,material,reflectedLight);}\n#endif\n}"; // eslint-disable-line
14282
14388
  var ibl_frag_define = "#define GLSLIFY 1\nvec3 getLightProbeIrradiance(vec3 sh[9],vec3 normal){normal.x=-normal.x;vec3 result=sh[0]+sh[1]*(normal.y)+sh[2]*(normal.z)+sh[3]*(normal.x)+sh[4]*(normal.y*normal.x)+sh[5]*(normal.y*normal.z)+sh[6]*(3.0*normal.z*normal.z-1.0)+sh[7]*(normal.z*normal.x)+sh[8]*(normal.x*normal.x-normal.y*normal.y);return max(result,vec3(0.0));}vec3 envBRDFApprox(vec3 specularColor,float roughness,float dotNV){const vec4 c0=vec4(-1,-0.0275,-0.572,0.022);const vec4 c1=vec4(1,0.0425,1.04,-0.04);vec4 r=roughness*c0+c1;float a004=min(r.x*r.x,exp2(-9.28*dotNV))*r.x+r.y;vec2 AB=vec2(-1.04,1.04)*a004+r.zw;return specularColor*AB.x+AB.y;}float getSpecularMIPLevel(float roughness,int maxMIPLevel){return roughness*float(maxMIPLevel);}vec3 getLightProbeRadiance(vec3 viewDir,vec3 normal,float roughness,int maxMIPLevel,float specularIntensity){\n#ifndef SCENE_USE_SPECULAR_ENV\nreturn vec3(0);\n#else\nvec3 reflectVec=reflect(-viewDir,normal);reflectVec.x=-reflectVec.x;float specularMIPLevel=getSpecularMIPLevel(roughness,maxMIPLevel);\n#ifdef HAS_TEX_LOD\nvec4 envMapColor=textureCubeLodEXT(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#else\nvec4 envMapColor=textureCube(scene_EnvSpecularSampler,reflectVec,specularMIPLevel);\n#endif\n#ifdef SCENE_IS_DECODE_ENV_RGBM\nenvMapColor.rgb=RGBMToLinear(envMapColor,5.0).rgb;\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=linearToGamma(envMapColor);\n#endif\n#else\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nenvMapColor=gammaToLinear(envMapColor);\n#endif\n#endif\nreturn envMapColor.rgb*specularIntensity;\n#endif\n}"; // eslint-disable-line
14283
- var pbr_frag = "#define GLSLIFY 1\nGeometry geometry;Material material;ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));initGeometry(geometry);initMaterial(material,geometry);addTotalDirectRadiance(geometry,material,reflectedLight);\n#ifdef SCENE_USE_SH\nvec3 irradiance=getLightProbeIrradiance(scene_EnvSH,geometry.normal);\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nirradiance=linearToGamma(vec4(irradiance,1.0)).rgb;\n#endif\nirradiance*=scene_EnvMapLight.diffuseIntensity;\n#else\nvec3 irradiance=scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity;irradiance*=PI;\n#endif\nreflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);vec3 radiance=getLightProbeRadiance(geometry.viewDir,geometry.normal,material.roughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);float radianceAttenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatRadiance=getLightProbeRadiance(geometry.viewDir,geometry.clearCoatNormal,material.clearCoatRoughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);reflectedLight.indirectSpecular+=clearCoatRadiance*material.clearCoat*envBRDFApprox(vec3(0.04),material.clearCoatRoughness,geometry.clearCoatDotNV);radianceAttenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nreflectedLight.indirectSpecular+=radianceAttenuation*radiance*envBRDFApprox(material.specularColor,material.roughness,geometry.dotNV);\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nvec2 aoUV=v_uv;\n#ifdef RENDERER_HAS_UV1\nif(material_OcclusionTextureCoord==1.0){aoUV=v_uv1;}\n#endif\nfloat ambientOcclusion=(texture2D(material_OcclusionTexture,aoUV).r-1.0)*material_OcclusionIntensity+1.0;reflectedLight.indirectDiffuse*=ambientOcclusion;\n#ifdef SCENE_USE_SPECULAR_ENV\nreflectedLight.indirectSpecular*=computeSpecularOcclusion(ambientOcclusion,material.roughness,geometry.dotNV);\n#endif\n#endif\nvec3 emissiveRadiance=material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveColor=gammaToLinear(emissiveColor);\n#endif\nemissiveRadiance*=emissiveColor.rgb;\n#endif\nvec3 totalRadiance=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+reflectedLight.directSpecular+reflectedLight.indirectSpecular+emissiveRadiance;vec4 targetColor=vec4(totalRadiance,material.opacity);gl_FragColor=targetColor;"; // eslint-disable-line
14389
+ var pbr_frag = "#define GLSLIFY 1\nGeometry geometry;Material material;ReflectedLight reflectedLight=ReflectedLight(vec3(0.0),vec3(0.0),vec3(0.0),vec3(0.0));initGeometry(geometry,gl_FrontFacing);initMaterial(material,geometry);addTotalDirectRadiance(geometry,material,reflectedLight);\n#ifdef SCENE_USE_SH\nvec3 irradiance=getLightProbeIrradiance(scene_EnvSH,geometry.normal);\n#ifdef ENGINE_IS_COLORSPACE_GAMMA\nirradiance=linearToGamma(vec4(irradiance,1.0)).rgb;\n#endif\nirradiance*=scene_EnvMapLight.diffuseIntensity;\n#else\nvec3 irradiance=scene_EnvMapLight.diffuse*scene_EnvMapLight.diffuseIntensity;irradiance*=PI;\n#endif\nreflectedLight.indirectDiffuse+=irradiance*BRDF_Diffuse_Lambert(material.diffuseColor);vec3 radiance=getLightProbeRadiance(geometry.viewDir,geometry.normal,material.roughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);float radianceAttenuation=1.0;\n#ifdef MATERIAL_ENABLE_CLEAR_COAT\nvec3 clearCoatRadiance=getLightProbeRadiance(geometry.viewDir,geometry.clearCoatNormal,material.clearCoatRoughness,int(scene_EnvMapLight.mipMapLevel),scene_EnvMapLight.specularIntensity);reflectedLight.indirectSpecular+=clearCoatRadiance*material.clearCoat*envBRDFApprox(vec3(0.04),material.clearCoatRoughness,geometry.clearCoatDotNV);radianceAttenuation-=material.clearCoat*F_Schlick(geometry.clearCoatDotNV);\n#endif\nreflectedLight.indirectSpecular+=radianceAttenuation*radiance*envBRDFApprox(material.specularColor,material.roughness,geometry.dotNV);\n#ifdef MATERIAL_HAS_OCCLUSION_TEXTURE\nvec2 aoUV=v_uv;\n#ifdef RENDERER_HAS_UV1\nif(material_OcclusionTextureCoord==1.0){aoUV=v_uv1;}\n#endif\nfloat ambientOcclusion=(texture2D(material_OcclusionTexture,aoUV).r-1.0)*material_OcclusionIntensity+1.0;reflectedLight.indirectDiffuse*=ambientOcclusion;\n#ifdef SCENE_USE_SPECULAR_ENV\nreflectedLight.indirectSpecular*=computeSpecularOcclusion(ambientOcclusion,material.roughness,geometry.dotNV);\n#endif\n#endif\nvec3 emissiveRadiance=material_EmissiveColor;\n#ifdef MATERIAL_HAS_EMISSIVETEXTURE\nvec4 emissiveColor=texture2D(material_EmissiveTexture,v_uv);\n#ifndef ENGINE_IS_COLORSPACE_GAMMA\nemissiveColor=gammaToLinear(emissiveColor);\n#endif\nemissiveRadiance*=emissiveColor.rgb;\n#endif\nvec3 totalRadiance=reflectedLight.directDiffuse+reflectedLight.indirectDiffuse+reflectedLight.directSpecular+reflectedLight.indirectSpecular+emissiveRadiance;vec4 targetColor=vec4(totalRadiance,material.opacity);gl_FragColor=targetColor;"; // eslint-disable-line
14284
14390
  var PBRShaderLib = {
14285
14391
  pbr_frag_define: pbr_frag_define,
14286
14392
  pbr_helper: pbr_helper,
@@ -14301,7 +14407,7 @@
14301
14407
  ShadowVertexDeclaration: ShadowVertexDeclaration,
14302
14408
  ShadowVertex: ShadowVertex
14303
14409
  };
14304
- var normal_get = "#define GLSLIFY 1\nvec3 getNormal(){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(gl_FrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(gl_FrontFacing)*2.0-1.0;return normal;}mat3 getTBN(){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal();vec3 position=v_pos;vec2 uv=gl_FrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;float invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));mat3 tbn=mat3(tangent*invmax,binormal*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
14410
+ var normal_get = "#define GLSLIFY 1\nvec3 getNormal(bool isFrontFacing){\n#ifdef RENDERER_HAS_NORMAL\nvec3 normal=normalize(v_normal);\n#elif defined(HAS_DERIVATIVES)\nvec3 pos_dx=dFdx(v_pos);vec3 pos_dy=dFdy(v_pos);vec3 normal=normalize(cross(pos_dx,pos_dy));\n#else\nvec3 normal=vec3(0,0,1);\n#endif\nnormal*=float(isFrontFacing)*2.0-1.0;return normal;}vec3 getNormalByNormalTexture(mat3 tbn,sampler2D normalTexture,float normalIntensity,vec2 uv,bool isFrontFacing){vec3 normal=texture2D(normalTexture,uv).rgb;normal=normalize(tbn*((2.0*normal-1.0)*vec3(normalIntensity,normalIntensity,1.0)));normal*=float(isFrontFacing)*2.0-1.0;return normal;}mat3 getTBN(bool isFrontFacing){\n#if defined(RENDERER_HAS_NORMAL) && defined(RENDERER_HAS_TANGENT) && ( defined(MATERIAL_HAS_NORMALTEXTURE) || defined(MATERIAL_HAS_CLEAR_COAT_NORMAL_TEXTURE) )\nmat3 tbn=v_TBN;\n#else\nvec3 normal=getNormal(isFrontFacing);vec3 position=v_pos;vec2 uv=isFrontFacing? v_uv:-v_uv;\n#ifdef HAS_DERIVATIVES\nvec3 dp1=dFdx(position);vec3 dp2=dFdy(position);vec2 duv1=dFdx(uv);vec2 duv2=dFdy(uv);vec3 dp2perp=cross(dp2,normal);vec3 dp1perp=cross(normal,dp1);vec3 tangent=dp2perp*duv1.x+dp1perp*duv2.x;vec3 binormal=dp2perp*duv1.y+dp1perp*duv2.y;float invmax=inversesqrt(max(dot(tangent,tangent),dot(binormal,binormal)));mat3 tbn=mat3(tangent*invmax,binormal*invmax,normal);\n#else\nmat3 tbn=mat3(vec3(0.0),vec3(0.0),normal);\n#endif\n#endif\nreturn tbn;}"; // eslint-disable-line
14305
14411
  var ShaderLib = _extends$2({
14306
14412
  common: common,
14307
14413
  common_vert: common_vert,
@@ -15285,6 +15391,9 @@
15285
15391
  this.shaderPass = shaderPass;
15286
15392
  this.renderState = renderState;
15287
15393
  };
15394
+ _proto.dispose = function dispose() {
15395
+ this.data = this.shaderPass = this.renderState = null;
15396
+ };
15288
15397
  return RenderElement;
15289
15398
  }();
15290
15399
  /**
@@ -15301,7 +15410,6 @@
15301
15410
  var Renderer1 = function Renderer1(entity) {
15302
15411
  var _this;
15303
15412
  _this = Component.call(this, entity) || this;
15304
- /** ShaderData related to renderer. */ _this.shaderData = new ShaderData(ShaderDataGroup.Renderer);
15305
15413
  /** @internal */ _this._onUpdateIndex = -1;
15306
15414
  /** @internal */ _this._rendererIndex = -1;
15307
15415
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
@@ -15309,6 +15417,7 @@
15309
15417
  _this._overrideUpdate = false;
15310
15418
  _this._materials = [];
15311
15419
  _this._dirtyUpdateFlag = 0;
15420
+ _this._shaderData = new ShaderData(ShaderDataGroup.Renderer);
15312
15421
  _this._mvMatrix = new Matrix();
15313
15422
  _this._mvpMatrix = new Matrix();
15314
15423
  _this._mvInvMatrix = new Matrix();
@@ -15438,6 +15547,14 @@
15438
15547
  };
15439
15548
  /**
15440
15549
  * @internal
15550
+ */ _proto._cloneTo = function _cloneTo(target) {
15551
+ var materials = this._materials;
15552
+ for(var i = 0, n = materials.length; i < n; i++){
15553
+ target._setMaterial(i, materials[i]);
15554
+ }
15555
+ };
15556
+ /**
15557
+ * @internal
15441
15558
  */ _proto._onDestroy = function _onDestroy() {
15442
15559
  Component.prototype._onDestroy.call(this);
15443
15560
  this.entity.transform._updateFlagManager.removeListener(this._onTransformChanged);
@@ -15447,15 +15564,30 @@
15447
15564
  var _materials_i;
15448
15565
  (_materials_i = materials[i]) == null ? void 0 : _materials_i._addReferCount(-1);
15449
15566
  }
15567
+ this._entity = null;
15568
+ this._globalShaderMacro = null;
15569
+ this._bounds = null;
15570
+ this._materials = null;
15571
+ this._shaderData = null;
15572
+ this._mvMatrix = null;
15573
+ this._mvpMatrix = null;
15574
+ this._mvInvMatrix = null;
15575
+ this._normalMatrix = null;
15576
+ this._materialsInstanced = null;
15577
+ this._rendererLayer = null;
15450
15578
  };
15451
- _proto._updateShaderData = function _updateShaderData(context) {
15579
+ /**
15580
+ * @internal
15581
+ */ _proto._updateShaderData = function _updateShaderData(context) {
15452
15582
  var entity = this.entity;
15453
15583
  var worldMatrix = entity.transform.worldMatrix;
15454
15584
  this._updateTransformShaderData(context, worldMatrix);
15455
15585
  var layer = entity.layer;
15456
15586
  this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
15457
15587
  };
15458
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
15588
+ /**
15589
+ * @internal
15590
+ */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
15459
15591
  var shaderData = this.shaderData;
15460
15592
  var virtualCamera = context.virtualCamera;
15461
15593
  var mvMatrix = this._mvMatrix;
@@ -15474,14 +15606,22 @@
15474
15606
  shaderData.setMatrix(exports.Renderer._mvInvMatrixProperty, mvInvMatrix);
15475
15607
  shaderData.setMatrix(exports.Renderer._normalMatrixProperty, normalMatrix);
15476
15608
  };
15477
- _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
15609
+ /**
15610
+ * @internal
15611
+ */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
15478
15612
  this.entity.transform._updateFlagManager.addListener(this._onTransformChanged);
15479
15613
  };
15480
- _proto._updateBounds = function _updateBounds(worldBounds) {};
15481
- _proto._render = function _render(context) {
15614
+ /**
15615
+ * @internal
15616
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {};
15617
+ /**
15618
+ * @internal
15619
+ */ _proto._render = function _render(context) {
15482
15620
  throw "not implement";
15483
15621
  };
15484
- _proto._createInstanceMaterial = function _createInstanceMaterial(material, index) {
15622
+ /**
15623
+ * @internal
15624
+ */ _proto._createInstanceMaterial = function _createInstanceMaterial(material, index) {
15485
15625
  var insMaterial = material.clone();
15486
15626
  insMaterial.name = insMaterial.name + "(Instance)";
15487
15627
  material._addReferCount(-1);
@@ -15504,10 +15644,20 @@
15504
15644
  materials[index] = material;
15505
15645
  }
15506
15646
  };
15507
- _proto._onTransformChanged = function _onTransformChanged(type) {
15647
+ /**
15648
+ * @internal
15649
+ */ _proto._onTransformChanged = function _onTransformChanged(type) {
15508
15650
  this._dirtyUpdateFlag |= 0x1;
15509
15651
  };
15510
15652
  _create_class$3(Renderer1, [
15653
+ {
15654
+ key: "shaderData",
15655
+ get: /**
15656
+ * ShaderData related to renderer.
15657
+ */ function get() {
15658
+ return this._shaderData;
15659
+ }
15660
+ },
15511
15661
  {
15512
15662
  key: "isCulled",
15513
15663
  get: /**
@@ -15592,9 +15742,6 @@
15592
15742
  }(), function() {
15593
15743
  _Renderer._rendererLayerProperty = ShaderProperty.getByName("renderer_Layer");
15594
15744
  }(), _Renderer);
15595
- __decorate$1([
15596
- deepClone
15597
- ], exports.Renderer.prototype, "shaderData", void 0);
15598
15745
  __decorate$1([
15599
15746
  ignoreClone
15600
15747
  ], exports.Renderer.prototype, "_distanceForSort", void 0);
@@ -15617,11 +15764,14 @@
15617
15764
  ignoreClone
15618
15765
  ], exports.Renderer.prototype, "_overrideUpdate", void 0);
15619
15766
  __decorate$1([
15620
- shallowClone
15767
+ ignoreClone
15621
15768
  ], exports.Renderer.prototype, "_materials", void 0);
15622
15769
  __decorate$1([
15623
15770
  ignoreClone
15624
15771
  ], exports.Renderer.prototype, "_dirtyUpdateFlag", void 0);
15772
+ __decorate$1([
15773
+ deepClone
15774
+ ], exports.Renderer.prototype, "_shaderData", void 0);
15625
15775
  __decorate$1([
15626
15776
  ignoreClone
15627
15777
  ], exports.Renderer.prototype, "_mvMatrix", void 0);
@@ -15804,8 +15954,10 @@
15804
15954
  _this = Renderer.call(this, entity) || this;
15805
15955
  /** The mask layers the sprite mask influence to. */ _this.influenceLayers = exports.SpriteMaskLayer.Everything;
15806
15956
  _this._sprite = null;
15807
- _this._width = undefined;
15808
- _this._height = undefined;
15957
+ _this._automaticWidth = 0;
15958
+ _this._automaticHeight = 0;
15959
+ _this._customWidth = undefined;
15960
+ _this._customHeight = undefined;
15809
15961
  _this._flipX = false;
15810
15962
  _this._flipY = false;
15811
15963
  _this._alphaCutoff = 0.5;
@@ -15820,30 +15972,33 @@
15820
15972
  /**
15821
15973
  * @internal
15822
15974
  */ _proto._cloneTo = function _cloneTo(target) {
15975
+ Renderer.prototype._cloneTo.call(this, target);
15823
15976
  target.sprite = this._sprite;
15824
15977
  };
15825
- _proto._updateBounds = function _updateBounds(worldBounds) {
15826
- var _this_sprite;
15827
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
15978
+ /**
15979
+ * @internal
15980
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
15981
+ if (this.sprite) {
15982
+ SimpleSpriteAssembler.updatePositions(this);
15983
+ } else {
15828
15984
  worldBounds.min.set(0, 0, 0);
15829
15985
  worldBounds.max.set(0, 0, 0);
15830
- } else {
15831
- SimpleSpriteAssembler.updatePositions(this);
15832
15986
  }
15833
15987
  };
15834
15988
  /**
15989
+ * @internal
15835
15990
  * @inheritdoc
15836
15991
  */ _proto._render = function _render(context) {
15837
15992
  var _this_sprite;
15838
15993
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
15839
15994
  return;
15840
15995
  }
15841
- // Update position.
15996
+ // Update position
15842
15997
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
15843
15998
  SimpleSpriteAssembler.updatePositions(this);
15844
15999
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
15845
16000
  }
15846
- // Update uv.
16001
+ // Update uv
15847
16002
  if (this._dirtyUpdateFlag & 0x2) {
15848
16003
  SimpleSpriteAssembler.updateUVs(this);
15849
16004
  this._dirtyUpdateFlag &= ~0x2;
@@ -15857,19 +16012,40 @@
15857
16012
  this._maskElement = renderElement;
15858
16013
  };
15859
16014
  /**
16015
+ * @internal
15860
16016
  * @inheritdoc
15861
16017
  */ _proto._onDestroy = function _onDestroy() {
15862
- var _this__sprite;
15863
16018
  Renderer.prototype._onDestroy.call(this);
15864
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
16019
+ var sprite = this._sprite;
16020
+ if (sprite) {
16021
+ sprite._addReferCount(-1);
16022
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
16023
+ }
16024
+ this._entity = null;
15865
16025
  this._sprite = null;
15866
16026
  this._verticesData = null;
15867
16027
  };
16028
+ _proto._calDefaultSize = function _calDefaultSize() {
16029
+ var sprite = this._sprite;
16030
+ if (sprite) {
16031
+ this._automaticWidth = sprite.width;
16032
+ this._automaticHeight = sprite.height;
16033
+ } else {
16034
+ this._automaticWidth = this._automaticHeight = 0;
16035
+ }
16036
+ this._dirtyUpdateFlag &= ~0x4;
16037
+ };
15868
16038
  _proto._onSpriteChange = function _onSpriteChange(type) {
15869
16039
  switch(type){
15870
16040
  case SpriteModifyFlags.texture:
15871
16041
  this.shaderData.setTexture(SpriteMask._textureProperty, this.sprite.texture);
15872
16042
  break;
16043
+ case SpriteModifyFlags.size:
16044
+ this._dirtyUpdateFlag |= 0x4;
16045
+ if (this._customWidth === undefined || this._customHeight === undefined) {
16046
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16047
+ }
16048
+ break;
15873
16049
  case SpriteModifyFlags.region:
15874
16050
  case SpriteModifyFlags.atlasRegionOffset:
15875
16051
  this._dirtyUpdateFlag |= 0x3;
@@ -15877,22 +16053,31 @@
15877
16053
  case SpriteModifyFlags.atlasRegion:
15878
16054
  this._dirtyUpdateFlag |= 0x2;
15879
16055
  break;
16056
+ case SpriteModifyFlags.pivot:
16057
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
16058
+ break;
15880
16059
  }
15881
16060
  };
15882
16061
  _create_class$3(SpriteMask, [
15883
16062
  {
15884
16063
  key: "width",
15885
16064
  get: /**
15886
- * Render width.
16065
+ * Render width (in world coordinates).
16066
+ *
16067
+ * @remarks
16068
+ * If width is set, return the set value,
16069
+ * otherwise return `SpriteMask.sprite.width`.
15887
16070
  */ function get() {
15888
- if (this._width === undefined && this._sprite) {
15889
- this.width = this._sprite.width;
16071
+ if (this._customWidth !== undefined) {
16072
+ return this._customWidth;
16073
+ } else {
16074
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
16075
+ return this._automaticWidth;
15890
16076
  }
15891
- return this._width;
15892
16077
  },
15893
16078
  set: function set(value) {
15894
- if (this._width !== value) {
15895
- this._width = value;
16079
+ if (this._customWidth !== value) {
16080
+ this._customWidth = value;
15896
16081
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
15897
16082
  }
15898
16083
  }
@@ -15900,16 +16085,22 @@
15900
16085
  {
15901
16086
  key: "height",
15902
16087
  get: /**
15903
- * Render height.
16088
+ * Render height (in world coordinates).
16089
+ *
16090
+ * @remarks
16091
+ * If height is set, return the set value,
16092
+ * otherwise return `SpriteMask.sprite.height`.
15904
16093
  */ function get() {
15905
- if (this._height === undefined && this._sprite) {
15906
- this.height = this._sprite.height;
16094
+ if (this._customHeight !== undefined) {
16095
+ return this._customHeight;
16096
+ } else {
16097
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
16098
+ return this._automaticHeight;
15907
16099
  }
15908
- return this._height;
15909
16100
  },
15910
16101
  set: function set(value) {
15911
- if (this._height !== value) {
15912
- this._height = value;
16102
+ if (this._customHeight !== value) {
16103
+ this._customHeight = value;
15913
16104
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
15914
16105
  }
15915
16106
  }
@@ -15952,10 +16143,14 @@
15952
16143
  set: function set(value) {
15953
16144
  var lastSprite = this._sprite;
15954
16145
  if (lastSprite !== value) {
15955
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
16146
+ if (lastSprite) {
16147
+ lastSprite._addReferCount(-1);
16148
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
16149
+ }
16150
+ this._dirtyUpdateFlag |= 0x7;
15956
16151
  if (value) {
16152
+ value._addReferCount(1);
15957
16153
  value._updateFlagManager.addListener(this._onSpriteChange);
15958
- this._dirtyUpdateFlag |= 0x3;
15959
16154
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
15960
16155
  } else {
15961
16156
  this.shaderData.setTexture(SpriteMask._textureProperty, null);
@@ -15995,10 +16190,16 @@
15995
16190
  ], SpriteMask.prototype, "_sprite", void 0);
15996
16191
  __decorate$1([
15997
16192
  ignoreClone
15998
- ], SpriteMask.prototype, "_width", void 0);
16193
+ ], SpriteMask.prototype, "_automaticWidth", void 0);
15999
16194
  __decorate$1([
16000
16195
  ignoreClone
16001
- ], SpriteMask.prototype, "_height", void 0);
16196
+ ], SpriteMask.prototype, "_automaticHeight", void 0);
16197
+ __decorate$1([
16198
+ assignmentClone
16199
+ ], SpriteMask.prototype, "_customWidth", void 0);
16200
+ __decorate$1([
16201
+ assignmentClone
16202
+ ], SpriteMask.prototype, "_customHeight", void 0);
16002
16203
  __decorate$1([
16003
16204
  assignmentClone
16004
16205
  ], SpriteMask.prototype, "_flipX", void 0);
@@ -16016,7 +16217,9 @@
16016
16217
  */ SpriteMaskUpdateFlags;
16017
16218
  (function(SpriteMaskUpdateFlags) {
16018
16219
  SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
16019
- SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x3] = "All";
16220
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
16221
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
16222
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x7] = "All";
16020
16223
  })(SpriteMaskUpdateFlags || (SpriteMaskUpdateFlags = {}));
16021
16224
  /**
16022
16225
  * Vertex element format.
@@ -16274,7 +16477,9 @@
16274
16477
  var platformBuffer = this._engine._hardwareRenderer.createPlatformBuffer(this._type, this._byteLength, this._bufferUsage);
16275
16478
  this._platformBuffer = platformBuffer;
16276
16479
  };
16277
- _proto._onDestroy = function _onDestroy() {
16480
+ /**
16481
+ * @internal
16482
+ */ _proto._onDestroy = function _onDestroy() {
16278
16483
  GraphicsResource.prototype._onDestroy.call(this);
16279
16484
  this._platformBuffer.destroy();
16280
16485
  };
@@ -16360,14 +16565,19 @@
16360
16565
  }();
16361
16566
  /**
16362
16567
  * Sub-mesh, mainly contains drawing information.
16363
- */ var SubMesh = function SubMesh(start, count, topology) {
16364
- if (start === void 0) start = 0;
16365
- if (count === void 0) count = 0;
16366
- if (topology === void 0) topology = exports.MeshTopology.Triangles;
16367
- this.start = start;
16368
- this.count = count;
16369
- this.topology = topology;
16370
- };
16568
+ */ var SubMesh = /*#__PURE__*/ function() {
16569
+ var SubMesh = function SubMesh(start, count, topology) {
16570
+ if (start === void 0) start = 0;
16571
+ if (count === void 0) count = 0;
16572
+ if (topology === void 0) topology = exports.MeshTopology.Triangles;
16573
+ this.start = start;
16574
+ this.count = count;
16575
+ this.topology = topology;
16576
+ };
16577
+ var _proto = SubMesh.prototype;
16578
+ _proto.dispose = function dispose() {};
16579
+ return SubMesh;
16580
+ }();
16371
16581
  /**
16372
16582
  * Mesh.
16373
16583
  */ var Mesh = /*#__PURE__*/ function(GraphicsResource) {
@@ -16448,10 +16658,11 @@
16448
16658
  /**
16449
16659
  * @internal
16450
16660
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
16451
- if (this._getReferCount() > 0) {
16452
- var lastBinding = this._vertexBufferBindings[index];
16453
- lastBinding && lastBinding._buffer._addReferCount(-1);
16454
- binding._buffer._addReferCount(1);
16661
+ var referCount = this._getReferCount();
16662
+ if (referCount > 0) {
16663
+ var _this__vertexBufferBindings_index;
16664
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addReferCount(-referCount);
16665
+ binding == null ? void 0 : binding._buffer._addReferCount(referCount);
16455
16666
  }
16456
16667
  this._vertexBufferBindings[index] = binding;
16457
16668
  this._bufferStructChanged = true;
@@ -16463,11 +16674,13 @@
16463
16674
  this._bufferStructChanged = false;
16464
16675
  };
16465
16676
  _proto._addReferCount = function _addReferCount(value) {
16677
+ var _this__indexBufferBinding;
16466
16678
  GraphicsResource.prototype._addReferCount.call(this, value);
16467
16679
  var vertexBufferBindings = this._vertexBufferBindings;
16468
16680
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
16469
16681
  vertexBufferBindings[i]._buffer._addReferCount(value);
16470
16682
  }
16683
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addReferCount(value);
16471
16684
  };
16472
16685
  _proto._rebuild = function _rebuild() {
16473
16686
  this._engine._hardwareRenderer.createPlatformPrimitive(this);
@@ -16482,14 +16695,23 @@
16482
16695
  this._vertexElementMap = null;
16483
16696
  this._platformPrimitive.destroy();
16484
16697
  };
16485
- _proto._setVertexElements = function _setVertexElements(elements) {
16698
+ /**
16699
+ * @internal
16700
+ */ _proto._setVertexElements = function _setVertexElements(elements) {
16486
16701
  this._clearVertexElements();
16487
16702
  for(var i = 0, n = elements.length; i < n; i++){
16488
16703
  this._addVertexElement(elements[i]);
16489
16704
  }
16490
16705
  };
16491
- _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
16706
+ /**
16707
+ * @internal
16708
+ */ _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
16492
16709
  var lastBinding = this._indexBufferBinding;
16710
+ var referCount = this._getReferCount();
16711
+ if (referCount > 0) {
16712
+ lastBinding == null ? void 0 : lastBinding.buffer._addReferCount(-referCount);
16713
+ binding == null ? void 0 : binding.buffer._addReferCount(referCount);
16714
+ }
16493
16715
  if (binding) {
16494
16716
  this._indexBufferBinding = binding;
16495
16717
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -16803,6 +17025,7 @@
16803
17025
  var subDataDirtyFlags = this._subDataDirtyFlags;
16804
17026
  var blendShapeFloatStride = this._vertexElementCount * 3;
16805
17027
  var blendShapeByteStride = blendShapeFloatStride * 4;
17028
+ var bufferOffset = this._bufferBindingOffset;
16806
17029
  // @todo: should fix bug when dataChangedFlag is true
16807
17030
  for(var i = 0, n = blendShapes.length; i < n; i++){
16808
17031
  var dataChangedFlag = subDataDirtyFlags[i];
@@ -16820,7 +17043,7 @@
16820
17043
  var offset = indexInBuffer * blendShapeFloatStride;
16821
17044
  var storeInfo = storeInfos[i];
16822
17045
  storeInfo || (storeInfos[i] = storeInfo = new Vector2());
16823
- storeInfo.set(bufferIndex + 1, indexInBuffer * blendShapeByteStride); // BlendShape buffer is start from 1
17046
+ storeInfo.set(bufferOffset + bufferIndex, indexInBuffer * blendShapeByteStride); // BufferOffset is mesh vertexBuffer offset
16824
17047
  var deltaPositions = endFrame.deltaPositions;
16825
17048
  for(var j = 0; j < vertexCount; j++){
16826
17049
  var start = offset + bufferFloatStride * j;
@@ -17622,7 +17845,9 @@
17622
17845
  }
17623
17846
  this.setTangents(tangents);
17624
17847
  };
17625
- _proto._onDestroy = function _onDestroy() {
17848
+ /**
17849
+ * @internal
17850
+ */ _proto._onDestroy = function _onDestroy() {
17626
17851
  Mesh.prototype._onDestroy.call(this);
17627
17852
  this._readable && this._releaseCache();
17628
17853
  };
@@ -18090,25 +18315,32 @@
18090
18315
  var MeshRenderer = function MeshRenderer(entity) {
18091
18316
  var _this;
18092
18317
  _this = Renderer.call(this, entity) || this;
18318
+ _this._enableVertexColor = false;
18093
18319
  _this._onMeshChanged = _this._onMeshChanged.bind(_assert_this_initialized(_this));
18094
18320
  return _this;
18095
18321
  };
18096
18322
  _inherits$2(MeshRenderer, Renderer);
18097
18323
  var _proto = MeshRenderer.prototype;
18098
- _proto._onDestroy = function _onDestroy() {
18324
+ /**
18325
+ * @internal
18326
+ */ _proto._onDestroy = function _onDestroy() {
18099
18327
  Renderer.prototype._onDestroy.call(this);
18100
18328
  var mesh = this._mesh;
18101
- if (mesh && !mesh.destroyed) {
18102
- mesh._addReferCount(-1);
18329
+ if (mesh) {
18330
+ mesh.destroyed || mesh._addReferCount(-1);
18331
+ mesh._updateFlagManager.removeListener(this._onMeshChanged);
18103
18332
  this._mesh = null;
18104
18333
  }
18105
18334
  };
18106
18335
  /**
18107
18336
  * @internal
18108
18337
  */ _proto._cloneTo = function _cloneTo(target) {
18338
+ Renderer.prototype._cloneTo.call(this, target);
18109
18339
  target.mesh = this._mesh;
18110
18340
  };
18111
- _proto._updateBounds = function _updateBounds(worldBounds) {
18341
+ /**
18342
+ * @internal
18343
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
18112
18344
  var mesh = this._mesh;
18113
18345
  if (mesh) {
18114
18346
  var localBounds = mesh.bounds;
@@ -18119,7 +18351,9 @@
18119
18351
  worldBounds.max.set(0, 0, 0);
18120
18352
  }
18121
18353
  };
18122
- _proto._render = function _render(context) {
18354
+ /**
18355
+ * @internal
18356
+ */ _proto._render = function _render(context) {
18123
18357
  var mesh = this._mesh;
18124
18358
  if (mesh) {
18125
18359
  if (this._dirtyUpdateFlag & 0x2) {
@@ -18129,7 +18363,7 @@
18129
18363
  shaderData.disableMacro(MeshRenderer._uv1Macro);
18130
18364
  shaderData.disableMacro(MeshRenderer._normalMacro);
18131
18365
  shaderData.disableMacro(MeshRenderer._tangentMacro);
18132
- shaderData.disableMacro(MeshRenderer._vertexColorMacro);
18366
+ shaderData.disableMacro(MeshRenderer._enableVertexColorMacro);
18133
18367
  for(var i = 0, n = vertexElements.length; i < n; i++){
18134
18368
  switch(vertexElements[i].semantic){
18135
18369
  case "TEXCOORD_0":
@@ -18145,7 +18379,7 @@
18145
18379
  shaderData.enableMacro(MeshRenderer._tangentMacro);
18146
18380
  break;
18147
18381
  case "COLOR_0":
18148
- shaderData.enableMacro(MeshRenderer._vertexColorMacro);
18382
+ this._enableVertexColor && shaderData.enableMacro(MeshRenderer._enableVertexColorMacro);
18149
18383
  break;
18150
18384
  }
18151
18385
  }
@@ -18196,6 +18430,20 @@
18196
18430
  this._setMesh(value);
18197
18431
  }
18198
18432
  }
18433
+ },
18434
+ {
18435
+ key: "enableVertexColor",
18436
+ get: /**
18437
+ * Whether enable vertex color.
18438
+ */ function get() {
18439
+ return this._enableVertexColor;
18440
+ },
18441
+ set: function set(value) {
18442
+ if (value !== this._enableVertexColor) {
18443
+ this._dirtyUpdateFlag |= 0x2;
18444
+ this._enableVertexColor = value;
18445
+ }
18446
+ }
18199
18447
  }
18200
18448
  ]);
18201
18449
  return MeshRenderer;
@@ -18213,7 +18461,7 @@
18213
18461
  MeshRenderer._tangentMacro = ShaderMacro.getByName("RENDERER_HAS_TANGENT");
18214
18462
  })();
18215
18463
  (function() {
18216
- MeshRenderer._vertexColorMacro = ShaderMacro.getByName("RENDERER_HAS_VERTEXCOLOR");
18464
+ MeshRenderer._enableVertexColorMacro = ShaderMacro.getByName("RENDERER_ENABLE_VERTEXCOLOR");
18217
18465
  })();
18218
18466
  __decorate$1([
18219
18467
  ignoreClone
@@ -18243,7 +18491,7 @@
18243
18491
  // Limit size to 256 to avoid some problem:
18244
18492
  // 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!
18245
18493
  // 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.
18246
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, 256);
18494
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
18247
18495
  _this._maxVertexUniformVectors = maxVertexUniformVectors;
18248
18496
  _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
18249
18497
  var localBounds = _this._localBounds;
@@ -18279,7 +18527,9 @@
18279
18527
  }
18280
18528
  }
18281
18529
  };
18282
- _proto._updateShaderData = function _updateShaderData(context) {
18530
+ /**
18531
+ * @internal
18532
+ */ _proto._updateShaderData = function _updateShaderData(context) {
18283
18533
  var entity = this.entity;
18284
18534
  var worldMatrix = this._rootBone ? this._rootBone.transform.worldMatrix : entity.transform.worldMatrix;
18285
18535
  this._updateTransformShaderData(context, worldMatrix);
@@ -18305,6 +18555,7 @@
18305
18555
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
18306
18556
  this._jointTexture = new Texture2D(engine, 4, jointCount, exports.TextureFormat.R32G32B32A32, false);
18307
18557
  this._jointTexture.filterMode = exports.TextureFilterMode.Point;
18558
+ this._jointTexture.isGCIgnored = true;
18308
18559
  }
18309
18560
  shaderData.disableMacro("RENDERER_JOINTS_NUM");
18310
18561
  shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
@@ -18330,14 +18581,37 @@
18330
18581
  };
18331
18582
  /**
18332
18583
  * @internal
18584
+ */ _proto._onDestroy = function _onDestroy() {
18585
+ var _this__rootBone, _this__jointTexture;
18586
+ MeshRenderer.prototype._onDestroy.call(this);
18587
+ (_this__rootBone = this._rootBone) == null ? void 0 : _this__rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
18588
+ this._rootBone = null;
18589
+ this._jointDataCreateCache = null;
18590
+ this._skin = null;
18591
+ this._blendShapeWeights = null;
18592
+ this._localBounds = null;
18593
+ this._jointMatrices = null;
18594
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
18595
+ this._jointTexture = null;
18596
+ if (this._jointEntities) {
18597
+ this._jointEntities.length = 0;
18598
+ this._jointEntities = null;
18599
+ }
18600
+ };
18601
+ /**
18602
+ * @internal
18333
18603
  */ _proto._cloneTo = function _cloneTo(target) {
18334
18604
  MeshRenderer.prototype._cloneTo.call(this, target);
18335
18605
  this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
18336
18606
  };
18337
- _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
18607
+ /**
18608
+ * @internal
18609
+ */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
18338
18610
  // Cancel register listener to entity transform.
18339
18611
  };
18340
- _proto._updateBounds = function _updateBounds(worldBounds) {
18612
+ /**
18613
+ * @internal
18614
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
18341
18615
  if (this._rootBone) {
18342
18616
  var localBounds = this._localBounds;
18343
18617
  var worldMatrix = this._rootBone.transform.worldMatrix;
@@ -19779,14 +20053,17 @@
19779
20053
  _proto._createMesh = function _createMesh(engine, index) {
19780
20054
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
19781
20055
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
20056
+ mesh.isGCIgnored = true;
19782
20057
  var vertexElements = [];
19783
20058
  var vertexStride = this.createVertexElements(vertexElements);
19784
20059
  // vertices
19785
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
20060
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
20061
+ vertexBuffer.isGCIgnored = true;
19786
20062
  // indices
19787
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 3, exports.BufferUsage.Dynamic);
19788
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
19789
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
20063
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
20064
+ indiceBuffer.isGCIgnored = true;
20065
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
20066
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
19790
20067
  mesh.setVertexElements(vertexElements);
19791
20068
  return mesh;
19792
20069
  };
@@ -20007,6 +20284,9 @@
20007
20284
  this.material = material;
20008
20285
  this.verticesData = verticesData;
20009
20286
  };
20287
+ _proto.dispose = function dispose() {
20288
+ this.component = this.material = this.verticesData = null;
20289
+ };
20010
20290
  return SpriteMaskRenderData;
20011
20291
  }(RenderData);
20012
20292
  var SpriteRenderData = /*#__PURE__*/ function(RenderData) {
@@ -20026,6 +20306,9 @@
20026
20306
  this.texture = texture;
20027
20307
  this.dataIndex = dataIndex;
20028
20308
  };
20309
+ _proto.dispose = function dispose() {
20310
+ this.component = this.material = this.verticesData = this.texture = null;
20311
+ };
20029
20312
  return SpriteRenderData;
20030
20313
  }(RenderData);
20031
20314
  var TextRenderData = /*#__PURE__*/ function(RenderData) {
@@ -20037,6 +20320,11 @@
20037
20320
  return _this;
20038
20321
  };
20039
20322
  _inherits$2(TextRenderData, RenderData);
20323
+ var _proto = TextRenderData.prototype;
20324
+ _proto.dispose = function dispose() {
20325
+ this.component = this.material = null;
20326
+ this.charsData.length = 0;
20327
+ };
20040
20328
  return TextRenderData;
20041
20329
  }(RenderData);
20042
20330
  /**
@@ -20062,6 +20350,12 @@
20062
20350
  var _proto = Sky.prototype;
20063
20351
  /**
20064
20352
  * @internal
20353
+ */ _proto.destroy = function destroy() {
20354
+ this.mesh = null;
20355
+ this.material = null;
20356
+ };
20357
+ /**
20358
+ * @internal
20065
20359
  */ _proto._render = function _render(context) {
20066
20360
  var _this = this, material = _this.material, mesh = _this.mesh;
20067
20361
  if (!material) {
@@ -20102,6 +20396,40 @@
20102
20396
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
20103
20397
  cameraShaderData.setMatrix(RenderContext.vpMatrixProperty, originViewProjMatrix);
20104
20398
  };
20399
+ _create_class$3(Sky, [
20400
+ {
20401
+ key: "material",
20402
+ get: /**
20403
+ * Material of the sky.
20404
+ */ function get() {
20405
+ return this._material;
20406
+ },
20407
+ set: function set(value) {
20408
+ if (this._material !== value) {
20409
+ var _this__material;
20410
+ value == null ? void 0 : value._addReferCount(1);
20411
+ (_this__material = this._material) == null ? void 0 : _this__material._addReferCount(-1);
20412
+ this._material = value;
20413
+ }
20414
+ }
20415
+ },
20416
+ {
20417
+ key: "mesh",
20418
+ get: /**
20419
+ * Mesh of the sky.
20420
+ */ function get() {
20421
+ return this._mesh;
20422
+ },
20423
+ set: function set(value) {
20424
+ if (this._mesh !== value) {
20425
+ var _this__mesh;
20426
+ value == null ? void 0 : value._addReferCount(1);
20427
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addReferCount(-1);
20428
+ this._mesh = value;
20429
+ }
20430
+ }
20431
+ }
20432
+ ]);
20105
20433
  return Sky;
20106
20434
  }();
20107
20435
  (function() {
@@ -20136,9 +20464,19 @@
20136
20464
  var _proto = Background.prototype;
20137
20465
  /**
20138
20466
  * @internal
20467
+ */ _proto.destroy = function destroy() {
20468
+ this._mesh._addReferCount(-1);
20469
+ this._mesh = null;
20470
+ this.texture = null;
20471
+ this.solidColor = null;
20472
+ this.sky.destroy();
20473
+ };
20474
+ /**
20475
+ * @internal
20139
20476
  * Standalone for CanvasRenderer plugin.
20140
20477
  */ _proto._initMesh = function _initMesh(engine) {
20141
20478
  this._mesh = this._createPlane(engine);
20479
+ this._mesh._addReferCount(1);
20142
20480
  };
20143
20481
  /**
20144
20482
  * @internal
@@ -20210,6 +20548,9 @@
20210
20548
  },
20211
20549
  set: function set(value) {
20212
20550
  if (this._texture !== value) {
20551
+ var _this__texture;
20552
+ value == null ? void 0 : value._addReferCount(1);
20553
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addReferCount(-1);
20213
20554
  this._texture = value;
20214
20555
  this._engine._backgroundTextureMaterial.shaderData.setTexture("material_BaseTexture", value);
20215
20556
  }
@@ -20509,8 +20850,6 @@
20509
20850
  function Scene(engine, name) {
20510
20851
  var _this;
20511
20852
  _this = EngineObject.call(this, engine) || this;
20512
- /** The background of the scene. */ _this.background = new Background(_this._engine);
20513
- /** Scene-related shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Scene);
20514
20853
  /** If cast shadows. */ _this.castShadows = true;
20515
20854
  /** The resolution of the shadow maps. */ _this.shadowResolution = exports.ShadowResolution.Medium;
20516
20855
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
@@ -20520,6 +20859,8 @@
20520
20859
  /** @internal */ _this._isActiveInEngine = false;
20521
20860
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
20522
20861
  /** @internal */ _this._rootEntities = [];
20862
+ _this._background = new Background(_this._engine);
20863
+ _this._shaderData = new ShaderData(ShaderDataGroup.Scene);
20523
20864
  _this._shadowCascades = exports.ShadowCascadesMode.NoCascades;
20524
20865
  _this._fogMode = exports.FogMode.None;
20525
20866
  _this._fogColor = new Color$1(0.5, 0.5, 0.5, 1.0);
@@ -20683,9 +21024,11 @@
20683
21024
  var sunLightIndex = lightManager._getSunLightIndex();
20684
21025
  if (sunLightIndex !== -1) {
20685
21026
  var sunlight = lightManager._directLights.get(sunLightIndex);
20686
- shaderData.setColor(Scene._sunlightColorProperty, sunlight.color);
21027
+ shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
20687
21028
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
20688
21029
  this._sunLight = sunlight;
21030
+ } else {
21031
+ this._sunLight = null;
20689
21032
  }
20690
21033
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== exports.ShadowType.None) {
20691
21034
  shaderData.enableMacro("SCENE_SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -20714,6 +21057,7 @@
20714
21057
  this._rootEntities[0].destroy();
20715
21058
  }
20716
21059
  this._activeCameras.length = 0;
21060
+ this.background.destroy();
20717
21061
  this.shaderData._addReferCount(-1);
20718
21062
  };
20719
21063
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -20744,6 +21088,22 @@
20744
21088
  this._fogParams.w = density / Math.sqrt(Math.LN2);
20745
21089
  };
20746
21090
  _create_class$3(Scene, [
21091
+ {
21092
+ key: "shaderData",
21093
+ get: /**
21094
+ * Scene-related shader data.
21095
+ */ function get() {
21096
+ return this._shaderData;
21097
+ }
21098
+ },
21099
+ {
21100
+ key: "background",
21101
+ get: /**
21102
+ * The background of the scene.
21103
+ */ function get() {
21104
+ return this._background;
21105
+ }
21106
+ },
20747
21107
  {
20748
21108
  key: "shadowCascades",
20749
21109
  get: /**
@@ -21146,7 +21506,7 @@
21146
21506
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
21147
21507
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
21148
21508
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
21149
- _this._textDefaultFont.isGCIgnored = false;
21509
+ _this._textDefaultFont.isGCIgnored = true;
21150
21510
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
21151
21511
  _this._initMagentaTextures(hardwareRenderer);
21152
21512
  if (!hardwareRenderer.canIUse(exports.GLCapabilityType.depthTexture)) {
@@ -21157,6 +21517,7 @@
21157
21517
  _this._depthTexture2D = depthTexture2D;
21158
21518
  }
21159
21519
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
21520
+ magentaMaterial.isGCIgnored = true;
21160
21521
  magentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
21161
21522
  _this._magentaMaterial = magentaMaterial;
21162
21523
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -21383,7 +21744,9 @@
21383
21744
  this._magentaTexture2DArray = magentaTexture2DArray;
21384
21745
  }
21385
21746
  };
21386
- _proto._initialize = function _initialize(configuration) {
21747
+ /**
21748
+ * @internal
21749
+ */ _proto._initialize = function _initialize(configuration) {
21387
21750
  var _this = this;
21388
21751
  var physics = configuration.physics;
21389
21752
  if (physics) {
@@ -21704,7 +22067,9 @@
21704
22067
  this._entity._removeScript(this);
21705
22068
  this._waitHandlingInValid = false;
21706
22069
  };
21707
- _proto._onDestroy = function _onDestroy() {
22070
+ /**
22071
+ * @internal
22072
+ */ _proto._onDestroy = function _onDestroy() {
21708
22073
  Component.prototype._onDestroy.call(this);
21709
22074
  this._engine._componentsManager.addPendingDestroyScript(this);
21710
22075
  };
@@ -22648,7 +23013,7 @@
22648
23013
  // prepare render target
22649
23014
  var renderTarget = this._getAvailableRenderTarget();
22650
23015
  // @todo: shouldn't set viewport and scissor in activeRenderTarget
22651
- rhi.activeRenderTarget(renderTarget, null, 0);
23016
+ rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
22652
23017
  if (this._supportDepthTexture) {
22653
23018
  rhi.clearRenderTarget(engine, exports.CameraClearFlags.Depth, null);
22654
23019
  } else {
@@ -22770,11 +23135,13 @@
22770
23135
  if (engine._hardwareRenderer._isWebGL2) {
22771
23136
  depthTexture.depthCompareFunction = exports.TextureDepthCompareFunction.Less;
22772
23137
  }
23138
+ renderTarget == null ? void 0 : renderTarget._addReferCount(-1);
22773
23139
  if (this._supportDepthTexture) {
22774
23140
  renderTarget = this._renderTargets = new RenderTarget(engine, width, height, null, depthTexture);
22775
23141
  } else {
22776
23142
  renderTarget = this._renderTargets = new RenderTarget(engine, width, height, depthTexture);
22777
23143
  }
23144
+ renderTarget._addReferCount(1);
22778
23145
  }
22779
23146
  return renderTarget;
22780
23147
  };
@@ -22797,7 +23164,12 @@
22797
23164
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
22798
23165
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
22799
23166
  }
22800
- this._renderTargets = null;
23167
+ var renderTargets = this._renderTargets;
23168
+ if (renderTargets) {
23169
+ renderTargets._addReferCount(-1);
23170
+ renderTargets.destroy();
23171
+ this._renderTargets = null;
23172
+ }
22801
23173
  var viewportOffset = this._viewportOffsets;
22802
23174
  var shadowTileResolution1 = this._shadowTileResolution;
22803
23175
  switch(shadowCascades){
@@ -22853,6 +23225,9 @@
22853
23225
  (function() {
22854
23226
  CascadedShadowCasterPass._cascadesSplitDistance = new Array(CascadedShadowCasterPass._maxCascades + 1);
22855
23227
  })();
23228
+ (function() {
23229
+ CascadedShadowCasterPass._viewport = new Vector4(0, 0, 1, 1);
23230
+ })();
22856
23231
  (function() {
22857
23232
  CascadedShadowCasterPass._clearColor = new Color$1(1, 1, 1, 1);
22858
23233
  })();
@@ -23160,7 +23535,6 @@
23160
23535
  var Camera1 = function Camera1(entity) {
23161
23536
  var _this;
23162
23537
  _this = Component.call(this, entity) || this;
23163
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Camera);
23164
23538
  /** Rendering priority - A Camera with higher priority will be rendered on top of a camera with lower priority. */ _this.priority = 0;
23165
23539
  /** Whether to enable frustum culling, it is enabled by default. */ _this.enableFrustumCulling = true;
23166
23540
  /**
@@ -23176,6 +23550,7 @@
23176
23550
  /** @internal */ _this._virtualCamera = new VirtualCamera();
23177
23551
  /** @internal */ _this._replacementShader = null;
23178
23552
  /** @internal */ _this._replacementSubShaderTag = null;
23553
+ _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
23179
23554
  _this._isProjMatSetting = false;
23180
23555
  _this._nearClipPlane = 0.1;
23181
23556
  _this._farClipPlane = 100;
@@ -23377,6 +23752,7 @@
23377
23752
  this.entity.scene._detachRenderCamera(this);
23378
23753
  };
23379
23754
  /**
23755
+ * @internal
23380
23756
  * @inheritdoc
23381
23757
  */ _proto._onDestroy = function _onDestroy() {
23382
23758
  var _this__renderPipeline;
@@ -23385,6 +23761,20 @@
23385
23761
  this._isInvViewProjDirty.destroy();
23386
23762
  this._isViewMatrixDirty.destroy();
23387
23763
  this.shaderData._addReferCount(-1);
23764
+ this._entity = null;
23765
+ this._globalShaderMacro = null;
23766
+ this._frustum = null;
23767
+ this._renderPipeline = null;
23768
+ this._virtualCamera = null;
23769
+ this._shaderData = null;
23770
+ this._frustumViewChangeFlag = null;
23771
+ this._transform = null;
23772
+ this._isViewMatrixDirty = null;
23773
+ this._isInvViewProjDirty = null;
23774
+ this._viewport = null;
23775
+ this._inverseProjectionMatrix = null;
23776
+ this._lastAspectSize = null;
23777
+ this._invViewProjMat = null;
23388
23778
  };
23389
23779
  _proto._projMatChange = function _projMatChange() {
23390
23780
  this._isFrustumProjectDirty = true;
@@ -23424,6 +23814,14 @@
23424
23814
  return this._inverseProjectionMatrix;
23425
23815
  };
23426
23816
  _create_class$3(Camera1, [
23817
+ {
23818
+ key: "shaderData",
23819
+ get: /**
23820
+ * Shader data.
23821
+ */ function get() {
23822
+ return this._shaderData;
23823
+ }
23824
+ },
23427
23825
  {
23428
23826
  key: "nearClipPlane",
23429
23827
  get: /**
@@ -23582,7 +23980,12 @@
23582
23980
  return this._renderTarget;
23583
23981
  },
23584
23982
  set: function set(value) {
23585
- this._renderTarget = value;
23983
+ if (this._renderTarget !== value) {
23984
+ var _this__renderTarget;
23985
+ value == null ? void 0 : value._addReferCount(1);
23986
+ (_this__renderTarget = this._renderTarget) == null ? void 0 : _this__renderTarget._addReferCount(-1);
23987
+ this._renderTarget = value;
23988
+ }
23586
23989
  }
23587
23990
  }
23588
23991
  ]);
@@ -24561,6 +24964,7 @@
24561
24964
  _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this;
24562
24965
  _this.shaderData.setFloat(PBRMaterial._metallicProp, 1);
24563
24966
  _this.shaderData.setFloat(PBRMaterial._roughnessProp, 1);
24967
+ _this.shaderData.setFloat(PBRMaterial._iorProp, 1.5);
24564
24968
  return _this;
24565
24969
  }
24566
24970
  var _proto = PBRMaterial.prototype;
@@ -24572,10 +24976,23 @@
24572
24976
  return dest;
24573
24977
  };
24574
24978
  _create_class$3(PBRMaterial, [
24979
+ {
24980
+ key: "ior",
24981
+ get: /**
24982
+ * Index Of Refraction.
24983
+ * @defaultValue `1.5`
24984
+ */ function get() {
24985
+ return this.shaderData.getFloat(PBRMaterial._iorProp);
24986
+ },
24987
+ set: function set(v) {
24988
+ this.shaderData.setFloat(PBRMaterial._iorProp, Math.max(v, 0));
24989
+ }
24990
+ },
24575
24991
  {
24576
24992
  key: "metallic",
24577
24993
  get: /**
24578
- * Metallic, default 1.0.
24994
+ * Metallic.
24995
+ * @defaultValue `1.0`
24579
24996
  */ function get() {
24580
24997
  return this.shaderData.getFloat(PBRMaterial._metallicProp);
24581
24998
  },
@@ -24586,7 +25003,8 @@
24586
25003
  {
24587
25004
  key: "roughness",
24588
25005
  get: /**
24589
- * Roughness, default 1.0.
25006
+ * Roughness. default 1.0.
25007
+ * @defaultValue `1.0`
24590
25008
  */ function get() {
24591
25009
  return this.shaderData.getFloat(PBRMaterial._roughnessProp);
24592
25010
  },
@@ -24623,6 +25041,9 @@
24623
25041
  (function() {
24624
25042
  PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
24625
25043
  })();
25044
+ (function() {
25045
+ PBRMaterial._iorProp = Shader.getPropertyByName("material_IOR");
25046
+ })();
24626
25047
  /**
24627
25048
  * PBR (Specular-Glossiness Workflow) Material.
24628
25049
  */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial) {
@@ -24830,9 +25251,18 @@
24830
25251
  * @internal
24831
25252
  */ _proto._addSprite = function _addSprite(sprite) {
24832
25253
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
25254
+ sprite._atlas = this;
25255
+ sprite.isGCIgnored = true;
24833
25256
  };
24834
- _proto._onDestroy = function _onDestroy() {
25257
+ /**
25258
+ * @internal
25259
+ */ _proto._onDestroy = function _onDestroy() {
24835
25260
  ReferResource.prototype._onDestroy.call(this);
25261
+ var _this = this, sprites = _this._sprites;
25262
+ for(var i = 0, n = sprites.length; i < n; i++){
25263
+ sprites[i].destroy();
25264
+ }
25265
+ sprites.length = 0;
24836
25266
  this._sprites = null;
24837
25267
  this._spriteNamesToIndex = null;
24838
25268
  };
@@ -24876,8 +25306,10 @@
24876
25306
  if (name === void 0) name = null;
24877
25307
  var _this;
24878
25308
  _this = ReferResource.call(this, engine) || this;
24879
- _this._width = undefined;
24880
- _this._height = undefined;
25309
+ _this._automaticWidth = 0;
25310
+ _this._automaticHeight = 0;
25311
+ _this._customWidth = undefined;
25312
+ _this._customHeight = undefined;
24881
25313
  _this._positions = [
24882
25314
  new Vector2(),
24883
25315
  new Vector2(),
@@ -24898,7 +25330,7 @@
24898
25330
  _this._region = new Rect(0, 0, 1, 1);
24899
25331
  _this._pivot = new Vector2(0.5, 0.5);
24900
25332
  _this._border = new Vector4(0, 0, 0, 0);
24901
- _this._dirtyUpdateFlag = 0x3;
25333
+ _this._dirtyUpdateFlag = 0x7;
24902
25334
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
24903
25335
  _this._texture = texture;
24904
25336
  region && _this._region.copyFrom(region);
@@ -24937,17 +25369,41 @@
24937
25369
  this._dirtyUpdateFlag & 0x1 && this._updatePositions();
24938
25370
  return this._bounds;
24939
25371
  };
24940
- _proto._onDestroy = function _onDestroy() {
25372
+ /**
25373
+ * @internal
25374
+ */ _proto._addReferCount = function _addReferCount(value) {
25375
+ var _this__atlas;
25376
+ ReferResource.prototype._addReferCount.call(this, value);
25377
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addReferCount(value);
25378
+ };
25379
+ /**
25380
+ * @internal
25381
+ */ _proto._onDestroy = function _onDestroy() {
24941
25382
  ReferResource.prototype._onDestroy.call(this);
25383
+ this._positions.length = 0;
25384
+ this._positions = null;
25385
+ this._uvs.length = 0;
25386
+ this._uvs = null;
25387
+ this._atlasRegion = null;
25388
+ this._atlasRegionOffset = null;
25389
+ this._region = null;
25390
+ this._pivot = null;
25391
+ this._border = null;
25392
+ this._bounds = null;
25393
+ this._atlas = null;
24942
25394
  this._texture = null;
25395
+ this._updateFlagManager = null;
24943
25396
  };
24944
25397
  _proto._calDefaultSize = function _calDefaultSize() {
24945
25398
  if (this._texture) {
24946
25399
  var _this = this, _texture = _this._texture, _atlasRegion = _this._atlasRegion, _atlasRegionOffset = _this._atlasRegionOffset, _region = _this._region;
24947
25400
  var pixelsPerUnitReciprocal = 1.0 / Engine._pixelsPerUnit;
24948
- this._width = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
24949
- this._height = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
25401
+ this._automaticWidth = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
25402
+ this._automaticHeight = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
25403
+ } else {
25404
+ this._automaticWidth = this._automaticHeight = 0;
24950
25405
  }
25406
+ this._dirtyUpdateFlag &= ~0x4;
24951
25407
  };
24952
25408
  _proto._updatePositions = function _updatePositions() {
24953
25409
  var blank = this._atlasRegionOffset;
@@ -25001,11 +25457,16 @@
25001
25457
  };
25002
25458
  _proto._dispatchSpriteChange = function _dispatchSpriteChange(type) {
25003
25459
  switch(type){
25460
+ case SpriteModifyFlags.texture:
25461
+ this._dirtyUpdateFlag |= 0x4;
25462
+ break;
25004
25463
  case SpriteModifyFlags.atlasRegionOffset:
25005
25464
  case SpriteModifyFlags.region:
25006
- this._dirtyUpdateFlag |= 0x3;
25465
+ this._dirtyUpdateFlag |= 0x7;
25007
25466
  break;
25008
25467
  case SpriteModifyFlags.atlasRegion:
25468
+ this._dirtyUpdateFlag |= 0x4 | 0x2;
25469
+ break;
25009
25470
  case SpriteModifyFlags.border:
25010
25471
  this._dirtyUpdateFlag |= 0x2;
25011
25472
  break;
@@ -25024,7 +25485,9 @@
25024
25485
  if (this._texture !== value) {
25025
25486
  this._texture = value;
25026
25487
  this._dispatchSpriteChange(SpriteModifyFlags.texture);
25027
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25488
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25489
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25490
+ }
25028
25491
  }
25029
25492
  }
25030
25493
  },
@@ -25032,13 +25495,21 @@
25032
25495
  key: "width",
25033
25496
  get: /**
25034
25497
  * The width of the sprite (in world coordinates).
25498
+ *
25499
+ * @remarks
25500
+ * If width is set, return the set value,
25501
+ * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
25035
25502
  */ function get() {
25036
- this._width === undefined && this._calDefaultSize();
25037
- return this._width;
25503
+ if (this._customWidth !== undefined) {
25504
+ return this._customWidth;
25505
+ } else {
25506
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
25507
+ return this._automaticWidth;
25508
+ }
25038
25509
  },
25039
25510
  set: function set(value) {
25040
- if (this._width !== value) {
25041
- this._width = value;
25511
+ if (this._customWidth !== value) {
25512
+ this._customWidth = value;
25042
25513
  this._dispatchSpriteChange(SpriteModifyFlags.size);
25043
25514
  }
25044
25515
  }
@@ -25047,13 +25518,21 @@
25047
25518
  key: "height",
25048
25519
  get: /**
25049
25520
  * The height of the sprite (in world coordinates).
25521
+ *
25522
+ * @remarks
25523
+ * If height is set, return the set value,
25524
+ * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
25050
25525
  */ function get() {
25051
- this._height === undefined && this._calDefaultSize();
25052
- return this._height;
25526
+ if (this._customHeight !== undefined) {
25527
+ return this._customHeight;
25528
+ } else {
25529
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
25530
+ return this._automaticHeight;
25531
+ }
25053
25532
  },
25054
25533
  set: function set(value) {
25055
- if (this._height !== value) {
25056
- this._height = value;
25534
+ if (this._customHeight !== value) {
25535
+ this._customHeight = value;
25057
25536
  this._dispatchSpriteChange(SpriteModifyFlags.size);
25058
25537
  }
25059
25538
  }
@@ -25083,7 +25562,9 @@
25083
25562
  var y = MathUtil$1.clamp(value.y, 0, 1);
25084
25563
  this._atlasRegion.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
25085
25564
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegion);
25086
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25565
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25566
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25567
+ }
25087
25568
  }
25088
25569
  },
25089
25570
  {
@@ -25098,7 +25579,9 @@
25098
25579
  var y = MathUtil$1.clamp(value.y, 0, 1);
25099
25580
  this._atlasRegionOffset.set(x, y, MathUtil$1.clamp(value.z, 0, 1 - x), MathUtil$1.clamp(value.w, 0, 1 - y));
25100
25581
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegionOffset);
25101
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25582
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25583
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25584
+ }
25102
25585
  }
25103
25586
  },
25104
25587
  {
@@ -25114,7 +25597,9 @@
25114
25597
  var y = MathUtil$1.clamp(value.y, 0, 1);
25115
25598
  region.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
25116
25599
  this._dispatchSpriteChange(SpriteModifyFlags.region);
25117
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
25600
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25601
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
25602
+ }
25118
25603
  }
25119
25604
  },
25120
25605
  {
@@ -25164,7 +25649,8 @@
25164
25649
  (function(SpriteUpdateFlags) {
25165
25650
  SpriteUpdateFlags[SpriteUpdateFlags["positions"] = 0x1] = "positions";
25166
25651
  SpriteUpdateFlags[SpriteUpdateFlags["uvs"] = 0x2] = "uvs";
25167
- SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x3] = "all";
25652
+ SpriteUpdateFlags[SpriteUpdateFlags["automaticSize"] = 0x4] = "automaticSize";
25653
+ SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x7] = "all";
25168
25654
  })(SpriteUpdateFlags || (SpriteUpdateFlags = {}));
25169
25655
  var _SlicedSpriteAssembler;
25170
25656
  var SlicedSpriteAssembler = (_SlicedSpriteAssembler = /*#__PURE__*/ function() {
@@ -25652,8 +26138,10 @@
25652
26138
  _this._tiledAdaptiveThreshold = 0.5;
25653
26139
  _this._color = new Color$1(1, 1, 1, 1);
25654
26140
  _this._sprite = null;
25655
- _this._width = undefined;
25656
- _this._height = undefined;
26141
+ _this._automaticWidth = 0;
26142
+ _this._automaticHeight = 0;
26143
+ _this._customWidth = undefined;
26144
+ _this._customHeight = undefined;
25657
26145
  _this._flipX = false;
25658
26146
  _this._flipY = false;
25659
26147
  _this._maskLayer = exports.SpriteMaskLayer.Layer0;
@@ -25669,38 +26157,45 @@
25669
26157
  /**
25670
26158
  * @internal
25671
26159
  */ _proto._cloneTo = function _cloneTo(target) {
26160
+ Renderer.prototype._cloneTo.call(this, target);
25672
26161
  target._assembler.resetData(target);
25673
26162
  target.sprite = this._sprite;
26163
+ target.drawMode = this._drawMode;
25674
26164
  };
25675
- _proto._updateShaderData = function _updateShaderData(context) {
26165
+ /**
26166
+ * @internal
26167
+ */ _proto._updateShaderData = function _updateShaderData(context) {
25676
26168
  // @ts-ignore
25677
26169
  this._updateTransformShaderData(context, Matrix._identity);
25678
26170
  };
25679
- _proto._updateBounds = function _updateBounds(worldBounds) {
25680
- var _this_sprite;
25681
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
26171
+ /**
26172
+ * @internal
26173
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
26174
+ if (this.sprite) {
26175
+ this._assembler.updatePositions(this);
26176
+ } else {
25682
26177
  worldBounds.min.set(0, 0, 0);
25683
26178
  worldBounds.max.set(0, 0, 0);
25684
- } else {
25685
- this._assembler.updatePositions(this);
25686
26179
  }
25687
26180
  };
25688
- _proto._render = function _render(context) {
26181
+ /**
26182
+ * @internal
26183
+ */ _proto._render = function _render(context) {
25689
26184
  var _this_sprite;
25690
26185
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
25691
26186
  return;
25692
26187
  }
25693
- // Update position.
26188
+ // Update position
25694
26189
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
25695
26190
  this._assembler.updatePositions(this);
25696
26191
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
25697
26192
  }
25698
- // Update uv.
26193
+ // Update uv
25699
26194
  if (this._dirtyUpdateFlag & 0x2) {
25700
26195
  this._assembler.updateUVs(this);
25701
26196
  this._dirtyUpdateFlag &= ~0x2;
25702
26197
  }
25703
- // Push render data
26198
+ // Push primitive
25704
26199
  var material = this.getMaterial();
25705
26200
  var texture = this.sprite.texture;
25706
26201
  var renderData = this._engine._spriteRenderDataPool.getFromPool();
@@ -25710,14 +26205,28 @@
25710
26205
  /**
25711
26206
  * @internal
25712
26207
  */ _proto._onDestroy = function _onDestroy() {
25713
- var _this__sprite;
25714
26208
  Renderer.prototype._onDestroy.call(this);
25715
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
26209
+ var sprite = this._sprite;
26210
+ if (sprite) {
26211
+ sprite._addReferCount(-1);
26212
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
26213
+ }
26214
+ this._entity = null;
25716
26215
  this._color = null;
25717
26216
  this._sprite = null;
25718
26217
  this._assembler = null;
25719
26218
  this._verticesData = null;
25720
26219
  };
26220
+ _proto._calDefaultSize = function _calDefaultSize() {
26221
+ var sprite = this._sprite;
26222
+ if (sprite) {
26223
+ this._automaticWidth = sprite.width;
26224
+ this._automaticHeight = sprite.height;
26225
+ } else {
26226
+ this._automaticWidth = this._automaticHeight = 0;
26227
+ }
26228
+ this._dirtyUpdateFlag &= ~0x4;
26229
+ };
25721
26230
  _proto._updateStencilState = function _updateStencilState() {
25722
26231
  // Update stencil.
25723
26232
  var material = this.getInstanceMaterial();
@@ -25744,22 +26253,21 @@
25744
26253
  break;
25745
26254
  case SpriteModifyFlags.size:
25746
26255
  var _this = this, drawMode = _this._drawMode;
25747
- if (drawMode === exports.SpriteDrawMode.Sliced) {
26256
+ this._dirtyUpdateFlag |= 0x4;
26257
+ if (this._drawMode === exports.SpriteDrawMode.Sliced) {
25748
26258
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25749
26259
  } else if (drawMode === exports.SpriteDrawMode.Tiled) {
25750
26260
  this._dirtyUpdateFlag |= 0x3;
25751
26261
  } else {
25752
26262
  // When the width and height of `SpriteRenderer` are `undefined`,
25753
26263
  // the `size` of `Sprite` will affect the position of `SpriteRenderer`.
25754
- if (this._width === undefined || this._height === undefined) {
26264
+ if (this._customWidth === undefined || this._customHeight === undefined) {
25755
26265
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25756
26266
  }
25757
26267
  }
25758
26268
  break;
25759
26269
  case SpriteModifyFlags.border:
25760
- if (this._drawMode === exports.SpriteDrawMode.Sliced || this._drawMode === exports.SpriteDrawMode.Tiled) {
25761
- this._dirtyUpdateFlag |= 0x3;
25762
- }
26270
+ this._drawMode === exports.SpriteDrawMode.Sliced && (this._dirtyUpdateFlag |= 0x3);
25763
26271
  break;
25764
26272
  case SpriteModifyFlags.region:
25765
26273
  case SpriteModifyFlags.atlasRegionOffset:
@@ -25843,10 +26351,14 @@
25843
26351
  set: function set(value) {
25844
26352
  var lastSprite = this._sprite;
25845
26353
  if (lastSprite !== value) {
25846
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
26354
+ if (lastSprite) {
26355
+ lastSprite._addReferCount(-1);
26356
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
26357
+ }
26358
+ this._dirtyUpdateFlag |= 0x7;
25847
26359
  if (value) {
26360
+ value._addReferCount(1);
25848
26361
  value._updateFlagManager.addListener(this._onSpriteChange);
25849
- this._dirtyUpdateFlag |= 0x3;
25850
26362
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
25851
26363
  } else {
25852
26364
  this.shaderData.setTexture(SpriteRenderer._textureProperty, null);
@@ -25871,16 +26383,22 @@
25871
26383
  {
25872
26384
  key: "width",
25873
26385
  get: /**
25874
- * Render width.
26386
+ * Render width (in world coordinates).
26387
+ *
26388
+ * @remarks
26389
+ * If width is set, return the set value,
26390
+ * otherwise return `SpriteRenderer.sprite.width`.
25875
26391
  */ function get() {
25876
- this._width === undefined && this._sprite && (this.width = this._sprite.width);
25877
- return this._width;
26392
+ if (this._customWidth !== undefined) {
26393
+ return this._customWidth;
26394
+ } else {
26395
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
26396
+ return this._automaticWidth;
26397
+ }
25878
26398
  },
25879
26399
  set: function set(value) {
25880
- // Update width if undefined
25881
- this._width === undefined && this._sprite && (this._width = this._sprite.width);
25882
- if (this._width !== value) {
25883
- this._width = value;
26400
+ if (this._customWidth !== value) {
26401
+ this._customWidth = value;
25884
26402
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25885
26403
  }
25886
26404
  }
@@ -25888,16 +26406,22 @@
25888
26406
  {
25889
26407
  key: "height",
25890
26408
  get: /**
25891
- * Render height.
26409
+ * Render height (in world coordinates).
26410
+ *
26411
+ * @remarks
26412
+ * If height is set, return the set value,
26413
+ * otherwise return `SpriteRenderer.sprite.height`.
25892
26414
  */ function get() {
25893
- this._height === undefined && this._sprite && (this.height = this._sprite.height);
25894
- return this._height;
26415
+ if (this._customHeight !== undefined) {
26416
+ return this._customHeight;
26417
+ } else {
26418
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
26419
+ return this._automaticHeight;
26420
+ }
25895
26421
  },
25896
26422
  set: function set(value) {
25897
- // Update height if undefined
25898
- this._height === undefined && this._sprite && (this._height = this._sprite.height);
25899
- if (this._height !== value) {
25900
- this._height = value;
26423
+ if (this._customHeight !== value) {
26424
+ this._customHeight = value;
25901
26425
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
25902
26426
  }
25903
26427
  }
@@ -25984,10 +26508,16 @@
25984
26508
  ], SpriteRenderer.prototype, "_sprite", void 0);
25985
26509
  __decorate$1([
25986
26510
  ignoreClone
25987
- ], SpriteRenderer.prototype, "_width", void 0);
26511
+ ], SpriteRenderer.prototype, "_automaticWidth", void 0);
25988
26512
  __decorate$1([
25989
26513
  ignoreClone
25990
- ], SpriteRenderer.prototype, "_height", void 0);
26514
+ ], SpriteRenderer.prototype, "_automaticHeight", void 0);
26515
+ __decorate$1([
26516
+ assignmentClone
26517
+ ], SpriteRenderer.prototype, "_customWidth", void 0);
26518
+ __decorate$1([
26519
+ assignmentClone
26520
+ ], SpriteRenderer.prototype, "_customHeight", void 0);
25991
26521
  __decorate$1([
25992
26522
  assignmentClone
25993
26523
  ], SpriteRenderer.prototype, "_flipX", void 0);
@@ -26008,7 +26538,9 @@
26008
26538
  */ SpriteRendererUpdateFlags;
26009
26539
  (function(SpriteRendererUpdateFlags) {
26010
26540
  SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
26011
- SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x3] = "All";
26541
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
26542
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
26543
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x7] = "All";
26012
26544
  })(SpriteRendererUpdateFlags || (SpriteRendererUpdateFlags = {}));
26013
26545
  /**
26014
26546
  * @internal
@@ -26093,7 +26625,9 @@
26093
26625
  this._font._addReferCount(1);
26094
26626
  this.setMaterial(engine._spriteDefaultMaterial);
26095
26627
  };
26096
- _proto._onDestroy = function _onDestroy() {
26628
+ /**
26629
+ * @internal
26630
+ */ _proto._onDestroy = function _onDestroy() {
26097
26631
  Renderer.prototype._onDestroy.call(this);
26098
26632
  // Clear render data.
26099
26633
  var charRenderDatas = this._charRenderDatas;
@@ -26110,6 +26644,7 @@
26110
26644
  /**
26111
26645
  * @internal
26112
26646
  */ _proto._cloneTo = function _cloneTo(target) {
26647
+ Renderer.prototype._cloneTo.call(this, target);
26113
26648
  target.font = this._font;
26114
26649
  target._subFont = this._subFont;
26115
26650
  };
@@ -26128,14 +26663,20 @@
26128
26663
  */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
26129
26664
  this._dirtyFlag &= ~type;
26130
26665
  };
26131
- _proto._updateShaderData = function _updateShaderData(context) {
26666
+ /**
26667
+ * @internal
26668
+ */ _proto._updateShaderData = function _updateShaderData(context) {
26132
26669
  // @ts-ignore
26133
26670
  this._updateTransformShaderData(context, Matrix._identity);
26134
26671
  };
26135
- _proto._updateBounds = function _updateBounds(worldBounds) {
26672
+ /**
26673
+ * @internal
26674
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
26136
26675
  BoundingBox.transform(this._localBounds, this._entity.transform.worldMatrix, worldBounds);
26137
26676
  };
26138
- _proto._render = function _render(context) {
26677
+ /**
26678
+ * @internal
26679
+ */ _proto._render = function _render(context) {
26139
26680
  if (this._text === "" || this.enableWrapping && this.width <= 0 || this.overflowMode === exports.OverflowMode.Truncate && this.height <= 0) {
26140
26681
  return;
26141
26682
  }
@@ -26230,8 +26771,6 @@
26230
26771
  _proto._updateLocalData = function _updateLocalData() {
26231
26772
  var _this = this, color = _this.color, horizontalAlignment = _this.horizontalAlignment, verticalAlignment = _this.verticalAlignment, charRenderDatas = _this._charRenderDatas;
26232
26773
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
26233
- min.set(0, 0, 0);
26234
- max.set(0, 0, 0);
26235
26774
  var _pixelsPerUnit = Engine._pixelsPerUnit;
26236
26775
  var pixelsPerUnitReciprocal = 1.0 / _pixelsPerUnit;
26237
26776
  var charFont = this._subFont;
@@ -26258,54 +26797,65 @@
26258
26797
  break;
26259
26798
  }
26260
26799
  var renderDataCount = 0;
26800
+ var firstLine = -1;
26261
26801
  var minX = Number.MAX_SAFE_INTEGER;
26262
26802
  var minY = Number.MAX_SAFE_INTEGER;
26263
26803
  var maxX = Number.MIN_SAFE_INTEGER;
26264
26804
  var maxY = Number.MIN_SAFE_INTEGER;
26265
- var lastLineIndex = linesLen - 1;
26266
26805
  for(var i = 0; i < linesLen; ++i){
26267
- var line = lines[i];
26268
26806
  var lineWidth = lineWidths[i];
26269
- var startX = 0;
26270
- switch(horizontalAlignment){
26271
- case exports.TextHorizontalAlignment.Left:
26272
- startX = -halfRendererWidth;
26273
- break;
26274
- case exports.TextHorizontalAlignment.Center:
26275
- startX = -lineWidth * 0.5;
26276
- break;
26277
- case exports.TextHorizontalAlignment.Right:
26278
- startX = halfRendererWidth - lineWidth;
26279
- break;
26280
- }
26281
- for(var j = 0, m = line.length - 1; j <= m; ++j){
26282
- var char = line[j];
26283
- var charInfo = charFont._getCharInfo(char);
26284
- if (charInfo.h > 0) {
26285
- var charRenderData = charRenderDatas[renderDataCount] || charRenderDataPool.get();
26286
- var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
26287
- charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
26288
- renderData.color = color;
26289
- renderData.uvs = charInfo.uvs;
26290
- var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
26291
- var left = startX * pixelsPerUnitReciprocal;
26292
- var right = (startX + w) * pixelsPerUnitReciprocal;
26293
- var top = (startY + ascent) * pixelsPerUnitReciprocal;
26294
- var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
26295
- localPositions.set(left, top, right, bottom);
26296
- charRenderDatas[renderDataCount] = charRenderData;
26297
- renderDataCount++;
26298
- i === 0 && (maxY = Math.max(maxY, top));
26299
- i === lastLineIndex && (minY = Math.min(minY, bottom));
26300
- j === 0 && (minX = Math.min(minX, left));
26301
- j === m && (maxX = Math.max(maxX, right));
26302
- }
26303
- startX += charInfo.xAdvance;
26807
+ if (lineWidth > 0) {
26808
+ var line = lines[i];
26809
+ var startX = 0;
26810
+ var firstRow = -1;
26811
+ if (firstLine < 0) {
26812
+ firstLine = i;
26813
+ }
26814
+ switch(horizontalAlignment){
26815
+ case exports.TextHorizontalAlignment.Left:
26816
+ startX = -halfRendererWidth;
26817
+ break;
26818
+ case exports.TextHorizontalAlignment.Center:
26819
+ startX = -lineWidth * 0.5;
26820
+ break;
26821
+ case exports.TextHorizontalAlignment.Right:
26822
+ startX = halfRendererWidth - lineWidth;
26823
+ break;
26824
+ }
26825
+ for(var j = 0, n = line.length; j < n; ++j){
26826
+ var char = line[j];
26827
+ var charInfo = charFont._getCharInfo(char);
26828
+ if (charInfo.h > 0) {
26829
+ var _charRenderDatas, _ref;
26830
+ firstRow < 0 && (firstRow = j);
26831
+ var charRenderData = (_charRenderDatas = charRenderDatas)[_ref = renderDataCount++] || (_charRenderDatas[_ref] = charRenderDataPool.get());
26832
+ var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
26833
+ charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
26834
+ renderData.color = color;
26835
+ renderData.uvs = charInfo.uvs;
26836
+ var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
26837
+ var left = startX * pixelsPerUnitReciprocal;
26838
+ var right = (startX + w) * pixelsPerUnitReciprocal;
26839
+ var top = (startY + ascent) * pixelsPerUnitReciprocal;
26840
+ var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
26841
+ localPositions.set(left, top, right, bottom);
26842
+ i === firstLine && (maxY = Math.max(maxY, top));
26843
+ minY = Math.min(minY, bottom);
26844
+ j === firstRow && (minX = Math.min(minX, left));
26845
+ maxX = Math.max(maxX, right);
26846
+ }
26847
+ startX += charInfo.xAdvance;
26848
+ }
26304
26849
  }
26305
26850
  startY -= lineHeight;
26306
26851
  }
26307
- min.set(minX, minY, 0);
26308
- max.set(maxX, maxY, 0);
26852
+ if (firstLine < 0) {
26853
+ min.set(0, 0, 0);
26854
+ max.set(0, 0, 0);
26855
+ } else {
26856
+ min.set(minX, minY, 0);
26857
+ max.set(maxX, maxY, 0);
26858
+ }
26309
26859
  // Revert excess render data to pool.
26310
26860
  var lastRenderDataCount = charRenderDatas.length;
26311
26861
  if (lastRenderDataCount > renderDataCount) {
@@ -26318,7 +26868,9 @@
26318
26868
  return a.texture.instanceId - b.texture.instanceId;
26319
26869
  });
26320
26870
  };
26321
- _proto._onTransformChanged = function _onTransformChanged(bit) {
26871
+ /**
26872
+ * @internal
26873
+ */ _proto._onTransformChanged = function _onTransformChanged(bit) {
26322
26874
  Renderer.prototype._onTransformChanged.call(this, bit);
26323
26875
  this._setDirtyFlagTrue(0x4 | 0x8);
26324
26876
  };
@@ -26635,7 +27187,6 @@
26635
27187
  * @internal
26636
27188
  */ var AnimationCurveOwner = /*#__PURE__*/ function() {
26637
27189
  function AnimationCurveOwner(target, type, property, cureType) {
26638
- this.crossCurveMark = 0;
26639
27190
  this.hasSavedDefaultValue = false;
26640
27191
  this.baseEvaluateData = {
26641
27192
  curKeyframeIndex: 0,
@@ -26829,6 +27380,11 @@
26829
27380
  return BlendShapeWeightsAnimationCurveOwnerAssembler;
26830
27381
  }();
26831
27382
  AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights", BlendShapeWeightsAnimationCurveOwnerAssembler);
27383
+ /**
27384
+ * @internal
27385
+ */ var AnimationCurveLayerOwner = function AnimationCurveLayerOwner() {
27386
+ this.crossCurveMark = 0;
27387
+ };
26832
27388
  /**
26833
27389
  * Associate AnimationCurve and the Entity
26834
27390
  */ var AnimationClipCurveBinding = /*#__PURE__*/ function() {
@@ -26846,6 +27402,13 @@
26846
27402
  };
26847
27403
  /**
26848
27404
  * @internal
27405
+ */ _proto._createCurveLayerOwner = function _createCurveLayerOwner(owner) {
27406
+ var layerOwner = new AnimationCurveLayerOwner();
27407
+ layerOwner.curveOwner = owner;
27408
+ return layerOwner;
27409
+ };
27410
+ /**
27411
+ * @internal
26849
27412
  */ _proto._getTempCurveOwner = function _getTempCurveOwner(entity) {
26850
27413
  var instanceId = entity.instanceId;
26851
27414
  if (!this._tempCurveOwner[instanceId]) {
@@ -27921,9 +28484,14 @@
27921
28484
  })(LayerState || (LayerState = {}));
27922
28485
  /**
27923
28486
  * @internal
27924
- */ var AnimationEventHandler = function AnimationEventHandler() {
27925
- this.handlers = [];
27926
- };
28487
+ */ var AnimationEventHandler = /*#__PURE__*/ function() {
28488
+ var AnimationEventHandler = function AnimationEventHandler() {
28489
+ this.handlers = [];
28490
+ };
28491
+ var _proto = AnimationEventHandler.prototype;
28492
+ _proto.dispose = function dispose() {};
28493
+ return AnimationEventHandler;
28494
+ }();
27927
28495
  /**
27928
28496
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.
27929
28497
  */ var AnimatorStateTransition = function AnimatorStateTransition() {
@@ -27977,12 +28545,14 @@
27977
28545
  * @internal
27978
28546
  */ var AnimatorLayerData = /*#__PURE__*/ function() {
27979
28547
  var AnimatorLayerData = function AnimatorLayerData() {
28548
+ this.curveOwnerPool = Object.create(null);
27980
28549
  this.animatorStateDataMap = {};
27981
28550
  this.srcPlayData = new AnimatorStatePlayData();
27982
28551
  this.destPlayData = new AnimatorStatePlayData();
27983
28552
  this.layerState = LayerState.Standby;
27984
28553
  this.crossCurveMark = 0;
27985
28554
  this.manuallyTransition = new AnimatorStateTransition();
28555
+ this.crossOwnerLayerDataCollection = [];
27986
28556
  };
27987
28557
  var _proto = AnimatorLayerData.prototype;
27988
28558
  _proto.switchPlayData = function switchPlayData() {
@@ -27996,7 +28566,7 @@
27996
28566
  /**
27997
28567
  * @internal
27998
28568
  */ var AnimatorStateData = function AnimatorStateData() {
27999
- this.curveOwners = [];
28569
+ this.curveLayerOwner = [];
28000
28570
  this.eventHandlers = [];
28001
28571
  };
28002
28572
  /**
@@ -28008,8 +28578,7 @@
28008
28578
  /** Culling mode of this Animator. */ _this.cullingMode = exports.AnimatorCullingMode.None;
28009
28579
  /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0;
28010
28580
  _this._animatorLayersData = [];
28011
- _this._crossOwnerCollection = [];
28012
- _this._animationCurveOwners = [];
28581
+ _this._curveOwnerPool = Object.create(null);
28013
28582
  _this._animationEventHandlerPool = new ClassPool(AnimationEventHandler);
28014
28583
  _this._tempAnimatorStateInfo = {
28015
28584
  layerIndex: -1,
@@ -28042,7 +28611,6 @@
28042
28611
  return;
28043
28612
  }
28044
28613
  var animatorLayerData = this._getAnimatorLayerData(stateInfo.layerIndex);
28045
- //TODO CM: Not consider same stateName, but different animation
28046
28614
  var animatorStateData = this._getAnimatorStateData(stateName, state, animatorLayerData);
28047
28615
  this._preparePlay(animatorLayerData, state, animatorStateData);
28048
28616
  animatorLayerData.layerState = LayerState.Playing;
@@ -28133,7 +28701,7 @@
28133
28701
  /**
28134
28702
  * @internal
28135
28703
  */ _proto._reset = function _reset() {
28136
- var _this = this, animationCurveOwners = _this._animationCurveOwners;
28704
+ var _this = this, animationCurveOwners = _this._curveOwnerPool;
28137
28705
  for(var instanceId in animationCurveOwners){
28138
28706
  var propertyOwners = animationCurveOwners[instanceId];
28139
28707
  for(var property in propertyOwners){
@@ -28142,8 +28710,7 @@
28142
28710
  }
28143
28711
  }
28144
28712
  this._animatorLayersData.length = 0;
28145
- this._crossOwnerCollection.length = 0;
28146
- this._animationCurveOwners.length = 0;
28713
+ this._curveOwnerPool = {};
28147
28714
  this._animationEventHandlerPool.resetPool();
28148
28715
  if (this._controllerUpdateFlag) {
28149
28716
  this._controllerUpdateFlag.flag = false;
@@ -28171,10 +28738,10 @@
28171
28738
  return stateInfo;
28172
28739
  };
28173
28740
  _proto._saveDefaultValues = function _saveDefaultValues(stateData) {
28174
- var curveOwners = stateData.curveOwners;
28175
- for(var i = curveOwners.length - 1; i >= 0; i--){
28176
- var _curveOwners_i;
28177
- (_curveOwners_i = curveOwners[i]) == null ? void 0 : _curveOwners_i.saveDefaultValue();
28741
+ var curveLayerOwner = stateData.curveLayerOwner;
28742
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
28743
+ var _curveLayerOwner_i;
28744
+ (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.saveDefaultValue();
28178
28745
  }
28179
28746
  };
28180
28747
  _proto._getAnimatorStateData = function _getAnimatorStateData(stateName, animatorState, animatorLayerData) {
@@ -28183,25 +28750,32 @@
28183
28750
  if (!animatorStateData) {
28184
28751
  animatorStateData = new AnimatorStateData();
28185
28752
  animatorStateDataMap[stateName] = animatorStateData;
28186
- this._saveAnimatorStateData(animatorState, animatorStateData);
28753
+ this._saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData);
28187
28754
  this._saveAnimatorEventHandlers(animatorState, animatorStateData);
28188
28755
  }
28189
28756
  return animatorStateData;
28190
28757
  };
28191
- _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData) {
28192
- var _this = this, entity = _this.entity, animationCureOwners = _this._animationCurveOwners;
28193
- var curveOwners = animatorStateData.curveOwners;
28758
+ _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData) {
28759
+ var _this = this, entity = _this.entity, curveOwnerPool = _this._curveOwnerPool;
28760
+ var curveLayerOwner = animatorStateData.curveLayerOwner;
28761
+ var layerCurveOwnerPool = animatorLayerData.curveOwnerPool;
28194
28762
  var _animatorState_clip = animatorState.clip, curves = _animatorState_clip._curveBindings;
28195
28763
  for(var i = curves.length - 1; i >= 0; i--){
28196
28764
  var curve = curves[i];
28197
28765
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
28198
28766
  if (targetEntity) {
28767
+ var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
28199
28768
  var property = curve.property;
28200
28769
  var instanceId = targetEntity.instanceId;
28201
- var propertyOwners = animationCureOwners[instanceId] || (animationCureOwners[instanceId] = {});
28202
- curveOwners[i] = propertyOwners[property] || (propertyOwners[property] = curve._createCurveOwner(targetEntity));
28770
+ // Get owner
28771
+ var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
28772
+ var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity));
28773
+ // Get layer owner
28774
+ var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
28775
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
28776
+ curveLayerOwner[i] = layerOwner;
28203
28777
  } else {
28204
- curveOwners[i] = null;
28778
+ curveLayerOwner[i] = null;
28205
28779
  console.warn("The entity don't have the child entity which path is " + curve.relativePath + ".");
28206
28780
  }
28207
28781
  }
@@ -28229,65 +28803,61 @@
28229
28803
  };
28230
28804
  _proto._clearCrossData = function _clearCrossData(animatorLayerData) {
28231
28805
  animatorLayerData.crossCurveMark++;
28232
- this._crossOwnerCollection.length = 0;
28806
+ animatorLayerData.crossOwnerLayerDataCollection.length = 0;
28233
28807
  };
28234
- _proto._addCrossCurveData = function _addCrossCurveData(crossCurveData, owner, curCurveIndex, nextCurveIndex) {
28235
- owner.crossSrcCurveIndex = curCurveIndex;
28236
- owner.crossDestCurveIndex = nextCurveIndex;
28237
- crossCurveData.push(owner);
28808
+ _proto._addCrossOwner = function _addCrossOwner(animatorLayerData, layerOwner, curCurveIndex, nextCurveIndex) {
28809
+ layerOwner.crossSrcCurveIndex = curCurveIndex;
28810
+ layerOwner.crossDestCurveIndex = nextCurveIndex;
28811
+ animatorLayerData.crossOwnerLayerDataCollection.push(layerOwner);
28238
28812
  };
28239
28813
  _proto._prepareCrossFading = function _prepareCrossFading(animatorLayerData) {
28240
- var crossCurveData = this._crossOwnerCollection;
28241
- var crossCurveMark = animatorLayerData.crossCurveMark;
28242
28814
  // Add src cross curve data.
28243
- this._prepareSrcCrossData(crossCurveData, animatorLayerData.srcPlayData, crossCurveMark, false);
28815
+ this._prepareSrcCrossData(animatorLayerData, false);
28244
28816
  // Add dest cross curve data.
28245
- this._prepareDestCrossData(crossCurveData, animatorLayerData.destPlayData, crossCurveMark, false);
28817
+ this._prepareDestCrossData(animatorLayerData, false);
28246
28818
  };
28247
28819
  _proto._prepareStandbyCrossFading = function _prepareStandbyCrossFading(animatorLayerData) {
28248
- var crossOwnerCollection = this._crossOwnerCollection;
28249
- var srcPlayData = animatorLayerData.srcPlayData, crossCurveMark = animatorLayerData.crossCurveMark;
28250
28820
  // Standby have two sub state, one is never play, one is finished, never play srcPlayData.state is null.
28251
- srcPlayData.state && this._prepareSrcCrossData(crossOwnerCollection, srcPlayData, crossCurveMark, true);
28821
+ animatorLayerData.srcPlayData.state && this._prepareSrcCrossData(animatorLayerData, true);
28252
28822
  // Add dest cross curve data.
28253
- this._prepareDestCrossData(crossOwnerCollection, animatorLayerData.destPlayData, crossCurveMark, true);
28823
+ this._prepareDestCrossData(animatorLayerData, true);
28254
28824
  };
28255
28825
  _proto._prepareFixedPoseCrossFading = function _prepareFixedPoseCrossFading(animatorLayerData) {
28256
- var crossOwnerCollection = this._crossOwnerCollection;
28826
+ var crossOwnerLayerDataCollection = animatorLayerData.crossOwnerLayerDataCollection;
28257
28827
  // Save current cross curve data owner fixed pose.
28258
- for(var i = crossOwnerCollection.length - 1; i >= 0; i--){
28259
- var item = crossOwnerCollection[i];
28260
- item.saveFixedPoseValue();
28828
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
28829
+ var layerOwner = crossOwnerLayerDataCollection[i];
28830
+ if (!layerOwner) continue;
28831
+ layerOwner.curveOwner.saveFixedPoseValue();
28261
28832
  // Reset destCurveIndex When fixed pose crossFading again.
28262
- item.crossDestCurveIndex = -1;
28833
+ layerOwner.crossDestCurveIndex = -1;
28263
28834
  }
28264
28835
  // prepare dest AnimatorState cross data.
28265
- this._prepareDestCrossData(crossOwnerCollection, animatorLayerData.destPlayData, animatorLayerData.crossCurveMark, true);
28266
- };
28267
- _proto._prepareSrcCrossData = function _prepareSrcCrossData(crossCurveData, srcPlayData, crossCurveMark, saveFixed) {
28268
- var curveOwners = srcPlayData.stateData.curveOwners;
28269
- for(var i = curveOwners.length - 1; i >= 0; i--){
28270
- var owner = curveOwners[i];
28271
- if (!owner) continue;
28272
- owner.crossCurveMark = crossCurveMark;
28273
- owner.crossCurveDataIndex = crossCurveData.length;
28274
- saveFixed && owner.saveFixedPoseValue();
28275
- this._addCrossCurveData(crossCurveData, owner, i, -1);
28276
- }
28277
- };
28278
- _proto._prepareDestCrossData = function _prepareDestCrossData(crossCurveData, destPlayData, crossCurveMark, saveFixed) {
28279
- var curveOwners = destPlayData.stateData.curveOwners;
28280
- for(var i = curveOwners.length - 1; i >= 0; i--){
28281
- var owner = curveOwners[i];
28282
- if (!owner) continue;
28283
- if (owner.crossCurveMark === crossCurveMark) {
28284
- crossCurveData[owner.crossCurveDataIndex].crossDestCurveIndex = i;
28836
+ this._prepareDestCrossData(animatorLayerData, true);
28837
+ };
28838
+ _proto._prepareSrcCrossData = function _prepareSrcCrossData(animatorLayerData, saveFixed) {
28839
+ var curveLayerOwner = animatorLayerData.srcPlayData.stateData.curveLayerOwner;
28840
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
28841
+ var layerOwner = curveLayerOwner[i];
28842
+ if (!layerOwner) continue;
28843
+ layerOwner.crossCurveMark = animatorLayerData.crossCurveMark;
28844
+ saveFixed && layerOwner.curveOwner.saveFixedPoseValue();
28845
+ this._addCrossOwner(animatorLayerData, layerOwner, i, -1);
28846
+ }
28847
+ };
28848
+ _proto._prepareDestCrossData = function _prepareDestCrossData(animatorLayerData, saveFixed) {
28849
+ var curveLayerOwner = animatorLayerData.destPlayData.stateData.curveLayerOwner;
28850
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
28851
+ var layerOwner = curveLayerOwner[i];
28852
+ if (!layerOwner) continue;
28853
+ if (layerOwner.crossCurveMark === animatorLayerData.crossCurveMark) {
28854
+ layerOwner.crossDestCurveIndex = i;
28285
28855
  } else {
28856
+ var owner = layerOwner.curveOwner;
28286
28857
  owner.saveDefaultValue();
28287
28858
  saveFixed && owner.saveFixedPoseValue();
28288
- owner.crossCurveMark = crossCurveMark;
28289
- owner.crossCurveDataIndex = crossCurveData.length;
28290
- this._addCrossCurveData(crossCurveData, owner, -1, i);
28859
+ layerOwner.crossCurveMark = animatorLayerData.crossCurveMark;
28860
+ this._addCrossOwner(animatorLayerData, layerOwner, -1, i);
28291
28861
  }
28292
28862
  }
28293
28863
  };
@@ -28317,7 +28887,7 @@
28317
28887
  }
28318
28888
  };
28319
28889
  _proto._updatePlayingState = function _updatePlayingState(playData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
28320
- var _playData_stateData = playData.stateData, curveOwners = _playData_stateData.curveOwners, eventHandlers = _playData_stateData.eventHandlers;
28890
+ var _playData_stateData = playData.stateData, curveLayerOwner = _playData_stateData.curveLayerOwner, eventHandlers = _playData_stateData.eventHandlers;
28321
28891
  var state = playData.state, lastPlayState = playData.playState, lastClipTime = playData.clipTime;
28322
28892
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
28323
28893
  playData.update(this.speed < 0);
@@ -28327,8 +28897,8 @@
28327
28897
  var clipTime = playData.clipTime, playState = playData.playState;
28328
28898
  eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
28329
28899
  for(var i = curveBindings.length - 1; i >= 0; i--){
28330
- var owner = curveOwners[i];
28331
- owner == null ? void 0 : owner.evaluateAndApplyValue(curveBindings[i].curve, clipTime, weight, additive);
28900
+ var _curveLayerOwner_i;
28901
+ (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.evaluateAndApplyValue(curveBindings[i].curve, clipTime, weight, additive);
28332
28902
  }
28333
28903
  playData.frameTime += state.speed * delta;
28334
28904
  if (playState === AnimatorStatePlayState.Finished) {
@@ -28344,7 +28914,7 @@
28344
28914
  }
28345
28915
  };
28346
28916
  _proto._updateCrossFade = function _updateCrossFade(srcPlayData, destPlayData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
28347
- var _this = this, crossCurveDataCollection = _this._crossOwnerCollection;
28917
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
28348
28918
  var _srcPlayData_state_clip = srcPlayData.state.clip, srcCurves = _srcPlayData_state_clip._curveBindings;
28349
28919
  var srcState = srcPlayData.state, srcStateData = srcPlayData.stateData, lastSrcPlayState = srcPlayData.playState;
28350
28920
  var srcEventHandlers = srcStateData.eventHandlers;
@@ -28383,14 +28953,16 @@
28383
28953
  } else {
28384
28954
  this._callAnimatorScriptOnUpdate(destState, layerIndex);
28385
28955
  }
28386
- for(var i = crossCurveDataCollection.length - 1; i >= 0; i--){
28387
- var crossCurveData = crossCurveDataCollection[i];
28388
- var crossSrcCurveIndex = crossCurveData.crossSrcCurveIndex, crossDestCurveIndex = crossCurveData.crossDestCurveIndex;
28389
- crossCurveData.crossFadeAndApplyValue(crossSrcCurveIndex >= 0 ? srcCurves[crossSrcCurveIndex].curve : null, crossDestCurveIndex >= 0 ? destCurves[crossDestCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, weight, additive);
28956
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
28957
+ var layerOwner = crossOwnerLayerDataCollection[i];
28958
+ if (!layerOwner) continue;
28959
+ var srcCurveIndex = layerOwner.crossSrcCurveIndex;
28960
+ var destCurveIndex = layerOwner.crossDestCurveIndex;
28961
+ layerOwner.curveOwner.crossFadeAndApplyValue(srcCurveIndex >= 0 ? srcCurves[srcCurveIndex].curve : null, destCurveIndex >= 0 ? destCurves[destCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, weight, additive);
28390
28962
  }
28391
28963
  };
28392
28964
  _proto._updateCrossFadeFromPose = function _updateCrossFadeFromPose(destPlayData, layerData, layerIndex, layerWeight, delta, additive, aniUpdate) {
28393
- var crossCurveDataCollection = this._crossOwnerCollection;
28965
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
28394
28966
  var state = destPlayData.state, stateData = destPlayData.stateData, lastPlayState = destPlayData.playState;
28395
28967
  var eventHandlers = stateData.eventHandlers;
28396
28968
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
@@ -28414,10 +28986,11 @@
28414
28986
  } else {
28415
28987
  this._callAnimatorScriptOnUpdate(state, layerIndex);
28416
28988
  }
28417
- for(var i = crossCurveDataCollection.length - 1; i >= 0; i--){
28418
- var crossCurveData = crossCurveDataCollection[i];
28419
- var crossDestCurveIndex = crossCurveData.crossDestCurveIndex;
28420
- crossCurveData.crossFadeFromPoseAndApplyValue(crossDestCurveIndex >= 0 ? curveBindings[crossDestCurveIndex].curve : null, destClipTime, crossWeight, layerWeight, additive);
28989
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
28990
+ var layerOwner = crossOwnerLayerDataCollection[i];
28991
+ if (!layerOwner) continue;
28992
+ var curveIndex = layerOwner.crossDestCurveIndex;
28993
+ layerOwner.curveOwner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, layerWeight, additive);
28421
28994
  }
28422
28995
  };
28423
28996
  _proto._updateCrossFadeData = function _updateCrossFadeData(layerData, crossWeight, delta, fixed) {
@@ -28439,18 +29012,19 @@
28439
29012
  if (layerData.layerState === LayerState.Playing) {
28440
29013
  var srcPlayData = layerData.srcPlayData;
28441
29014
  if (srcPlayData.state !== playState) {
28442
- var curveOwners = srcPlayData.stateData.curveOwners;
28443
- for(var i = curveOwners.length - 1; i >= 0; i--){
28444
- var owner = curveOwners[i];
29015
+ var curveLayerOwner = srcPlayData.stateData.curveLayerOwner;
29016
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
29017
+ var _curveLayerOwner_i;
29018
+ var owner = (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner;
28445
29019
  (owner == null ? void 0 : owner.hasSavedDefaultValue) && owner.revertDefaultValue();
28446
29020
  }
28447
29021
  this._saveDefaultValues(playStateData);
28448
29022
  }
28449
29023
  } else {
28450
29024
  // layerState is CrossFading, FixedCrossFading, Standby
28451
- var crossCurveDataCollection = this._crossOwnerCollection;
28452
- for(var i1 = crossCurveDataCollection.length - 1; i1 >= 0; i1--){
28453
- var owner1 = crossCurveDataCollection[i1];
29025
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
29026
+ for(var i1 = crossOwnerLayerDataCollection.length - 1; i1 >= 0; i1--){
29027
+ var owner1 = crossOwnerLayerDataCollection[i1].curveOwner;
28454
29028
  owner1.hasSavedDefaultValue && owner1.revertDefaultValue();
28455
29029
  }
28456
29030
  this._saveDefaultValues(playStateData);
@@ -28620,10 +29194,7 @@
28620
29194
  ], Animator.prototype, "_animatorLayersData", void 0);
28621
29195
  __decorate$1([
28622
29196
  ignoreClone
28623
- ], Animator.prototype, "_crossOwnerCollection", void 0);
28624
- __decorate$1([
28625
- ignoreClone
28626
- ], Animator.prototype, "_animationCurveOwners", void 0);
29197
+ ], Animator.prototype, "_curveOwnerPool", void 0);
28627
29198
  __decorate$1([
28628
29199
  ignoreClone
28629
29200
  ], Animator.prototype, "_animationEventHandlerPool", void 0);
@@ -30041,7 +30612,9 @@
30041
30612
  this.getMaterial().shaderData.setTexture("u_texture", texture);
30042
30613
  }
30043
30614
  };
30044
- _proto._render = function _render(context) {
30615
+ /**
30616
+ * @internal
30617
+ */ _proto._render = function _render(context) {
30045
30618
  this._updateStrapVertices(context.camera, this._points);
30046
30619
  this._updateStrapCoords();
30047
30620
  this._vertexBuffer.setData(this._vertices);
@@ -30232,7 +30805,7 @@
30232
30805
  /**
30233
30806
  * The position of the probe can be set, the default is the origin [0,0,0].
30234
30807
  */ _this.position = new Vector3(0, 0, 0);
30235
- _this._isCube = true;
30808
+ /** @internal */ _this._isCube = true;
30236
30809
  _this.oriViewMatrix = new Matrix();
30237
30810
  return _this;
30238
30811
  };
@@ -30343,6 +30916,7 @@
30343
30916
  get BlendOperation () { return exports.BlendOperation; },
30344
30917
  BlendShape: BlendShape,
30345
30918
  BlendShapeFrame: BlendShapeFrame,
30919
+ BlendState: BlendState,
30346
30920
  BlinnPhongMaterial: BlinnPhongMaterial,
30347
30921
  BoolUpdateFlag: BoolUpdateFlag,
30348
30922
  BoxColliderShape: BoxColliderShape,
@@ -30371,6 +30945,7 @@
30371
30945
  get CullMode () { return exports.CullMode; },
30372
30946
  get DataType () { return exports.DataType; },
30373
30947
  get DependentMode () { return exports.DependentMode; },
30948
+ DepthState: DepthState,
30374
30949
  get DiffuseMode () { return exports.DiffuseMode; },
30375
30950
  DirectLight: DirectLight,
30376
30951
  DynamicCollider: DynamicCollider,
@@ -30422,13 +30997,16 @@
30422
30997
  get PointerPhase () { return exports.PointerPhase; },
30423
30998
  PrimitiveMesh: PrimitiveMesh,
30424
30999
  Probe: Probe,
31000
+ RasterState: RasterState,
30425
31001
  ReferResource: ReferResource,
30426
31002
  get RenderBufferDepthFormat () { return exports.RenderBufferDepthFormat; },
30427
31003
  get RenderFace () { return exports.RenderFace; },
30428
31004
  RenderPass: RenderPass,
30429
31005
  RenderQueue: RenderQueue,
30430
31006
  get RenderQueueType () { return exports.RenderQueueType; },
31007
+ RenderState: RenderState,
30431
31008
  RenderTarget: RenderTarget,
31009
+ RenderTargetBlendState: RenderTargetBlendState,
30432
31010
  get Renderer () { return exports.Renderer; },
30433
31011
  ResourceManager: ResourceManager,
30434
31012
  Scene: Scene,
@@ -30466,6 +31044,7 @@
30466
31044
  StateMachineScript: StateMachineScript,
30467
31045
  StaticCollider: StaticCollider,
30468
31046
  get StencilOperation () { return exports.StencilOperation; },
31047
+ StencilState: StencilState,
30469
31048
  SubMesh: SubMesh,
30470
31049
  SubShader: SubShader,
30471
31050
  get SunMode () { return exports.SunMode; },
@@ -30691,8 +31270,9 @@
30691
31270
  */ WebGLEngine.create = function create(configuration) {
30692
31271
  var canvas = configuration.canvas;
30693
31272
  var webCanvas = new WebCanvas(typeof canvas === "string" ? document.getElementById(canvas) : canvas);
30694
- var webGLRenderer = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
30695
- var engine = new WebGLEngine(webCanvas, webGLRenderer, configuration);
31273
+ var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
31274
+ var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
31275
+ // @ts-ignore
30696
31276
  return engine._initialize(configuration);
30697
31277
  };
30698
31278
  _create_class$2(WebGLEngine, [
@@ -30701,6 +31281,7 @@
30701
31281
  get: /**
30702
31282
  * Web canvas.
30703
31283
  */ function get() {
31284
+ // @ts-ignore
30704
31285
  return this._canvas;
30705
31286
  }
30706
31287
  }
@@ -32214,7 +32795,8 @@
32214
32795
  var options = _extends$1({
32215
32796
  webGLMode: 0,
32216
32797
  stencil: true,
32217
- _forceFlush: false
32798
+ _forceFlush: false,
32799
+ _maxAllowSkinUniformVectorCount: 256
32218
32800
  }, initializeOptions);
32219
32801
  if (SystemInfo.platform === exports.Platform.IPhone || SystemInfo.platform === exports.Platform.IPad) {
32220
32802
  var version = SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
@@ -32369,23 +32951,23 @@
32369
32951
  };
32370
32952
  _proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, mipLevel) {
32371
32953
  var gl = this._gl;
32954
+ var bufferWidth, bufferHeight;
32372
32955
  if (renderTarget) {
32373
32956
  var /** @ts-ignore */ _renderTarget__platformRenderTarget;
32374
32957
  (_renderTarget__platformRenderTarget = renderTarget._platformRenderTarget) == null ? void 0 : _renderTarget__platformRenderTarget._activeRenderTarget();
32375
- var width = renderTarget.width >> mipLevel;
32376
- var height = renderTarget.height >> mipLevel;
32377
- this.viewport(0, 0, width, height);
32378
- this.scissor(0, 0, width, height);
32958
+ bufferWidth = renderTarget.width >> mipLevel;
32959
+ bufferHeight = renderTarget.height >> mipLevel;
32379
32960
  } else {
32380
32961
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
32381
- var drawingBufferWidth = gl.drawingBufferWidth, drawingBufferHeight = gl.drawingBufferHeight;
32382
- var width1 = drawingBufferWidth * viewport.z;
32383
- var height1 = drawingBufferHeight * viewport.w;
32384
- var x = viewport.x * drawingBufferWidth;
32385
- var y = drawingBufferHeight - viewport.y * drawingBufferHeight - height1;
32386
- this.viewport(x, y, width1, height1);
32387
- this.scissor(x, y, width1, height1);
32962
+ bufferWidth = gl.drawingBufferWidth;
32963
+ bufferHeight = gl.drawingBufferHeight;
32388
32964
  }
32965
+ var width = bufferWidth * viewport.z;
32966
+ var height = bufferHeight * viewport.w;
32967
+ var x = viewport.x * bufferWidth;
32968
+ var y = bufferHeight - viewport.y * bufferHeight - height;
32969
+ this.viewport(x, y, width, height);
32970
+ this.scissor(x, y, width, height);
32389
32971
  };
32390
32972
  _proto.activeTexture = function activeTexture(textureID) {
32391
32973
  if (this._activeTextureID !== textureID) {
@@ -34388,6 +34970,10 @@
34388
34970
  }
34389
34971
  glTFResource.sceneRoots = sceneRoots;
34390
34972
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
34973
+ // @ts-ignore
34974
+ glTFResource.defaultSceneRoot._hookResource = glTFResource;
34975
+ // @ts-ignore
34976
+ glTFResource._addReferCount(1);
34391
34977
  };
34392
34978
  return GLTFEntityParser;
34393
34979
  }(GLTFParser);
@@ -34581,21 +35167,31 @@
34581
35167
  var vertexCount;
34582
35168
  var bufferBindIndex = 0;
34583
35169
  var positions;
34584
- keepMeshData && (positions = new Array(vertexCount));
35170
+ var boneIndices;
35171
+ var boneWeights;
35172
+ if (keepMeshData) {
35173
+ positions = new Array(vertexCount);
35174
+ boneIndices = new Array(vertexCount);
35175
+ boneWeights = new Array(vertexCount);
35176
+ }
34585
35177
  for(var attribute in attributes){
34586
35178
  var accessor = accessors[attributes[attribute]];
34587
35179
  var accessorBuffer = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor);
34588
35180
  var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
34589
- var attributeCount = accessor.count;
35181
+ var accessorCount = accessor.count;
34590
35182
  var vertices = accessorBuffer.data;
34591
35183
  var vertexElement = void 0;
34592
35184
  var meshId = mesh.instanceId;
34593
35185
  var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
34594
- var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, accessor.normalized);
35186
+ var elementNormalized = accessor.normalized;
35187
+ var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
35188
+ var scaleFactor = void 0;
35189
+ elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
35190
+ var elementOffset = void 0;
34595
35191
  if (accessorBuffer.interleaved) {
34596
35192
  var byteOffset = accessor.byteOffset || 0;
34597
35193
  var stride = accessorBuffer.stride;
34598
- var elementOffset = byteOffset % stride;
35194
+ elementOffset = byteOffset % stride;
34599
35195
  if (vertexBindingInfos[meshId] === undefined) {
34600
35196
  vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
34601
35197
  var vertexBuffer = accessorBuffer.vertexBuffer;
@@ -34611,7 +35207,8 @@
34611
35207
  vertexElement = new VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
34612
35208
  }
34613
35209
  } else {
34614
- vertexElement = new VertexElement(attribute, 0, elementFormat, bufferBindIndex);
35210
+ elementOffset = 0;
35211
+ vertexElement = new VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
34615
35212
  var vertexBuffer1 = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, vertices.byteLength, exports.BufferUsage.Static);
34616
35213
  vertexBuffer1.setData(vertices);
34617
35214
  meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
@@ -34620,35 +35217,61 @@
34620
35217
  }
34621
35218
  vertexElements.push(vertexElement);
34622
35219
  if (attribute === "POSITION") {
34623
- vertexCount = attributeCount;
35220
+ vertexCount = accessorCount;
34624
35221
  var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
34625
35222
  if (accessor.min && accessor.max) {
34626
35223
  min.copyFromArray(accessor.min);
34627
35224
  max.copyFromArray(accessor.max);
34628
35225
  if (keepMeshData) {
34629
- var stride1 = vertices.length / attributeCount;
34630
- for(var j = 0; j < attributeCount; j++){
34631
- var offset = j * stride1;
34632
- positions[j] = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
35226
+ var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
35227
+ var stride1 = vertices.length / accessorCount;
35228
+ for(var j = 0; j < accessorCount; j++){
35229
+ var offset = baseOffset + j * stride1;
35230
+ var position = new Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
35231
+ elementNormalized && position.scale(scaleFactor);
35232
+ positions[j] = position;
34633
35233
  }
34634
35234
  }
34635
35235
  } else {
34636
- var position = GLTFMeshParser._tempVector3;
35236
+ var position1 = GLTFMeshParser._tempVector3;
34637
35237
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
34638
35238
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
34639
- var stride2 = vertices.length / attributeCount;
34640
- for(var j1 = 0; j1 < attributeCount; j1++){
34641
- var offset1 = j1 * stride2;
34642
- position.copyFromArray(vertices, offset1);
34643
- Vector3.min(min, position, min);
34644
- Vector3.max(max, position, max);
35239
+ var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
35240
+ var stride2 = vertices.length / accessorCount;
35241
+ for(var j1 = 0; j1 < accessorCount; j1++){
35242
+ var offset1 = baseOffset1 + j1 * stride2;
35243
+ position1.copyFromArray(vertices, offset1);
35244
+ Vector3.min(min, position1, min);
35245
+ Vector3.max(max, position1, max);
35246
+ if (keepMeshData) {
35247
+ var clonePosition = position1.clone();
35248
+ elementNormalized && clonePosition.scale(scaleFactor);
35249
+ positions[j1] = clonePosition;
35250
+ }
34645
35251
  }
34646
35252
  }
34647
- if (accessor.normalized) {
34648
- var scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType);
35253
+ if (elementNormalized) {
34649
35254
  min.scale(scaleFactor);
34650
35255
  max.scale(scaleFactor);
34651
35256
  }
35257
+ } else if (attribute === "JOINTS_0" && keepMeshData) {
35258
+ var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
35259
+ var stride3 = vertices.length / accessorCount;
35260
+ for(var j2 = 0; j2 < accessorCount; j2++){
35261
+ var offset2 = baseOffset2 + j2 * stride3;
35262
+ var boneIndex = new Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
35263
+ elementNormalized && boneIndex.scale(scaleFactor);
35264
+ boneIndices[j2] = boneIndex;
35265
+ }
35266
+ } else if (attribute === "WEIGHTS_0" && keepMeshData) {
35267
+ var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
35268
+ var stride4 = vertices.length / accessorCount;
35269
+ for(var j3 = 0; j3 < accessorCount; j3++){
35270
+ var offset3 = baseOffset3 + j3 * stride4;
35271
+ var boneWeight = new Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
35272
+ elementNormalized && boneWeight.scale(scaleFactor);
35273
+ boneWeights[j3] = boneWeight;
35274
+ }
34652
35275
  }
34653
35276
  }
34654
35277
  mesh.setVertexElements(vertexElements);
@@ -34667,6 +35290,10 @@
34667
35290
  mesh.uploadData(!keepMeshData);
34668
35291
  //@ts-ignore
34669
35292
  mesh._positions = positions;
35293
+ //@ts-ignore
35294
+ mesh._boneIndices = boneIndices;
35295
+ //@ts-ignore
35296
+ mesh._boneWeights = boneWeights;
34670
35297
  return Promise.resolve(mesh);
34671
35298
  };
34672
35299
  /**
@@ -34756,14 +35383,7 @@
34756
35383
  camera.enabled = false;
34757
35384
  };
34758
35385
  _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
34759
- var glTFResource = context.glTFResource, glTF = context.glTF;
34760
- var glTFMeshes = glTF.meshes;
34761
- var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
34762
- var meshID = glTFNode.mesh, skinID = glTFNode.skin;
34763
- var glTFMesh = glTFMeshes[meshID];
34764
- var glTFMeshPrimitives = glTFMesh.primitives;
34765
- var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
34766
- for(var i = 0; i < glTFMeshPrimitives.length; i++){
35386
+ var _loop = function _loop(i) {
34767
35387
  var gltfPrimitive = glTFMeshPrimitives[i];
34768
35388
  var mesh = meshes[meshID][i];
34769
35389
  var renderer = void 0;
@@ -34785,8 +35405,22 @@
34785
35405
  var materialIndex = gltfPrimitive.material;
34786
35406
  var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
34787
35407
  renderer.setMaterial(material);
35408
+ // Enable vertex color if mesh has COLOR_0 vertex element
35409
+ mesh.vertexElements.forEach(function(element) {
35410
+ if (element.semantic === "COLOR_0") {
35411
+ renderer.enableVertexColor = true;
35412
+ }
35413
+ });
34788
35414
  GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
34789
- }
35415
+ };
35416
+ var glTFResource = context.glTFResource, glTF = context.glTF;
35417
+ var glTFMeshes = glTF.meshes;
35418
+ var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
35419
+ var meshID = glTFNode.mesh, skinID = glTFNode.skin;
35420
+ var glTFMesh = glTFMeshes[meshID];
35421
+ var glTFMeshPrimitives = glTFMesh.primitives;
35422
+ var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
35423
+ for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
34790
35424
  };
34791
35425
  _proto._createAnimator = function _createAnimator(context) {
34792
35426
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -35071,31 +35705,16 @@
35071
35705
  })();
35072
35706
  /**
35073
35707
  * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
35074
- */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
35708
+ */ var GLTFResource = /*#__PURE__*/ function(ReferResource) {
35075
35709
  var GLTFResource = function GLTFResource(engine, url) {
35076
35710
  var _this;
35077
- _this = EngineObject.call(this, engine) || this;
35711
+ _this = ReferResource.call(this, engine) || this;
35078
35712
  _this.url = url;
35079
35713
  return _this;
35080
35714
  };
35081
- _inherits(GLTFResource, EngineObject);
35082
- var _proto = GLTFResource.prototype;
35083
- _proto._onDestroy = function _onDestroy() {
35084
- EngineObject.prototype._onDestroy.call(this);
35085
- this.defaultSceneRoot.destroy();
35086
- this.textures = null;
35087
- this.materials = null;
35088
- this.meshes = null;
35089
- this.skins = null;
35090
- this.animations = null;
35091
- this.entities = null;
35092
- this.cameras = null;
35093
- this.lights = null;
35094
- this.sceneRoots = null;
35095
- this.extensionsData = null;
35096
- };
35715
+ _inherits(GLTFResource, ReferResource);
35097
35716
  return GLTFResource;
35098
- }(EngineObject);
35717
+ }(ReferResource);
35099
35718
  var GLTFLoader = /*#__PURE__*/ function(Loader) {
35100
35719
  var GLTFLoader = function GLTFLoader() {
35101
35720
  return Loader.apply(this, arguments);
@@ -35720,6 +36339,15 @@
35720
36339
  "ktx"
35721
36340
  ])
35722
36341
  ], KTXLoader);
36342
+ function parseProperty(object, key, value) {
36343
+ if (typeof value === "object") {
36344
+ for(var subKey in value){
36345
+ parseProperty(object[key], subKey, value[subKey]);
36346
+ }
36347
+ } else {
36348
+ object[key] = value;
36349
+ }
36350
+ }
35723
36351
  var MaterialLoader = /*#__PURE__*/ function(Loader) {
35724
36352
  var MaterialLoader = function MaterialLoader() {
35725
36353
  return Loader.apply(this, arguments);
@@ -35731,7 +36359,7 @@
35731
36359
  return new AssetPromise(function(resolve, reject) {
35732
36360
  _this.request(item.url, _extends({}, item, {
35733
36361
  type: "json"
35734
- })).then(function(json) {
36362
+ })).then(function(materialSchema) {
35735
36363
  var _loop = function _loop(key) {
35736
36364
  var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
35737
36365
  switch(type){
@@ -35758,27 +36386,8 @@
35758
36386
  }
35759
36387
  };
35760
36388
  var engine = resourceManager.engine;
35761
- var name = json.name, shader = json.shader, shaderData = json.shaderData, macros = json.macros, renderState = json.renderState;
35762
- var material;
35763
- switch(shader){
35764
- case "pbr":
35765
- material = new PBRMaterial(engine);
35766
- break;
35767
- case "pbr-specular":
35768
- material = new PBRSpecularMaterial(engine);
35769
- break;
35770
- case "unlit":
35771
- material = new UnlitMaterial(engine);
35772
- break;
35773
- case "blinn-phong":
35774
- material = new BlinnPhongMaterial(engine);
35775
- break;
35776
- case "bake-pbr":
35777
- // @todo refactor custom shader later
35778
- // @ts-ignore
35779
- material = new PBRBaseMaterial(engine, Shader.find("bake-pbr"));
35780
- break;
35781
- }
36389
+ var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
36390
+ var material = new Material(engine, Shader.find(shader));
35782
36391
  material.name = name;
35783
36392
  var texturePromises = new Array();
35784
36393
  var materialShaderData = material.shaderData;
@@ -35791,9 +36400,7 @@
35791
36400
  materialShaderData.enableMacro(name1, value);
35792
36401
  }
35793
36402
  }
35794
- for(var key1 in renderState){
35795
- material[key1] = renderState[key1];
35796
- }
36403
+ parseProperty(material, "renderState", renderState);
35797
36404
  return Promise.all(texturePromises).then(function() {
35798
36405
  resolve(material);
35799
36406
  });
@@ -36529,6 +37136,11 @@
36529
37136
  exports.AnimationClipDecoder = __decorate([
36530
37137
  decoder("AnimationClip")
36531
37138
  ], exports.AnimationClipDecoder);
37139
+ exports.SpecularMode = void 0;
37140
+ (function(SpecularMode) {
37141
+ SpecularMode["Sky"] = "Sky";
37142
+ SpecularMode["Custom"] = "Custom";
37143
+ })(exports.SpecularMode || (exports.SpecularMode = {}));
36532
37144
  var SceneParserContext = /*#__PURE__*/ function() {
36533
37145
  var SceneParserContext = function SceneParserContext(originalData, scene) {
36534
37146
  this.originalData = originalData;
@@ -36804,7 +37416,7 @@
36804
37416
  var atlasItem = atlasItems[i];
36805
37417
  if (atlasItem.img) {
36806
37418
  chainPromises.push(resourceManager.load({
36807
- url: atlasItem.img,
37419
+ url: Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
36808
37420
  type: exports.AssetType.Texture2D,
36809
37421
  params: {
36810
37422
  format: format,
@@ -37073,47 +37685,63 @@
37073
37685
  // @ts-ignore
37074
37686
  engine.resourceManager.initVirtualResources(data.files);
37075
37687
  return SceneParser.parse(engine, data).then(function(scene) {
37688
+ var promises = [];
37076
37689
  // parse ambient light
37077
37690
  var ambient = data.scene.ambient;
37078
- var ambientLightPromise = Promise.resolve();
37079
- if (ambient.ambientLight) {
37080
- ambientLightPromise = resourceManager // @ts-ignore
37081
- .getResourceByRef(data.scene.ambient.ambientLight).then(function(light) {
37082
- scene.ambientLight = light;
37691
+ var useCustomAmbient = ambient.specularMode === "Custom";
37692
+ if (useCustomAmbient && ambient.customAmbientLight) {
37693
+ // @ts-ignore
37694
+ // prettier-ignore
37695
+ var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
37696
+ scene.ambientLight = ambientLight;
37083
37697
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
37084
37698
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
37699
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
37700
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
37085
37701
  });
37086
- } else {
37087
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
37088
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
37089
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
37702
+ promises.push(customAmbientPromise);
37703
+ } else if (!useCustomAmbient && ambient.ambientLight) {
37704
+ // @ts-ignore
37705
+ // prettier-ignore
37706
+ var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
37707
+ scene.ambientLight = ambientLight;
37708
+ scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
37709
+ scene.ambientLight.specularIntensity = ambient.specularIntensity;
37710
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
37711
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
37712
+ });
37713
+ promises.push(ambientLightPromise);
37090
37714
  }
37091
37715
  var background = data.scene.background;
37092
37716
  scene.background.mode = background.mode;
37093
- var backgroundPromise = Promise.resolve();
37094
37717
  switch(scene.background.mode){
37095
37718
  case exports.BackgroundMode.SolidColor:
37096
37719
  scene.background.solidColor.copyFrom(background.color);
37097
37720
  break;
37098
37721
  case exports.BackgroundMode.Sky:
37099
- if (background.sky) {
37722
+ if (background.skyMesh && background.skyMaterial) {
37723
+ // @ts-ignore
37724
+ var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
37725
+ scene.background.sky.mesh = mesh;
37726
+ });
37100
37727
  // @ts-ignore
37101
- backgroundPromise = resourceManager.getResourceByRef(background.sky).then(function(light) {
37102
- var sky = scene.background.sky;
37103
- var skyMaterial = new SkyBoxMaterial(engine);
37104
- skyMaterial.texture = light.specularTexture;
37105
- skyMaterial.textureDecodeRGBM = true;
37106
- sky.material = skyMaterial;
37107
- sky.mesh = PrimitiveMesh.createCuboid(engine, 1, 1, 1);
37728
+ // prettier-ignore
37729
+ var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
37730
+ scene.background.sky.material = material;
37108
37731
  });
37732
+ promises.push(skyMeshPromise, skyMaterialPromise);
37733
+ } else {
37734
+ Logger.warn("Sky background mode requires skyMesh and skyMaterial");
37109
37735
  }
37110
37736
  break;
37111
37737
  case exports.BackgroundMode.Texture:
37112
37738
  if (background.texture) {
37113
37739
  // @ts-ignore
37114
- backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
37740
+ // prettier-ignore
37741
+ var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
37115
37742
  scene.background.texture = texture;
37116
37743
  });
37744
+ promises.push(backgroundPromise);
37117
37745
  }
37118
37746
  break;
37119
37747
  }
@@ -37125,10 +37753,7 @@
37125
37753
  if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
37126
37754
  if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
37127
37755
  }
37128
- return Promise.all([
37129
- ambientLightPromise,
37130
- backgroundPromise
37131
- ]).then(function() {
37756
+ return Promise.all(promises).then(function() {
37132
37757
  resolve(scene);
37133
37758
  });
37134
37759
  });
@@ -37384,6 +38009,21 @@
37384
38009
  KHR_materials_clearcoat = __decorate([
37385
38010
  registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
37386
38011
  ], KHR_materials_clearcoat);
38012
+ var KHR_materials_ior = /*#__PURE__*/ function(GLTFExtensionParser) {
38013
+ var KHR_materials_ior = function KHR_materials_ior() {
38014
+ return GLTFExtensionParser.apply(this, arguments);
38015
+ };
38016
+ _inherits(KHR_materials_ior, GLTFExtensionParser);
38017
+ var _proto = KHR_materials_ior.prototype;
38018
+ _proto.additiveParse = function additiveParse(context, material, schema) {
38019
+ var _schema_ior = schema.ior, ior = _schema_ior === void 0 ? 1.5 : _schema_ior;
38020
+ material.ior = ior;
38021
+ };
38022
+ return KHR_materials_ior;
38023
+ }(GLTFExtensionParser);
38024
+ KHR_materials_ior = __decorate([
38025
+ registerGLTFExtension("KHR_materials_ior", exports.GLTFExtensionMode.AdditiveParse)
38026
+ ], KHR_materials_ior);
37387
38027
  var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
37388
38028
  var KHR_materials_pbrSpecularGlossiness = function KHR_materials_pbrSpecularGlossiness() {
37389
38029
  return GLTFExtensionParser.apply(this, arguments);
@@ -37516,7 +38156,7 @@
37516
38156
  ], GALACEAN_animation_event);
37517
38157
 
37518
38158
  //@ts-ignore
37519
- var version = "1.0.0-beta.1";
38159
+ var version = "1.0.0-beta.11";
37520
38160
  console.log("Galacean engine version: " + version);
37521
38161
  for(var key in CoreObjects){
37522
38162
  Loader.registerClass(key, CoreObjects[key]);
@@ -37540,6 +38180,7 @@
37540
38180
  exports.BasicRenderPipeline = BasicRenderPipeline;
37541
38181
  exports.BlendShape = BlendShape;
37542
38182
  exports.BlendShapeFrame = BlendShapeFrame;
38183
+ exports.BlendState = BlendState;
37543
38184
  exports.BlinnPhongMaterial = BlinnPhongMaterial;
37544
38185
  exports.BoolUpdateFlag = BoolUpdateFlag;
37545
38186
  exports.BoundingBox = BoundingBox;
@@ -37559,6 +38200,7 @@
37559
38200
  exports.ComponentMap = ComponentMap;
37560
38201
  exports.ContentRestorer = ContentRestorer;
37561
38202
  exports.CubeProbe = CubeProbe;
38203
+ exports.DepthState = DepthState;
37562
38204
  exports.DirectLight = DirectLight;
37563
38205
  exports.DynamicCollider = DynamicCollider;
37564
38206
  exports.Engine = Engine;
@@ -37613,13 +38255,16 @@
37613
38255
  exports.PrimitiveMesh = PrimitiveMesh;
37614
38256
  exports.Probe = Probe;
37615
38257
  exports.Quaternion = Quaternion;
38258
+ exports.RasterState = RasterState;
37616
38259
  exports.Ray = Ray;
37617
38260
  exports.Rect = Rect;
37618
38261
  exports.ReferResource = ReferResource;
37619
38262
  exports.ReflectionParser = ReflectionParser;
37620
38263
  exports.RenderPass = RenderPass;
37621
38264
  exports.RenderQueue = RenderQueue;
38265
+ exports.RenderState = RenderState;
37622
38266
  exports.RenderTarget = RenderTarget;
38267
+ exports.RenderTargetBlendState = RenderTargetBlendState;
37623
38268
  exports.ResourceManager = ResourceManager;
37624
38269
  exports.Scene = Scene;
37625
38270
  exports.SceneManager = SceneManager;
@@ -37648,6 +38293,7 @@
37648
38293
  exports.SpriteRenderer = SpriteRenderer;
37649
38294
  exports.StateMachineScript = StateMachineScript;
37650
38295
  exports.StaticCollider = StaticCollider;
38296
+ exports.StencilState = StencilState;
37651
38297
  exports.SubMesh = SubMesh;
37652
38298
  exports.SubShader = SubShader;
37653
38299
  exports.SystemInfo = SystemInfo;