@galacean/engine 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/browser.js CHANGED
@@ -6257,9 +6257,11 @@
6257
6257
  renderTexture
6258
6258
  ];
6259
6259
  for(var i = 0, n = colorTextures.length; i < n; i++){
6260
- if (colorTextures[i]._isDepthTexture) {
6260
+ var colorTexture = colorTextures[i];
6261
+ if (colorTexture._isDepthTexture) {
6261
6262
  throw "Render texture can't use depth format.";
6262
6263
  }
6264
+ colorTexture._addRefCount(1);
6263
6265
  }
6264
6266
  _this._colorTextures = colorTextures;
6265
6267
  } else {
@@ -6270,6 +6272,7 @@
6270
6272
  throw "Depth texture must use depth format.";
6271
6273
  }
6272
6274
  _this._depthTexture = depth;
6275
+ _this._depthTexture._addRefCount(1);
6273
6276
  }
6274
6277
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
6275
6278
  return _this;
@@ -6299,8 +6302,14 @@
6299
6302
  /**
6300
6303
  * Destroy render target.
6301
6304
  */ _proto.destroy = function destroy() {
6305
+ var _this__depthTexture;
6302
6306
  this._platformRenderTarget.destroy();
6303
- this._colorTextures.length = 0;
6307
+ var _this = this, colorTextures = _this._colorTextures;
6308
+ for(var i = 0, n = colorTextures.length; i < n; i++){
6309
+ colorTextures[i]._addRefCount(-1);
6310
+ }
6311
+ colorTextures.length = 0;
6312
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
6304
6313
  this._depthTexture = null;
6305
6314
  this._depth = null;
6306
6315
  };
@@ -6741,6 +6750,7 @@
6741
6750
  var fontAtlas = new FontAtlas(engine);
6742
6751
  var texture = new Texture2D(engine, 256, 256);
6743
6752
  fontAtlas.texture = texture;
6753
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
6744
6754
  this._fontAtlases.push(fontAtlas);
6745
6755
  return fontAtlas;
6746
6756
  };
@@ -7016,6 +7026,28 @@
7016
7026
  * @remarks The release principle is that it is not referenced by the components, including direct and indirect reference.
7017
7027
  */ _proto.gc = function gc() {
7018
7028
  this._gc(false);
7029
+ var engine = this.engine;
7030
+ engine._renderElementPool.garbageCollection();
7031
+ engine._spriteElementPool.garbageCollection();
7032
+ engine._spriteMaskElementPool.garbageCollection();
7033
+ engine._textElementPool.garbageCollection();
7034
+ var _componentsManager = engine._componentsManager, _lightManager = engine._lightManager;
7035
+ _componentsManager._renderers.garbageCollection();
7036
+ // @ts-ignore
7037
+ _componentsManager._onStartScripts.garbageCollection();
7038
+ // @ts-ignore
7039
+ _componentsManager._onUpdateScripts.garbageCollection();
7040
+ // @ts-ignore
7041
+ _componentsManager._onLateUpdateScripts.garbageCollection();
7042
+ // @ts-ignore
7043
+ _componentsManager._onPhysicsUpdateScripts.garbageCollection();
7044
+ // @ts-ignore
7045
+ _componentsManager._onUpdateAnimations.garbageCollection();
7046
+ // @ts-ignore
7047
+ _componentsManager._onUpdateRenderers.garbageCollection();
7048
+ _lightManager._spotLights.garbageCollection();
7049
+ _lightManager._pointLights.garbageCollection();
7050
+ _lightManager._directLights.garbageCollection();
7019
7051
  };
7020
7052
  /**
7021
7053
  * @internal
@@ -8846,6 +8878,11 @@
8846
8878
  * @returns Cloned entity
8847
8879
  */ _proto.clone = function clone() {
8848
8880
  var cloneEntity = new Entity(this._engine, this.name);
8881
+ var _this = this, hookResource = _this._hookResource;
8882
+ if (hookResource) {
8883
+ cloneEntity._hookResource = hookResource;
8884
+ hookResource._addRefCount(1);
8885
+ }
8849
8886
  cloneEntity._isActive = this._isActive;
8850
8887
  cloneEntity.transform.localMatrix = this.transform.localMatrix;
8851
8888
  var children = this._children;
@@ -8870,6 +8907,10 @@
8870
8907
  return;
8871
8908
  }
8872
8909
  EngineObject.prototype.destroy.call(this);
8910
+ if (this._hookResource) {
8911
+ this._hookResource._addRefCount(-1);
8912
+ this._hookResource = null;
8913
+ }
8873
8914
  var components = this._components;
