Skip to content

Commit

Permalink
Add 3 parameters
Browse files Browse the repository at this point in the history
Global SmokeScreen Parameter:
atmDensityExp - SmokeScreen.cfg variable, adjusts input atmospheric
pressure by an exponent, to give similar plume scaling between RSS and
Stock.

ModelMultiParticlePersistFX Parameters:
vRandPosOffset - Random positive position offset to spread fast
particles out.  Additive.
vPosOffset - nonrandom positive offset to adjust starting particle
position.  Additive.
  • Loading branch information
Felger committed Aug 16, 2015
1 parent 25ba6b1 commit 02209e8
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 11 deletions.
39 changes: 37 additions & 2 deletions ModelMultiParticlePersistFX.cs
Expand Up @@ -56,6 +56,8 @@ public class ModelMultiParticlePersistFX : EffectBehaviour

[Persistent] public float fixedScale = 1;

[Persistent] public float emissionMult = 1;

[Persistent] public float sizeClamp = 50;

// Initial density of the particle seen as sphere of radius size of perfect
Expand Down Expand Up @@ -125,6 +127,10 @@ public class ModelMultiParticlePersistFX : EffectBehaviour

public MultiInputCurve randConeEmit;

public MultiInputCurve vRandPosOffset;

public MultiInputCurve vPosOffset;

public MultiInputCurve xyForce;

public MultiInputCurve zForce;
Expand Down Expand Up @@ -334,7 +340,7 @@ private void UpdateInputs(float power)
}

inputs[(int)MultiInputCurve.Inputs.power] = power;
inputs[(int)MultiInputCurve.Inputs.density] = atmDensity;
inputs[(int)MultiInputCurve.Inputs.density] = (float)Math.Pow(atmDensity,SmokeScreenConfig.Instance.atmDensityExp);
inputs[(int)MultiInputCurve.Inputs.mach] = surfaceVelMach;
inputs[(int)MultiInputCurve.Inputs.parttemp] = partTemp;
inputs[(int)MultiInputCurve.Inputs.externaltemp] = externalTemp;
Expand All @@ -361,7 +367,7 @@ public void UpdateEmitters(float power)
pkpe.pe.minSize = Mathf.Min(pkpe.minSizeBase * sizePower, finalSizeClamp);
pkpe.pe.maxSize = Mathf.Min(pkpe.maxSizeBase * sizePower, finalSizeClamp);

float emissionPower = emission.Value(inputs);
float emissionPower = emission.Value(inputs) * emissionMult;
pkpe.pe.minEmission = Mathf.FloorToInt(pkpe.minEmissionBase * emissionPower);
pkpe.pe.maxEmission = Mathf.FloorToInt(pkpe.maxEmissionBase * emissionPower);

Expand Down Expand Up @@ -390,6 +396,9 @@ public void UpdateEmitters(float power)
pkpe.xyForce = xyForce.Value(inputs);
pkpe.zForce = zForce.Value(inputs);

pkpe.vRandPosOffset = vRandPosOffset.Value(inputs);
pkpe.vPosOffset = vPosOffset.Value(inputs);

pkpe.physical = physical && !SmokeScreenConfig.Instance.globalPhysicalDisable;
pkpe.initialDensity = initialDensity;
pkpe.dragCoefficient = dragCoefficient;
Expand Down Expand Up @@ -636,6 +645,8 @@ public override void OnLoad(ConfigNode node)
initalVelocityOffsetMaxRadius = new MultiInputCurve("initalVelocityOffsetMaxRadius", true);
sizeClampCurve = new MultiInputCurve("sizeClamp", true);
randConeEmit = new MultiInputCurve("randConeEmit", true);
vRandPosOffset = new MultiInputCurve("vRandPosOffset", true);
vPosOffset = new MultiInputCurve("vPosOffset", true);
xyForce = new MultiInputCurve("xyForce", false);
zForce = new MultiInputCurve("zForce", false);

Expand All @@ -657,6 +668,8 @@ public override void OnLoad(ConfigNode node)
initalVelocityOffsetMaxRadius.Load(node);
sizeClampCurve.Load(node);
randConeEmit.Load(node);
vRandPosOffset.Load(node);
vPosOffset.Load(node);
xyForce.Load(node);
zForce.Load(node);

Expand Down Expand Up @@ -817,6 +830,24 @@ public override void OnSave(ConfigNode node)
Print("OnSave randConeEmit is null");
}

if (vRandPosOffset != null)
{
vRandPosOffset.Save(node);
}
else
{
Print("OnSave vRandPosOffset is null");
}

if (vPosOffset != null)
{
vPosOffset.Save(node);
}
else
{
Print("OnSave vPosOffset is null");
}

