@galacean/engine 0.9.11 → 0.9.12

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
  };
@@ -13413,6 +13423,7 @@
13413
13423
  _proto.cloneTo = function cloneTo(target) {
13414
13424
  CloneManager.deepCloneObject(this._macroCollection, target._macroCollection);
13415
13425
  Object.assign(target._macroMap, this._macroMap);
13426
+ var referCount = target._getRefCount();
13416
13427
  var propertyValueMap = this._propertyValueMap;
13417
13428
  var targetPropertyValueMap = target._propertyValueMap;
13418
13429
  var keys = Object.keys(propertyValueMap);
@@ -13424,6 +13435,7 @@
13424
13435
  targetPropertyValueMap[k] = property;
13425
13436
  } else if (_instanceof1$2(property, Texture)) {
13426
13437
  targetPropertyValueMap[k] = property;
13438
+ referCount > 0 && property._addRefCount(referCount);
13427
13439
  } else if (_instanceof1$2(property, Array) || _instanceof1$2(property, Float32Array) || _instanceof1$2(property, Int32Array)) {
13428
13440
  targetPropertyValueMap[k] = property.slice();
13429
13441
  } else {
@@ -15140,16 +15152,6 @@
15140
15152
  }
15141
15153
  var _proto = SpriteMask.prototype;
15142
15154
  /**
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
15155
  * @internal
15154
15156
  */ _proto._cloneTo = function _cloneTo(target) {
15155
15157
  Renderer.prototype._cloneTo.call(this, target);
@@ -15189,6 +15191,19 @@
15189
15191
  context.camera._renderPipeline._allSpriteMasks.add(this);
15190
15192
  this._maskElement = maskElement;
15191
15193
  };
