Click or drag to resize
AB4D logo

DXMeshGeometry3D Class

DXMeshGeometry3D class is initialized by the WPF's MeshGeometry3D and uses its data to prepare the low level DirectX objects (Index and Vertex buffers) that are needed to render the mesh.
Inheritance Hierarchy
SystemObject
  Ab3d.DirectXDXResourceBase
    Ab3d.DirectXSharedDXResource
      Ab3d.DirectXSharedDXDeviceResource
        Ab3d.DirectXMeshBase
          Ab3d.DirectX.ModelsDXMeshGeometry3D

Namespace: Ab3d.DirectX.Models
Assembly: Ab3d.DXEngine.Wpf (in Ab3d.DXEngine.Wpf.dll) Version: 7.0.8865.1045
Syntax
C#
public class DXMeshGeometry3D : MeshBase, 
	IDynamicVertexBufferCreator, IRayHitTestedObject, ITriangularMesh, IOctTreeMesh

The DXMeshGeometry3D type exposes the following members.

Constructors
 NameDescription
Public methodDXMeshGeometry3D Constructor - note: it is recommended to use static Create method instead.
Top
Properties
 NameDescription
Public propertyAutomaticallyChangeToDynamicVertexBuffer Gets or sets a Boolean property that after 3 changes of the vertex buffer sets the CreateDynamicVertexBuffer to true (if not already set to true). This improves performance of subsequent buffer changes. Default value is true.
Public propertyCreateDynamicIndexBuffer Gets or sets a Boolean that specifies if the index buffer is created as a dynamic buffer. This can provide slightly better performance for cases when index buffer is updated very often. Default value is false.
Public propertyCreateDynamicVertexBuffer Gets or sets a Boolean that specifies if the vertex buffer is created as a dynamic buffer. This can provide slightly better performance for cases when vertex buffer is updated very often. Default value is false.
Public propertyFlipYTextureCoordinate Gets or sets a Boolean that specifies if y texture coordinate is changed to y' = 1 - y (flipped texture coordinates instead of flipping the image is much faster)
Public propertyIsIndexBufferDirty Gets a boolean that specifies that index buffer needs to be regenerated.
Public propertyIsVertexBufferDirty Gets a boolean that specifies that vertex buffer needs to be regenerated (Positions, Normals or TextureCoordinates have changed)
Public propertyMeshGeometry Gets MeshGeometry3D that is used to create this DXMeshGeometry3D.
Public propertyOctTree Gets or sets an MeshOctTree that can be used for hit testing. The MeshOctTree is automatically generated when number of positions in this mesh is bigger or equal to the value set in MeshPositionsCountForOctTreeGeneration.
Public propertyPositionsCount Gets a number of positions that are defined by this mesh.
Public propertyTriangleIndicesCount Gets a number of triangle indices that are defined by this mesh.
Public propertyTrianglesCount Gets the number of triangles that are used to define this mesh.
Public propertyVersion Gets the version number of the DirectX buffers created from this MeshGeometry3D. Version is increased each time the buffers change. Note: When MeshGeometry3D 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)
Top
Methods
 NameDescription
Public methodCreateOctTree CreateOctTree returns a MeshOctTree that is created from the mesh defined in this DXMeshGeometry3D. This method must be called after the DXMeshGeometry3D has been initialized (added to DXScene or after InitializeResources method is called).
Public methodGetClosestHitResult GetClosestHitResult method returns a DXRayHitTestResult with the closest triangle hit by the specified ray. When no triangle is hit, null is returned.
Public methodGetDetailsText Returns string that tells details about this SceneNode
Public methodGetNextHitResult GetNextHitResult method continues hit testing from the previously returned hit test and returns a DXRayHitTestResult with the next hit triangle (not necessary the next closest triangle) or null if no other triangle is hit. This method can be used to get all hit results.
Public methodGetTrianglePositions GetTrianglePositions sets the 3 positions that define the triangle with the specified triangle index.
Public methodStatic memberGetUsedDXMeshGeometry3D GetUsedDXMeshGeometry3D method returns DXMeshGeometry3D that was created from the WPF MeshGeometry3D (or null if no DXMeshGeometry3D was created for the WPF material). parentDXDevice is requireed to check if the created DXMeshGeometry3D was created for the same device.
Public methodGetVertexAndIndexBuffers GetVertexAndIndexBuffers method gets vertex and index buffer array that are created from MeshGeometry3D. This method must be called after the DXMeshGeometry3D was initialized or the Update method was called. Otherwise the returned array will be null.
Public methodHitTest HitTest method test the triangles defined in this mesh for hitting with the specified ray. When getOnlyNextHitTest is false, then the closest hit result is returned, else the next hit result is returned. When no hit is found, null is returned.
Public methodRecreateMesh Forces creation of new VertexBuffers and IndexBuffer. This method sets IsVertexBufferDirty and IsIndexBufferDirty to true and then calls Update(Boolean) method.
Public methodStatic memberSetUsedDXMeshGeometry3D Sets a DXMeshGeometry3D that will be used when showing WPF MeshGeometry3D in DXEngine (must be set before the objects are initialized in DXEngine).
Public methodSortTrianglesByCameraDistance SortTrianglesByCameraDistance method sorts the triangle indices so that the triangles are sorted by camera distance - triangles that are farther away are rendered first. After sorting indices, the Update(Boolean) method needs to be called to update the DirectX buffer. When using this method it is highly recommended to set CreateDynamicIndexBuffer to true. See remarks for more info.
Public methodToString Returns a String that represents this instance.
(Overrides ObjectToString)
Public methodUpdate Updates vertex and index buffers based on the IsVertexBufferDirty and IsIndexBufferDirty. To force update both vertex and index buffer call RecreateMesh method. When updateGpuBuffers parameter is false, then the vertex buffer array and index buffer array can be created without a DXDevice object and they will not be sent to the GPU.
Top
Remarks

DXMeshGeometry3D class is initialized by the WPF's MeshGeometry3D and uses its data to prepare the low level DirectX objects (Index and Vertex buffers) that are needed to render the mesh.

The created vertex buffer is set to the VertexBufferBindings property. Index buffer is set to the IndexBuffer property.

Vertex buffer is created with Position (as SharpDX.Vector3), Normal (as SharpDX.Vector3) and TextureCoordinate (as SharpDX.Vector).

When MeshTangentArray attribute is set to the MeshGeometry3D (with using SetDXAttribute(Geometry3D, DXAttributeType, Object) extension method), a special vertex buffer with tangent data is created and set to the second slot of the created VertexBufferBindings property. In this case the Tangent is added to the InputLayoutType value.

See Also