@galacean/engine-core 1.0.0-beta.1 → 1.0.0-beta.10

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.
Files changed (48) hide show
  1. package/dist/main.js +762 -335
  2. package/dist/main.js.map +1 -1
  3. package/dist/miniprogram.js +762 -335
  4. package/dist/module.js +757 -336
  5. package/dist/module.js.map +1 -1
  6. package/package.json +3 -3
  7. package/types/2d/atlas/SpriteAtlas.d.ts +0 -1
  8. package/types/2d/sprite/Sprite.d.ts +12 -3
  9. package/types/2d/sprite/SpriteMask.d.ts +16 -17
  10. package/types/2d/sprite/SpriteRenderer.d.ts +17 -11
  11. package/types/2d/text/Font.d.ts +0 -1
  12. package/types/2d/text/TextRenderer.d.ts +1 -9
  13. package/types/Camera.d.ts +0 -4
  14. package/types/Component.d.ts +0 -1
  15. package/types/Engine.d.ts +0 -2
  16. package/types/Renderer.d.ts +3 -11
  17. package/types/SafeLoopArray.d.ts +37 -0
  18. package/types/Script.d.ts +0 -1
  19. package/types/animation/Animator.d.ts +2 -3
  20. package/types/animation/internal/AnimationCurveLayerOwner.d.ts +1 -0
  21. package/types/animation/internal/AnimationCurveOwnerLayerData.d.ts +1 -0
  22. package/types/asset/GraphicsResource.d.ts +0 -1
  23. package/types/asset/ReferResource.d.ts +0 -1
  24. package/types/enums/ActiveChangeFlag.d.ts +6 -0
  25. package/types/env-probe/CubeProbe.d.ts +0 -1
  26. package/types/graphic/Buffer.d.ts +0 -1
  27. package/types/graphic/Mesh.d.ts +2 -6
  28. package/types/index.d.ts +1 -1
  29. package/types/lighting/Light.d.ts +0 -1
  30. package/types/material/PBRMaterial.d.ts +11 -2
  31. package/types/mesh/MeshRenderer.d.ts +8 -8
  32. package/types/mesh/ModelMesh.d.ts +0 -1
  33. package/types/mesh/SkinnedMeshRenderer.d.ts +0 -4
  34. package/types/physics/Collider.d.ts +0 -1
  35. package/types/physics/PhysicsScene.d.ts +75 -0
  36. package/types/shader/index.d.ts +1 -0
  37. package/types/shader/state/index.d.ts +6 -0
  38. package/types/shadow/CascadedShadowCasterPass.d.ts +1 -0
  39. package/types/sky/Sky.d.ts +12 -4
  40. package/types/texture/RenderTarget.d.ts +0 -1
  41. package/types/texture/Texture.d.ts +0 -1
  42. package/types/trail/TrailRenderer.d.ts +0 -2
  43. package/types/utils/BoolUpdateFlag.d.ts +12 -0
  44. package/types/utils/DisorderedArray.d.ts +18 -0
  45. package/types/utils/SafeLoopArray.d.ts +41 -0
  46. package/types/utils/UpdateFlag.d.ts +20 -0
  47. package/types/utils/UpdateFlagManager.d.ts +1 -0
  48. package/types/utils/Utils.d.ts +31 -0
package/dist/module.js CHANGED
@@ -678,7 +678,9 @@ __decorate([
678
678
  */ _proto._addToResourceManager = function _addToResourceManager(path) {
679
679
  this._engine.resourceManager._addAsset(path, this);
680
680
  };
681
- _proto._onDestroy = function _onDestroy() {
681
+ /**
682
+ * @internal
683
+ */ _proto._onDestroy = function _onDestroy() {
682
684
  EngineObject.prototype._onDestroy.call(this);
683
685
  this._engine.resourceManager._deleteReferResource(this);
684
686
  var refCount = this._getReferCount();
@@ -810,7 +812,9 @@ var GraphicsResource = /*#__PURE__*/ function(ReferResource) {
810
812
  return _this;
811
813
  }
812
814
  var _proto = GraphicsResource.prototype;
813
- _proto._onDestroy = function _onDestroy() {
815
+ /**
816
+ * @internal
817
+ */ _proto._onDestroy = function _onDestroy() {
814
818
  ReferResource.prototype._onDestroy.call(this);
815
819
  this.engine.resourceManager._deleteGraphicResource(this);
816
820
  };
@@ -889,7 +893,9 @@ var Logger = {
889
893
  platformTexture.depthCompareFunction = this._depthCompareFunction;
890
894
  platformTexture.setUseDepthCompareMode(this._useDepthCompareMode);
891
895
  };
892
- _proto._onDestroy = function _onDestroy() {
896
+ /**
897
+ * @internal
898
+ */ _proto._onDestroy = function _onDestroy() {
893
899
  GraphicsResource.prototype._onDestroy.call(this);
894
900
  this._platformTexture.destroy();
895
901
  this._platformTexture = null;
@@ -1039,9 +1045,11 @@ var Logger = {
1039
1045
  renderTexture
1040
1046
  ];
1041
1047
  for(var i = 0, n = colorTextures.length; i < n; i++){
1042
- if (colorTextures[i]._isDepthTexture) {
1048
+ var colorTexture = colorTextures[i];
1049
+ if (colorTexture._isDepthTexture) {
1043
1050
  throw "Render texture can't use depth format.";
1044
1051
  }
1052
+ colorTexture._addReferCount(1);
1045
1053
  }
1046
1054
  _this._colorTextures = colorTextures;
1047
1055
  } else {
@@ -1052,6 +1060,7 @@ var Logger = {
1052
1060
  throw "Depth texture must use depth format.";
1053
1061
  }
1054
1062
  _this._depthTexture = depth;
1063
+ _this._depthTexture._addReferCount(1);
1055
1064
  }
1056
1065
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
1057
1066
  return _this;
@@ -1077,10 +1086,18 @@ var Logger = {
1077
1086
  this._depthTexture && this._depthTexture.generateMipmaps();
1078
1087
  }
1079
1088
  };
1080
- _proto._onDestroy = function _onDestroy() {
1089
+ /**
1090
+ * @internal
1091
+ */ _proto._onDestroy = function _onDestroy() {
1092
+ var _this__depthTexture;
1081
1093
  GraphicsResource.prototype._onDestroy.call(this);
1082
1094
  this._platformRenderTarget.destroy();
1083
- this._colorTextures.length = 0;
1095
+ var _this = this, colorTextures = _this._colorTextures;
1096
+ for(var i = 0, n = colorTextures.length; i < n; i++){
1097
+ colorTextures[i]._addReferCount(-1);
1098
+ }
1099
+ colorTextures.length = 0;
1100
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addReferCount(-1);
1084
1101
  this._depthTexture = null;
1085
1102
  this._depth = null;
1086
1103
  };
@@ -1455,7 +1472,9 @@ var Logger = {
1455
1472
  _proto.getCharInfo = function getCharInfo(char) {
1456
1473
  return this._charInfoMap[char.charCodeAt(0)];
1457
1474
  };
1458
- _proto._onDestroy = function _onDestroy() {
1475
+ /**
1476
+ * @internal
1477
+ */ _proto._onDestroy = function _onDestroy() {
1459
1478
  ReferResource.prototype._onDestroy.call(this);
1460
1479
  this.texture.destroy();
1461
1480
  this.texture = null;
@@ -1962,6 +1981,7 @@ var Logger = {
1962
1981
  var fontAtlas = new FontAtlas(engine);
1963
1982
  var texture = new Texture2D(engine, 256, 256);
1964
1983
  fontAtlas.texture = texture;
1984
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
1965
1985
  this._fontAtlases.push(fontAtlas);
1966
1986
  var nativeFontString = this.nativeFontString;
1967
1987
  engine.resourceManager.addContentRestorer(new /*#__PURE__*/ (function(ContentRestorer) {
@@ -2018,7 +2038,9 @@ var Logger = {
2018
2038
  subFontMap[key] = subFont;
2019
2039
  return subFont;
2020
2040
  };
2021
- _proto._onDestroy = function _onDestroy() {
2041
+ /**
2042
+ * @internal
2043
+ */ _proto._onDestroy = function _onDestroy() {
2022
2044
  ReferResource.prototype._onDestroy.call(this);
2023
2045
  var subFontMap = this._subFontMap;
2024
2046
  for(var k in subFontMap){
@@ -3237,7 +3259,9 @@ var GLCapabilityType;
3237
3259
  }
3238
3260
  }
3239
3261
  };
3240
- _proto._onDestroy = function _onDestroy() {
3262
+ /**
3263
+ * @internal
3264
+ */ _proto._onDestroy = function _onDestroy() {
3241
3265
  EngineObject.prototype._onDestroy.call(this);
3242
3266
  this._entity._removeComponent(this);
3243
3267
  if (this._entity.isActiveInHierarchy) {
@@ -5247,14 +5271,14 @@ SystemInfo._initialize();
5247
5271
  Keys[Keys[/** Tab or ⇥. */ "Tab"] = 63] = "Tab";
5248
5272
  Keys[Keys[/** Japanese: 変換 (henkan). */ "Convert"] = 64] = "Convert";
5249
5273
  Keys[Keys[/** Japanese: カタカナ/ひらがな/ローマ字 (katakana/hiragana/romaji). */ "KanaMode"] = 65] = "KanaMode";
5250
- Keys[Keys[/**
5251
- * Korean: HangulMode 한/영 (han/yeong).
5252
- * Japanese (Mac keyboard): かな (kana).
5253
- * */ "Lang1"] = 66] = "Lang1";
5254
5274
  Keys[Keys[/**
5255
- * Korean: Hanja 한자 (hanja).
5256
- * Japanese (Mac keyboard): 英数 (eisu).
5257
- */ "Lang2"] = 67] = "Lang2";
5275
+ * Korean: HangulMode 한/영 (han/yeong).
5276
+ * Japanese (Mac keyboard): かな (kana).
5277
+ * */ "Lang1"] = 66] = "Lang1";
5278
+ Keys[Keys[/**
5279
+ * Korean: Hanja 한자 (hanja).
5280
+ * Japanese (Mac keyboard): 英数 (eisu).
5281
+ */ "Lang2"] = 67] = "Lang2";
5258
5282
  Keys[Keys[/** Japanese (word-processing keyboard): Katakana. */ "Lang3"] = 68] = "Lang3";
5259
5283
  Keys[Keys[/** Japanese (word-processing keyboard): Hiragana. */ "Lang4"] = 69] = "Lang4";
5260
5284
  Keys[Keys[/** Japanese (word-processing keyboard): Zenkaku/Hankaku. */ "Lang5"] = 70] = "Lang5";
@@ -5271,46 +5295,46 @@ SystemInfo._initialize();
5271
5295
  Keys[Keys[/** → */ "ArrowRight"] = 81] = "ArrowRight";
5272
5296
  Keys[Keys[/** ↑ */ "ArrowUp"] = 82] = "ArrowUp";
5273
5297
  Keys[Keys[/** On the Mac, the "NumLock" code should be used for the numpad Clear key. */ "NumLock"] = 83] = "NumLock";
5274
- Keys[Keys[/**
5275
- * 0 Ins on a keyboard.
5276
- * 0 on a phone or remote control.
5277
- * */ "Numpad0"] = 84] = "Numpad0";
5278
5298
  Keys[Keys[/**
5279
- * 1 End on a keyboard.
5280
- * 1 or 1 QZ on a phone or remote control.
5281
- */ "Numpad1"] = 85] = "Numpad1";
5299
+ * 0 Ins on a keyboard.
5300
+ * 0 on a phone or remote control.
5301
+ * */ "Numpad0"] = 84] = "Numpad0";
5282
5302
  Keys[Keys[/**
5283
- * 2 on a keyboard.
5284
- * 2 ABC on a phone or remote control.
5285
- */ "Numpad2"] = 86] = "Numpad2";
5303
+ * 1 End on a keyboard.
5304
+ * 1 or 1 QZ on a phone or remote control.
5305
+ */ "Numpad1"] = 85] = "Numpad1";
5286
5306
  Keys[Keys[/**
5287
- * 3 PgDn on a keyboard.
5288
- * 3 DEF on a phone or remote control.
5289
- */ "Numpad3"] = 87] = "Numpad3";
5307
+ * 2 on a keyboard.
5308
+ * 2 ABC on a phone or remote control.
5309
+ */ "Numpad2"] = 86] = "Numpad2";
5290
5310
  Keys[Keys[/**
5291
- * 4 on a keyboard.
5292
- * 4 GHI on a phone or remote control.
5293
- */ "Numpad4"] = 88] = "Numpad4";
5311
+ * 3 PgDn on a keyboard.
5312
+ * 3 DEF on a phone or remote control.
5313
+ */ "Numpad3"] = 87] = "Numpad3";
5294
5314
  Keys[Keys[/**
5295
- * 5 on a keyboard.
5296
- * 5 JKL on a phone or remote control.
5297
- */ "Numpad5"] = 89] = "Numpad5";
5315
+ * 4 on a keyboard.
5316
+ * 4 GHI on a phone or remote control.
5317
+ */ "Numpad4"] = 88] = "Numpad4";
5298
5318
  Keys[Keys[/**
5299
- * 6 on a keyboard.
5300
- * 6 MNO on a phone or remote control.
5301
- */ "Numpad6"] = 90] = "Numpad6";
5319
+ * 5 on a keyboard.
5320
+ * 5 JKL on a phone or remote control.
5321
+ */ "Numpad5"] = 89] = "Numpad5";
5302
5322
  Keys[Keys[/**
5303
- * 7 Home on a keyboard.
5304
- * 7 PQRS or 7 PRS on a phone or remote control.
5305
- */ "Numpad7"] = 91] = "Numpad7";
5323
+ * 6 on a keyboard.
5324
+ * 6 MNO on a phone or remote control.
5325
+ */ "Numpad6"] = 90] = "Numpad6";
5306
5326
  Keys[Keys[/**
5307
- * 8 on a keyboard.
5308
- * 8 TUV on a phone or remote control.
5309
- */ "Numpad8"] = 92] = "Numpad8";
5327
+ * 7 Home on a keyboard.
5328
+ * 7 PQRS or 7 PRS on a phone or remote control.
5329
+ */ "Numpad7"] = 91] = "Numpad7";
5310
5330
  Keys[Keys[/**
5311
- * 9 PgUp on a keyboard.
5312
- * 9 WXYZ or 9 WXY on a phone or remote control.
5313
- */ "Numpad9"] = 93] = "Numpad9";
5331
+ * 8 on a keyboard.
5332
+ * 8 TUV on a phone or remote control.
5333
+ */ "Numpad8"] = 92] = "Numpad8";
5334
+ Keys[Keys[/**
5335
+ * 9 PgUp on a keyboard.
5336
+ * 9 WXYZ or 9 WXY on a phone or remote control.
5337
+ */ "Numpad9"] = 93] = "Numpad9";
5314
5338
  Keys[Keys[/** + */ "NumpadAdd"] = 94] = "NumpadAdd";
5315
5339
  Keys[Keys[/** Found on the Microsoft Natural Keyboard. */ "NumpadBackspace"] = 95] = "NumpadBackspace";
5316
5340
  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";
@@ -5326,16 +5350,16 @@ SystemInfo._initialize();
5326
5350
  Keys[Keys[/** MR Replace the current entry with the value stored in memory. */ "NumpadMemoryRecall"] = 106] = "NumpadMemoryRecall";
