@galacean/engine-core 0.9.11 → 0.9.13

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/module.js CHANGED
@@ -1461,9 +1461,11 @@ var GLCapabilityType;
1461
1461
  renderTexture
1462
1462
  ];
1463
1463
  for(var i = 0, n = colorTextures.length; i < n; i++){
1464
- if (colorTextures[i]._isDepthTexture) {
1464
+ var colorTexture = colorTextures[i];
1465
+ if (colorTexture._isDepthTexture) {
1465
1466
  throw "Render texture can't use depth format.";
1466
1467
  }
1468
+ colorTexture._addRefCount(1);
1467
1469
  }
1468
1470
  _this._colorTextures = colorTextures;
1469
1471
  } else {
@@ -1474,6 +1476,7 @@ var GLCapabilityType;
1474
1476
  throw "Depth texture must use depth format.";
1475
1477
  }
1476
1478
  _this._depthTexture = depth;
1479
+ _this._depthTexture._addRefCount(1);
1477
1480
  }
1478
1481
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
1479
1482
  return _this;
@@ -1502,8 +1505,14 @@ var GLCapabilityType;
1502
1505
  /**
1503
1506
  * Destroy render target.
1504
1507
  */ _proto.destroy = function destroy() {
1508
+ var _this__depthTexture;
1505
1509
  this._platformRenderTarget.destroy();
1506
- this._colorTextures.length = 0;
1510
+ var _this = this, colorTextures = _this._colorTextures;
1511
+ for(var i = 0, n = colorTextures.length; i < n; i++){
1512
+ colorTextures[i]._addRefCount(-1);
1513
+ }
1514
+ colorTextures.length = 0;
1515
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
1507
1516
  this._depthTexture = null;
1508
1517
  this._depth = null;
1509
1518
  };
@@ -1949,6 +1958,7 @@ var GLCapabilityType;
1949
1958
  var fontAtlas = new FontAtlas(engine);
1950
1959
  var texture = new Texture2D(engine, 256, 256);
1951
1960
  fontAtlas.texture = texture;
1961
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
1952
1962
  this._fontAtlases.push(fontAtlas);
1953
1963
  return fontAtlas;
1954
1964
  };
@@ -2228,6 +2238,28 @@ var /** @internal */ PromiseState;
2228
2238
  * @remarks The release principle is that it is not referenced by the components, including direct and indirect reference.
2229
2239
  */ _proto.gc = function gc() {
2230
2240
  this._gc(false);
2241
+ var engine = this.engine;
2242
+ engine._renderElementPool.garbageCollection();
2243
+ engine._spriteElementPool.garbageCollection();
2244
+ engine._spriteMaskElementPool.garbageCollection();
2245
+ engine._textElementPool.garbageCollection();
2246
+ var _componentsManager = engine._componentsManager, _lightManager = engine._lightManager;
2247
+ _componentsManager._renderers.garbageCollection();
2248
+ // @ts-ignore
2249
+ _componentsManager._onStartScripts.garbageCollection();
2250
+ // @ts-ignore
2251
+ _componentsManager._onUpdateScripts.garbageCollection();
2252
+ // @ts-ignore
2253
+ _componentsManager._onLateUpdateScripts.garbageCollection();
2254
+ // @ts-ignore
2255
+ _componentsManager._onPhysicsUpdateScripts.garbageCollection();
2256
+ // @ts-ignore
2257
+ _componentsManager._onUpdateAnimations.garbageCollection();
2258
+ // @ts-ignore
2259
+ _componentsManager._onUpdateRenderers.garbageCollection();
2260
+ _lightManager._spotLights.garbageCollection();
2261
+ _lightManager._pointLights.garbageCollection();
2262
+ _lightManager._directLights.garbageCollection();
2231
2263
  };
2232
2264
  /**
2233
2265
  * @internal
@@ -4070,6 +4102,11 @@ var TransformModifyFlags;
4070
4102
  * @returns Cloned entity
4071
4103
  */ _proto.clone = function clone() {
4072
4104
  var cloneEntity = new Entity(this._engine, this.name);
4105
+ var _this = this, hookResource = _this._hookResource;
4106
+ if (hookResource) {
4107
+ cloneEntity._hookResource = hookResource;
4108
+ hookResource._addRefCount(1);
4109
+ }
4073
4110
  cloneEntity._isActive = this._isActive;
4074
4111
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
4075
4112
  var children = this._children;
@@ -4094,6 +4131,10 @@ var TransformModifyFlags;
4094
4131
  return;
4095
4132
  }
