Tutorial 7 - Loading MeshesBy Pieter Germishuys, January 4 2006 |
Loading models is what we
are going to do today. We are going
to be using the .x file format for simplicity and use the set of helper classes
and functions in direct3d.
What is a model?
a Model is a series of vertices that define a mesh and that being
a series of polygons grouped together to form a surface.
What do we need to know?
We will need to remember the following steps
1 . a Mesh object
2 . a Texture object
3 . a Material associated with the texture
What this means is the following, When we create a mesh we want to make it look
nice and realistic so we assign a texture to it. We also want light to react
differently to certain objects/entities in our game, sometimes we want smoothness
and sometimes we want our objects to give off a glow, this is what our material
does.
The code
Declaring your objects.
| private ExtendedMaterial[]
eMaterials = null; private Material[] materials; private Texture[] textures; private Mesh mesh; private Matrix matWorld; |
The constructor that will initialize our objects and load our mesh.
| public
Core() { window = new Window(); //Set 1 Light window.D3DDevice.Lights[0].Type = LightType.Directional; window.D3DDevice.Lights[0].Direction = new Vector3(0.0f, 0.0f, 1.0f); window.D3DDevice.Lights[0].Enabled = true; //Enable lighting in our
engine //Open the mesh. This
mesh can be found in your samples directory of the DirectX SDK |
| private
void Render() { window.BeginRender(Color.Black); //for the amount of materials we have, set each texture/material and render the mesh for(int i = 0;i < materials.Length; i++) { window.D3DDevice.Material = materials[i]; window.D3DDevice.SetTexture(0, textures[i]); /* Draws a subset of a mesh: * An attribute table is used to identify areas of the mesh that need to be drawn with different textures, render states, and materials. The application can use the attribute table to hide portions of a mesh by leaving out a given attribute identifier (attributeID) when drawing the frame. Attribute tables can also be used for application defined purposes.*/ mesh.DrawSubset(i); } window.FinishRender(); } |
Files for this tutorial
| Filename | Size |
|
|
655.0 KB |