5327
5351
  Keys[Keys[/** MS Replace the value stored in memory with the current entry. */ "NumpadMemoryStore"] = 107] = "NumpadMemoryStore";
5328
5352
  Keys[Keys[/** M- Subtract current entry from the value stored in memory. */ "NumpadMemorySubtract"] = 108] = "NumpadMemorySubtract";
5329
- Keys[Keys[/**
5330
- * * on a keyboard. For use with numpads that provide mathematical operations (+, -, * and /).
5331
- * Use "NumpadStar" for the * key on phones and remote controls.
5332
- */ "NumpadMultiply"] = 109] = "NumpadMultiply";
5353
+ Keys[Keys[/**
5354
+ * * on a keyboard. For use with numpads that provide mathematical operations (+, -, * and /).
5355
+ * Use "NumpadStar" for the * key on phones and remote controls.
5356
+ */ "NumpadMultiply"] = 109] = "NumpadMultiply";
5333
5357
  Keys[Keys[/** ( Found on the Microsoft Natural Keyboard. */ "NumpadParenLeft"] = 110] = "NumpadParenLeft";
5334
5358
  Keys[Keys[/** ) Found on the Microsoft Natural Keyboard. */ "NumpadParenRight"] = 111] = "NumpadParenRight";
5335
5359
  Keys[Keys[/**
5336
- * * on a phone or remote control device. This key is typically found below the 7 key and to the left of the 0 key.
5337
- * Use "NumpadMultiply" for the * key on numeric keypads.
5338
- */ "NumpadStar"] = 112] = "NumpadStar";
5360
+ * * on a phone or remote control device. This key is typically found below the 7 key and to the left of the 0 key.
5361
+ * Use "NumpadMultiply" for the * key on numeric keypads.
5362
+ */ "NumpadStar"] = 112] = "NumpadStar";
5339
5363
  Keys[Keys[/** - */ "NumpadSubtract"] = 113] = "NumpadSubtract";
5340
5364
  Keys[Keys[/** Esc or ⎋. */ "Escape"] = 114] = "Escape";
5341
5365
  Keys[Keys[/** F1 */ "F1"] = 115] = "F1";
