Use emitter shape from particle system

This commit is contained in:
Ammar Askar 2023-08-03 12:19:13 -04:00
parent 4e53fafb0a
commit 756ecc9cb1
2 changed files with 28 additions and 1 deletions

View file

@ -17,5 +17,28 @@ namespace OpenTS2.Content.DBPF.Effects.Types
return new BoundingBox(
Vector3Serializer.Deserialize(reader), Vector3Serializer.Deserialize(reader));
}
/// <summary>
/// These bounding boxes usually represent cuboids, ellipsoids or toruses. They are represented by the two
/// corners of the shape.
///
/// In Unity land shapes are usually represented by their center, scale and rotation from a unit cube, sphere.
/// This function handles converting corners to the Unity style.
/// </summary>
/// <returns>
/// The center position of the box, its rotation and scale as a triple in that order.
/// </returns>
public readonly (Vector3, Quaternion, Vector3) GetCenterRotationAndScale()
{
var center = (LowerCorner + UpperCorner) / 2;
// TODO: figure out how to calculate rotation.
var rotation = Quaternion.identity;
// TODO: this might be wrong.
var scale = (UpperCorner - LowerCorner);
return (center, rotation, scale);
}
}
}

View file

@ -77,8 +77,12 @@ namespace OpenTS2.Scenes
var emission = system.emission;
emission.rateOverTime = effect.Emission.RateCurve.ToUnityCurve();
// Set the emitter shape and drection.
// Set the emitter shape and direction.
var shape = system.shape;
var (emitterPos, emitterRotation, emitterScale) = effect.Emission.EmitVolume.GetCenterRotationAndScale();
shape.position = emitterPos;
shape.rotation = emitterRotation.eulerAngles;
shape.scale = emitterScale;
if (effect.Emission.EmitTorusWidth > 0)
{
shape.shapeType = ParticleSystemShapeType.Donut;