Click or drag to resize
Ab4d.SharpEngine logo

Mesh Class

Mesh provides geometry information to the rendering engine. Mesh is a base abstract class that defines the common properties for all mesh objects.
Inheritance Hierarchy

Namespace: Ab4d.SharpEngine.Meshes
Assembly: Ab4d.SharpEngine (in Ab4d.SharpEngine.dll) Version: 2.0.8956+4c7684e186ca1be74e7a284fbe739d9a1b843d3c
Syntax
C#
public abstract class Mesh : InitializedSceneComponent, 
	IDisposable

The Mesh type exposes the following members.

Constructors
 NameDescription
Protected methodMesh Constructor
Top
Properties
 NameDescription
Public propertyAvailableDataChannels Gets all available data channels for this mesh.
Public propertyBoundingBox Gets the bounding box of the mesh
Public propertyHasCustomMeshDataChannels True when this mesh has any custom data channels that were added by calling SetDataChannel method.
Public propertyIndexBuffer Gets the GpuBuffer with IndexBuffer data. The IndexBuffer is set by protected SetIndexBuffer(GpuBuffer, Int32) method.
Public propertyIndexBufferType Gets IndexBufferType
Public propertyIndexCount Gets number of vertices that are used by this mesh.
Public propertyIsLocked Indicates that the mesh will never change, so it can be optimized by the engine (for example merged with some other mesh).
Public propertyIsSceneCached Indicates that this mesh is cashed by Scene objects and cannot be disposed by calling Dispose method. This means the mesh can be shared without worrying that someone will dispose the mesh. This flag is set when the mesh is cached by calling Scene.CacheObject(String, Object) method. The mesh will be disposed when the Scene will be disposed or if it is removed from the cache and then disposed.
Public propertyPrimitiveTopology Gets PrimitiveTopology
Public propertyVersion Gets the version number of this Material. Version is increased each time the material is changed. Note: When material is changed a lot of times, the Version value can overflow from positive to negative numbers (to prevent problems do not check for bigger value but for not equal value)
Public propertyVertexBuffer Gets the GpuBuffer with VertexBuffer data. The VertexBuffer is set by protected SetVertexBuffer(GpuBuffer, Int32) method.
Public propertyVertexBufferDescription Gets VertexBufferDescription
Public propertyVertexCount Gets number of vertices that are used by this mesh.
Top
Methods
 NameDescription
