diff --git a/Assets/Scripts/OpenTS2/Content/DBPF/Effects/Types/BoundingBox.cs b/Assets/Scripts/OpenTS2/Content/DBPF/Effects/Types/BoundingBox.cs index cd9f67d..a2c65cc 100644 --- a/Assets/Scripts/OpenTS2/Content/DBPF/Effects/Types/BoundingBox.cs +++ b/Assets/Scripts/OpenTS2/Content/DBPF/Effects/Types/BoundingBox.cs @@ -17,5 +17,28 @@ namespace OpenTS2.Content.DBPF.Effects.Types return new BoundingBox( Vector3Serializer.Deserialize(reader), Vector3Serializer.Deserialize(reader)); } + + /// + /// 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. + /// + /// + /// The center position of the box, its rotation and scale as a triple in that order. + /// + 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); + } } } \ No newline at end of file diff --git a/Assets/Scripts/OpenTS2/Scenes/EffectsManager.cs b/Assets/Scripts/OpenTS2/Scenes/EffectsManager.cs index d444f96..ad07b0b 100644 --- a/Assets/Scripts/OpenTS2/Scenes/EffectsManager.cs +++ b/Assets/Scripts/OpenTS2/Scenes/EffectsManager.cs @@ -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;