using System; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; namespace BansheeEngine { /** @addtogroup Rendering * @{ */ /// /// Primary class for holding geometry. Stores data in the form of vertex buffers and optionally an index buffer, which /// may be bound to the pipeline for drawing. May contain multiple sub-meshes. /// public partial class Mesh : Resource { private Mesh(bool __dummy0) { } protected Mesh() { } /// /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. All indices will /// be part of a single sub-mesh. /// /// Number of vertices in the mesh. /// /// Number of indices in the mesh. Must be a multiple of primitive size as specified by provided topology. /// /// /// Determines how should the provided indices be interpreted by the pipeline. Default option is a triangle list, where /// three indices represent a single triangle. /// /// Optimizes performance depending on planned usage of the mesh. /// Controls how are vertices organized in the vertex buffer and what data they contain. /// /// Size of indices, use smaller size for better performance, however be careful not to go over the number of vertices /// limited by the data type size. /// public Mesh(int numVertices, int numIndices, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Static, VertexLayout vertex = VertexLayout.Position, IndexType index = IndexType.Index32) { Internal_create(this, numVertices, numIndices, topology, usage, vertex, index); } /// /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. Indices can be /// referenced by multiple sub-meshes. /// /// Number of vertices in the mesh. /// /// Number of indices in the mesh. Must be a multiple of primitive size as specified by provided topology. /// /// /// Defines how are indices separated into sub-meshes, and how are those sub-meshes rendered. Sub-meshes may be rendered /// independently, each with a different material. /// /// Optimizes performance depending on planned usage of the mesh. /// Controls how are vertices organized in the vertex buffer and what data they contain. /// /// Size of indices, use smaller size for better performance, however be careful not to go over the number of vertices /// limited by the data type size. /// public Mesh(int numVertices, int numIndices, SubMesh[] subMeshes, MeshUsage usage = MeshUsage.Static, VertexLayout vertex = VertexLayout.Position, IndexType index = IndexType.Index32) { Internal_create0(this, numVertices, numIndices, subMeshes, usage, vertex, index); } /// /// Creates a new mesh from an existing mesh data. Created mesh will match the vertex and index buffers described by the /// mesh data exactly. Mesh will have no sub-meshes. /// /// Vertex and index data to initialize the mesh with. /// /// Determines how should the provided indices be interpreted by the pipeline. Default option is a triangle list, where /// three indices represent a single triangle. /// /// Optimizes performance depending on planned usage of the mesh. public Mesh(MeshData data, MeshTopology topology = MeshTopology.TriangleList, MeshUsage usage = MeshUsage.Static) { Internal_create1(this, data, topology, usage); } /// /// Creates a new mesh with enough space to hold the a number of primitives using the specified layout. Indices can be /// referenced by multiple sub-meshes. /// /// Vertex and index data to initialize the mesh with. /// /// Defines how are indices separated into sub-meshes, and how are those sub-meshes rendered. Sub-meshes may be rendered /// independently, each with a different material. /// /// Optimizes performance depending on planned usage of the mesh. public Mesh(MeshData data, SubMesh[] subMeshes, MeshUsage usage = MeshUsage.Static) { Internal_create2(this, data, subMeshes, usage); } /// Gets the skeleton required for animation of this mesh, if any is available. public Skeleton Skeleton { get { return Internal_getSkeleton(mCachedPtr); } } /// Returns an object containing all shapes used for morph animation, if any are available. public MorphShapes MorphShapes { get { return Internal_getMorphShapes(mCachedPtr); } } /// Returns all sub-meshes contained in the mesh. public SubMesh[] SubMeshes { get { return Internal_getSubMeshes(mCachedPtr); } } /// Returns the number of sub-meshes contained in this mesh. public uint SubMeshCount { get { return Internal_getSubMeshCount(mCachedPtr); } } /// /// Accesses the vertex and index data of the mesh. If reading, mesh must have been created with the MeshUsage::CPUCached /// flag. If writing the caller must ensure the data matches mesh's vertex/index counts, vertex layout and index format. /// public MeshData MeshData { get { return Internal_getMeshData(mCachedPtr); } set { Internal_setMeshData(mCachedPtr, value); } } [MethodImpl(MethodImplOptions.InternalCall)] private static extern Skeleton Internal_getSkeleton(IntPtr thisPtr); [MethodImpl(MethodImplOptions.InternalCall)] private static extern MorphShapes Internal_getMorphShapes(IntPtr thisPtr); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_create(Mesh managedInstance, int numVertices, int numIndices, MeshTopology topology, MeshUsage usage, VertexLayout vertex, IndexType index); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_create0(Mesh managedInstance, int numVertices, int numIndices, SubMesh[] subMeshes, MeshUsage usage, VertexLayout vertex, IndexType index); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_create1(Mesh managedInstance, MeshData data, MeshTopology topology, MeshUsage usage); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_create2(Mesh managedInstance, MeshData data, SubMesh[] subMeshes, MeshUsage usage); [MethodImpl(MethodImplOptions.InternalCall)] private static extern SubMesh[] Internal_getSubMeshes(IntPtr thisPtr); [MethodImpl(MethodImplOptions.InternalCall)] private static extern uint Internal_getSubMeshCount(IntPtr thisPtr); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_getBounds(IntPtr thisPtr, out AABox box, out Sphere sphere); [MethodImpl(MethodImplOptions.InternalCall)] private static extern MeshData Internal_getMeshData(IntPtr thisPtr); [MethodImpl(MethodImplOptions.InternalCall)] private static extern void Internal_setMeshData(IntPtr thisPtr, MeshData value); } /** @} */ }