@galacean/engine-core 1.1.0-beta.4 → 1.1.0-beta.6

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
@@ -2541,8 +2541,8 @@ var ActiveChangeFlag;
2541
2541
  var _this;
2542
2542
  _this = EngineObject1.call(this, entity.engine) || this;
2543
2543
  /** @internal */ _this._awoken = false;
2544
- _this._phasedActive = false;
2545
2544
  _this._phasedActiveInScene = false;
2545
+ _this._phasedActive = false;
2546
2546
  _this._enabled = true;
2547
2547
  _this._entity = entity;
2548
2548
  return _this;
@@ -2674,10 +2674,10 @@ __decorate([
2674
2674
  ], Component.prototype, "_awoken", void 0);
2675
2675
  __decorate([
2676
2676
  ignoreClone
2677
- ], Component.prototype, "_phasedActive", void 0);
2677
+ ], Component.prototype, "_phasedActiveInScene", void 0);
2678
2678
  __decorate([
2679
2679
  ignoreClone
2680
- ], Component.prototype, "_phasedActiveInScene", void 0);
2680
+ ], Component.prototype, "_phasedActive", void 0);
2681
2681
  __decorate([
2682
2682
  assignmentClone
2683
2683
  ], Component.prototype, "_enabled", void 0);
@@ -12591,16 +12591,31 @@ var SafeLoopArray = /*#__PURE__*/ function() {
12591
12591
  }
12592
12592
  var _proto = SceneManager.prototype;
12593
12593
  _proto.addScene = function addScene(indexOrScene, scene) {
12594
+ var scenes = this._scenes;
12595
+ var index;
12594
12596
  if (typeof indexOrScene === "number") {
12595
- this._scenes.add(indexOrScene, scene);
12597
+ if (indexOrScene < 0 || indexOrScene > scenes.length) {
12598
+ throw "The index is out of range.";
12599
+ }
12600
+ index = indexOrScene;
12596
12601
  } else {
12602
+ index = scenes.length;
12597
12603
  scene = indexOrScene;
12598
- this._scenes.push(scene);
12599
12604
  }
12600
12605
  if (scene.engine !== this.engine) {
12601
12606
  throw "The scene is not belong to this engine.";
12602
12607
  }
12603
- scene._processActive(true);
12608
+ if (scene._sceneManager) {
12609
+ var currentIndex = scenes.indexOf(scene);
12610
+ if (currentIndex !== index) {
12611
+ scenes.removeByIndex(currentIndex);
12612
+ scenes.add(index, scene);
12613
+ }
12614
+ } else {
12615
+ scene._sceneManager = this;
12616
+ scenes.add(index, scene);
12617
+ scene.isActive && scene._processActive(true);
12618
+ }
12604
12619
  };
12605
12620
  /**
12606
12621
  * Remove scene.
@@ -12611,7 +12626,8 @@ var SafeLoopArray = /*#__PURE__*/ function() {
12611
12626
  if (index !== -1) {
12612
12627
  var removedScene = scenes.getArray()[index];
12613
12628
  scenes.removeByIndex(index);
12614
- removedScene._processActive(false);
12629
+ scene._sceneManager = null;
12630
+ removedScene.isActive && removedScene._processActive(false);
12615
12631
  }
12616
12632
  };
12617
12633
  /**
@@ -13815,9 +13831,9 @@ exports.Collider = /*#__PURE__*/ function(Component1) {
13815
13831
  oldCollider.removeShape(shape);
13816
13832
  }
13817
13833
  this._shapes.push(shape);
13818
- this.scene.physics._addColliderShape(shape);
13819
13834
  shape._collider = this;
13820
13835
  this._nativeCollider.addShape(shape._nativeShape);
13836
+ this._phasedActiveInScene && this.scene.physics._addColliderShape(shape);
13821
13837
  }
13822
13838
  };
