BaseMesh.VertexBuffer Property (Microsoft.DirectX.Direct3D)

How Do I...?

  • Compute a Bounding Sphere from a Mesh

Retrieves the vertex buffer of a mesh.

Definition

Visual Basic Public ReadOnly Property VertexBuffer As VertexBuffer
C# public VertexBuffer VertexBuffer { get; }
C++ public:
property VertexBuffer^ VertexBuffer {
        VertexBuffer^ get();
}
JScript public function get VertexBuffer() : VertexBuffer

Property Value

Microsoft.DirectX.Direct3D.VertexBuffer
A VertexBuffer object that contains the vertex data associated with the mesh.

This property is read-only. 

Remarks

Exceptions

InvalidCallException

The method call is invalid. For example, a method's parameter might contain an invalid value.

How Do I...?

Compute a Bounding Sphere from a Mesh

This example shows how to generate a simple bounding sphere around a 3-D object, using the Geometry.ComputeBoundingSphere method. A bounding sphere has many possible uses in 3-D graphics; for example, to help test whether one 3-D object intersects with another.

In the following C# code example, a vertex buffer is created from the vertex data of the mesh object. The new vertex buffer is then locked so that Geometry algorithms can be computed on it. The output of the ComputeBoundingSphere is the radius from the center to the farthest extremity of the mesh object. The mesh object is assumed to be a valid mesh loaded with Mesh.FromFile.

              [C#]
              

float objectRadius = 0.0f;
Vector3 objectCenter = new Vector3();

using (VertexBuffer vb = Mesh.VertexBuffer)
{
    GraphicsStream vertexData = vb.Lock(0, 0, LockFlags.None);
    objectRadius = Geometry.ComputeBoundingSphere(vertexData,
                                                  mesh.NumberVertices,
                                                  mesh.VertexFormat,
                                                  out objectCenter);
    vb.Unlock();
}

Applies To

Mesh, ProgressiveMesh