@galacean/engine-core 0.0.0-experimental-0.9-plus.6 → 0.0.0-experimental-0.9-plus.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/main.js CHANGED
@@ -2748,9 +2748,11 @@ function ObjectValues(obj) {
2748
2748
  renderTexture
2749
2749
  ];
2750
2750
  for(var i = 0, n = colorTextures.length; i < n; i++){
2751
- if (colorTextures[i]._isDepthTexture) {
2751
+ var colorTexture = colorTextures[i];
2752
+ if (colorTexture._isDepthTexture) {
2752
2753
  throw "Render texture can't use depth format.";
2753
2754
  }
2755
+ colorTexture._addRefCount(1);
2754
2756
  }
2755
2757
  _this._colorTextures = colorTextures;
2756
2758
  } else {
@@ -2761,6 +2763,7 @@ function ObjectValues(obj) {
2761
2763
  throw "Depth texture must use depth format.";
2762
2764
  }
2763
2765
  _this._depthTexture = depth;
2766
+ _this._depthTexture._addRefCount(1);
2764
2767
  }
2765
2768
  _this._platformRenderTarget = engine._hardwareRenderer.createPlatformRenderTarget(_assert_this_initialized(_this));
2766
2769
  return _this;
@@ -2789,8 +2792,14 @@ function ObjectValues(obj) {
2789
2792
  /**
2790
2793
  * Destroy render target.
2791
2794
  */ _proto.destroy = function destroy() {
2795
+ var _this__depthTexture;
2792
2796
  this._platformRenderTarget.destroy();
2793
- this._colorTextures.length = 0;
2797
+ var _this = this, colorTextures = _this._colorTextures;
2798
+ for(var i = 0, n = colorTextures.length; i < n; i++){
2799
+ colorTextures[i]._addRefCount(-1);
2800
+ }
2801
+ colorTextures.length = 0;
2802
+ (_this__depthTexture = this._depthTexture) == null ? void 0 : _this__depthTexture._addRefCount(-1);
2794
2803
  this._depthTexture = null;
2795
2804
  this._depth = null;
2796
2805
  };
@@ -3236,6 +3245,7 @@ function ObjectValues(obj) {
3236
3245
  var fontAtlas = new FontAtlas(engine);
3237
3246
  var texture = new Texture2D(engine, 256, 256);
3238
3247
  fontAtlas.texture = texture;
3248
+ fontAtlas.isGCIgnored = texture.isGCIgnored = true;
3239
3249
  this._fontAtlases.push(fontAtlas);
3240
3250
  return fontAtlas;
3241
3251
  };
@@ -8772,6 +8782,7 @@ exports.DynamicColliderConstraints = void 0;
8772
8782
  _proto.cloneTo = function cloneTo(target) {
8773
8783
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
8774
8784
  Object.assign(target._macroMap, this._macroMap);
8785
+ var referCount = target._getRefCount();
8775
8786
  var propertyValueMap = this._propertyValueMap;
8776
8787
  var targetPropertyValueMap = target._propertyValueMap;
8777
8788
  var keys = Object.keys(propertyValueMap);
@@ -8783,6 +8794,7 @@ exports.DynamicColliderConstraints = void 0;
8783
8794
  targetPropertyValueMap[k] = property;
8784
8795
  } else if (_instanceof(property, Texture)) {
8785
8796
  targetPropertyValueMap[k] = property;
8797
+ referCount > 0 && property._addRefCount(referCount);
8786
8798
  } else if (_instanceof(property, Array) || _instanceof(property, Float32Array) || _instanceof(property, Int32Array)) {
8787
8799
  targetPropertyValueMap[k] = property.slice();
8788
8800
  } else {
@@ -10527,16 +10539,6 @@ SimpleSpriteAssembler = __decorate([
10527
10539
  }
10528
10540
  var _proto = SpriteMask.prototype;
10529
10541
  /**
10530
- * @override
10531
- * @inheritdoc
10532
- */ _proto._onDestroy = function _onDestroy() {
10533
- var _this__sprite;
10534
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
10535
- this._sprite = null;
10536
- this._renderData = null;
10537
- Renderer.prototype._onDestroy.call(this);
10538
- };
10539
- /**
10540
10542
  * @internal
10541
10543
  */ _proto._cloneTo = function _cloneTo(target) {
10542
10544
  Renderer.prototype._cloneTo.call(this, target);
@@ -10576,6 +10578,19 @@ SimpleSpriteAssembler = __decorate([
10576
10578
  context.camera._renderPipeline._allSpriteMasks.add(this);
10577
10579
  this._maskElement = maskElement;
10578
10580
  };
10581
+ /**
10582
+ * @internal
10583
+ * @inheritdoc
10584
+ */ _proto._onDestroy = function _onDestroy() {
10585
+ Renderer.prototype._onDestroy.call(this);
10586
+ var sprite = this._sprite;
10587
+ if (sprite) {
10588
+ sprite._addRefCount(-1);
10589
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
10590
+ }
10591
+ this._sprite = null;
10592
+ this._renderData = null;
10593
+ };
10579
10594
  _proto._calDefaultSize = function _calDefaultSize() {
10580
10595
  var sprite = this._sprite;
10581
10596
  if (sprite) {
@@ -10694,9 +10709,13 @@ SimpleSpriteAssembler = __decorate([
10694
10709
  set: function set(value) {
10695
10710
  var lastSprite = this._sprite;
10696
10711
  if (lastSprite !== value) {
10697
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10712
+ if (lastSprite) {
10713
+ lastSprite._addRefCount(-1);
10714
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
10715
+ }
10698
10716
  this._dirtyUpdateFlag |= 0x7;
10699
10717
  if (value) {
10718
+ value._addRefCount(1);
10700
10719
  value._updateFlagManager.addListener(this._onSpriteChange);
10701
10720
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
10702
10721
  } else {
@@ -11263,10 +11282,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11263
11282
  /**
11264
11283
  * @internal
11265
11284
  */ _proto._setVertexBufferBinding = function _setVertexBufferBinding(index, binding) {
11266
- if (this._getRefCount() > 0) {
11267
- var lastBinding = this._vertexBufferBindings[index];
11268
- lastBinding && lastBinding._buffer._addRefCount(-1);
11269
- binding._buffer._addRefCount(1);
11285
+ var referCount = this._getRefCount();
11286
+ if (referCount > 0) {
11287
+ var _this__vertexBufferBindings_index;
11288
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
11289
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
11270
11290
  }
11271
11291
  this._vertexBufferBindings[index] = binding;
11272
11292
  this._bufferStructChanged = true;
@@ -11280,11 +11300,13 @@ var BufferUtil = /*#__PURE__*/ function() {
11280
11300
  /**
11281
11301
  * @override
11282
11302
  */ _proto._addRefCount = function _addRefCount(value) {
11303
+ var _this__indexBufferBinding;
11283
11304
  RefObject.prototype._addRefCount.call(this, value);
11284
11305
  var vertexBufferBindings = this._vertexBufferBindings;
11285
11306
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
11286
11307
  vertexBufferBindings[i]._buffer._addRefCount(value);
11287
11308
  }
11309
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
11288
11310
  };
11289
11311
  /**
11290
11312
  * @override
@@ -11304,6 +11326,11 @@ var BufferUtil = /*#__PURE__*/ function() {
11304
11326
  };
11305
11327
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
11306
11328
  var lastBinding = this._indexBufferBinding;
11329
+ var referCount = this._getRefCount();
11330
+ if (referCount > 0) {
11331
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
11332
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
11333
+ }
11307
11334
  if (binding) {
11308
11335
  this._indexBufferBinding = binding;
11309
11336
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -14482,14 +14509,17 @@ var Basic2DBatcher = /*#__PURE__*/ function() {
14482
14509
  _proto._createMesh = function _createMesh(engine, index) {
14483
14510
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
14484
14511
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
14512
+ mesh.isGCIgnored = true;
14485
14513
  var vertexElements = [];
14486
14514
  var vertexStride = this.createVertexElements(vertexElements);
14487
14515
  // vertices
14488
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14516
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
14517
+ vertexBuffer.isGCIgnored = true;
14489
14518
  // indices
14490
- this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14491
- mesh.setVertexBufferBinding(this._vertexBuffers[index], vertexStride);
14492
- mesh.setIndexBufferBinding(this._indiceBuffers[index], exports.IndexFormat.UInt16);
14519
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
14520
+ indiceBuffer.isGCIgnored = true;
14521
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
14522
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
14493
14523
  mesh.setVertexElements(vertexElements);
14494
14524
  return mesh;
14495
14525
  };
@@ -14728,6 +14758,12 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14728
14758
  var _proto = Sky.prototype;
14729
14759
  /**
14730
14760
  * @internal
14761
+ */ _proto.destroy = function destroy() {
14762
+ this.mesh = null;
14763
+ this.material = null;
14764
+ };
14765
+ /**
14766
+ * @internal
14731
14767
  */ _proto._render = function _render(context) {
14732
14768
  var _this = this, material = _this.material, mesh = _this.mesh;
14733
14769
  if (!material) {
@@ -14766,6 +14802,40 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14766
14802
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
14767
14803
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
14768
14804
  };
14805
+ _create_class(Sky, [
14806
+ {
14807
+ key: "material",
14808
+ get: /**
14809
+ * Material of the sky.
14810
+ */ function get() {
14811
+ return this._material;
14812
+ },
14813
+ set: function set(value) {
14814
+ if (this._material !== value) {
14815
+ var _this__material;
14816
+ value == null ? void 0 : value._addRefCount(1);
14817
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
14818
+ this._material = value;
14819
+ }
14820
+ }
14821
+ },
14822
+ {
14823
+ key: "mesh",
14824
+ get: /**
14825
+ * Mesh of the sky.
14826
+ */ function get() {
14827
+ return this._mesh;
14828
+ },
14829
+ set: function set(value) {
14830
+ if (this._mesh !== value) {
14831
+ var _this__mesh;
14832
+ value == null ? void 0 : value._addRefCount(1);
14833
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
14834
+ this._mesh = value;
14835
+ }
14836
+ }
14837
+ }
14838
+ ]);
14769
14839
  return Sky;
14770
14840
  }();
14771
14841
  (function() {
@@ -14796,11 +14866,28 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14796
14866
  this.sky = new Sky();
14797
14867
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
14798
14868
  this._texture = null;
14799
- this._mesh = this._createPlane(_engine);
14869
+ this._initMesh(_engine);
14800
14870
  }
14801
14871
  var _proto = Background.prototype;
14802
14872
  /**
14803
14873
  * @internal
14874
+ */ _proto.destroy = function destroy() {
14875
+ this._mesh._addRefCount(-1);
14876
+ this._mesh = null;
14877
+ this.texture = null;
14878
+ this.solidColor = null;
14879
+ this.sky.destroy();
14880
+ this._engine = null;
14881
+ };
14882
+ /**
14883
+ * @internal
14884
+ * Standalone for CanvasRenderer plugin.
14885
+ */ _proto._initMesh = function _initMesh(engine) {
14886
+ this._mesh = this._createPlane(engine);
14887
+ this._mesh._addRefCount(1);
14888
+ };
14889
+ /**
14890
+ * @internal
14804
14891
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
14805
14892
  if (!this._texture) {
14806
14893
  return;
@@ -14869,6 +14956,9 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
14869
14956
  },
14870
14957
  set: function set(value) {
14871
14958
  if (this._texture !== value) {
14959
+ var _this__texture;
14960
+ value == null ? void 0 : value._addRefCount(1);
14961
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
14872
14962
  this._texture = value;
14873
14963
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
14874
14964
  }
@@ -15381,6 +15471,7 @@ var TextRenderElement = /*#__PURE__*/ function(RenderElement) {
15381
15471
  this._rootEntities[0].destroy();
15382
15472
  }
15383
15473
  this._activeCameras.length = 0;
15474
+ this.background.destroy();
15384
15475
  this.shaderData._addRefCount(-1);
15385
15476
  };
15386
15477
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -15800,7 +15891,7 @@ ShaderPool.init();
15800
15891
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
15801
15892
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
15802
15893
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
15803
- _this._textDefaultFont.isGCIgnored = false;
15894
+ _this._textDefaultFont.isGCIgnored = true;
15804
15895
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
15805
15896
  var magentaPixel = new Uint8Array([
15806
15897
  255,
@@ -15835,6 +15926,7 @@ ShaderPool.init();
15835
15926
  _this._magentaTexture2DArray = magentaTexture2DArray;
15836
15927
  }
15837
15928
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
15929
+ magentaMaterial.isGCIgnored = true;
15838
15930
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
15839
15931
  _this._magentaMaterial = magentaMaterial;
15840
15932
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -17367,7 +17459,11 @@ var /**
17367
17459
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
17368
17460
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
17369
17461
  }
17370
- this._renderTargets = null;
17462
+ var renderTargets = this._renderTargets;
17463
+ if (renderTargets) {
17464
+ renderTargets.destroy();
17465
+ this._renderTargets = null;
17466
+ }
17371
17467
  var viewportOffset = this._viewportOffsets;
17372
17468
  var shadowTileResolution1 = this._shadowTileResolution;
17373
17469
  switch(shadowCascades){
@@ -19409,10 +19505,17 @@ exports.TextVerticalAlignment = void 0;
19409
19505
  * @internal
19410
19506
  */ _proto._addSprite = function _addSprite(sprite) {
19411
19507
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
19508
+ sprite._atlas = this;
19509
+ sprite.isGCIgnored = true;
19412
19510
  };
19413
19511
  /**
19414
19512
  * @override
19415
19513
  */ _proto._onDestroy = function _onDestroy() {
19514
+ var _this = this, sprites = _this._sprites;
19515
+ for(var i = 0, n = sprites.length; i < n; i++){
19516
+ sprites[i].destroy();
19517
+ }
19518
+ sprites.length = 0;
19416
19519
  this._sprites = null;
19417
19520
  this._spriteNamesToIndex = null;
19418
19521
  };
@@ -19513,10 +19616,29 @@ exports.TextVerticalAlignment = void 0;
19513
19616
  };
19514
19617
  /**
19515
19618
  * @override
19619
+ * @internal
19620
+ */ _proto._addRefCount = function _addRefCount(value) {
19621
+ var _this__atlas;
19622
+ RefObject.prototype._addRefCount.call(this, value);
19623
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
19624
+ };
19625
+ /**
19626
+ * @override
19627
+ * @internal
19516
19628
  */ _proto._onDestroy = function _onDestroy() {
19517
- if (this._texture) {
19518
- this._texture = null;
19519
- }
19629
+ this._positions.length = 0;
19630
+ this._positions = null;
19631
+ this._uvs.length = 0;
19632
+ this._uvs = null;
19633
+ this._atlasRegion = null;
19634
+ this._atlasRegionOffset = null;
19635
+ this._region = null;
19636
+ this._pivot = null;
19637
+ this._border = null;
19638
+ this._bounds = null;
19639
+ this._atlas = null;
19640
+ this._texture = null;
19641
+ this._updateFlagManager = null;
19520
19642
  };
19521
19643
  _proto._calDefaultSize = function _calDefaultSize() {
19522
19644
  if (this._texture) {
@@ -19619,7 +19741,7 @@ exports.TextVerticalAlignment = void 0;
19619
19741
  key: "width",
19620
19742
  get: /**
19621
19743
  * The width of the sprite (in world coordinates).
19622
- *
19744
+ *
19623
19745
  * @remarks
19624
19746
  * If width is set, return the set value,
19625
19747
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19642,7 +19764,7 @@ exports.TextVerticalAlignment = void 0;
19642
19764
  key: "height",
19643
19765
  get: /**
19644
19766
  * The height of the sprite (in world coordinates).
19645
- *
19767
+ *
19646
19768
  * @remarks
19647
19769
  * If height is set, return the set value,
19648
19770
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -19950,17 +20072,6 @@ SlicedSpriteAssembler = __decorate([
19950
20072
  target.drawMode = this._drawMode;
19951
20073
  };
19952
20074
  /**
19953
- * @internal
19954
- */ _proto._onDestroy = function _onDestroy() {
19955
- var _this__sprite;
19956
- (_this__sprite = this._sprite) == null ? void 0 : _this__sprite._updateFlagManager.removeListener(this._onSpriteChange);
19957
- this._color = null;
19958
- this._sprite = null;
19959
- this._assembler = null;
19960
- this._renderData = null;
19961
- Renderer.prototype._onDestroy.call(this);
19962
- };
19963
- /**
19964
20075
  * @override
19965
20076
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
19966
20077
  if (this.sprite) {
@@ -19998,6 +20109,20 @@ SlicedSpriteAssembler = __decorate([
19998
20109
  context.camera._renderPipeline.pushPrimitive(spriteElement);
19999
20110
  }
20000
20111
  };
20112
+ /**
20113
+ * @internal
20114
+ */ _proto._onDestroy = function _onDestroy() {
20115
+ Renderer.prototype._onDestroy.call(this);
20116
+ var sprite = this._sprite;
20117
+ if (sprite) {
20118
+ sprite._addRefCount(-1);
20119
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
20120
+ }
20121
+ this._color = null;
20122
+ this._sprite = null;
20123
+ this._assembler = null;
20124
+ this._renderData = null;
20125
+ };
20001
20126
  _proto._calDefaultSize = function _calDefaultSize() {
20002
20127
  var sprite = this._sprite;
20003
20128
  if (sprite) {
@@ -20089,9 +20214,13 @@ SlicedSpriteAssembler = __decorate([
20089
20214
  set: function set(value) {
20090
20215
  var lastSprite = this._sprite;
20091
20216
  if (lastSprite !== value) {
20092
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20217
+ if (lastSprite) {
20218
+ lastSprite._addRefCount(-1);
20219
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
20220
+ }
20093
20221
  this._dirtyUpdateFlag |= 0x7;
20094
20222
  if (value) {
20223
+ value._addRefCount(1);
20095
20224
  value._updateFlagManager.addListener(this._onSpriteChange);
20096
20225
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
20097
20226
  } else {