Next we will use Mesh to read. X file, about. there are actually a lot of X Files. We can use external tools such as 3DS MAX to create them. 3ds file, and then convert. X file. If you use 3DS at the same time, you may ask, what should we do with the material? You don't have to worry, The. X file can automatically contain materials, and animations, so we can use Mesh to make it easy for us to use 3DS MAX in the game.
. The X file allows custom extensions. Of course, we will talk about this in the future. Let's take a look at how to use it first. By the way, there is also a file format that is used more often. md3 format file, that is, the file used by Quake3. If you have the opportunity, I will also talk about it.
For 3DS files and. X conversions, see the article http://www.gameres.com/Articles/Program/Visual/3D/3DinApp.htm at the GameRes website.
The following process is simple and you cannot believe it. Please refer:
Private Mesh mesh = null; // create a Mesh object
Private Material [] meshMaterials; // used to save Materials
Private Texture [] meshTextures; // used to save the Texture
Private void LoadMesh (string file)
{
ExtendedMaterial [] mtrl; // saves the Mesh subset information and Material information
// Load our mesh
Mesh = Mesh. FromFile (file, MeshFlags. Managed, device, out mtrl );
// If we have any materials, store them
If (mtrl! = Null) & (mtrl. Length> 0 ))
{
MeshMaterials = new Material [mtrl. Length];