Public methodDispose Disposes all resources that are used by this mesh (except in case when SceneCached flag is set then nothing is disposed).
Protected methodDispose(Boolean) Releases unmanaged and managed resources (when disposing is true). This method may be called only from the CheckAndDispose(Boolean) method and must not be called manually by the user.
(Overrides ComponentBaseDispose(Boolean))
Protected methodDisposeIndexBuffer DisposeIndexBuffer
Protected methodDisposeVertexBuffer DisposeVertexBuffer
Public methodDumpDetails Dumps values of individual vertices and triangle indices into the Visual Studio Output window.
Public methodDumpOverview Dumps an overview information about this mesh into the Visual Studio Output window.
Public methodGetDataChannel(MeshDataChannelTypes) GetDataChannel returns an object with the data from the specified channel. For example, for Positions an array of Vector3 is returned with positions defined by this mesh. Executing this method may take some time because the method may need to create new array objects and copy data from some other data structure (for example an array of PositionNormalTextureVertex values).
Public methodGetDataChannelT(MeshDataChannelTypes) GetDataChannel returns an object with the data from the specified channel. For example, for Positions an array of Vector3 is returned with positions defined by this mesh. When the type of the data does not match the specified type T, then ArgumentException is thrown. Executing this method may take some time because the method may need to create new array objects and copy data from some other data structure (for example an array of PositionNormalTextureVertex values).
Public methodGetDataChannelArrayT GetDataChannel returns an array with data from the specified channel. For example, for Positions an array of Vector3 is returned with positions defined by this mesh. When the type of the data array does not match the specified type T, then null is returned. Executing this method may take some time because the method may need to create new array objects and copy data from some other data structure (for example an array of PositionNormalTextureVertex values).
Public methodGetDataChannelGpuBuffer Returns a GpuBuffer that is defined by the specified data channel. When no GpuBuffer is defined, then null is returned.
Public methodGetDetailsText GetDetailsText method gets string with values of individual vertices and triangle indices of this mesh.
Public methodGetMetadata(String) Gets the object that was stored to the specified key by the SetMetadata(String, Object) method. When the key is not found then null is returned. If you know that the key exists and you know the type, then you can use the generic GetMetadataT(String) method.
Public methodGetMetadataT(String) Gets the object that was stored to the specified key by the SetMetadata(String, Object) method. When the key is not found then ArgumentException is thrown. When the metadata with that key cannot be converted to the target type T, then FormatException is thrown. If you are not sure if the key exist or what type its data is, then use the non-generic GetMetadata(String) that returns object or null.
Public methodGetOverviewText GetOverviewText adds string that writes an overview information about this mesh into the specified StringBuilder. To get values of individual vertices and triangle indices use GetDetailsText(Boolean, Boolean, Boolean, Int32, Int32, Int32) method.
Public methodLockMesh LockMesh method locks the mesh and prevents changing it. To indicate that the mesh is locked, the LockedMesh is set in _flags property. Locked mesh cannot be unlocked.
Protected methodNotifyMeshChange NotifyMeshChange sets the MeshChanged and updates the Version number.
Protected methodOnUpdateMesh OnUpdateMesh
Public methodRemoveDataChannel RemoveDataChannel method removes the data from the specified channel. If GpuBuffer is assigned to that channel, then it is disposed when disposeGpuBuffer parameter is true (by default).
Public methodRemoveMetadata Removes the specified key from the metadata Dictionary.
Public methodSetDataChannel(MeshDataChannelTypes, Object) SetDataChannel method sets the specified data to the specified channel.
Public methodSetDataChannel(MeshDataChannelTypes, Object, GpuBuffer, Boolean) SetDataChannel method sets the specified data and the GpuBuffer to the specified channel.
Public methodSetDataChannelGpuBuffer Sets the specified GpuBuffer to the data with the specified channel type. If any existing GpuBuffer was already assigned to the channel, then it is disposed.
Protected methodSetIndexBuffer SetIndexBuffer sets the IndexBuffer and IndexCount. The method disposes any existing IndexBuffer and subscribes to Disposing event on the new indexBuffer.
Public methodSetMetadata Sets the key with the specified value to the metadata Dictionary that is created for this mesh (using Metadata channel). When value is nul, then the key is removed from the Dictionary.
Protected methodSetVertexBuffer SetVertexBuffer sets the VertexBuffer and VertexCount. The method disposes any existing VertexBuffer and subscribes to Disposing event on the new vertexBuffer.
Public methodToString
(Overrides ObjectToString)
Public methodUpdateDataChannel UpdateDataChannel method should be called when the data in the channel array are changed. This will dispose the existing GpuBuffer and generate a new one when needed.
Public methodUpdateMesh UpdateMesh method can be called to update the GPU buffers from the mesh data. When possible, use the UpdateMesh(BoundingBox) that takes boundingBox as parameter.
Public methodUpdateMesh(BoundingBox) UpdateMesh method can be called to update the GPU buffers from the mesh data.
Top
Remarks

Mesh provides geometry information to the rendering engine.

Mesh is a base abstract class that defines VertexBuffer, IndexBuffer, VertexCount, IndexCount and other properties that common for all meshes.

Mesh can also define other data that are stored as data channels. Each data channel has its type (MeshDataChannelTypes), data (usually an array of items, for example Color4 for vertex colors) and optionally a GpuBuffer that defines the buffer that is used by the graphics card.

Data can be set to the channel by SetDataChannel(MeshDataChannelTypes, Object) or SetDataChannel(MeshDataChannelTypes, Object, GpuBuffer, Boolean) methods.

To retrieve the data use the GetDataChannel(MeshDataChannelTypes), GetDataChannelT(MeshDataChannelTypes), GetDataChannelArrayT(MeshDataChannelTypes) or GetDataChannelGpuBuffer(MeshDataChannelTypes).

To remove the data channel use the RemoveDataChannel(MeshDataChannelTypes, Boolean) method.

To see which data channels are available see the AvailableDataChannels.

Some derived classes, for example TriangleMeshT and StandardMesh, can split a more complex vertex declaration (for example using PositionNormalTextureVertex) into individual array of positions, normals and texture coordinates. This can be done by calling GetDataChannelT(MeshDataChannelTypes) or GetDataChannelArrayT(MeshDataChannelTypes) and setting channelType to Positions, Normals or TextureCoordinates.

See Also