using System.Collections.Generic; using System.Numerics; using ACE.DatLoader.Entity; using ACE.Server.Physics; namespace ACE.Server.Entity { public enum ModelMeshType { Building, LandObject, Scenery, Weenie }; /// /// An instanced static mesh /// public class ModelMesh: Mesh { /// /// The static mesh /// public StaticMesh StaticMesh; /// /// The position and orientation /// from the original data /// public Frame Frame; /// /// The position backing store /// private Vector3? _position; /// /// The rotation backing store /// private Quaternion? _rotation; /// /// The position of the model instance /// public Vector3 Position { get { return _position == null ? Frame.Origin : _position.Value; } set { _position = value; } } /// /// The rotation of the model instance /// public Quaternion Rotation { get { return _rotation == null ? Frame.Orientation : _rotation.Value; } set { _rotation = value; } } /// /// The cell offsets within the landblock /// public Vector2 Cell = Vector2.Zero; /// /// The scale of the model /// public float Scale = 1.0f; /// /// For scenery object types /// public ObjectDesc ObjectDesc; /// /// The list of polygons comprising the mesh /// public List Polygons; /// /// The bounding box for collision detection /// public BoundingBox BoundingBox; /// /// Constructs a static mesh instance from a model and frame /// public ModelMesh(uint modelId, Frame frame) { Init(modelId, frame); } /// /// Constructs a new model mesh for a static land object /// public ModelMesh(Stab stab) { Init(stab.Id, stab.Frame); } /// /// Constructs a new model mesh for a building /// public ModelMesh(BuildInfo buildInfo) { Init(buildInfo.ModelId, buildInfo.Frame); } /// /// Initializes a new mesh instance /// /// The modelID of the mesh to load /// The position/orientation info public void Init(uint modelId, Frame frame) { GetMesh(modelId); Frame = frame; BuildPolygons(); BuildBoundingBox(); } /// /// Returns a pointer to the static mesh /// public void GetMesh(uint modelId) { StaticMesh = StaticMeshCache.GetMesh(modelId); } /// /// Builds the polygons for this model mesh /// into world space /// public void BuildPolygons() { Polygons = new List(); foreach (var polygon in StaticMesh.Polygons) { Polygons.Add(new Polygon(polygon, Position, Rotation, Scale)); } } /// /// Builds a bounding box for the model mesh /// public void BuildBoundingBox() { BoundingBox = new BoundingBox(this); } } }