8874
8915
  for(var i = components.length - 1; i >= 0; i--){
8875
8916
  components[i].destroy();
@@ -13413,6 +13454,7 @@
13413
13454
  _proto.cloneTo = function cloneTo(target) {
13414
13455
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
13415
13456
  Object.assign(target._macroMap, this._macroMap);
13457
+ var referCount = target._getRefCount();
13416
13458
  var propertyValueMap = this._propertyValueMap;
13417
13459
  var targetPropertyValueMap = target._propertyValueMap;
13418
13460
  var keys = Object.keys(propertyValueMap);
@@ -13424,6 +13466,7 @@
13424
13466
  targetPropertyValueMap[k] = property;
13425
13467
  } else if (_instanceof1$2(property, Texture)) {
13426
13468
  targetPropertyValueMap[k] = property;
13469
+ referCount > 0 && property._addRefCount(referCount);
13427
13470
  } else if (_instanceof1$2(property, Array) || _instanceof1$2(property, Float32Array) || _instanceof1$2(property, Int32Array)) {
13428
13471
  targetPropertyValueMap[k] = property.slice();
13429
13472
  } else {
@@ -14414,9 +14457,9 @@
14414
14457
  var Material = function Material(engine, shader) {
14415
14458
  var _this;
14416
14459
  _this = RefObject.call(this, engine) || this;
14417
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Material);
14418
14460
  /** @internal */ _this._renderStates = [] // todo: later will as a part of shaderData when shader effect frame is OK, that is more powerful and flexible.
14419
14461
  ;
14462
+ _this._shaderData = new ShaderData(ShaderDataGroup.Material);
14420
14463
  _this.shader = shader;
14421
14464
  return _this;
14422
14465
  };
@@ -14449,8 +14492,21 @@
14449
14492
  */ _proto._preRender = function _preRender(renderElement) {};
14450
14493
  /**
14451
14494
  * @override
14452
- */ _proto._onDestroy = function _onDestroy() {};
14495
+ */ _proto._onDestroy = function _onDestroy() {
14496
+ this._shader = null;
14497
+ this._shaderData = null;
14498
+ this._renderStates.length = 0;
14499
+ this._renderStates = null;
14500
+ };
14453
14501
  _create_class$3(Material, [
14502
+ {
14503
+ key: "shaderData",
14504
+ get: /**
14505
+ * Shader data.
14506
+ */ function get() {
14507
+ return this._shaderData;
14508
+ }
14509
+ },
14454
14510
  {
14455
14511
  key: "shader",
14456
14512
  get: /**
@@ -14518,6 +14574,12 @@
14518
14574
  */ _proto.resetPool = function resetPool() {
14519
14575
  this._elementPoolIndex = 0;
14520
14576
  };
14577
+ _proto.garbageCollection = function garbageCollection() {
14578
+ var _this = this, pool = _this._elementPool;
14579
+ for(var i = pool.length - 1; i >= 0; i--){
14580
+ pool[i].dispose && pool[i].dispose();
14581
+ }
14582
+ };
14521
14583
  return ClassPool;
14522
14584
  }();
14523
14585
  var RenderElement = function RenderElement() {};
@@ -14537,6 +14599,9 @@
14537
14599
  this.renderState = renderState;
14538
14600
  this.shaderPass = shaderPass;
14539
14601
  };
14602
+ _proto.dispose = function dispose() {
14603
+ this.component = this.mesh = this.subMesh = this.material = this.renderState = this.shaderPass = null;
14604
+ };
14540
14605
  return MeshRenderElement;
14541
14606
  }(RenderElement);
14542
14607
  /**
@@ -14580,6 +14645,9 @@
14580
14645
  this.renderState = renderState;
14581
14646
  this.shaderPass = shaderPass;
14582
14647
  };
14648
+ _proto.dispose = function dispose() {
14649
+ this.component = this.renderData = this.material = this.texture = this.renderState = this.shaderPass = null;
14650
+ };
14583
14651
  return SpriteElement;
14584
14652
  }(RenderElement);
14585
14653
  var SpriteMaskElement = /*#__PURE__*/ function(RenderElement) {
@@ -14597,6 +14665,9 @@
14597
14665
  this.renderData = renderData;
14598
14666
  this.material = material;
14599
14667
  };
14668
+ _proto.dispose = function dispose() {
14669
+ this.component = this.renderData = this.material = null;
14670
+ };
14600
14671
  return SpriteMaskElement;
14601
14672
  }(RenderElement);
14602
14673
  /**
@@ -14612,7 +14683,6 @@
14612
14683
  var Renderer1 = function Renderer1(entity) {
14613
14684
  var _this;
14614
14685
  _this = Component.call(this, entity) || this;
14615
- /** ShaderData related to renderer. */ _this.shaderData = new ShaderData(ShaderDataGroup.Renderer);
14616
14686
  /** @internal */ _this._onUpdateIndex = -1;
14617
14687
  /** @internal */ _this._rendererIndex = -1;
14618
14688
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
@@ -14620,6 +14690,7 @@
14620
14690
  _this._overrideUpdate = false;
14621
14691
  _this._materials = [];
14622
14692
  _this._dirtyUpdateFlag = 0;