@@ -6010,7 +6034,9 @@ var Collider = /*#__PURE__*/ function(Component) {
6010
6034
  */ _proto._onDisable = function _onDisable() {
6011
6035
  this.engine.physicsManager._removeCollider(this);
6012
6036
  };
6013
- _proto._onDestroy = function _onDestroy() {
6037
+ /**
6038
+ * @internal
6039
+ */ _proto._onDestroy = function _onDestroy() {
6014
6040
  Component.prototype._onDestroy.call(this);
6015
6041
  this.clearShapes();
6016
6042
  this._nativeCollider.destroy();
@@ -7860,7 +7886,10 @@ var DynamicColliderConstraints;
7860
7886
  return _this;
7861
7887
  }
7862
7888
  var _proto = Light.prototype;
7863
- _proto._getLightColor = function _getLightColor() {
7889
+ /**
7890
+ * Light Color, include intensity.
7891
+ * @internal
7892
+ */ _proto._getLightIntensityColor = function _getLightIntensityColor() {
7864
7893
  this._lightColor.r = this.color.r * this.intensity;
7865
7894
  this._lightColor.g = this.color.g * this.intensity;
7866
7895
  this._lightColor.b = this.color.b * this.intensity;
@@ -7930,15 +7959,21 @@ __decorate([
7930
7959
  var cullingMaskStart = lightIndex * 2;
7931
7960
  var colorStart = lightIndex * 3;
7932
7961
  var directionStart = lightIndex * 3;
7933
- var lightColor = this._getLightColor();
7962
+ var lightColor = this._getLightIntensityColor();
7934
7963
  var direction = this.direction;
7935
7964
  var data = DirectLight._combinedData;
7936
7965
  var cullingMask = this.cullingMask;
7937
7966
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
7938
7967
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
7939
- data.color[colorStart] = lightColor.r;
7940
- data.color[colorStart + 1] = lightColor.g;
7941
- data.color[colorStart + 2] = lightColor.b;
7968
+ if (this.engine.settings.colorSpace === ColorSpace.Linear) {
7969
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
7970
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
7971
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
7972
+ } else {
7973
+ data.color[colorStart] = lightColor.r;
7974
+ data.color[colorStart + 1] = lightColor.g;
7975
+ data.color[colorStart + 2] = lightColor.b;
7976
+ }
7942
7977
  data.direction[directionStart] = direction.x;
7943
7978
  data.direction[directionStart + 1] = direction.y;
7944
7979
  data.direction[directionStart + 2] = direction.z;
@@ -8027,15 +8062,21 @@ __decorate([
8027
8062
  var colorStart = lightIndex * 3;
8028
8063
  var positionStart = lightIndex * 3;
8029
8064
  var distanceStart = lightIndex;
8030
- var lightColor = this._getLightColor();
8065
+ var lightColor = this._getLightIntensityColor();
8031
8066
  var lightPosition = this.position;
8032
8067
  var data = PointLight._combinedData;
8033
8068
  var cullingMask = this.cullingMask;
8034
8069
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
8035
8070
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
8036
- data.color[colorStart] = lightColor.r;
8037
- data.color[colorStart + 1] = lightColor.g;
8038
- data.color[colorStart + 2] = lightColor.b;
8071
+ if (this.engine.settings.colorSpace === ColorSpace.Linear) {
8072
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
8073
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
8074
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
8075
+ } else {
8076
+ data.color[colorStart] = lightColor.r;
8077
+ data.color[colorStart + 1] = lightColor.g;
8078
+ data.color[colorStart + 2] = lightColor.b;
8079
+ }
8039
8080
  data.position[positionStart] = lightPosition.x;
8040
8081
  data.position[positionStart + 1] = lightPosition.y;
8041
8082
  data.position[positionStart + 2] = lightPosition.z;
@@ -8128,16 +8169,22 @@ __decorate([
8128
8169
  var distanceStart = lightIndex;
8129
8170
  var penumbraCosStart = lightIndex;
8130
8171
  var angleCosStart = lightIndex;
8131
- var color = this._getLightColor();
8172
+ var lightColor = this._getLightIntensityColor();
8132
8173
  var position = this.position;
8133
8174
  var direction = this.direction;
8134
8175
  var data = SpotLight._combinedData;
8135
8176
  var cullingMask = this.cullingMask;
8136
8177
  data.cullingMask[cullingMaskStart] = cullingMask & 65535;
8137
8178
  data.cullingMask[cullingMaskStart + 1] = cullingMask >>> 16 & 65535;
8138
- data.color[colorStart] = color.r;
8139
- data.color[colorStart + 1] = color.g;
8140
- data.color[colorStart + 2] = color.b;
8179
+ if (this.engine.settings.colorSpace === ColorSpace.Linear) {
8180
+ data.color[colorStart] = Color$1.gammaToLinearSpace(lightColor.r);
8181
+ data.color[colorStart + 1] = Color$1.gammaToLinearSpace(lightColor.g);
8182
+ data.color[colorStart + 2] = Color$1.gammaToLinearSpace(lightColor.b);
8183
+ } else {
8184
+ data.color[colorStart] = lightColor.r;
8185
+ data.color[colorStart + 1] = lightColor.g;
8186
+ data.color[colorStart + 2] = lightColor.b;
8187
+ }
8141
8188
  data.position[positionStart] = position.x;
8142
8189
  data.position[positionStart + 1] = position.y;
8143
8190
  data.position[positionStart + 2] = position.z;
@@ -8780,6 +8827,7 @@ __decorate([
8780
8827
  _proto.cloneTo = function cloneTo(target) {
8781
8828
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8782
8829
  Object.assign(target._macroMap, this._macroMap);
8830
+ var referCount = target._getReferCount();
8783
8831
  var propertyValueMap = this._propertyValueMap;
8784
8832
  var targetPropertyValueMap = target._propertyValueMap;
8785
8833
  var keys = Object.keys(propertyValueMap);
@@ -8791,6 +8839,7 @@ __decorate([
8791
8839
  targetPropertyValueMap[k] = property;
8792
8840
  } else if (_instanceof(property, Texture)) {
8793
8841
  targetPropertyValueMap[k] = property;
8842
+ referCount > 0 && property._addReferCount(referCount);
8794
8843
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8795
8844
  targetPropertyValueMap[k] = property.slice();
8796
8845
  } else {
@@ -9495,11 +9544,11 @@ var camera_declare = "#define GLSLIFY 1\nuniform vec3 camera_Position;"; // esli
9495
9544
 
9496
9545
  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
9497
9546
 
9498
- 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
9547
+ 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
9499
9548
 
9500
9549
  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
9501
9550
 
9502
- var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
9551
+ var color_share = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nvarying vec4 v_color;\n#endif\n"; // eslint-disable-line
9503
9552
 
9504
9553
  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
9505
9554
 
@@ -9519,7 +9568,7 @@ var blendShape_input = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_BLENDSHAPE\n#ifde
9519
9568
 
9520
9569
  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
9521
9570
 
9522
- var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_HAS_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
9571
+ var color_vert = "#define GLSLIFY 1\n#ifdef RENDERER_ENABLE_VERTEXCOLOR\nv_color=COLOR_0;\n#endif\n"; // eslint-disable-line
9523
9572
 
9524
9573
  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
9525
9574
 
@@ -9539,11 +9588,11 @@ var light_frag_define = "#define GLSLIFY 1\n#ifdef SCENE_DIRECT_LIGHT_COUNT\nstr
9539
9588
 
9540
9589
  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
9541
9590
 
9542
- 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
9591
+ 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
9543
9592
 
9544
9593
  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
9545
9594
 
9546
- 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
9595
+ 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
9547
9596
 
9548
9597
  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
9549
9598
 
@@ -9577,9 +9626,9 @@ var noise_simplex_3D_grad = "#define GLSLIFY 1\nfloat simplex(vec3 v,out vec3 gr
9577
9626
 
9578
9627
  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
9579
9628
 
9580
- 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
9629
+ 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
9581
9630
 
9582
- 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
9631
+ 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
9583
9632
 
9584
9633
  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
9585
9634
 
@@ -9587,7 +9636,7 @@ var direct_irradiance_frag_define = "#define GLSLIFY 1\n#include <ShadowFragment
9587
9636
 
9588
9637
  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
9589
9638
 
9590
- 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
9639
+ 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
9591
9640
 
9592
9641
  var PBRShaderLib = {
9593
9642
  pbr_frag_define: pbr_frag_define,
@@ -9616,7 +9665,7 @@ var ShadowLib = {
9616
9665
  ShadowVertex: ShadowVertex
9617
9666
  };
9618
9667
 
9619
- 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
9668
+ 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
9620
9669
 
9621
9670
  var ShaderLib = _extends({
9622
9671
  common: common,
@@ -10767,6 +10816,14 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10767
10816
  };
10768
10817
  /**
10769
10818
  * @internal
10819
+ */ _proto._cloneTo = function _cloneTo(target) {
10820
+ var materials = this._materials;
10821
+ for(var i = 0, n = materials.length; i < n; i++){
10822
+ target._setMaterial(i, materials[i]);
10823
+ }
10824
+ };
10825
+ /**
10826
+ * @internal
10770
10827
  */ _proto._onDestroy = function _onDestroy() {
10771
10828
  Component.prototype._onDestroy.call(this);
10772
10829
  this.entity.transform._updateFlagManager.removeListener(this._onTransformChanged);
@@ -10777,14 +10834,18 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10777
10834
  (_materials_i = materials[i]) == null ? void 0 : _materials_i._addReferCount(-1);
10778
10835
  }
10779
10836
  };
10780
- _proto._updateShaderData = function _updateShaderData(context) {
10837
+ /**
10838
+ * @internal
10839
+ */ _proto._updateShaderData = function _updateShaderData(context) {
10781
10840
  var entity = this.entity;
10782
10841
  var worldMatrix = entity.transform.worldMatrix;
10783
10842
  this._updateTransformShaderData(context, worldMatrix);
10784
10843
  var layer = entity.layer;
10785
10844
  this._rendererLayer.set(layer & 65535, layer >>> 16 & 65535, 0, 0);
10786
10845
  };
10787
- _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
10846
+ /**
10847
+ * @internal
10848
+ */ _proto._updateTransformShaderData = function _updateTransformShaderData(context, worldMatrix) {
10788
10849
  var shaderData = this.shaderData;
10789
10850
  var virtualCamera = context.virtualCamera;
10790
10851
  var mvMatrix = this._mvMatrix;
@@ -10803,14 +10864,22 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10803
10864
  shaderData.setMatrix(Renderer._mvInvMatrixProperty, mvInvMatrix);
10804
10865
  shaderData.setMatrix(Renderer._normalMatrixProperty, normalMatrix);
10805
10866
  };
10806
- _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
10867
+ /**
10868
+ * @internal
10869
+ */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
10807
10870
  this.entity.transform._updateFlagManager.addListener(this._onTransformChanged);
10808
10871
  };
10809
- _proto._updateBounds = function _updateBounds(worldBounds) {};
10810
- _proto._render = function _render(context) {
10872
+ /**
10873
+ * @internal
10874
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {};
10875
+ /**
10876
+ * @internal
10877
+ */ _proto._render = function _render(context) {
10811
10878
  throw "not implement";
10812
10879
  };
10813
- _proto._createInstanceMaterial = function _createInstanceMaterial(material, index) {
10880
+ /**
10881
+ * @internal
10882
+ */ _proto._createInstanceMaterial = function _createInstanceMaterial(material, index) {
10814
10883
  var insMaterial = material.clone();
10815
10884
  insMaterial.name = insMaterial.name + "(Instance)";
10816
10885
  material._addReferCount(-1);
@@ -10833,7 +10902,9 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10833
10902
  materials[index] = material;
10834
10903
  }
10835
10904
  };
10836
- _proto._onTransformChanged = function _onTransformChanged(type) {
10905
+ /**
10906
+ * @internal
10907
+ */ _proto._onTransformChanged = function _onTransformChanged(type) {
10837
10908
  this._dirtyUpdateFlag |= 0x1;
10838
10909
  };
10839
10910
  _create_class(Renderer1, [
@@ -10946,7 +11017,7 @@ __decorate([
10946
11017
  ignoreClone
10947
11018
  ], Renderer.prototype, "_overrideUpdate", void 0);
10948
11019
  __decorate([
10949
- shallowClone
11020
+ ignoreClone
10950
11021
  ], Renderer.prototype, "_materials", void 0);
10951
11022
  __decorate([
10952
11023
  ignoreClone
@@ -11140,8 +11211,10 @@ SimpleSpriteAssembler = __decorate([
11140
11211
  _this = Renderer.call(this, entity) || this;
11141
11212
  /** The mask layers the sprite mask influence to. */ _this.influenceLayers = SpriteMaskLayer.Everything;
11142
11213
  _this._sprite = null;
11143
- _this._width = undefined;
11144
- _this._height = undefined;
11214
+ _this._automaticWidth = 0;
11215
+ _this._automaticHeight = 0;
11216
+ _this._customWidth = undefined;
11217
+ _this._customHeight = undefined;
11145
11218
  _this._flipX = false;
11146
11219
  _this._flipY = false;
11147
11220
  _this._alphaCutoff = 0.5;
@@ -11156,30 +11229,33 @@ SimpleSpriteAssembler = __decorate([
11156
11229
  /**
11157
11230
  * @internal
11158
11231
  */ _proto._cloneTo = function _cloneTo(target) {
11232
+ Renderer.prototype._cloneTo.call(this, target);
11159
11233
  target.sprite = this._sprite;
11160
11234
  };
11161
- _proto._updateBounds = function _updateBounds(worldBounds) {
11162
- var _this_sprite;
11163
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
11235
+ /**
11236
+ * @internal
11237
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
11238
+ if (this.sprite) {
11239
+ SimpleSpriteAssembler.updatePositions(this);
11240
+ } else {
11164
11241
  worldBounds.min.set(0, 0, 0);
11165
11242
  worldBounds.max.set(0, 0, 0);
11166
- } else {
11167
- SimpleSpriteAssembler.updatePositions(this);
11168
11243
  }
11169
11244
  };
11170
11245
  /**
11246
+ * @internal
11171
11247
  * @inheritdoc
11172
11248
  */ _proto._render = function _render(context) {
11173
11249
  var _this_sprite;
11174
11250
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
11175
11251
  return;
11176
11252
  }
11177
- // Update position.
11253
+ // Update position
11178
11254
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
11179
11255
  SimpleSpriteAssembler.updatePositions(this);
11180
11256
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
11181
11257
  }
11182
- // Update uv.
11258
+ // Update uv
11183
11259
  if (this._dirtyUpdateFlag & 0x2) {
11184
11260
  SimpleSpriteAssembler.updateUVs(this);
11185
11261
  this._dirtyUpdateFlag &= ~0x2;
@@ -11193,19 +11269,39 @@ SimpleSpriteAssembler = __decorate([
11193
11269
  this._maskElement = renderElement;
11194
11270
  };
11195
11271
  /**
11272
+ * @internal
11196
11273
  * @inheritdoc
11197
11274
  */ _proto._onDestroy = function _onDestroy() {
11198
- var _this__sprite;
11199
11275
  Renderer.prototype._onDestroy.call(this);
11200
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
11276
+ var sprite = this._sprite;
11277
+ if (sprite) {
11278
+ sprite._addReferCount(-1);
11279
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
11280
+ }
11201
11281
  this._sprite = null;
11202
11282
  this._verticesData = null;
11203
11283
  };
11284
+ _proto._calDefaultSize = function _calDefaultSize() {
11285
+ var sprite = this._sprite;
11286
+ if (sprite) {
11287
+ this._automaticWidth = sprite.width;
11288
+ this._automaticHeight = sprite.height;
11289
+ } else {
11290
+ this._automaticWidth = this._automaticHeight = 0;
11291
+ }
11292
+ this._dirtyUpdateFlag &= ~0x4;
11293
+ };
11204
11294
  _proto._onSpriteChange = function _onSpriteChange(type) {
11205
11295
  switch(type){
11206
11296
  case SpriteModifyFlags.texture:
11207
11297
  this.shaderData.setTexture(SpriteMask._textureProperty, this.sprite.texture);
11208
11298
  break;
11299
+ case SpriteModifyFlags.size:
11300
+ this._dirtyUpdateFlag |= 0x4;
11301
+ if (this._customWidth === undefined || this._customHeight === undefined) {
11302
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11303
+ }
11304
+ break;
11209
11305
  case SpriteModifyFlags.region:
11210
11306
  case SpriteModifyFlags.atlasRegionOffset:
11211
11307
  this._dirtyUpdateFlag |= 0x3;
@@ -11213,22 +11309,31 @@ SimpleSpriteAssembler = __decorate([
11213
11309
  case SpriteModifyFlags.atlasRegion:
11214
11310
  this._dirtyUpdateFlag |= 0x2;
11215
11311
  break;
11312
+ case SpriteModifyFlags.pivot:
11313
+ this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11314
+ break;
11216
11315
  }
11217
11316
  };
11218
11317
  _create_class(SpriteMask, [
11219
11318
  {
11220
11319
  key: "width",
11221
11320
  get: /**
11222
- * Render width.
11321
+ * Render width (in world coordinates).
11322
+ *
11323
+ * @remarks
11324
+ * If width is set, return the set value,
11325
+ * otherwise return `SpriteMask.sprite.width`.
11223
11326
  */ function get() {
11224
- if (this._width === undefined && this._sprite) {
11225
- this.width = this._sprite.width;
11327
+ if (this._customWidth !== undefined) {
11328
+ return this._customWidth;
11329
+ } else {
11330
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
11331
+ return this._automaticWidth;
11226
11332
  }
11227
- return this._width;
11228
11333
  },
11229
11334
  set: function set(value) {
11230
- if (this._width !== value) {
11231
- this._width = value;
11335
+ if (this._customWidth !== value) {
11336
+ this._customWidth = value;
11232
11337
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11233
11338
  }
11234
11339
  }
@@ -11236,16 +11341,22 @@ SimpleSpriteAssembler = __decorate([
11236
11341
  {
11237
11342
  key: "height",
11238
11343
  get: /**
11239
- * Render height.
11344
+ * Render height (in world coordinates).
11345
+ *
11346
+ * @remarks
11347
+ * If height is set, return the set value,
11348
+ * otherwise return `SpriteMask.sprite.height`.
11240
11349
  */ function get() {
11241
- if (this._height === undefined && this._sprite) {
11242
- this.height = this._sprite.height;
11350
+ if (this._customHeight !== undefined) {
11351
+ return this._customHeight;
11352
+ } else {
11353
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
11354
+ return this._automaticHeight;
11243
11355
  }
11244
- return this._height;
11245
11356
  },
11246
11357
  set: function set(value) {
11247
- if (this._height !== value) {
11248
- this._height = value;
11358
+ if (this._customHeight !== value) {
11359
+ this._customHeight = value;
11249
11360
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
11250
11361
  }
11251
11362
  }
@@ -11288,10 +11399,14 @@ SimpleSpriteAssembler = __decorate([
11288
11399
  set: function set(value) {
11289
11400
  var lastSprite = this._sprite;
11290
11401
  if (lastSprite !== value) {
11291
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
11402
+ if (lastSprite) {
11403
+ lastSprite._addReferCount(-1);
11404
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
11405
+ }
11406
+ this._dirtyUpdateFlag |= 0x7;
11292
11407
  if (value) {
11408
+ value._addReferCount(1);
11293
11409
  value._updateFlagManager.addListener(this._onSpriteChange);
11294
- this._dirtyUpdateFlag |= 0x3;
11295
11410
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
11296
11411
  } else {
11297
11412
  this.shaderData.setTexture(SpriteMask._textureProperty, null);
@@ -11331,10 +11446,16 @@ __decorate([
11331
11446
  ], SpriteMask.prototype, "_sprite", void 0);
11332
11447
  __decorate([
11333
11448
  ignoreClone
11334
- ], SpriteMask.prototype, "_width", void 0);
11449
+ ], SpriteMask.prototype, "_automaticWidth", void 0);
11335
11450
  __decorate([
11336
11451
  ignoreClone
11337
- ], SpriteMask.prototype, "_height", void 0);
11452
+ ], SpriteMask.prototype, "_automaticHeight", void 0);
11453
+ __decorate([
11454
+ assignmentClone
11455
+ ], SpriteMask.prototype, "_customWidth", void 0);
11456
+ __decorate([
11457
+ assignmentClone
11458
+ ], SpriteMask.prototype, "_customHeight", void 0);
11338
11459
  __decorate([
11339
11460
  assignmentClone
11340
11461
  ], SpriteMask.prototype, "_flipX", void 0);
@@ -11352,7 +11473,9 @@ var /**
11352
11473
  */ SpriteMaskUpdateFlags;
11353
11474
  (function(SpriteMaskUpdateFlags) {
11354
11475
  SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
11355
- SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x3] = "All";
11476
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
11477
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
11478
+ SpriteMaskUpdateFlags[SpriteMaskUpdateFlags[/** All. */ "All"] = 0x7] = "All";
11356
11479
  })(SpriteMaskUpdateFlags || (SpriteMaskUpdateFlags = {}));
11357
11480
 
11358
11481
  /**
@@ -11617,7 +11740,9 @@ var BufferUtil = /*#__PURE__*/ function() {
11617
11740
  var platformBuffer = this._engine._hardwareRenderer.createPlatformBuffer(this._type, this._byteLength, this._bufferUsage);
11618
11741
  this._platformBuffer = platformBuffer;
11619
11742
  };
11620
- _proto._onDestroy = function _onDestroy() {
11743
+ /**
11744
+ * @internal
11745
+ */ _proto._onDestroy = function _onDestroy() {
11621
11746
  GraphicsResource.prototype._onDestroy.call(this);
11622
11747
  this._platformBuffer.destroy();
11623
11748
  };
@@ -11796,10 +11921,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11796
11921
  /**
11797
11922
  * @internal
11798
11923
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11799
- if (this._getReferCount() > 0) {
11800
- var lastBinding = this._vertexBufferBindings[index];
11801
- lastBinding && lastBinding._buffer._addReferCount(-1);
11802
- binding._buffer._addReferCount(1);
11924
+ var referCount = this._getReferCount();
11925
+ if (referCount > 0) {
11926
+ var _this__vertexBufferBindings_index;
11927
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addReferCount(-referCount);
11928
+ binding == null ? void 0 : binding._buffer._addReferCount(referCount);
11803
11929
  }
11804
11930
  this._vertexBufferBindings[index] = binding;
11805
11931
  this._bufferStructChanged = true;
@@ -11811,11 +11937,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11811
11937
  this._bufferStructChanged = false;
11812
11938
  };
11813
11939
  _proto._addReferCount = function _addReferCount(value) {
11940
+ var _this__indexBufferBinding;
11814
11941
  GraphicsResource.prototype._addReferCount.call(this, value);
11815
11942
  var vertexBufferBindings = this._vertexBufferBindings;
11816
11943
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11817
11944
  vertexBufferBindings[i]._buffer._addReferCount(value);
11818
11945
  }
11946
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addReferCount(value);
11819
11947
  };
11820
11948
  _proto._rebuild = function _rebuild() {
11821
11949
  this._engine._hardwareRenderer.createPlatformPrimitive(this);
@@ -11830,14 +11958,23 @@ var BufferUtil = /*#__PURE__*/ function() {
11830
11958
  this._vertexElementMap = null;
11831
11959
  this._platformPrimitive.destroy();
11832
11960
  };
11833
- _proto._setVertexElements = function _setVertexElements(elements) {
11961
+ /**
11962
+ * @internal
11963
+ */ _proto._setVertexElements = function _setVertexElements(elements) {
11834
11964
  this._clearVertexElements();
11835
11965
  for(var i = 0, n = elements.length; i < n; i++){
11836
11966
  this._addVertexElement(elements[i]);
11837
11967
  }
11838
11968
  };
11839
- _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11969
+ /**
11970
+ * @internal
11971
+ */ _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11840
11972
  var lastBinding = this._indexBufferBinding;
11973
+ var referCount = this._getReferCount();
11974
+ if (referCount > 0) {
11975
+ lastBinding == null ? void 0 : lastBinding.buffer._addReferCount(-referCount);
11976
+ binding == null ? void 0 : binding.buffer._addReferCount(referCount);
11977
+ }
11841
11978
  if (binding) {
11842
11979
  this._indexBufferBinding = binding;
11843
11980
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -12153,6 +12290,7 @@ var MeshModifyFlags;
12153
12290
  var subDataDirtyFlags = this._subDataDirtyFlags;
12154
12291
  var blendShapeFloatStride = this._vertexElementCount * 3;
12155
12292
  var blendShapeByteStride = blendShapeFloatStride * 4;
12293
+ var bufferOffset = this._bufferBindingOffset;
12156
12294
  // @todo: should fix bug when dataChangedFlag is true
12157
12295
  for(var i = 0, n = blendShapes.length; i < n; i++){
12158
12296
  var dataChangedFlag = subDataDirtyFlags[i];
@@ -12170,7 +12308,7 @@ var MeshModifyFlags;
12170
12308
  var offset = indexInBuffer * blendShapeFloatStride;
12171
12309
  var storeInfo = storeInfos[i];
12172
12310
  storeInfo || (storeInfos[i] = storeInfo = new Vector2());
12173
- storeInfo.set(bufferIndex + 1, indexInBuffer * blendShapeByteStride); // BlendShape buffer is start from 1
12311
+ storeInfo.set(bufferOffset + bufferIndex, indexInBuffer * blendShapeByteStride); // BufferOffset is mesh vertexBuffer offset
12174
12312
  var deltaPositions = endFrame.deltaPositions;
12175
12313
  for(var j = 0; j < vertexCount; j++){
12176
12314
  var start = offset + bufferFloatStride * j;
@@ -12974,7 +13112,9 @@ var MeshModifyFlags;
12974
13112
  }
12975
13113
  this.setTangents(tangents);
12976
13114
  };
12977
- _proto._onDestroy = function _onDestroy() {
13115
+ /**
13116
+ * @internal
13117
+ */ _proto._onDestroy = function _onDestroy() {
12978
13118
  Mesh.prototype._onDestroy.call(this);
12979
13119
  this._readable && this._releaseCache();
12980
13120
  };
@@ -13445,24 +13585,31 @@ var VertexChangedFlags;
13445
13585
  function MeshRenderer(entity) {
13446
13586
  var _this;
13447
13587
  _this = Renderer.call(this, entity) || this;
13588
+ _this._enableVertexColor = false;
13448
13589
  _this._onMeshChanged = _this._onMeshChanged.bind(_assert_this_initialized(_this));
13449
13590
  return _this;
13450
13591
  }
13451
13592
  var _proto = MeshRenderer.prototype;
13452
- _proto._onDestroy = function _onDestroy() {
13593
+ /**
13594
+ * @internal
13595
+ */ _proto._onDestroy = function _onDestroy() {
13453
13596
  Renderer.prototype._onDestroy.call(this);
13454
13597
  var mesh = this._mesh;
13455
13598
  if (mesh && !mesh.destroyed) {
13456
13599
  mesh._addReferCount(-1);
13600
+ mesh._updateFlagManager.removeListener(this._onMeshChanged);
13457
13601
  this._mesh = null;
13458
13602
  }
13459
13603
  };
13460
13604
  /**
13461
13605
  * @internal
13462
13606
  */ _proto._cloneTo = function _cloneTo(target) {
13607
+ Renderer.prototype._cloneTo.call(this, target);
13463
13608
  target.mesh = this._mesh;
13464
13609
  };
13465
- _proto._updateBounds = function _updateBounds(worldBounds) {
13610
+ /**
13611
+ * @internal
13612
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
13466
13613
  var mesh = this._mesh;
13467
13614
  if (mesh) {
13468
13615
  var localBounds = mesh.bounds;
@@ -13473,7 +13620,9 @@ var VertexChangedFlags;
13473
13620
  worldBounds.max.set(0, 0, 0);
13474
13621
  }
13475
13622
  };
13476
- _proto._render = function _render(context) {
13623
+ /**
13624
+ * @internal
13625
+ */ _proto._render = function _render(context) {
13477
13626
  var mesh = this._mesh;
13478
13627
  if (mesh) {
13479
13628
  if (this._dirtyUpdateFlag & 0x2) {
@@ -13483,7 +13632,7 @@ var VertexChangedFlags;
13483
13632
  shaderData.disableMacro(MeshRenderer._uv1Macro);
13484
13633
  shaderData.disableMacro(MeshRenderer._normalMacro);
13485
13634
  shaderData.disableMacro(MeshRenderer._tangentMacro);
13486
- shaderData.disableMacro(MeshRenderer._vertexColorMacro);
13635
+ shaderData.disableMacro(MeshRenderer._enableVertexColorMacro);
13487
13636
  for(var i = 0, n = vertexElements.length; i < n; i++){
13488
13637
  switch(vertexElements[i].semantic){
13489
13638
  case "TEXCOORD_0":
@@ -13499,7 +13648,7 @@ var VertexChangedFlags;
13499
13648
  shaderData.enableMacro(MeshRenderer._tangentMacro);
13500
13649
  break;
13501
13650
  case "COLOR_0":
13502
- shaderData.enableMacro(MeshRenderer._vertexColorMacro);
13651
+ this._enableVertexColor && shaderData.enableMacro(MeshRenderer._enableVertexColorMacro);
13503
13652
  break;
13504
13653
  }
13505
13654
  }
@@ -13550,6 +13699,20 @@ var VertexChangedFlags;
13550
13699
  this._setMesh(value);
13551
13700
  }
13552
13701
  }
13702
+ },
13703
+ {
13704
+ key: "enableVertexColor",
13705
+ get: /**
13706
+ * Whether enable vertex color.
13707
+ */ function get() {
13708
+ return this._enableVertexColor;
13709
+ },
13710
+ set: function set(value) {
13711
+ if (value !== this._enableVertexColor) {
13712
+ this._dirtyUpdateFlag |= 0x2;
13713
+ this._enableVertexColor = value;
13714
+ }
13715
+ }
13553
13716
  }
13554
13717
  ]);
13555
13718
  return MeshRenderer;
@@ -13567,7 +13730,7 @@ var VertexChangedFlags;
13567
13730
  MeshRenderer._tangentMacro = ShaderMacro.getByName("RENDERER_HAS_TANGENT");
13568
13731
  })();
13569
13732
  (function() {
13570
- MeshRenderer._vertexColorMacro = ShaderMacro.getByName("RENDERER_HAS_VERTEXCOLOR");
13733
+ MeshRenderer._enableVertexColorMacro = ShaderMacro.getByName("RENDERER_ENABLE_VERTEXCOLOR");
13571
13734
  })();
13572
13735
  __decorate([
13573
13736
  ignoreClone
@@ -13599,7 +13762,7 @@ var /**
13599
13762
  // Limit size to 256 to avoid some problem:
13600
13763
  // 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!
13601
13764
  // 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.
13602
- maxVertexUniformVectors = Math.min(maxVertexUniformVectors, 256);
13765
+ maxVertexUniformVectors = Math.min(maxVertexUniformVectors, rhi._options._maxAllowSkinUniformVectorCount);
13603
13766
  _this._maxVertexUniformVectors = maxVertexUniformVectors;
13604
13767
  _this._onLocalBoundsChanged = _this._onLocalBoundsChanged.bind(_assert_this_initialized(_this));
13605
13768
  var localBounds = _this._localBounds;
@@ -13634,7 +13797,9 @@ var /**
13634
13797
  }
13635
13798
  }
13636
13799
  };
13637
- _proto._updateShaderData = function _updateShaderData(context) {
13800
+ /**
13801
+ * @internal
13802
+ */ _proto._updateShaderData = function _updateShaderData(context) {
13638
13803
  var entity = this.entity;
13639
13804
  var worldMatrix = this._rootBone ? this._rootBone.transform.worldMatrix : entity.transform.worldMatrix;
13640
13805
  this._updateTransformShaderData(context, worldMatrix);
@@ -13660,6 +13825,7 @@ var /**
13660
13825
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13661
13826
  this._jointTexture = new Texture2D(engine, 4, jointCount, TextureFormat.R32G32B32A32, false);
13662
13827
  this._jointTexture.filterMode = TextureFilterMode.Point;
13828
+ this._jointTexture.isGCIgnored = true;
13663
13829
  }
13664
13830
  shaderData.disableMacro("RENDERER_JOINTS_NUM");
13665
13831
  shaderData.enableMacro("RENDERER_USE_JOINT_TEXTURE");
@@ -13685,14 +13851,26 @@ var /**
13685
13851
  };
13686
13852
  /**
13687
13853
  * @internal
13854
+ */ _proto._onDestroy = function _onDestroy() {
13855
+ var _this_rootBone, _this__jointTexture;
13856
+ MeshRenderer.prototype._onDestroy.call(this);
13857
+ (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13858
+ (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13859
+ };
13860
+ /**
13861
+ * @internal
13688
13862
  */ _proto._cloneTo = function _cloneTo(target) {
13689
13863
  MeshRenderer.prototype._cloneTo.call(this, target);
13690
13864
  this._blendShapeWeights && (target._blendShapeWeights = this._blendShapeWeights.slice());
13691
13865
  };
13692
- _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
13866
+ /**
13867
+ * @internal
13868
+ */ _proto._registerEntityTransformListener = function _registerEntityTransformListener() {
13693
13869
  // Cancel register listener to entity transform.
13694
13870
  };
13695
- _proto._updateBounds = function _updateBounds(worldBounds) {
13871
+ /**
13872
+ * @internal
13873
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
13696
13874
  if (this._rootBone) {
13697
13875
  var localBounds = this._localBounds;
13698
13876
  var worldMatrix = this._rootBone.transform.worldMatrix;
@@ -15145,14 +15323,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
15145
15323
  _proto._createMesh = function _createMesh(engine, index) {
15146
15324
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
15147
15325
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
15326
+ mesh.isGCIgnored = true;
15148
15327
  var vertexElements = [];
15149
15328
  var vertexStride = this.createVertexElements(vertexElements);
15150
15329
  // vertices
15151
- this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
15330
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
15331
+ vertexBuffer.isGCIgnored = true;
15152
15332
  // indices
15153
- this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 3, BufferUsage.Dynamic);
15154
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
15155
- mesh.setIndexBufferBinding(this._indiceBuffers[index], IndexFormat.UInt16);
15333
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, BufferUsage.Dynamic);
15334
+ indiceBuffer.isGCIgnored = true;
15335
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
15336
+ mesh.setIndexBufferBinding(indiceBuffer, IndexFormat.UInt16);
15156
15337
  mesh.setVertexElements(vertexElements);
15157
15338
  return mesh;
15158
15339
  };
@@ -15436,6 +15617,12 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15436
15617
  var _proto = Sky.prototype;
15437
15618
  /**
15438
15619
  * @internal
15620
+ */ _proto.destroy = function destroy() {
15621
+ this.mesh = null;
15622
+ this.material = null;
15623
+ };
15624
+ /**
15625
+ * @internal
15439
15626
  */ _proto._render = function _render(context) {
15440
15627
  var _this = this, material = _this.material, mesh = _this.mesh;
15441
15628
  if (!material) {
@@ -15476,6 +15663,40 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15476
15663
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
15477
15664
  cameraShaderData.setMatrix(RenderContext.vpMatrixProperty, originViewProjMatrix);
15478
15665
  };
15666
+ _create_class(Sky, [
15667
+ {
15668
+ key: "material",
15669
+ get: /**
15670
+ * Material of the sky.
15671
+ */ function get() {
15672
+ return this._material;
15673
+ },
15674
+ set: function set(value) {
15675
+ if (this._material !== value) {
15676
+ var _this__material;
15677
+ value == null ? void 0 : value._addReferCount(1);
15678
+ (_this__material = this._material) == null ? void 0 : _this__material._addReferCount(-1);
15679
+ this._material = value;
15680
+ }
15681
+ }
15682
+ },
15683
+ {
15684
+ key: "mesh",
15685
+ get: /**
15686
+ * Mesh of the sky.
15687
+ */ function get() {
15688
+ return this._mesh;
15689
+ },
15690
+ set: function set(value) {
15691
+ if (this._mesh !== value) {
15692
+ var _this__mesh;
15693
+ value == null ? void 0 : value._addReferCount(1);
15694
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addReferCount(-1);
15695
+ this._mesh = value;
15696
+ }
15697
+ }
15698
+ }
15699
+ ]);
15479
15700
  return Sky;
15480
15701
  }();
15481
15702
  (function() {
@@ -15511,9 +15732,19 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15511
15732
  var _proto = Background.prototype;
15512
15733
  /**
15513
15734
  * @internal
15735
+ */ _proto.destroy = function destroy() {
15736
+ this._mesh._addReferCount(-1);
15737
+ this._mesh = null;
15738
+ this.texture = null;
15739
+ this.solidColor = null;
15740
+ this.sky.destroy();
15741
+ };
15742
+ /**
15743
+ * @internal
15514
15744
  * Standalone for CanvasRenderer plugin.
15515
15745
  */ _proto._initMesh = function _initMesh(engine) {
15516
15746
  this._mesh = this._createPlane(engine);
15747
+ this._mesh._addReferCount(1);
15517
15748
  };
15518
15749
  /**
15519
15750
  * @internal
@@ -15585,6 +15816,9 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
15585
15816
  },
15586
15817
  set: function set(value) {
15587
15818
  if (this._texture !== value) {
15819
+ var _this__texture;
15820
+ value == null ? void 0 : value._addReferCount(1);
15821
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addReferCount(-1);
15588
15822
  this._texture = value;
15589
15823
  this._engine._backgroundTextureMaterial.shaderData.setTexture("material_BaseTexture", value);
15590
15824
  }
@@ -16062,7 +16296,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16062
16296
  var sunLightIndex = lightManager._getSunLightIndex();
16063
16297
  if (sunLightIndex !== -1) {
16064
16298
  var sunlight = lightManager._directLights.get(sunLightIndex);
16065
- shaderData.setColor(Scene._sunlightColorProperty, sunlight.color);
16299
+ shaderData.setColor(Scene._sunlightColorProperty, sunlight._getLightIntensityColor());
16066
16300
  shaderData.setVector3(Scene._sunlightDirectionProperty, sunlight.direction);
16067
16301
  this._sunLight = sunlight;
16068
16302
  }
@@ -16093,6 +16327,7 @@ var TextRenderData = /*#__PURE__*/ function(RenderData) {
16093
16327
  this._rootEntities[0].destroy();
16094
16328
  }
16095
16329
  this._activeCameras.length = 0;
16330
+ this.background.destroy();
16096
16331
  this.shaderData._addReferCount(-1);
16097
16332
  };
16098
16333
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -16550,7 +16785,7 @@ ShaderPool.init();
16550
16785
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
16551
16786
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
16552
16787
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
16553
- _this._textDefaultFont.isGCIgnored = false;
16788
+ _this._textDefaultFont.isGCIgnored = true;
16554
16789
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
16555
16790
  _this._initMagentaTextures(hardwareRenderer);
16556
16791
  if (!hardwareRenderer.canIUse(GLCapabilityType.depthTexture)) {
@@ -16561,6 +16796,7 @@ ShaderPool.init();
16561
16796
  _this._depthTexture2D = depthTexture2D;
16562
16797
  }
16563
16798
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
16799
+ magentaMaterial.isGCIgnored = true;
16564
16800
  magentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
16565
16801
  _this._magentaMaterial = magentaMaterial;
16566
16802
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -16787,7 +17023,9 @@ ShaderPool.init();
16787
17023
  this._magentaTexture2DArray = magentaTexture2DArray;
16788
17024
  }
16789
17025
  };
16790
- _proto._initialize = function _initialize(configuration) {
17026
+ /**
17027
+ * @internal
17028
+ */ _proto._initialize = function _initialize(configuration) {
16791
17029
  var _this = this;
16792
17030
  var physics = configuration.physics;
16793
17031
  if (physics) {
@@ -17109,7 +17347,9 @@ ShaderPool.init();
17109
17347
  this._entity._removeScript(this);
17110
17348
  this._waitHandlingInValid = false;
17111
17349
  };
17112
- _proto._onDestroy = function _onDestroy() {
17350
+ /**
17351
+ * @internal
17352
+ */ _proto._onDestroy = function _onDestroy() {
17113
17353
  Component.prototype._onDestroy.call(this);
17114
17354
  this._engine._componentsManager.addPendingDestroyScript(this);
17115
17355
  };
@@ -18059,7 +18299,7 @@ var /**
18059
18299
  // prepare render target
18060
18300
  var renderTarget = this._getAvailableRenderTarget();
18061
18301
  // @todo: shouldn't set viewport and scissor in activeRenderTarget
18062
- rhi.activeRenderTarget(renderTarget, null, 0);
18302
+ rhi.activeRenderTarget(renderTarget, CascadedShadowCasterPass._viewport, 0);
18063
18303
  if (this._supportDepthTexture) {
18064
18304
  rhi.clearRenderTarget(engine, CameraClearFlags.Depth, null);
18065
18305
  } else {
@@ -18181,11 +18421,13 @@ var /**
18181
18421
  if (engine._hardwareRenderer._isWebGL2) {
18182
18422
  depthTexture.depthCompareFunction = TextureDepthCompareFunction.Less;
18183
18423
  }
18424
+ renderTarget == null ? void 0 : renderTarget._addReferCount(-1);
18184
18425
  if (this._supportDepthTexture) {
18185
18426
  renderTarget = this._renderTargets = new RenderTarget(engine, width, height, null, depthTexture);
18186
18427
  } else {
18187
18428
  renderTarget = this._renderTargets = new RenderTarget(engine, width, height, depthTexture);
18188
18429
  }
18430
+ renderTarget._addReferCount(1);
18189
18431
  }
18190
18432
  return renderTarget;
18191
18433
  };
@@ -18208,7 +18450,12 @@ var /**
18208
18450
  var height = shadowCascades == ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
18209
18451
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
18210
18452
  }
18211
- this._renderTargets = null;
18453
+ var renderTargets = this._renderTargets;
18454
+ if (renderTargets) {
18455
+ renderTargets._addReferCount(-1);
18456
+ renderTargets.destroy();
18457
+ this._renderTargets = null;
18458
+ }
18212
18459
  var viewportOffset = this._viewportOffsets;
18213
18460
  var shadowTileResolution1 = this._shadowTileResolution;
18214
18461
  switch(shadowCascades){
@@ -18264,6 +18511,9 @@ var /**
18264
18511
  (function() {
18265
18512
  CascadedShadowCasterPass._cascadesSplitDistance = new Array(CascadedShadowCasterPass._maxCascades + 1);
18266
18513
  })();
18514
+ (function() {
18515
+ CascadedShadowCasterPass._viewport = new Vector4(0, 0, 1, 1);
18516
+ })();
18267
18517
  (function() {
18268
18518
  CascadedShadowCasterPass._clearColor = new Color$1(1, 1, 1, 1);
18269
18519
  })();
@@ -18792,6 +19042,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component) {
18792
19042
  this.entity.scene._detachRenderCamera(this);
18793
19043
  };
18794
19044
  /**
19045
+ * @internal
18795
19046
  * @inheritdoc
18796
19047
  */ _proto._onDestroy = function _onDestroy() {
18797
19048
  var _this__renderPipeline;
@@ -18997,7 +19248,12 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component) {
18997
19248
  return this._renderTarget;
18998
19249
  },
18999
19250
  set: function set(value) {
19000
- this._renderTarget = value;
19251
+ if (this._renderTarget !== value) {
19252
+ var _this__renderTarget;
19253
+ value == null ? void 0 : value._addReferCount(1);
19254
+ (_this__renderTarget = this._renderTarget) == null ? void 0 : _this__renderTarget._addReferCount(-1);
19255
+ this._renderTarget = value;
19256
+ }
19001
19257
  }
19002
19258
  }
19003
19259
  ]);
@@ -19986,6 +20242,7 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
19986
20242
  _this = PBRBaseMaterial.call(this, engine, Shader.find("pbr")) || this;
19987
20243
  _this.shaderData.setFloat(PBRMaterial._metallicProp, 1);
19988
20244
  _this.shaderData.setFloat(PBRMaterial._roughnessProp, 1);
20245
+ _this.shaderData.setFloat(PBRMaterial._iorProp, 1.5);
19989
20246
  return _this;
19990
20247
  }
19991
20248
  var _proto = PBRMaterial.prototype;
@@ -19997,10 +20254,23 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
19997
20254
  return dest;
19998
20255
  };
19999
20256
  _create_class(PBRMaterial, [
20257
+ {
20258
+ key: "ior",
20259
+ get: /**
20260
+ * Index Of Refraction.
20261
+ * @defaultValue `1.5`
20262
+ */ function get() {
20263
+ return this.shaderData.getFloat(PBRMaterial._iorProp);
20264
+ },
20265
+ set: function set(v) {
20266
+ this.shaderData.setFloat(PBRMaterial._iorProp, Math.max(v, 0));
20267
+ }
20268
+ },
20000
20269
  {
20001
20270
  key: "metallic",
20002
20271
  get: /**
20003
- * Metallic, default 1.0.
20272
+ * Metallic.
20273
+ * @defaultValue `1.0`
20004
20274
  */ function get() {
20005
20275
  return this.shaderData.getFloat(PBRMaterial._metallicProp);
20006
20276
  },
@@ -20011,7 +20281,8 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
20011
20281
  {
20012
20282
  key: "roughness",
20013
20283
  get: /**
20014
- * Roughness, default 1.0.
20284
+ * Roughness. default 1.0.
20285
+ * @defaultValue `1.0`
20015
20286
  */ function get() {
20016
20287
  return this.shaderData.getFloat(PBRMaterial._roughnessProp);
20017
20288
  },
@@ -20048,6 +20319,9 @@ var BaseMaterial = /*#__PURE__*/ function(Material) {
20048
20319
  (function() {
20049
20320
  PBRMaterial._roughnessMetallicTextureProp = ShaderProperty.getByName("material_RoughnessMetallicTexture");
20050
20321
  })();
20322
+ (function() {
20323
+ PBRMaterial._iorProp = Shader.getPropertyByName("material_IOR");
20324
+ })();
20051
20325
 
20052
20326
  /**
20053
20327
  * PBR (Specular-Glossiness Workflow) Material.
@@ -20259,9 +20533,18 @@ var TextVerticalAlignment;
20259
20533
  * @internal
20260
20534
  */ _proto._addSprite = function _addSprite(sprite) {
20261
20535
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
20536
+ sprite._atlas = this;
20537
+ sprite.isGCIgnored = true;
20262
20538
  };
20263
- _proto._onDestroy = function _onDestroy() {
20539
+ /**
20540
+ * @internal
20541
+ */ _proto._onDestroy = function _onDestroy() {
20264
20542
  ReferResource.prototype._onDestroy.call(this);
20543
+ var _this = this, sprites = _this._sprites;
20544
+ for(var i = 0, n = sprites.length; i < n; i++){
20545
+ sprites[i].destroy();
20546
+ }
20547
+ sprites.length = 0;
20265
20548
  this._sprites = null;
20266
20549
  this._spriteNamesToIndex = null;
20267
20550
  };
@@ -20309,8 +20592,10 @@ var TextVerticalAlignment;
20309
20592
  if (name === void 0) name = null;
20310
20593
  var _this;
20311
20594
  _this = ReferResource.call(this, engine) || this;
20312
- _this._width = undefined;
20313
- _this._height = undefined;
20595
+ _this._automaticWidth = 0;
20596
+ _this._automaticHeight = 0;
20597
+ _this._customWidth = undefined;
20598
+ _this._customHeight = undefined;
20314
20599
  _this._positions = [
20315
20600
  new Vector2(),
20316
20601
  new Vector2(),
@@ -20331,7 +20616,7 @@ var TextVerticalAlignment;
20331
20616
  _this._region = new Rect(0, 0, 1, 1);
20332
20617
  _this._pivot = new Vector2(0.5, 0.5);
20333
20618
  _this._border = new Vector4(0, 0, 0, 0);
20334
- _this._dirtyUpdateFlag = 0x3;
20619
+ _this._dirtyUpdateFlag = 0x7;
20335
20620
  /** @internal */ _this._updateFlagManager = new UpdateFlagManager();
20336
20621
  _this._texture = texture;
20337
20622
  region && _this._region.copyFrom(region);
@@ -20369,17 +20654,41 @@ var TextVerticalAlignment;
20369
20654
  this._dirtyUpdateFlag & 0x1 && this._updatePositions();
20370
20655
  return this._bounds;
20371
20656
  };
20372
- _proto._onDestroy = function _onDestroy() {
20657
+ /**
20658
+ * @internal
20659
+ */ _proto._addReferCount = function _addReferCount(value) {
20660
+ var _this__atlas;
20661
+ ReferResource.prototype._addReferCount.call(this, value);
20662
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addReferCount(value);
20663
+ };
20664
+ /**
20665
+ * @internal
20666
+ */ _proto._onDestroy = function _onDestroy() {
20373
20667
  ReferResource.prototype._onDestroy.call(this);
20668
+ this._positions.length = 0;
20669
+ this._positions = null;
20670
+ this._uvs.length = 0;
20671
+ this._uvs = null;
20672
+ this._atlasRegion = null;
20673
+ this._atlasRegionOffset = null;
20674
+ this._region = null;
20675
+ this._pivot = null;
20676
+ this._border = null;
20677
+ this._bounds = null;
20678
+ this._atlas = null;
20374
20679
  this._texture = null;
20680
+ this._updateFlagManager = null;
20375
20681
  };
20376
20682
  _proto._calDefaultSize = function _calDefaultSize() {
20377
20683
  if (this._texture) {
20378
20684
  var _this = this, _texture = _this._texture, _atlasRegion = _this._atlasRegion, _atlasRegionOffset = _this._atlasRegionOffset, _region = _this._region;
20379
20685
  var pixelsPerUnitReciprocal = 1.0 / Engine._pixelsPerUnit;
20380
- this._width = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
20381
- this._height = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
20686
+ this._automaticWidth = _texture.width * _atlasRegion.width / (1 - _atlasRegionOffset.x - _atlasRegionOffset.z) * _region.width * pixelsPerUnitReciprocal;
20687
+ this._automaticHeight = _texture.height * _atlasRegion.height / (1 - _atlasRegionOffset.y - _atlasRegionOffset.w) * _region.height * pixelsPerUnitReciprocal;
20688
+ } else {
20689
+ this._automaticWidth = this._automaticHeight = 0;
20382
20690
  }
20691
+ this._dirtyUpdateFlag &= ~0x4;
20383
20692
  };
20384
20693
  _proto._updatePositions = function _updatePositions() {
20385
20694
  var blank = this._atlasRegionOffset;
@@ -20433,11 +20742,16 @@ var TextVerticalAlignment;
20433
20742
  };
20434
20743
  _proto._dispatchSpriteChange = function _dispatchSpriteChange(type) {
20435
20744
  switch(type){
20745
+ case SpriteModifyFlags.texture:
20746
+ this._dirtyUpdateFlag |= 0x4;
20747
+ break;
20436
20748
  case SpriteModifyFlags.atlasRegionOffset:
20437
20749
  case SpriteModifyFlags.region:
20438
- this._dirtyUpdateFlag |= 0x3;
20750
+ this._dirtyUpdateFlag |= 0x7;
20439
20751
  break;
20440
20752
  case SpriteModifyFlags.atlasRegion:
20753
+ this._dirtyUpdateFlag |= 0x4 | 0x2;
20754
+ break;
20441
20755
  case SpriteModifyFlags.border:
20442
20756
  this._dirtyUpdateFlag |= 0x2;
20443
20757
  break;
@@ -20456,7 +20770,9 @@ var TextVerticalAlignment;
20456
20770
  if (this._texture !== value) {
20457
20771
  this._texture = value;
20458
20772
  this._dispatchSpriteChange(SpriteModifyFlags.texture);
20459
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20773
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20774
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20775
+ }
20460
20776
  }
20461
20777
  }
20462
20778
  },
@@ -20464,13 +20780,21 @@ var TextVerticalAlignment;
20464
20780
  key: "width",
20465
20781
  get: /**
20466
20782
  * The width of the sprite (in world coordinates).
20783
+ *
20784
+ * @remarks
20785
+ * If width is set, return the set value,
20786
+ * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
20467
20787
  */ function get() {
20468
- this._width === undefined && this._calDefaultSize();
20469
- return this._width;
20788
+ if (this._customWidth !== undefined) {
20789
+ return this._customWidth;
20790
+ } else {
20791
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
20792
+ return this._automaticWidth;
20793
+ }
20470
20794
  },
20471
20795
  set: function set(value) {
20472
- if (this._width !== value) {
20473
- this._width = value;
20796
+ if (this._customWidth !== value) {
20797
+ this._customWidth = value;
20474
20798
  this._dispatchSpriteChange(SpriteModifyFlags.size);
20475
20799
  }
20476
20800
  }
@@ -20479,13 +20803,21 @@ var TextVerticalAlignment;
20479
20803
  key: "height",
20480
20804
  get: /**
20481
20805
  * The height of the sprite (in world coordinates).
20806
+ *
20807
+ * @remarks
20808
+ * If height is set, return the set value,
20809
+ * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
20482
20810
  */ function get() {
20483
- this._height === undefined && this._calDefaultSize();
20484
- return this._height;
20811
+ if (this._customHeight !== undefined) {
20812
+ return this._customHeight;
20813
+ } else {
20814
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
20815
+ return this._automaticHeight;
20816
+ }
20485
20817
  },
20486
20818
  set: function set(value) {
20487
- if (this._height !== value) {
20488
- this._height = value;
20819
+ if (this._customHeight !== value) {
20820
+ this._customHeight = value;
20489
20821
  this._dispatchSpriteChange(SpriteModifyFlags.size);
20490
20822
  }
20491
20823
  }
@@ -20515,7 +20847,9 @@ var TextVerticalAlignment;
20515
20847
  var y = MathUtil$1.clamp(value.y, 0, 1);
20516
20848
  this._atlasRegion.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
20517
20849
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegion);
20518
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20850
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20851
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20852
+ }
20519
20853
  }
20520
20854
  },
20521
20855
  {
@@ -20530,7 +20864,9 @@ var TextVerticalAlignment;
20530
20864
  var y = MathUtil$1.clamp(value.y, 0, 1);
20531
20865
  this._atlasRegionOffset.set(x, y, MathUtil$1.clamp(value.z, 0, 1 - x), MathUtil$1.clamp(value.w, 0, 1 - y));
20532
20866
  this._dispatchSpriteChange(SpriteModifyFlags.atlasRegionOffset);
20533
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20867
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20868
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20869
+ }
20534
20870
  }
20535
20871
  },
20536
20872
  {
@@ -20546,7 +20882,9 @@ var TextVerticalAlignment;
20546
20882
  var y = MathUtil$1.clamp(value.y, 0, 1);
20547
20883
  region.set(x, y, MathUtil$1.clamp(value.width, 0, 1 - x), MathUtil$1.clamp(value.height, 0, 1 - y));
20548
20884
  this._dispatchSpriteChange(SpriteModifyFlags.region);
20549
- (this._width === undefined || this._height === undefined) && this._dispatchSpriteChange(SpriteModifyFlags.size);
20885
+ if (this._customWidth === undefined || this._customHeight === undefined) {
20886
+ this._dispatchSpriteChange(SpriteModifyFlags.size);
20887
+ }
20550
20888
  }
20551
20889
  },
20552
20890
  {
@@ -20596,7 +20934,8 @@ var SpriteUpdateFlags;
20596
20934
  (function(SpriteUpdateFlags) {
20597
20935
  SpriteUpdateFlags[SpriteUpdateFlags["positions"] = 0x1] = "positions";
20598
20936
  SpriteUpdateFlags[SpriteUpdateFlags["uvs"] = 0x2] = "uvs";
20599
- SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x3] = "all";
20937
+ SpriteUpdateFlags[SpriteUpdateFlags["automaticSize"] = 0x4] = "automaticSize";
20938
+ SpriteUpdateFlags[SpriteUpdateFlags["all"] = 0x7] = "all";
20600
20939
  })(SpriteUpdateFlags || (SpriteUpdateFlags = {}));
20601
20940
 
20602
20941
  var _SlicedSpriteAssembler;
@@ -21088,8 +21427,10 @@ var TiledType;
21088
21427
  _this._tiledAdaptiveThreshold = 0.5;
21089
21428
  _this._color = new Color$1(1, 1, 1, 1);
21090
21429
  _this._sprite = null;
21091
- _this._width = undefined;
21092
- _this._height = undefined;
21430
+ _this._automaticWidth = 0;
21431
+ _this._automaticHeight = 0;
21432
+ _this._customWidth = undefined;
21433
+ _this._customHeight = undefined;
21093
21434
  _this._flipX = false;
21094
21435
  _this._flipY = false;
21095
21436
  _this._maskLayer = SpriteMaskLayer.Layer0;
@@ -21104,38 +21445,45 @@ var TiledType;
21104
21445
  /**
21105
21446
  * @internal
21106
21447
  */ _proto._cloneTo = function _cloneTo(target) {
21448
+ Renderer.prototype._cloneTo.call(this, target);
21107
21449
  target._assembler.resetData(target);
21108
21450
  target.sprite = this._sprite;
21451
+ target.drawMode = this._drawMode;
21109
21452
  };
21110
- _proto._updateShaderData = function _updateShaderData(context) {
21453
+ /**
21454
+ * @internal
21455
+ */ _proto._updateShaderData = function _updateShaderData(context) {
21111
21456
  // @ts-ignore
21112
21457
  this._updateTransformShaderData(context, Matrix._identity);
21113
21458
  };
21114
- _proto._updateBounds = function _updateBounds(worldBounds) {
21115
- var _this_sprite;
21116
- if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
21459
+ /**
21460
+ * @internal
21461
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
21462
+ if (this.sprite) {
21463
+ this._assembler.updatePositions(this);
21464
+ } else {
21117
21465
  worldBounds.min.set(0, 0, 0);
21118
21466
  worldBounds.max.set(0, 0, 0);
21119
- } else {
21120
- this._assembler.updatePositions(this);
21121
21467
  }
21122
21468
  };
21123
- _proto._render = function _render(context) {
21469
+ /**
21470
+ * @internal
21471
+ */ _proto._render = function _render(context) {
21124
21472
  var _this_sprite;
21125
21473
  if (!((_this_sprite = this.sprite) == null ? void 0 : _this_sprite.texture) || !this.width || !this.height) {
21126
21474
  return;
21127
21475
  }
21128
- // Update position.
21476
+ // Update position
21129
21477
  if (this._dirtyUpdateFlag & RendererUpdateFlags.WorldVolume) {
21130
21478
  this._assembler.updatePositions(this);
21131
21479
  this._dirtyUpdateFlag &= ~RendererUpdateFlags.WorldVolume;
21132
21480
  }
21133
- // Update uv.
21481
+ // Update uv
21134
21482
  if (this._dirtyUpdateFlag & 0x2) {
21135
21483
  this._assembler.updateUVs(this);
21136
21484
  this._dirtyUpdateFlag &= ~0x2;
21137
21485
  }
21138
- // Push render data
21486
+ // Push primitive
21139
21487
  var material = this.getMaterial();
21140
21488
  var texture = this.sprite.texture;
21141
21489
  var renderData = this._engine._spriteRenderDataPool.getFromPool();
@@ -21145,14 +21493,27 @@ var TiledType;
21145
21493
  /**
21146
21494
  * @internal
21147
21495
  */ _proto._onDestroy = function _onDestroy() {
21148
- var _this__sprite;
21149
21496
  Renderer.prototype._onDestroy.call(this);
21150
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
21497
+ var sprite = this._sprite;
21498
+ if (sprite) {
21499
+ sprite._addReferCount(-1);
21500
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
21501
+ }
21151
21502
  this._color = null;
21152
21503
  this._sprite = null;
21153
21504
  this._assembler = null;
21154
21505
  this._verticesData = null;
21155
21506
  };
21507
+ _proto._calDefaultSize = function _calDefaultSize() {
21508
+ var sprite = this._sprite;
21509
+ if (sprite) {
21510
+ this._automaticWidth = sprite.width;
21511
+ this._automaticHeight = sprite.height;
21512
+ } else {
21513
+ this._automaticWidth = this._automaticHeight = 0;
21514
+ }
21515
+ this._dirtyUpdateFlag &= ~0x4;
21516
+ };
21156
21517
  _proto._updateStencilState = function _updateStencilState() {
21157
21518
  // Update stencil.
21158
21519
  var material = this.getInstanceMaterial();
@@ -21179,22 +21540,21 @@ var TiledType;
21179
21540
  break;
21180
21541
  case SpriteModifyFlags.size:
21181
21542
  var _this = this, drawMode = _this._drawMode;
21182
- if (drawMode === SpriteDrawMode.Sliced) {
21543
+ this._dirtyUpdateFlag |= 0x4;
21544
+ if (this._drawMode === SpriteDrawMode.Sliced) {
21183
21545
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21184
21546
  } else if (drawMode === SpriteDrawMode.Tiled) {
21185
21547
  this._dirtyUpdateFlag |= 0x3;
21186
21548
  } else {
21187
21549
  // When the width and height of `SpriteRenderer` are `undefined`,
21188
21550
  // the `size` of `Sprite` will affect the position of `SpriteRenderer`.
21189
- if (this._width === undefined || this._height === undefined) {
21551
+ if (this._customWidth === undefined || this._customHeight === undefined) {
21190
21552
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21191
21553
  }
21192
21554
  }
21193
21555
  break;
21194
21556
  case SpriteModifyFlags.border:
21195
- if (this._drawMode === SpriteDrawMode.Sliced || this._drawMode === SpriteDrawMode.Tiled) {
21196
- this._dirtyUpdateFlag |= 0x3;
21197
- }
21557
+ this._drawMode === SpriteDrawMode.Sliced && (this._dirtyUpdateFlag |= 0x3);
21198
21558
  break;
21199
21559
  case SpriteModifyFlags.region:
21200
21560
  case SpriteModifyFlags.atlasRegionOffset:
@@ -21278,10 +21638,14 @@ var TiledType;
21278
21638
  set: function set(value) {
21279
21639
  var lastSprite = this._sprite;
21280
21640
  if (lastSprite !== value) {
21281
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
21641
+ if (lastSprite) {
21642
+ lastSprite._addReferCount(-1);
21643
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
21644
+ }
21645
+ this._dirtyUpdateFlag |= 0x7;
21282
21646
  if (value) {
21647
+ value._addReferCount(1);
21283
21648
  value._updateFlagManager.addListener(this._onSpriteChange);
21284
- this._dirtyUpdateFlag |= 0x3;
21285
21649
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
21286
21650
  } else {
21287
21651
  this.shaderData.setTexture(SpriteRenderer._textureProperty, null);
@@ -21306,16 +21670,22 @@ var TiledType;
21306
21670
  {
21307
21671
  key: "width",
21308
21672
  get: /**
21309
- * Render width.
21673
+ * Render width (in world coordinates).
21674
+ *
21675
+ * @remarks
21676
+ * If width is set, return the set value,
21677
+ * otherwise return `SpriteRenderer.sprite.width`.
21310
21678
  */ function get() {
21311
- this._width === undefined && this._sprite && (this.width = this._sprite.width);
21312
- return this._width;
21679
+ if (this._customWidth !== undefined) {
21680
+ return this._customWidth;
21681
+ } else {
21682
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
21683
+ return this._automaticWidth;
21684
+ }
21313
21685
  },
21314
21686
  set: function set(value) {
21315
- // Update width if undefined
21316
- this._width === undefined && this._sprite && (this._width = this._sprite.width);
21317
- if (this._width !== value) {
21318
- this._width = value;
21687
+ if (this._customWidth !== value) {
21688
+ this._customWidth = value;
21319
21689
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21320
21690
  }
21321
21691
  }
@@ -21323,16 +21693,22 @@ var TiledType;
21323
21693
  {
21324
21694
  key: "height",
21325
21695
  get: /**
21326
- * Render height.
21696
+ * Render height (in world coordinates).
21697
+ *
21698
+ * @remarks
21699
+ * If height is set, return the set value,
21700
+ * otherwise return `SpriteRenderer.sprite.height`.
21327
21701
  */ function get() {
21328
- this._height === undefined && this._sprite && (this.height = this._sprite.height);
21329
- return this._height;
21702
+ if (this._customHeight !== undefined) {
21703
+ return this._customHeight;
21704
+ } else {
21705
+ this._dirtyUpdateFlag & 0x4 && this._calDefaultSize();
21706
+ return this._automaticHeight;
21707
+ }
21330
21708
  },
21331
21709
  set: function set(value) {
21332
- // Update height if undefined
21333
- this._height === undefined && this._sprite && (this._height = this._sprite.height);
21334
- if (this._height !== value) {
21335
- this._height = value;
21710
+ if (this._customHeight !== value) {
21711
+ this._customHeight = value;
21336
21712
  this._dirtyUpdateFlag |= RendererUpdateFlags.WorldVolume;
21337
21713
  }
21338
21714
  }
@@ -21419,10 +21795,16 @@ __decorate([
21419
21795
  ], SpriteRenderer.prototype, "_sprite", void 0);
21420
21796
  __decorate([
21421
21797
  ignoreClone
21422
- ], SpriteRenderer.prototype, "_width", void 0);
21798
+ ], SpriteRenderer.prototype, "_automaticWidth", void 0);
21423
21799
  __decorate([
21424
21800
  ignoreClone
21425
- ], SpriteRenderer.prototype, "_height", void 0);
21801
+ ], SpriteRenderer.prototype, "_automaticHeight", void 0);
21802
+ __decorate([
21803
+ assignmentClone
21804
+ ], SpriteRenderer.prototype, "_customWidth", void 0);
21805
+ __decorate([
21806
+ assignmentClone
21807
+ ], SpriteRenderer.prototype, "_customHeight", void 0);
21426
21808
  __decorate([
21427
21809
  assignmentClone
21428
21810
  ], SpriteRenderer.prototype, "_flipX", void 0);
@@ -21443,7 +21825,9 @@ var /**
21443
21825
  */ SpriteRendererUpdateFlags;
21444
21826
  (function(SpriteRendererUpdateFlags) {
21445
21827
  SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** UV. */ "UV"] = 0x2] = "UV";
21446
- SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x3] = "All";
21828
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** WorldVolume and UV . */ "RenderData"] = 0x3] = "RenderData";
21829
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** Automatic Size. */ "AutomaticSize"] = 0x4] = "AutomaticSize";
21830
+ SpriteRendererUpdateFlags[SpriteRendererUpdateFlags[/** All. */ "All"] = 0x7] = "All";
21447
21831
  })(SpriteRendererUpdateFlags || (SpriteRendererUpdateFlags = {}));
21448
21832
 
21449
21833
  /**
@@ -21531,7 +21915,9 @@ var /**
21531
21915
  this._font._addReferCount(1);
21532
21916
  this.setMaterial(engine._spriteDefaultMaterial);
21533
21917
  };
21534
- _proto._onDestroy = function _onDestroy() {
21918
+ /**
21919
+ * @internal
21920
+ */ _proto._onDestroy = function _onDestroy() {
21535
21921
  Renderer.prototype._onDestroy.call(this);
21536
21922
  // Clear render data.
21537
21923
  var charRenderDatas = this._charRenderDatas;
@@ -21548,6 +21934,7 @@ var /**
21548
21934
  /**
21549
21935
  * @internal
21550
21936
  */ _proto._cloneTo = function _cloneTo(target) {
21937
+ Renderer.prototype._cloneTo.call(this, target);
21551
21938
  target.font = this._font;
21552
21939
  target._subFont = this._subFont;
21553
21940
  };
@@ -21566,14 +21953,20 @@ var /**
21566
21953
  */ _proto._setDirtyFlagFalse = function _setDirtyFlagFalse(type) {
21567
21954
  this._dirtyFlag &= ~type;
21568
21955
  };
21569
- _proto._updateShaderData = function _updateShaderData(context) {
21956
+ /**
21957
+ * @internal
21958
+ */ _proto._updateShaderData = function _updateShaderData(context) {
21570
21959
  // @ts-ignore
21571
21960
  this._updateTransformShaderData(context, Matrix._identity);
21572
21961
  };
21573
- _proto._updateBounds = function _updateBounds(worldBounds) {
21962
+ /**
21963
+ * @internal
21964
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
21574
21965
  BoundingBox.transform(this._localBounds, this._entity.transform.worldMatrix, worldBounds);
21575
21966
  };
21576
- _proto._render = function _render(context) {
21967
+ /**
21968
+ * @internal
21969
+ */ _proto._render = function _render(context) {
21577
21970
  if (this._text === "" || this.enableWrapping && this.width <= 0 || this.overflowMode === OverflowMode.Truncate && this.height <= 0) {
21578
21971
  return;
21579
21972
  }
@@ -21668,8 +22061,6 @@ var /**
21668
22061
  _proto._updateLocalData = function _updateLocalData() {
21669
22062
  var _this = this, color = _this.color, horizontalAlignment = _this.horizontalAlignment, verticalAlignment = _this.verticalAlignment, charRenderDatas = _this._charRenderDatas;
21670
22063
  var _this__localBounds = this._localBounds, min = _this__localBounds.min, max = _this__localBounds.max;
21671
- min.set(0, 0, 0);
21672
- max.set(0, 0, 0);
21673
22064
  var _pixelsPerUnit = Engine._pixelsPerUnit;
21674
22065
  var pixelsPerUnitReciprocal = 1.0 / _pixelsPerUnit;
21675
22066
  var charFont = this._subFont;
@@ -21696,54 +22087,65 @@ var /**
21696
22087
  break;
21697
22088
  }
21698
22089
  var renderDataCount = 0;
22090
+ var firstLine = -1;
21699
22091
  var minX = Number.MAX_SAFE_INTEGER;
21700
22092
  var minY = Number.MAX_SAFE_INTEGER;
21701
22093
  var maxX = Number.MIN_SAFE_INTEGER;
21702
22094
  var maxY = Number.MIN_SAFE_INTEGER;
21703
- var lastLineIndex = linesLen - 1;
21704
22095
  for(var i = 0; i < linesLen; ++i){
21705
- var line = lines[i];
21706
22096
  var lineWidth = lineWidths[i];
21707
- var startX = 0;
21708
- switch(horizontalAlignment){
21709
- case TextHorizontalAlignment.Left:
21710
- startX = -halfRendererWidth;
21711
- break;
21712
- case TextHorizontalAlignment.Center:
21713
- startX = -lineWidth * 0.5;
21714
- break;
21715
- case TextHorizontalAlignment.Right:
21716
- startX = halfRendererWidth - lineWidth;
21717
- break;
21718
- }
21719
- for(var j = 0, m = line.length - 1; j <= m; ++j){
21720
- var char = line[j];
21721
- var charInfo = charFont._getCharInfo(char);
21722
- if (charInfo.h > 0) {
21723
- var charRenderData = charRenderDatas[renderDataCount] || charRenderDataPool.get();
21724
- var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
21725
- charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
21726
- renderData.color = color;
21727
- renderData.uvs = charInfo.uvs;
21728
- var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
21729
- var left = startX * pixelsPerUnitReciprocal;
21730
- var right = (startX + w) * pixelsPerUnitReciprocal;
21731
- var top = (startY + ascent) * pixelsPerUnitReciprocal;
21732
- var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
21733
- localPositions.set(left, top, right, bottom);
21734
- charRenderDatas[renderDataCount] = charRenderData;
21735
- renderDataCount++;
21736
- i === 0 && (maxY = Math.max(maxY, top));
21737
- i === lastLineIndex && (minY = Math.min(minY, bottom));
21738
- j === 0 && (minX = Math.min(minX, left));
21739
- j === m && (maxX = Math.max(maxX, right));
21740
- }
21741
- startX += charInfo.xAdvance;
22097
+ if (lineWidth > 0) {
22098
+ var line = lines[i];
22099
+ var startX = 0;
22100
+ var firstRow = -1;
22101
+ if (firstLine < 0) {
22102
+ firstLine = i;
22103
+ }
22104
+ switch(horizontalAlignment){
22105
+ case TextHorizontalAlignment.Left:
22106
+ startX = -halfRendererWidth;
22107
+ break;
22108
+ case TextHorizontalAlignment.Center:
22109
+ startX = -lineWidth * 0.5;
22110
+ break;
22111
+ case TextHorizontalAlignment.Right:
22112
+ startX = halfRendererWidth - lineWidth;
22113
+ break;
22114
+ }
22115
+ for(var j = 0, n = line.length; j < n; ++j){
22116
+ var char = line[j];
22117
+ var charInfo = charFont._getCharInfo(char);
22118
+ if (charInfo.h > 0) {
22119
+ var _charRenderDatas, _ref;
22120
+ firstRow < 0 && (firstRow = j);
22121
+ var charRenderData = (_charRenderDatas = charRenderDatas)[_ref = renderDataCount++] || (_charRenderDatas[_ref] = charRenderDataPool.get());
22122
+ var renderData = charRenderData.renderData, localPositions = charRenderData.localPositions;
22123
+ charRenderData.texture = charFont._getTextureByIndex(charInfo.index);
22124
+ renderData.color = color;
22125
+ renderData.uvs = charInfo.uvs;
22126
+ var w = charInfo.w, ascent = charInfo.ascent, descent = charInfo.descent;
22127
+ var left = startX * pixelsPerUnitReciprocal;
22128
+ var right = (startX + w) * pixelsPerUnitReciprocal;
22129
+ var top = (startY + ascent) * pixelsPerUnitReciprocal;
22130
+ var bottom = (startY - descent + 1) * pixelsPerUnitReciprocal;
22131
+ localPositions.set(left, top, right, bottom);
22132
+ i === firstLine && (maxY = Math.max(maxY, top));
22133
+ minY = Math.min(minY, bottom);
22134
+ j === firstRow && (minX = Math.min(minX, left));
22135
+ maxX = Math.max(maxX, right);
22136
+ }
22137
+ startX += charInfo.xAdvance;
22138
+ }
21742
22139
  }
21743
22140
  startY -= lineHeight;
21744
22141
  }
21745
- min.set(minX, minY, 0);
21746
- max.set(maxX, maxY, 0);
22142
+ if (firstLine < 0) {
22143
+ min.set(0, 0, 0);
22144
+ max.set(0, 0, 0);
22145
+ } else {
22146
+ min.set(minX, minY, 0);
22147
+ max.set(maxX, maxY, 0);
22148
+ }
21747
22149
  // Revert excess render data to pool.
21748
22150
  var lastRenderDataCount = charRenderDatas.length;
21749
22151
  if (lastRenderDataCount > renderDataCount) {
@@ -21756,7 +22158,9 @@ var /**
21756
22158
  return a.texture.instanceId - b.texture.instanceId;
21757
22159
  });
21758
22160
  };
21759
- _proto._onTransformChanged = function _onTransformChanged(bit) {
22161
+ /**
22162
+ * @internal
22163
+ */ _proto._onTransformChanged = function _onTransformChanged(bit) {
21760
22164
  Renderer.prototype._onTransformChanged.call(this, bit);
21761
22165
  this._setDirtyFlagTrue(0x4 | 0x8);
21762
22166
  };
@@ -22075,7 +22479,6 @@ var DirtyFlag;
22075
22479
  * @internal
22076
22480
  */ var AnimationCurveOwner = /*#__PURE__*/ function() {
22077
22481
  function AnimationCurveOwner(target, type, property, cureType) {
22078
- this.crossCurveMark = 0;
22079
22482
  this.hasSavedDefaultValue = false;
22080
22483
  this.baseEvaluateData = {
22081
22484
  curKeyframeIndex: 0,
@@ -22274,6 +22677,12 @@ AnimationCurveOwner.registerAssembler(Transform, "scale", ScaleAnimationCurveOwn
22274
22677
  }();
22275
22678
  AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights", BlendShapeWeightsAnimationCurveOwnerAssembler);
22276
22679
 
22680
+ /**
22681
+ * @internal
22682
+ */ var AnimationCurveLayerOwner = function AnimationCurveLayerOwner() {
22683
+ this.crossCurveMark = 0;
22684
+ };
22685
+
22277
22686
  /**
22278
22687
  * Associate AnimationCurve and the Entity
22279
22688
  */ var AnimationClipCurveBinding = /*#__PURE__*/ function() {
@@ -22291,6 +22700,13 @@ AnimationCurveOwner.registerAssembler(SkinnedMeshRenderer, "blendShapeWeights",
22291
22700
  };
22292
22701
  /**
22293
22702
  * @internal
22703
+ */ _proto._createCurveLayerOwner = function _createCurveLayerOwner(owner) {
22704
+ var layerOwner = new AnimationCurveLayerOwner();
22705
+ layerOwner.curveOwner = owner;
22706
+ return layerOwner;
22707
+ };
22708
+ /**
22709
+ * @internal
22294
22710
  */ _proto._getTempCurveOwner = function _getTempCurveOwner(entity) {
22295
22711
  var instanceId = entity.instanceId;
22296
22712
  if (!this._tempCurveOwner[instanceId]) {
@@ -23445,12 +23861,14 @@ var AnimatorLayerBlendingMode;
23445
23861
  * @internal
23446
23862
  */ var AnimatorLayerData = /*#__PURE__*/ function() {
23447
23863
  function AnimatorLayerData() {
23864
+ this.curveOwnerPool = Object.create(null);
23448
23865
  this.animatorStateDataMap = {};
23449
23866
  this.srcPlayData = new AnimatorStatePlayData();
23450
23867
  this.destPlayData = new AnimatorStatePlayData();
23451
23868
  this.layerState = LayerState.Standby;
23452
23869
  this.crossCurveMark = 0;
23453
23870
  this.manuallyTransition = new AnimatorStateTransition();
23871
+ this.crossOwnerLayerDataCollection = [];
23454
23872
  }
23455
23873
  var _proto = AnimatorLayerData.prototype;
23456
23874
  _proto.switchPlayData = function switchPlayData() {
@@ -23465,7 +23883,7 @@ var AnimatorLayerBlendingMode;
23465
23883
  /**
23466
23884
  * @internal
23467
23885
  */ var AnimatorStateData = function AnimatorStateData() {
23468
- this.curveOwners = [];
23886
+ this.curveLayerOwner = [];
23469
23887
  this.eventHandlers = [];
23470
23888
  };
23471
23889
 
@@ -23479,8 +23897,7 @@ var AnimatorLayerBlendingMode;
23479
23897
  /** Culling mode of this Animator. */ _this.cullingMode = AnimatorCullingMode.None;
23480
23898
  /** The playback speed of the Animator, 1.0 is normal playback speed. */ _this.speed = 1.0;
23481
23899
  _this._animatorLayersData = [];
23482
- _this._crossOwnerCollection = [];
23483
- _this._animationCurveOwners = [];
23900
+ _this._curveOwnerPool = Object.create(null);
23484
23901
  _this._animationEventHandlerPool = new ClassPool(AnimationEventHandler);
23485
23902
  _this._tempAnimatorStateInfo = {
23486
23903
  layerIndex: -1,
@@ -23512,7 +23929,6 @@ var AnimatorLayerBlendingMode;
23512
23929
  return;
23513
23930
  }
23514
23931
  var animatorLayerData = this._getAnimatorLayerData(stateInfo.layerIndex);
23515
- //TODO CM: Not consider same stateName, but different animation
23516
23932
  var animatorStateData = this._getAnimatorStateData(stateName, state, animatorLayerData);
23517
23933
  this._preparePlay(animatorLayerData, state, animatorStateData);
23518
23934
  animatorLayerData.layerState = LayerState.Playing;
@@ -23603,7 +24019,7 @@ var AnimatorLayerBlendingMode;
23603
24019
  /**
23604
24020
  * @internal
23605
24021
  */ _proto._reset = function _reset() {
23606
- var _this = this, animationCurveOwners = _this._animationCurveOwners;
24022
+ var _this = this, animationCurveOwners = _this._curveOwnerPool;
23607
24023
  for(var instanceId in animationCurveOwners){
23608
24024
  var propertyOwners = animationCurveOwners[instanceId];
23609
24025
  for(var property in propertyOwners){
@@ -23612,8 +24028,7 @@ var AnimatorLayerBlendingMode;
23612
24028
  }
23613
24029
  }
23614
24030
  this._animatorLayersData.length = 0;
23615
- this._crossOwnerCollection.length = 0;
23616
- this._animationCurveOwners.length = 0;
24031
+ this._curveOwnerPool = {};
23617
24032
  this._animationEventHandlerPool.resetPool();
23618
24033
  if (this._controllerUpdateFlag) {
23619
24034
  this._controllerUpdateFlag.flag = false;
@@ -23641,10 +24056,10 @@ var AnimatorLayerBlendingMode;
23641
24056
  return stateInfo;
23642
24057
  };
23643
24058
  _proto._saveDefaultValues = function _saveDefaultValues(stateData) {
23644
- var curveOwners = stateData.curveOwners;
23645
- for(var i = curveOwners.length - 1; i >= 0; i--){
23646
- var _curveOwners_i;
23647
- (_curveOwners_i = curveOwners[i]) == null ? void 0 : _curveOwners_i.saveDefaultValue();
24059
+ var curveLayerOwner = stateData.curveLayerOwner;
24060
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24061
+ var _curveLayerOwner_i;
24062
+ (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.saveDefaultValue();
23648
24063
  }
23649
24064
  };
23650
24065
  _proto._getAnimatorStateData = function _getAnimatorStateData(stateName, animatorState, animatorLayerData) {
@@ -23653,25 +24068,32 @@ var AnimatorLayerBlendingMode;
23653
24068
  if (!animatorStateData) {
23654
24069
  animatorStateData = new AnimatorStateData();
23655
24070
  animatorStateDataMap[stateName] = animatorStateData;
23656
- this._saveAnimatorStateData(animatorState, animatorStateData);
24071
+ this._saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData);
23657
24072
  this._saveAnimatorEventHandlers(animatorState, animatorStateData);
23658
24073
  }
23659
24074
  return animatorStateData;
23660
24075
  };
23661
- _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData) {
23662
- var _this = this, entity = _this.entity, animationCureOwners = _this._animationCurveOwners;
23663
- var curveOwners = animatorStateData.curveOwners;
24076
+ _proto._saveAnimatorStateData = function _saveAnimatorStateData(animatorState, animatorStateData, animatorLayerData) {
24077
+ var _this = this, entity = _this.entity, curveOwnerPool = _this._curveOwnerPool;
24078
+ var curveLayerOwner = animatorStateData.curveLayerOwner;
24079
+ var layerCurveOwnerPool = animatorLayerData.curveOwnerPool;
23664
24080
  var _animatorState_clip = animatorState.clip, curves = _animatorState_clip._curveBindings;
23665
24081
  for(var i = curves.length - 1; i >= 0; i--){
23666
24082
  var curve = curves[i];
23667
24083
  var targetEntity = curve.relativePath === "" ? entity : entity.findByPath(curve.relativePath);
23668
24084
  if (targetEntity) {
24085
+ var _curveOwnerPool, _instanceId, _propertyOwners, _property, _layerCurveOwnerPool, _instanceId1, _layerPropertyOwners, _property1;
23669
24086
  var property = curve.property;
23670
24087
  var instanceId = targetEntity.instanceId;
23671
- var propertyOwners = animationCureOwners[instanceId] || (animationCureOwners[instanceId] = {});
23672
- curveOwners[i] = propertyOwners[property] || (propertyOwners[property] = curve._createCurveOwner(targetEntity));
24088
+ // Get owner
24089
+ var propertyOwners = (_curveOwnerPool = curveOwnerPool)[_instanceId = instanceId] || (_curveOwnerPool[_instanceId] = Object.create(null));
24090
+ var owner = (_propertyOwners = propertyOwners)[_property = property] || (_propertyOwners[_property] = curve._createCurveOwner(targetEntity));
24091
+ // Get layer owner
24092
+ var layerPropertyOwners = (_layerCurveOwnerPool = layerCurveOwnerPool)[_instanceId1 = instanceId] || (_layerCurveOwnerPool[_instanceId1] = Object.create(null));
24093
+ var layerOwner = (_layerPropertyOwners = layerPropertyOwners)[_property1 = property] || (_layerPropertyOwners[_property1] = curve._createCurveLayerOwner(owner));
24094
+ curveLayerOwner[i] = layerOwner;
23673
24095
  } else {
23674
- curveOwners[i] = null;
24096
+ curveLayerOwner[i] = null;
23675
24097
  console.warn("The entity don't have the child entity which path is " + curve.relativePath + ".");
23676
24098
  }
23677
24099
  }
@@ -23699,65 +24121,61 @@ var AnimatorLayerBlendingMode;
23699
24121
  };
23700
24122
  _proto._clearCrossData = function _clearCrossData(animatorLayerData) {
23701
24123
  animatorLayerData.crossCurveMark++;
23702
- this._crossOwnerCollection.length = 0;
24124
+ animatorLayerData.crossOwnerLayerDataCollection.length = 0;
23703
24125
  };
23704
- _proto._addCrossCurveData = function _addCrossCurveData(crossCurveData, owner, curCurveIndex, nextCurveIndex) {
23705
- owner.crossSrcCurveIndex = curCurveIndex;
23706
- owner.crossDestCurveIndex = nextCurveIndex;
23707
- crossCurveData.push(owner);
24126
+ _proto._addCrossOwner = function _addCrossOwner(animatorLayerData, layerOwner, curCurveIndex, nextCurveIndex) {
24127
+ layerOwner.crossSrcCurveIndex = curCurveIndex;
24128
+ layerOwner.crossDestCurveIndex = nextCurveIndex;
24129
+ animatorLayerData.crossOwnerLayerDataCollection.push(layerOwner);
23708
24130
  };
23709
24131
  _proto._prepareCrossFading = function _prepareCrossFading(animatorLayerData) {
23710
- var crossCurveData = this._crossOwnerCollection;
23711
- var crossCurveMark = animatorLayerData.crossCurveMark;
23712
24132
  // Add src cross curve data.
23713
- this._prepareSrcCrossData(crossCurveData, animatorLayerData.srcPlayData, crossCurveMark, false);
24133
+ this._prepareSrcCrossData(animatorLayerData, false);
23714
24134
  // Add dest cross curve data.
23715
- this._prepareDestCrossData(crossCurveData, animatorLayerData.destPlayData, crossCurveMark, false);
24135
+ this._prepareDestCrossData(animatorLayerData, false);
23716
24136
  };
23717
24137
  _proto._prepareStandbyCrossFading = function _prepareStandbyCrossFading(animatorLayerData) {
23718
- var crossOwnerCollection = this._crossOwnerCollection;
23719
- var srcPlayData = animatorLayerData.srcPlayData, crossCurveMark = animatorLayerData.crossCurveMark;
23720
24138
  // Standby have two sub state, one is never play, one is finished, never play srcPlayData.state is null.
23721
- srcPlayData.state && this._prepareSrcCrossData(crossOwnerCollection, srcPlayData, crossCurveMark, true);
24139
+ animatorLayerData.srcPlayData.state && this._prepareSrcCrossData(animatorLayerData, true);
23722
24140
  // Add dest cross curve data.
23723
- this._prepareDestCrossData(crossOwnerCollection, animatorLayerData.destPlayData, crossCurveMark, true);
24141
+ this._prepareDestCrossData(animatorLayerData, true);
23724
24142
  };
23725
24143
  _proto._prepareFixedPoseCrossFading = function _prepareFixedPoseCrossFading(animatorLayerData) {
23726
- var crossOwnerCollection = this._crossOwnerCollection;
24144
+ var crossOwnerLayerDataCollection = animatorLayerData.crossOwnerLayerDataCollection;
23727
24145
  // Save current cross curve data owner fixed pose.
23728
- for(var i = crossOwnerCollection.length - 1; i >= 0; i--){
23729
- var item = crossOwnerCollection[i];
23730
- item.saveFixedPoseValue();
24146
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24147
+ var layerOwner = crossOwnerLayerDataCollection[i];
24148
+ if (!layerOwner) continue;
24149
+ layerOwner.curveOwner.saveFixedPoseValue();
23731
24150
  // Reset destCurveIndex When fixed pose crossFading again.
23732
- item.crossDestCurveIndex = -1;
24151
+ layerOwner.crossDestCurveIndex = -1;
23733
24152
  }
23734
24153
  // prepare dest AnimatorState cross data.
23735
- this._prepareDestCrossData(crossOwnerCollection, animatorLayerData.destPlayData, animatorLayerData.crossCurveMark, true);
23736
- };
23737
- _proto._prepareSrcCrossData = function _prepareSrcCrossData(crossCurveData, srcPlayData, crossCurveMark, saveFixed) {
23738
- var curveOwners = srcPlayData.stateData.curveOwners;
23739
- for(var i = curveOwners.length - 1; i >= 0; i--){
23740
- var owner = curveOwners[i];
23741
- if (!owner) continue;
23742
- owner.crossCurveMark = crossCurveMark;
23743
- owner.crossCurveDataIndex = crossCurveData.length;
23744
- saveFixed && owner.saveFixedPoseValue();
23745
- this._addCrossCurveData(crossCurveData, owner, i, -1);
23746
- }
23747
- };
23748
- _proto._prepareDestCrossData = function _prepareDestCrossData(crossCurveData, destPlayData, crossCurveMark, saveFixed) {
23749
- var curveOwners = destPlayData.stateData.curveOwners;
23750
- for(var i = curveOwners.length - 1; i >= 0; i--){
23751
- var owner = curveOwners[i];
23752
- if (!owner) continue;
23753
- if (owner.crossCurveMark === crossCurveMark) {
23754
- crossCurveData[owner.crossCurveDataIndex].crossDestCurveIndex = i;
24154
+ this._prepareDestCrossData(animatorLayerData, true);
24155
+ };
24156
+ _proto._prepareSrcCrossData = function _prepareSrcCrossData(animatorLayerData, saveFixed) {
24157
+ var curveLayerOwner = animatorLayerData.srcPlayData.stateData.curveLayerOwner;
24158
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24159
+ var layerOwner = curveLayerOwner[i];
24160
+ if (!layerOwner) continue;
24161
+ layerOwner.crossCurveMark = animatorLayerData.crossCurveMark;
24162
+ saveFixed && layerOwner.curveOwner.saveFixedPoseValue();
24163
+ this._addCrossOwner(animatorLayerData, layerOwner, i, -1);
24164
+ }
24165
+ };
24166
+ _proto._prepareDestCrossData = function _prepareDestCrossData(animatorLayerData, saveFixed) {
24167
+ var curveLayerOwner = animatorLayerData.destPlayData.stateData.curveLayerOwner;
24168
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24169
+ var layerOwner = curveLayerOwner[i];
24170
+ if (!layerOwner) continue;
24171
+ if (layerOwner.crossCurveMark === animatorLayerData.crossCurveMark) {
24172
+ layerOwner.crossDestCurveIndex = i;
23755
24173
  } else {
24174
+ var owner = layerOwner.curveOwner;
23756
24175
  owner.saveDefaultValue();
23757
24176
  saveFixed && owner.saveFixedPoseValue();
23758
- owner.crossCurveMark = crossCurveMark;
23759
- owner.crossCurveDataIndex = crossCurveData.length;
23760
- this._addCrossCurveData(crossCurveData, owner, -1, i);
24177
+ layerOwner.crossCurveMark = animatorLayerData.crossCurveMark;
24178
+ this._addCrossOwner(animatorLayerData, layerOwner, -1, i);
23761
24179
  }
23762
24180
  }
23763
24181
  };
@@ -23787,7 +24205,7 @@ var AnimatorLayerBlendingMode;
23787
24205
  }
23788
24206
  };
23789
24207
  _proto._updatePlayingState = function _updatePlayingState(playData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
23790
- var _playData_stateData = playData.stateData, curveOwners = _playData_stateData.curveOwners, eventHandlers = _playData_stateData.eventHandlers;
24208
+ var _playData_stateData = playData.stateData, curveLayerOwner = _playData_stateData.curveLayerOwner, eventHandlers = _playData_stateData.eventHandlers;
23791
24209
  var state = playData.state, lastPlayState = playData.playState, lastClipTime = playData.clipTime;
23792
24210
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
23793
24211
  playData.update(this.speed < 0);
@@ -23797,8 +24215,8 @@ var AnimatorLayerBlendingMode;
23797
24215
  var clipTime = playData.clipTime, playState = playData.playState;
23798
24216
  eventHandlers.length && this._fireAnimationEvents(playData, eventHandlers, lastClipTime, clipTime);
23799
24217
  for(var i = curveBindings.length - 1; i >= 0; i--){
23800
- var owner = curveOwners[i];
23801
- owner == null ? void 0 : owner.evaluateAndApplyValue(curveBindings[i].curve, clipTime, weight, additive);
24218
+ var _curveLayerOwner_i;
24219
+ (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner.evaluateAndApplyValue(curveBindings[i].curve, clipTime, weight, additive);
23802
24220
  }
23803
24221
  playData.frameTime += state.speed * delta;
23804
24222
  if (playState === AnimatorStatePlayState.Finished) {
@@ -23814,7 +24232,7 @@ var AnimatorLayerBlendingMode;
23814
24232
  }
23815
24233
  };
23816
24234
  _proto._updateCrossFade = function _updateCrossFade(srcPlayData, destPlayData, layerData, layerIndex, weight, delta, additive, aniUpdate) {
23817
- var _this = this, crossCurveDataCollection = _this._crossOwnerCollection;
24235
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
23818
24236
  var _srcPlayData_state_clip = srcPlayData.state.clip, srcCurves = _srcPlayData_state_clip._curveBindings;
23819
24237
  var srcState = srcPlayData.state, srcStateData = srcPlayData.stateData, lastSrcPlayState = srcPlayData.playState;
23820
24238
  var srcEventHandlers = srcStateData.eventHandlers;
@@ -23853,14 +24271,16 @@ var AnimatorLayerBlendingMode;
23853
24271
  } else {
23854
24272
  this._callAnimatorScriptOnUpdate(destState, layerIndex);
23855
24273
  }
23856
- for(var i = crossCurveDataCollection.length - 1; i >= 0; i--){
23857
- var crossCurveData = crossCurveDataCollection[i];
23858
- var crossSrcCurveIndex = crossCurveData.crossSrcCurveIndex, crossDestCurveIndex = crossCurveData.crossDestCurveIndex;
23859
- crossCurveData.crossFadeAndApplyValue(crossSrcCurveIndex >= 0 ? srcCurves[crossSrcCurveIndex].curve : null, crossDestCurveIndex >= 0 ? destCurves[crossDestCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, weight, additive);
24274
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24275
+ var layerOwner = crossOwnerLayerDataCollection[i];
24276
+ if (!layerOwner) continue;
24277
+ var srcCurveIndex = layerOwner.crossSrcCurveIndex;
24278
+ var destCurveIndex = layerOwner.crossDestCurveIndex;
24279
+ layerOwner.curveOwner.crossFadeAndApplyValue(srcCurveIndex >= 0 ? srcCurves[srcCurveIndex].curve : null, destCurveIndex >= 0 ? destCurves[destCurveIndex].curve : null, srcClipTime, destClipTime, crossWeight, weight, additive);
23860
24280
  }
23861
24281
  };
23862
24282
  _proto._updateCrossFadeFromPose = function _updateCrossFadeFromPose(destPlayData, layerData, layerIndex, layerWeight, delta, additive, aniUpdate) {
23863
- var crossCurveDataCollection = this._crossOwnerCollection;
24283
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
23864
24284
  var state = destPlayData.state, stateData = destPlayData.stateData, lastPlayState = destPlayData.playState;
23865
24285
  var eventHandlers = stateData.eventHandlers;
23866
24286
  var _state_clip = state.clip, curveBindings = _state_clip._curveBindings;
@@ -23884,10 +24304,11 @@ var AnimatorLayerBlendingMode;
23884
24304
  } else {
23885
24305
  this._callAnimatorScriptOnUpdate(state, layerIndex);
23886
24306
  }
23887
- for(var i = crossCurveDataCollection.length - 1; i >= 0; i--){
23888
- var crossCurveData = crossCurveDataCollection[i];
23889
- var crossDestCurveIndex = crossCurveData.crossDestCurveIndex;
23890
- crossCurveData.crossFadeFromPoseAndApplyValue(crossDestCurveIndex >= 0 ? curveBindings[crossDestCurveIndex].curve : null, destClipTime, crossWeight, layerWeight, additive);
24307
+ for(var i = crossOwnerLayerDataCollection.length - 1; i >= 0; i--){
24308
+ var layerOwner = crossOwnerLayerDataCollection[i];
24309
+ if (!layerOwner) continue;
24310
+ var curveIndex = layerOwner.crossDestCurveIndex;
24311
+ layerOwner.curveOwner.crossFadeFromPoseAndApplyValue(curveIndex >= 0 ? curveBindings[curveIndex].curve : null, destClipTime, crossWeight, layerWeight, additive);
23891
24312
  }
23892
24313
  };
23893
24314
  _proto._updateCrossFadeData = function _updateCrossFadeData(layerData, crossWeight, delta, fixed) {
@@ -23909,18 +24330,19 @@ var AnimatorLayerBlendingMode;
23909
24330
  if (layerData.layerState === LayerState.Playing) {
23910
24331
  var srcPlayData = layerData.srcPlayData;
23911
24332
  if (srcPlayData.state !== playState) {
23912
- var curveOwners = srcPlayData.stateData.curveOwners;
23913
- for(var i = curveOwners.length - 1; i >= 0; i--){
23914
- var owner = curveOwners[i];
24333
+ var curveLayerOwner = srcPlayData.stateData.curveLayerOwner;
24334
+ for(var i = curveLayerOwner.length - 1; i >= 0; i--){
24335
+ var _curveLayerOwner_i;
24336
+ var owner = (_curveLayerOwner_i = curveLayerOwner[i]) == null ? void 0 : _curveLayerOwner_i.curveOwner;
23915
24337
  (owner == null ? void 0 : owner.hasSavedDefaultValue) && owner.revertDefaultValue();
23916
24338
  }
23917
24339
  this._saveDefaultValues(playStateData);
23918
24340
  }
23919
24341
  } else {
23920
24342
  // layerState is CrossFading, FixedCrossFading, Standby
23921
- var crossCurveDataCollection = this._crossOwnerCollection;
23922
- for(var i1 = crossCurveDataCollection.length - 1; i1 >= 0; i1--){
23923
- var owner1 = crossCurveDataCollection[i1];
24343
+ var crossOwnerLayerDataCollection = layerData.crossOwnerLayerDataCollection;
24344
+ for(var i1 = crossOwnerLayerDataCollection.length - 1; i1 >= 0; i1--){
24345
+ var owner1 = crossOwnerLayerDataCollection[i1].curveOwner;
23924
24346
  owner1.hasSavedDefaultValue && owner1.revertDefaultValue();
23925
24347
  }
23926
24348
  this._saveDefaultValues(playStateData);
@@ -24090,10 +24512,7 @@ __decorate([
24090
24512
  ], Animator.prototype, "_animatorLayersData", void 0);
24091
24513
  __decorate([
24092
24514
  ignoreClone
24093
- ], Animator.prototype, "_crossOwnerCollection", void 0);
24094
- __decorate([
24095
- ignoreClone
24096
- ], Animator.prototype, "_animationCurveOwners", void 0);
24515
+ ], Animator.prototype, "_curveOwnerPool", void 0);
24097
24516
  __decorate([
24098
24517
  ignoreClone
24099
24518
  ], Animator.prototype, "_animationEventHandlerPool", void 0);
@@ -25526,7 +25945,9 @@ var _tempVector3 = new Vector3();
25526
25945
  this.getMaterial().shaderData.setTexture("u_texture", texture);
25527
25946
  }
25528
25947
  };
25529
- _proto._render = function _render(context) {
25948
+ /**
25949
+ * @internal
25950
+ */ _proto._render = function _render(context) {
25530
25951
  this._updateStrapVertices(context.camera, this._points);
25531
25952
  this._updateStrapCoords();
25532
25953
  this._vertexBuffer.setData(this._vertices);
@@ -25720,7 +26141,7 @@ var cacheDir = new Vector3();
25720
26141
  /**
25721
26142
  * The position of the probe can be set, the default is the origin [0,0,0].
25722
26143
  */ _this.position = new Vector3(0, 0, 0);
25723
- _this._isCube = true;
26144
+ /** @internal */ _this._isCube = true;
25724
26145
  _this.oriViewMatrix = new Matrix();
25725
26146
  return _this;
25726
26147
  }
@@ -25792,5 +26213,5 @@ var cacheDir = new Vector3();
25792
26213
  return CubeProbe;
25793
26214
  }(Probe);
25794
26215
 
25795
- export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, Basic2DBatcher, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlinnPhongMaterial, BoolUpdateFlag, BoxColliderShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Camera, CameraClearFlags, CapsuleColliderShape, CharacterController, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorSpace, ColorWriteMask, CompareFunction, Component, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, DataType, DependentMode, DiffuseMode, DirectLight, DynamicCollider, DynamicColliderConstraints, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, Light, Loader, Logger, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleRenderer, ParticleRendererBlendMode, PhysicsManager, PhysicsMaterial, PhysicsMaterialCombineMode, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, PrimitiveMesh, Probe, ReferResource, RenderBufferDepthFormat, RenderFace, RenderPass, RenderQueue, RenderQueueType, RenderTarget, Renderer, ResourceManager, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, SubMesh, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureWrapMode, Time, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
26216
+ export { AmbientLight, AnimationArrayCurve, AnimationBoolCurve, AnimationClip, AnimationClipCurveBinding, AnimationColorCurve, AnimationCurve, AnimationEvent, AnimationFloatArrayCurve, AnimationFloatCurve, AnimationQuaternionCurve, AnimationVector2Curve, AnimationVector3Curve, AnimationVector4Curve, Animator, AnimatorConditionMode, AnimatorController, AnimatorControllerLayer, AnimatorCullingMode, AnimatorLayerBlendingMode, AnimatorState, AnimatorStateMachine, AnimatorStateTransition, AssetPromise, AssetType, Background, BackgroundMode, BackgroundTextureFillMode, BaseMaterial, Basic2DBatcher, BasicRenderPipeline, BlendFactor, BlendMode, BlendOperation, BlendShape, BlendShapeFrame, BlendState, BlinnPhongMaterial, BoolUpdateFlag, BoxColliderShape, Buffer, BufferBindFlag, BufferMesh, BufferUsage, BufferUtil, Camera, CameraClearFlags, CapsuleColliderShape, CharacterController, CloneManager, Collider, ColliderShape, ColliderShapeUpAxis, CollisionDetectionMode, ColorSpace, ColorWriteMask, CompareFunction, Component, ContentRestorer, ControllerCollisionFlag, ControllerNonWalkableMode, CubeProbe, CullMode, DataType, DependentMode, DepthState, DiffuseMode, DirectLight, DynamicCollider, DynamicColliderConstraints, Engine, EngineObject, Entity, EventDispatcher, FixedJoint, FogMode, Font, FontStyle, GLCapabilityType, HingeJoint, HitResult, IndexBufferBinding, IndexFormat, InputManager, InterpolationType, Joint, JointLimits, JointMotor, Keyframe, Keys, Layer, Light, Loader, Logger, Material, Mesh, MeshRenderer, MeshTopology, ModelMesh, OverflowMode, PBRBaseMaterial, PBRMaterial, PBRSpecularMaterial, ParticleRenderer, ParticleRendererBlendMode, PhysicsManager, PhysicsMaterial, PhysicsMaterialCombineMode, PipelineStage, PlaneColliderShape, Platform, PointLight, Pointer, PointerButton, PointerPhase, PrimitiveMesh, Probe, RasterState, ReferResource, RenderBufferDepthFormat, RenderFace, RenderPass, RenderQueue, RenderQueueType, RenderState, RenderTarget, RenderTargetBlendState, Renderer, ResourceManager, Scene, SceneManager, Script, SetDataOptions, Shader, ShaderData, ShaderFactory, ShaderMacro, ShaderMacroCollection, ShaderPass, ShaderProperty, ShaderPropertyType, ShaderTagKey, ShadowCascadesMode, ShadowResolution, ShadowType, Skin, SkinnedMeshRenderer, Sky, SkyBoxMaterial, SkyProceduralMaterial, SphereColliderShape, SpotLight, SpringJoint, Sprite, SpriteAtlas, SpriteDrawMode, SpriteMask, SpriteMaskInteraction, SpriteMaskLayer, SpriteRenderer, SpriteTileMode, StateMachineScript, StaticCollider, StencilOperation, StencilState, SubMesh, SubShader, SunMode, SystemInfo, TextHorizontalAlignment, TextRenderer, TextUtils, TextVerticalAlignment, Texture, Texture2D, Texture2DArray, TextureCoordinate, TextureCube, TextureCubeFace, TextureDepthCompareFunction, TextureFilterMode, TextureFormat, TextureWrapMode, Time, TrailMaterial, TrailRenderer, Transform, UnlitMaterial, Utils, VertexBufferBinding, VertexElement, VertexElementFormat, WrapMode, assignmentClone, deepClone, dependentComponents, ignoreClone, request, resourceLoader, shallowClone };
25796
26217
  //# sourceMappingURL=module.js.map