15194
+ /**
15195
+ * @internal
15196
+ * @inheritdoc
15197
+ */ _proto._onDestroy = function _onDestroy() {
15198
+ Renderer.prototype._onDestroy.call(this);
15199
+ var sprite = this._sprite;
15200
+ if (sprite) {
15201
+ sprite._addRefCount(-1);
15202
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
15203
+ }
15204
+ this._sprite = null;
15205
+ this._renderData = null;
15206
+ };
15192
15207
  _proto._calDefaultSize = function _calDefaultSize() {
15193
15208
  var sprite = this._sprite;
15194
15209
  if (sprite) {
@@ -15307,9 +15322,13 @@
15307
15322
  set: function set(value) {
15308
15323
  var lastSprite = this._sprite;
15309
15324
  if (lastSprite !== value) {
15310
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
15325
+ if (lastSprite) {
15326
+ lastSprite._addRefCount(-1);
15327
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
15328
+ }
15311
15329
  this._dirtyUpdateFlag |= 0x7;
15312
15330
  if (value) {
15331
+ value._addRefCount(1);
15313
15332
  value._updateFlagManager.addListener(this._onSpriteChange);
15314
15333
  this.shaderData.setTexture(SpriteMask._textureProperty, value.texture);
15315
15334
  } else {
@@ -15864,10 +15883,11 @@
15864
15883
  /**
15865
15884
  * @internal
15866
15885
  */ _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);
15886
+ var referCount = this._getRefCount();
15887
+ if (referCount > 0) {
15888
+ var _this__vertexBufferBindings_index;
15889
+ (_this__vertexBufferBindings_index = this._vertexBufferBindings[index]) == null ? void 0 : _this__vertexBufferBindings_index._buffer._addRefCount(-referCount);
15890
+ binding == null ? void 0 : binding._buffer._addRefCount(referCount);
15871
15891
  }
15872
15892
  this._vertexBufferBindings[index] = binding;
15873
15893
  this._bufferStructChanged = true;
@@ -15881,11 +15901,13 @@
15881
15901
  /**
15882
15902
  * @override
15883
15903
  */ _proto._addRefCount = function _addRefCount(value) {
15904
+ var _this__indexBufferBinding;
15884
15905
  RefObject.prototype._addRefCount.call(this, value);
15885
15906
  var vertexBufferBindings = this._vertexBufferBindings;
15886
15907
  for(var i = 0, n = vertexBufferBindings.length; i < n; i++){
15887
15908
  vertexBufferBindings[i]._buffer._addRefCount(value);
15888
15909
  }
15910
+ (_this__indexBufferBinding = this._indexBufferBinding) == null ? void 0 : _this__indexBufferBinding._buffer._addRefCount(value);
15889
15911
  };
15890
15912
  /**
15891
15913
  * @override
@@ -15905,6 +15927,11 @@
15905
15927
  };
15906
15928
  _proto._setIndexBufferBinding = function _setIndexBufferBinding(binding) {
15907
15929
  var lastBinding = this._indexBufferBinding;
15930
+ var referCount = this._getRefCount();
15931
+ if (referCount > 0) {
15932
+ lastBinding == null ? void 0 : lastBinding.buffer._addRefCount(-referCount);
15933
+ binding == null ? void 0 : binding.buffer._addRefCount(referCount);
15934
+ }
15908
15935
  if (binding) {
15909
15936
  this._indexBufferBinding = binding;
15910
15937
  this._glIndexType = BufferUtil._getGLIndexType(binding.format);
@@ -19064,14 +19091,17 @@
19064
19091
  _proto._createMesh = function _createMesh(engine, index) {
19065
19092
  var MAX_VERTEX_COUNT = Basic2DBatcher.MAX_VERTEX_COUNT;
19066
19093
  var mesh = new BufferMesh(engine, "BufferMesh" + index);
19094
+ mesh.isGCIgnored = true;
19067
19095
  var vertexElements = [];
19068
19096
  var vertexStride = this.createVertexElements(vertexElements);
19069
19097
  // vertices
19070
- this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
19098
+ var vertexBuffer = this._vertexBuffers[index] = new Buffer(engine, exports.BufferBindFlag.VertexBuffer, MAX_VERTEX_COUNT * 4 * vertexStride, exports.BufferUsage.Dynamic);
19099
+ vertexBuffer.isGCIgnored = true;
19071
19100
  // 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);
19101
+ var indiceBuffer = this._indiceBuffers[index] = new Buffer(engine, exports.BufferBindFlag.IndexBuffer, MAX_VERTEX_COUNT * 2 * 3, exports.BufferUsage.Dynamic);
19102
+ indiceBuffer.isGCIgnored = true;
19103
+ mesh.setVertexBufferBinding(vertexBuffer, vertexStride);
19104
+ mesh.setIndexBufferBinding(indiceBuffer, exports.IndexFormat.UInt16);
19075
19105
  mesh.setVertexElements(vertexElements);
19076
19106
  return mesh;
19077
19107
  };
@@ -19304,6 +19334,12 @@
19304
19334
  var _proto = Sky.prototype;
19305
19335
  /**
19306
19336
  * @internal
19337
+ */ _proto.destroy = function destroy() {
19338
+ this.mesh = null;
19339
+ this.material = null;
19340
+ };
19341
+ /**
19342
+ * @internal
19307
19343
  */ _proto._render = function _render(context) {
19308
19344
  var _this = this, material = _this.material, mesh = _this.mesh;
19309
19345
  if (!material) {
@@ -19342,6 +19378,40 @@
19342
19378
  rhi.drawPrimitive(mesh, mesh.subMesh, program);
19343
19379
  cameraShaderData.setMatrix(RenderContext._vpMatrixProperty, originViewProjMatrix);
19344
19380
  };
19381
+ _create_class$3(Sky, [
19382
+ {
19383
+ key: "material",
19384
+ get: /**
19385
+ * Material of the sky.
19386
+ */ function get() {
19387
+ return this._material;
19388
+ },
19389
+ set: function set(value) {
19390
+ if (this._material !== value) {
19391
+ var _this__material;
19392
+ value == null ? void 0 : value._addRefCount(1);
19393
+ (_this__material = this._material) == null ? void 0 : _this__material._addRefCount(-1);
19394
+ this._material = value;
19395
+ }
19396
+ }
19397
+ },
19398
+ {
19399
+ key: "mesh",
19400
+ get: /**
19401
+ * Mesh of the sky.
19402
+ */ function get() {
19403
+ return this._mesh;
19404
+ },
19405
+ set: function set(value) {
19406
+ if (this._mesh !== value) {
19407
+ var _this__mesh;
19408
+ value == null ? void 0 : value._addRefCount(1);
19409
+ (_this__mesh = this._mesh) == null ? void 0 : _this__mesh._addRefCount(-1);
19410
+ this._mesh = value;
19411
+ }
19412
+ }
19413
+ }
19414
+ ]);
19345
19415
  return Sky;
19346
19416
  }();
19347
19417
  (function() {
@@ -19371,11 +19441,28 @@
19371
19441
  this.sky = new Sky();
19372
19442
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
19373
19443
  this._texture = null;
19374
- this._mesh = this._createPlane(_engine);
19444
+ this._initMesh(_engine);
19375
19445
  };
19376
19446
  var _proto = Background.prototype;
19377
19447
  /**
19378
19448
  * @internal
19449
+ */ _proto.destroy = function destroy() {
19450
+ this._mesh._addRefCount(-1);
19451
+ this._mesh = null;
19452
+ this.texture = null;
19453
+ this.solidColor = null;
19454
+ this.sky.destroy();
19455
+ this._engine = null;
19456
+ };
19457
+ /**
19458
+ * @internal
19459
+ * Standalone for CanvasRenderer plugin.
19460
+ */ _proto._initMesh = function _initMesh(engine) {
19461
+ this._mesh = this._createPlane(engine);
19462
+ this._mesh._addRefCount(1);
19463
+ };
19464
+ /**
19465
+ * @internal
19379
19466
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
19380
19467
  if (!this._texture) {
19381
19468
  return;
@@ -19444,6 +19531,9 @@
19444
19531
  },
19445
19532
  set: function set(value) {
19446
19533
  if (this._texture !== value) {
19534
+ var _this__texture;
19535
+ value == null ? void 0 : value._addRefCount(1);
19536
+ (_this__texture = this._texture) == null ? void 0 : _this__texture._addRefCount(-1);
19447
19537
  this._texture = value;
19448
19538
  this._engine._backgroundTextureMaterial.shaderData.setTexture("u_baseTexture", value);
19449
19539
  }
@@ -19943,6 +20033,7 @@
19943
20033
  this._rootEntities[0].destroy();
19944
20034
  }
19945
20035
  this._activeCameras.length = 0;
20036
+ this.background.destroy();
19946
20037
  this.shaderData._addRefCount(-1);
19947
20038
  };
19948
20039
  _proto._addToRootEntityList = function _addToRootEntityList(index, rootEntity) {
@@ -20333,7 +20424,7 @@
20333
20424
  _this._spriteDefaultMaterial = _this._createSpriteMaterial();
20334
20425
  _this._spriteMaskDefaultMaterial = _this._createSpriteMaskMaterial();
20335
20426
  _this._textDefaultFont = Font.createFromOS(_assert_this_initialized(_this), "Arial");
20336
- _this._textDefaultFont.isGCIgnored = false;
20427
+ _this._textDefaultFont.isGCIgnored = true;
20337
20428
  _this.inputManager = new InputManager(_assert_this_initialized(_this));
20338
20429
  var magentaPixel = new Uint8Array([
20339
20430
  255,
@@ -20368,6 +20459,7 @@
20368
20459
  _this._magentaTexture2DArray = magentaTexture2DArray;
20369
20460
  }
20370
20461
  var magentaMaterial = new Material(_assert_this_initialized(_this), Shader.find("unlit"));
20462
+ magentaMaterial.isGCIgnored = true;
20371
20463
  magentaMaterial.shaderData.setColor("u_baseColor", new Color(1.0, 0.0, 1.01, 1.0));
20372
20464
  _this._magentaMaterial = magentaMaterial;
20373
20465
  var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
@@ -21893,7 +21985,11 @@
21893
21985
  var height = shadowCascades == exports.ShadowCascadesMode.TwoCascades ? shadowTileResolution : shadowTileResolution * 2;
21894
21986
  this._shadowMapSize.set(1.0 / width, 1.0 / height, width, height);
21895
21987
  }
21896
- this._renderTargets = null;
21988
+ var renderTargets = this._renderTargets;
21989
+ if (renderTargets) {
21990
+ renderTargets.destroy();
21991
+ this._renderTargets = null;
21992
+ }
21897
21993
  var viewportOffset = this._viewportOffsets;
21898
21994
  var shadowTileResolution1 = this._shadowTileResolution;
21899
21995
  switch(shadowCascades){
@@ -23915,10 +24011,17 @@
23915
24011
  * @internal
23916
24012
  */ _proto._addSprite = function _addSprite(sprite) {
23917
24013
  this._spriteNamesToIndex[sprite.name] = this._sprites.push(sprite) - 1;
24014
+ sprite._atlas = this;
24015
+ sprite.isGCIgnored = true;
23918
24016
  };
23919
24017
  /**
23920
24018
  * @override
23921
24019
  */ _proto._onDestroy = function _onDestroy() {
24020
+ var _this = this, sprites = _this._sprites;
24021
+ for(var i = 0, n = sprites.length; i < n; i++){
24022
+ sprites[i].destroy();
24023
+ }
24024
+ sprites.length = 0;
23922
24025
  this._sprites = null;
23923
24026
  this._spriteNamesToIndex = null;
23924
24027
  };
@@ -24017,10 +24120,29 @@
24017
24120
  };
24018
24121
  /**
24019
24122
  * @override
24123
+ * @internal
24124
+ */ _proto._addRefCount = function _addRefCount(value) {
24125
+ var _this__atlas;
24126
+ RefObject.prototype._addRefCount.call(this, value);
24127
+ (_this__atlas = this._atlas) == null ? void 0 : _this__atlas._addRefCount(value);
24128
+ };
24129
+ /**
24130
+ * @override
24131
+ * @internal
24020
24132
  */ _proto._onDestroy = function _onDestroy() {
24021
- if (this._texture) {
24022
- this._texture = null;
24023
- }
24133
+ this._positions.length = 0;
24134
+ this._positions = null;
24135
+ this._uvs.length = 0;
24136
+ this._uvs = null;
24137
+ this._atlasRegion = null;
24138
+ this._atlasRegionOffset = null;
24139
+ this._region = null;
24140
+ this._pivot = null;
24141
+ this._border = null;
24142
+ this._bounds = null;
24143
+ this._atlas = null;
24144
+ this._texture = null;
24145
+ this._updateFlagManager = null;
24024
24146
  };
24025
24147
  _proto._calDefaultSize = function _calDefaultSize() {
24026
24148
  if (this._texture) {
@@ -24123,7 +24245,7 @@
24123
24245
  key: "width",
24124
24246
  get: /**
24125
24247
  * The width of the sprite (in world coordinates).
24126
- *
24248
+ *
24127
24249
  * @remarks
24128
24250
  * If width is set, return the set value,
24129
24251
  * otherwise return the width calculated according to `Texture.width`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -24146,7 +24268,7 @@
24146
24268
  key: "height",
24147
24269
  get: /**
24148
24270
  * The height of the sprite (in world coordinates).
24149
- *
24271
+ *
24150
24272
  * @remarks
24151
24273
  * If height is set, return the set value,
24152
24274
  * otherwise return the height calculated according to `Texture.height`, `Sprite.region`, `Sprite.atlasRegion`, `Sprite.atlasRegionOffset` and `Engine._pixelsPerUnit`.
@@ -24452,17 +24574,6 @@
24452
24574
  target.drawMode = this._drawMode;
24453
24575
  };
24454
24576
  /**
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
24577
  * @override
24467
24578
  */ _proto._updateBounds = function _updateBounds(worldBounds) {
24468
24579
  if (this.sprite) {
@@ -24500,6 +24611,20 @@
24500
24611
  context.camera._renderPipeline.pushPrimitive(spriteElement);
24501
24612
  }
24502
24613
  };
24614
+ /**
24615
+ * @internal
24616
+ */ _proto._onDestroy = function _onDestroy() {
24617
+ Renderer.prototype._onDestroy.call(this);
24618
+ var sprite = this._sprite;
24619
+ if (sprite) {
24620
+ sprite._addRefCount(-1);
24621
+ sprite._updateFlagManager.removeListener(this._onSpriteChange);
24622
+ }
24623
+ this._color = null;
24624
+ this._sprite = null;
24625
+ this._assembler = null;
24626
+ this._renderData = null;
24627
+ };
24503
24628
  _proto._calDefaultSize = function _calDefaultSize() {
24504
24629
  var sprite = this._sprite;
24505
24630
  if (sprite) {
@@ -24591,9 +24716,13 @@
24591
24716
  set: function set(value) {
24592
24717
  var lastSprite = this._sprite;
24593
24718
  if (lastSprite !== value) {
24594
- lastSprite && lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
24719
+ if (lastSprite) {
24720
+ lastSprite._addRefCount(-1);
24721
+ lastSprite._updateFlagManager.removeListener(this._onSpriteChange);
24722
+ }
24595
24723
  this._dirtyUpdateFlag |= 0x7;
24596
24724
  if (value) {
24725
+ value._addRefCount(1);
24597
24726
  value._updateFlagManager.addListener(this._onSpriteChange);
24598
24727
  this.shaderData.setTexture(SpriteRenderer._textureProperty, value.texture);
24599
24728
  } else {
@@ -36010,7 +36139,7 @@
36010
36139
  }));
36011
36140
 
36012
36141
  //@ts-ignore
36013
- var version = "0.9.11";
36142
+ var version = "0.9.12";
36014
36143
  console.log("Galacean engine version: " + version);
36015
36144
  for(var key in CoreObjects){
36016
36145
  Loader.registerClass(key, CoreObjects[key]);