@galacean/engine-physics-physx 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.
@@ -726,7 +726,9 @@ __decorate$1([
726
726
  */ _proto._addToResourceManager = function _addToResourceManager(path) {
727
727
  this._engine.resourceManager._addAsset(path, this);
728
728
  };
729
- _proto._onDestroy = function _onDestroy() {
729
+ /**
730
+ * @internal
731
+ */ _proto._onDestroy = function _onDestroy() {
730
732
  EngineObject.prototype._onDestroy.call(this);
731
733
  this._engine.resourceManager._deleteReferResource(this);
732
734
  var refCount = this._getReferCount();
@@ -850,7 +852,9 @@ var GraphicsResource = /*#__PURE__*/ function(ReferResource) {
850
852
  };
851
853
  _inherits$2(GraphicsResource, ReferResource);
852
854
  var _proto = GraphicsResource.prototype;
853
- _proto._onDestroy = function _onDestroy() {
855
+ /**
856
+ * @internal
857
+ */ _proto._onDestroy = function _onDestroy() {
854
858
  ReferResource.prototype._onDestroy.call(this);
855
859
  this.engine.resourceManager._deleteGraphicResource(this);
856
860
  };
@@ -927,7 +931,9 @@ var Logger = {
927
931
  platformTexture.depthCompareFunction = this._depthCompareFunction;
928
932
  platformTexture.setUseDepthCompareMode(this._useDepthCompareMode);
929
933
  };
930
- _proto._onDestroy = function _onDestroy() {
934
+ /**
935
+ * @internal
936
+ */ _proto._onDestroy = function _onDestroy() {
931
937
  GraphicsResource.prototype._onDestroy.call(this);
932
938
  this._platformTexture.destroy();
933
939
  this._platformTexture = null;
@@ -1075,9 +1081,11 @@ var Logger = {
1075
1081
  renderTexture
1076
1082
  ];
1077
1083
  for(var i = 0, n = colorTextures.length; i < n; i++){
1078
- if (colorTextures[i]._isDepthTexture) {
1084
+ var colorTexture = colorTextures[i];
1085
+ if (colorTexture._isDepthTexture) {
1079
1086
  throw "Render texture can't use depth format.";
1080
1087
  }
1088
+ colorTexture._addReferCount(1);
1081
1089
  }
1082
1090
  _this._colorTextures = colorTextures;
1083
1091
  } else {
@@ -1088,6 +1096,7 @@ var Logger = {
1088
1096
  throw "Depth texture must use depth format.";
1089
1097
  }
1090
1098
  _this._depthTexture = depth;
1099
+ _this._depthTexture._addReferCount(1);
1091
1100
  }
1092
1101
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
1093
1102
  return _this;
@@ -1114,10 +1123,18 @@ var Logger = {
1114
1123
  this._depthTexture && this._depthTexture.generateMipmaps();
1115
1124
  }
1116
1125
  };
1117
- _proto._onDestroy = function _onDestroy() {
1126
+ /**
1127
+ * @internal
1128
+ */ _proto._onDestroy = function _onDestroy() {
1129
+ var _this__depthTexture;
1118
1130
  GraphicsResource.prototype._onDestroy.call(this);
1119
1131
  this._platformRenderTarget.destroy();
1120
- this._colorTextures.length = 0;
1132
+ var _this = this, colorTextures = _this._colorTextures;
1133
+ for(var i = 0, n = colorTextures.length; i < n; i++){
1134
+ colorTextures[i]._addReferCount(-1);
1135
+ }
1136
+ colorTextures.length = 0;
1137
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addReferCount(-1);
1121
1138
  this._depthTexture = null;
1122
1139
  this._depth = null;
1123
1140
  };
@@ -1488,7 +1505,9 @@ var Logger = {
1488
1505
  _proto.getCharInfo = function getCharInfo(char) {
1489
1506
  return this._charInfoMap[char.charCodeAt(0)];
1490
1507
  };
1491
- _proto._onDestroy = function _onDestroy() {
1508
+ /**
1509
+ * @internal
1510
+ */ _proto._onDestroy = function _onDestroy() {
1492
1511
  ReferResource.prototype._onDestroy.call(this);
1493
1512
  this.texture.destroy();
1494
1513
  this.texture = null;
@@ -1991,6 +2010,7 @@ var Logger = {
1991
2010
  var fontAtlas = new FontAtlas(engine);
1992
2011
  var texture = new Texture2D(engine, 256, 256);
1993
2012
  fontAtlas.texture = texture;
2013
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
1994
2014
  this._fontAtlases.push(fontAtlas);
1995
2015
  var nativeFontString = this.nativeFontString;
1996
2016
  engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
@@ -2046,7 +2066,9 @@ var Logger = {
2046
2066
  subFontMap[key] = subFont;
2047
2067
  return subFont;
2048
2068
  };
2049
- _proto._onDestroy = function _onDestroy() {
2069
+ /**
2070
+ * @internal
2071
+ */ _proto._onDestroy = function _onDestroy() {
2050
2072
  ReferResource.prototype._onDestroy.call(this);
2051
2073
  var subFontMap = this._subFontMap;
2052
2074
  for(var k in subFontMap){
@@ -2287,6 +2309,29 @@ var /** @internal */ PromiseState;
2287
2309
  * @remarks The release principle is that it is not referenced by the components, including direct and indirect reference.
2288
2310
  */ _proto.gc = function gc() {
2289
2311
  this._gc(false);
2312
+ var engine = this.engine;
2313
+ engine._renderElementPool.garbageCollection();
2314
+ engine._meshRenderDataPool.garbageCollection();
2315
+ engine._spriteRenderDataPool.garbageCollection();
2316
+ engine._spriteMaskRenderDataPool.garbageCollection();
2317
+ engine._textRenderDataPool.garbageCollection();
2318
+ var _componentsManager = engine._componentsManager, _lightManager = engine._lightManager;
2319
+ _componentsManager._renderers.garbageCollection();
2320
+ // @ts-ignore
2321
+ _componentsManager._onStartScripts.garbageCollection();
2322
+ // @ts-ignore
2323
+ _componentsManager._onUpdateScripts.garbageCollection();
2324
+ // @ts-ignore
2325
+ _componentsManager._onLateUpdateScripts.garbageCollection();
2326
+ // @ts-ignore
2327
+ _componentsManager._onPhysicsUpdateScripts.garbageCollection();
2328
+ // @ts-ignore
2329
+ _componentsManager._onUpdateAnimations.garbageCollection();
2330
+ // @ts-ignore
2331
+ _componentsManager._onUpdateRenderers.garbageCollection();
2332
+ _lightManager._spotLights.garbageCollection();
2333
+ _lightManager._pointLights.garbageCollection();
2334
+ _lightManager._directLights.garbageCollection();
2290
2335
  };
2291
2336
  /**
2292
2337
  * Add content restorer.
@@ -3253,7 +3298,9 @@ exports.GLCapabilityType = void 0;
3253
3298
  }
3254
3299
  }
3255
3300
  };
3256
- _proto._onDestroy = function _onDestroy() {
3301
+ /**
3302
+ * @internal
3303
+ */ _proto._onDestroy = function _onDestroy() {
3257
3304
  EngineObject.prototype._onDestroy.call(this);
3258
3305
  this._entity._removeComponent(this);
3259
3306
  if (this._entity.isActiveInHierarchy) {
@@ -4701,6 +4748,11 @@ var ComponentCloner = /*#__PURE__*/ function() {
4701
4748
  * @returns Cloned entity
4702
4749
  */ _proto.clone = function clone() {
4703
4750
  var cloneEntity = new Entity(this._engine, this.name);
4751
+ var _this = this, hookResource = _this._hookResource;
4752
+ if (hookResource) {
4753
+ cloneEntity._hookResource = hookResource;
4754
+ hookResource._addReferCount(1);
4755
+ }
4704
4756
  cloneEntity._isActive = this._isActive;
4705
4757
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
4706
4758
  var children = this._children;
@@ -4725,6 +4777,10 @@ var ComponentCloner = /*#__PURE__*/ function() {
4725
4777
  return;
4726
4778
  }
4727
4779
  EngineObject.prototype.destroy.call(this);
4780
+ if (this._hookResource) {
4781
+ this._hookResource._addReferCount(-1);
4782
+ this._hookResource = null;
4783
+ }
4728
4784
  var components = this._components;
4729
4785
  for(var i = components.length - 1; i >= 0; i--){
4730
4786
  components[i].destroy();
@@ -5248,14 +5304,14 @@ SystemInfo._initialize();
5248
5304
  Keys[Keys[/** Tab or ⇥. */ "Tab"] = 63] = "Tab";
5249
5305
  Keys[Keys[/** Japanese: 変換 (henkan). */ "Convert"] = 64] = "Convert";
5250
5306
  Keys[Keys[/** Japanese: カタカナ/ひらがな/ローマ字 (katakana/hiragana/romaji). */ "KanaMode"] = 65] = "KanaMode";
5251
- Keys[Keys[/**
5252
- * Korean: HangulMode 한/영 (han/yeong).
5253
- * Japanese (Mac keyboard): かな (kana).
5254
- * */ "Lang1"] = 66] = "Lang1";
5255
5307
  Keys[Keys[/**
5256
- * Korean: Hanja 한자 (hanja).
5257
- * Japanese (Mac keyboard): 英数 (eisu).
5258
- */ "Lang2"] = 67] = "Lang2";
5308
+ * Korean: HangulMode 한/영 (han/yeong).
5309
+ * Japanese (Mac keyboard): かな (kana).
5310
+ * */ "Lang1"] = 66] = "Lang1";
5311
+ Keys[Keys[/**
5312
+ * Korean: Hanja 한자 (hanja).
5313
+ * Japanese (Mac keyboard): 英数 (eisu).
5314
+ */ "Lang2"] = 67] = "Lang2";
5259
5315
  Keys[Keys[/** Japanese (word-processing keyboard): Katakana. */ "Lang3"] = 68] = "Lang3";
5260
5316
  Keys[Keys[/** Japanese (word-processing keyboard): Hiragana. */ "Lang4"] = 69] = "Lang4";
5261
5317
  Keys[Keys[/** Japanese (word-processing keyboard): Zenkaku/Hankaku. */ "Lang5"] = 70] = "Lang5";
@@ -5272,46 +5328,46 @@ SystemInfo._initialize();
5272
5328
  Keys[Keys[/** → */ "ArrowRight"] = 81] = "ArrowRight";
5273
5329
  Keys[Keys[/** ↑ */ "ArrowUp"] = 82] = "ArrowUp";
5274
5330
  Keys[Keys[/** On the Mac, the "NumLock" code should be used for the numpad Clear key. */ "NumLock"] = 83] = "NumLock";
5275
- Keys[Keys[/**
5276
- * 0 Ins on a keyboard.
5277
- * 0 on a phone or remote control.
5278
- * */ "Numpad0"] = 84] = "Numpad0";
5279
5331
  Keys[Keys[/**
5280
- * 1 End on a keyboard.
5281
- * 1 or 1 QZ on a phone or remote control.
5282
- */ "Numpad1"] = 85] = "Numpad1";
5332
+ * 0 Ins on a keyboard.
5333
+ * 0 on a phone or remote control.
5334
+ * */ "Numpad0"] = 84] = "Numpad0";
5335
+ Keys[Keys[/**
5336
+ * 1 End on a keyboard.
5337
+ * 1 or 1 QZ on a phone or remote control.
5338
+ */ "Numpad1"] = 85] = "Numpad1";
5283
5339
  Keys[Keys[/**
5284
- * 2 ↓ on a keyboard.
5285
- * 2 ABC on a phone or remote control.
5286
- */ "Numpad2"] = 86] = "Numpad2";
5340
+ * 2 ↓ on a keyboard.
5341
+ * 2 ABC on a phone or remote control.
5342
+ */ "Numpad2"] = 86] = "Numpad2";
5287
5343
  Keys[Keys[/**
5288
- * 3 PgDn on a keyboard.
5289
- * 3 DEF on a phone or remote control.
5290
- */ "Numpad3"] = 87] = "Numpad3";
5344
+ * 3 PgDn on a keyboard.
5345
+ * 3 DEF on a phone or remote control.
5346
+ */ "Numpad3"] = 87] = "Numpad3";
5291
5347
  Keys[Keys[/**
5292
- * 4 ← on a keyboard.
5293
- * 4 GHI on a phone or remote control.
5294
- */ "Numpad4"] = 88] = "Numpad4";
5348
+ * 4 ← on a keyboard.
5349
+ * 4 GHI on a phone or remote control.
5350
+ */ "Numpad4"] = 88] = "Numpad4";
5295
5351
  Keys[Keys[/**
5296
- * 5 on a keyboard.
5297
- * 5 JKL on a phone or remote control.
5298
- */ "Numpad5"] = 89] = "Numpad5";
5352
+ * 5 on a keyboard.
5353
+ * 5 JKL on a phone or remote control.
5354
+ */ "Numpad5"] = 89] = "Numpad5";
5299
5355
  Keys[Keys[/**
5300
- * 6 → on a keyboard.
5301
- * 6 MNO on a phone or remote control.
5302
- */ "Numpad6"] = 90] = "Numpad6";
5356
+ * 6 → on a keyboard.
5357
+ * 6 MNO on a phone or remote control.
5358
+ */ "Numpad6"] = 90] = "Numpad6";
5303
5359
  Keys[Keys[/**
5304
- * 7 Home on a keyboard.
5305
- * 7 PQRS or 7 PRS on a phone or remote control.
5306
- */ "Numpad7"] = 91] = "Numpad7";
5360
+ * 7 Home on a keyboard.
5361
+ * 7 PQRS or 7 PRS on a phone or remote control.
5362
+ */ "Numpad7"] = 91] = "Numpad7";
5307
5363
  Keys[Keys[/**
5308
- * 8 ↑ on a keyboard.
5309
- * 8 TUV on a phone or remote control.
5310
- */ "Numpad8"] = 92] = "Numpad8";
5364
+ * 8 ↑ on a keyboard.
5365
+ * 8 TUV on a phone or remote control.
5366
+ */ "Numpad8"] = 92] = "Numpad8";
5311
5367
  Keys[Keys[/**
5312
- * 9 PgUp on a keyboard.
5313
- * 9 WXYZ or 9 WXY on a phone or remote control.
5314
- */ "Numpad9"] = 93] = "Numpad9";
5368
+ * 9 PgUp on a keyboard.
5369
+ * 9 WXYZ or 9 WXY on a phone or remote control.
5370
+ */ "Numpad9"] = 93] = "Numpad9";
5315
5371
  Keys[Keys[/** + */ "NumpadAdd"] = 94] = "NumpadAdd";
5316
5372
  Keys[Keys[/** Found on the Microsoft Natural Keyboard. */ "NumpadBackspace"] = 95] = "NumpadBackspace";
5317
5373
  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";
@@ -5327,16 +5383,16 @@ SystemInfo._initialize();
5327
5383
  Keys[Keys[/** MR Replace the current entry with the value stored in memory. */ "NumpadMemoryRecall"] = 106] = "NumpadMemoryRecall";
5328
5384
  Keys[Keys[/** MS Replace the value stored in memory with the current entry. */ "NumpadMemoryStore"] = 107] = "NumpadMemoryStore";
5329
5385
  Keys[Keys[/** M- Subtract current entry from the value stored in memory. */ "NumpadMemorySubtract"] = 108] = "NumpadMemorySubtract";
5330
- Keys[Keys[/**
5331
- * * on a keyboard. For use with numpads that provide mathematical operations (+, -, * and /).
5332
- * Use "NumpadStar" for the * key on phones and remote controls.
5333
- */ "NumpadMultiply"] = 109] = "NumpadMultiply";
5386
+ Keys[Keys[/**
5387
+ * * on a keyboard. For use with numpads that provide mathematical operations (+, -, * and /).
5388
+ * Use "NumpadStar" for the * key on phones and remote controls.
5389
+ */ "NumpadMultiply"] = 109] = "NumpadMultiply";
5334
5390
  Keys[Keys[/** ( Found on the Microsoft Natural Keyboard. */ "NumpadParenLeft"] = 110] = "NumpadParenLeft";
5335
5391
  Keys[Keys[/** ) Found on the Microsoft Natural Keyboard. */ "NumpadParenRight"] = 111] = "NumpadParenRight";
5336
5392
  Keys[Keys[/**
5337
- * * on a phone or remote control device. This key is typically found below the 7 key and to the left of the 0 key.
5338
- * Use "NumpadMultiply" for the * key on numeric keypads.
5339
- */ "NumpadStar"] = 112] = "NumpadStar";
5393
+ * * on a phone or remote control device. This key is typically found below the 7 key and to the left of the 0 key.
5394
+ * Use "NumpadMultiply" for the * key on numeric keypads.
5395
+ */ "NumpadStar"] = 112] = "NumpadStar";
5340
5396
  Keys[Keys[/** - */ "NumpadSubtract"] = 113] = "NumpadSubtract";
5341
5397
  Keys[Keys[/** Esc or ⎋. */ "Escape"] = 114] = "Escape";
5342
5398
  Keys[Keys[/** F1 */ "F1"] = 115] = "F1";
