8
3D Models and Meshes Asst. Prof. Rujchai Ung- arunyawee COE, KKU

3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

Embed Size (px)

Citation preview

Page 1: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

3D Models and Meshes

Asst. Prof. Rujchai Ung-arunyawee

COE, KKU

Page 2: 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.

Page 3: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

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.

Page 4: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

Adding a model file

Page 5: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

Declare a model variable

public class Game1 : Microsoft.Xna.Framework.Game{ GraphicsDeviceManager graphics; ContentManager content; BasicEffect effect; VertexBuffer vertexBuffer; Model myModel;

…………… ……………}

Page 6: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

Loading model

In the LoadContent method

myModel = Content.Load<Model>("Cube");

Page 7: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

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();

}

Page 8: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU

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();}