Upload
nathan-sims
View
216
Download
0
Embed Size (px)
Citation preview
3D Models and Meshes
Asst. Prof. Rujchai Ung-arunyawee
COE, KKU
3D Models
Simply called Models a hierarchy of meshes, which can be
rendered independently. mesh is a collection of interconnected
vertices, along with some rendering information.
XNA provides special classes to manipulatemodels and meshes: Model and ModelMesh.
Using 3D models in XNA Add existing item of the model file (.x
or .fxb) to the project. Declare a model variable as a member of
the game class. Load a model with content manager and
assign it to the model variable. Draw each mesh in the model.
Adding a model file
Declare a model variable
public class Game1 : Microsoft.Xna.Framework.Game{ GraphicsDeviceManager graphics; ContentManager content; BasicEffect effect; VertexBuffer vertexBuffer; Model myModel;
…………… ……………}
Loading model
In the LoadContent method
myModel = Content.Load<Model>("Cube");
Drawing model
In the Draw method, run through all meshes in the model and draw each one
foreach (ModelMesh mesh in myModel.Meshes){
// Draw the current meshmesh.Draw();
}
Model Transformationforeach (ModelMesh mesh in myModel.Meshes){ foreach (BasicEffect eff in mesh.Effects) {
eff.World *= Matrix.CreateScale(0.5f); eff.View = effect.View;
eff.Projection = effect.Projection; eff.EnableDefaultLighting(); } mesh.Draw();}