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