@@ -6002,7 +6058,9 @@ exports.Collider = /*#__PURE__*/ function(Component) {
6002
6058
  */ _proto._onDisable = function _onDisable() {
6003
6059
  this.engine.physicsManager._removeCollider(this);
6004
6060
  };
6005
- _proto._onDestroy = function _onDestroy() {
6061
+ /**
6062
+ * @internal
6063
+ */ _proto._onDestroy = function _onDestroy() {
6006
6064
  Component.prototype._onDestroy.call(this);
6007
6065
  this.clearShapes();
6008
6066
  this._nativeCollider.destroy();
@@ -7826,7 +7884,10 @@ exports.DynamicColliderConstraints = void 0;
7826
7884
  };
7827
7885
  _inherits$2(Light, Component);
7828
7886
  var _proto = Light.prototype;
7829
- _proto._getLightColor = function _getLightColor() {
7887
+ /**
7888
+ * Light Color, include intensity.
7889
+ * @internal
7890
+ */ _proto._getLightIntensityColor = function _getLightIntensityColor() {
7830
7891
  this._lightColor.r = this.color.r * this.intensity;
7831
7892
  this._lightColor.g = this.color.g * this.intensity;
7832
7893
  this._lightColor.b = this.color.b * this.intensity;
@@ -7895,15 +7956,21 @@ __decorate$1([
7895
7956
  var cullingMaskStart = lightIndex * 2;
7896
7957
  var colorStart = lightIndex * 3;
7897
7958
  var directionStart = lightIndex * 3;
7898
- var lightColor = this._getLightColor();
7959
+ var lightColor = this._getLightIntensityColor();
7899
7960
  var direction = this.direction;
7900
7961
  var data = DirectLight._combinedData;
7901
7962
  var cullingMask = this.cullingMask;
7902
7963
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
7903
7964
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
7904
- data.color[colorStart] = lightColor.r;
7905
- data.color[colorStart + 1] = lightColor.g;
7906
- data.color[colorStart + 2] = lightColor.b;
7965
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
7966
+ data.color[colorStart] = miniprogram$7.Color.gammaToLinearSpace(lightColor.r);
7967
+ data.color[colorStart + 1] = miniprogram$7.Color.gammaToLinearSpace(lightColor.g);
7968
+ data.color[colorStart + 2] = miniprogram$7.Color.gammaToLinearSpace(lightColor.b);
7969
+ } else {
7970
+ data.color[colorStart] = lightColor.r;
7971
+ data.color[colorStart + 1] = lightColor.g;
7972
+ data.color[colorStart + 2] = lightColor.b;
7973
+ }
7907
7974
  data.direction[directionStart] = direction.x;
7908
7975
  data.direction[directionStart + 1] = direction.y;
7909
7976
  data.direction[directionStart + 2] = direction.z;
@@ -7991,15 +8058,21 @@ __decorate$1([
7991
8058
  var colorStart = lightIndex * 3;
7992
8059
  var positionStart = lightIndex * 3;
7993
8060
  var distanceStart = lightIndex;
7994
- var lightColor = this._getLightColor();
8061
+ var lightColor = this._getLightIntensityColor();
7995
8062
  var lightPosition = this.position;
7996
8063
  var data = PointLight._combinedData;
7997
8064
  var cullingMask = this.cullingMask;
7998
8065
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
7999
8066
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
8000
- data.color[colorStart] = lightColor.r;
8001
- data.color[colorStart + 1] = lightColor.g;
8002
- data.color[colorStart + 2] = lightColor.b;
8067
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
8068
+ data.color[colorStart] = miniprogram$7.Color.gammaToLinearSpace(lightColor.r);
8069
+ data.color[colorStart + 1] = miniprogram$7.Color.gammaToLinearSpace(lightColor.g);
8070
+ data.color[colorStart + 2] = miniprogram$7.Color.gammaToLinearSpace(lightColor.b);
8071
+ } else {
8072
+ data.color[colorStart] = lightColor.r;
8073
+ data.color[colorStart + 1] = lightColor.g;
8074
+ data.color[colorStart + 2] = lightColor.b;
8075
+ }
8003
8076
  data.position[positionStart] = lightPosition.x;
8004
8077
  data.position[positionStart + 1] = lightPosition.y;
8005
8078
  data.position[positionStart + 2] = lightPosition.z;
@@ -8091,16 +8164,22 @@ __decorate$1([
8091
8164
  var distanceStart = lightIndex;
8092
8165
  var penumbraCosStart = lightIndex;
8093
8166
  var angleCosStart = lightIndex;
8094
- var color = this._getLightColor();
8167
+ var lightColor = this._getLightIntensityColor();
8095
8168
  var position = this.position;
8096
8169
  var direction = this.direction;
8097
8170
  var data = SpotLight._combinedData;
8098
8171
  var cullingMask = this.cullingMask;
8099
8172
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
8100
8173
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
8101
- data.color[colorStart] = color.r;
8102
- data.color[colorStart + 1] = color.g;
8103
- data.color[colorStart + 2] = color.b;
8174
+ if (this.engine.settings.colorSpace === exports.ColorSpace.Linear) {
8175
+ data.color[colorStart] = miniprogram$7.Color.gammaToLinearSpace(lightColor.r);
8176
+ data.color[colorStart + 1] = miniprogram$7.Color.gammaToLinearSpace(lightColor.g);
8177
+ data.color[colorStart + 2] = miniprogram$7.Color.gammaToLinearSpace(lightColor.b);
8178
+ } else {
8179
+ data.color[colorStart] = lightColor.r;
8180
+ data.color[colorStart + 1] = lightColor.g;
8181
+ data.color[colorStart + 2] = lightColor.b;
8182
+ }
8104
8183
  data.position[positionStart] = position.x;
8105
8184
  data.position[positionStart + 1] = position.y;
8106
8185
  data.position[positionStart + 2] = position.z;
@@ -8737,6 +8816,7 @@ __decorate$1([
8737
8816
  _proto.cloneTo = function cloneTo(target) {
8738
8817
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8739
8818
  Object.assign(target._macroMap, this._macroMap);
8819
+ var referCount = target._getReferCount();
8740
8820
  var propertyValueMap = this._propertyValueMap;
8741
8821
  var targetPropertyValueMap = target._propertyValueMap;
8742
8822
  var keys = Object.keys(propertyValueMap);
@@ -8748,6 +8828,7 @@ __decorate$1([
8748
8828
  targetPropertyValueMap[k] = property;
8749
8829
  } else if (_instanceof1$2(property, Texture)) {
8750
8830
  targetPropertyValueMap[k] = property;
8831
+ referCount > 0 && property._addReferCount(referCount);
8751
8832
  } else if (_instanceof1$2(property, Array) || _instanceof1$2(property, Float32Array) || _instanceof1$2(property, Int32Array)) {
8752
8833
  targetPropertyValueMap[k] = property.slice();
8753
8834
  } else {
@@ -9290,9 +9371,9 @@ __decorate$1([
9290
9371
  var Material = function Material(engine, shader) {
9291
9372
  var _this;
9292
9373
  _this = ReferResource.call(this, engine) || this;
9293
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Material);
9294
9374
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
9295
9375
  ;
9376
+ _this._shaderData = new ShaderData(ShaderDataGroup.Material);
9296
9377
  _this.shader = shader;
9297
9378
  return _this;
9298
9379
  };
@@ -9317,7 +9398,23 @@ __decorate$1([
9317
9398
  ReferResource.prototype._addReferCount.call(this, value);
9318
9399
  this.shaderData._addReferCount(value);
9319
9400
  };
9401
+ /**
9402
+ * @override
9403
+ */ _proto._onDestroy = function _onDestroy() {
9404
+ this._shader = null;
9405
+ this._shaderData = null;
9406
+ this._renderStates.length = 0;
9407
+ this._renderStates = null;
9408
+ };
9320
9409
  _create_class$2(Material, [
9410
+ {
9411
+ key: "shaderData",
9412
+ get: /**
9413
+ * Shader data.
9414
+ */ function get() {
9415
+ return this._shaderData;
9416
+ }
9417
+ },
9321
9418
  {
9322
9419
  key: "shader",
9323
9420
  get: /**
@@ -9389,6 +9486,12 @@ __decorate$1([
9389
9486
  */ _proto.resetPool = function resetPool() {
9390
9487
  this._elementPoolIndex = 0;
9391
9488
  };
9489
+ _proto.garbageCollection = function garbageCollection() {
9490
+ var _this = this, pool = _this._elementPool;
9491
+ for(var i = pool.length - 1; i >= 0; i--){
9492
+ pool[i].dispose && pool[i].dispose();
9493
+ }
9494
+ };
9392
9495
  return ClassPool;
9393
9496
  }();
9394
9497
  var RenderData = function RenderData() {};
@@ -9406,6 +9509,9 @@ var RenderData = function RenderData() {};
9406
9509
  this.mesh = mesh;
9407
9510
  this.subMesh = subMesh;
9408
9511
  };
9512
+ _proto.dispose = function dispose() {
9513
+ this.component = this.material = this.mesh = this.subMesh = null;
9514
+ };
9409
9515
  return MeshRenderData;
9410
9516
  }(RenderData);
9411
9517
  /**
@@ -9427,9 +9533,9 @@ function _extends$2() {
9427
9533
  }
9428
9534
  var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // eslint-disable-line
9429
9535
  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
9430
- 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
9536
+ 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
9431
9537
  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
9432
- var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
9538
+ var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
9433
9539
  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
9434
9540
  var FogVertexDeclaration = "#define GLSLIFY 1\n#if SCENE_FOG_MODE != 0\nvarying vec3 v_positionVS;\n#endif\n"; // eslint-disable-line
9435
9541
  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
@@ -9439,7 +9545,7 @@ var begin_normal_vert = "#define GLSLIFY 1\n#ifndef MATERIAL_OMIT_NORMAL\n#ifdef
9439
9545
  var begin_position_vert = "#define GLSLIFY 1\nvec4 position=vec4(POSITION,1.0);"; // eslint-disable-line
9440
9546
  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
9441
9547
  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
9442
- var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
9548
+ var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
9443
9549
  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
9444
9550
  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
9445
9551
  var position_vert = "#define GLSLIFY 1\ngl_Position=renderer_MVPMat*position;"; // eslint-disable-line
@@ -9449,9 +9555,9 @@ var worldpos_vert = "#define GLSLIFY 1\n#ifdef MATERIAL_NEED_WORLD_POS\nvec4 tem
9449
9555
  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
9450
9556
  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
9451
9557
  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
9452
- 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
9558
+ 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
9453
9559
  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
9454
- 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
9560
+ 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
9455
9561
  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
9456
9562
  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
9457
9563
  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
@@ -9468,12 +9574,12 @@ var noise_simplex_2D = "#define GLSLIFY 1\nfloat simplex(vec2 v){const vec4 C=ve
9468
9574
  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
9469
9575
  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
9470
9576
  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
9471
- 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
9472
- 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
9577
+ 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
9578
+ 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
9473
9579
  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
9474
9580
  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
9475
9581
  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
9476
- 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
9582
+ 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
9477
9583
  var PBRShaderLib = {
9478
9584
  pbr_frag_define: pbr_frag_define,
9479
9585
  pbr_helper: pbr_helper,
@@ -9494,7 +9600,7 @@ var ShadowLib = {
9494
9600
  ShadowVertexDeclaration: ShadowVertexDeclaration,
9495
9601
  ShadowVertex: ShadowVertex
9496
9602
  };
9497
- 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
9603
+ 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
9498
9604
  var ShaderLib = _extends$2({
9499
9605
  common: common,
9500
9606
  common_vert: common_vert,
@@ -10478,6 +10584,9 @@ var RenderElement = /*#__PURE__*/ function() {
10478
10584
  this.shaderPass = shaderPass;
10479
10585
  this.renderState = renderState;
10480
10586
  };
10587
+ _proto.dispose = function dispose() {
10588
+ this.data = this.shaderPass = this.renderState = null;
10589
+ };
10481
10590
  return RenderElement;
10482
10591
  }();
10483
10592
  /**
@@ -10494,7 +10603,6 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10494
10603
  var Renderer1 = function Renderer1(entity) {
10495
10604
  var _this;
10496
10605
  _this = Component.call(this, entity) || this;
10497
- /** ShaderData related to renderer. */ _this.shaderData = new ShaderData(ShaderDataGroup.Renderer);
10498
10606
  /** @internal */ _this._onUpdateIndex = -1;
10499
10607
  /** @internal */ _this._rendererIndex = -1;
10500
10608
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
@@ -10502,6 +10610,7 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10502
10610
  _this._overrideUpdate = false;
10503
10611
  _this._materials = [];
10504
10612
  _this._dirtyUpdateFlag = 0;
10613
+ _this._shaderData = new ShaderData(ShaderDataGroup.Renderer);
10505
10614
  _this._mvMatrix = new miniprogram$7.Matrix();
10506
10615
  _this._mvpMatrix = new miniprogram$7.Matrix();
10507
10616
  _this._mvInvMatrix = new miniprogram$7.Matrix();
@@ -10631,6 +10740,14 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10631
10740
  };
10632
10741
  /**
10633
10742
  * @internal
10743
+ */ _proto._cloneTo = function _cloneTo(target) {
10744
+ var materials = this._materials;
10745
+ for(var i = 0, n = materials.length; i < n; i++){
10746
+ target._setMaterial(i, materials[i]);
10747
+ }
10748
+ };
10749
+ /**
10750
+ * @internal
10634
10751
  */ _proto._onDestroy = function _onDestroy() {
10635
10752
  Component.prototype._onDestroy.call(this);
10636
10753
  this.entity.transform._updateFlagManager.removeListener(this._onTransformChanged);
@@ -10640,15 +10757,30 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10640
10757
  var _materials_i;
10641
10758
  (_materials_i = materials[i]) == null ? void 0 : _materials_i._addReferCount(-1);
10642
10759
  }
10760
+ this._entity = null;
10761
+ this._globalShaderMacro = null;
10762
+ this._bounds = null;
10763
+ this._materials = null;
10764
+ this._shaderData = null;
10765
+ this._mvMatrix = null;
10766
+ this._mvpMatrix = null;
10767
+ this._mvInvMatrix = null;
10768
+ this._normalMatrix = null;
10769
+ this._materialsInstanced = null;
10770
+ this._rendererLayer = null;
10643
10771
  };
10644
- _proto._updateShaderData = function _updateShaderData(context) {
10772
+ /**
10773
+ * @internal
10774
+ */ _proto._updateShaderData = function _updateShaderData(context) {
10645
10775
  var entity = this.entity;
10646
10776
  var worldMatrix = entity.transform.worldMatrix;
10647
10777
  this._updateTransformShaderData(context, worldMatrix);
10648
10778
  var layer = entity.layer;
10649
10779
  this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
10650
10780
  };
10651
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
10781
+ /**
10782
+ * @internal
10783
+ */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
10652
10784
  var shaderData = this.shaderData;
10653
10785
  var virtualCamera = context.virtualCamera;
10654
10786
  var mvMatrix = this._mvMatrix;
@@ -10667,14 +10799,22 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10667
10799
  shaderData.setMatrix(exports.Renderer._mvInvMatrixProperty, mvInvMatrix);
10668
10800
  shaderData.setMatrix(exports.Renderer._normalMatrixProperty, normalMatrix);
10669
10801
  };
10670
- _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
10802
+ /**
10803
+ * @internal
10804
+ */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
10671
10805
  this.entity.transform._updateFlagManager.addListener(this._onTransformChanged);
10672
10806
  };
10673
- _proto._updateBounds = function _updateBounds(worldBounds) {};
10674
- _proto._render = function _render(context) {
10807
+ /**
10808
+ * @internal
10809
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {};
10810
+ /**
10811
+ * @internal
10812
+ */ _proto._render = function _render(context) {
10675
10813
  throw "not implement";
10676
10814
  };
10677
- _proto._createInstanceMaterial = function _createInstanceMaterial(material, index) {
10815
+ /**
10816
+ * @internal
10817
+ */ _proto._createInstanceMaterial = function _createInstanceMaterial(material, index) {
10678
10818
  var insMaterial = material.clone();
10679
10819
  insMaterial.name = insMaterial.name + "(Instance)";
10680
10820
  material._addReferCount(-1);
@@ -10697,10 +10837,20 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10697
10837
  materials[index] = material;
10698
10838
  }
10699
10839
  };
10700
- _proto._onTransformChanged = function _onTransformChanged(type) {
10840
+ /**
10841
+ * @internal
10842
+ */ _proto._onTransformChanged = function _onTransformChanged(type) {
10701
10843
  this._dirtyUpdateFlag |= 0x1;
10702
10844
  };
10703
10845
  _create_class$2(Renderer1, [
10846
+ {
10847
+ key: "shaderData",
10848
+ get: /**
10849
+ * ShaderData related to renderer.
10850
+ */ function get() {
10851
+ return this._shaderData;
10852
+ }
10853
+ },
10704
10854
  {
10705
10855
  key: "isCulled",
10706
10856
  get: /**
@@ -10785,9 +10935,6 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10785
10935
  }(), function() {
10786
10936
  _Renderer._rendererLayerProperty = ShaderProperty.getByName("renderer_Layer");
10787
10937
  }(), _Renderer);
10788
- __decorate$1([
10789
- deepClone
10790
- ], exports.Renderer.prototype, "shaderData", void 0);
10791
10938
  __decorate$1([
10792
10939
  ignoreClone
10793
10940
  ], exports.Renderer.prototype, "_distanceForSort", void 0);
@@ -10810,11 +10957,14 @@ __decorate$1([
10810
10957
  ignoreClone
10811
10958
  ], exports.Renderer.prototype, "_overrideUpdate", void 0);
10812
10959
  __decorate$1([
10813
- shallowClone
10960
+ ignoreClone
10814
10961
  ], exports.Renderer.prototype, "_materials", void 0);
10815
10962
  __decorate$1([
10816
10963
  ignoreClone
10817
10964
  ], exports.Renderer.prototype, "_dirtyUpdateFlag", void 0);
10965
+ __decorate$1([
10966
+ deepClone
10967
+ ], exports.Renderer.prototype, "_shaderData", void 0);
10818
10968
  __decorate$1([
10819
10969
  ignoreClone
10820
10970
  ], exports.Renderer.prototype, "_mvMatrix", void 0);
@@ -10997,8 +11147,10 @@ SimpleSpriteAssembler = __decorate$1([
10997
11147
  _this = Renderer.call(this, entity) || this;
10998
11148
  /** The mask layers the sprite mask influence to. */ _this.influenceLayers = exports.SpriteMaskLayer.Everything;
10999
11149
  _this._sprite = null;
11000
- _this._width = undefined;
11001
- _this._height = undefined;
11150
+ _this._automaticWidth = 0;
11151
+ _this._automaticHeight = 0;
11152
+ _this._customWidth = undefined;
11153
+ _this._customHeight = undefined;
11002
11154
  _this._flipX = false;
11003
11155
  _this._flipY = false;
11004
11156
  _this._alphaCutoff = 0.5;
@@ -11013,30 +11165,33 @@ SimpleSpriteAssembler = __decorate$1([
11013
11165
  /**
11014
11166
  * @internal
11015
11167
  */ _proto._cloneTo = function _cloneTo(target) {
11168
+ Renderer.prototype._cloneTo.call(this, target);
11016
11169
  target.sprite = this._sprite;
11017
11170
  };
11018
- _proto._updateBounds = function _updateBounds(worldBounds) {
11019
- var _this_sprite;
11020
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
11171
+ /**
11172
+ * @internal
11173
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
11174
+ if (this.sprite) {
11175
+ SimpleSpriteAssembler.updatePositions(this);
11176
+ } else {
11021
11177
  worldBounds.min.set(0, 0, 0);
11022
11178
  worldBounds.max.set(0, 0, 0);
11023
- } else {
11024
- SimpleSpriteAssembler.updatePositions(this);
11025
11179
  }
11026
11180
  };
11027
11181
  /**
11182
+ * @internal
11028
11183
  * @inheritdoc
11029
11184
  */ _proto._render = function _render(context) {
11030
11185
  var _this_sprite;
11031
11186
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
11032
11187
  return;
11033
11188
  }
11034
- // Update position.
11189
+ // Update position
11035
11190
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
11036
11191
  SimpleSpriteAssembler.updatePositions(this);
11037
11192
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
11038
11193
  }
11039
- // Update uv.
11194
+ // Update uv
11040
11195
  if (this._dirtyUpdateFlag & 0x2) {
11041
11196
  SimpleSpriteAssembler.updateUVs(this);
11042
11197
  this._dirtyUpdateFlag &= ~0x2;
@@ -11050,19 +11205,40 @@ SimpleSpriteAssembler = __decorate$1([
11050
11205
  this._maskElement = renderElement;
11051
11206
  };
11052
11207
  /**
11208
+ * @internal
11053
11209
  * @inheritdoc
11054
11210
  */ _proto._onDestroy = function _onDestroy() {
11055
- var _this__sprite;
11056
11211
  Renderer.prototype._onDestroy.call(this);
11057
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
11212
+ var sprite = this._sprite;
11213
+ if (sprite) {
11214
+ sprite._addReferCount(-1);
11215
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
11216
+ }
11217
+ this._entity = null;
11058
11218
  this._sprite = null;
11059
11219
  this._verticesData = null;
11060
11220
  };
11221
+ _proto._calDefaultSize = function _calDefaultSize() {
11222
+ var sprite = this._sprite;
11223
+ if (sprite) {
11224
+ this._automaticWidth = sprite.width;
11225
+ this._automaticHeight = sprite.height;
11226
+ } else {
11227
+ this._automaticWidth = this._automaticHeight = 0;
11228
+ }
11229
+ this._dirtyUpdateFlag &= ~0x4;
11230
+ };
11061
11231
  _proto._onSpriteChange = function _onSpriteChange(type) {
11062
11232
  switch(type){
11063
11233
  case SpriteModifyFlags.texture:
11064
11234
  this.shaderData.setTexture(SpriteMask._textureProperty, this.sprite.texture);
11065
11235
  break;
11236
+ case SpriteModifyFlags.size:
11237
+ this._dirtyUpdateFlag |= 0x4;
11238
+ if (this._customWidth === undefined || this._customHeight === undefined) {
11239
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11240
+ }
11241
+ break;
11066
11242
  case SpriteModifyFlags.region:
11067
11243
  case SpriteModifyFlags.atlasRegionOffset:
11068
11244
  this._dirtyUpdateFlag |= 0x3;
@@ -11070,22 +11246,31 @@ SimpleSpriteAssembler = __decorate$1([
11070
11246
  case SpriteModifyFlags.atlasRegion:
11071
11247
  this._dirtyUpdateFlag |= 0x2;
11072
11248
  break;
11249
+ case SpriteModifyFlags.pivot:
11250
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11251
+ break;
11073
11252
  }
11074
11253
  };
11075
11254
  _create_class$2(SpriteMask, [
11076
11255
  {
11077
11256
  key: "width",
11078
11257
  get: /**
11079
- * Render width.
11258
+ * Render width (in world coordinates).
11259
+ *
11260
+ * @remarks
11261
+ * If width is set, return the set value,
11262
+ * otherwise return `SpriteMask.sprite.width`.
11080
11263
  */ function get() {
11081
- if (this._width === undefined && this._sprite) {
11082
- this.width = this._sprite.width;
11264
+ if (this._customWidth !== undefined) {
11265
+ return this._customWidth;
11266
+ } else {
11267
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
11268
+ return this._automaticWidth;
11083
11269
  }
11084
- return this._width;
11085
11270
  },
11086
11271
  set: function set(value) {
11087
- if (this._width !== value) {
11088
- this._width = value;
11272
+ if (this._customWidth !== value) {
11273
+ this._customWidth = value;
11089
11274
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11090
11275
  }
11091
11276
  }
@@ -11093,16 +11278,22 @@ SimpleSpriteAssembler = __decorate$1([
11093
11278
  {
11094
11279
  key: "height",
11095
11280
  get: /**
11096
- * Render height.
11281
+ * Render height (in world coordinates).
11282
+ *
11283
+ * @remarks
11284
+ * If height is set, return the set value,
11285
+ * otherwise return `SpriteMask.sprite.height`.
11097
11286
  */ function get() {
11098
- if (this._height === undefined && this._sprite) {
11099
- this.height = this._sprite.height;
11287
+ if (this._customHeight !== undefined) {
11288
+ return this._customHeight;
11289
+ } else {
11290
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
11291
+ return this._automaticHeight;
11100
11292
  }
11101
- return this._height;
11102
11293
  },
11103
11294
  set: function set(value) {
11104
- if (this._height !== value) {
11105
- this._height = value;
11295
+ if (this._customHeight !== value) {
11296
+ this._customHeight = value;
11106
11297
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11107
11298
  }
11108
11299
  }
@@ -11145,10 +11336,14 @@ SimpleSpriteAssembler = __decorate$1([
11145
11336
  set: function set(value) {
11146
11337
  var lastSprite = this._sprite;
11147
11338
  if (lastSprite !== value) {
11148
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
11339
+ if (lastSprite) {
11340
+ lastSprite._addReferCount(-1);
11341
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
11342
+ }
11343
+ this._dirtyUpdateFlag |= 0x7;
11149
11344
  if (value) {
11345
+ value._addReferCount(1);
11150
11346
  value._updateFlagManager.addListener(this._onSpriteChange);
11151
- this._dirtyUpdateFlag |= 0x3;
11152
11347
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
11153
11348
  } else {
11154
11349
  this.shaderData.setTexture(SpriteMask._textureProperty, null);
@@ -11188,10 +11383,16 @@ __decorate$1([
11188
11383
  ], SpriteMask.prototype, "_sprite", void 0);
11189
11384
  __decorate$1([
11190
11385
  ignoreClone
11191
- ], SpriteMask.prototype, "_width", void 0);
11386
+ ], SpriteMask.prototype, "_automaticWidth", void 0);
11192
11387
  __decorate$1([
11193
11388
  ignoreClone
11194
- ], SpriteMask.prototype, "_height", void 0);
11389
+ ], SpriteMask.prototype, "_automaticHeight", void 0);
11390
+ __decorate$1([
11391
+ assignmentClone
11392
+ ], SpriteMask.prototype, "_customWidth", void 0);
11393
+ __decorate$1([
11394
+ assignmentClone
11395
+ ], SpriteMask.prototype, "_customHeight", void 0);
11195
11396
  __decorate$1([
11196
11397
  assignmentClone
11197
11398
  ], SpriteMask.prototype, "_flipX", void 0);
@@ -11209,7 +11410,9 @@ var /**
11209
11410
  */ SpriteMaskUpdateFlags;
11210
11411
  (function(SpriteMaskUpdateFlags) {
11211
11412
  SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
11212
- SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x3] = "All";
11413
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
11414
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
11415
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x7] = "All";
11213
11416
  })(SpriteMaskUpdateFlags || (SpriteMaskUpdateFlags = {}));
11214
11417
  /**
11215
11418
  * Vertex element format.
@@ -11467,7 +11670,9 @@ var BufferUtil = /*#__PURE__*/ function() {
11467
11670
  var platformBuffer = this._engine._hardwareRenderer.createPlatformBuffer(this._type, this._byteLength, this._bufferUsage);
11468
11671
  this._platformBuffer = platformBuffer;
11469
11672
  };
11470
- _proto._onDestroy = function _onDestroy() {
11673
+ /**
11674
+ * @internal
11675
+ */ _proto._onDestroy = function _onDestroy() {
11471
11676
  GraphicsResource.prototype._onDestroy.call(this);
11472
11677
  this._platformBuffer.destroy();
11473
11678
  };
@@ -11553,14 +11758,19 @@ var BufferUtil = /*#__PURE__*/ function() {
11553
11758
  }();
11554
11759
  /**
11555
11760
  * Sub-mesh, mainly contains drawing information.
11556
- */ var SubMesh = function SubMesh(start, count, topology) {
11557
- if (start === void 0) start = 0;
11558
- if (count === void 0) count = 0;
11559
- if (topology === void 0) topology = exports.MeshTopology.Triangles;
11560
- this.start = start;
11561
- this.count = count;
11562
- this.topology = topology;
11563
- };
11761
+ */ var SubMesh = /*#__PURE__*/ function() {
11762
+ var SubMesh = function SubMesh(start, count, topology) {
11763
+ if (start === void 0) start = 0;
11764
+ if (count === void 0) count = 0;
11765
+ if (topology === void 0) topology = exports.MeshTopology.Triangles;
11766
+ this.start = start;
11767
+ this.count = count;
11768
+ this.topology = topology;
11769
+ };
11770
+ var _proto = SubMesh.prototype;
11771
+ _proto.dispose = function dispose() {};
11772
+ return SubMesh;
11773
+ }();
11564
11774
  /**
11565
11775
  * Mesh.
11566
11776
  */ var Mesh = /*#__PURE__*/ function(GraphicsResource) {
@@ -11641,10 +11851,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11641
11851
  /**
11642
11852
  * @internal
11643
11853
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11644
- if (this._getReferCount() > 0) {
11645
- var lastBinding = this._vertexBufferBindings[index];
11646
- lastBinding && lastBinding._buffer._addReferCount(-1);
11647
- binding._buffer._addReferCount(1);
11854
+ var referCount = this._getReferCount();
11855
+ if (referCount > 0) {
11856
+ var _this__vertexBufferBindings_index;
11857
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addReferCount(-referCount);
11858
+ binding == null ? void 0 : binding._buffer._addReferCount(referCount);
11648
11859
  }
11649
11860
  this._vertexBufferBindings[index] = binding;
11650
11861
  this._bufferStructChanged = true;
@@ -11656,11 +11867,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11656
11867
  this._bufferStructChanged = false;
11657
11868
  };
11658
11869
  _proto._addReferCount = function _addReferCount(value) {
11870
+ var _this__indexBufferBinding;
11659
11871
  GraphicsResource.prototype._addReferCount.call(this, value);
11660
11872
  var vertexBufferBindings = this._vertexBufferBindings;
11661
11873
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11662
11874
  vertexBufferBindings[i]._buffer._addReferCount(value);
11663
11875
  }
11876
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addReferCount(value);
11664
11877
  };
11665
11878
  _proto._rebuild = function _rebuild() {
11666
11879
  this._engine._hardwareRenderer.createPlatformPrimitive(this);
@@ -11675,14 +11888,23 @@ var BufferUtil = /*#__PURE__*/ function() {
11675
11888
  this._vertexElementMap = null;
11676
11889
  this._platformPrimitive.destroy();
11677
11890
  };
11678
- _proto._setVertexElements = function _setVertexElements(elements) {
11891
+ /**
11892
+ * @internal
11893
+ */ _proto._setVertexElements = function _setVertexElements(elements) {
11679
11894
  this._clearVertexElements();
11680
11895
  for(var i = 0, n = elements.length; i < n; i++){
11681
11896
  this._addVertexElement(elements[i]);
11682
11897
  }
11683
11898
  };
11684
- _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11899
+ /**
11900
+ * @internal
11901
+ */ _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11685
11902
  var lastBinding = this._indexBufferBinding;
11903
+ var referCount = this._getReferCount();
11904
+ if (referCount > 0) {
11905
+ lastBinding == null ? void 0 : lastBinding.buffer._addReferCount(-referCount);
11906
+ binding == null ? void 0 : binding.buffer._addReferCount(referCount);
11907
+ }
11686
11908
  if (binding) {
11687
11909
  this._indexBufferBinding = binding;
11688
11910
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -11996,6 +12218,7 @@ var MeshModifyFlags;
11996
12218
  var subDataDirtyFlags = this._subDataDirtyFlags;
11997
12219
  var blendShapeFloatStride = this._vertexElementCount * 3;
11998
12220
  var blendShapeByteStride = blendShapeFloatStride * 4;
12221
+ var bufferOffset = this._bufferBindingOffset;
11999
12222
  // @todo: should fix bug when dataChangedFlag is true
12000
12223
  for(var i = 0, n = blendShapes.length; i < n; i++){
12001
12224
  var dataChangedFlag = subDataDirtyFlags[i];
@@ -12013,7 +12236,7 @@ var MeshModifyFlags;
12013
12236
  var offset = indexInBuffer * blendShapeFloatStride;
12014
12237
  var storeInfo = storeInfos[i];
12015
12238
  storeInfo || (storeInfos[i] = storeInfo = new miniprogram$7.Vector2());
12016
- storeInfo.set(bufferIndex + 1, indexInBuffer * blendShapeByteStride); // BlendShape buffer is start from 1
12239
+ storeInfo.set(bufferOffset + bufferIndex, indexInBuffer * blendShapeByteStride); // BufferOffset is mesh vertexBuffer offset
12017
12240
  var deltaPositions = endFrame.deltaPositions;
12018
12241
  for(var j = 0; j < vertexCount; j++){
12019
12242
  var start = offset + bufferFloatStride * j;
@@ -12815,7 +13038,9 @@ var MeshModifyFlags;
12815
13038
  }
12816
13039
  this.setTangents(tangents);
12817
13040
  };
12818
- _proto._onDestroy = function _onDestroy() {
13041
+ /**
13042
+ * @internal
13043
+ */ _proto._onDestroy = function _onDestroy() {
12819
13044
  Mesh.prototype._onDestroy.call(this);
12820
13045
  this._readable && this._releaseCache();
12821
13046
  };
@@ -13283,25 +13508,32 @@ var VertexChangedFlags;
13283
13508
  var MeshRenderer = function MeshRenderer(entity) {
13284
13509
  var _this;
13285
13510
  _this = Renderer.call(this, entity) || this;
13511
+ _this._enableVertexColor = false;
13286
13512
  _this._onMeshChanged = _this._onMeshChanged.bind(_assert_this_initialized(_this));
13287
13513
  return _this;
13288
13514
  };
13289
13515
  _inherits$2(MeshRenderer, Renderer);
13290
13516
  var _proto = MeshRenderer.prototype;
13291
- _proto._onDestroy = function _onDestroy() {
13517
+ /**
13518
+ * @internal
13519
+ */ _proto._onDestroy = function _onDestroy() {
13292
13520
  Renderer.prototype._onDestroy.call(this);
13293
13521
  var mesh = this._mesh;
13294
- if (mesh && !mesh.destroyed) {
13295
- mesh._addReferCount(-1);
13522
+ if (mesh) {
13523
+ mesh.destroyed || mesh._addReferCount(-1);
13524
+ mesh._updateFlagManager.removeListener(this._onMeshChanged);
13296
13525
  this._mesh = null;
13297
13526
  }
13298
13527
  };
13299
13528
  /**
13300
13529
  * @internal
13301
13530
  */ _proto._cloneTo = function _cloneTo(target) {
13531
+ Renderer.prototype._cloneTo.call(this, target);
13302
13532
  target.mesh = this._mesh;
13303
13533
  };
13304
- _proto._updateBounds = function _updateBounds(worldBounds) {
13534
+ /**
13535
+ * @internal
13536
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
13305
13537
  var mesh = this._mesh;
13306
13538
  if (mesh) {
13307
13539
  var localBounds = mesh.bounds;
@@ -13312,7 +13544,9 @@ var VertexChangedFlags;
13312
13544
  worldBounds.max.set(0, 0, 0);
13313
13545
  }
13314
13546
  };
13315
- _proto._render = function _render(context) {
13547
+ /**
13548
+ * @internal
13549
+ */ _proto._render = function _render(context) {
13316
13550
  var mesh = this._mesh;
13317
13551
  if (mesh) {
13318
13552
  if (this._dirtyUpdateFlag & 0x2) {
@@ -13322,7 +13556,7 @@ var VertexChangedFlags;
13322
13556
  shaderData.disableMacro(MeshRenderer._uv1Macro);
13323
13557
  shaderData.disableMacro(MeshRenderer._normalMacro);
13324
13558
  shaderData.disableMacro(MeshRenderer._tangentMacro);
13325
- shaderData.disableMacro(MeshRenderer._vertexColorMacro);
13559
+ shaderData.disableMacro(MeshRenderer._enableVertexColorMacro);
13326
13560
  for(var i = 0, n = vertexElements.length; i < n; i++){
13327
13561
  switch(vertexElements[i].semantic){
13328
13562
  case "TEXCOORD_0":
@@ -13338,7 +13572,7 @@ var VertexChangedFlags;
13338
13572
  shaderData.enableMacro(MeshRenderer._tangentMacro);
13339
13573
  break;
13340
13574
  case "COLOR_0":
13341
- shaderData.enableMacro(MeshRenderer._vertexColorMacro);
13575
+ this._enableVertexColor && shaderData.enableMacro(MeshRenderer._enableVertexColorMacro);
13342
13576
  break;
13343
13577
  }
13344
13578
  }
@@ -13389,6 +13623,20 @@ var VertexChangedFlags;
13389
13623
  this._setMesh(value);
13390
13624
  }
13391
13625
  }
13626
+ },
13627
+ {
13628
+ key: "enableVertexColor",
13629
+ get: /**
13630
+ * Whether enable vertex color.
13631
+ */ function get() {
13632
+ return this._enableVertexColor;
13633
+ },
13634
+ set: function set(value) {
13635
+ if (value !== this._enableVertexColor) {
13636
+ this._dirtyUpdateFlag |= 0x2;
13637
+ this._enableVertexColor = value;
13638
+ }
13639
+ }
13392
13640
  }
13393
13641
  ]);
13394
13642
  return MeshRenderer;
@@ -13406,7 +13654,7 @@ var VertexChangedFlags;
13406
13654
  MeshRenderer._tangentMacro = ShaderMacro.getByName("RENDERER_HAS_TANGENT");
13407
13655
  })();
13408
13656
  (function() {
13409
- MeshRenderer._vertexColorMacro = ShaderMacro.getByName("RENDERER_HAS_VERTEXCOLOR");
13657
+ MeshRenderer._enableVertexColorMacro = ShaderMacro.getByName("RENDERER_ENABLE_VERTEXCOLOR");
13410
13658
  })();
13411
13659
  __decorate$1([
13412
13660
  ignoreClone
@@ -13436,7 +13684,7 @@ var /**
13436
13684
  // Limit size to 256 to avoid some problem:
13437
13685
  // 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!
13438
13686
  // 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.
13439
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, 256);
13687
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
13440
13688
  _this._maxVertexUniformVectors = maxVertexUniformVectors;
13441
13689
  _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
13442
13690
  var localBounds = _this._localBounds;
@@ -13472,7 +13720,9 @@ var /**
13472
13720
  }
13473
13721
  }
13474
13722
  };
13475
- _proto._updateShaderData = function _updateShaderData(context) {
13723
+ /**
13724
+ * @internal
13725
+ */ _proto._updateShaderData = function _updateShaderData(context) {
13476
13726
  var entity = this.entity;
13477
13727
  var worldMatrix = this._rootBone ? this._rootBone.transform.worldMatrix : entity.transform.worldMatrix;
13478
13728
  this._updateTransformShaderData(context, worldMatrix);
@@ -13498,6 +13748,7 @@ var /**
13498
13748
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13499
13749
  this._jointTexture = new Texture2D(engine, 4, jointCount, exports.TextureFormat.R32G32B32A32, false);
13500
13750
  this._jointTexture.filterMode = exports.TextureFilterMode.Point;
13751
+ this._jointTexture.isGCIgnored = true;
13501
13752
  }
13502
13753
  shaderData.disableMacro("RENDERER_JOINTS_NUM");
13503
13754
  shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
@@ -13523,14 +13774,37 @@ var /**
13523
13774
  };
13524
13775
  /**
13525
13776
  * @internal
13777
+ */ _proto._onDestroy = function _onDestroy() {
13778
+ var _this__rootBone, _this__jointTexture;
13779
+ MeshRenderer.prototype._onDestroy.call(this);
13780
+ (_this__rootBone = this._rootBone) == null ? void 0 : _this__rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13781
+ this._rootBone = null;
13782
+ this._jointDataCreateCache = null;
13783
+ this._skin = null;
13784
+ this._blendShapeWeights = null;
13785
+ this._localBounds = null;
13786
+ this._jointMatrices = null;
13787
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13788
+ this._jointTexture = null;
13789
+ if (this._jointEntities) {
13790
+ this._jointEntities.length = 0;
13791
+ this._jointEntities = null;
13792
+ }
13793
+ };
13794
+ /**
13795
+ * @internal
13526
13796
  */ _proto._cloneTo = function _cloneTo(target) {
13527
13797
  MeshRenderer.prototype._cloneTo.call(this, target);
13528
13798
  this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
13529
13799
  };
13530
- _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
13800
+ /**
13801
+ * @internal
13802
+ */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
13531
13803
  // Cancel register listener to entity transform.
13532
13804
  };
13533
- _proto._updateBounds = function _updateBounds(worldBounds) {
13805
+ /**
13806
+ * @internal
13807
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
13534
13808
  if (this._rootBone) {
13535
13809
  var localBounds = this._localBounds;
13536
13810
  var worldMatrix = this._rootBone.transform.worldMatrix;
@@ -14972,14 +15246,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14972
15246
  _proto._createMesh = function _createMesh(engine, index) {
14973
15247
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14974
15248
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
15249
+ mesh.isGCIgnored = true;
14975
15250
  var vertexElements = [];
14976
15251
  var vertexStride = this.createVertexElements(vertexElements);
14977
15252
  // vertices
14978
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
15253
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
15254
+ vertexBuffer.isGCIgnored = true;
14979
15255
  // indices
14980
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 3, exports.BufferUsage.Dynamic);
14981
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14982
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
15256
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
15257
+ indiceBuffer.isGCIgnored = true;
15258
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
15259
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
14983
15260
  mesh.setVertexElements(vertexElements);
14984
15261
  return mesh;
14985
15262
  };
@@ -15200,6 +15477,9 @@ var SpriteMaskRenderData = /*#__PURE__*/ function(RenderData) {
15200
15477
  this.material = material;
15201
15478
  this.verticesData = verticesData;
15202
15479
  };
15480
+ _proto.dispose = function dispose() {
15481
+ this.component = this.material = this.verticesData = null;
15482
+ };
15203
15483
  return SpriteMaskRenderData;
15204
15484
  }(RenderData);
15205
15485
  var SpriteRenderData = /*#__PURE__*/ function(RenderData) {
@@ -15219,6 +15499,9 @@ var SpriteRenderData = /*#__PURE__*/ function(RenderData) {
15219
15499
  this.texture = texture;
15220
15500
  this.dataIndex = dataIndex;
15221
15501
  };
15502
+ _proto.dispose = function dispose() {
15503
+ this.component = this.material = this.verticesData = this.texture = null;
15504
+ };
15222
15505
  return SpriteRenderData;
15223
15506
  }(RenderData);
15224
15507
  var TextRenderData = /*#__PURE__*/ function(RenderData) {
@@ -15230,6 +15513,11 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15230
15513
  return _this;
15231
15514
  };
15232
15515
  _inherits$2(TextRenderData, RenderData);
15516
+ var _proto = TextRenderData.prototype;
15517
+ _proto.dispose = function dispose() {
15518
+ this.component = this.material = null;
15519
+ this.charsData.length = 0;
15520
+ };
15233
15521
  return TextRenderData;
15234
15522
  }(RenderData);
15235
15523
  /**
@@ -15255,6 +15543,12 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15255
15543
  var _proto = Sky.prototype;
15256
15544
  /**
15257
15545
  * @internal
15546
+ */ _proto.destroy = function destroy() {
15547
+ this.mesh = null;
15548
+ this.material = null;
15549
+ };
15550
+ /**
15551
+ * @internal
15258
15552
  */ _proto._render = function _render(context) {
15259
15553
  var _this = this, material = _this.material, mesh = _this.mesh;
15260
15554
  if (!material) {
@@ -15295,6 +15589,40 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15295
15589
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
15296
15590
  cameraShaderData.setMatrix(RenderContext.vpMatrixProperty, originViewProjMatrix);
15297
15591
  };
15592
+ _create_class$2(Sky, [
15593
+ {
15594
+ key: "material",
15595
+ get: /**
15596
+ * Material of the sky.
15597
+ */ function get() {
15598
+ return this._material;
15599
+ },
15600
+ set: function set(value) {
15601
+ if (this._material !== value) {
15602
+ var _this__material;
15603
+ value == null ? void 0 : value._addReferCount(1);
15604
+ (_this__material = this._material) == null ? void 0 : _this__material._addReferCount(-1);
15605
+ this._material = value;
15606
+ }
15607
+ }
15608
+ },
15609
+ {
15610
+ key: "mesh",
15611
+ get: /**
15612
+ * Mesh of the sky.
15613
+ */ function get() {
15614
+ return this._mesh;
15615
+ },
15616
+ set: function set(value) {
15617
+ if (this._mesh !== value) {
15618
+ var _this__mesh;
15619
+ value == null ? void 0 : value._addReferCount(1);
15620
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addReferCount(-1);
15621
+ this._mesh = value;
15622
+ }
15623
+ }
15624
+ }
15625
+ ]);
15298
15626
  return Sky;
15299
15627
  }();
15300
15628
  (function() {
@@ -15329,9 +15657,19 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15329
15657
  var _proto = Background.prototype;
15330
15658
  /**
15331
15659
  * @internal
15660
+ */ _proto.destroy = function destroy() {
15661
+ this._mesh._addReferCount(-1);
15662
+ this._mesh = null;
15663
+ this.texture = null;
15664
+ this.solidColor = null;
15665
+ this.sky.destroy();
15666
+ };
15667
+ /**
15668
+ * @internal
15332
15669
  * Standalone for CanvasRenderer plugin.
15333
15670
  */ _proto._initMesh = function _initMesh(engine) {
15334
15671
  this._mesh = this._createPlane(engine);
15672
+ this._mesh._addReferCount(1);
15335
15673
  };
15336
15674
  /**
15337
15675
  * @internal
@@ -15403,6 +15741,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15403
15741
  },
15404
15742
  set: function set(value) {
15405
15743
  if (this._texture !== value) {
15744
+ var _this__texture;
15745
+ value == null ? void 0 : value._addReferCount(1);
15746
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addReferCount(-1);
15406
15747
  this._texture = value;
15407
15748
  this._engine._backgroundTextureMaterial.shaderData.setTexture("material_BaseTexture", value);
15408
15749
  }
@@ -15702,8 +16043,6 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15702
16043
  function Scene(engine, name) {
15703
16044
  var _this;
15704
16045
  _this = EngineObject.call(this, engine) || this;
15705
- /** The background of the scene. */ _this.background = new Background(_this._engine);
15706
- /** Scene-related shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Scene);
15707
16046
  /** If cast shadows. */ _this.castShadows = true;
15708
16047
  /** The resolution of the shadow maps. */ _this.shadowResolution = exports.ShadowResolution.Medium;
15709
16048
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
@@ -15713,6 +16052,8 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15713
16052
  /** @internal */ _this._isActiveInEngine = false;
15714
16053
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
15715
16054
  /** @internal */ _this._rootEntities = [];
16055
+ _this._background = new Background(_this._engine);
16056
+ _this._shaderData = new ShaderData(ShaderDataGroup.Scene);
15716
16057
  _this._shadowCascades = exports.ShadowCascadesMode.NoCascades;
15717
16058
  _this._fogMode = exports.FogMode.None;
15718
16059
  _this._fogColor = new miniprogram$7.Color(0.5, 0.5, 0.5, 1.0);
@@ -15876,9 +16217,11 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15876
16217
  var sunLightIndex = lightManager._getSunLightIndex();
15877
16218
  if (sunLightIndex !== -1) {
15878
16219
  var sunlight = lightManager._directLights.get(sunLightIndex);
15879
- shaderData.setColor(Scene._sunlightColorProperty, sunlight.color);
16220
+ shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
15880
16221
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
15881
16222
  this._sunLight = sunlight;
16223
+ } else {
16224
+ this._sunLight = null;
15882
16225
  }
15883
16226
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== exports.ShadowType.None) {
15884
16227
  shaderData.enableMacro("SCENE_SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -15907,6 +16250,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15907
16250
  this._rootEntities[0].destroy();
15908
16251
  }
15909
16252
  this._activeCameras.length = 0;
16253
+ this.background.destroy();
15910
16254
  this.shaderData._addReferCount(-1);
15911
16255
  };
15912
16256
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15937,6 +16281,22 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15937
16281
  this._fogParams.w = density / Math.sqrt(Math.LN2);
15938
16282
  };
15939
16283
  _create_class$2(Scene, [
16284
+ {
16285
+ key: "shaderData",
16286
+ get: /**
16287
+ * Scene-related shader data.
16288
+ */ function get() {
16289
+ return this._shaderData;
16290
+ }
16291
+ },
16292
+ {
16293
+ key: "background",
16294
+ get: /**
16295
+ * The background of the scene.
16296
+ */ function get() {
16297
+ return this._background;
16298
+ }
16299
+ },
15940
16300
  {
15941
16301
  key: "shadowCascades",
15942
16302
  get: /**
@@ -16339,7 +16699,7 @@ ShaderPool.init();
16339
16699
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
16340
16700
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
16341
16701
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
16342
- _this._textDefaultFont.isGCIgnored = false;
16702
+ _this._textDefaultFont.isGCIgnored = true;
16343
16703
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
16344
16704
  _this._initMagentaTextures(hardwareRenderer);
16345
16705
  if (!hardwareRenderer.canIUse(exports.GLCapabilityType.depthTexture)) {
@@ -16350,6 +16710,7 @@ ShaderPool.init();
16350
16710
  _this._depthTexture2D = depthTexture2D;
16351
16711
  }
16352
16712
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
16713
+ magentaMaterial.isGCIgnored = true;
16353
16714
  magentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
16354
16715
  _this._magentaMaterial = magentaMaterial;
16355
16716
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -16576,7 +16937,9 @@ ShaderPool.init();
16576
16937
  this._magentaTexture2DArray = magentaTexture2DArray;
16577
16938
  }
16578
16939
  };
16579
- _proto._initialize = function _initialize(configuration) {
16940
+ /**
16941
+ * @internal
16942
+ */ _proto._initialize = function _initialize(configuration) {
16580
16943
  var _this = this;
16581
16944
  var physics = configuration.physics;
16582
16945
  if (physics) {
@@ -16897,7 +17260,9 @@ ShaderPool.init();
16897
17260
  this._entity._removeScript(this);
16898
17261
  this._waitHandlingInValid = false;
16899
17262
  };
16900
- _proto._onDestroy = function _onDestroy() {
17263
+ /**
17264
+ * @internal
17265
+ */ _proto._onDestroy = function _onDestroy() {
16901
17266
  Component.prototype._onDestroy.call(this);
16902
17267
  this._engine._componentsManager.addPendingDestroyScript(this);
16903
17268
  };
@@ -17841,7 +18206,7 @@ var /**
17841
18206
  // prepare render target
17842
18207
  var renderTarget = this._getAvailableRenderTarget();
17843
18208
  // @todo: shouldn't set viewport and scissor in activeRenderTarget
17844
- rhi.activeRenderTarget(renderTarget, null, 0);
18209
+ rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
17845
18210
  if (this._supportDepthTexture) {
17846
18211
  rhi.clearRenderTarget(engine, exports.CameraClearFlags.Depth, null);
17847
18212
  } else {
@@ -17963,11 +18328,13 @@ var /**
17963
18328
  if (engine._hardwareRenderer._isWebGL2) {
17964
18329
  depthTexture.depthCompareFunction = exports.TextureDepthCompareFunction.Less;
17965
18330
  }
18331
+ renderTarget == null ? void 0 : renderTarget._addReferCount(-1);
17966
18332
  if (this._supportDepthTexture) {
17967
18333
  renderTarget = this._renderTargets = new RenderTarget(engine, width, height, null, depthTexture);
17968
18334
  } else {
17969
18335
  renderTarget = this._renderTargets = new RenderTarget(engine, width, height, depthTexture);
17970
18336
  }
18337
+ renderTarget._addReferCount(1);
17971
18338
  }
17972
18339
  return renderTarget;
17973
18340
  };
@@ -17990,7 +18357,12 @@ var /**
17990
18357
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17991
18358
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17992
18359
  }
17993
- this._renderTargets = null;
18360
+ var renderTargets = this._renderTargets;
18361
+ if (renderTargets) {
18362
+ renderTargets._addReferCount(-1);
18363
+ renderTargets.destroy();
18364
+ this._renderTargets = null;
18365
+ }
17994
18366
  var viewportOffset = this._viewportOffsets;
17995
18367
  var shadowTileResolution1 = this._shadowTileResolution;
17996
18368
  switch(shadowCascades){
@@ -18046,6 +18418,9 @@ var /**
18046
18418
  (function() {
18047
18419
  CascadedShadowCasterPass._cascadesSplitDistance = new Array(CascadedShadowCasterPass._maxCascades + 1);
18048
18420
  })();
18421
+ (function() {
18422
+ CascadedShadowCasterPass._viewport = new miniprogram$7.Vector4(0, 0, 1, 1);
18423
+ })();
18049
18424
  (function() {
18050
18425
  CascadedShadowCasterPass._clearColor = new miniprogram$7.Color(1, 1, 1, 1);
18051
18426
  })();
@@ -18353,7 +18728,6 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
18353
18728
  var Camera1 = function Camera1(entity) {
18354
18729
  var _this;
18355
18730
  _this = Component.call(this, entity) || this;
18356
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Camera);
18357
18731
  /** Rendering priority - A Camera with higher priority will be rendered on top of a camera with lower priority. */ _this.priority = 0;
18358
18732
  /** Whether to enable frustum culling, it is enabled by default. */ _this.enableFrustumCulling = true;
18359
18733
  /**
@@ -18369,6 +18743,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
18369
18743
  /** @internal */ _this._virtualCamera = new VirtualCamera();
18370
18744
  /** @internal */ _this._replacementShader = null;
18371
18745
  /** @internal */ _this._replacementSubShaderTag = null;
18746
+ _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
18372
18747
  _this._isProjMatSetting = false;
18373
18748
  _this._nearClipPlane = 0.1;
18374
18749
  _this._farClipPlane = 100;
@@ -18570,6 +18945,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
18570
18945
  this.entity.scene._detachRenderCamera(this);
18571
18946
  };
18572
18947
  /**
18948
+ * @internal
18573
18949
  * @inheritdoc
18574
18950
  */ _proto._onDestroy = function _onDestroy() {
18575
18951
  var _this__renderPipeline;
@@ -18578,6 +18954,20 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
18578
18954
  this._isInvViewProjDirty.destroy();
18579
18955
  this._isViewMatrixDirty.destroy();
18580
18956
  this.shaderData._addReferCount(-1);
18957
+ this._entity = null;
18958
+ this._globalShaderMacro = null;
18959
+ this._frustum = null;
18960
+ this._renderPipeline = null;
18961
+ this._virtualCamera = null;
18962
+ this._shaderData = null;
18963
+ this._frustumViewChangeFlag = null;
18964
+ this._transform = null;
18965
+ this._isViewMatrixDirty = null;
18966
+ this._isInvViewProjDirty = null;
18967
+ this._viewport = null;
18968
+ this._inverseProjectionMatrix = null;
18969
+ this._lastAspectSize = null;
18970
+ this._invViewProjMat = null;
18581
18971
  };
18582
18972
  _proto._projMatChange = function _projMatChange() {
18583
18973
  this._isFrustumProjectDirty = true;
@@ -18617,6 +19007,14 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
18617
19007
  return this._inverseProjectionMatrix;
18618
19008
  };
18619
19009
  _create_class$2(Camera1, [
19010
+ {
19011
+ key: "shaderData",
19012
+ get: /**
19013
+ * Shader data.
19014
+ */ function get() {
19015
+ return this._shaderData;
19016
+ }
19017
+ },
18620
19018
  {
18621
19019
  key: "nearClipPlane",
18622
19020
  get: /**
@@ -18775,7 +19173,12 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
18775
19173
  return this._renderTarget;
18776
19174
  },
18777
19175
  set: function set(value) {
18778
- this._renderTarget = value;
19176
+ if (this._renderTarget !== value) {
19177
+ var _this__renderTarget;
19178
+ value == null ? void 0 : value._addReferCount(1);
19179
+ (_this__renderTarget = this._renderTarget) == null ? void 0 : _this__renderTarget._addReferCount(-1);
19180
+ this._renderTarget = value;
19181
+ }
18779
19182
  }
18780
19183
  }
18781
19184
  ]);
@@ -19754,6 +20157,7 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
19754
20157
  _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this;
19755
20158
  _this.shaderData.setFloat(PBRMaterial._metallicProp, 1);
19756
20159
  _this.shaderData.setFloat(PBRMaterial._roughnessProp, 1);
20160
+ _this.shaderData.setFloat(PBRMaterial._iorProp, 1.5);
19757
20161
  return _this;
19758
20162
  }
19759
20163
  var _proto = PBRMaterial.prototype;
@@ -19765,10 +20169,23 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
19765
20169
  return dest;
19766
20170
  };
19767
20171
  _create_class$2(PBRMaterial, [
20172
+ {
20173
+ key: "ior",
20174
+ get: /**
20175
+ * Index Of Refraction.
20176
+ * @defaultValue `1.5`
20177
+ */ function get() {
20178
+ return this.shaderData.getFloat(PBRMaterial._iorProp);
20179
+ },
20180
+ set: function set(v) {
20181
+ this.shaderData.setFloat(PBRMaterial._iorProp, Math.max(v, 0));
20182
+ }
20183
+ },
19768
20184
  {
19769
20185
  key: "metallic",
19770
20186
  get: /**
19771
- * Metallic, default 1.0.
20187
+ * Metallic.
20188
+ * @defaultValue `1.0`
19772
20189
  */ function get() {
19773
20190
  return this.shaderData.getFloat(PBRMaterial._metallicProp);
19774
20191
  },
@@ -19779,7 +20196,8 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
19779
20196
  {
19780
20197
  key: "roughness",
19781
20198
  get: /**
19782
- * Roughness, default 1.0.
20199
+ * Roughness. default 1.0.
20200
+ * @defaultValue `1.0`
19783
20201
  */ function get() {
19784
20202
  return this.shaderData.getFloat(PBRMaterial._roughnessProp);
19785
20203
  },
@@ -19816,6 +20234,9 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
19816
20234
  (function() {
19817
20235
  PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
19818
20236
  })();
20237
+ (function() {
20238
+ PBRMaterial._iorProp = Shader.getPropertyByName("material_IOR");
20239
+ })();
19819
20240
  /**
19820
20241
  * PBR (Specular-Glossiness Workflow) Material.
19821
20242
  */ var PBRSpecularMaterial = /*#__PURE__*/ function(PBRBaseMaterial) {
@@ -20023,9 +20444,18 @@ exports.TextVerticalAlignment = void 0;
20023
20444
  * @internal
20024
20445
  */ _proto._addSprite = function _addSprite(sprite) {
20025
20446
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
20447
+ sprite._atlas = this;
20448
+ sprite.isGCIgnored = true;
20026
20449
  };
20027
- _proto._onDestroy = function _onDestroy() {
20450
+ /**
20451
+ * @internal
20452
+ */ _proto._onDestroy = function _onDestroy() {
20028
20453
  ReferResource.prototype._onDestroy.call(this);
20454
+ var _this = this, sprites = _this._sprites;
20455
+ for(var i = 0, n = sprites.length; i < n; i++){
20456
+ sprites[i].destroy();
20457
+ }
20458
+ sprites.length = 0;
20029
20459
  this._sprites = null;
20030
20460
  this._spriteNamesToIndex = null;
20031
20461
  };
@@ -20069,8 +20499,10 @@ exports.TextVerticalAlignment = void 0;
20069
20499
  if (name === void 0) name = null;
20070
20500
  var _this;
20071
20501
  _this = ReferResource.call(this, engine) || this;
20072
- _this._width = undefined;
20073
- _this._height = undefined;
20502
+ _this._automaticWidth = 0;
20503
+ _this._automaticHeight = 0;
20504
+ _this._customWidth = undefined;
20505
+ _this._customHeight = undefined;
20074
20506
  _this._positions = [
20075
20507
  new miniprogram$7.Vector2(),
20076
20508
  new miniprogram$7.Vector2(),
@@ -20091,7 +20523,7 @@ exports.TextVerticalAlignment = void 0;
20091
20523
  _this._region = new miniprogram$7.Rect(0, 0, 1, 1);
20092
20524
  _this._pivot = new miniprogram$7.Vector2(0.5, 0.5);
20093
20525
  _this._border = new miniprogram$7.Vector4(0, 0, 0, 0);
20094
- _this._dirtyUpdateFlag = 0x3;
20526
+ _this._dirtyUpdateFlag = 0x7;
20095
20527
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20096
20528
  _this._texture = texture;
20097
20529
  region && _this._region.copyFrom(region);
@@ -20130,17 +20562,41 @@ exports.TextVerticalAlignment = void 0;
20130
20562
  this._dirtyUpdateFlag & 0x1 && this._updatePositions();
20131
20563
  return this._bounds;
20132
20564
  };
20133
- _proto._onDestroy = function _onDestroy() {
20565
+ /**
20566
+ * @internal
20567
+ */ _proto._addReferCount = function _addReferCount(value) {
20568
+ var _this__atlas;
20569
+ ReferResource.prototype._addReferCount.call(this, value);
20570
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addReferCount(value);
20571
+ };
20572
+ /**
20573
+ * @internal
20574
+ */ _proto._onDestroy = function _onDestroy() {
20134
20575
  ReferResource.prototype._onDestroy.call(this);
20576
+ this._positions.length = 0;
20577
+ this._positions = null;
20578
+ this._uvs.length = 0;
20579
+ this._uvs = null;
20580
+ this._atlasRegion = null;
20581
+ this._atlasRegionOffset = null;
20582
+ this._region = null;
20583
+ this._pivot = null;
20584
+ this._border = null;
20585
+ this._bounds = null;
20586
+ this._atlas = null;
20135
20587
  this._texture = null;
20588
+ this._updateFlagManager = null;
20136
20589
  };
20137
20590
  _proto._calDefaultSize = function _calDefaultSize() {
20138
20591
  if (this._texture) {
20139
20592
  var _this = this, _texture = _this._texture, _atlasRegion = _this._atlasRegion, _atlasRegionOffset = _this._atlasRegionOffset, _region = _this._region;
20140
20593
  var pixelsPerUnitReciprocal = 1.0 / Engine._pixelsPerUnit;
20141
- this._width = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
20142
- this._height = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
20594
+ this._automaticWidth = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
20595
+ this._automaticHeight = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
20596
+ } else {
20597
+ this._automaticWidth = this._automaticHeight = 0;
20143
20598
  }
20599
+ this._dirtyUpdateFlag &= ~0x4;
20144
20600
  };
20145
20601
  _proto._updatePositions = function _updatePositions() {
20146
20602
  var blank = this._atlasRegionOffset;
@@ -20194,11 +20650,16 @@ exports.TextVerticalAlignment = void 0;
20194
20650
  };
20195
20651
  _proto._dispatchSpriteChange = function _dispatchSpriteChange(type) {
20196
20652
  switch(type){
20653
+ case SpriteModifyFlags.texture:
20654
+ this._dirtyUpdateFlag |= 0x4;
20655
+ break;
20197
20656
  case SpriteModifyFlags.atlasRegionOffset:
20198
20657
  case SpriteModifyFlags.region:
20199
- this._dirtyUpdateFlag |= 0x3;
20658
+ this._dirtyUpdateFlag |= 0x7;
20200
20659
  break;
20201
20660
  case SpriteModifyFlags.atlasRegion:
20661
+ this._dirtyUpdateFlag |= 0x4 | 0x2;
20662
+ break;
20202
20663
  case SpriteModifyFlags.border:
20203
20664
  this._dirtyUpdateFlag |= 0x2;
20204
20665
  break;
@@ -20217,7 +20678,9 @@ exports.TextVerticalAlignment = void 0;
20217
20678
  if (this._texture !== value) {
20218
20679
  this._texture = value;
20219
20680
  this._dispatchSpriteChange(SpriteModifyFlags.texture);
20220
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20681
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20682
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20683
+ }
20221
20684
  }
20222
20685
  }
20223
20686
  },
@@ -20225,13 +20688,21 @@ exports.TextVerticalAlignment = void 0;
20225
20688
  key: "width",
20226
20689
  get: /**
20227
20690
  * The width of the sprite (in world coordinates).
20691
+ *
20692
+ * @remarks
20693
+ * If width is set, return the set value,
20694
+ * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
20228
20695
  */ function get() {
20229
- this._width === undefined && this._calDefaultSize();
20230
- return this._width;
20696
+ if (this._customWidth !== undefined) {
20697
+ return this._customWidth;
20698
+ } else {
20699
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
20700
+ return this._automaticWidth;
20701
+ }
20231
20702
  },
20232
20703
  set: function set(value) {
20233
- if (this._width !== value) {
20234
- this._width = value;
20704
+ if (this._customWidth !== value) {
20705
+ this._customWidth = value;
20235
20706
  this._dispatchSpriteChange(SpriteModifyFlags.size);
20236
20707
  }
20237
20708
  }
@@ -20240,13 +20711,21 @@ exports.TextVerticalAlignment = void 0;
20240
20711
  key: "height",
20241
20712
  get: /**
20242
20713
  * The height of the sprite (in world coordinates).
20714
+ *
20715
+ * @remarks
20716
+ * If height is set, return the set value,
20717
+ * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
20243
20718
  */ function get() {
20244
- this._height === undefined && this._calDefaultSize();
20245
- return this._height;
20719
+ if (this._customHeight !== undefined) {
20720
+ return this._customHeight;
20721
+ } else {
20722
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
20723
+ return this._automaticHeight;
20724
+ }
20246
20725
  },
20247
20726
  set: function set(value) {
20248
- if (this._height !== value) {
20249
- this._height = value;
20727
+ if (this._customHeight !== value) {
20728
+ this._customHeight = value;
20250
20729
  this._dispatchSpriteChange(SpriteModifyFlags.size);
20251
20730
  }
20252
20731
  }
@@ -20276,7 +20755,9 @@ exports.TextVerticalAlignment = void 0;
20276
20755
  var y = miniprogram$7.MathUtil.clamp(value.y, 0, 1);
20277
20756
  this._atlasRegion.set(x, y, miniprogram$7.MathUtil.clamp(value.width, 0, 1 - x), miniprogram$7.MathUtil.clamp(value.height, 0, 1 - y));
20278
20757
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegion);
20279
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20758
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20759
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20760
+ }
20280
20761
  }
20281
20762
  },
20282
20763
  {
@@ -20291,7 +20772,9 @@ exports.TextVerticalAlignment = void 0;
20291
20772
  var y = miniprogram$7.MathUtil.clamp(value.y, 0, 1);
20292
20773
  this._atlasRegionOffset.set(x, y, miniprogram$7.MathUtil.clamp(value.z, 0, 1 - x), miniprogram$7.MathUtil.clamp(value.w, 0, 1 - y));
20293
20774
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegionOffset);
20294
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20775
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20776
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20777
+ }
20295
20778
  }
20296
20779
  },
20297
20780
  {
@@ -20307,7 +20790,9 @@ exports.TextVerticalAlignment = void 0;
20307
20790
  var y = miniprogram$7.MathUtil.clamp(value.y, 0, 1);
20308
20791
  region.set(x, y, miniprogram$7.MathUtil.clamp(value.width, 0, 1 - x), miniprogram$7.MathUtil.clamp(value.height, 0, 1 - y));
20309
20792
  this._dispatchSpriteChange(SpriteModifyFlags.region);
20310
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20793
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20794
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20795
+ }
20311
20796
  }
20312
20797
  },
20313
20798
  {
@@ -20357,7 +20842,8 @@ var SpriteUpdateFlags;
20357
20842
  (function(SpriteUpdateFlags) {
20358
20843
  SpriteUpdateFlags[SpriteUpdateFlags["positions"] = 0x1] = "positions";
20359
20844
  SpriteUpdateFlags[SpriteUpdateFlags["uvs"] = 0x2] = "uvs";
20360
- SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x3] = "all";
20845
+ SpriteUpdateFlags[SpriteUpdateFlags["automaticSize"] = 0x4] = "automaticSize";
20846
+ SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x7] = "all";
20361
20847
  })(SpriteUpdateFlags || (SpriteUpdateFlags = {}));
20362
20848
  var _SlicedSpriteAssembler;
20363
20849
  var SlicedSpriteAssembler = (_SlicedSpriteAssembler = /*#__PURE__*/ function() {
@@ -20845,8 +21331,10 @@ var TiledType;
20845
21331
  _this._tiledAdaptiveThreshold = 0.5;
20846
21332
  _this._color = new miniprogram$7.Color(1, 1, 1, 1);
20847
21333
  _this._sprite = null;
20848
- _this._width = undefined;
20849
- _this._height = undefined;
21334
+ _this._automaticWidth = 0;
21335
+ _this._automaticHeight = 0;
21336
+ _this._customWidth = undefined;
21337
+ _this._customHeight = undefined;
20850
21338
  _this._flipX = false;
20851
21339
  _this._flipY = false;
20852
21340
  _this._maskLayer = exports.SpriteMaskLayer.Layer0;
@@ -20862,38 +21350,45 @@ var TiledType;
20862
21350
  /**
20863
21351
  * @internal
20864
21352
  */ _proto._cloneTo = function _cloneTo(target) {
21353
+ Renderer.prototype._cloneTo.call(this, target);
20865
21354
  target._assembler.resetData(target);
20866
21355
  target.sprite = this._sprite;
21356
+ target.drawMode = this._drawMode;
20867
21357
  };
20868
- _proto._updateShaderData = function _updateShaderData(context) {
21358
+ /**
21359
+ * @internal
21360
+ */ _proto._updateShaderData = function _updateShaderData(context) {
20869
21361
  // @ts-ignore
20870
21362
  this._updateTransformShaderData(context, miniprogram$7.Matrix._identity);
20871
21363
  };
20872
- _proto._updateBounds = function _updateBounds(worldBounds) {
20873
- var _this_sprite;
20874
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
21364
+ /**
21365
+ * @internal
21366
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
21367
+ if (this.sprite) {
21368
+ this._assembler.updatePositions(this);
21369
+ } else {
20875
21370
  worldBounds.min.set(0, 0, 0);
20876
21371
  worldBounds.max.set(0, 0, 0);
20877
- } else {
20878
- this._assembler.updatePositions(this);
20879
21372
  }
20880
21373
  };
20881
- _proto._render = function _render(context) {
21374
+ /**
21375
+ * @internal
21376
+ */ _proto._render = function _render(context) {
20882
21377
  var _this_sprite;
20883
21378
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
20884
21379
  return;
20885
21380
  }
20886
- // Update position.
21381
+ // Update position
20887
21382
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
20888
21383
  this._assembler.updatePositions(this);
20889
21384
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
20890
21385
  }
20891
- // Update uv.
21386
+ // Update uv
20892
21387
  if (this._dirtyUpdateFlag & 0x2) {
20893
21388
  this._assembler.updateUVs(this);
20894
21389
  this._dirtyUpdateFlag &= ~0x2;
20895
21390
  }
20896
- // Push render data
21391
+ // Push primitive
20897
21392
  var material = this.getMaterial();
20898
21393
  var texture = this.sprite.texture;
20899
21394
  var renderData = this._engine._spriteRenderDataPool.getFromPool();
@@ -20903,14 +21398,28 @@ var TiledType;
20903
21398
  /**
20904
21399
  * @internal
20905
21400
  */ _proto._onDestroy = function _onDestroy() {
20906
- var _this__sprite;
20907
21401
  Renderer.prototype._onDestroy.call(this);
20908
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
21402
+ var sprite = this._sprite;
21403
+ if (sprite) {
21404
+ sprite._addReferCount(-1);
21405
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
21406
+ }
21407
+ this._entity = null;
20909
21408
  this._color = null;
20910
21409
  this._sprite = null;
20911
21410
  this._assembler = null;
20912
21411
  this._verticesData = null;
20913
21412
  };
21413
+ _proto._calDefaultSize = function _calDefaultSize() {
21414
+ var sprite = this._sprite;
21415
+ if (sprite) {
21416
+ this._automaticWidth = sprite.width;
21417
+ this._automaticHeight = sprite.height;
21418
+ } else {
21419
+ this._automaticWidth = this._automaticHeight = 0;
21420
+ }
21421
+ this._dirtyUpdateFlag &= ~0x4;
21422
+ };
20914
21423
  _proto._updateStencilState = function _updateStencilState() {
20915
21424
  // Update stencil.
20916
21425
  var material = this.getInstanceMaterial();
@@ -20937,22 +21446,21 @@ var TiledType;
20937
21446
  break;
20938
21447
  case SpriteModifyFlags.size:
20939
21448
  var _this = this, drawMode = _this._drawMode;
20940
- if (drawMode === exports.SpriteDrawMode.Sliced) {
21449
+ this._dirtyUpdateFlag |= 0x4;
21450
+ if (this._drawMode === exports.SpriteDrawMode.Sliced) {
20941
21451
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
20942
21452
  } else if (drawMode === exports.SpriteDrawMode.Tiled) {
20943
21453
  this._dirtyUpdateFlag |= 0x3;
20944
21454
  } else {
20945
21455
  // When the width and height of `SpriteRenderer` are `undefined`,
20946
21456
  // the `size` of `Sprite` will affect the position of `SpriteRenderer`.
20947
- if (this._width === undefined || this._height === undefined) {
21457
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20948
21458
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
20949
21459
  }
20950
21460
  }
20951
21461
  break;
20952
21462
  case SpriteModifyFlags.border:
20953
- if (this._drawMode === exports.SpriteDrawMode.Sliced || this._drawMode === exports.SpriteDrawMode.Tiled) {
20954
- this._dirtyUpdateFlag |= 0x3;
20955
- }
21463
+ this._drawMode === exports.SpriteDrawMode.Sliced && (this._dirtyUpdateFlag |= 0x3);
20956
21464
  break;
20957
21465
  case SpriteModifyFlags.region:
20958
21466
  case SpriteModifyFlags.atlasRegionOffset:
@@ -21036,10 +21544,14 @@ var TiledType;
21036
21544
  set: function set(value) {
21037
21545
  var lastSprite = this._sprite;
21038
21546
  if (lastSprite !== value) {
21039
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
21547
+ if (lastSprite) {
21548
+ lastSprite._addReferCount(-1);
21549
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
21550
+ }
21551
+ this._dirtyUpdateFlag |= 0x7;
21040
21552
  if (value) {
21553
+ value._addReferCount(1);
21041
21554
  value._updateFlagManager.addListener(this._onSpriteChange);
21042
- this._dirtyUpdateFlag |= 0x3;
21043
21555
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
21044
21556
  } else {
21045
21557
  this.shaderData.setTexture(SpriteRenderer._textureProperty, null);
@@ -21064,16 +21576,22 @@ var TiledType;
21064
21576
  {
21065
21577
  key: "width",
21066
21578
  get: /**
21067
- * Render width.
21579
+ * Render width (in world coordinates).
21580
+ *
21581
+ * @remarks
21582
+ * If width is set, return the set value,
21583
+ * otherwise return `SpriteRenderer.sprite.width`.
21068
21584
  */ function get() {
21069
- this._width === undefined && this._sprite && (this.width = this._sprite.width);
21070
- return this._width;
21585
+ if (this._customWidth !== undefined) {
21586
+ return this._customWidth;
21587
+ } else {
21588
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
21589
+ return this._automaticWidth;
21590
+ }
21071
21591
  },
21072
21592
  set: function set(value) {
21073
- // Update width if undefined
21074
- this._width === undefined && this._sprite && (this._width = this._sprite.width);
21075
- if (this._width !== value) {
21076
- this._width = value;
21593
+ if (this._customWidth !== value) {
21594
+ this._customWidth = value;
21077
21595
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21078
21596
  }
21079
21597
  }
@@ -21081,16 +21599,22 @@ var TiledType;
21081
21599
  {
21082
21600
  key: "height",
21083
21601
  get: /**
21084
- * Render height.
21602
+ * Render height (in world coordinates).
21603
+ *
21604
+ * @remarks
21605
+ * If height is set, return the set value,
21606
+ * otherwise return `SpriteRenderer.sprite.height`.
21085
21607
  */ function get() {
21086
- this._height === undefined && this._sprite && (this.height = this._sprite.height);
21087
- return this._height;
21608
+ if (this._customHeight !== undefined) {
21609
+ return this._customHeight;
21610
+ } else {
21611
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
21612
+ return this._automaticHeight;
21613
+ }
21088
21614
  },
21089
21615
  set: function set(value) {
21090
- // Update height if undefined
21091
- this._height === undefined && this._sprite && (this._height = this._sprite.height);
21092
- if (this._height !== value) {
21093
- this._height = value;
21616
+ if (this._customHeight !== value) {
21617
+ this._customHeight = value;
21094
21618
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21095
21619
  }
21096
21620
  }
@@ -21177,10 +21701,16 @@ __decorate$1([
21177
21701
  ], SpriteRenderer.prototype, "_sprite", void 0);
21178
21702
  __decorate$1([
21179
21703
  ignoreClone
21180
- ], SpriteRenderer.prototype, "_width", void 0);
21704
+ ], SpriteRenderer.prototype, "_automaticWidth", void 0);
21181
21705
  __decorate$1([
21182
21706
  ignoreClone
21183
- ], SpriteRenderer.prototype, "_height", void 0);
21707
+ ], SpriteRenderer.prototype, "_automaticHeight", void 0);
21708
+ __decorate$1([
21709
+ assignmentClone
21710
+ ], SpriteRenderer.prototype, "_customWidth", void 0);
21711
+ __decorate$1([
21712
+ assignmentClone
21713
+ ], SpriteRenderer.prototype, "_customHeight", void 0);
21184
21714
  __decorate$1([
21185
21715
  assignmentClone
21186
21716
  ], SpriteRenderer.prototype, "_flipX", void 0);
@@ -21201,7 +21731,9 @@ var /**
21201
21731
  */ SpriteRendererUpdateFlags;
21202
21732
  (function(SpriteRendererUpdateFlags) {
21203
21733
  SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
21204
- SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x3] = "All";
21734
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
21735
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
21736
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x7] = "All";
21205
21737
  })(SpriteRendererUpdateFlags || (SpriteRendererUpdateFlags = {}));
21206
21738
  /**
21207
21739
  * @internal
@@ -21286,7 +21818,9 @@ var /**
21286
21818
  this._font._addReferCount(1);
21287
21819
  this.setMaterial(engine._spriteDefaultMaterial);
21288
21820
  };
21289
- _proto._onDestroy = function _onDestroy() {
21821
+ /**
21822
+ * @internal
21823
+ */ _proto._onDestroy = function _onDestroy() {
21290
21824
  Renderer.prototype._onDestroy.call(this);
21291
21825
  // Clear render data.
21292
21826
  var charRenderDatas = this._charRenderDatas;
@@ -21303,6 +21837,7 @@ var /**
21303
21837
  /**
21304
21838
  * @internal
21305
21839
  */ _proto._cloneTo = function _cloneTo(target) {
21840
+ Renderer.prototype._cloneTo.call(this, target);
21306
21841
  target.font = this._font;
21307
21842
  target._subFont = this._subFont;
21308
21843
  };
@@ -21321,14 +21856,20 @@ var /**
21321
21856
  */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
21322
21857
  this._dirtyFlag &= ~type;
21323
21858
  };
21324
- _proto._updateShaderData = function _updateShaderData(context) {
21859
+ /**
21860
+ * @internal
21861
+ */ _proto._updateShaderData = function _updateShaderData(context) {
21325
21862
  // @ts-ignore
21326
21863
  this._updateTransformShaderData(context, miniprogram$7.Matrix._identity);
21327
21864
  };
21328
- _proto._updateBounds = function _updateBounds(worldBounds) {
21865
+ /**
21866
+ * @internal
21867
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
21329
21868
  miniprogram$7.BoundingBox.transform(this._localBounds, this._entity.transform.worldMatrix, worldBounds);
21330
21869
  };
21331
- _proto._render = function _render(context) {
21870
+ /**
21871
+ * @internal
21872
+ */ _proto._render = function _render(context) {
21332
21873
  if (this._text === "" || this.enableWrapping && this.width <= 0 || this.overflowMode === exports.OverflowMode.Truncate && this.height <= 0) {
21333
21874
  return;
21334
21875
  }
@@ -21423,8 +21964,6 @@ var /**
21423
21964
  _proto._updateLocalData = function _updateLocalData() {
21424
21965
  var _this = this, color = _this.color, horizontalAlignment = _this.horizontalAlignment, verticalAlignment = _this.verticalAlignment, charRenderDatas = _this._charRenderDatas;
21425
21966
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
21426
- min.set(0, 0, 0);
21427
- max.set(0, 0, 0);
21428
21967
  var _pixelsPerUnit = Engine._pixelsPerUnit;
21429
21968
  var pixelsPerUnitReciprocal = 1.0 / _pixelsPerUnit;
21430
21969
  var charFont = this._subFont;
@@ -21451,54 +21990,65 @@ var /**
21451
21990
  break;
21452
21991
  }
21453
21992
  var renderDataCount = 0;
21993
+ var firstLine = -1;
21454
21994
  var minX = Number.MAX_SAFE_INTEGER;
21455
21995
  var minY = Number.MAX_SAFE_INTEGER;
21456
21996
  var maxX = Number.MIN_SAFE_INTEGER;
21457
21997
  var maxY = Number.MIN_SAFE_INTEGER;
21458
- var lastLineIndex = linesLen - 1;
21459
21998
  for(var i = 0; i < linesLen; ++i){
21460
- var line = lines[i];
21461
21999
  var lineWidth = lineWidths[i];
21462
- var startX = 0;
21463
- switch(horizontalAlignment){
21464
- case exports.TextHorizontalAlignment.Left:
21465
- startX = -halfRendererWidth;
21466
- break;
21467
- case exports.TextHorizontalAlignment.Center:
21468
- startX = -lineWidth * 0.5;
21469
- break;
21470
- case exports.TextHorizontalAlignment.Right:
21471
- startX = halfRendererWidth - lineWidth;
21472
- break;
21473
- }
21474
- for(var j = 0, m = line.length - 1; j <= m; ++j){
21475
- var char = line[j];
21476
- var charInfo = charFont._getCharInfo(char);
21477
- if (charInfo.h > 0) {
21478
- var charRenderData = charRenderDatas[renderDataCount] || charRenderDataPool.get();
21479
- var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
21480
- charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
21481
- renderData.color = color;
21482
- renderData.uvs = charInfo.uvs;
21483
- var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
21484
- var left = startX * pixelsPerUnitReciprocal;
21485
- var right = (startX + w) * pixelsPerUnitReciprocal;
21486
- var top = (startY + ascent) * pixelsPerUnitReciprocal;
21487
- var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
21488
- localPositions.set(left, top, right, bottom);
21489
- charRenderDatas[renderDataCount] = charRenderData;
21490
- renderDataCount++;
21491
- i === 0 && (maxY = Math.max(maxY, top));
21492
- i === lastLineIndex && (minY = Math.min(minY, bottom));
21493
- j === 0 && (minX = Math.min(minX, left));
21494
- j === m && (maxX = Math.max(maxX, right));
21495
- }
21496
- startX += charInfo.xAdvance;
22000
+ if (lineWidth > 0) {
22001
+ var line = lines[i];
22002
+ var startX = 0;
22003
+ var firstRow = -1;
22004
+ if (firstLine < 0) {
22005
+ firstLine = i;
22006
+ }
22007
+ switch(horizontalAlignment){
22008
+ case exports.TextHorizontalAlignment.Left:
22009
+ startX = -halfRendererWidth;
22010
+ break;
22011
+ case exports.TextHorizontalAlignment.Center:
22012
+ startX = -lineWidth * 0.5;
22013
+ break;
22014
+ case exports.TextHorizontalAlignment.Right:
22015
+ startX = halfRendererWidth - lineWidth;
22016
+ break;
22017
+ }
22018
+ for(var j = 0, n = line.length; j < n; ++j){
22019
+ var char = line[j];
22020
+ var charInfo = charFont._getCharInfo(char);
22021
+ if (charInfo.h > 0) {
22022
+ var _charRenderDatas, _ref;
22023
+ firstRow < 0 && (firstRow = j);
22024
+ var charRenderData = (_charRenderDatas = charRenderDatas)[_ref = renderDataCount++] || (_charRenderDatas[_ref] = charRenderDataPool.get());
22025
+ var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
22026
+ charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
22027
+ renderData.color = color;
22028
+ renderData.uvs = charInfo.uvs;
22029
+ var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
22030
+ var left = startX * pixelsPerUnitReciprocal;
22031
+ var right = (startX + w) * pixelsPerUnitReciprocal;
22032
+ var top = (startY + ascent) * pixelsPerUnitReciprocal;
22033
+ var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
22034
+ localPositions.set(left, top, right, bottom);
22035
+ i === firstLine && (maxY = Math.max(maxY, top));
22036
+ minY = Math.min(minY, bottom);
22037
+ j === firstRow && (minX = Math.min(minX, left));
22038
+ maxX = Math.max(maxX, right);
22039
+ }
22040
+ startX += charInfo.xAdvance;
22041
+ }
21497
22042
  }
21498
22043
  startY -= lineHeight;
21499
22044
  }
21500
- min.set(minX, minY, 0);
21501
- max.set(maxX, maxY, 0);
22045
+ if (firstLine < 0) {
22046
+ min.set(0, 0, 0);
22047
+ max.set(0, 0, 0);
22048
+ } else {
22049
+ min.set(minX, minY, 0);
22050
+ max.set(maxX, maxY, 0);
22051
+ }
21502
22052
  // Revert excess render data to pool.
21503
22053
  var lastRenderDataCount = charRenderDatas.length;
21504
22054
  if (lastRenderDataCount > renderDataCount) {
@@ -21511,7 +22061,9 @@ var /**
21511
22061
  return a.texture.instanceId - b.texture.instanceId;
21512
22062
  });
21513
22063
  };
21514
- _proto._onTransformChanged = function _onTransformChanged(bit) {
22064
+ /**
22065
+ * @internal
22066
+ */ _proto._onTransformChanged = function _onTransformChanged(bit) {
21515
22067
  Renderer.prototype._onTransformChanged.call(this, bit);
21516
22068
  this._setDirtyFlagTrue(0x4 | 0x8);
21517
22069
  };
@@ -21828,7 +22380,6 @@ var DirtyFlag;
21828
22380
  * @internal
21829
22381
  */ var AnimationCurveOwner = /*#__PURE__*/ function() {
21830
22382
  function AnimationCurveOwner(target, type, property, cureType) {
21831
- this.crossCurveMark = 0;
21832
22383
  this.hasSavedDefaultValue = false;
21833
22384
  this.baseEvaluateData = {
21834
22385
  curKeyframeIndex: 0,
@@ -22022,6 +22573,11 @@ AnimationCurveOwner.registerAssembler(Transform, "scale", ScaleAnimationCurveOwn
22022
22573
  return BlendShapeWeightsAnimationCurveOwnerAssembler;
22023
22574
  }();
22024
22575
  AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights", BlendShapeWeightsAnimationCurveOwnerAssembler);
22576
+ /**
22577
+ * @internal
22578
+ */ var AnimationCurveLayerOwner = function AnimationCurveLayerOwner() {
22579
+ this.crossCurveMark = 0;
22580
+ };
22025
22581
  /**
22026
22582
  * Associate AnimationCurve and the Entity
22027
22583
  */ var AnimationClipCurveBinding = /*#__PURE__*/ function() {
@@ -22039,6 +22595,13 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
22039
22595
  };
22040
22596
  /**
22041
22597
  * @internal
22598
+ */ _proto._createCurveLayerOwner = function _createCurveLayerOwner(owner) {
22599
+ var layerOwner = new AnimationCurveLayerOwner();
22600
+ layerOwner.curveOwner = owner;
22601
+ return layerOwner;
22602
+ };
22603
+ /**
22604
+ * @internal
22042
22605
  */ _proto._getTempCurveOwner = function _getTempCurveOwner(entity) {
22043
22606
  var instanceId = entity.instanceId;
22044
22607
  if (!this._tempCurveOwner[instanceId]) {
@@ -23114,9 +23677,14 @@ exports.AnimatorLayerBlendingMode = void 0;
23114
23677
  })(LayerState || (LayerState = {}));
23115
23678
  /**
23116
23679
  * @internal
23117
- */ var AnimationEventHandler = function AnimationEventHandler() {
23118
- this.handlers = [];
23119
- };
23680
+ */ var AnimationEventHandler = /*#__PURE__*/ function() {
23681
+ var AnimationEventHandler = function AnimationEventHandler() {
23682
+ this.handlers = [];
23683
+ };
23684
+ var _proto = AnimationEventHandler.prototype;
23685
+ _proto.dispose = function dispose() {};
23686
+ return AnimationEventHandler;
23687
+ }();
23120
23688
  /**
23121
23689
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.
23122
23690
  */ var AnimatorStateTransition = function AnimatorStateTransition() {
@@ -23170,12 +23738,14 @@ exports.AnimatorLayerBlendingMode = void 0;
23170
23738
  * @internal
23171
23739
  */ var AnimatorLayerData = /*#__PURE__*/ function() {
23172
23740
  var AnimatorLayerData = function AnimatorLayerData() {
23741
+ this.curveOwnerPool = Object.create(null);
23173
23742
  this.animatorStateDataMap = {};
23174
23743
  this.srcPlayData = new AnimatorStatePlayData();
23175
23744
  this.destPlayData = new AnimatorStatePlayData();
23176
23745
  this.layerState = LayerState.Standby;
23177
23746
  this.crossCurveMark = 0;
23178
23747
  this.manuallyTransition = new AnimatorStateTransition();
23748
+ this.crossOwnerLayerDataCollection = [];
23179
23749
  };
23180
23750
  var _proto = AnimatorLayerData.prototype;
23181
23751
  _proto.switchPlayData = function switchPlayData() {
@@ -23189,7 +23759,7 @@ exports.AnimatorLayerBlendingMode = void 0;
23189
23759
  /**
23190
23760
  * @internal
23191
23761
  */ var AnimatorStateData = function AnimatorStateData() {
23192
- this.curveOwners = [];
23762
+ this.curveLayerOwner = [];
23193
23763
  this.eventHandlers = [];
23194
23764
  };
23195
23765
  /**
@@ -23201,8 +23771,7 @@ exports.AnimatorLayerBlendingMode = void 0;
23201
23771
  /** Culling mode of this Animator. */ _this.cullingMode = exports.AnimatorCullingMode.None;
23202
23772
  /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0;
23203
23773
  _this._animatorLayersData = [];
23204
- _this._crossOwnerCollection = [];
23205
- _this._animationCurveOwners = [];
23774
+ _this._curveOwnerPool = Object.create(null);
23206
23775
  _this._animationEventHandlerPool = new ClassPool(AnimationEventHandler);
23207
23776
  _this._tempAnimatorStateInfo = {
23208
23777
  layerIndex: -1,
@@ -23235,7 +23804,6 @@ exports.AnimatorLayerBlendingMode = void 0;
23235
23804
  return;
23236
23805
  }
23237
23806
  var animatorLayerData = this._getAnimatorLayerData(stateInfo.layerIndex);
23238
- //TODO CM: Not consider same stateName, but different animation
23239
23807
  var animatorStateData = this._getAnimatorStateData(stateName, state, animatorLayerData);
23240
23808
  this._preparePlay(animatorLayerData, state, animatorStateData);
23241
23809
  animatorLayerData.layerState = LayerState.Playing;
@@ -23326,7 +23894,7 @@ exports.AnimatorLayerBlendingMode = void 0;
23326
23894
  /**
23327
23895
  * @internal
23328
23896
  */ _proto._reset = function _reset() {
23329
- var _this = this, animationCurveOwners = _this._animationCurveOwners;
23897
+ var _this = this, animationCurveOwners = _this._curveOwnerPool;
23330
23898
  for(var instanceId in animationCurveOwners){
23331
23899
  var propertyOwners = animationCurveOwners[instanceId];
23332
23900
  for(var property in propertyOwners){
@@ -23335,8 +23903,7 @@ exports.AnimatorLayerBlendingMode = void 0;
23335
23903
  }
23336
23904
  }
23337
23905
  this._animatorLayersData.length = 0;
23338
- this._crossOwnerCollection.length = 0;
23339
- this._animationCurveOwners.length = 0;
23906
+ this._curveOwnerPool = {};
23340
23907
  this._animationEventHandlerPool.resetPool();
23341
23908
  if (this._controllerUpdateFlag) {
23342
23909
  this._controllerUpdateFlag.flag = false;
@@ -23364,10 +23931,10 @@ exports.AnimatorLayerBlendingMode = void 0;
23364
23931
  return stateInfo;
23365
23932
  };
23366
23933
  _proto._saveDefaultValues = function _saveDefaultValues(stateData) {
23367
- var curveOwners = stateData.curveOwners;
23368
- for(var i = curveOwners.length - 1; i >= 0; i--){
23369
- var _curveOwners_i;
23370
- (_curveOwners_i = curveOwners[i]) == null ? void 0 : _curveOwners_i.saveDefaultValue();
23934
+ var curveLayerOwner = stateData.curveLayerOwner;
23935
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
23936
+ var _curveLayerOwner_i;
23937
+ (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.saveDefaultValue();
23371
23938
  }
23372
23939
  };
23373
23940
  _proto._getAnimatorStateData = function _getAnimatorStateData(stateName, animatorState, animatorLayerData) {
@@ -23376,25 +23943,32 @@ exports.AnimatorLayerBlendingMode = void 0;
23376
23943
  if (!animatorStateData) {
23377
23944
  animatorStateData = new AnimatorStateData();
23378
23945
  animatorStateDataMap[stateName] = animatorStateData;
23379
- this._saveAnimatorStateData(animatorState, animatorStateData);
23946
+ this._saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData);
23380
23947
  this._saveAnimatorEventHandlers(animatorState, animatorStateData);
23381
23948
  }
23382
23949
  return animatorStateData;
23383
23950
  };
23384
- _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData) {
23385
- var _this = this, entity = _this.entity, animationCureOwners = _this._animationCurveOwners;
23386
- var curveOwners = animatorStateData.curveOwners;
23951
+ _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData) {
23952
+ var _this = this, entity = _this.entity, curveOwnerPool = _this._curveOwnerPool;
23953
+ var curveLayerOwner = animatorStateData.curveLayerOwner;
23954
+ var layerCurveOwnerPool = animatorLayerData.curveOwnerPool;
23387
23955
  var _animatorState_clip = animatorState.clip, curves = _animatorState_clip._curveBindings;
23388
23956
  for(var i = curves.length - 1; i >= 0; i--){
23389
23957
  var curve = curves[i];
23390
23958
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
23391
23959
  if (targetEntity) {
23960
+ var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
23392
23961
  var property = curve.property;
23393
23962
  var instanceId = targetEntity.instanceId;
23394
- var propertyOwners = animationCureOwners[instanceId] || (animationCureOwners[instanceId] = {});
23395
- curveOwners[i] = propertyOwners[property] || (propertyOwners[property] = curve._createCurveOwner(targetEntity));
23963
+ // Get owner
23964
+ var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
23965
+ var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity));
23966
+ // Get layer owner
23967
+ var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
23968
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
23969
+ curveLayerOwner[i] = layerOwner;
23396
23970
  } else {
23397
- curveOwners[i] = null;
23971
+ curveLayerOwner[i] = null;
23398
23972
  console.warn("The entity don't have the child entity which path is " + curve.relativePath + ".");
23399
23973
  }
23400
23974
  }
@@ -23422,65 +23996,61 @@ exports.AnimatorLayerBlendingMode = void 0;
23422
23996
  };
23423
23997
  _proto._clearCrossData = function _clearCrossData(animatorLayerData) {
23424
23998
  animatorLayerData.crossCurveMark++;
23425
- this._crossOwnerCollection.length = 0;
23999
+ animatorLayerData.crossOwnerLayerDataCollection.length = 0;
23426
24000
  };
23427
- _proto._addCrossCurveData = function _addCrossCurveData(crossCurveData, owner, curCurveIndex, nextCurveIndex) {
23428
- owner.crossSrcCurveIndex = curCurveIndex;
23429
- owner.crossDestCurveIndex = nextCurveIndex;
23430
- crossCurveData.push(owner);
24001
+ _proto._addCrossOwner = function _addCrossOwner(animatorLayerData, layerOwner, curCurveIndex, nextCurveIndex) {
24002
+ layerOwner.crossSrcCurveIndex = curCurveIndex;
24003
+ layerOwner.crossDestCurveIndex = nextCurveIndex;
24004
+ animatorLayerData.crossOwnerLayerDataCollection.push(layerOwner);
23431
24005
  };
23432
24006
  _proto._prepareCrossFading = function _prepareCrossFading(animatorLayerData) {
23433
- var crossCurveData = this._crossOwnerCollection;
23434
- var crossCurveMark = animatorLayerData.crossCurveMark;
23435
24007
  // Add src cross curve data.
23436
- this._prepareSrcCrossData(crossCurveData, animatorLayerData.srcPlayData, crossCurveMark, false);
24008
+ this._prepareSrcCrossData(animatorLayerData, false);
23437
24009
  // Add dest cross curve data.
23438
- this._prepareDestCrossData(crossCurveData, animatorLayerData.destPlayData, crossCurveMark, false);
24010
+ this._prepareDestCrossData(animatorLayerData, false);
23439
24011
  };
23440
24012
  _proto._prepareStandbyCrossFading = function _prepareStandbyCrossFading(animatorLayerData) {
23441
- var crossOwnerCollection = this._crossOwnerCollection;
23442
- var srcPlayData = animatorLayerData.srcPlayData, crossCurveMark = animatorLayerData.crossCurveMark;
23443
24013
  // Standby have two sub state, one is never play, one is finished, never play srcPlayData.state is null.
23444
- srcPlayData.state && this._prepareSrcCrossData(crossOwnerCollection, srcPlayData, crossCurveMark, true);
24014
+ animatorLayerData.srcPlayData.state && this._prepareSrcCrossData(animatorLayerData, true);
23445
24015
  // Add dest cross curve data.
23446
- this._prepareDestCrossData(crossOwnerCollection, animatorLayerData.destPlayData, crossCurveMark, true);
24016
+ this._prepareDestCrossData(animatorLayerData, true);
23447
24017
  };
23448
24018
  _proto._prepareFixedPoseCrossFading = function _prepareFixedPoseCrossFading(animatorLayerData) {
23449
- var crossOwnerCollection = this._crossOwnerCollection;
24019
+ var crossOwnerLayerDataCollection = animatorLayerData.crossOwnerLayerDataCollection;
23450
24020
  // Save current cross curve data owner fixed pose.
23451
- for(var i = crossOwnerCollection.length - 1; i >= 0; i--){
23452
- var item = crossOwnerCollection[i];
23453
- item.saveFixedPoseValue();
24021
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24022
+ var layerOwner = crossOwnerLayerDataCollection[i];
24023
+ if (!layerOwner) continue;
24024
+ layerOwner.curveOwner.saveFixedPoseValue();
23454
24025
  // Reset destCurveIndex When fixed pose crossFading again.
23455
- item.crossDestCurveIndex = -1;
24026
+ layerOwner.crossDestCurveIndex = -1;
23456
24027
  }
23457
24028
  // prepare dest AnimatorState cross data.
23458
- this._prepareDestCrossData(crossOwnerCollection, animatorLayerData.destPlayData, animatorLayerData.crossCurveMark, true);
23459
- };
23460
- _proto._prepareSrcCrossData = function _prepareSrcCrossData(crossCurveData, srcPlayData, crossCurveMark, saveFixed) {
23461
- var curveOwners = srcPlayData.stateData.curveOwners;
23462
- for(var i = curveOwners.length - 1; i >= 0; i--){
23463
- var owner = curveOwners[i];
23464
- if (!owner) continue;
23465
- owner.crossCurveMark = crossCurveMark;
23466
- owner.crossCurveDataIndex = crossCurveData.length;
23467
- saveFixed && owner.saveFixedPoseValue();
23468
- this._addCrossCurveData(crossCurveData, owner, i, -1);
23469
- }
23470
- };
23471
- _proto._prepareDestCrossData = function _prepareDestCrossData(crossCurveData, destPlayData, crossCurveMark, saveFixed) {
23472
- var curveOwners = destPlayData.stateData.curveOwners;
23473
- for(var i = curveOwners.length - 1; i >= 0; i--){
23474
- var owner = curveOwners[i];
23475
- if (!owner) continue;
23476
- if (owner.crossCurveMark === crossCurveMark) {
23477
- crossCurveData[owner.crossCurveDataIndex].crossDestCurveIndex = i;
24029
+ this._prepareDestCrossData(animatorLayerData, true);
24030
+ };
24031
+ _proto._prepareSrcCrossData = function _prepareSrcCrossData(animatorLayerData, saveFixed) {
24032
+ var curveLayerOwner = animatorLayerData.srcPlayData.stateData.curveLayerOwner;
24033
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24034
+ var layerOwner = curveLayerOwner[i];
24035
+ if (!layerOwner) continue;
24036
+ layerOwner.crossCurveMark = animatorLayerData.crossCurveMark;
24037
+ saveFixed && layerOwner.curveOwner.saveFixedPoseValue();
24038
+ this._addCrossOwner(animatorLayerData, layerOwner, i, -1);
24039
+ }
24040
+ };
24041
+ _proto._prepareDestCrossData = function _prepareDestCrossData(animatorLayerData, saveFixed) {
24042
+ var curveLayerOwner = animatorLayerData.destPlayData.stateData.curveLayerOwner;
24043
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24044
+ var layerOwner = curveLayerOwner[i];
24045
+ if (!layerOwner) continue;
24046
+ if (layerOwner.crossCurveMark === animatorLayerData.crossCurveMark) {
24047
+ layerOwner.crossDestCurveIndex = i;
23478
24048
  } else {
24049
+ var owner = layerOwner.curveOwner;
23479
24050
  owner.saveDefaultValue();
23480
24051
  saveFixed && owner.saveFixedPoseValue();
23481
- owner.crossCurveMark = crossCurveMark;
23482
- owner.crossCurveDataIndex = crossCurveData.length;
23483
- this._addCrossCurveData(crossCurveData, owner, -1, i);
24052
+ layerOwner.crossCurveMark = animatorLayerData.crossCurveMark;
24053
+ this._addCrossOwner(animatorLayerData, layerOwner, -1, i);
23484
24054
  }
23485
24055
  }
23486
24056
  };
@@ -23510,7 +24080,7 @@ exports.AnimatorLayerBlendingMode = void 0;
23510
24080
  }
23511
24081
  };
23512
24082
  _proto._updatePlayingState = function _updatePlayingState(playData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
23513
- var _playData_stateData = playData.stateData, curveOwners = _playData_stateData.curveOwners, eventHandlers = _playData_stateData.eventHandlers;
24083
+ var _playData_stateData = playData.stateData, curveLayerOwner = _playData_stateData.curveLayerOwner, eventHandlers = _playData_stateData.eventHandlers;
23514
24084
  var state = playData.state, lastPlayState = playData.playState, lastClipTime = playData.clipTime;
23515
24085
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
23516
24086
  playData.update(this.speed < 0);
@@ -23520,8 +24090,8 @@ exports.AnimatorLayerBlendingMode = void 0;
23520
24090
  var clipTime = playData.clipTime, playState = playData.playState;
23521
24091
  eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
23522
24092
  for(var i = curveBindings.length - 1; i >= 0; i--){
23523
- var owner = curveOwners[i];
23524
- owner == null ? void 0 : owner.evaluateAndApplyValue(curveBindings[i].curve, clipTime, weight, additive);
24093
+ var _curveLayerOwner_i;
24094
+ (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.evaluateAndApplyValue(curveBindings[i].curve, clipTime, weight, additive);
23525
24095
  }
23526
24096
  playData.frameTime += state.speed * delta;
23527
24097
  if (playState === AnimatorStatePlayState.Finished) {
@@ -23537,7 +24107,7 @@ exports.AnimatorLayerBlendingMode = void 0;
23537
24107
  }
23538
24108
  };
23539
24109
  _proto._updateCrossFade = function _updateCrossFade(srcPlayData, destPlayData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
23540
- var _this = this, crossCurveDataCollection = _this._crossOwnerCollection;
24110
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
23541
24111
  var _srcPlayData_state_clip = srcPlayData.state.clip, srcCurves = _srcPlayData_state_clip._curveBindings;
23542
24112
  var srcState = srcPlayData.state, srcStateData = srcPlayData.stateData, lastSrcPlayState = srcPlayData.playState;
23543
24113
  var srcEventHandlers = srcStateData.eventHandlers;
@@ -23576,14 +24146,16 @@ exports.AnimatorLayerBlendingMode = void 0;
23576
24146
  } else {
23577
24147
  this._callAnimatorScriptOnUpdate(destState, layerIndex);
23578
24148
  }
23579
- for(var i = crossCurveDataCollection.length - 1; i >= 0; i--){
23580
- var crossCurveData = crossCurveDataCollection[i];
23581
- var crossSrcCurveIndex = crossCurveData.crossSrcCurveIndex, crossDestCurveIndex = crossCurveData.crossDestCurveIndex;
23582
- crossCurveData.crossFadeAndApplyValue(crossSrcCurveIndex >= 0 ? srcCurves[crossSrcCurveIndex].curve : null, crossDestCurveIndex >= 0 ? destCurves[crossDestCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, weight, additive);
24149
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24150
+ var layerOwner = crossOwnerLayerDataCollection[i];
24151
+ if (!layerOwner) continue;
24152
+ var srcCurveIndex = layerOwner.crossSrcCurveIndex;
24153
+ var destCurveIndex = layerOwner.crossDestCurveIndex;
24154
+ layerOwner.curveOwner.crossFadeAndApplyValue(srcCurveIndex >= 0 ? srcCurves[srcCurveIndex].curve : null, destCurveIndex >= 0 ? destCurves[destCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, weight, additive);
23583
24155
  }
23584
24156
  };
23585
24157
  _proto._updateCrossFadeFromPose = function _updateCrossFadeFromPose(destPlayData, layerData, layerIndex, layerWeight, delta, additive, aniUpdate) {
23586
- var crossCurveDataCollection = this._crossOwnerCollection;
24158
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
23587
24159
  var state = destPlayData.state, stateData = destPlayData.stateData, lastPlayState = destPlayData.playState;
23588
24160
  var eventHandlers = stateData.eventHandlers;
23589
24161
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
@@ -23607,10 +24179,11 @@ exports.AnimatorLayerBlendingMode = void 0;
23607
24179
  } else {
23608
24180
  this._callAnimatorScriptOnUpdate(state, layerIndex);
23609
24181
  }
23610
- for(var i = crossCurveDataCollection.length - 1; i >= 0; i--){
23611
- var crossCurveData = crossCurveDataCollection[i];
23612
- var crossDestCurveIndex = crossCurveData.crossDestCurveIndex;
23613
- crossCurveData.crossFadeFromPoseAndApplyValue(crossDestCurveIndex >= 0 ? curveBindings[crossDestCurveIndex].curve : null, destClipTime, crossWeight, layerWeight, additive);
24182
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24183
+ var layerOwner = crossOwnerLayerDataCollection[i];
24184
+ if (!layerOwner) continue;
24185
+ var curveIndex = layerOwner.crossDestCurveIndex;
24186
+ layerOwner.curveOwner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, layerWeight, additive);
23614
24187
  }
23615
24188
  };
23616
24189
  _proto._updateCrossFadeData = function _updateCrossFadeData(layerData, crossWeight, delta, fixed) {
@@ -23632,18 +24205,19 @@ exports.AnimatorLayerBlendingMode = void 0;
23632
24205
  if (layerData.layerState === LayerState.Playing) {
23633
24206
  var srcPlayData = layerData.srcPlayData;
23634
24207
  if (srcPlayData.state !== playState) {
23635
- var curveOwners = srcPlayData.stateData.curveOwners;
23636
- for(var i = curveOwners.length - 1; i >= 0; i--){
23637
- var owner = curveOwners[i];
24208
+ var curveLayerOwner = srcPlayData.stateData.curveLayerOwner;
24209
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24210
+ var _curveLayerOwner_i;
24211
+ var owner = (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner;
23638
24212
  (owner == null ? void 0 : owner.hasSavedDefaultValue) && owner.revertDefaultValue();
23639
24213
  }
23640
24214
  this._saveDefaultValues(playStateData);
23641
24215
  }
23642
24216
  } else {
23643
24217
  // layerState is CrossFading, FixedCrossFading, Standby
23644
- var crossCurveDataCollection = this._crossOwnerCollection;
23645
- for(var i1 = crossCurveDataCollection.length - 1; i1 >= 0; i1--){
23646
- var owner1 = crossCurveDataCollection[i1];
24218
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
24219
+ for(var i1 = crossOwnerLayerDataCollection.length - 1; i1 >= 0; i1--){
24220
+ var owner1 = crossOwnerLayerDataCollection[i1].curveOwner;
23647
24221
  owner1.hasSavedDefaultValue && owner1.revertDefaultValue();
23648
24222
  }
23649
24223
  this._saveDefaultValues(playStateData);
@@ -23813,10 +24387,7 @@ __decorate$1([
23813
24387
  ], Animator.prototype, "_animatorLayersData", void 0);
23814
24388
  __decorate$1([
23815
24389
  ignoreClone
23816
- ], Animator.prototype, "_crossOwnerCollection", void 0);
23817
- __decorate$1([
23818
- ignoreClone
23819
- ], Animator.prototype, "_animationCurveOwners", void 0);
24390
+ ], Animator.prototype, "_curveOwnerPool", void 0);
23820
24391
  __decorate$1([
23821
24392
  ignoreClone
23822
24393
  ], Animator.prototype, "_animationEventHandlerPool", void 0);
@@ -25234,7 +25805,9 @@ var _tempVector3 = new miniprogram$7.Vector3();
25234
25805
  this.getMaterial().shaderData.setTexture("u_texture", texture);
25235
25806
  }
25236
25807
  };
25237
- _proto._render = function _render(context) {
25808
+ /**
25809
+ * @internal
25810
+ */ _proto._render = function _render(context) {
25238
25811
  this._updateStrapVertices(context.camera, this._points);
25239
25812
  this._updateStrapCoords();
25240
25813
  this._vertexBuffer.setData(this._vertices);
@@ -25425,7 +25998,7 @@ var cacheDir = new miniprogram$7.Vector3();
25425
25998
  /**
25426
25999
  * The position of the probe can be set, the default is the origin [0,0,0].
25427
26000
  */ _this.position = new miniprogram$7.Vector3(0, 0, 0);
25428
- _this._isCube = true;
26001
+ /** @internal */ _this._isCube = true;
25429
26002
  _this.oriViewMatrix = new miniprogram$7.Matrix();
25430
26003
  return _this;
25431
26004
  };
@@ -25515,6 +26088,7 @@ exports.Basic2DBatcher = Basic2DBatcher;
25515
26088
  exports.BasicRenderPipeline = BasicRenderPipeline;
25516
26089
  exports.BlendShape = BlendShape;
25517
26090
  exports.BlendShapeFrame = BlendShapeFrame;
26091
+ exports.BlendState = BlendState;
25518
26092
  exports.BlinnPhongMaterial = BlinnPhongMaterial;
25519
26093
  exports.BoolUpdateFlag = BoolUpdateFlag;
25520
26094
  exports.BoxColliderShape = BoxColliderShape;
@@ -25528,6 +26102,7 @@ exports.ColliderShape = ColliderShape;
25528
26102
  exports.Component = Component;
25529
26103
  exports.ContentRestorer = ContentRestorer;
25530
26104
  exports.CubeProbe = CubeProbe;
26105
+ exports.DepthState = DepthState;
25531
26106
  exports.DirectLight = DirectLight;
25532
26107
  exports.DynamicCollider = DynamicCollider;
25533
26108
  exports.Engine = Engine;
@@ -25561,10 +26136,13 @@ exports.PointLight = PointLight;
25561
26136
  exports.Pointer = Pointer;
25562
26137
  exports.PrimitiveMesh = PrimitiveMesh;
25563
26138
  exports.Probe = Probe;
26139
+ exports.RasterState = RasterState;
25564
26140
  exports.ReferResource = ReferResource;
25565
26141
  exports.RenderPass = RenderPass;
25566
26142
  exports.RenderQueue = RenderQueue;
26143
+ exports.RenderState = RenderState;
25567
26144
  exports.RenderTarget = RenderTarget;
26145
+ exports.RenderTargetBlendState = RenderTargetBlendState;
25568
26146
  exports.ResourceManager = ResourceManager;
25569
26147
  exports.Scene = Scene;
25570
26148
  exports.SceneManager = SceneManager;
@@ -25591,6 +26169,7 @@ exports.SpriteMask = SpriteMask;
25591
26169
  exports.SpriteRenderer = SpriteRenderer;
25592
26170
  exports.StateMachineScript = StateMachineScript;
25593
26171
  exports.StaticCollider = StaticCollider;
26172
+ exports.StencilState = StencilState;
25594
26173
  exports.SubMesh = SubMesh;
25595
26174
  exports.SubShader = SubShader;
25596
26175
  exports.SystemInfo = SystemInfo;
@@ -27284,6 +27863,10 @@ var GLTFEntityParser = /*#__PURE__*/ function(GLTFParser) {
27284
27863
  }
27285
27864
  glTFResource.sceneRoots = sceneRoots;
27286
27865
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
27866
+ // @ts-ignore
27867
+ glTFResource.defaultSceneRoot._hookResource = glTFResource;
27868
+ // @ts-ignore
27869
+ glTFResource._addReferCount(1);
27287
27870
  };
27288
27871
  return GLTFEntityParser;
27289
27872
  }(GLTFParser);
@@ -27477,21 +28060,31 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
27477
28060
  var vertexCount;
27478
28061
  var bufferBindIndex = 0;
27479
28062
  var positions;
27480
- keepMeshData && (positions = new Array(vertexCount));
28063
+ var boneIndices;
28064
+ var boneWeights;
28065
+ if (keepMeshData) {
28066
+ positions = new Array(vertexCount);
28067
+ boneIndices = new Array(vertexCount);
28068
+ boneWeights = new Array(vertexCount);
28069
+ }
27481
28070
  for(var attribute in attributes){
27482
28071
  var accessor = accessors[attributes[attribute]];
27483
28072
  var accessorBuffer = GLTFUtils.getAccessorBuffer(context, gltf.bufferViews, accessor);
27484
28073
  var dataElementSize = GLTFUtils.getAccessorTypeSize(accessor.type);
27485
- var attributeCount = accessor.count;
28074
+ var accessorCount = accessor.count;
27486
28075
  var vertices = accessorBuffer.data;
27487
28076
  var vertexElement = void 0;
27488
28077
  var meshId = mesh.instanceId;
27489
28078
  var vertexBindingInfos = accessorBuffer.vertexBindingInfos;
27490
- var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, accessor.normalized);
28079
+ var elementNormalized = accessor.normalized;
28080
+ var elementFormat = GLTFUtils.getElementFormat(accessor.componentType, dataElementSize, elementNormalized);
28081
+ var scaleFactor = void 0;
28082
+ elementNormalized && (scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType));
28083
+ var elementOffset = void 0;
27491
28084
  if (accessorBuffer.interleaved) {
27492
28085
  var byteOffset = accessor.byteOffset || 0;
27493
28086
  var stride = accessorBuffer.stride;
27494
- var elementOffset = byteOffset % stride;
28087
+ elementOffset = byteOffset % stride;
27495
28088
  if (vertexBindingInfos[meshId] === undefined) {
27496
28089
  vertexElement = new miniprogram$5.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
27497
28090
  var vertexBuffer = accessorBuffer.vertexBuffer;
@@ -27507,7 +28100,8 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
27507
28100
  vertexElement = new miniprogram$5.VertexElement(attribute, elementOffset, elementFormat, vertexBindingInfos[meshId]);
27508
28101
  }
27509
28102
  } else {
27510
- vertexElement = new miniprogram$5.VertexElement(attribute, 0, elementFormat, bufferBindIndex);
28103
+ elementOffset = 0;
28104
+ vertexElement = new miniprogram$5.VertexElement(attribute, elementOffset, elementFormat, bufferBindIndex);
27511
28105
  var vertexBuffer1 = new miniprogram$5.Buffer(engine, miniprogram$5.BufferBindFlag.VertexBuffer, vertices.byteLength, miniprogram$5.BufferUsage.Static);
27512
28106
  vertexBuffer1.setData(vertices);
27513
28107
  meshRestoreInfo.vertexBuffers.push(new BufferRestoreInfo(vertexBuffer1, accessorBuffer.restoreInfo));
@@ -27516,35 +28110,61 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
27516
28110
  }
27517
28111
  vertexElements.push(vertexElement);
27518
28112
  if (attribute === "POSITION") {
27519
- vertexCount = attributeCount;
28113
+ vertexCount = accessorCount;
27520
28114
  var _mesh_bounds = mesh.bounds, min = _mesh_bounds.min, max = _mesh_bounds.max;
27521
28115
  if (accessor.min && accessor.max) {
27522
28116
  min.copyFromArray(accessor.min);
27523
28117
  max.copyFromArray(accessor.max);
27524
28118
  if (keepMeshData) {
27525
- var stride1 = vertices.length / attributeCount;
27526
- for(var j = 0; j < attributeCount; j++){
27527
- var offset = j * stride1;
27528
- positions[j] = new miniprogram$1$2.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
28119
+ var baseOffset = elementOffset / vertices.BYTES_PER_ELEMENT;
28120
+ var stride1 = vertices.length / accessorCount;
28121
+ for(var j = 0; j < accessorCount; j++){
28122
+ var offset = baseOffset + j * stride1;
28123
+ var position = new miniprogram$1$2.Vector3(vertices[offset], vertices[offset + 1], vertices[offset + 2]);
28124
+ elementNormalized && position.scale(scaleFactor);
28125
+ positions[j] = position;
27529
28126
  }
27530
28127
  }
27531
28128
  } else {
27532
- var position = GLTFMeshParser._tempVector3;
28129
+ var position1 = GLTFMeshParser._tempVector3;
27533
28130
  min.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
27534
28131
  max.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
27535
- var stride2 = vertices.length / attributeCount;
27536
- for(var j1 = 0; j1 < attributeCount; j1++){
27537
- var offset1 = j1 * stride2;
27538
- position.copyFromArray(vertices, offset1);
27539
- miniprogram$1$2.Vector3.min(min, position, min);
27540
- miniprogram$1$2.Vector3.max(max, position, max);
28132
+ var baseOffset1 = elementOffset / vertices.BYTES_PER_ELEMENT;
28133
+ var stride2 = vertices.length / accessorCount;
28134
+ for(var j1 = 0; j1 < accessorCount; j1++){
28135
+ var offset1 = baseOffset1 + j1 * stride2;
28136
+ position1.copyFromArray(vertices, offset1);
28137
+ miniprogram$1$2.Vector3.min(min, position1, min);
28138
+ miniprogram$1$2.Vector3.max(max, position1, max);
28139
+ if (keepMeshData) {
28140
+ var clonePosition = position1.clone();
28141
+ elementNormalized && clonePosition.scale(scaleFactor);
28142
+ positions[j1] = clonePosition;
28143
+ }
27541
28144
  }
27542
28145
  }
27543
- if (accessor.normalized) {
27544
- var scaleFactor = GLTFUtils.getNormalizedComponentScale(accessor.componentType);
28146
+ if (elementNormalized) {
27545
28147
  min.scale(scaleFactor);
27546
28148
  max.scale(scaleFactor);
27547
28149
  }
28150
+ } else if (attribute === "JOINTS_0" && keepMeshData) {
28151
+ var baseOffset2 = elementOffset / vertices.BYTES_PER_ELEMENT;
28152
+ var stride3 = vertices.length / accessorCount;
28153
+ for(var j2 = 0; j2 < accessorCount; j2++){
28154
+ var offset2 = baseOffset2 + j2 * stride3;
28155
+ var boneIndex = new miniprogram$1$2.Vector4(vertices[offset2], vertices[offset2 + 1], vertices[offset2 + 2], vertices[offset2 + 3]);
28156
+ elementNormalized && boneIndex.scale(scaleFactor);
28157
+ boneIndices[j2] = boneIndex;
28158
+ }
28159
+ } else if (attribute === "WEIGHTS_0" && keepMeshData) {
28160
+ var baseOffset3 = elementOffset / vertices.BYTES_PER_ELEMENT;
28161
+ var stride4 = vertices.length / accessorCount;
28162
+ for(var j3 = 0; j3 < accessorCount; j3++){
28163
+ var offset3 = baseOffset3 + j3 * stride4;
28164
+ var boneWeight = new miniprogram$1$2.Vector4(vertices[offset3], vertices[offset3 + 1], vertices[offset3 + 2], vertices[offset3 + 3]);
28165
+ elementNormalized && boneWeight.scale(scaleFactor);
28166
+ boneWeights[j3] = boneWeight;
28167
+ }
27548
28168
  }
27549
28169
  }
27550
28170
  mesh.setVertexElements(vertexElements);
@@ -27563,6 +28183,10 @@ var GLTFMeshParser = /*#__PURE__*/ function(GLTFParser1) {
27563
28183
  mesh.uploadData(!keepMeshData);
27564
28184
  //@ts-ignore
27565
28185
  mesh._positions = positions;
28186
+ //@ts-ignore
28187
+ mesh._boneIndices = boneIndices;
28188
+ //@ts-ignore
28189
+ mesh._boneWeights = boneWeights;
27566
28190
  return Promise.resolve(mesh);
27567
28191
  };
27568
28192
  /**
@@ -27652,14 +28276,7 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
27652
28276
  camera.enabled = false;
27653
28277
  };
27654
28278
  _proto._createRenderer = function _createRenderer(context, glTFNode, entity) {
27655
- var glTFResource = context.glTFResource, glTF = context.glTF;
27656
- var glTFMeshes = glTF.meshes;
27657
- var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
27658
- var meshID = glTFNode.mesh, skinID = glTFNode.skin;
27659
- var glTFMesh = glTFMeshes[meshID];
27660
- var glTFMeshPrimitives = glTFMesh.primitives;
27661
- var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
27662
- for(var i = 0; i < glTFMeshPrimitives.length; i++){
28279
+ var _loop = function _loop(i) {
27663
28280
  var gltfPrimitive = glTFMeshPrimitives[i];
27664
28281
  var mesh = meshes[meshID][i];
27665
28282
  var renderer = void 0;
@@ -27681,8 +28298,22 @@ var GLTFSceneParser = /*#__PURE__*/ function(GLTFParser1) {
27681
28298
  var materialIndex = gltfPrimitive.material;
27682
28299
  var material = (materials == null ? void 0 : materials[materialIndex]) || GLTFSceneParser._getDefaultMaterial(engine);
27683
28300
  renderer.setMaterial(material);
28301
+ // Enable vertex color if mesh has COLOR_0 vertex element
28302
+ mesh.vertexElements.forEach(function(element) {
28303
+ if (element.semantic === "COLOR_0") {
28304
+ renderer.enableVertexColor = true;
28305
+ }
28306
+ });
27684
28307
  GLTFParser.executeExtensionsAdditiveAndParse(gltfPrimitive.extensions, context, renderer, gltfPrimitive);
27685
- }
28308
+ };
28309
+ var glTFResource = context.glTFResource, glTF = context.glTF;
28310
+ var glTFMeshes = glTF.meshes;
28311
+ var engine = glTFResource.engine, meshes = glTFResource.meshes, materials = glTFResource.materials, skins = glTFResource.skins;
28312
+ var meshID = glTFNode.mesh, skinID = glTFNode.skin;
28313
+ var glTFMesh = glTFMeshes[meshID];
28314
+ var glTFMeshPrimitives = glTFMesh.primitives;
28315
+ var blendShapeWeights = glTFNode.weights || glTFMesh.weights;
28316
+ for(var i = 0; i < glTFMeshPrimitives.length; i++)_loop(i);
27686
28317
  };
27687
28318
  _proto._createAnimator = function _createAnimator(context) {
27688
28319
  if (!context.hasSkinned && !context.glTFResource.animations) {
@@ -27967,31 +28598,16 @@ var GLTFValidator = /*#__PURE__*/ function(GLTFParser1) {
27967
28598
  })();
27968
28599
  /**
27969
28600
  * Product after glTF parser, usually, `defaultSceneRoot` is only needed to use.
27970
- */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
28601
+ */ var GLTFResource = /*#__PURE__*/ function(ReferResource) {
27971
28602
  var GLTFResource = function GLTFResource(engine, url) {
27972
28603
  var _this;
27973
- _this = EngineObject.call(this, engine) || this;
28604
+ _this = ReferResource.call(this, engine) || this;
27974
28605
  _this.url = url;
27975
28606
  return _this;
27976
28607
  };
27977
- _inherits$1(GLTFResource, EngineObject);
27978
- var _proto = GLTFResource.prototype;
27979
- _proto._onDestroy = function _onDestroy() {
27980
- EngineObject.prototype._onDestroy.call(this);
27981
- this.defaultSceneRoot.destroy();
27982
- this.textures = null;
27983
- this.materials = null;
27984
- this.meshes = null;
27985
- this.skins = null;
27986
- this.animations = null;
27987
- this.entities = null;
27988
- this.cameras = null;
27989
- this.lights = null;
27990
- this.sceneRoots = null;
27991
- this.extensionsData = null;
27992
- };
28608
+ _inherits$1(GLTFResource, ReferResource);
27993
28609
  return GLTFResource;
27994
- }(miniprogram$5.EngineObject);
28610
+ }(miniprogram$5.ReferResource);
27995
28611
  var GLTFLoader = /*#__PURE__*/ function(Loader) {
27996
28612
  var GLTFLoader = function GLTFLoader() {
27997
28613
  return Loader.apply(this, arguments);
@@ -28616,6 +29232,15 @@ KTXLoader = __decorate([
28616
29232
  "ktx"
28617
29233
  ])
28618
29234
  ], KTXLoader);
29235
+ function parseProperty(object, key, value) {
29236
+ if (typeof value === "object") {
29237
+ for(var subKey in value){
29238
+ parseProperty(object[key], subKey, value[subKey]);
29239
+ }
29240
+ } else {
29241
+ object[key] = value;
29242
+ }
29243
+ }
28619
29244
  var MaterialLoader = /*#__PURE__*/ function(Loader) {
28620
29245
  var MaterialLoader = function MaterialLoader() {
28621
29246
  return Loader.apply(this, arguments);
@@ -28627,7 +29252,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
28627
29252
  return new miniprogram$5.AssetPromise(function(resolve, reject) {
28628
29253
  _this.request(item.url, _extends$1({}, item, {
28629
29254
  type: "json"
28630
- })).then(function(json) {
29255
+ })).then(function(materialSchema) {
28631
29256
  var _loop = function _loop(key) {
28632
29257
  var _shaderData_key = shaderData[key], type = _shaderData_key.type, value = _shaderData_key.value;
28633
29258
  switch(type){
@@ -28654,27 +29279,8 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
28654
29279
  }
28655
29280
  };
28656
29281
  var engine = resourceManager.engine;
28657
- var name = json.name, shader = json.shader, shaderData = json.shaderData, macros = json.macros, renderState = json.renderState;
28658
- var material;
28659
- switch(shader){
28660
- case "pbr":
28661
- material = new miniprogram$5.PBRMaterial(engine);
28662
- break;
28663
- case "pbr-specular":
28664
- material = new miniprogram$5.PBRSpecularMaterial(engine);
28665
- break;
28666
- case "unlit":
28667
- material = new miniprogram$5.UnlitMaterial(engine);
28668
- break;
28669
- case "blinn-phong":
28670
- material = new miniprogram$5.BlinnPhongMaterial(engine);
28671
- break;
28672
- case "bake-pbr":
28673
- // @todo refactor custom shader later
28674
- // @ts-ignore
28675
- material = new miniprogram$5.PBRBaseMaterial(engine, miniprogram$5.Shader.find("bake-pbr"));
28676
- break;
28677
- }
29282
+ var name = materialSchema.name, shader = materialSchema.shader, shaderData = materialSchema.shaderData, macros = materialSchema.macros, renderState = materialSchema.renderState;
29283
+ var material = new miniprogram$5.Material(engine, miniprogram$5.Shader.find(shader));
28678
29284
  material.name = name;
28679
29285
  var texturePromises = new Array();
28680
29286
  var materialShaderData = material.shaderData;
@@ -28687,9 +29293,7 @@ var MaterialLoader = /*#__PURE__*/ function(Loader) {
28687
29293
  materialShaderData.enableMacro(name1, value);
28688
29294
  }
28689
29295
  }
28690
- for(var key1 in renderState){
28691
- material[key1] = renderState[key1];
28692
- }
29296
+ parseProperty(material, "renderState", renderState);
28693
29297
  return Promise.all(texturePromises).then(function() {
28694
29298
  resolve(material);
28695
29299
  });
@@ -29425,6 +30029,11 @@ exports.AnimationClipDecoder = /*#__PURE__*/ function() {
29425
30029
  exports.AnimationClipDecoder = __decorate([
29426
30030
  decoder("AnimationClip")
29427
30031
  ], exports.AnimationClipDecoder);
30032
+ exports.SpecularMode = void 0;
30033
+ (function(SpecularMode) {
30034
+ SpecularMode["Sky"] = "Sky";
30035
+ SpecularMode["Custom"] = "Custom";
30036
+ })(exports.SpecularMode || (exports.SpecularMode = {}));
29428
30037
  var SceneParserContext = /*#__PURE__*/ function() {
29429
30038
  var SceneParserContext = function SceneParserContext(originalData, scene) {
29430
30039
  this.originalData = originalData;
@@ -29700,7 +30309,7 @@ var SpriteAtlasLoader = /*#__PURE__*/ function(Loader) {
29700
30309
  var atlasItem = atlasItems[i];
29701
30310
  if (atlasItem.img) {
29702
30311
  chainPromises.push(resourceManager.load({
29703
- url: atlasItem.img,
30312
+ url: miniprogram$5.Utils.resolveAbsoluteUrl(item.url, atlasItem.img),
29704
30313
  type: miniprogram$5.AssetType.Texture2D,
29705
30314
  params: {
29706
30315
  format: format,
@@ -29969,47 +30578,63 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
29969
30578
  // @ts-ignore
29970
30579
  engine.resourceManager.initVirtualResources(data.files);
29971
30580
  return SceneParser.parse(engine, data).then(function(scene) {
30581
+ var promises = [];
29972
30582
  // parse ambient light
29973
30583
  var ambient = data.scene.ambient;
29974
- var ambientLightPromise = Promise.resolve();
29975
- if (ambient.ambientLight) {
29976
- ambientLightPromise = resourceManager // @ts-ignore
29977
- .getResourceByRef(data.scene.ambient.ambientLight).then(function(light) {
29978
- scene.ambientLight = light;
30584
+ var useCustomAmbient = ambient.specularMode === "Custom";
30585
+ if (useCustomAmbient && ambient.customAmbientLight) {
30586
+ // @ts-ignore
30587
+ // prettier-ignore
30588
+ var customAmbientPromise = resourceManager.getResourceByRef(ambient.customAmbientLight).then(function(ambientLight) {
30589
+ scene.ambientLight = ambientLight;
29979
30590
  scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
29980
30591
  scene.ambientLight.specularIntensity = ambient.specularIntensity;
30592
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
30593
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
29981
30594
  });
29982
- } else {
29983
- scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
29984
- scene.ambientLight.specularIntensity = ambient.specularIntensity;
29985
- scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
30595
+ promises.push(customAmbientPromise);
30596
+ } else if (!useCustomAmbient && ambient.ambientLight) {
30597
+ // @ts-ignore
30598
+ // prettier-ignore
30599
+ var ambientLightPromise = resourceManager.getResourceByRef(ambient.ambientLight).then(function(ambientLight) {
30600
+ scene.ambientLight = ambientLight;
30601
+ scene.ambientLight.diffuseIntensity = ambient.diffuseIntensity;
30602
+ scene.ambientLight.specularIntensity = ambient.specularIntensity;
30603
+ scene.ambientLight.diffuseMode = ambient.diffuseMode;
30604
+ scene.ambientLight.diffuseSolidColor.copyFrom(ambient.diffuseSolidColor);
30605
+ });
30606
+ promises.push(ambientLightPromise);
29986
30607
  }
29987
30608
  var background = data.scene.background;
29988
30609
  scene.background.mode = background.mode;
29989
- var backgroundPromise = Promise.resolve();
29990
30610
  switch(scene.background.mode){
29991
30611
  case miniprogram$5.BackgroundMode.SolidColor:
29992
30612
  scene.background.solidColor.copyFrom(background.color);
29993
30613
  break;
29994
30614
  case miniprogram$5.BackgroundMode.Sky:
29995
- if (background.sky) {
30615
+ if (background.skyMesh && background.skyMaterial) {
30616
+ // @ts-ignore
30617
+ var skyMeshPromise = resourceManager.getResourceByRef(background.skyMesh).then(function(mesh) {
30618
+ scene.background.sky.mesh = mesh;
30619
+ });
29996
30620
  // @ts-ignore
29997
- backgroundPromise = resourceManager.getResourceByRef(background.sky).then(function(light) {
29998
- var sky = scene.background.sky;
29999
- var skyMaterial = new miniprogram$5.SkyBoxMaterial(engine);
30000
- skyMaterial.texture = light.specularTexture;
30001
- skyMaterial.textureDecodeRGBM = true;
30002
- sky.material = skyMaterial;
30003
- sky.mesh = miniprogram$5.PrimitiveMesh.createCuboid(engine, 1, 1, 1);
30621
+ // prettier-ignore
30622
+ var skyMaterialPromise = resourceManager.getResourceByRef(background.skyMaterial).then(function(material) {
30623
+ scene.background.sky.material = material;
30004
30624
  });
30625
+ promises.push(skyMeshPromise, skyMaterialPromise);
30626
+ } else {
30627
+ miniprogram$5.Logger.warn("Sky background mode requires skyMesh and skyMaterial");
30005
30628
  }
30006
30629
  break;
30007
30630
  case miniprogram$5.BackgroundMode.Texture:
30008
30631
  if (background.texture) {
30009
30632
  // @ts-ignore
30010
- backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
30633
+ // prettier-ignore
30634
+ var backgroundPromise = resourceManager.getResourceByRef(background.texture).then(function(texture) {
30011
30635
  scene.background.texture = texture;
30012
30636
  });
30637
+ promises.push(backgroundPromise);
30013
30638
  }
30014
30639
  break;
30015
30640
  }
@@ -30021,10 +30646,7 @@ var SceneLoader = /*#__PURE__*/ function(Loader) {
30021
30646
  if (shadow.shadowDistance != undefined) scene.shadowDistance = shadow.shadowDistance;
30022
30647
  if (shadow.shadowCascades != undefined) scene.shadowCascades = shadow.shadowCascades;
30023
30648
  }
30024
- return Promise.all([
30025
- ambientLightPromise,
30026
- backgroundPromise
30027
- ]).then(function() {
30649
+ return Promise.all(promises).then(function() {
30028
30650
  resolve(scene);
30029
30651
  });
30030
30652
  });
@@ -30280,6 +30902,21 @@ var KHR_materials_clearcoat = /*#__PURE__*/ function(GLTFExtensionParser) {
30280
30902
  KHR_materials_clearcoat = __decorate([
30281
30903
  registerGLTFExtension("KHR_materials_clearcoat", exports.GLTFExtensionMode.AdditiveParse)
30282
30904
  ], KHR_materials_clearcoat);
30905
+ var KHR_materials_ior = /*#__PURE__*/ function(GLTFExtensionParser) {
30906
+ var KHR_materials_ior = function KHR_materials_ior() {
30907
+ return GLTFExtensionParser.apply(this, arguments);
30908
+ };
30909
+ _inherits$1(KHR_materials_ior, GLTFExtensionParser);
30910
+ var _proto = KHR_materials_ior.prototype;
30911
+ _proto.additiveParse = function additiveParse(context, material, schema) {
30912
+ var _schema_ior = schema.ior, ior = _schema_ior === void 0 ? 1.5 : _schema_ior;
30913
+ material.ior = ior;
30914
+ };
30915
+ return KHR_materials_ior;
30916
+ }(GLTFExtensionParser);
30917
+ KHR_materials_ior = __decorate([
30918
+ registerGLTFExtension("KHR_materials_ior", exports.GLTFExtensionMode.AdditiveParse)
30919
+ ], KHR_materials_ior);
30283
30920
  var KHR_materials_pbrSpecularGlossiness = /*#__PURE__*/ function(GLTFExtensionParser) {
30284
30921
  var KHR_materials_pbrSpecularGlossiness = function KHR_materials_pbrSpecularGlossiness() {
30285
30922
  return GLTFExtensionParser.apply(this, arguments);
@@ -35513,8 +36150,9 @@ function _inherits(subClass, superClass) {
35513
36150
  */ WebGLEngine.create = function create(configuration) {
35514
36151
  var canvas = configuration.canvas;
35515
36152
  var webCanvas = new WebCanvas(typeof canvas === "string" ? engineMiniprogramAdapter.document.getElementById(canvas) : canvas);
35516
- var webGLRenderer = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
35517
- var engine = new WebGLEngine(webCanvas, webGLRenderer, configuration);
36153
+ var webGLGraphicDevice = new WebGLGraphicDevice(configuration.graphicDeviceOptions);
36154
+ var engine = new WebGLEngine(webCanvas, webGLGraphicDevice, configuration);
36155
+ // @ts-ignore
35518
36156
  return engine._initialize(configuration);
35519
36157
  };
35520
36158
  _create_class(WebGLEngine, [
@@ -35523,6 +36161,7 @@ function _inherits(subClass, superClass) {
35523
36161
  get: /**
35524
36162
  * Web canvas.
35525
36163
  */ function get() {
36164
+ // @ts-ignore
35526
36165
  return this._canvas;
35527
36166
  }
35528
36167
  }
@@ -37036,7 +37675,8 @@ exports.WebGLMode = void 0;
37036
37675
  var options = _extends({
37037
37676
  webGLMode: 0,
37038
37677
  stencil: true,
37039
- _forceFlush: false
37678
+ _forceFlush: false,
37679
+ _maxAllowSkinUniformVectorCount: 256
37040
37680
  }, initializeOptions);
37041
37681
  if (miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPhone || miniprogram$1$1.SystemInfo.platform === miniprogram$1$1.Platform.IPad) {
37042
37682
  var version = miniprogram$1$1.SystemInfo.operatingSystem.match(/(\d+).?(\d+)?.?(\d+)?/);
@@ -37191,23 +37831,23 @@ exports.WebGLMode = void 0;
37191
37831
  };
37192
37832
  _proto.activeRenderTarget = function activeRenderTarget(renderTarget, viewport, mipLevel) {
37193
37833
  var gl = this._gl;
37834
+ var bufferWidth, bufferHeight;
37194
37835
  if (renderTarget) {
37195
37836
  var /** @ts-ignore */ _renderTarget__platformRenderTarget;
37196
37837
  (_renderTarget__platformRenderTarget = renderTarget._platformRenderTarget) == null ? void 0 : _renderTarget__platformRenderTarget._activeRenderTarget();
37197
- var width = renderTarget.width >> mipLevel;
37198
- var height = renderTarget.height >> mipLevel;
37199
- this.viewport(0, 0, width, height);
37200
- this.scissor(0, 0, width, height);
37838
+ bufferWidth = renderTarget.width >> mipLevel;
37839
+ bufferHeight = renderTarget.height >> mipLevel;
37201
37840
  } else {
37202
37841
  gl.bindFramebuffer(gl.FRAMEBUFFER, null);
37203
- var drawingBufferWidth = gl.drawingBufferWidth, drawingBufferHeight = gl.drawingBufferHeight;
37204
- var width1 = drawingBufferWidth * viewport.z;
37205
- var height1 = drawingBufferHeight * viewport.w;
37206
- var x = viewport.x * drawingBufferWidth;
37207
- var y = drawingBufferHeight - viewport.y * drawingBufferHeight - height1;
37208
- this.viewport(x, y, width1, height1);
37209
- this.scissor(x, y, width1, height1);
37842
+ bufferWidth = gl.drawingBufferWidth;
37843
+ bufferHeight = gl.drawingBufferHeight;
37210
37844
  }
37845
+ var width = bufferWidth * viewport.z;
37846
+ var height = bufferHeight * viewport.w;
37847
+ var x = viewport.x * bufferWidth;
37848
+ var y = bufferHeight - viewport.y * bufferHeight - height;
37849
+ this.viewport(x, y, width, height);
37850
+ this.scissor(x, y, width, height);
37211
37851
  };
37212
37852
  _proto.activeTexture = function activeTexture(textureID) {
37213
37853
  if (this._activeTextureID !== textureID) {
@@ -37372,7 +38012,7 @@ function _interopNamespace(e) {
37372
38012
  }
37373
38013
  var CoreObjects__namespace = /*#__PURE__*/ _interopNamespace(CoreObjects);
37374
38014
  //@ts-ignore
37375
- var version = "1.0.0-beta.1";
38015
+ var version = "1.0.0-beta.11";
37376
38016
  console.log("Galacean engine version: " + version);
37377
38017
  for(var key in CoreObjects__namespace){
37378
38018
  CoreObjects.Loader.registerClass(key, CoreObjects__namespace[key]);
@@ -38378,12 +39018,15 @@ var CollisionDetectionMode;
38378
39018
  /**
38379
39019
  * {@inheritDoc IPhysicsManager.addCharacterController }
38380
39020
  */ _proto.addCharacterController = function addCharacterController(characterController) {
38381
- var lastPXManager = characterController._pxManager;
38382
- var shape = characterController._shape;
38383
- if (shape) {
38384
- if (lastPXManager !== this) {
38385
- lastPXManager && characterController._destroyPXController();
38386
- characterController._createPXController(this, shape);
39021
+ // Physx have no API to remove/readd cct into scene.
39022
+ if (!characterController._pxController) {
39023
+ var shape = characterController._shape;
39024
+ if (shape) {
39025
+ var lastPXManager = characterController._pxManager;
39026
+ if (lastPXManager !== this) {
39027
+ lastPXManager && characterController._destroyPXController();
39028
+ characterController._createPXController(this, shape);
39029
+ }
38387
39030
  }
38388
39031
  }
38389
39032
  characterController._pxManager = this;
@@ -38391,7 +39034,6 @@ var CollisionDetectionMode;
38391
39034
  /**
38392
39035
  * {@inheritDoc IPhysicsManager.removeCharacterController }
38393
39036
  */ _proto.removeCharacterController = function removeCharacterController(characterController) {
38394
- characterController._pxController = null;
38395
39037
  characterController._pxManager = null;
38396
39038
  };
38397
39039
  /**