@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/main.js CHANGED
@@ -1465,9 +1465,11 @@ exports.GLCapabilityType = void 0;
1465
1465
  renderTexture
1466
1466
  ];
1467
1467
  for(var i = 0, n = colorTextures.length; i < n; i++){
1468
- if (colorTextures[i]._isDepthTexture) {
1468
+ var colorTexture = colorTextures[i];
1469
+ if (colorTexture._isDepthTexture) {
1469
1470
  throw "Render texture can't use depth format.";
1470
1471
  }
1472
+ colorTexture._addRefCount(1);
1471
1473
  }
1472
1474
  _this._colorTextures = colorTextures;
1473
1475
  } else {
@@ -1478,6 +1480,7 @@ exports.GLCapabilityType = void 0;
1478
1480
  throw "Depth texture must use depth format.";
1479
1481
  }
1480
1482
  _this._depthTexture = depth;
1483
+ _this._depthTexture._addRefCount(1);
1481
1484
  }
1482
1485
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
1483
1486
  return _this;
@@ -1506,8 +1509,14 @@ exports.GLCapabilityType = void 0;
1506
1509
  /**
1507
1510
  * Destroy render target.
1508
1511
  */ _proto.destroy = function destroy() {
1512
+ var _this__depthTexture;
1509
1513
  this._platformRenderTarget.destroy();
1510
- this._colorTextures.length = 0;
1514
+ var _this = this, colorTextures = _this._colorTextures;
1515
+ for(var i = 0, n = colorTextures.length; i < n; i++){
1516
+ colorTextures[i]._addRefCount(-1);
1517
+ }
1518
+ colorTextures.length = 0;
1519
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
1511
1520
  this._depthTexture = null;
1512
1521
  this._depth = null;
1513
1522
  };
@@ -1953,6 +1962,7 @@ exports.GLCapabilityType = void 0;
1953
1962
  var fontAtlas = new FontAtlas(engine);
1954
1963
  var texture = new Texture2D(engine, 256, 256);
1955
1964
  fontAtlas.texture = texture;
1965
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
1956
1966
  this._fontAtlases.push(fontAtlas);
1957
1967
  return fontAtlas;
1958
1968
  };
@@ -2232,6 +2242,28 @@ var /** @internal */ PromiseState;
2232
2242
  * @remarks The release principle is that it is not referenced by the components, including direct and indirect reference.
2233
2243
  */ _proto.gc = function gc() {
2234
2244
  this._gc(false);
2245
+ var engine = this.engine;
2246
+ engine._renderElementPool.garbageCollection();
2247
+ engine._spriteElementPool.garbageCollection();
2248
+ engine._spriteMaskElementPool.garbageCollection();
2249
+ engine._textElementPool.garbageCollection();
2250
+ var _componentsManager = engine._componentsManager, _lightManager = engine._lightManager;
2251
+ _componentsManager._renderers.garbageCollection();
2252
+ // @ts-ignore
2253
+ _componentsManager._onStartScripts.garbageCollection();
2254
+ // @ts-ignore
2255
+ _componentsManager._onUpdateScripts.garbageCollection();
2256
+ // @ts-ignore
2257
+ _componentsManager._onLateUpdateScripts.garbageCollection();
2258
+ // @ts-ignore
2259
+ _componentsManager._onPhysicsUpdateScripts.garbageCollection();
2260
+ // @ts-ignore
2261
+ _componentsManager._onUpdateAnimations.garbageCollection();
2262
+ // @ts-ignore
2263
+ _componentsManager._onUpdateRenderers.garbageCollection();
2264
+ _lightManager._spotLights.garbageCollection();
2265
+ _lightManager._pointLights.garbageCollection();
2266
+ _lightManager._directLights.garbageCollection();
2235
2267
  };
2236
2268
  /**
2237
2269
  * @internal
@@ -4074,6 +4106,11 @@ var TransformModifyFlags;
4074
4106
  * @returns Cloned entity
4075
4107
  */ _proto.clone = function clone() {
4076
4108
  var cloneEntity = new Entity(this._engine, this.name);
4109
+ var _this = this, hookResource = _this._hookResource;
4110
+ if (hookResource) {
4111
+ cloneEntity._hookResource = hookResource;
4112
+ hookResource._addRefCount(1);
4113
+ }
4077
4114
  cloneEntity._isActive = this._isActive;
4078
4115
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
4079
4116
  var children = this._children;
@@ -4098,6 +4135,10 @@ var TransformModifyFlags;
4098
4135
  return;
4099
4136
  }