13823
13839
  /**
@@ -13827,7 +13843,7 @@ exports.Collider = /*#__PURE__*/ function(Component1) {
13827
13843
  var index = this._shapes.indexOf(shape);
13828
13844
  if (index !== -1) {
13829
13845
  this._shapes.splice(index, 1);
13830
- this.scene.physics._removeColliderShape(shape);
13846
+ this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
13831
13847
  shape._collider = null;
13832
13848
  this._nativeCollider.removeShape(shape._nativeShape);
13833
13849
  }
@@ -13838,7 +13854,7 @@ exports.Collider = /*#__PURE__*/ function(Component1) {
13838
13854
  var shapes = this._shapes;
13839
13855
  for(var i = 0, n = shapes.length; i < n; i++){
13840
13856
  var shape = shapes[i];
13841
- this.scene.physics._removeColliderShape(shape);
13857
+ this._phasedActiveInScene && this.scene.physics._removeColliderShape(shape);
13842
13858
  shape._destroy();
13843
13859
  this._nativeCollider.removeShape(shape._nativeShape);
13844
13860
  }
@@ -13863,12 +13879,22 @@ exports.Collider = /*#__PURE__*/ function(Component1) {
13863
13879
  /**
13864
13880
  * @internal
13865
13881
  */ _proto._onEnableInScene = function _onEnableInScene() {
13866
- this.scene.physics._addCollider(this);
13882
+ var physics = this.scene.physics;
13883
+ physics._addCollider(this);
13884
+ var shapes = this.shapes;
13885
+ for(var i = 0, n = shapes.length; i < n; i++){
13886
+ physics._addColliderShape(shapes[i]);
13887
+ }
13867
13888
  };
13868
13889
  /**
13869
13890
  * @internal
13870
13891
  */ _proto._onDisableInScene = function _onDisableInScene() {
13871
- this.scene.physics._removeCollider(this);
13892
+ var physics = this.scene.physics;
13893
+ physics._removeCollider(this);
13894
+ var shapes = this.shapes;
13895
+ for(var i = 0, n = shapes.length; i < n; i++){
13896
+ physics._removeColliderShape(shapes[i]);
13897
+ }
13872
13898
  };
13873
13899
  /**
13874
13900
  * @internal
@@ -14246,12 +14272,22 @@ var Collision = function Collision() {
14246
14272
  /**
14247
14273
  * @internal
14248
14274
  */ _proto._onEnableInScene = function _onEnableInScene() {
14249
- this.scene.physics._addCharacterController(this);
14275
+ var physics = this.scene.physics;
14276
+ physics._addCharacterController(this);
14277
+ var shapes = this.shapes;
14278
+ for(var i = 0, n = shapes.length; i < n; i++){
14279
+ physics._addColliderShape(shapes[i]);
14280
+ }
14250
14281
  };
14251
14282
  /**
14252
14283
  * @internal
14253
14284
  */ _proto._onDisableInScene = function _onDisableInScene() {
14254
- this.scene.physics._removeCharacterController(this);
14285
+ var physics = this.scene.physics;
14286
+ physics._removeCharacterController(this);
14287
+ var shapes = this.shapes;
14288
+ for(var i = 0, n = shapes.length; i < n; i++){
14289
+ physics._removeColliderShape(shapes[i]);
14290
+ }
14255
14291
  };
14256
14292
  _proto._setUpDirection = function _setUpDirection() {
14257
14293
  this._nativeCollider.setUpDirection(this._upDirection);
@@ -15710,8 +15746,8 @@ exports.Joint = __decorate([
15710
15746
  continue;
15711
15747
  }
15712
15748
  var cameras = scene._activeCameras;
15713
- for(var j = 0; j < cameras.length; j++){
15714
- var camera = cameras[i];
15749
+ for(var j = cameras.length - 1; j >= 0; j--){
15750
+ var camera = cameras[j];
15715
15751
  if (!camera.enabled || camera.renderTarget) {
15716
15752
  continue;
15717
15753
  }
@@ -16403,10 +16439,6 @@ ShaderPool.init();
16403
16439
  magentaMaterial.isGCIgnored = true;
16404
16440
  magentaMaterial.shaderData.setColor("material_BaseColor", new Color(1.0, 0.0, 1.01, 1.0));
16405
16441
  _this._magentaMaterial = magentaMaterial;
16406
- var backgroundTextureMaterial = new Material(_assert_this_initialized(_this), Shader.find("background-texture"));
16407
- backgroundTextureMaterial.isGCIgnored = true;
16408
- backgroundTextureMaterial.renderState.depthState.compareFunction = exports.CompareFunction.LessEqual;
16409
- _this._backgroundTextureMaterial = backgroundTextureMaterial;
16410
16442
  var innerSettings = _this._settings;
16411
16443
  var colorSpace = configuration.colorSpace || exports.ColorSpace.Linear;
16412
16444
  colorSpace === exports.ColorSpace.Gamma && _this._macroCollection.enable(Engine._gammaMacro);
@@ -17024,26 +17056,22 @@ ShaderPool.init();
17024
17056
  this./** @internal */ _textureFillMode = exports.BackgroundTextureFillMode.AspectFitHeight;
17025
17057
  this._texture = null;
17026
17058
  this._initMesh(_engine);
17059
+ this._initMaterial(_engine);
17027
17060
  }
17028
17061
  var _proto = Background.prototype;
17029
17062
  /**
17030
17063
  * @internal
17031
17064
  */ _proto.destroy = function destroy() {
17065
+ this.texture = null;
17032
17066
  this._mesh._addReferCount(-1);
17033
17067
  this._mesh = null;
17034
- this.texture = null;
17068
+ this._material._addReferCount(-1);
17069
+ this._material = null;
17035
17070
  this.solidColor = null;
17036
17071
  this.sky.destroy();
17037
17072
  };
17038
17073
  /**
17039
17074
  * @internal
17040
- * Standalone for CanvasRenderer plugin.
17041
- */ _proto._initMesh = function _initMesh(engine) {
17042
- this._mesh = this._createPlane(engine);
17043
- this._mesh._addReferCount(1);
17044
- };
17045
- /**
17046
- * @internal
17047
17075
  */ _proto._resizeBackgroundTexture = function _resizeBackgroundTexture() {
17048
17076
  if (!this._texture) {
17049
17077
  return;
@@ -17077,6 +17105,15 @@ ShaderPool.init();
17077
17105
  _backgroundTextureMesh.setPositions(positions);
17078
17106
  _backgroundTextureMesh.uploadData(false);
17079
17107
  };
17108
+ _proto._initMesh = function _initMesh(engine) {
17109
+ this._mesh = this._createPlane(engine);
17110
+ this._mesh._addReferCount(1);
17111
+ };
17112
+ _proto._initMaterial = function _initMaterial(engine) {
17113
+ var material = this._material = new Material(engine, Shader.find("background-texture"));
17114
+ material.renderState.depthState.compareFunction = exports.CompareFunction.LessEqual;
17115
+ material._addReferCount(1);
17116
+ };
17080
17117
  _proto._createPlane = function _createPlane(engine) {
17081
17118
  var mesh = new ModelMesh(engine);
17082
17119
  mesh.isGCIgnored = true;
@@ -17116,7 +17153,7 @@ ShaderPool.init();
17116
17153
  (_value = value) == null ? void 0 : _value._addReferCount(1);
17117
17154
  (_this__texture = this._texture) == null ? void 0 : _this__texture._addReferCount(-1);
17118
17155
  this._texture = value;
17119
- this._engine._backgroundTextureMaterial.shaderData.setTexture("material_BaseTexture", value);
17156
+ this._material.shaderData.setTexture("material_BaseTexture", value);
17120
17157
  }
17121
17158
  }
17122
17159
  },
@@ -17274,7 +17311,7 @@ ShaderPool.init();
17274
17311
  var _this = this, pendingDestroyScripts = _this._disposeDestroyScripts, disposeDestroyScripts = _this._pendingDestroyScripts;
17275
17312
  this._disposeDestroyScripts = disposeDestroyScripts;
17276
17313
  this._pendingDestroyScripts = pendingDestroyScripts;
17277
- length = disposeDestroyScripts.length;
17314
+ var length = disposeDestroyScripts.length;
17278
17315
  if (length > 0) {
17279
17316
  for(var i = length - 1; i >= 0; i--){
17280
17317
  disposeDestroyScripts[i].onDestroy();
@@ -18196,6 +18233,7 @@ __decorate([
18196
18233
  _this._fogEnd = 300;
18197
18234
  _this._fogDensity = 0.01;
18198
18235
  _this._fogParams = new engineMath.Vector4();
18236
+ _this._isActive = true;
18199
18237
  _this.name = name || "";
18200
18238
  var shaderData = _this.shaderData;
18201
18239
  shaderData._addReferCount(1);
@@ -18443,6 +18481,24 @@ __decorate([
18443
18481
  this._fogParams.w = density / Math.sqrt(Math.LN2);
18444
18482
  };
18445
18483
  _create_class(Scene, [
18484
+ {
18485
+ key: "isActive",
18486
+ get: /**
18487
+ * Whether the scene is active.
18488
+ */ function get() {
18489
+ return this._isActive;
18490
+ },
18491
+ set: function set(value) {
18492
+ if (this._isActive !== value) {
18493
+ this._isActive = value;
18494
+ if (value) {
18495
+ this._sceneManager && this._processActive(true);
18496
+ } else {
18497
+ this._sceneManager && this._processActive(false);
18498
+ }
18499
+ }
18500
+ }
18501
+ },
18446
18502
  {
18447
18503
  key: "shaderData",
18448
18504
  get: /**
@@ -18761,7 +18817,11 @@ __decorate([
18761
18817
  * @internal
18762
18818
  */ _proto._onDestroy = function _onDestroy() {
18763
18819
  Component1.prototype._onDestroy.call(this);
18764
- this.scene._componentsManager.addPendingDestroyScript(this);
18820
+ if (this.scene) {
18821
+ this.scene._componentsManager.addPendingDestroyScript(this);
18822
+ } else {
18823
+ this.onDestroy();
18824
+ }
18765
18825
  };
18766
18826
  return Script;
18767
18827
  }(Component);
@@ -20311,8 +20371,8 @@ var /**
20311
20371
  };
20312
20372
  _proto._drawBackgroundTexture = function _drawBackgroundTexture(engine, background) {
20313
20373
  var rhi = engine._hardwareRenderer;
20314
- var material = engine._backgroundTextureMaterial, canvas = engine.canvas;
20315
- var mesh = background._mesh;
20374
+ var canvas = engine.canvas;
20375
+ var material = background._material, mesh = background._mesh;
20316
20376
  if ((this._lastCanvasSize.x !== canvas.width || this._lastCanvasSize.y !== canvas.height) && background._textureFillMode !== exports.BackgroundTextureFillMode.Fill) {
20317
20377
  this._lastCanvasSize.set(canvas.width, canvas.height);
20318
20378
  background._resizeBackgroundTexture();
@@ -20487,7 +20547,7 @@ exports.Camera = (_Camera = /*#__PURE__*/ function(Component1) {
20487
20547
  // Use the intersection of the near clipping plane as the origin point.
20488
20548
  var origin = this._innerViewportToWorldPoint(point.x, point.y, 0.0, invViewProjMat, out.origin);
20489
20549
  // Use the intersection of the far clipping plane as the origin point.
20490
- var direction = this._innerViewportToWorldPoint(point.x, point.y, 1.0, invViewProjMat, out.direction);
20550
+ var direction = this._innerViewportToWorldPoint(point.x, point.y, 1 - engineMath.MathUtil.zeroTolerance, invViewProjMat, out.direction);
20491
20551
  engineMath.Vector3.subtract(direction, origin, direction);
20492
20552
  direction.normalize();
20493
20553
  return out;
@@ -26971,64 +27031,203 @@ exports.SunMode = void 0;
26971
27031
  SkyProceduralMaterial._sunSimpleMacro = ShaderMacro.getByName("MATERIAL_SUN_SIMPLE");
26972
27032
  })();
26973
27033
 
27034
+ var SubPrimitive = function SubPrimitive() {
27035
+ };
27036
+
26974
27037
  /**
26975
- * Particle Material.
26976
- */ var ParticleMaterial = /*#__PURE__*/ function(BaseMaterial1) {
26977
- _inherits(ParticleMaterial, BaseMaterial1);
26978
- function ParticleMaterial(engine) {
27038
+ * The rendering mode for particle renderer.
27039
+ */ exports.ParticleRenderMode = void 0;
27040
+ (function(ParticleRenderMode) {
27041
+ ParticleRenderMode[ParticleRenderMode[/** Render particles as billboards facing the active camera. */ "Billboard"] = 0] = "Billboard";
27042
+ ParticleRenderMode[ParticleRenderMode[/** Stretch particles in the direction of motion. */ "StretchBillboard"] = 1] = "StretchBillboard";
27043
+ ParticleRenderMode[ParticleRenderMode[/** Render particles as billboards always facing up along the y-Axis. */ "HorizontalBillboard"] = 2] = "HorizontalBillboard";
27044
+ ParticleRenderMode[ParticleRenderMode[/** Render particles as billboards always facing the player, but not pitching along the x-Axis. */ "VerticalBillboard"] = 3] = "VerticalBillboard";
27045
+ ParticleRenderMode[ParticleRenderMode[/** Render particles as meshes. */ "Mesh"] = 4] = "Mesh";
27046
+ ParticleRenderMode[ParticleRenderMode[/** Do not render particles. */ "None"] = 5] = "None";
27047
+ })(exports.ParticleRenderMode || (exports.ParticleRenderMode = {}));
27048
+
27049
+ exports.ParticleStopMode = void 0;
27050
+ (function(ParticleStopMode) {
27051
+ ParticleStopMode[ParticleStopMode[/** Stop emitting new particles and clear existing particles immediately. */ "StopEmittingAndClear"] = 0] = "StopEmittingAndClear";
27052
+ ParticleStopMode[ParticleStopMode[/** Stop emitting new particles, but keep existing particles until they expire. */ "StopEmitting"] = 1] = "StopEmitting";
27053
+ })(exports.ParticleStopMode || (exports.ParticleStopMode = {}));
27054
+
27055
+ /**
27056
+ * Particle Renderer Component.
27057
+ */ var ParticleRenderer = /*#__PURE__*/ function(Renderer1) {
27058
+ _inherits(ParticleRenderer, Renderer1);
27059
+ function ParticleRenderer(entity) {
26979
27060
  var _this;
26980
- _this = BaseMaterial1.call(this, engine, Shader.find("particle-shader")) || this;
26981
- var shaderData = _this.shaderData;
26982
- shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
26983
- shaderData.setColor(BaseMaterial._baseColorProp, new engineMath.Color(1, 1, 1, 1));
26984
- _this.isTransparent = true;
27061
+ _this = Renderer1.call(this, entity) || this;
27062
+ /** Particle generator. */ _this.generator = new ParticleGenerator(_assert_this_initialized(_this));
27063
+ /** Specifies how much particles stretch depending on their velocity. */ _this.velocityScale = 0;
27064
+ /** How much are the particles stretched in their direction of motion, defined as the length of the particle compared to its width. */ _this.lengthScale = 2;
27065
+ /** The pivot of particle. */ _this.pivot = new engineMath.Vector3();
27066
+ _this._currentRenderModeMacro = ParticleRenderer._billboardModeMacro;
27067
+ _this.shaderData.enableMacro(ParticleRenderer._billboardModeMacro);
27068
+ _this._supportInstancedArrays = _this.engine._hardwareRenderer.canIUse(exports.GLCapabilityType.instancedArrays);
26985
27069
  return _this;
26986
27070
  }
26987
- var _proto = ParticleMaterial.prototype;
27071
+ var _proto = ParticleRenderer.prototype;
26988
27072
  /**
26989
- * @inheritdoc
26990
- */ _proto.clone = function clone() {
26991
- var dest = new ParticleMaterial(this._engine);
26992
- this.cloneTo(dest);
26993
- return dest;
27073
+ * @internal
27074
+ */ _proto._onEnable = function _onEnable() {
27075
+ if (this.generator.main.playOnEnabled) {
27076
+ this.generator.play(false);
27077
+ }
26994
27078
  };
26995
- _create_class(ParticleMaterial, [
27079
+ /**
27080
+ * @internal
27081
+ */ _proto._onDisable = function _onDisable() {
27082
+ this.generator.stop(false, exports.ParticleStopMode.StopEmittingAndClear);
27083
+ };
27084
+ /**
27085
+ * @internal
27086
+ */ _proto._prepareRender = function _prepareRender(context) {
27087
+ if (!this._supportInstancedArrays) {
27088
+ return;
27089
+ }
27090
+ var generator = this.generator;
27091
+ generator._update(this.engine.time.deltaTime);
27092
+ // No particles to render
27093
+ if (generator._firstActiveElement === generator._firstFreeElement) {
27094
+ return;
27095
+ }
27096
+ Renderer1.prototype._prepareRender.call(this, context);
27097
+ };
27098
+ /**
27099
+ * @internal
27100
+ */ _proto._updateBounds = function _updateBounds(worldBounds) {
27101
+ worldBounds.min.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
27102
+ worldBounds.max.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
27103
+ };
27104
+ /**
27105
+ * @internal
27106
+ */ _proto._updateShaderData = function _updateShaderData(context) {
27107
+ var shaderData = this.shaderData;
27108
+ shaderData.setFloat(ParticleRenderer._lengthScale, this.lengthScale);
27109
+ shaderData.setFloat(ParticleRenderer._speedScale, this.velocityScale);
27110
+ shaderData.setFloat(ParticleRenderer._currentTime, this.generator._playTime);
27111
+ shaderData.setVector3(ParticleRenderer._pivotOffsetProperty, this.pivot);
27112
+ this.generator._updateShaderData(shaderData);
27113
+ };
27114
+ _proto._render = function _render(context) {
27115
+ var generator = this.generator;
27116
+ var primitive = generator._primitive;
27117
+ if (generator._firstActiveElement < generator._firstFreeElement) {
27118
+ primitive.instanceCount = generator._firstFreeElement - generator._firstActiveElement;
27119
+ } else {
27120
+ var instanceCount = generator._currentParticleCount - generator._firstActiveElement;
27121
+ if (generator._firstFreeElement > 0) {
27122
+ instanceCount += generator._firstFreeElement;
27123
+ }
27124
+ primitive.instanceCount = instanceCount;
27125
+ }
27126
+ var material = this.getMaterial();
27127
+ var renderData = this._engine._renderDataPool.getFromPool();
27128
+ renderData.setX(this, material, generator._primitive, generator._subPrimitive);
27129
+ context.camera._renderPipeline.pushRenderData(context, renderData);
27130
+ };
27131
+ _proto._onDestroy = function _onDestroy() {
27132
+ this.generator._destroy();
27133
+ };
27134
+ _create_class(ParticleRenderer, [
26996
27135
  {
26997
- key: "baseColor",
27136
+ key: "renderMode",
26998
27137
  get: /**
26999
- * Base color.
27138
+ * Specifies how particles are rendered.
27000
27139
  */ function get() {
27001
- return this.shaderData.getColor(BaseMaterial._baseColorProp);
27140
+ return this._renderMode;
27002
27141
  },
27003
27142
  set: function set(value) {
27004
- var baseColor = this.shaderData.getColor(BaseMaterial._baseColorProp);
27005
- if (value !== baseColor) {
27006
- baseColor.copyFrom(value);
27143
+ if (this._renderMode !== value) {
27144
+ var lastRenderMode = this._renderMode;
27145
+ this._renderMode = value;
27146
+ var renderModeMacro = null;
27147
+ var shaderData = this.shaderData;
27148
+ switch(value){
27149
+ case exports.ParticleRenderMode.Billboard:
27150
+ renderModeMacro = ParticleRenderer._billboardModeMacro;
27151
+ break;
27152
+ case exports.ParticleRenderMode.StretchBillboard:
27153
+ renderModeMacro = ParticleRenderer._stretchedBillboardModeMacro;
27154
+ break;
27155
+ case exports.ParticleRenderMode.HorizontalBillboard:
27156
+ throw "Not implemented";
27157
+ case exports.ParticleRenderMode.VerticalBillboard:
27158
+ throw "Not implemented";
27159
+ case exports.ParticleRenderMode.Mesh:
27160
+ throw "Not implemented";
27161
+ }
27162
+ if (this._currentRenderModeMacro !== renderModeMacro) {
27163
+ this._currentRenderModeMacro && shaderData.disableMacro(this._currentRenderModeMacro);
27164
+ renderModeMacro && shaderData.enableMacro(renderModeMacro);
27165
+ this._currentRenderModeMacro = renderModeMacro;
27166
+ }
27167
+ // @ts-ignore
27168
+ if (lastRenderMode !== exports.ParticleRenderMode.Mesh !== (value === exports.ParticleRenderMode.Mesh)) {
27169
+ this.generator._reorganizeGeometryBuffers();
27170
+ }
27007
27171
  }
27008
27172
  }
27009
27173
  },
27010
27174
  {
27011
- key: "baseTexture",
27175
+ key: "mesh",
27012
27176
  get: /**
27013
- * Base texture.
27177
+ * The mesh of particle.
27178
+ * @remarks Valid when `renderMode` is `Mesh`.
27014
27179
  */ function get() {
27015
- return this.shaderData.getTexture(BaseMaterial._baseTextureProp);
27180
+ return this._mesh;
27016
27181
  },
27017
27182
  set: function set(value) {
27018
- this.shaderData.setTexture(BaseMaterial._baseTextureProp, value);
27019
- if (value) {
27020
- this.shaderData.enableMacro(BaseMaterial._baseTextureMacro);
27021
- } else {
27022
- this.shaderData.disableMacro(BaseMaterial._baseTextureMacro);
27183
+ var lastMesh = this._mesh;
27184
+ if (lastMesh !== value) {
27185
+ var _lastMesh, _value;
27186
+ this._mesh = value;
27187
+ (_lastMesh = lastMesh) == null ? void 0 : _lastMesh._addReferCount(-1);
27188
+ (_value = value) == null ? void 0 : _value._addReferCount(1);
27189
+ if (this.renderMode === exports.ParticleRenderMode.Mesh) {
27190
+ this.generator._reorganizeGeometryBuffers();
27191
+ }
27023
27192
  }
27024
27193
  }
27025
27194
  }
27026
27195
  ]);
27027
- return ParticleMaterial;
27028
- }(BaseMaterial);
27029
-
27030
- var SubPrimitive = function SubPrimitive() {
27031
- };
27196
+ return ParticleRenderer;
27197
+ }(exports.Renderer);
27198
+ (function() {
27199
+ ParticleRenderer._billboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_SPHERE_BILLBOARD");
27200
+ })();
27201
+ (function() {
27202
+ ParticleRenderer._stretchedBillboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_STRETCHED_BILLBOARD");
27203
+ })();
27204
+ (function() {
27205
+ ParticleRenderer._horizontalBillboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_HORIZONTAL_BILLBOARD");
27206
+ })();
27207
+ (function() {
27208
+ ParticleRenderer._verticalBillboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_VERTICAL_BILLBOARD");
27209
+ })();
27210
+ (function() {
27211
+ ParticleRenderer._renderModeMeshMacro = ShaderMacro.getByName("RENDERER_MODE_MESH");
27212
+ })();
27213
+ (function() {
27214
+ ParticleRenderer._pivotOffsetProperty = ShaderProperty.getByName("renderer_PivotOffset");
27215
+ })();
27216
+ (function() {
27217
+ ParticleRenderer._lengthScale = ShaderProperty.getByName("renderer_StretchedBillboardLengthScale");
27218
+ })();
27219
+ (function() {
27220
+ ParticleRenderer._speedScale = ShaderProperty.getByName("renderer_StretchedBillboardSpeedScale");
27221
+ })();
27222
+ (function() {
27223
+ ParticleRenderer._currentTime = ShaderProperty.getByName("renderer_CurrentTime");
27224
+ })();
27225
+ __decorate([
27226
+ deepClone
27227
+ ], ParticleRenderer.prototype, "generator", void 0);
27228
+ __decorate([
27229
+ shallowClone
27230
+ ], ParticleRenderer.prototype, "pivot", void 0);
27032
27231
 
27033
27232
  /**
27034
27233
  * Particle curve mode.
@@ -27050,18 +27249,6 @@ var SubPrimitive = function SubPrimitive() {
27050
27249
  ParticleGradientMode[ParticleGradientMode[/* Random value between two color gradients. */ "TwoGradients"] = 3] = "TwoGradients";
27051
27250
  })(exports.ParticleGradientMode || (exports.ParticleGradientMode = {}));
27052
27251
 
27053
- /**
27054
- * The rendering mode for particle renderer.
27055
- */ exports.ParticleRenderMode = void 0;
27056
- (function(ParticleRenderMode) {
27057
- ParticleRenderMode[ParticleRenderMode[/** Render particles as billboards facing the active camera. */ "Billboard"] = 0] = "Billboard";
27058
- ParticleRenderMode[ParticleRenderMode[/** Stretch particles in the direction of motion. */ "StretchBillboard"] = 1] = "StretchBillboard";
27059
- ParticleRenderMode[ParticleRenderMode[/** Render particles as billboards always facing up along the y-Axis. */ "HorizontalBillboard"] = 2] = "HorizontalBillboard";
27060
- ParticleRenderMode[ParticleRenderMode[/** Render particles as billboards always facing the player, but not pitching along the x-Axis. */ "VerticalBillboard"] = 3] = "VerticalBillboard";
27061
- ParticleRenderMode[ParticleRenderMode[/** Render particles as meshes. */ "Mesh"] = 4] = "Mesh";
27062
- ParticleRenderMode[ParticleRenderMode[/** Do not render particles. */ "None"] = 5] = "None";
27063
- })(exports.ParticleRenderMode || (exports.ParticleRenderMode = {}));
27064
-
27065
27252
  /**
27066
27253
  * The space to simulate particles in.
27067
27254
  */ exports.ParticleSimulationSpace = void 0;
@@ -27070,12 +27257,6 @@ var SubPrimitive = function SubPrimitive() {
27070
27257
  ParticleSimulationSpace[ParticleSimulationSpace[/** Simulate particles in world space. */ "World"] = 1] = "World";
27071
27258
  })(exports.ParticleSimulationSpace || (exports.ParticleSimulationSpace = {}));
27072
27259
 
27073
- exports.ParticleStopMode = void 0;
27074
- (function(ParticleStopMode) {
27075
- ParticleStopMode[ParticleStopMode[/** Stop emitting new particles and clear existing particles immediately. */ "StopEmittingAndClear"] = 0] = "StopEmittingAndClear";
27076
- ParticleStopMode[ParticleStopMode[/** Stop emitting new particles, but keep existing particles until they expire. */ "StopEmitting"] = 1] = "StopEmitting";
27077
- })(exports.ParticleStopMode || (exports.ParticleStopMode = {}));
27078
-
27079
27260
  /**
27080
27261
  * @internal
27081
27262
  */ var ParticleRandomSubSeeds;
@@ -29026,181 +29207,60 @@ __decorate([
29026
29207
  ], ParticleGenerator.prototype, "_instanceVertices", void 0);
29027
29208
 
29028
29209
  /**
29029
- * Particle Renderer Component.
29030
- */ var ParticleRenderer = /*#__PURE__*/ function(Renderer1) {
29031
- _inherits(ParticleRenderer, Renderer1);
29032
- function ParticleRenderer(entity) {
29210
+ * Particle Material.
29211
+ */ var ParticleMaterial = /*#__PURE__*/ function(BaseMaterial1) {
29212
+ _inherits(ParticleMaterial, BaseMaterial1);
29213
+ function ParticleMaterial(engine) {
29033
29214
  var _this;
29034
- _this = Renderer1.call(this, entity) || this;
29035
- /** Particle generator. */ _this.generator = new ParticleGenerator(_assert_this_initialized(_this));
29036
- /** Specifies how much particles stretch depending on their velocity. */ _this.velocityScale = 0;
29037
- /** How much are the particles stretched in their direction of motion, defined as the length of the particle compared to its width. */ _this.lengthScale = 2;
29038
- /** The pivot of particle. */ _this.pivot = new engineMath.Vector3();
29039
- _this._currentRenderModeMacro = ParticleRenderer._billboardModeMacro;
29040
- _this.shaderData.enableMacro(ParticleRenderer._billboardModeMacro);
29041
- _this._supportInstancedArrays = _this.engine._hardwareRenderer.canIUse(exports.GLCapabilityType.instancedArrays);
29215
+ _this = BaseMaterial1.call(this, engine, Shader.find("particle-shader")) || this;
29216
+ var shaderData = _this.shaderData;
29217
+ shaderData.enableMacro("MATERIAL_OMIT_NORMAL");
29218
+ shaderData.setColor(BaseMaterial._baseColorProp, new engineMath.Color(1, 1, 1, 1));
29219
+ _this.isTransparent = true;
29042
29220
  return _this;
29043
29221
  }
29044
- var _proto = ParticleRenderer.prototype;
29045
- /**
29046
- * @internal
29047
- */ _proto._onEnable = function _onEnable() {
29048
- if (this.generator.main.playOnEnabled) {
29049
- this.generator.play(false);
29050
- }
29051
- };
29052
- /**
29053
- * @internal
29054
- */ _proto._onDisable = function _onDisable() {
29055
- this.generator.stop(false, exports.ParticleStopMode.StopEmittingAndClear);
29056
- };
29057
- /**
29058
- * @internal
29059
- */ _proto._prepareRender = function _prepareRender(context) {
29060
- if (!this._supportInstancedArrays) {
29061
- return;
29062
- }
29063
- var generator = this.generator;
29064
- generator._update(this.engine.time.deltaTime);
29065
- // No particles to render
29066
- if (generator._firstActiveElement === generator._firstFreeElement) {
29067
- return;
29068
- }
29069
- Renderer1.prototype._prepareRender.call(this, context);
29070
- };
29071
- /**
29072
- * @internal
29073
- */ _proto._updateBounds = function _updateBounds(worldBounds) {
29074
- worldBounds.min.set(-Number.MAX_VALUE, -Number.MAX_VALUE, -Number.MAX_VALUE);
29075
- worldBounds.max.set(Number.MAX_VALUE, Number.MAX_VALUE, Number.MAX_VALUE);
29076
- };
29222
+ var _proto = ParticleMaterial.prototype;
29077
29223
  /**
29078
- * @internal
29079
- */ _proto._updateShaderData = function _updateShaderData(context) {
29080
- var shaderData = this.shaderData;
29081
- shaderData.setFloat(ParticleRenderer._lengthScale, this.lengthScale);
29082
- shaderData.setFloat(ParticleRenderer._speedScale, this.velocityScale);
29083
- shaderData.setFloat(ParticleRenderer._currentTime, this.generator._playTime);
29084
- shaderData.setVector3(ParticleRenderer._pivotOffsetProperty, this.pivot);
29085
- this.generator._updateShaderData(shaderData);
29086
- };
29087
- _proto._render = function _render(context) {
29088
- var generator = this.generator;
29089
- var primitive = generator._primitive;
29090
- if (generator._firstActiveElement < generator._firstFreeElement) {
29091
- primitive.instanceCount = generator._firstFreeElement - generator._firstActiveElement;
29092
- } else {
29093
- var instanceCount = generator._currentParticleCount - generator._firstActiveElement;
29094
- if (generator._firstFreeElement > 0) {
29095
- instanceCount += generator._firstFreeElement;
29096
- }
29097
- primitive.instanceCount = instanceCount;
29098
- }
29099
- var material = this.getMaterial();
29100
- var renderData = this._engine._renderDataPool.getFromPool();
29101
- renderData.setX(this, material, generator._primitive, generator._subPrimitive);
29102
- context.camera._renderPipeline.pushRenderData(context, renderData);
29103
- };
29104
- _proto._onDestroy = function _onDestroy() {
29105
- this.generator._destroy();
29224
+ * @inheritdoc
29225
+ */ _proto.clone = function clone() {
29226
+ var dest = new ParticleMaterial(this._engine);
29227
+ this.cloneTo(dest);
29228
+ return dest;
29106
29229
  };
29107
- _create_class(ParticleRenderer, [
29230
+ _create_class(ParticleMaterial, [
29108
29231
  {
29109
- key: "renderMode",
29232
+ key: "baseColor",
29110
29233
  get: /**
29111
- * Specifies how particles are rendered.
29234
+ * Base color.
29112
29235
  */ function get() {
29113
- return this._renderMode;
29236
+ return this.shaderData.getColor(BaseMaterial._baseColorProp);
29114
29237
  },
29115
29238
  set: function set(value) {
29116
- if (this._renderMode !== value) {
29117
- var lastRenderMode = this._renderMode;
29118
- this._renderMode = value;
29119
- var renderModeMacro = null;
29120
- var shaderData = this.shaderData;
29121
- switch(value){
29122
- case exports.ParticleRenderMode.Billboard:
29123
- renderModeMacro = ParticleRenderer._billboardModeMacro;
29124
- break;
29125
- case exports.ParticleRenderMode.StretchBillboard:
29126
- renderModeMacro = ParticleRenderer._stretchedBillboardModeMacro;
29127
- break;
29128
- case exports.ParticleRenderMode.HorizontalBillboard:
29129
- throw "Not implemented";
29130
- case exports.ParticleRenderMode.VerticalBillboard:
29131
- throw "Not implemented";
29132
- case exports.ParticleRenderMode.Mesh:
29133
- throw "Not implemented";
29134
- }
29135
- if (this._currentRenderModeMacro !== renderModeMacro) {
29136
- this._currentRenderModeMacro && shaderData.disableMacro(this._currentRenderModeMacro);
29137
- renderModeMacro && shaderData.enableMacro(renderModeMacro);
29138
- this._currentRenderModeMacro = renderModeMacro;
29139
- }
29140
- // @ts-ignore
29141
- if (lastRenderMode !== exports.ParticleRenderMode.Mesh !== (value === exports.ParticleRenderMode.Mesh)) {
29142
- this.generator._reorganizeGeometryBuffers();
29143
- }
29239
+ var baseColor = this.shaderData.getColor(BaseMaterial._baseColorProp);
29240
+ if (value !== baseColor) {
29241
+ baseColor.copyFrom(value);
29144
29242
  }
29145
29243
  }
29146
29244
  },
29147
29245
  {
29148
- key: "mesh",
29246
+ key: "baseTexture",
29149
29247
  get: /**
29150
- * The mesh of particle.
29151
- * @remarks Valid when `renderMode` is `Mesh`.
29248
+ * Base texture.
29152
29249
  */ function get() {
29153
- return this._mesh;
29250
+ return this.shaderData.getTexture(BaseMaterial._baseTextureProp);
29154
29251
  },
29155
29252
  set: function set(value) {
29156
- var lastMesh = this._mesh;
29157
- if (lastMesh !== value) {
29158
- var _lastMesh, _value;
29159
- this._mesh = value;
29160
- (_lastMesh = lastMesh) == null ? void 0 : _lastMesh._addReferCount(-1);
29161
- (_value = value) == null ? void 0 : _value._addReferCount(1);
29162
- if (this.renderMode === exports.ParticleRenderMode.Mesh) {
29163
- this.generator._reorganizeGeometryBuffers();
29164
- }
29253
+ this.shaderData.setTexture(BaseMaterial._baseTextureProp, value);
29254
+ if (value) {
29255
+ this.shaderData.enableMacro(BaseMaterial._baseTextureMacro);
29256
+ } else {
29257
+ this.shaderData.disableMacro(BaseMaterial._baseTextureMacro);
29165
29258
  }
29166
29259
  }
29167
29260
  }
29168
29261
  ]);
29169
- return ParticleRenderer;
29170
- }(exports.Renderer);
29171
- (function() {
29172
- ParticleRenderer._billboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_SPHERE_BILLBOARD");
29173
- })();
29174
- (function() {
29175
- ParticleRenderer._stretchedBillboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_STRETCHED_BILLBOARD");
29176
- })();
29177
- (function() {
29178
- ParticleRenderer._horizontalBillboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_HORIZONTAL_BILLBOARD");
29179
- })();
29180
- (function() {
29181
- ParticleRenderer._verticalBillboardModeMacro = ShaderMacro.getByName("RENDERER_MODE_VERTICAL_BILLBOARD");
29182
- })();
29183
- (function() {
29184
- ParticleRenderer._renderModeMeshMacro = ShaderMacro.getByName("RENDERER_MODE_MESH");
29185
- })();
29186
- (function() {
29187
- ParticleRenderer._pivotOffsetProperty = ShaderProperty.getByName("renderer_PivotOffset");
29188
- })();
29189
- (function() {
29190
- ParticleRenderer._lengthScale = ShaderProperty.getByName("renderer_StretchedBillboardLengthScale");
29191
- })();
29192
- (function() {
29193
- ParticleRenderer._speedScale = ShaderProperty.getByName("renderer_StretchedBillboardSpeedScale");
29194
- })();
29195
- (function() {
29196
- ParticleRenderer._currentTime = ShaderProperty.getByName("renderer_CurrentTime");
29197
- })();
29198
- __decorate([
29199
- deepClone
29200
- ], ParticleRenderer.prototype, "generator", void 0);
29201
- __decorate([
29202
- shallowClone
29203
- ], ParticleRenderer.prototype, "pivot", void 0);
29262
+ return ParticleMaterial;
29263
+ }(BaseMaterial);
29204
29264
 
29205
29265
  /**
29206
29266
  * A burst is a particle emission event, where a number of particles are all emitted at the same time
@@ -29906,6 +29966,7 @@ exports.PBRMaterial = PBRMaterial;
29906
29966
  exports.PBRSpecularMaterial = PBRSpecularMaterial;
29907
29967
  exports.ParticleCompositeCurve = ParticleCompositeCurve;
29908
29968
  exports.ParticleCurve = ParticleCurve;
29969
+ exports.ParticleGenerator = ParticleGenerator;
29909
29970
  exports.ParticleMaterial = ParticleMaterial;
29910
29971
  exports.ParticleRenderer = ParticleRenderer;
29911
29972
  exports.PhysicsMaterial = PhysicsMaterial;