14693
+ _this._shaderData = new ShaderData(ShaderDataGroup.Renderer);
14623
14694
  _this._mvMatrix = new Matrix();
14624
14695
  _this._mvpMatrix = new Matrix();
14625
14696
  _this._mvInvMatrix = new Matrix();
@@ -14767,6 +14838,17 @@
14767
14838
  var _materials_i;
14768
14839
  (_materials_i = materials[i]) == null ? void 0 : _materials_i._addRefCount(-1);
14769
14840
  }
14841
+ this._entity = null;
14842
+ this._globalShaderMacro = null;
14843
+ this._bounds = null;
14844
+ this._materials = null;
14845
+ this._shaderData = null;
14846
+ this._mvMatrix = null;
14847
+ this._mvpMatrix = null;
14848
+ this._mvInvMatrix = null;
14849
+ this._normalMatrix = null;
14850
+ this._materialsInstanced = null;
14851
+ this._rendererLayer = null;
14770
14852
  };
14771
14853
  _proto._updateShaderData = function _updateShaderData(context) {
14772
14854
  var entity = this.entity;
@@ -14828,6 +14910,14 @@
14828
14910
  this._dirtyUpdateFlag |= 0x1;
14829
14911
  };
14830
14912
  _create_class$3(Renderer1, [
14913
+ {
14914
+ key: "shaderData",
14915
+ get: /**
14916
+ * ShaderData related to renderer.
14917
+ */ function get() {
14918
+ return this._shaderData;
14919
+ }
14920
+ },
14831
14921
  {
14832
14922
  key: "isCulled",
14833
14923
  get: /**
@@ -14912,9 +15002,6 @@
14912
15002
  }(), function() {
14913
15003
  _Renderer._rendererLayerProperty = Shader.getPropertyByName("oasis_RendererLayer");
14914
15004
  }(), _Renderer);
14915
- __decorate$1([
14916
- deepClone
14917
- ], exports.Renderer.prototype, "shaderData", void 0);
14918
15005
  __decorate$1([
14919
15006
  ignoreClone
14920
15007
  ], exports.Renderer.prototype, "_distanceForSort", void 0);
@@ -14942,6 +15029,9 @@
14942
15029
  __decorate$1([
14943
15030
  ignoreClone
14944
15031
  ], exports.Renderer.prototype, "_dirtyUpdateFlag", void 0);
15032
+ __decorate$1([
15033
+ deepClone
15034
+ ], exports.Renderer.prototype, "_shaderData", void 0);
14945
15035
  __decorate$1([
14946
15036
  ignoreClone
14947
15037
  ], exports.Renderer.prototype, "_mvMatrix", void 0);
@@ -15140,16 +15230,6 @@
15140
15230
  }
15141
15231
  var _proto = SpriteMask.prototype;
15142
15232
  /**
15143
- * @override
15144
- * @inheritdoc
15145
- */ _proto._onDestroy = function _onDestroy() {
15146
- var _this__sprite;
15147
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
15148
- this._sprite = null;
15149
- this._renderData = null;
15150
- Renderer.prototype._onDestroy.call(this);
15151
- };
15152
- /**
15153
15233
  * @internal
15154
15234
  */ _proto._cloneTo = function _cloneTo(target) {
15155
15235
  Renderer.prototype._cloneTo.call(this, target);
@@ -15189,6 +15269,20 @@
15189
15269
  context.camera._renderPipeline._allSpriteMasks.add(this);
15190
15270
  this._maskElement = maskElement;
15191
15271
  };
15272
+ /**
15273
+ * @internal
15274
+ * @inheritdoc
15275
+ */ _proto._onDestroy = function _onDestroy() {
15276
+ Renderer.prototype._onDestroy.call(this);
15277
+ var sprite = this._sprite;
15278
+ if (sprite) {
15279
+ sprite._addRefCount(-1);
15280
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
15281
+ }
15282
+ this._entity = null;
15283
+ this._sprite = null;
15284
+ this._renderData = null;
15285
+ };
15192
15286
  _proto._calDefaultSize = function _calDefaultSize() {
15193
15287
  var sprite = this._sprite;
15194
15288
  if (sprite) {
@@ -15307,9 +15401,13 @@
15307
15401
  set: function set(value) {
15308
15402
  var lastSprite = this._sprite;
15309
15403
  if (lastSprite !== value) {
15310
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
15404
+ if (lastSprite) {
15405
+ lastSprite._addRefCount(-1);
15406
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
15407
+ }
15311
15408
  this._dirtyUpdateFlag |= 0x7;
15312
15409
  if (value) {
15410
+ value._addRefCount(1);
15313
15411
  value._updateFlagManager.addListener(this._onSpriteChange);
15314
15412
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
15315
15413
  } else {
@@ -15776,14 +15874,19 @@
15776
15874
  }();
15777
15875
  /**
15778
15876
  * Sub-mesh, mainly contains drawing information.
15779
- */ var SubMesh = function SubMesh(start, count, topology) {
15780
- if (start === void 0) start = 0;
15781
- if (count === void 0) count = 0;
15782
- if (topology === void 0) topology = exports.MeshTopology.Triangles;
15783
- this.start = start;
15784
- this.count = count;
15785
- this.topology = topology;
15786
- };
15877
+ */ var SubMesh = /*#__PURE__*/ function() {
15878
+ var SubMesh = function SubMesh(start, count, topology) {
15879
+ if (start === void 0) start = 0;
15880
+ if (count === void 0) count = 0;
15881
+ if (topology === void 0) topology = exports.MeshTopology.Triangles;
15882
+ this.start = start;
15883
+ this.count = count;
15884
+ this.topology = topology;
15885
+ };
15886
+ var _proto = SubMesh.prototype;
15887
+ _proto.dispose = function dispose() {};
15888
+ return SubMesh;
15889
+ }();
15787
15890
  /**
15788
15891
  * Mesh.
15789
15892
  */ var Mesh = /*#__PURE__*/ function(RefObject) {
@@ -15864,10 +15967,11 @@
15864
15967
  /**
15865
15968
  * @internal
15866
15969
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
15867
- if (this._getRefCount() > 0) {
15868
- var lastBinding = this._vertexBufferBindings[index];
15869
- lastBinding && lastBinding._buffer._addRefCount(-1);
15870
- binding._buffer._addRefCount(1);
15970
+ var referCount = this._getRefCount();
15971
+ if (referCount > 0) {
15972
+ var _this__vertexBufferBindings_index;
15973
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
15974
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
15871
15975
  }
15872
15976
  this._vertexBufferBindings[index] = binding;
15873
15977
  this._bufferStructChanged = true;
@@ -15881,11 +15985,13 @@
15881
15985
  /**
15882
15986
  * @override
15883
15987
  */ _proto._addRefCount = function _addRefCount(value) {
15988
+ var _this__indexBufferBinding;
15884
15989
  RefObject.prototype._addRefCount.call(this, value);
15885
15990
  var vertexBufferBindings = this._vertexBufferBindings;
15886
15991
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
15887
15992
  vertexBufferBindings[i]._buffer._addRefCount(value);
15888
15993
  }
15994
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
15889
15995
  };
15890
15996
  /**
15891
15997
  * @override
@@ -15895,6 +16001,7 @@
15895
16001
  this._indexBufferBinding = null;
15896
16002
  this._vertexElements = null;
15897
16003
  this._vertexElementMap = null;
16004
+ this._updateFlagManager = null;
15898
16005
  this._platformPrimitive.destroy();
15899
16006
  };
15900
16007
  _proto._setVertexElements = function _setVertexElements(elements) {
@@ -15905,6 +16012,11 @@
15905
16012
  };
15906
16013
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
15907
16014
  var lastBinding = this._indexBufferBinding;
16015
+ var referCount = this._getRefCount();
16016
+ if (referCount > 0) {
16017
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
16018
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
16019
+ }
15908
16020
  if (binding) {
15909
16021
  this._indexBufferBinding = binding;
15910
16022
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -17569,8 +17681,8 @@
17569
17681
  */ _proto._onDestroy = function _onDestroy() {
17570
17682
  Renderer.prototype._onDestroy.call(this);
17571
17683
  var mesh = this._mesh;
17572
- if (mesh && !mesh.destroyed) {
17573
- mesh._addRefCount(-1);
17684
+ if (mesh) {
17685
+ mesh.destroyed || mesh._addRefCount(-1);
17574
17686
  mesh._updateFlagManager.removeListener(this._onMeshChanged);
17575
17687
  this._mesh = null;
17576
17688
  }
@@ -17904,10 +18016,21 @@
17904
18016
  * @internal
17905
18017
  * @override
17906
18018
  */ _proto._onDestroy = function _onDestroy() {
17907
- var _this_rootBone, _this__jointTexture;
18019
+ var _this__rootBone, _this__jointTexture;
17908
18020
  MeshRenderer.prototype._onDestroy.call(this);
17909
- (_this_rootBone = this.rootBone) == null ? void 0 : _this_rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
18021
+ (_this__rootBone = this._rootBone) == null ? void 0 : _this__rootBone.transform._updateFlagManager.removeListener(this._onTransformChanged);
18022
+ this._rootBone = null;
18023
+ this._jointDataCreateCache = null;
18024
+ this._skin = null;
18025
+ this._blendShapeWeights = null;
18026
+ this._localBounds = null;
18027
+ this._jointMatrices = null;
17910
18028
  (_this__jointTexture = this._jointTexture) == null ? void 0 : _this__jointTexture.destroy();
18029
+ this._jointTexture = null;
18030
+ if (this._jointEntities) {
18031
+ this._jointEntities.length = 0;
18032
+ this._jointEntities = null;
18033
+ }
17911
18034
  };
17912
18035
  /**
17913
18036
  * @internal
@@ -19064,14 +19187,17 @@
19064
19187
  _proto._createMesh = function _createMesh(engine, index) {
19065
19188
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
19066
19189
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
19190
+ mesh.isGCIgnored = true;
19067
19191
  var vertexElements = [];
19068
19192
  var vertexStride = this.createVertexElements(vertexElements);
19069
19193
  // vertices
19070
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
19194
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
19195
+ vertexBuffer.isGCIgnored = true;
19071
19196
  // indices
19072
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
19073
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
19074
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
19197
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
19198
+ indiceBuffer.isGCIgnored = true;
19199
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
19200
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
19075
19201
  mesh.setVertexElements(vertexElements);
19076
19202
  return mesh;
19077
19203
  };
@@ -19279,6 +19405,11 @@
19279
19405
  return _this;
19280
19406
  };
19281
19407
  _inherits$2(TextRenderElement, RenderElement);
19408
+ var _proto = TextRenderElement.prototype;
19409
+ _proto.dispose = function dispose() {
19410
+ this.component = this.material = this.renderState = this.shaderPass = null;
19411
+ this.charElements.length = 0;
19412
+ };
19282
19413
  return TextRenderElement;
19283
19414
  }(RenderElement);
19284
19415
  /**
@@ -19304,6 +19435,12 @@
19304
19435
  var _proto = Sky.prototype;
19305
19436
  /**
19306
19437
  * @internal
19438
+ */ _proto.destroy = function destroy() {
19439
+ this.mesh = null;
19440
+ this.material = null;
19441
+ };
19442
+ /**
19443
+ * @internal
19307
19444
  */ _proto._render = function _render(context) {
19308
19445
  var _this = this, material = _this.material, mesh = _this.mesh;
19309
19446
  if (!material) {
@@ -19342,6 +19479,40 @@
19342
19479
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
19343
19480
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
19344
19481
  };
19482
+ _create_class$3(Sky, [
19483
+ {
19484
+ key: "material",
19485
+ get: /**
19486
+ * Material of the sky.
19487
+ */ function get() {
19488
+ return this._material;
19489
+ },
19490
+ set: function set(value) {
19491
+ if (this._material !== value) {
19492
+ var _this__material;
19493
+ value == null ? void 0 : value._addRefCount(1);
19494
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
19495
+ this._material = value;
19496
+ }
19497
+ }
19498
+ },
19499
+ {
19500
+ key: "mesh",
19501
+ get: /**
19502
+ * Mesh of the sky.
19503
+ */ function get() {
19504
+ return this._mesh;
19505
+ },
19506
+ set: function set(value) {
19507
+ if (this._mesh !== value) {
19508
+ var _this__mesh;
19509
+ value == null ? void 0 : value._addRefCount(1);
19510
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
19511
+ this._mesh = value;
19512
+ }
19513
+ }
19514
+ }
19515
+ ]);
19345
19516
  return Sky;
19346
19517
  }();
19347
19518
  (function() {
@@ -19371,11 +19542,27 @@
19371
19542
  this.sky = new Sky();
19372
19543
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
19373
19544
  this._texture = null;
19374
- this._mesh = this._createPlane(_engine);
19545
+ this._initMesh(_engine);
19375
19546
  };
19376
19547
  var _proto = Background.prototype;
19377
19548
  /**
19378
19549
  * @internal
19550
+ */ _proto.destroy = function destroy() {
19551
+ this._mesh._addRefCount(-1);
19552
+ this._mesh = null;
19553
+ this.texture = null;
19554
+ this.solidColor = null;
19555
+ this.sky.destroy();
19556
+ };
19557
+ /**
19558
+ * @internal
19559
+ * Standalone for CanvasRenderer plugin.
19560
+ */ _proto._initMesh = function _initMesh(engine) {
19561
+ this._mesh = this._createPlane(engine);
19562
+ this._mesh._addRefCount(1);
19563
+ };
19564
+ /**
19565
+ * @internal
19379
19566
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
19380
19567
  if (!this._texture) {
19381
19568
  return;
@@ -19444,6 +19631,9 @@
19444
19631
  },
19445
19632
  set: function set(value) {
19446
19633
  if (this._texture !== value) {
19634
+ var _this__texture;
19635
+ value == null ? void 0 : value._addRefCount(1);
19636
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
19447
19637
  this._texture = value;
19448
19638
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
19449
19639
  }
@@ -19743,8 +19933,6 @@
19743
19933
  function Scene(engine, name) {
19744
19934
  var _this;
19745
19935
  _this = EngineObject.call(this, engine) || this;
19746
- /** The background of the scene. */ _this.background = new Background(_this._engine);
19747
- /** Scene-related shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Scene);
19748
19936
  /** If cast shadows. */ _this.castShadows = true;
19749
19937
  /** The resolution of the shadow maps. */ _this.shadowResolution = exports.ShadowResolution.Medium;
19750
19938
  /** The splits of two cascade distribution. */ _this.shadowTwoCascadeSplits = 1.0 / 3.0;
@@ -19754,6 +19942,8 @@
19754
19942
  /** @internal */ _this._isActiveInEngine = false;
19755
19943
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
19756
19944
  /** @internal */ _this._rootEntities = [];
19945
+ _this._background = new Background(_this._engine);
19946
+ _this._shaderData = new ShaderData(ShaderDataGroup.Scene);
19757
19947
  _this._shadowCascades = exports.ShadowCascadesMode.NoCascades;
19758
19948
  _this._fogMode = exports.FogMode.None;
19759
19949
  _this._fogColor = new Color$1(0.5, 0.5, 0.5, 1.0);
@@ -19915,6 +20105,8 @@
19915
20105
  var sunLightIndex = lightManager._getSunLightIndex();
19916
20106
  if (sunLightIndex !== -1) {
19917
20107
  this._sunLight = lightManager._directLights.get(sunLightIndex);
20108
+ } else {
20109
+ this._sunLight = null;
19918
20110
  }
19919
20111
  if (this.castShadows && this._sunLight && this._sunLight.shadowType !== exports.ShadowType.None) {
19920
20112
  shaderData.enableMacro("SHADOW_TYPE", this._sunLight.shadowType.toString());
@@ -19943,6 +20135,7 @@
19943
20135
  this._rootEntities[0].destroy();
19944
20136
  }
19945
20137
  this._activeCameras.length = 0;
20138
+ this.background.destroy();
19946
20139
  this.shaderData._addRefCount(-1);
19947
20140
  };
19948
20141
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -19973,6 +20166,22 @@
19973
20166
  this._fogParams.w = density / Math.sqrt(Math.LN2);
19974
20167
  };
19975
20168
  _create_class$3(Scene, [
20169
+ {
20170
+ key: "shaderData",
20171
+ get: /**
20172
+ * Scene-related shader data.
20173
+ */ function get() {
20174
+ return this._shaderData;
20175
+ }
20176
+ },
20177
+ {
20178
+ key: "background",
20179
+ get: /**
20180
+ * The background of the scene.
20181
+ */ function get() {
20182
+ return this._background;
20183
+ }
20184
+ },
19976
20185
  {
19977
20186
  key: "shadowCascades",
19978
20187
  get: /**
@@ -20333,7 +20542,7 @@
20333
20542
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
20334
20543
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
20335
20544
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
20336
- _this._textDefaultFont.isGCIgnored = false;
20545
+ _this._textDefaultFont.isGCIgnored = true;
20337
20546
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
20338
20547
  var magentaPixel = new Uint8Array([
20339
20548
  255,
@@ -20368,6 +20577,7 @@
20368
20577
  _this._magentaTexture2DArray = magentaTexture2DArray;
20369
20578
  }
20370
20579
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
20580
+ magentaMaterial.isGCIgnored = true;
20371
20581
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
20372
20582
  _this._magentaMaterial = magentaMaterial;
20373
20583
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -21893,7 +22103,11 @@
21893
22103
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
21894
22104
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
21895
22105
  }
21896
- this._renderTargets = null;
22106
+ var renderTargets = this._renderTargets;
22107
+ if (renderTargets) {
22108
+ renderTargets.destroy();
22109
+ this._renderTargets = null;
22110
+ }
21897
22111
  var viewportOffset = this._viewportOffsets;
21898
22112
  var shadowTileResolution1 = this._shadowTileResolution;
21899
22113
  switch(shadowCascades){
@@ -22224,7 +22438,6 @@
22224
22438
  var Camera1 = function Camera1(entity) {
22225
22439
  var _this;
22226
22440
  _this = Component.call(this, entity) || this;
22227
- /** Shader data. */ _this.shaderData = new ShaderData(ShaderDataGroup.Camera);
22228
22441
  /** Rendering priority - A Camera with higher priority will be rendered on top of a camera with lower priority. */ _this.priority = 0;
22229
22442
  /** Whether to enable frustum culling, it is enabled by default. */ _this.enableFrustumCulling = true;
22230
22443
  /**
@@ -22238,6 +22451,7 @@
22238
22451
  /** @internal */ _this._globalShaderMacro = new ShaderMacroCollection();
22239
22452
  /** @internal */ _this._frustum = new BoundingFrustum();
22240
22453
  /** @internal */ _this._virtualCamera = new VirtualCamera();
22454
+ _this._shaderData = new ShaderData(ShaderDataGroup.Camera);
22241
22455
  _this._isProjMatSetting = false;
22242
22456
  _this._nearClipPlane = 0.1;
22243
22457
  _this._farClipPlane = 100;
@@ -22437,6 +22651,20 @@
22437
22651
  this._isInvViewProjDirty.destroy();
22438
22652
  this._isViewMatrixDirty.destroy();
22439
22653
  this.shaderData._addRefCount(-1);
22654
+ this._entity = null;
22655
+ this._globalShaderMacro = null;
22656
+ this._frustum = null;
22657
+ this._renderPipeline = null;
22658
+ this._virtualCamera = null;
22659
+ this._shaderData = null;
22660
+ this._frustumViewChangeFlag = null;
22661
+ this._transform = null;
22662
+ this._isViewMatrixDirty = null;
22663
+ this._isInvViewProjDirty = null;
22664
+ this._viewport = null;
22665
+ this._inverseProjectionMatrix = null;
22666
+ this._lastAspectSize = null;
22667
+ this._invViewProjMat = null;
22440
22668
  };
22441
22669
  _proto._projMatChange = function _projMatChange() {
22442
22670
  this._isFrustumProjectDirty = true;
@@ -22476,6 +22704,14 @@
22476
22704
  return this._inverseProjectionMatrix;
22477
22705
  };
22478
22706
  _create_class$3(Camera1, [
22707
+ {
22708
+ key: "shaderData",
22709
+ get: /**
22710
+ * Shader data.
22711
+ */ function get() {
22712
+ return this._shaderData;
22713
+ }
22714
+ },
22479
22715
  {
22480
22716
  key: "nearClipPlane",
22481
22717
  get: /**
@@ -23915,10 +24151,17 @@
23915
24151
  * @internal
23916
24152
  */ _proto._addSprite = function _addSprite(sprite) {
23917
24153
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
24154
+ sprite._atlas = this;
24155
+ sprite.isGCIgnored = true;
23918
24156
  };
23919
24157
  /**
23920
24158
  * @override
23921
24159
  */ _proto._onDestroy = function _onDestroy() {
24160
+ var _this = this, sprites = _this._sprites;
24161
+ for(var i = 0, n = sprites.length; i < n; i++){
24162
+ sprites[i].destroy();
24163
+ }
24164
+ sprites.length = 0;
23922
24165
  this._sprites = null;
23923
24166
  this._spriteNamesToIndex = null;
23924
24167
  };
@@ -24017,10 +24260,29 @@
24017
24260
  };
24018
24261
  /**
24019
24262
  * @override
24263
+ * @internal
24264
+ */ _proto._addRefCount = function _addRefCount(value) {
24265
+ var _this__atlas;
24266
+ RefObject.prototype._addRefCount.call(this, value);
24267
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
24268
+ };
24269
+ /**
24270
+ * @override
24271
+ * @internal
24020
24272
  */ _proto._onDestroy = function _onDestroy() {
24021
- if (this._texture) {
24022
- this._texture = null;
24023
- }
24273
+ this._positions.length = 0;
24274
+ this._positions = null;
24275
+ this._uvs.length = 0;
24276
+ this._uvs = null;
24277
+ this._atlasRegion = null;
24278
+ this._atlasRegionOffset = null;
24279
+ this._region = null;
24280
+ this._pivot = null;
24281
+ this._border = null;
24282
+ this._bounds = null;
24283
+ this._atlas = null;
24284
+ this._texture = null;
24285
+ this._updateFlagManager = null;
24024
24286
  };
24025
24287
  _proto._calDefaultSize = function _calDefaultSize() {
24026
24288
  if (this._texture) {
@@ -24123,7 +24385,7 @@
24123
24385
  key: "width",
24124
24386
  get: /**
24125
24387
  * The width of the sprite (in world coordinates).
24126
- *
24388
+ *
24127
24389
  * @remarks
24128
24390
  * If width is set, return the set value,
24129
24391
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -24146,7 +24408,7 @@
24146
24408
  key: "height",
24147
24409
  get: /**
24148
24410
  * The height of the sprite (in world coordinates).
24149
- *
24411
+ *
24150
24412
  * @remarks
24151
24413
  * If height is set, return the set value,
24152
24414
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -24452,17 +24714,6 @@
24452
24714
  target.drawMode = this._drawMode;
24453
24715
  };
24454
24716
  /**
24455
- * @internal
24456
- */ _proto._onDestroy = function _onDestroy() {
24457
- var _this__sprite;
24458
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
24459
- this._color = null;
24460
- this._sprite = null;
24461
- this._assembler = null;
24462
- this._renderData = null;
24463
- Renderer.prototype._onDestroy.call(this);
24464
- };
24465
- /**
24466
24717
  * @override
24467
24718
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
24468
24719
  if (this.sprite) {
@@ -24500,6 +24751,21 @@
24500
24751
  context.camera._renderPipeline.pushPrimitive(spriteElement);
24501
24752
  }
24502
24753
  };
24754
+ /**
24755
+ * @internal
24756
+ */ _proto._onDestroy = function _onDestroy() {
24757
+ Renderer.prototype._onDestroy.call(this);
24758
+ var sprite = this._sprite;
24759
+ if (sprite) {
24760
+ sprite._addRefCount(-1);
24761
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
24762
+ }
24763
+ this._entity = null;
24764
+ this._color = null;
24765
+ this._sprite = null;
24766
+ this._assembler = null;
24767
+ this._renderData = null;
24768
+ };
24503
24769
  _proto._calDefaultSize = function _calDefaultSize() {
24504
24770
  var sprite = this._sprite;
24505
24771
  if (sprite) {
@@ -24591,9 +24857,13 @@
24591
24857
  set: function set(value) {
24592
24858
  var lastSprite = this._sprite;
24593
24859
  if (lastSprite !== value) {
24594
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
24860
+ if (lastSprite) {
24861
+ lastSprite._addRefCount(-1);
24862
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
24863
+ }
24595
24864
  this._dirtyUpdateFlag |= 0x7;
24596
24865
  if (value) {
24866
+ value._addRefCount(1);
24597
24867
  value._updateFlagManager.addListener(this._onSpriteChange);
24598
24868
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
24599
24869
  } else {
@@ -27007,9 +27277,16 @@
27007
27277
  })(LayerState || (LayerState = {}));
27008
27278
  /**
27009
27279
  * @internal
27010
- */ var AnimationEventHandler = function AnimationEventHandler() {
27011
- this.handlers = [];
27012
- };
27280
+ */ var AnimationEventHandler = /*#__PURE__*/ function() {
27281
+ var AnimationEventHandler = function AnimationEventHandler() {
27282
+ this.handlers = [];
27283
+ };
27284
+ var _proto = AnimationEventHandler.prototype;
27285
+ _proto.dispose = function dispose() {
27286
+ this.handlers.length = 0;
27287
+ };
27288
+ return AnimationEventHandler;
27289
+ }();
27013
27290
  /**
27014
27291
  * Transitions define when and how the state machine switch from on state to another. AnimatorTransition always originate from a StateMachine or a StateMachine entry.
27015
27292
  */ var AnimatorStateTransition = function AnimatorStateTransition() {
@@ -33241,6 +33518,10 @@
33241
33518
  }
33242
33519
  glTFResource.sceneRoots = sceneRoots;
33243
33520
  glTFResource.defaultSceneRoot = sceneRoots[sceneID];
33521
+ // @ts-ignore
33522
+ glTFResource.defaultSceneRoot._hookResource = glTFResource;
33523
+ // @ts-ignore
33524
+ glTFResource._addRefCount(1);
33244
33525
  };
33245
33526
  return EntityParser;
33246
33527
  }(Parser);
@@ -33972,36 +34253,20 @@
33972
34253
  })();
33973
34254
  /**
33974
34255
  * Product after GLTF parser, usually, `defaultSceneRoot` is only needed to use.
33975
- */ var GLTFResource = /*#__PURE__*/ function(EngineObject) {
34256
+ */ var GLTFResource = /*#__PURE__*/ function(RefObject) {
33976
34257
  var GLTFResource = function GLTFResource(engine, url) {
33977
34258
  var _this;
33978
- _this = EngineObject.call(this, engine) || this;
34259
+ _this = RefObject.call(this, engine) || this;
33979
34260
  _this.url = url;
33980
34261
  return _this;
33981
34262
  };
33982
- _inherits(GLTFResource, EngineObject);
34263
+ _inherits(GLTFResource, RefObject);
33983
34264
  var _proto = GLTFResource.prototype;
33984
34265
  /**
33985
- * @override
33986
- */ _proto.destroy = function destroy() {
33987
- if (this._destroyed) {
33988
- return;
33989
- }
33990
- EngineObject.prototype.destroy.call(this);
33991
- this.defaultSceneRoot.destroy();
33992
- this.textures = null;
33993
- this.materials = null;
33994
- this.meshes = null;
33995
- this.skins = null;
33996
- this.animations = null;
33997
- this.entities = null;
33998
- this.cameras = null;
33999
- this.lights = null;
34000
- this.sceneRoots = null;
34001
- this.variants = null;
34002
- };
34266
+ * @internal
34267
+ */ _proto._onDestroy = function _onDestroy() {};
34003
34268
  return GLTFResource;
34004
- }(EngineObject);
34269
+ }(RefObject);
34005
34270
  var GLTFLoader = /*#__PURE__*/ function(Loader) {
34006
34271
  var GLTFLoader = function GLTFLoader() {
34007
34272
  return Loader.apply(this, arguments);
@@ -36010,7 +36275,7 @@
36010
36275
  }));
36011
36276
 
36012
36277
  //@ts-ignore
36013
- var version = "0.9.11";
36278
+ var version = "0.9.13";
36014
36279
  console.log("Galacean engine version: " + version);
36015
36280
  for(var key in CoreObjects){
36016
36281
  Loader.registerClass(key, CoreObjects[key]);