4096
4133
  EngineObject.prototype.destroy.call(this);
4134
+ if (this._hookResource) {
4135
+ this._hookResource._addRefCount(-1);
4136
+ this._hookResource = null;
4137
+ }
4097
4138
  var components = this._components;
4098
4139
  for(var i = components.length - 1; i >= 0; i--){
4099
4140
  components[i].destroy();
@@ -8754,6 +8795,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8754
8795
  _proto.cloneTo = function cloneTo(target) {
8755
8796
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8756
8797
  Object.assign(target._macroMap, this._macroMap);
8798
+ var referCount = target._getRefCount();
8757
8799
  var propertyValueMap = this._propertyValueMap;
8758
8800
  var targetPropertyValueMap = target._propertyValueMap;
8759
8801
  var keys = Object.keys(propertyValueMap);
@@ -8765,6 +8807,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8765
8807
  targetPropertyValueMap[k] = property;
8766
8808
  } else if (_instanceof(property, Texture)) {
8767
8809
  targetPropertyValueMap[k] = property;
8810
+ referCount > 0 && property._addRefCount(referCount);
8768
8811
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8769
8812
  targetPropertyValueMap[k] = property.slice();
8770
8813
  } else {
@@ -9768,9 +9811,9 @@ __decorate([
9768
9811
  function Material(engine, shader) {
9769
9812
  var _this;
9770
9813
  _this = RefObject.call(this, engine) || this;
9771
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Material);
9772
9814
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
9773
9815
  ;
9816
+ _this._shaderData = new ShaderData(ShaderDataGroup.Material);
9774
9817
  _this.shader = shader;
9775
9818
  return _this;
9776
9819
  }
@@ -9802,8 +9845,21 @@ __decorate([
9802
9845
  */ _proto._preRender = function _preRender(renderElement) {};
9803
9846
  /**
9804
9847
  * @override
9805
- */ _proto._onDestroy = function _onDestroy() {};
9848
+ */ _proto._onDestroy = function _onDestroy() {
9849
+ this._shader = null;
9850
+ this._shaderData = null;
9851
+ this._renderStates.length = 0;
9852
+ this._renderStates = null;
9853
+ };
9806
9854
  _create_class(Material, [
9855
+ {
9856
+ key: "shaderData",
9857
+ get: /**
9858
+ * Shader data.
9859
+ */ function get() {
9860
+ return this._shaderData;
9861
+ }
9862
+ },
9807
9863
  {
9808
9864
  key: "shader",
9809
9865
  get: /**
@@ -9872,6 +9928,12 @@ __decorate([
9872
9928
  */ _proto.resetPool = function resetPool() {
9873
9929
  this._elementPoolIndex = 0;
9874
9930
  };
9931
+ _proto.garbageCollection = function garbageCollection() {
9932
+ var _this = this, pool = _this._elementPool;
9933
+ for(var i = pool.length - 1; i >= 0; i--){
9934
+ pool[i].dispose && pool[i].dispose();
9935
+ }
9936
+ };
9875
9937
  return ClassPool;
9876
9938
  }();
9877
9939
 
@@ -9894,6 +9956,9 @@ var RenderElement = function RenderElement() {
9894
9956
  this.renderState = renderState;
9895
9957
  this.shaderPass = shaderPass;
9896
9958
  };
9959
+ _proto.dispose = function dispose() {
9960
+ this.component = this.mesh = this.subMesh = this.material = this.renderState = this.shaderPass = null;
9961
+ };
9897
9962
  return MeshRenderElement;
9898
9963
  }(RenderElement);
9899
9964
 
@@ -9939,6 +10004,9 @@ var SpriteElement = /*#__PURE__*/ function(RenderElement) {
9939
10004
  this.renderState = renderState;
9940
10005
  this.shaderPass = shaderPass;
9941
10006
  };
10007
+ _proto.dispose = function dispose() {
10008
+ this.component = this.renderData = this.material = this.texture = this.renderState = this.shaderPass = null;
10009
+ };
9942
10010
  return SpriteElement;
9943
10011
  }(RenderElement);
9944
10012
 
@@ -9957,6 +10025,9 @@ var SpriteMaskElement = /*#__PURE__*/ function(RenderElement) {
9957
10025
  this.renderData = renderData;
9958
10026
  this.material = material;
9959
10027
  };
10028
+ _proto.dispose = function dispose() {
10029
+ this.component = this.renderData = this.material = null;
10030
+ };
9960
10031
  return SpriteMaskElement;
9961
10032
  }(RenderElement);
9962
10033
 
@@ -9975,7 +10046,6 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
9975
10046
  function Renderer1(entity) {
9976
10047
  var _this;
9977
10048
  _this = Component.call(this, entity) || this;
9978
- /** ShaderData related to renderer. */ _this.shaderData = new ShaderData(ShaderDataGroup.Renderer);
9979
10049
  /** @internal */ _this._onUpdateIndex = -1;
9980
10050
  /** @internal */ _this._rendererIndex = -1;
9981
10051
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
@@ -9983,6 +10053,7 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
9983
10053
  _this._overrideUpdate = false;
9984
10054
  _this._materials = [];
9985
10055
  _this._dirtyUpdateFlag = 0;
10056
+ _this._shaderData = new ShaderData(ShaderDataGroup.Renderer);
9986
10057
  _this._mvMatrix = new Matrix();
9987
10058
  _this._mvpMatrix = new Matrix();
9988
10059
  _this._mvInvMatrix = new Matrix();
@@ -10129,6 +10200,17 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10129
10200
  var _materials_i;
10130
10201
  (_materials_i = materials[i]) == null ? void 0 : _materials_i._addRefCount(-1);
10131
10202
  }
10203
+ this._entity = null;
10204
+ this._globalShaderMacro = null;
10205
+ this._bounds = null;
10206
+ this._materials = null;
10207
+ this._shaderData = null;
10208
+ this._mvMatrix = null;
10209
+ this._mvpMatrix = null;
10210
+ this._mvInvMatrix = null;
10211
+ this._normalMatrix = null;
10212
+ this._materialsInstanced = null;
10213
+ this._rendererLayer = null;
10132
10214
  };
10133
10215
  _proto._updateShaderData = function _updateShaderData(context) {
10134
10216
  var entity = this.entity;
@@ -10190,6 +10272,14 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10190
10272
  this._dirtyUpdateFlag |= 0x1;
10191
10273
  };
10192
10274
  _create_class(Renderer1, [
10275
+ {
10276
+ key: "shaderData",
10277
+ get: /**
10278
+ * ShaderData related to renderer.
10279
+ */ function get() {
10280
+ return this._shaderData;
10281
+ }
10282
+ },
10193
10283
  {
10194
10284
  key: "isCulled",
10195
10285
  get: /**
@@ -10274,9 +10364,6 @@ var Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10274
10364
  }(), function() {
10275
10365
  _Renderer._rendererLayerProperty = Shader.getPropertyByName("oasis_RendererLayer");
10276
10366
  }(), _Renderer);
10277
- __decorate([
10278
- deepClone
10279
- ], Renderer.prototype, "shaderData", void 0);
10280
10367
  __decorate([
10281
10368
  ignoreClone
10282
10369
  ], Renderer.prototype, "_distanceForSort", void 0);
@@ -10304,6 +10391,9 @@ __decorate([
10304
10391
  __decorate([
10305
10392
  ignoreClone
10306
10393
  ], Renderer.prototype, "_dirtyUpdateFlag", void 0);
10394
+ __decorate([
10395
+ deepClone
10396
+ ], Renderer.prototype, "_shaderData", void 0);
10307
10397
  __decorate([
10308
10398
  ignoreClone
10309
10399
  ], Renderer.prototype, "_mvMatrix", void 0);
@@ -10509,16 +10599,6 @@ SimpleSpriteAssembler = __decorate([
10509
10599
  }
10510
10600
  var _proto = SpriteMask.prototype;
10511
10601
  /**
10512
- * @override
10513
- * @inheritdoc
10514
- */ _proto._onDestroy = function _onDestroy() {
10515
- var _this__sprite;
10516
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10517
- this._sprite = null;
10518
- this._renderData = null;
10519
- Renderer.prototype._onDestroy.call(this);
10520
- };
10521
- /**
10522
10602
  * @internal
10523
10603
  */ _proto._cloneTo = function _cloneTo(target) {
10524
10604
  Renderer.prototype._cloneTo.call(this, target);
@@ -10558,6 +10638,20 @@ SimpleSpriteAssembler = __decorate([
10558
10638
  context.camera._renderPipeline._allSpriteMasks.add(this);
10559
10639
  this._maskElement = maskElement;
10560
10640
  };
10641
+ /**
10642
+ * @internal
10643
+ * @inheritdoc
10644
+ */ _proto._onDestroy = function _onDestroy() {
10645
+ Renderer.prototype._onDestroy.call(this);
10646
+ var sprite = this._sprite;
10647
+ if (sprite) {
10648
+ sprite._addRefCount(-1);
10649
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10650
+ }
10651
+ this._entity = null;
10652
+ this._sprite = null;
10653
+ this._renderData = null;
10654
+ };
10561
10655
  _proto._calDefaultSize = function _calDefaultSize() {
10562
10656
  var sprite = this._sprite;
10563
10657
  if (sprite) {
@@ -10676,9 +10770,13 @@ SimpleSpriteAssembler = __decorate([
10676
10770
  set: function set(value) {
10677
10771
  var lastSprite = this._sprite;
10678
10772
  if (lastSprite !== value) {
10679
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10773
+ if (lastSprite) {
10774
+ lastSprite._addRefCount(-1);
10775
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10776
+ }
10680
10777
  this._dirtyUpdateFlag |= 0x7;
10681
10778
  if (value) {
10779
+ value._addRefCount(1);
10682
10780
  value._updateFlagManager.addListener(this._onSpriteChange);
10683
10781
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10684
10782
  } else {
@@ -11156,14 +11254,19 @@ var BufferUtil = /*#__PURE__*/ function() {
11156
11254
 
11157
11255
  /**
11158
11256
  * Sub-mesh, mainly contains drawing information.
11159
- */ var SubMesh = function SubMesh(start, count, topology) {
11160
- if (start === void 0) start = 0;
11161
- if (count === void 0) count = 0;
11162
- if (topology === void 0) topology = MeshTopology.Triangles;
11163
- this.start = start;
11164
- this.count = count;
11165
- this.topology = topology;
11166
- };
11257
+ */ var SubMesh = /*#__PURE__*/ function() {
11258
+ function SubMesh(start, count, topology) {
11259
+ if (start === void 0) start = 0;
11260
+ if (count === void 0) count = 0;
11261
+ if (topology === void 0) topology = MeshTopology.Triangles;
11262
+ this.start = start;
11263
+ this.count = count;
11264
+ this.topology = topology;
11265
+ }
11266
+ var _proto = SubMesh.prototype;
11267
+ _proto.dispose = function dispose() {};
11268
+ return SubMesh;
11269
+ }();
11167
11270
 
11168
11271
  /**
11169
11272
  * Mesh.
@@ -11245,10 +11348,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11245
11348
  /**
11246
11349
  * @internal
11247
11350
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11248
- if (this._getRefCount() > 0) {
11249
- var lastBinding = this._vertexBufferBindings[index];
11250
- lastBinding && lastBinding._buffer._addRefCount(-1);
11251
- binding._buffer._addRefCount(1);
11351
+ var referCount = this._getRefCount();
11352
+ if (referCount > 0) {
11353
+ var _this__vertexBufferBindings_index;
11354
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11355
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11252
11356
  }
11253
11357
  this._vertexBufferBindings[index] = binding;
11254
11358
  this._bufferStructChanged = true;
@@ -11262,11 +11366,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11262
11366
  /**
11263
11367
  * @override
11264
11368
  */ _proto._addRefCount = function _addRefCount(value) {
11369
+ var _this__indexBufferBinding;
11265
11370
  RefObject.prototype._addRefCount.call(this, value);
11266
11371
  var vertexBufferBindings = this._vertexBufferBindings;
11267
11372
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11268
11373
  vertexBufferBindings[i]._buffer._addRefCount(value);
11269
11374
  }
11375
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11270
11376
  };
11271
11377
  /**
11272
11378
  * @override
@@ -11276,6 +11382,7 @@ var BufferUtil = /*#__PURE__*/ function() {
11276
11382
  this._indexBufferBinding = null;
11277
11383
  this._vertexElements = null;
11278
11384
  this._vertexElementMap = null;
11385
+ this._updateFlagManager = null;
11279
11386
  this._platformPrimitive.destroy();
11280
11387
  };
11281
11388
  _proto._setVertexElements = function _setVertexElements(elements) {
@@ -11286,6 +11393,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11286
11393
  };
11287
11394
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11288
11395
  var lastBinding = this._indexBufferBinding;
11396
+ var referCount = this._getRefCount();
11397
+ if (referCount > 0) {
11398
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11399
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11400
+ }
11289
11401
  if (binding) {
11290
11402
  this._indexBufferBinding = binding;
11291
11403
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -12956,8 +13068,8 @@ var VertexChangedFlags;
12956
13068
  */ _proto._onDestroy = function _onDestroy() {
12957
13069
  Renderer.prototype._onDestroy.call(this);
12958
13070
  var mesh = this._mesh;
12959
- if (mesh && !mesh.destroyed) {
12960
- mesh._addRefCount(-1);
13071
+ if (mesh) {
13072
+ mesh.destroyed || mesh._addRefCount(-1);
12961
13073
  mesh._updateFlagManager.removeListener(this._onMeshChanged);
12962
13074
  this._mesh = null;
12963
13075
  }
@@ -13294,10 +13406,21 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13294
13406
  * @internal
13295
13407
  * @override
13296
13408
  */ _proto._onDestroy = function _onDestroy() {
13297
- var _this_rootBone, _this__jointTexture;
13409
+ var _this__rootBone, _this__jointTexture;
13298
13410
  MeshRenderer.prototype._onDestroy.call(this);
13299
- (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13411
+ (_this__rootBone = this._rootBone) == null ? void 0 : _this__rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13412
+ this._rootBone = null;
13413
+ this._jointDataCreateCache = null;
13414
+ this._skin = null;
13415
+ this._blendShapeWeights = null;
13416
+ this._localBounds = null;
13417
+ this._jointMatrices = null;
13300
13418
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13419
+ this._jointTexture = null;
13420
+ if (this._jointEntities) {
13421
+ this._jointEntities.length = 0;
13422
+ this._jointEntities = null;
13423
+ }
13301
13424
  };
13302
13425
  /**
13303
13426
  * @internal
@@ -14464,14 +14587,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14464
14587
  _proto._createMesh = function _createMesh(engine, index) {
14465
14588
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14466
14589
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14590
+ mesh.isGCIgnored = true;
14467
14591
  var vertexElements = [];
14468
14592
  var vertexStride = this.createVertexElements(vertexElements);
14469
14593
  // vertices
14470
- this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
14594
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, BufferUsage.Dynamic);
14595
+ vertexBuffer.isGCIgnored = true;
14471
14596
  // indices
14472
- this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, BufferUsage.Dynamic);
14473
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14474
- mesh.setIndexBufferBinding(this._indiceBuffers[index], IndexFormat.UInt16);
14597
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, BufferUsage.Dynamic);
14598
+ indiceBuffer.isGCIgnored = true;
14599
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14600
+ mesh.setIndexBufferBinding(indiceBuffer, IndexFormat.UInt16);
14475
14601
  mesh.setVertexElements(vertexElements);
14476
14602
  return mesh;
14477
14603
  };
@@ -14682,6 +14808,11 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14682
14808
  _this.multiRenderData = true;
14683
14809
  return _this;
14684
14810
  }
14811
+ var _proto = TextRenderElement.prototype;
14812
+ _proto.dispose = function dispose() {
14813
+ this.component = this.material = this.renderState = this.shaderPass = null;
14814
+ this.charElements.length = 0;
14815
+ };
14685
14816
  return TextRenderElement;
14686
14817
  }(RenderElement);
14687
14818
 
@@ -14710,6 +14841,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14710
14841
  var _proto = Sky.prototype;
14711
14842
  /**
14712
14843
  * @internal
14844
+ */ _proto.destroy = function destroy() {
14845
+ this.mesh = null;
14846
+ this.material = null;
14847
+ };
14848
+ /**
14849
+ * @internal
14713
14850
  */ _proto._render = function _render(context) {
14714
14851
  var _this = this, material = _this.material, mesh = _this.mesh;
14715
14852
  if (!material) {
@@ -14748,6 +14885,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14748
14885
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14749
14886
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14750
14887
  };
14888
+ _create_class(Sky, [
14889
+ {
14890
+ key: "material",
14891
+ get: /**
14892
+ * Material of the sky.
14893
+ */ function get() {
14894
+ return this._material;
14895
+ },
14896
+ set: function set(value) {
14897
+ if (this._material !== value) {
14898
+ var _this__material;
14899
+ value == null ? void 0 : value._addRefCount(1);
14900
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14901
+ this._material = value;
14902
+ }
14903
+ }
14904
+ },
14905
+ {
14906
+ key: "mesh",
14907
+ get: /**
14908
+ * Mesh of the sky.
14909
+ */ function get() {
14910
+ return this._mesh;
14911
+ },
14912
+ set: function set(value) {
14913
+ if (this._mesh !== value) {
14914
+ var _this__mesh;
14915
+ value == null ? void 0 : value._addRefCount(1);
14916
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14917
+ this._mesh = value;
14918
+ }
14919
+ }
14920
+ }
14921
+ ]);
14751
14922
  return Sky;
14752
14923
  }();
14753
14924
  (function() {
@@ -14778,11 +14949,27 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14778
14949
  this.sky = new Sky();
14779
14950
  this./** @internal */ _textureFillMode = BackgroundTextureFillMode.AspectFitHeight;
14780
14951
  this._texture = null;
14781
- this._mesh = this._createPlane(_engine);
14952
+ this._initMesh(_engine);
14782
14953
  }
14783
14954
  var _proto = Background.prototype;
14784
14955
  /**
14785
14956
  * @internal
14957
+ */ _proto.destroy = function destroy() {
14958
+ this._mesh._addRefCount(-1);
14959
+ this._mesh = null;
14960
+ this.texture = null;
14961
+ this.solidColor = null;
14962
+ this.sky.destroy();
14963
+ };
14964
+ /**
14965
+ * @internal
14966
+ * Standalone for CanvasRenderer plugin.
14967
+ */ _proto._initMesh = function _initMesh(engine) {
14968
+ this._mesh = this._createPlane(engine);
14969
+ this._mesh._addRefCount(1);
14970
+ };
14971
+ /**
14972
+ * @internal
14786
14973
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14787
14974
  if (!this._texture) {
14788
14975
  return;
@@ -14851,6 +15038,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14851
15038
  },
14852
15039
  set: function set(value) {
14853
15040
  if (this._texture !== value) {
15041
+ var _this__texture;
15042
+ value == null ? void 0 : value._addRefCount(1);
15043
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14854
15044
  this._texture = value;
14855
15045
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14856
15046
  }
@@ -15154,8 +15344,6 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15154
15344
  function Scene(engine, name) {
15155
15345
  var _this;
15156
15346
  _this = EngineObject.call(this, engine) || this;
15157
- /** The background of the scene. */ _this.background = new Background(_this._engine);
15158
- /** Scene-related shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Scene);
15159
15347
  /** If cast shadows. */ _this.castShadows = true;
15160
15348
  /** The resolution of the shadow maps. */ _this.shadowResolution = ShadowResolution.Medium;
15161
15349
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
@@ -15165,6 +15353,8 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15165
15353
  /** @internal */ _this._isActiveInEngine = false;
15166
15354
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
15167
15355
  /** @internal */ _this._rootEntities = [];
15356
+ _this._background = new Background(_this._engine);
15357
+ _this._shaderData = new ShaderData(ShaderDataGroup.Scene);
15168
15358
  _this._shadowCascades = ShadowCascadesMode.NoCascades;
15169
15359
  _this._fogMode = FogMode.None;
15170
15360
  _this._fogColor = new Color$1(0.5, 0.5, 0.5, 1.0);
@@ -15326,6 +15516,8 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15326
15516
  var sunLightIndex = lightManager._getSunLightIndex();
15327
15517
  if (sunLightIndex !== -1) {
15328
15518
  this._sunLight = lightManager._directLights.get(sunLightIndex);
15519
+ } else {
15520
+ this._sunLight = null;
15329
15521
  }
15330
15522
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== ShadowType.None) {
15331
15523
  shaderData.enableMacro("SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -15354,6 +15546,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15354
15546
  this._rootEntities[0].destroy();
15355
15547
  }
15356
15548
  this._activeCameras.length = 0;
15549
+ this.background.destroy();
15357
15550
  this.shaderData._addRefCount(-1);
15358
15551
  };
15359
15552
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15384,6 +15577,22 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15384
15577
  this._fogParams.w = density / Math.sqrt(Math.LN2);
15385
15578
  };
15386
15579
  _create_class(Scene, [
15580
+ {
15581
+ key: "shaderData",
15582
+ get: /**
15583
+ * Scene-related shader data.
15584
+ */ function get() {
15585
+ return this._shaderData;
15586
+ }
15587
+ },
15588
+ {
15589
+ key: "background",
15590
+ get: /**
15591
+ * The background of the scene.
15592
+ */ function get() {
15593
+ return this._background;
15594
+ }
15595
+ },
15387
15596
  {
15388
15597
  key: "shadowCascades",
15389
15598
  get: /**
@@ -15767,7 +15976,7 @@ ShaderPool.init();
15767
15976
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15768
15977
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15769
15978
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15770
- _this._textDefaultFont.isGCIgnored = false;
15979
+ _this._textDefaultFont.isGCIgnored = true;
15771
15980
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15772
15981
  var magentaPixel = new Uint8Array([
15773
15982
  255,
@@ -15802,6 +16011,7 @@ ShaderPool.init();
15802
16011
  _this._magentaTexture2DArray = magentaTexture2DArray;
15803
16012
  }
15804
16013
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
16014
+ magentaMaterial.isGCIgnored = true;
15805
16015
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15806
16016
  _this._magentaMaterial = magentaMaterial;
15807
16017
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17334,7 +17544,11 @@ var /**
17334
17544
  var height = shadowCascades == ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17335
17545
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17336
17546
  }
17337
- this._renderTargets = null;
17547
+ var renderTargets = this._renderTargets;
17548
+ if (renderTargets) {
17549
+ renderTargets.destroy();
17550
+ this._renderTargets = null;
17551
+ }
17338
17552
  var viewportOffset = this._viewportOffsets;
17339
17553
  var shadowTileResolution1 = this._shadowTileResolution;
17340
17554
  switch(shadowCascades){
@@ -17670,7 +17884,6 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component) {
17670
17884
  function Camera1(entity) {
17671
17885
  var _this;
17672
17886
  _this = Component.call(this, entity) || this;
17673
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Camera);
17674
17887
  /** Rendering priority - A Camera with higher priority will be rendered on top of a camera with lower priority. */ _this.priority = 0;
17675
17888
  /** Whether to enable frustum culling, it is enabled by default. */ _this.enableFrustumCulling = true;
17676
17889
  /**
@@ -17684,6 +17897,7 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component) {
17684
17897
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
17685
17898
  /** @internal */ _this._frustum = new BoundingFrustum();
17686
17899
  /** @internal */ _this._virtualCamera = new VirtualCamera();
17900
+ _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
17687
17901
  _this._isProjMatSetting = false;
17688
17902
  _this._nearClipPlane = 0.1;
17689
17903
  _this._farClipPlane = 100;
@@ -17882,6 +18096,20 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component) {
17882
18096
  this._isInvViewProjDirty.destroy();
17883
18097
  this._isViewMatrixDirty.destroy();
17884
18098
  this.shaderData._addRefCount(-1);
18099
+ this._entity = null;
18100
+ this._globalShaderMacro = null;
18101
+ this._frustum = null;
18102
+ this._renderPipeline = null;
18103
+ this._virtualCamera = null;
18104
+ this._shaderData = null;
18105
+ this._frustumViewChangeFlag = null;
18106
+ this._transform = null;
18107
+ this._isViewMatrixDirty = null;
18108
+ this._isInvViewProjDirty = null;
18109
+ this._viewport = null;
18110
+ this._inverseProjectionMatrix = null;
18111
+ this._lastAspectSize = null;
18112
+ this._invViewProjMat = null;
17885
18113
  };
17886
18114
  _proto._projMatChange = function _projMatChange() {
17887
18115
  this._isFrustumProjectDirty = true;
@@ -17921,6 +18149,14 @@ var Camera = (_Camera = /*#__PURE__*/ function(Component) {
17921
18149
  return this._inverseProjectionMatrix;
17922
18150
  };
17923
18151
  _create_class(Camera1, [
18152
+ {
18153
+ key: "shaderData",
18154
+ get: /**
18155
+ * Shader data.
18156
+ */ function get() {
18157
+ return this._shaderData;
18158
+ }
18159
+ },
17924
18160
  {
17925
18161
  key: "nearClipPlane",
17926
18162
  get: /**
@@ -19376,10 +19612,17 @@ var TextVerticalAlignment;
19376
19612
  * @internal
19377
19613
  */ _proto._addSprite = function _addSprite(sprite) {
19378
19614
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19615
+ sprite._atlas = this;
19616
+ sprite.isGCIgnored = true;
19379
19617
  };
19380
19618
  /**
19381
19619
  * @override
19382
19620
  */ _proto._onDestroy = function _onDestroy() {
19621
+ var _this = this, sprites = _this._sprites;
19622
+ for(var i = 0, n = sprites.length; i < n; i++){
19623
+ sprites[i].destroy();
19624
+ }
19625
+ sprites.length = 0;
19383
19626
  this._sprites = null;
19384
19627
  this._spriteNamesToIndex = null;
19385
19628
  };
@@ -19480,10 +19723,29 @@ var TextVerticalAlignment;
19480
19723
  };
19481
19724
  /**
19482
19725
  * @override
19726
+ * @internal
19727
+ */ _proto._addRefCount = function _addRefCount(value) {
19728
+ var _this__atlas;
19729
+ RefObject.prototype._addRefCount.call(this, value);
19730
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19731
+ };
19732
+ /**
19733
+ * @override
19734
+ * @internal
19483
19735
  */ _proto._onDestroy = function _onDestroy() {
19484
- if (this._texture) {
19485
- this._texture = null;
19486
- }
19736
+ this._positions.length = 0;
19737
+ this._positions = null;
19738
+ this._uvs.length = 0;
19739
+ this._uvs = null;
19740
+ this._atlasRegion = null;
19741
+ this._atlasRegionOffset = null;
19742
+ this._region = null;
19743
+ this._pivot = null;
19744
+ this._border = null;
19745
+ this._bounds = null;
19746
+ this._atlas = null;
19747
+ this._texture = null;
19748
+ this._updateFlagManager = null;
19487
19749
  };
19488
19750
  _proto._calDefaultSize = function _calDefaultSize() {
19489
19751
  if (this._texture) {
@@ -19586,7 +19848,7 @@ var TextVerticalAlignment;
19586
19848
  key: "width",
19587
19849
  get: /**
19588
19850
  * The width of the sprite (in world coordinates).
19589
- *
19851
+ *
19590
19852
  * @remarks
19591
19853
  * If width is set, return the set value,
19592
19854
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19609,7 +19871,7 @@ var TextVerticalAlignment;
19609
19871
  key: "height",
19610
19872
  get: /**
19611
19873
  * The height of the sprite (in world coordinates).
19612
- *
19874
+ *
19613
19875
  * @remarks
19614
19876
  * If height is set, return the set value,
19615
19877
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19917,17 +20179,6 @@ SlicedSpriteAssembler = __decorate([
19917
20179
  target.drawMode = this._drawMode;
19918
20180
  };
19919
20181
  /**
19920
- * @internal
19921
- */ _proto._onDestroy = function _onDestroy() {
19922
- var _this__sprite;
19923
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19924
- this._color = null;
19925
- this._sprite = null;
19926
- this._assembler = null;
19927
- this._renderData = null;
19928
- Renderer.prototype._onDestroy.call(this);
19929
- };
19930
- /**
19931
20182
  * @override
19932
20183
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19933
20184
  if (this.sprite) {
@@ -19965,6 +20216,21 @@ SlicedSpriteAssembler = __decorate([
19965
20216
  context.camera._renderPipeline.pushPrimitive(spriteElement);
19966
20217
  }
19967
20218
  };
20219
+ /**
20220
+ * @internal
20221
+ */ _proto._onDestroy = function _onDestroy() {
20222
+ Renderer.prototype._onDestroy.call(this);
20223
+ var sprite = this._sprite;
20224
+ if (sprite) {
20225
+ sprite._addRefCount(-1);
20226
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20227
+ }
20228
+ this._entity = null;
20229
+ this._color = null;
20230
+ this._sprite = null;
20231
+ this._assembler = null;
20232
+ this._renderData = null;
20233
+ };
19968
20234
  _proto._calDefaultSize = function _calDefaultSize() {
19969
20235
  var sprite = this._sprite;
19970
20236
  if (sprite) {
@@ -20056,9 +20322,13 @@ SlicedSpriteAssembler = __decorate([
20056
20322
  set: function set(value) {
20057
20323
  var lastSprite = this._sprite;
20058
20324
  if (lastSprite !== value) {
20059
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20325
+ if (lastSprite) {
20326
+ lastSprite._addRefCount(-1);
20327
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20328
+ }
20060
20329
  this._dirtyUpdateFlag |= 0x7;
20061
20330
  if (value) {
20331
+ value._addRefCount(1);
20062
20332
  value._updateFlagManager.addListener(this._onSpriteChange);
20063
20333
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
20064
20334
  } else {
@@ -22502,9 +22772,16 @@ var AnimatorLayerBlendingMode;
22502
22772
 
22503
22773
  /**
22504
22774
  * @internal
22505
- */ var AnimationEventHandler = function AnimationEventHandler() {
22506
- this.handlers = [];
22507
- };
22775
+ */ var AnimationEventHandler = /*#__PURE__*/ function() {
22776
+ function AnimationEventHandler() {
22777
+ this.handlers = [];
22778
+ }
22779
+ var _proto = AnimationEventHandler.prototype;
22780
+ _proto.dispose = function dispose() {
22781
+ this.handlers.length = 0;
22782
+ };
22783
+ return AnimationEventHandler;
22784
+ }();
22508
22785
 
22509
22786
  /**
22510
22787
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.