if (xyForce != null)
{
xyForce.Save(node);
Expand Down Expand Up @@ -1026,6 +1057,8 @@ private float minInput(int id)
min = Mathf.Min(min, initalVelocityOffsetMaxRadius.minInput[id]);
min = Mathf.Min(min, sizeClampCurve.minInput[id]);
min = Mathf.Min(min, randConeEmit.minInput[id]);
min = Mathf.Min(min, vRandPosOffset.minInput[id]);
min = Mathf.Min(min, vPosOffset.minInput[id]);
min = Mathf.Min(min, xyForce.minInput[id]);
min = Mathf.Min(min, zForce.minInput[id]);

Expand All @@ -1052,6 +1085,8 @@ private float maxInput(int id)
max = Mathf.Max(max, initalVelocityOffsetMaxRadius.maxInput[id]);
max = Mathf.Max(max, sizeClampCurve.maxInput[id]);
max = Mathf.Max(max, randConeEmit.minInput[id]);
max = Mathf.Max(max, vRandPosOffset.minInput[id]);
max = Mathf.Max(max, vPosOffset.minInput[id]);
max = Mathf.Max(max, xyForce.minInput[id]);
max = Mathf.Max(max, zForce.minInput[id]);

Expand Down
38 changes: 29 additions & 9 deletions PersistentKSPParticleEmitter.cs
Expand Up @@ -75,6 +75,8 @@ public class PersistentKSPParticleEmitter

public float sizeClamp = 50;

public bool clampXYstart = false;

// The initial velocity of the particles will be offset by a random amount
// lying in a disk perpendicular to the mean initial velocity whose radius
// is randomOffsetMaxRadius. This is similar to Unity's 'Random Velocity'
Expand All @@ -85,6 +87,12 @@ public class PersistentKSPParticleEmitter
//Similar to randomInitalVelocityOffsetMaxRadius, cleaned a little
public float randConeEmit = 0.0f;

//Additive random position offset
public float vRandPosOffset = 0.0f;

//Additive non-random position offset
public float vPosOffset = 0.0f;

//xyForce multiplicatively damps non-axis (x,y) motion, leaving axis
//motion (z) untouched.
public float xyForce = 1.0f;
Expand Down Expand Up @@ -194,8 +202,9 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity)

//For randConeEmit:
//Only generate a random vector on every other particle, for the in-between particles, negate the disk.
bool coneToggle = true;
bool toggle = true;
Vector2 disk = new Vector2 (0,0);
//For startSpread

//Step through all the particles:
for (int j = 0; j < particles.Length; j++)
Expand All @@ -217,51 +226,62 @@ public void EmitterOnUpdate(Vector3 emitterWorldVelocity)

if (particle.energy > 0)
{
Vector3d pPos = pe.useWorldSpace
? particle.position
: pe.transform.TransformPoint(particle.position);

//Slight methodology change to avoid duplicating if statements:
Vector3d pVel;
Vector3d pPos;
if (pe.useWorldSpace)
{
pVel = particle.velocity;
pPos = particle.position;
}
else if (!pe.useWorldSpace && particle.energy == particle.startEnergy && (randConeEmit != 0))
else if (!pe.useWorldSpace && particle.energy == particle.startEnergy)
{
Vector3 lVel = new Vector3(0, 0, 1); ;
Vector3 lVel = new Vector3(0, 0, 1);
Vector3 lPos = particle.position;

// Adjust initial velocity to make a cone. Only perform if pe.useWorldSpace
// is true, and we have a randConeEmit set.
//Produce a random vector within "angle" of the original vector.
//The maximum producible cone is 90 degrees when randConeEmit is very large.
//Could open up more if we used trig, but it'd be less efficient.
if (coneToggle)

if (toggle)
{
disk = Random.insideUnitCircle * randConeEmit;
coneToggle = false;
toggle = false;
}
else
{
disk *= -1;
coneToggle = true;
toggle = true;
}
lVel.x = disk.x;
lVel.y = disk.y;
lVel = Vector3.Normalize(lVel);
lVel *= Vector3.Magnitude(particle.velocity);

//Adjust initial position back along its position, if required.
//Apply a random offset if vRandOffset != 0, else apply zero.
float randoff = (vRandPosOffset != 0)? Random.Range(0, vRandPosOffset) : 0;
lPos += Vector3.Normalize(lVel) * (randoff + vPosOffset);

//Finalize position and velocity
pPos = pe.transform.TransformPoint(lPos);
pVel = pe.transform.TransformDirection(lVel)
+ Krakensbane.GetFrameVelocity();
}
else if (!pe.useWorldSpace && particle.energy != particle.startEnergy)
{
pPos = pe.transform.TransformPoint(particle.position);
pVel = pe.transform.TransformDirection(particle.velocity.x * xyForce,
particle.velocity.y * xyForce,
particle.velocity.z * zForce)
+ Krakensbane.GetFrameVelocity();
}
else
{
pPos = pe.transform.TransformPoint(particle.position);
pVel = pe.transform.TransformDirection(particle.velocity)
+ Krakensbane.GetFrameVelocity();
}
Expand Down
2 changes: 2 additions & 0 deletions SmokeScreenConfig.cs
Expand Up @@ -36,6 +36,8 @@ internal class SmokeScreenConfig : MonoBehaviour
{
[Persistent] public int maximumActiveParticles = 8000; // The engine won't spawn more than 10k anyway

[Persistent] public float atmDensityExp = 1; //Atmospheric multiplier for scaling growth. Intended as a global RealPlume parameter.

[Persistent] public bool globalCollideDisable = false;

[Persistent] public bool globalPhysicalDisable = false;
Expand Down

0 comments on commit 02209e8

Please sign in to comment.