@galacean/engine-physics-physx 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.
@@ -1516,9 +1516,11 @@ exports.GLCapabilityType = void 0;
1516
1516
  renderTexture
1517
1517
  ];
1518
1518
  for(var i = 0, n = colorTextures.length; i < n; i++){
1519
- if (colorTextures[i]._isDepthTexture) {
1519
+ var colorTexture = colorTextures[i];
1520
+ if (colorTexture._isDepthTexture) {
1520
1521
  throw "Render texture can't use depth format.";
1521
1522
  }
1523
+ colorTexture._addRefCount(1);
1522
1524
  }
1523
1525
  _this._colorTextures = colorTextures;
1524
1526
  } else {
@@ -1529,6 +1531,7 @@ exports.GLCapabilityType = void 0;
1529
1531
  throw "Depth texture must use depth format.";
1530
1532
  }
1531
1533
  _this._depthTexture = depth;
1534
+ _this._depthTexture._addRefCount(1);
1532
1535
  }
1533
1536
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
1534
1537
  return _this;
@@ -1558,8 +1561,14 @@ exports.GLCapabilityType = void 0;
1558
1561
  /**
1559
1562
  * Destroy render target.
1560
1563
  */ _proto.destroy = function destroy() {
1564
+ var _this__depthTexture;
1561
1565
  this._platformRenderTarget.destroy();
1562
- this._colorTextures.length = 0;
1566
+ var _this = this, colorTextures = _this._colorTextures;
1567
+ for(var i = 0, n = colorTextures.length; i < n; i++){
1568
+ colorTextures[i]._addRefCount(-1);
1569
+ }
1570
+ colorTextures.length = 0;
1571
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
1563
1572
  this._depthTexture = null;
1564
1573
  this._depth = null;
1565
1574
  };
@@ -2000,6 +2009,7 @@ exports.GLCapabilityType = void 0;
2000
2009
  var fontAtlas = new FontAtlas(engine);
2001
2010
  var texture = new Texture2D(engine, 256, 256);
2002
2011
  fontAtlas.texture = texture;
2012
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
2003
2013
  this._fontAtlases.push(fontAtlas);
2004
2014
  return fontAtlas;
2005
2015
  };
@@ -2275,6 +2285,28 @@ var /** @internal */ PromiseState;
2275
2285
  * @remarks The release principle is that it is not referenced by the components, including direct and indirect reference.
2276
2286
  */ _proto.gc = function gc() {
2277
2287
  this._gc(false);
2288
+ var engine = this.engine;
2289
+ engine._renderElementPool.garbageCollection();
2290
+ engine._spriteElementPool.garbageCollection();
2291
+ engine._spriteMaskElementPool.garbageCollection();
2292
+ engine._textElementPool.garbageCollection();
2293
+ var _componentsManager = engine._componentsManager, _lightManager = engine._lightManager;
2294
+ _componentsManager._renderers.garbageCollection();
2295
+ // @ts-ignore
2296
+ _componentsManager._onStartScripts.garbageCollection();
2297
+ // @ts-ignore
2298
+ _componentsManager._onUpdateScripts.garbageCollection();
2299
+ // @ts-ignore
2300
+ _componentsManager._onLateUpdateScripts.garbageCollection();
2301
+ // @ts-ignore
2302
+ _componentsManager._onPhysicsUpdateScripts.garbageCollection();
2303
+ // @ts-ignore
2304
+ _componentsManager._onUpdateAnimations.garbageCollection();
2305
+ // @ts-ignore
2306
+ _componentsManager._onUpdateRenderers.garbageCollection();
2307
+ _lightManager._spotLights.garbageCollection();
2308
+ _lightManager._pointLights.garbageCollection();
2309
+ _lightManager._directLights.garbageCollection();
2278
2310
  };
2279
2311
  /**
2280
2312
  * @internal
@@ -4105,6 +4137,11 @@ var TransformModifyFlags;
4105
4137
  * @returns Cloned entity
4106
4138
  */ _proto.clone = function clone() {
4107
4139
  var cloneEntity = new Entity(this._engine, this.name);
4140
+ var _this = this, hookResource = _this._hookResource;
4141
+ if (hookResource) {
4142
+ cloneEntity._hookResource = hookResource;
4143
+ hookResource._addRefCount(1);
4144
+ }
4108
4145
  cloneEntity._isActive = this._isActive;
4109
4146
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
4110
4147
  var children = this._children;
@@ -4129,6 +4166,10 @@ var TransformModifyFlags;
4129
4166
  return;
4130
4167
  }
4131
4168
  EngineObject.prototype.destroy.call(this);
4169
+ if (this._hookResource) {
4170
+ this._hookResource._addRefCount(-1);
4171
+ this._hookResource = null;
4172
+ }
4132
4173
  var components = this._components;