4100
4137
  EngineObject.prototype.destroy.call(this);
4138
+ if (this._hookResource) {
4139
+ this._hookResource._addRefCount(-1);
4140
+ this._hookResource = null;
4141
+ }
4101
4142
  var components = this._components;
4102
4143
  for(var i = components.length - 1; i >= 0; i--){
4103
4144
  components[i].destroy();
@@ -8758,6 +8799,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8758
8799
  _proto.cloneTo = function cloneTo(target) {
8759
8800
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8760
8801
  Object.assign(target._macroMap, this._macroMap);
8802
+ var referCount = target._getRefCount();
8761
8803
  var propertyValueMap = this._propertyValueMap;
8762
8804
  var targetPropertyValueMap = target._propertyValueMap;
8763
8805
  var keys = Object.keys(propertyValueMap);
@@ -8769,6 +8811,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8769
8811
  targetPropertyValueMap[k] = property;
8770
8812
  } else if (_instanceof(property, Texture)) {
8771
8813
  targetPropertyValueMap[k] = property;
8814
+ referCount > 0 && property._addRefCount(referCount);
8772
8815
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8773
8816
  targetPropertyValueMap[k] = property.slice();
8774
8817
  } else {
@@ -9772,9 +9815,9 @@ __decorate([
9772
9815
  function Material(engine, shader) {
9773
9816
  var _this;
9774
9817
  _this = RefObject.call(this, engine) || this;
9775
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Material);
9776
9818
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
9777
9819
  ;
9820
+ _this._shaderData = new ShaderData(ShaderDataGroup.Material);
9778
9821
  _this.shader = shader;
9779
9822
  return _this;
9780
9823
  }
@@ -9806,8 +9849,21 @@ __decorate([
9806
9849
  */ _proto._preRender = function _preRender(renderElement) {};
9807
9850
  /**
9808
9851
  * @override
9809
- */ _proto._onDestroy = function _onDestroy() {};
9852
+ */ _proto._onDestroy = function _onDestroy() {
9853
+ this._shader = null;
9854
+ this._shaderData = null;
9855
+ this._renderStates.length = 0;
9856
+ this._renderStates = null;
9857
+ };
9810
9858
  _create_class(Material, [
9859
+ {
9860
+ key: "shaderData",
9861
+ get: /**
9862
+ * Shader data.
9863
+ */ function get() {
9864
+ return this._shaderData;
9865
+ }
9866
+ },
9811
9867
  {
9812
9868
  key: "shader",
9813
9869
  get: /**
@@ -9876,6 +9932,12 @@ __decorate([
9876
9932
  */ _proto.resetPool = function resetPool() {
9877
9933
  this._elementPoolIndex = 0;
9878
9934
  };
9935
+ _proto.garbageCollection = function garbageCollection() {
9936
+ var _this = this, pool = _this._elementPool;
9937
+ for(var i = pool.length - 1; i >= 0; i--){
9938
+ pool[i].dispose && pool[i].dispose();
9939
+ }
9940
+ };
9879
9941
  return ClassPool;
9880
9942
  }();
9881
9943
 
@@ -9898,6 +9960,9 @@ var RenderElement = function RenderElement() {
9898
9960
  this.renderState = renderState;
9899
9961
  this.shaderPass = shaderPass;
9900
9962
  };
9963
+ _proto.dispose = function dispose() {
9964
+ this.component = this.mesh = this.subMesh = this.material = this.renderState = this.shaderPass = null;
9965
+ };
9901
9966
  return MeshRenderElement;
9902
9967
  }(RenderElement);
9903
9968
 
@@ -9943,6 +10008,9 @@ var SpriteElement = /*#__PURE__*/ function(RenderElement) {
9943
10008
  this.renderState = renderState;
9944
10009
  this.shaderPass = shaderPass;
9945
10010
  };
10011
+ _proto.dispose = function dispose() {
10012
+ this.component = this.renderData = this.material = this.texture = this.renderState = this.shaderPass = null;
10013
+ };
9946
10014
  return SpriteElement;
9947
10015
  }(RenderElement);
9948
10016
 
@@ -9961,6 +10029,9 @@ var SpriteMaskElement = /*#__PURE__*/ function(RenderElement) {
9961
10029
  this.renderData = renderData;
9962
10030
  this.material = material;
9963
10031
  };
10032
+ _proto.dispose = function dispose() {
10033
+ this.component = this.renderData = this.material = null;
10034
+ };
9964
10035
  return SpriteMaskElement;
9965
10036
  }(RenderElement);
9966
10037
 
@@ -9979,7 +10050,6 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
9979
10050
  function Renderer1(entity) {
9980
10051
  var _this;
9981
10052
  _this = Component.call(this, entity) || this;
9982
- /** ShaderData related to renderer. */ _this.shaderData = new ShaderData(ShaderDataGroup.Renderer);
9983
10053
  /** @internal */ _this._onUpdateIndex = -1;
9984
10054
  /** @internal */ _this._rendererIndex = -1;
9985
10055
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
@@ -9987,6 +10057,7 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
9987
10057
  _this._overrideUpdate = false;
9988
10058
  _this._materials = [];
9989
10059
  _this._dirtyUpdateFlag = 0;
10060
+ _this._shaderData = new ShaderData(ShaderDataGroup.Renderer);
9990
10061
  _this._mvMatrix = new engineMath.Matrix();
9991
10062
  _this._mvpMatrix = new engineMath.Matrix();
9992
10063
  _this._mvInvMatrix = new engineMath.Matrix();
@@ -10133,6 +10204,17 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10133
10204
  var _materials_i;
10134
10205
  (_materials_i = materials[i]) == null ? void 0 : _materials_i._addRefCount(-1);
10135
10206
  }
10207
+ this._entity = null;
10208
+ this._globalShaderMacro = null;
10209
+ this._bounds = null;
10210
+ this._materials = null;
10211
+ this._shaderData = null;
10212
+ this._mvMatrix = null;
10213
+ this._mvpMatrix = null;
10214
+ this._mvInvMatrix = null;
10215
+ this._normalMatrix = null;
10216
+ this._materialsInstanced = null;
10217
+ this._rendererLayer = null;
10136
10218
  };
10137
10219
  _proto._updateShaderData = function _updateShaderData(context) {
10138
10220
  var entity = this.entity;
@@ -10194,6 +10276,14 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10194
10276
  this._dirtyUpdateFlag |= 0x1;
10195
10277
  };
10196
10278
  _create_class(Renderer1, [
10279
+ {
10280
+ key: "shaderData",
10281
+ get: /**
10282
+ * ShaderData related to renderer.
10283
+ */ function get() {
10284
+ return this._shaderData;
10285
+ }
10286
+ },
10197
10287
  {
10198
10288
  key: "isCulled",
10199
10289
  get: /**
@@ -10278,9 +10368,6 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10278
10368
  }(), function() {
10279
10369
  _Renderer._rendererLayerProperty = Shader.getPropertyByName("oasis_RendererLayer");
10280
10370
  }(), _Renderer);
10281
- __decorate([
10282
- deepClone
10283
- ], exports.Renderer.prototype, "shaderData", void 0);
10284
10371
  __decorate([
10285
10372
  ignoreClone
10286
10373
  ], exports.Renderer.prototype, "_distanceForSort", void 0);
@@ -10308,6 +10395,9 @@ __decorate([
10308
10395
  __decorate([
10309
10396
  ignoreClone
10310
10397
  ], exports.Renderer.prototype, "_dirtyUpdateFlag", void 0);
10398
+ __decorate([
10399
+ deepClone
10400
+ ], exports.Renderer.prototype, "_shaderData", void 0);
10311
10401
  __decorate([
10312
10402
  ignoreClone
10313
10403
  ], exports.Renderer.prototype, "_mvMatrix", void 0);
@@ -10513,16 +10603,6 @@ SimpleSpriteAssembler = __decorate([
10513
10603
  }
10514
10604
  var _proto = SpriteMask.prototype;
10515
10605
  /**
10516
- * @override
10517
- * @inheritdoc
10518
- */ _proto._onDestroy = function _onDestroy() {
10519
- var _this__sprite;
10520
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10521
- this._sprite = null;
10522
- this._renderData = null;
10523
- Renderer.prototype._onDestroy.call(this);
10524
- };
10525
- /**
10526
10606
  * @internal
10527
10607
  */ _proto._cloneTo = function _cloneTo(target) {
10528
10608
  Renderer.prototype._cloneTo.call(this, target);
@@ -10562,6 +10642,20 @@ SimpleSpriteAssembler = __decorate([
10562
10642
  context.camera._renderPipeline._allSpriteMasks.add(this);
10563
10643
  this._maskElement = maskElement;
10564
10644
  };
10645
+ /**
10646
+ * @internal
10647
+ * @inheritdoc
10648
+ */ _proto._onDestroy = function _onDestroy() {
10649
+ Renderer.prototype._onDestroy.call(this);
10650
+ var sprite = this._sprite;
10651
+ if (sprite) {
10652
+ sprite._addRefCount(-1);
10653
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10654
+ }
10655
+ this._entity = null;
10656
+ this._sprite = null;
10657
+ this._renderData = null;
10658
+ };
10565
10659
  _proto._calDefaultSize = function _calDefaultSize() {
10566
10660
  var sprite = this._sprite;
10567
10661
  if (sprite) {
@@ -10680,9 +10774,13 @@ SimpleSpriteAssembler = __decorate([
10680
10774
  set: function set(value) {
10681
10775
  var lastSprite = this._sprite;
10682
10776
  if (lastSprite !== value) {
10683
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10777
+ if (lastSprite) {
10778
+ lastSprite._addRefCount(-1);
10779
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10780
+ }
10684
10781
  this._dirtyUpdateFlag |= 0x7;
10685
10782
  if (value) {
10783
+ value._addRefCount(1);
10686
10784
  value._updateFlagManager.addListener(this._onSpriteChange);
10687
10785
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10688
10786
  } else {
@@ -11160,14 +11258,19 @@ var BufferUtil = /*#__PURE__*/ function() {
11160
11258
 
11161
11259
  /**
11162
11260
  * Sub-mesh, mainly contains drawing information.
11163
- */ var SubMesh = function SubMesh(start, count, topology) {
11164
- if (start === void 0) start = 0;
11165
- if (count === void 0) count = 0;
11166
- if (topology === void 0) topology = exports.MeshTopology.Triangles;
11167
- this.start = start;
11168
- this.count = count;
11169
- this.topology = topology;
11170
- };
11261
+ */ var SubMesh = /*#__PURE__*/ function() {
11262
+ function SubMesh(start, count, topology) {
11263
+ if (start === void 0) start = 0;
11264
+ if (count === void 0) count = 0;
11265
+ if (topology === void 0) topology = exports.MeshTopology.Triangles;
11266
+ this.start = start;
11267
+ this.count = count;
11268
+ this.topology = topology;
11269
+ }
11270
+ var _proto = SubMesh.prototype;
11271
+ _proto.dispose = function dispose() {};
11272
+ return SubMesh;
11273
+ }();
11171
11274
 
11172
11275
  /**
11173
11276
  * Mesh.
@@ -11249,10 +11352,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11249
11352
  /**
11250
11353
  * @internal
11251
11354
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11252
- if (this._getRefCount() > 0) {
11253
- var lastBinding = this._vertexBufferBindings[index];
11254
- lastBinding && lastBinding._buffer._addRefCount(-1);
11255
- binding._buffer._addRefCount(1);
11355
+ var referCount = this._getRefCount();
11356
+ if (referCount > 0) {
11357
+ var _this__vertexBufferBindings_index;
11358
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11359
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11256
11360
  }
11257
11361
  this._vertexBufferBindings[index] = binding;
11258
11362
  this._bufferStructChanged = true;
@@ -11266,11 +11370,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11266
11370
  /**
11267
11371
  * @override
11268
11372
  */ _proto._addRefCount = function _addRefCount(value) {
11373
+ var _this__indexBufferBinding;
11269
11374
  RefObject.prototype._addRefCount.call(this, value);
11270
11375
  var vertexBufferBindings = this._vertexBufferBindings;
11271
11376
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11272
11377
  vertexBufferBindings[i]._buffer._addRefCount(value);
11273
11378
  }
11379
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11274
11380
  };
11275
11381
  /**
11276
11382
  * @override
@@ -11280,6 +11386,7 @@ var BufferUtil = /*#__PURE__*/ function() {
11280
11386
  this._indexBufferBinding = null;
11281
11387
  this._vertexElements = null;
11282
11388
  this._vertexElementMap = null;
11389
+ this._updateFlagManager = null;
11283
11390
  this._platformPrimitive.destroy();
11284
11391
  };
11285
11392
  _proto._setVertexElements = function _setVertexElements(elements) {
@@ -11290,6 +11397,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11290
11397
  };
11291
11398
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11292
11399
  var lastBinding = this._indexBufferBinding;
11400
+ var referCount = this._getRefCount();
11401
+ if (referCount > 0) {
11402
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11403
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11404
+ }
11293
11405
  if (binding) {
11294
11406
  this._indexBufferBinding = binding;
11295
11407
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -12960,8 +13072,8 @@ var VertexChangedFlags;
12960
13072
  */ _proto._onDestroy = function _onDestroy() {
12961
13073
  Renderer.prototype._onDestroy.call(this);
12962
13074
  var mesh = this._mesh;
12963
- if (mesh && !mesh.destroyed) {
12964
- mesh._addRefCount(-1);
13075
+ if (mesh) {
13076
+ mesh.destroyed || mesh._addRefCount(-1);
12965
13077
  mesh._updateFlagManager.removeListener(this._onMeshChanged);
12966
13078
  this._mesh = null;
12967
13079
  }
@@ -13298,10 +13410,21 @@ var rePropName = RegExp(// Match anything that isn't a dot or bracket.
13298
13410
  * @internal
13299
13411
  * @override
13300
13412
  */ _proto._onDestroy = function _onDestroy() {
13301
- var _this_rootBone, _this__jointTexture;
13413
+ var _this__rootBone, _this__jointTexture;
13302
13414
  MeshRenderer.prototype._onDestroy.call(this);
13303
- (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13415
+ (_this__rootBone = this._rootBone) == null ? void 0 : _this__rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13416
+ this._rootBone = null;
13417
+ this._jointDataCreateCache = null;
13418
+ this._skin = null;
13419
+ this._blendShapeWeights = null;
13420
+ this._localBounds = null;
13421
+ this._jointMatrices = null;
13304
13422
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13423
+ this._jointTexture = null;
13424
+ if (this._jointEntities) {
13425
+ this._jointEntities.length = 0;
13426
+ this._jointEntities = null;
13427
+ }
13305
13428
  };
13306
13429
  /**
13307
13430
  * @internal
@@ -14468,14 +14591,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14468
14591
  _proto._createMesh = function _createMesh(engine, index) {
14469
14592
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14470
14593
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14594
+ mesh.isGCIgnored = true;
14471
14595
  var vertexElements = [];
14472
14596
  var vertexStride = this.createVertexElements(vertexElements);
14473
14597
  // vertices
14474
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14598
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14599
+ vertexBuffer.isGCIgnored = true;
14475
14600
  // indices
14476
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14477
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14478
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
14601
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14602
+ indiceBuffer.isGCIgnored = true;
14603
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14604
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
14479
14605
  mesh.setVertexElements(vertexElements);
14480
14606
  return mesh;
14481
14607
  };
@@ -14686,6 +14812,11 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14686
14812
  _this.multiRenderData = true;
14687
14813
  return _this;
14688
14814
  }
14815
+ var _proto = TextRenderElement.prototype;
14816
+ _proto.dispose = function dispose() {
14817
+ this.component = this.material = this.renderState = this.shaderPass = null;
14818
+ this.charElements.length = 0;
14819
+ };
14689
14820
  return TextRenderElement;
14690
14821
  }(RenderElement);
14691
14822
 
@@ -14714,6 +14845,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14714
14845
  var _proto = Sky.prototype;
14715
14846
  /**
14716
14847
  * @internal
14848
+ */ _proto.destroy = function destroy() {
14849
+ this.mesh = null;
14850
+ this.material = null;
14851
+ };
14852
+ /**
14853
+ * @internal
14717
14854
  */ _proto._render = function _render(context) {
14718
14855
  var _this = this, material = _this.material, mesh = _this.mesh;
14719
14856
  if (!material) {
@@ -14752,6 +14889,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14752
14889
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14753
14890
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14754
14891
  };
14892
+ _create_class(Sky, [
14893
+ {
14894
+ key: "material",
14895
+ get: /**
14896
+ * Material of the sky.
14897
+ */ function get() {
14898
+ return this._material;
14899
+ },
14900
+ set: function set(value) {
14901
+ if (this._material !== value) {
14902
+ var _this__material;
14903
+ value == null ? void 0 : value._addRefCount(1);
14904
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14905
+ this._material = value;
14906
+ }
14907
+ }
14908
+ },
14909
+ {
14910
+ key: "mesh",
14911
+ get: /**
14912
+ * Mesh of the sky.
14913
+ */ function get() {
14914
+ return this._mesh;
14915
+ },
14916
+ set: function set(value) {
14917
+ if (this._mesh !== value) {
14918
+ var _this__mesh;
14919
+ value == null ? void 0 : value._addRefCount(1);
14920
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14921
+ this._mesh = value;
14922
+ }
14923
+ }
14924
+ }
14925
+ ]);
14755
14926
  return Sky;
14756
14927
  }();
14757
14928
  (function() {
@@ -14782,11 +14953,27 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14782
14953
  this.sky = new Sky();
14783
14954
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
14784
14955
  this._texture = null;
14785
- this._mesh = this._createPlane(_engine);
14956
+ this._initMesh(_engine);
14786
14957
  }
14787
14958
  var _proto = Background.prototype;
14788
14959
  /**
14789
14960
  * @internal
14961
+ */ _proto.destroy = function destroy() {
14962
+ this._mesh._addRefCount(-1);
14963
+ this._mesh = null;
14964
+ this.texture = null;
14965
+ this.solidColor = null;
14966
+ this.sky.destroy();
14967
+ };
14968
+ /**
14969
+ * @internal
14970
+ * Standalone for CanvasRenderer plugin.
14971
+ */ _proto._initMesh = function _initMesh(engine) {
14972
+ this._mesh = this._createPlane(engine);
14973
+ this._mesh._addRefCount(1);
14974
+ };
14975
+ /**
14976
+ * @internal
14790
14977
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14791
14978
  if (!this._texture) {
14792
14979
  return;
@@ -14855,6 +15042,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14855
15042
  },
14856
15043
  set: function set(value) {
14857
15044
  if (this._texture !== value) {
15045
+ var _this__texture;
15046
+ value == null ? void 0 : value._addRefCount(1);
15047
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14858
15048
  this._texture = value;
14859
15049
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14860
15050
  }
@@ -15158,8 +15348,6 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15158
15348
  function Scene(engine, name) {
15159
15349
  var _this;
15160
15350
  _this = EngineObject.call(this, engine) || this;
15161
- /** The background of the scene. */ _this.background = new Background(_this._engine);
15162
- /** Scene-related shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Scene);
15163
15351
  /** If cast shadows. */ _this.castShadows = true;
15164
15352
  /** The resolution of the shadow maps. */ _this.shadowResolution = exports.ShadowResolution.Medium;
15165
15353
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
@@ -15169,6 +15357,8 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15169
15357
  /** @internal */ _this._isActiveInEngine = false;
15170
15358
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
15171
15359
  /** @internal */ _this._rootEntities = [];
15360
+ _this._background = new Background(_this._engine);
15361
+ _this._shaderData = new ShaderData(ShaderDataGroup.Scene);
15172
15362
  _this._shadowCascades = exports.ShadowCascadesMode.NoCascades;
15173
15363
  _this._fogMode = exports.FogMode.None;
15174
15364
  _this._fogColor = new engineMath.Color(0.5, 0.5, 0.5, 1.0);
@@ -15330,6 +15520,8 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15330
15520
  var sunLightIndex = lightManager._getSunLightIndex();
15331
15521
  if (sunLightIndex !== -1) {
15332
15522
  this._sunLight = lightManager._directLights.get(sunLightIndex);
15523
+ } else {
15524
+ this._sunLight = null;
15333
15525
  }
15334
15526
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== exports.ShadowType.None) {
15335
15527
  shaderData.enableMacro("SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -15358,6 +15550,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15358
15550
  this._rootEntities[0].destroy();
15359
15551
  }
15360
15552
  this._activeCameras.length = 0;
15553
+ this.background.destroy();
15361
15554
  this.shaderData._addRefCount(-1);
15362
15555
  };
15363
15556
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15388,6 +15581,22 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15388
15581
  this._fogParams.w = density / Math.sqrt(Math.LN2);
15389
15582
  };
15390
15583
  _create_class(Scene, [
15584
+ {
15585
+ key: "shaderData",
15586
+ get: /**
15587
+ * Scene-related shader data.
15588
+ */ function get() {
15589
+ return this._shaderData;
15590
+ }
15591
+ },
15592
+ {
15593
+ key: "background",
15594
+ get: /**
15595
+ * The background of the scene.
15596
+ */ function get() {
15597
+ return this._background;
15598
+ }
15599
+ },
15391
15600
  {
15392
15601
  key: "shadowCascades",
15393
15602
  get: /**
@@ -15771,7 +15980,7 @@ ShaderPool.init();
15771
15980
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15772
15981
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15773
15982
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15774
- _this._textDefaultFont.isGCIgnored = false;
15983
+ _this._textDefaultFont.isGCIgnored = true;
15775
15984
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15776
15985
  var magentaPixel = new Uint8Array([
15777
15986
  255,
@@ -15806,6 +16015,7 @@ ShaderPool.init();
15806
16015
  _this._magentaTexture2DArray = magentaTexture2DArray;
15807
16016
  }
15808
16017
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
16018
+ magentaMaterial.isGCIgnored = true;
15809
16019
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15810
16020
  _this._magentaMaterial = magentaMaterial;
15811
16021
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17338,7 +17548,11 @@ var /**
17338
17548
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17339
17549
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17340
17550
  }
17341
- this._renderTargets = null;
17551
+ var renderTargets = this._renderTargets;
17552
+ if (renderTargets) {
17553
+ renderTargets.destroy();
17554
+ this._renderTargets = null;
17555
+ }
17342
17556
  var viewportOffset = this._viewportOffsets;
17343
17557
  var shadowTileResolution1 = this._shadowTileResolution;
17344
17558
  switch(shadowCascades){
@@ -17674,7 +17888,6 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17674
17888
  function Camera1(entity) {
17675
17889
  var _this;
17676
17890
  _this = Component.call(this, entity) || this;
17677
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Camera);
17678
17891
  /** Rendering priority - A Camera with higher priority will be rendered on top of a camera with lower priority. */ _this.priority = 0;
17679
17892
  /** Whether to enable frustum culling, it is enabled by default. */ _this.enableFrustumCulling = true;
17680
17893
  /**
@@ -17688,6 +17901,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17688
17901
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
17689
17902
  /** @internal */ _this._frustum = new engineMath.BoundingFrustum();
17690
17903
  /** @internal */ _this._virtualCamera = new VirtualCamera();
17904
+ _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
17691
17905
  _this._isProjMatSetting = false;
17692
17906
  _this._nearClipPlane = 0.1;
17693
17907
  _this._farClipPlane = 100;
@@ -17886,6 +18100,20 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17886
18100
  this._isInvViewProjDirty.destroy();
17887
18101
  this._isViewMatrixDirty.destroy();
17888
18102
  this.shaderData._addRefCount(-1);
18103
+ this._entity = null;
18104
+ this._globalShaderMacro = null;
18105
+ this._frustum = null;
18106
+ this._renderPipeline = null;
18107
+ this._virtualCamera = null;
18108
+ this._shaderData = null;
18109
+ this._frustumViewChangeFlag = null;
18110
+ this._transform = null;
18111
+ this._isViewMatrixDirty = null;
18112
+ this._isInvViewProjDirty = null;
18113
+ this._viewport = null;
18114
+ this._inverseProjectionMatrix = null;
18115
+ this._lastAspectSize = null;
18116
+ this._invViewProjMat = null;
17889
18117
  };
17890
18118
  _proto._projMatChange = function _projMatChange() {
17891
18119
  this._isFrustumProjectDirty = true;
@@ -17925,6 +18153,14 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17925
18153
  return this._inverseProjectionMatrix;
17926
18154
  };
17927
18155
  _create_class(Camera1, [
18156
+ {
18157
+ key: "shaderData",
18158
+ get: /**
18159
+ * Shader data.
18160
+ */ function get() {
18161
+ return this._shaderData;
18162
+ }
18163
+ },
17928
18164
  {
17929
18165
  key: "nearClipPlane",
17930
18166
  get: /**
@@ -19380,10 +19616,17 @@ exports.TextVerticalAlignment = void 0;
19380
19616
  * @internal
19381
19617
  */ _proto._addSprite = function _addSprite(sprite) {
19382
19618
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19619
+ sprite._atlas = this;
19620
+ sprite.isGCIgnored = true;
19383
19621
  };
19384
19622
  /**
19385
19623
  * @override
19386
19624
  */ _proto._onDestroy = function _onDestroy() {
19625
+ var _this = this, sprites = _this._sprites;
19626
+ for(var i = 0, n = sprites.length; i < n; i++){
19627
+ sprites[i].destroy();
19628
+ }
19629
+ sprites.length = 0;
19387
19630
  this._sprites = null;
19388
19631
  this._spriteNamesToIndex = null;
19389
19632
  };
@@ -19484,10 +19727,29 @@ exports.TextVerticalAlignment = void 0;
19484
19727
  };
19485
19728
  /**
19486
19729
  * @override
19730
+ * @internal
19731
+ */ _proto._addRefCount = function _addRefCount(value) {
19732
+ var _this__atlas;
19733
+ RefObject.prototype._addRefCount.call(this, value);
19734
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19735
+ };
19736
+ /**
19737
+ * @override
19738
+ * @internal
19487
19739
  */ _proto._onDestroy = function _onDestroy() {
19488
- if (this._texture) {
19489
- this._texture = null;
19490
- }
19740
+ this._positions.length = 0;
19741
+ this._positions = null;
19742
+ this._uvs.length = 0;
19743
+ this._uvs = null;
19744
+ this._atlasRegion = null;
19745
+ this._atlasRegionOffset = null;
19746
+ this._region = null;
19747
+ this._pivot = null;
19748
+ this._border = null;
19749
+ this._bounds = null;
19750
+ this._atlas = null;
19751
+ this._texture = null;
19752
+ this._updateFlagManager = null;
19491
19753
  };
19492
19754
  _proto._calDefaultSize = function _calDefaultSize() {
19493
19755
  if (this._texture) {
@@ -19590,7 +19852,7 @@ exports.TextVerticalAlignment = void 0;
19590
19852
  key: "width",
19591
19853
  get: /**
19592
19854
  * The width of the sprite (in world coordinates).
19593
- *
19855
+ *
19594
19856
  * @remarks
19595
19857
  * If width is set, return the set value,
19596
19858
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19613,7 +19875,7 @@ exports.TextVerticalAlignment = void 0;
19613
19875
  key: "height",
19614
19876
  get: /**
19615
19877
  * The height of the sprite (in world coordinates).
19616
- *
19878
+ *
19617
19879
  * @remarks
19618
19880
  * If height is set, return the set value,
19619
19881
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19921,17 +20183,6 @@ SlicedSpriteAssembler = __decorate([
19921
20183
  target.drawMode = this._drawMode;
19922
20184
  };
19923
20185
  /**
19924
- * @internal
19925
- */ _proto._onDestroy = function _onDestroy() {
19926
- var _this__sprite;
19927
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19928
- this._color = null;
19929
- this._sprite = null;
19930
- this._assembler = null;
19931
- this._renderData = null;
19932
- Renderer.prototype._onDestroy.call(this);
19933
- };
19934
- /**
19935
20186
  * @override
19936
20187
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19937
20188
  if (this.sprite) {
@@ -19969,6 +20220,21 @@ SlicedSpriteAssembler = __decorate([
19969
20220
  context.camera._renderPipeline.pushPrimitive(spriteElement);
19970
20221
  }
19971
20222
  };
20223
+ /**
20224
+ * @internal
20225
+ */ _proto._onDestroy = function _onDestroy() {
20226
+ Renderer.prototype._onDestroy.call(this);
20227
+ var sprite = this._sprite;
20228
+ if (sprite) {
20229
+ sprite._addRefCount(-1);
20230
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20231
+ }
20232
+ this._entity = null;
20233
+ this._color = null;
20234
+ this._sprite = null;
20235
+ this._assembler = null;
20236
+ this._renderData = null;
20237
+ };
19972
20238
  _proto._calDefaultSize = function _calDefaultSize() {
19973
20239
  var sprite = this._sprite;
19974
20240
  if (sprite) {
@@ -20060,9 +20326,13 @@ SlicedSpriteAssembler = __decorate([
20060
20326
  set: function set(value) {
20061
20327
  var lastSprite = this._sprite;
20062
20328
  if (lastSprite !== value) {
20063
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20329
+ if (lastSprite) {
20330
+ lastSprite._addRefCount(-1);
20331
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20332
+ }
20064
20333
  this._dirtyUpdateFlag |= 0x7;
20065
20334
  if (value) {
20335
+ value._addRefCount(1);
20066
20336
  value._updateFlagManager.addListener(this._onSpriteChange);
20067
20337
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
20068
20338
  } else {
@@ -22506,9 +22776,16 @@ exports.AnimatorLayerBlendingMode = void 0;
22506
22776
 
22507
22777
  /**
22508
22778
  * @internal
22509
- */ var AnimationEventHandler = function AnimationEventHandler() {
22510
- this.handlers = [];
22511
- };
22779
+ */ var AnimationEventHandler = /*#__PURE__*/ function() {
22780
+ function AnimationEventHandler() {
22781
+ this.handlers = [];
22782
+ }
22783
+ var _proto = AnimationEventHandler.prototype;
22784
+ _proto.dispose = function dispose() {
22785
+ this.handlers.length = 0;
22786
+ };
22787
+ return AnimationEventHandler;
22788
+ }();
22512
22789
 
22513
22790
  /**
22514
22791
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.