Cloning Mesh Data

So you've finally gotten your mesh loaded and rendered in your scene. The scene has a few lights, and yet your mesh just appears completely black. Glancing at the properties of your mesh, you notice the vertex format doesn't include normal data, which as we already know is required for lighting calculations.

What we need is a simple way to take all of the mesh data we already have, and simply add the normal data to it. If you guessed that there is already a mechanism for this, then you've guessed correctly. Look at Listing 7.1:

Listing 7.1. Ensuring That Your Mesh Contains Normal Data
 // Check if mesh doesn't include normal data if ((mesh.VertexFormat & VertexFormats.Normal) != VertexFormats.Normal) { Mesh tempMesh = mesh.Clone(mesh.Options.Value, ...

Get Managed DirectX® 9 Kick Start: Graphics and Game Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.