Răsfoiți Sursa

FXE: Add lifeTimeRand

trethaller 6 ani în urmă
părinte
comite
4c60f67c34
1 a modificat fișierele cu 6 adăugiri și 1 ștergeri
  1. 6 1
      hide/prefab/fx/Emitter.hx

+ 6 - 1
hide/prefab/fx/Emitter.hx

@@ -52,6 +52,7 @@ private class ParticleInstance extends h3d.scene.Object {
 	var evaluator : Evaluator;
 	var evaluator : Evaluator;
 
 
 	public var life = 0.0;
 	public var life = 0.0;
+	public var lifeTime = 0.0;
 
 
 	public var curVelocity = new h3d.Vector();
 	public var curVelocity = new h3d.Vector();
 	public var orientation = new h3d.Quat();
 	public var orientation = new h3d.Quat();
@@ -85,7 +86,7 @@ private class ParticleInstance extends h3d.scene.Object {
 		if(child == null)
 		if(child == null)
 			return;
 			return;
 
 
-		var t = hxd.Math.clamp(life / emitter.lifeTime, 0.0, 1.0);
+		var t = hxd.Math.clamp(life / lifeTime, 0.0, 1.0);
 
 
 		evaluator.getVector(def.localSpeed, t, tmpLocalSpeed);
 		evaluator.getVector(def.localSpeed, t, tmpLocalSpeed);
 		if(tmpLocalSpeed.length() > 0.001) {
 		if(tmpLocalSpeed.length() > 0.001) {
@@ -204,6 +205,7 @@ class EmitterObject extends h3d.scene.Object {
 	public var particleTemplate : hide.prefab.Object3D;
 	public var particleTemplate : hide.prefab.Object3D;
 	public var maxCount = 20;
 	public var maxCount = 20;
 	public var lifeTime = 2.0;
 	public var lifeTime = 2.0;
+	public var lifeTimeRand = 0.0;
 	public var emitShape : EmitShape = Cylinder;
 	public var emitShape : EmitShape = Cylinder;
 	public var emitOrientation : Orientation = Forward;
 	public var emitOrientation : Orientation = Forward;
 	public var simulationSpace : SimulationSpace = Local;
 	public var simulationSpace : SimulationSpace = Local;
@@ -281,6 +283,7 @@ class EmitterObject extends h3d.scene.Object {
 		for(i in 0...count) {
 		for(i in 0...count) {
 			var part = new ParticleInstance(this, instDef);
 			var part = new ParticleInstance(this, instDef);
 			part.visible = particleVisibility;
 			part.visible = particleVisibility;
+			part.lifeTime = hxd.Math.max(0.01, lifeTime + hxd.Math.srand(lifeTimeRand));
 			context.local3d = part;
 			context.local3d = part;
 			var ctx = particleTemplate.makeInstance(context);
 			var ctx = particleTemplate.makeInstance(context);
 
 
@@ -463,6 +466,7 @@ class Emitter extends Object3D {
 		{ name: "simulationSpace", t: PEnum(SimulationSpace), def: SimulationSpace.Local, disp: "Simulation Space", },
 		{ name: "simulationSpace", t: PEnum(SimulationSpace), def: SimulationSpace.Local, disp: "Simulation Space", },
 		{ name: "emitRate", t: PInt(0, 100), def: 5, disp: "Rate", animate: true },
 		{ name: "emitRate", t: PInt(0, 100), def: 5, disp: "Rate", animate: true },
 		{ name: "lifeTime", t: PFloat(0, 10), def: 1.0 },
 		{ name: "lifeTime", t: PFloat(0, 10), def: 1.0 },
+		{ name: "lifeTimeRand", t: PFloat(0, 1), def: 0.0 },
 		{ name: "maxCount", t: PInt(0, 100), def: 20, },
 		{ name: "maxCount", t: PInt(0, 100), def: 20, },
 		{ name: "emitShape", t: PEnum(EmitShape), def: EmitShape.Sphere, disp: "Emit Shape", },
 		{ name: "emitShape", t: PEnum(EmitShape), def: EmitShape.Sphere, disp: "Emit Shape", },
 		{ name: "emitAngle", t: PFloat(0, 360.0), disp: "Angle", },
 		{ name: "emitAngle", t: PFloat(0, 360.0), disp: "Angle", },
@@ -652,6 +656,7 @@ class Emitter extends Object3D {
 
 
 		emitterObj.simulationSpace = getParamVal("simulationSpace");
 		emitterObj.simulationSpace = getParamVal("simulationSpace");
 		emitterObj.lifeTime = getParamVal("lifeTime");
 		emitterObj.lifeTime = getParamVal("lifeTime");
+		emitterObj.lifeTimeRand = getParamVal("lifeTimeRand");
 		emitterObj.maxCount = getParamVal("maxCount");
 		emitterObj.maxCount = getParamVal("maxCount");
 		emitterObj.emitRate = makeParam(this, "emitRate");
 		emitterObj.emitRate = makeParam(this, "emitRate");
 		emitterObj.emitShape = getParamVal("emitShape");
 		emitterObj.emitShape = getParamVal("emitShape");