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