4133
4174
  for(var i = components.length - 1; i >= 0; i--){
4134
4175
  components[i].destroy();
@@ -8672,6 +8713,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8672
8713
  _proto.cloneTo = function cloneTo(target) {
8673
8714
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8674
8715
  Object.assign(target._macroMap, this._macroMap);
8716
+ var referCount = target._getRefCount();
8675
8717
  var propertyValueMap = this._propertyValueMap;
8676
8718
  var targetPropertyValueMap = target._propertyValueMap;
8677
8719
  var keys = Object.keys(propertyValueMap);
@@ -8683,6 +8725,7 @@ var ShaderFactory = /*#__PURE__*/ function() {
8683
8725
  targetPropertyValueMap[k] = property;
8684
8726
  } else if (_instanceof1$2(property, Texture)) {
8685
8727
  targetPropertyValueMap[k] = property;
8728
+ referCount > 0 && property._addRefCount(referCount);
8686
8729
  } else if (_instanceof1$2(property, Array) || _instanceof1$2(property, Float32Array) || _instanceof1$2(property, Int32Array)) {
8687
8730
  targetPropertyValueMap[k] = property.slice();
8688
8731
  } else {
@@ -9673,9 +9716,9 @@ __decorate$1([
9673
9716
  var Material = function Material(engine, shader) {
9674
9717
  var _this;
9675
9718
  _this = RefObject.call(this, engine) || this;
9676
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Material);
9677
9719
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
9678
9720
  ;
9721
+ _this._shaderData = new ShaderData(ShaderDataGroup.Material);
9679
9722
  _this.shader = shader;
9680
9723
  return _this;
9681
9724
  };
@@ -9708,8 +9751,21 @@ __decorate$1([
9708
9751
  */ _proto._preRender = function _preRender(renderElement) {};
9709
9752
  /**
9710
9753
  * @override
9711
- */ _proto._onDestroy = function _onDestroy() {};
9754
+ */ _proto._onDestroy = function _onDestroy() {
9755
+ this._shader = null;
9756
+ this._shaderData = null;
9757
+ this._renderStates.length = 0;
9758
+ this._renderStates = null;
9759
+ };
9712
9760
  _create_class$2(Material, [
9761
+ {
9762
+ key: "shaderData",
9763
+ get: /**
9764
+ * Shader data.
9765
+ */ function get() {
9766
+ return this._shaderData;
9767
+ }
9768
+ },
9713
9769
  {
9714
9770
  key: "shader",
9715
9771
  get: /**
@@ -9777,6 +9833,12 @@ __decorate$1([
9777
9833
  */ _proto.resetPool = function resetPool() {
9778
9834
  this._elementPoolIndex = 0;
9779
9835
  };
9836
+ _proto.garbageCollection = function garbageCollection() {
9837
+ var _this = this, pool = _this._elementPool;
9838
+ for(var i = pool.length - 1; i >= 0; i--){
9839
+ pool[i].dispose && pool[i].dispose();
9840
+ }
9841
+ };
9780
9842
  return ClassPool;
9781
9843
  }();
9782
9844
  var RenderElement = function RenderElement() {};
@@ -9796,6 +9858,9 @@ var RenderElement = function RenderElement() {};
9796
9858
  this.renderState = renderState;
9797
9859
  this.shaderPass = shaderPass;
9798
9860
  };
9861
+ _proto.dispose = function dispose() {
9862
+ this.component = this.mesh = this.subMesh = this.material = this.renderState = this.shaderPass = null;
9863
+ };
9799
9864
  return MeshRenderElement;
9800
9865
  }(RenderElement);
9801
9866
  /**
@@ -9839,6 +9904,9 @@ var SpriteElement = /*#__PURE__*/ function(RenderElement) {
9839
9904
  this.renderState = renderState;
9840
9905
  this.shaderPass = shaderPass;
9841
9906
  };
9907
+ _proto.dispose = function dispose() {
9908
+ this.component = this.renderData = this.material = this.texture = this.renderState = this.shaderPass = null;
9909
+ };
9842
9910
  return SpriteElement;
9843
9911
  }(RenderElement);
9844
9912
  var SpriteMaskElement = /*#__PURE__*/ function(RenderElement) {
@@ -9856,6 +9924,9 @@ var SpriteMaskElement = /*#__PURE__*/ function(RenderElement) {
9856
9924
  this.renderData = renderData;
9857
9925
  this.material = material;
9858
9926
  };
9927
+ _proto.dispose = function dispose() {
9928
+ this.component = this.renderData = this.material = null;
9929
+ };
9859
9930
  return SpriteMaskElement;
9860
9931
  }(RenderElement);
9861
9932
  /**
@@ -9871,7 +9942,6 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
9871
9942
  var Renderer1 = function Renderer1(entity) {
9872
9943
  var _this;
9873
9944
  _this = Component.call(this, entity) || this;
9874
- /** ShaderData related to renderer. */ _this.shaderData = new ShaderData(ShaderDataGroup.Renderer);
9875
9945
  /** @internal */ _this._onUpdateIndex = -1;
9876
9946
  /** @internal */ _this._rendererIndex = -1;
9877
9947
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
@@ -9879,6 +9949,7 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
9879
9949
  _this._overrideUpdate = false;
9880
9950
  _this._materials = [];
9881
9951
  _this._dirtyUpdateFlag = 0;
9952
+ _this._shaderData = new ShaderData(ShaderDataGroup.Renderer);
9882
9953
  _this._mvMatrix = new miniprogram$7.Matrix();
9883
9954
  _this._mvpMatrix = new miniprogram$7.Matrix();
9884
9955
  _this._mvInvMatrix = new miniprogram$7.Matrix();
@@ -10026,6 +10097,17 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10026
10097
  var _materials_i;
10027
10098
  (_materials_i = materials[i]) == null ? void 0 : _materials_i._addRefCount(-1);
10028
10099
  }
10100
+ this._entity = null;
10101
+ this._globalShaderMacro = null;
10102
+ this._bounds = null;
10103
+ this._materials = null;
10104
+ this._shaderData = null;
10105
+ this._mvMatrix = null;
10106
+ this._mvpMatrix = null;
10107
+ this._mvInvMatrix = null;
10108
+ this._normalMatrix = null;
10109
+ this._materialsInstanced = null;
10110
+ this._rendererLayer = null;
10029
10111
  };
10030
10112
  _proto._updateShaderData = function _updateShaderData(context) {
10031
10113
  var entity = this.entity;
@@ -10087,6 +10169,14 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10087
10169
  this._dirtyUpdateFlag |= 0x1;
10088
10170
  };
10089
10171
  _create_class$2(Renderer1, [
10172
+ {
10173
+ key: "shaderData",
10174
+ get: /**
10175
+ * ShaderData related to renderer.
10176
+ */ function get() {
10177
+ return this._shaderData;
10178
+ }
10179
+ },
10090
10180
  {
10091
10181
  key: "isCulled",
10092
10182
  get: /**
@@ -10171,9 +10261,6 @@ exports.Renderer = (_Renderer = /*#__PURE__*/ function(Component) {
10171
10261
  }(), function() {
10172
10262
  _Renderer._rendererLayerProperty = Shader.getPropertyByName("oasis_RendererLayer");
10173
10263
  }(), _Renderer);
10174
- __decorate$1([
10175
- deepClone
10176
- ], exports.Renderer.prototype, "shaderData", void 0);
10177
10264
  __decorate$1([
10178
10265
  ignoreClone
10179
10266
  ], exports.Renderer.prototype, "_distanceForSort", void 0);
@@ -10201,6 +10288,9 @@ __decorate$1([
10201
10288
  __decorate$1([
10202
10289
  ignoreClone
10203
10290
  ], exports.Renderer.prototype, "_dirtyUpdateFlag", void 0);
10291
+ __decorate$1([
10292
+ deepClone
10293
+ ], exports.Renderer.prototype, "_shaderData", void 0);
10204
10294
  __decorate$1([
10205
10295
  ignoreClone
10206
10296
  ], exports.Renderer.prototype, "_mvMatrix", void 0);
@@ -10399,16 +10489,6 @@ SimpleSpriteAssembler = __decorate$1([
10399
10489
  }
10400
10490
  var _proto = SpriteMask.prototype;
10401
10491
  /**
10402
- * @override
10403
- * @inheritdoc
10404
- */ _proto._onDestroy = function _onDestroy() {
10405
- var _this__sprite;
10406
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10407
- this._sprite = null;
10408
- this._renderData = null;
10409
- Renderer.prototype._onDestroy.call(this);
10410
- };
10411
- /**
10412
10492
  * @internal
10413
10493
  */ _proto._cloneTo = function _cloneTo(target) {
10414
10494
  Renderer.prototype._cloneTo.call(this, target);
@@ -10448,6 +10528,20 @@ SimpleSpriteAssembler = __decorate$1([
10448
10528
  context.camera._renderPipeline._allSpriteMasks.add(this);
10449
10529
  this._maskElement = maskElement;
10450
10530
  };
10531
+ /**
10532
+ * @internal
10533
+ * @inheritdoc
10534
+ */ _proto._onDestroy = function _onDestroy() {
10535
+ Renderer.prototype._onDestroy.call(this);
10536
+ var sprite = this._sprite;
10537
+ if (sprite) {
10538
+ sprite._addRefCount(-1);
10539
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10540
+ }
10541
+ this._entity = null;
10542
+ this._sprite = null;
10543
+ this._renderData = null;
10544
+ };
10451
10545
  _proto._calDefaultSize = function _calDefaultSize() {
10452
10546
  var sprite = this._sprite;
10453
10547
  if (sprite) {
@@ -10566,9 +10660,13 @@ SimpleSpriteAssembler = __decorate$1([
10566
10660
  set: function set(value) {
10567
10661
  var lastSprite = this._sprite;
10568
10662
  if (lastSprite !== value) {
10569
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10663
+ if (lastSprite) {
10664
+ lastSprite._addRefCount(-1);
10665
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10666
+ }
10570
10667
  this._dirtyUpdateFlag |= 0x7;
10571
10668
  if (value) {
10669
+ value._addRefCount(1);
10572
10670
  value._updateFlagManager.addListener(this._onSpriteChange);
10573
10671
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10574
10672
  } else {
@@ -11035,14 +11133,19 @@ var BufferUtil = /*#__PURE__*/ function() {
11035
11133
  }();
11036
11134
  /**
11037
11135
  * Sub-mesh, mainly contains drawing information.
11038
- */ var SubMesh = function SubMesh(start, count, topology) {
11039
- if (start === void 0) start = 0;
11040
- if (count === void 0) count = 0;
11041
- if (topology === void 0) topology = exports.MeshTopology.Triangles;
11042
- this.start = start;
11043
- this.count = count;
11044
- this.topology = topology;
11045
- };
11136
+ */ var SubMesh = /*#__PURE__*/ function() {
11137
+ var SubMesh = function SubMesh(start, count, topology) {
11138
+ if (start === void 0) start = 0;
11139
+ if (count === void 0) count = 0;
11140
+ if (topology === void 0) topology = exports.MeshTopology.Triangles;
11141
+ this.start = start;
11142
+ this.count = count;
11143
+ this.topology = topology;
11144
+ };
11145
+ var _proto = SubMesh.prototype;
11146
+ _proto.dispose = function dispose() {};
11147
+ return SubMesh;
11148
+ }();
11046
11149
  /**
11047
11150
  * Mesh.
11048
11151
  */ var Mesh = /*#__PURE__*/ function(RefObject) {
@@ -11123,10 +11226,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11123
11226
  /**
11124
11227
  * @internal
11125
11228
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11126
- if (this._getRefCount() > 0) {
11127
- var lastBinding = this._vertexBufferBindings[index];
11128
- lastBinding && lastBinding._buffer._addRefCount(-1);
11129
- binding._buffer._addRefCount(1);
11229
+ var referCount = this._getRefCount();
11230
+ if (referCount > 0) {
11231
+ var _this__vertexBufferBindings_index;
11232
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11233
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11130
11234
  }
11131
11235
  this._vertexBufferBindings[index] = binding;
11132
11236
  this._bufferStructChanged = true;
@@ -11140,11 +11244,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11140
11244
  /**
11141
11245
  * @override
11142
11246
  */ _proto._addRefCount = function _addRefCount(value) {
11247
+ var _this__indexBufferBinding;
11143
11248
  RefObject.prototype._addRefCount.call(this, value);
11144
11249
  var vertexBufferBindings = this._vertexBufferBindings;
11145
11250
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11146
11251
  vertexBufferBindings[i]._buffer._addRefCount(value);
11147
11252
  }
11253
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11148
11254
  };
11149
11255
  /**
11150
11256
  * @override
@@ -11154,6 +11260,7 @@ var BufferUtil = /*#__PURE__*/ function() {
11154
11260
  this._indexBufferBinding = null;
11155
11261
  this._vertexElements = null;
11156
11262
  this._vertexElementMap = null;
11263
+ this._updateFlagManager = null;
11157
11264
  this._platformPrimitive.destroy();
11158
11265
  };
11159
11266
  _proto._setVertexElements = function _setVertexElements(elements) {
@@ -11164,6 +11271,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11164
11271
  };
11165
11272
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11166
11273
  var lastBinding = this._indexBufferBinding;
11274
+ var referCount = this._getRefCount();
11275
+ if (referCount > 0) {
11276
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11277
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11278
+ }
11167
11279
  if (binding) {
11168
11280
  this._indexBufferBinding = binding;
11169
11281
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -12828,8 +12940,8 @@ var VertexChangedFlags;
12828
12940
  */ _proto._onDestroy = function _onDestroy() {
12829
12941
  Renderer.prototype._onDestroy.call(this);
12830
12942
  var mesh = this._mesh;
12831
- if (mesh && !mesh.destroyed) {
12832
- mesh._addRefCount(-1);
12943
+ if (mesh) {
12944
+ mesh.destroyed || mesh._addRefCount(-1);
12833
12945
  mesh._updateFlagManager.removeListener(this._onMeshChanged);
12834
12946
  this._mesh = null;
12835
12947
  }
@@ -13163,10 +13275,21 @@ var rePropName = RegExp("[^.[\\]]+" + "|" + // Or match property names within br
13163
13275
  * @internal
13164
13276
  * @override
13165
13277
  */ _proto._onDestroy = function _onDestroy() {
13166
- var _this_rootBone, _this__jointTexture;
13278
+ var _this__rootBone, _this__jointTexture;
13167
13279
  MeshRenderer.prototype._onDestroy.call(this);
13168
- (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13280
+ (_this__rootBone = this._rootBone) == null ? void 0 : _this__rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
13281
+ this._rootBone = null;
13282
+ this._jointDataCreateCache = null;
13283
+ this._skin = null;
13284
+ this._blendShapeWeights = null;
13285
+ this._localBounds = null;
13286
+ this._jointMatrices = null;
13169
13287
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
13288
+ this._jointTexture = null;
13289
+ if (this._jointEntities) {
13290
+ this._jointEntities.length = 0;
13291
+ this._jointEntities = null;
13292
+ }
13170
13293
  };
13171
13294
  /**
13172
13295
  * @internal
@@ -14323,14 +14446,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14323
14446
  _proto._createMesh = function _createMesh(engine, index) {
14324
14447
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14325
14448
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14449
+ mesh.isGCIgnored = true;
14326
14450
  var vertexElements = [];
14327
14451
  var vertexStride = this.createVertexElements(vertexElements);
14328
14452
  // vertices
14329
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14453
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14454
+ vertexBuffer.isGCIgnored = true;
14330
14455
  // indices
14331
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14332
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14333
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
14456
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14457
+ indiceBuffer.isGCIgnored = true;
14458
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14459
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
14334
14460
  mesh.setVertexElements(vertexElements);
14335
14461
  return mesh;
14336
14462
  };
@@ -14538,6 +14664,11 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14538
14664
  return _this;
14539
14665
  };
14540
14666
  _inherits$2(TextRenderElement, RenderElement);
14667
+ var _proto = TextRenderElement.prototype;
14668
+ _proto.dispose = function dispose() {
14669
+ this.component = this.material = this.renderState = this.shaderPass = null;
14670
+ this.charElements.length = 0;
14671
+ };
14541
14672
  return TextRenderElement;
14542
14673
  }(RenderElement);
14543
14674
  /**
@@ -14563,6 +14694,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14563
14694
  var _proto = Sky.prototype;
14564
14695
  /**
14565
14696
  * @internal
14697
+ */ _proto.destroy = function destroy() {
14698
+ this.mesh = null;
14699
+ this.material = null;
14700
+ };
14701
+ /**
14702
+ * @internal
14566
14703
  */ _proto._render = function _render(context) {
14567
14704
  var _this = this, material = _this.material, mesh = _this.mesh;
14568
14705
  if (!material) {
@@ -14601,6 +14738,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14601
14738
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14602
14739
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14603
14740
  };
14741
+ _create_class$2(Sky, [
14742
+ {
14743
+ key: "material",
14744
+ get: /**
14745
+ * Material of the sky.
14746
+ */ function get() {
14747
+ return this._material;
14748
+ },
14749
+ set: function set(value) {
14750
+ if (this._material !== value) {
14751
+ var _this__material;
14752
+ value == null ? void 0 : value._addRefCount(1);
14753
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14754
+ this._material = value;
14755
+ }
14756
+ }
14757
+ },
14758
+ {
14759
+ key: "mesh",
14760
+ get: /**
14761
+ * Mesh of the sky.
14762
+ */ function get() {
14763
+ return this._mesh;
14764
+ },
14765
+ set: function set(value) {
14766
+ if (this._mesh !== value) {
14767
+ var _this__mesh;
14768
+ value == null ? void 0 : value._addRefCount(1);
14769
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14770
+ this._mesh = value;
14771
+ }
14772
+ }
14773
+ }
14774
+ ]);
14604
14775
  return Sky;
14605
14776
  }();
14606
14777
  (function() {
@@ -14630,11 +14801,27 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14630
14801
  this.sky = new Sky();
14631
14802
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
14632
14803
  this._texture = null;
14633
- this._mesh = this._createPlane(_engine);
14804
+ this._initMesh(_engine);
14634
14805
  };
14635
14806
  var _proto = Background.prototype;
14636
14807
  /**
14637
14808
  * @internal
14809
+ */ _proto.destroy = function destroy() {
14810
+ this._mesh._addRefCount(-1);
14811
+ this._mesh = null;
14812
+ this.texture = null;
14813
+ this.solidColor = null;
14814
+ this.sky.destroy();
14815
+ };
14816
+ /**
14817
+ * @internal
14818
+ * Standalone for CanvasRenderer plugin.
14819
+ */ _proto._initMesh = function _initMesh(engine) {
14820
+ this._mesh = this._createPlane(engine);
14821
+ this._mesh._addRefCount(1);
14822
+ };
14823
+ /**
14824
+ * @internal
14638
14825
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14639
14826
  if (!this._texture) {
14640
14827
  return;
@@ -14703,6 +14890,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14703
14890
  },
14704
14891
  set: function set(value) {
14705
14892
  if (this._texture !== value) {
14893
+ var _this__texture;
14894
+ value == null ? void 0 : value._addRefCount(1);
14895
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14706
14896
  this._texture = value;
14707
14897
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14708
14898
  }
@@ -15002,8 +15192,6 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15002
15192
  function Scene(engine, name) {
15003
15193
  var _this;
15004
15194
  _this = EngineObject.call(this, engine) || this;
15005
- /** The background of the scene. */ _this.background = new Background(_this._engine);
15006
- /** Scene-related shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Scene);
15007
15195
  /** If cast shadows. */ _this.castShadows = true;
15008
15196
  /** The resolution of the shadow maps. */ _this.shadowResolution = exports.ShadowResolution.Medium;
15009
15197
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
@@ -15013,6 +15201,8 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15013
15201
  /** @internal */ _this._isActiveInEngine = false;
15014
15202
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
15015
15203
  /** @internal */ _this._rootEntities = [];
15204
+ _this._background = new Background(_this._engine);
15205
+ _this._shaderData = new ShaderData(ShaderDataGroup.Scene);
15016
15206
  _this._shadowCascades = exports.ShadowCascadesMode.NoCascades;
15017
15207
  _this._fogMode = exports.FogMode.None;
15018
15208
  _this._fogColor = new miniprogram$7.Color(0.5, 0.5, 0.5, 1.0);
@@ -15174,6 +15364,8 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15174
15364
  var sunLightIndex = lightManager._getSunLightIndex();
15175
15365
  if (sunLightIndex !== -1) {
15176
15366
  this._sunLight = lightManager._directLights.get(sunLightIndex);
15367
+ } else {
15368
+ this._sunLight = null;
15177
15369
  }
15178
15370
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== exports.ShadowType.None) {
15179
15371
  shaderData.enableMacro("SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -15202,6 +15394,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15202
15394
  this._rootEntities[0].destroy();
15203
15395
  }
15204
15396
  this._activeCameras.length = 0;
15397
+ this.background.destroy();
15205
15398
  this.shaderData._addRefCount(-1);
15206
15399
  };
15207
15400
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15232,6 +15425,22 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15232
15425
  this._fogParams.w = density / Math.sqrt(Math.LN2);
15233
15426
  };
15234
15427
  _create_class$2(Scene, [
15428
+ {
15429
+ key: "shaderData",
15430
+ get: /**
15431
+ * Scene-related shader data.
15432
+ */ function get() {
15433
+ return this._shaderData;
15434
+ }
15435
+ },
15436
+ {
15437
+ key: "background",
15438
+ get: /**
15439
+ * The background of the scene.
15440
+ */ function get() {
15441
+ return this._background;
15442
+ }
15443
+ },
15235
15444
  {
15236
15445
  key: "shadowCascades",
15237
15446
  get: /**
@@ -15592,7 +15801,7 @@ ShaderPool.init();
15592
15801
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15593
15802
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15594
15803
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15595
- _this._textDefaultFont.isGCIgnored = false;
15804
+ _this._textDefaultFont.isGCIgnored = true;
15596
15805
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15597
15806
  var magentaPixel = new Uint8Array([
15598
15807
  255,
@@ -15627,6 +15836,7 @@ ShaderPool.init();
15627
15836
  _this._magentaTexture2DArray = magentaTexture2DArray;
15628
15837
  }
15629
15838
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
15839
+ magentaMaterial.isGCIgnored = true;
15630
15840
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15631
15841
  _this._magentaMaterial = magentaMaterial;
15632
15842
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17152,7 +17362,11 @@ var /**
17152
17362
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17153
17363
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17154
17364
  }
17155
- this._renderTargets = null;
17365
+ var renderTargets = this._renderTargets;
17366
+ if (renderTargets) {
17367
+ renderTargets.destroy();
17368
+ this._renderTargets = null;
17369
+ }
17156
17370
  var viewportOffset = this._viewportOffsets;
17157
17371
  var shadowTileResolution1 = this._shadowTileResolution;
17158
17372
  switch(shadowCascades){
@@ -17483,7 +17697,6 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17483
17697
  var Camera1 = function Camera1(entity) {
17484
17698
  var _this;
17485
17699
  _this = Component.call(this, entity) || this;
17486
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Camera);
17487
17700
  /** Rendering priority - A Camera with higher priority will be rendered on top of a camera with lower priority. */ _this.priority = 0;
17488
17701
  /** Whether to enable frustum culling, it is enabled by default. */ _this.enableFrustumCulling = true;
17489
17702
  /**
@@ -17497,6 +17710,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17497
17710
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
17498
17711
  /** @internal */ _this._frustum = new miniprogram$7.BoundingFrustum();
17499
17712
  /** @internal */ _this._virtualCamera = new VirtualCamera();
17713
+ _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
17500
17714
  _this._isProjMatSetting = false;
17501
17715
  _this._nearClipPlane = 0.1;
17502
17716
  _this._farClipPlane = 100;
@@ -17696,6 +17910,20 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17696
17910
  this._isInvViewProjDirty.destroy();
17697
17911
  this._isViewMatrixDirty.destroy();
17698
17912
  this.shaderData._addRefCount(-1);
17913
+ this._entity = null;
17914
+ this._globalShaderMacro = null;
17915
+ this._frustum = null;
17916
+ this._renderPipeline = null;
17917
+ this._virtualCamera = null;
17918
+ this._shaderData = null;
17919
+ this._frustumViewChangeFlag = null;
17920
+ this._transform = null;
17921
+ this._isViewMatrixDirty = null;
17922
+ this._isInvViewProjDirty = null;
17923
+ this._viewport = null;
17924
+ this._inverseProjectionMatrix = null;
17925
+ this._lastAspectSize = null;
17926
+ this._invViewProjMat = null;
17699
17927
  };
17700
17928
  _proto._projMatChange = function _projMatChange() {
17701
17929
  this._isFrustumProjectDirty = true;
@@ -17735,6 +17963,14 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component) {
17735
17963
  return this._inverseProjectionMatrix;
17736
17964
  };
17737
17965
  _create_class$2(Camera1, [
17966
+ {
17967
+ key: "shaderData",
17968
+ get: /**
17969
+ * Shader data.
17970
+ */ function get() {
17971
+ return this._shaderData;
17972
+ }
17973
+ },
17738
17974
  {
17739
17975
  key: "nearClipPlane",
17740
17976
  get: /**
@@ -19174,10 +19410,17 @@ exports.TextVerticalAlignment = void 0;
19174
19410
  * @internal
19175
19411
  */ _proto._addSprite = function _addSprite(sprite) {
19176
19412
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19413
+ sprite._atlas = this;
19414
+ sprite.isGCIgnored = true;
19177
19415
  };
19178
19416
  /**
19179
19417
  * @override
19180
19418
  */ _proto._onDestroy = function _onDestroy() {
19419
+ var _this = this, sprites = _this._sprites;
19420
+ for(var i = 0, n = sprites.length; i < n; i++){
19421
+ sprites[i].destroy();
19422
+ }
19423
+ sprites.length = 0;
19181
19424
  this._sprites = null;
19182
19425
  this._spriteNamesToIndex = null;
19183
19426
  };
@@ -19276,10 +19519,29 @@ exports.TextVerticalAlignment = void 0;
19276
19519
  };
19277
19520
  /**
19278
19521
  * @override
19522
+ * @internal
19523
+ */ _proto._addRefCount = function _addRefCount(value) {
19524
+ var _this__atlas;
19525
+ RefObject.prototype._addRefCount.call(this, value);
19526
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19527
+ };
19528
+ /**
19529
+ * @override
19530
+ * @internal
19279
19531
  */ _proto._onDestroy = function _onDestroy() {
19280
- if (this._texture) {
19281
- this._texture = null;
19282
- }
19532
+ this._positions.length = 0;
19533
+ this._positions = null;
19534
+ this._uvs.length = 0;
19535
+ this._uvs = null;
19536
+ this._atlasRegion = null;
19537
+ this._atlasRegionOffset = null;
19538
+ this._region = null;
19539
+ this._pivot = null;
19540
+ this._border = null;
19541
+ this._bounds = null;
19542
+ this._atlas = null;
19543
+ this._texture = null;
19544
+ this._updateFlagManager = null;
19283
19545
  };
19284
19546
  _proto._calDefaultSize = function _calDefaultSize() {
19285
19547
  if (this._texture) {
@@ -19382,7 +19644,7 @@ exports.TextVerticalAlignment = void 0;
19382
19644
  key: "width",
19383
19645
  get: /**
19384
19646
  * The width of the sprite (in world coordinates).
19385
- *
19647
+ *
19386
19648
  * @remarks
19387
19649
  * If width is set, return the set value,
19388
19650
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19405,7 +19667,7 @@ exports.TextVerticalAlignment = void 0;
19405
19667
  key: "height",
19406
19668
  get: /**
19407
19669
  * The height of the sprite (in world coordinates).
19408
- *
19670
+ *
19409
19671
  * @remarks
19410
19672
  * If height is set, return the set value,
19411
19673
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19711,17 +19973,6 @@ SlicedSpriteAssembler = __decorate$1([
19711
19973
  target.drawMode = this._drawMode;
19712
19974
  };
19713
19975
  /**
19714
- * @internal
19715
- */ _proto._onDestroy = function _onDestroy() {
19716
- var _this__sprite;
19717
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19718
- this._color = null;
19719
- this._sprite = null;
19720
- this._assembler = null;
19721
- this._renderData = null;
19722
- Renderer.prototype._onDestroy.call(this);
19723
- };
19724
- /**
19725
19976
  * @override
19726
19977
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19727
19978
  if (this.sprite) {
@@ -19759,6 +20010,21 @@ SlicedSpriteAssembler = __decorate$1([
19759
20010
  context.camera._renderPipeline.pushPrimitive(spriteElement);
19760
20011
  }
19761
20012
  };
20013
+ /**
20014
+ * @internal
20015
+ */ _proto._onDestroy = function _onDestroy() {
20016
+ Renderer.prototype._onDestroy.call(this);
20017
+ var sprite = this._sprite;
20018
+ if (sprite) {
20019
+ sprite._addRefCount(-1);
20020
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20021
+ }
20022
+ this._entity = null;
20023
+ this._color = null;
20024
+ this._sprite = null;
20025
+ this._assembler = null;
20026
+ this._renderData = null;
20027
+ };
19762
20028
  _proto._calDefaultSize = function _calDefaultSize() {
19763
20029
  var sprite = this._sprite;
19764
20030
  if (sprite) {
@@ -19850,9 +20116,13 @@ SlicedSpriteAssembler = __decorate$1([
19850
20116
  set: function set(value) {
19851
20117
  var lastSprite = this._sprite;
19852
20118
  if (lastSprite !== value) {
19853
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20119
+ if (lastSprite) {
20120
+ lastSprite._addRefCount(-1);
20121
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20122
+ }
19854
20123
  this._dirtyUpdateFlag |= 0x7;
19855
20124
  if (value) {
20125
+ value._addRefCount(1);
19856
20126
  value._updateFlagManager.addListener(this._onSpriteChange);
19857
20127
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
19858
20128
  } else {
@@ -22266,9 +22536,16 @@ exports.AnimatorLayerBlendingMode = void 0;
22266
22536
  })(LayerState || (LayerState = {}));
22267
22537
  /**
22268
22538
  * @internal
22269
- */ var AnimationEventHandler = function AnimationEventHandler() {
22270
- this.handlers = [];
22271
- };
22539
+ */ var AnimationEventHandler = /*#__PURE__*/ function() {
22540
+ var AnimationEventHandler = function AnimationEventHandler() {
22541
+ this.handlers = [];
22542
+ };
22543
+ var _proto = AnimationEventHandler.prototype;
22544
+ _proto.dispose = function dispose() {
22545
+ this.handlers.length = 0;
22546
+ };
22547
+ return AnimationEventHandler;
22548
+ }();
22272
22549
  /**
22273
22550
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.
22274
22551
  */ var AnimatorStateTransition = function AnimatorStateTransition() {
@@ -26343,6 +26620,10 @@ var EntityParser = /*#__PURE__*/ function(Parser) {
26343
26620
  }
26344
26621
  glTFResource.sceneRoots = sceneRoots;
26345
26622
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
26623
+ // @ts-ignore
26624
+ glTFResource.defaultSceneRoot._hookResource = glTFResource;
26625
+ // @ts-ignore
26626
+ glTFResource._addRefCount(1);
26346
26627
  };
26347
26628
  return EntityParser;
26348
26629
  }(Parser);
@@ -27074,36 +27355,20 @@ var GLTFParser = /*#__PURE__*/ function() {
27074
27355
  })();
27075
27356
  /**
27076
27357
  * Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
27077
- */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
27358
+ */ var GLTFResource = /*#__PURE__*/ function(RefObject) {
27078
27359
  var GLTFResource = function GLTFResource(engine, url) {
27079
27360
  var _this;
27080
- _this = EngineObject.call(this, engine) || this;
27361
+ _this = RefObject.call(this, engine) || this;
27081
27362
  _this.url = url;
27082
27363
  return _this;
27083
27364
  };
27084
- _inherits$1(GLTFResource, EngineObject);
27365
+ _inherits$1(GLTFResource, RefObject);
27085
27366
  var _proto = GLTFResource.prototype;
27086
27367
  /**
27087
- * @override
27088
- */ _proto.destroy = function destroy() {
27089
- if (this._destroyed) {
27090
- return;
27091
- }
27092
- EngineObject.prototype.destroy.call(this);
27093
- this.defaultSceneRoot.destroy();
27094
- this.textures = null;
27095
- this.materials = null;
27096
- this.meshes = null;
27097
- this.skins = null;
27098
- this.animations = null;
27099
- this.entities = null;
27100
- this.cameras = null;
27101
- this.lights = null;
27102
- this.sceneRoots = null;
27103
- this.variants = null;
27104
- };
27368
+ * @internal
27369
+ */ _proto._onDestroy = function _onDestroy() {};
27105
27370
  return GLTFResource;
27106
- }(miniprogram$5.EngineObject);
27371
+ }(miniprogram$5.RefObject);
27107
27372
  var GLTFLoader = /*#__PURE__*/ function(Loader) {
27108
27373
  var GLTFLoader = function GLTFLoader() {
27109
27374
  return Loader.apply(this, arguments);
@@ -35877,7 +36142,7 @@ function _interopNamespace(e) {
35877
36142
  }
35878
36143
  var CoreObjects__namespace = /*#__PURE__*/ _interopNamespace(CoreObjects);
35879
36144
  //@ts-ignore
35880
- var version = "0.9.11";
36145
+ var version = "0.9.13";
35881
36146
  console.log("Galacean engine version: " + version);
35882
36147
  for(var key in CoreObjects__namespace){
35883
36148
  CoreObjects.Loader.registerClass(key, CoreObjects__namespace[key]);