3d models and meshes asst. prof. rujchai ung-arunyawee coe, kku
TRANSCRIPT
![Page 1: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/1.jpg)
3D Models and Meshes
Asst. Prof. Rujchai Ung-arunyawee
COE, KKU
![Page 2: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/2.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/3.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/4.jpg)
Adding a model file
![Page 5: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/5.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/6.jpg)
Loading model
In the LoadContent method
myModel = Content.Load<Model>("Cube");
![Page 7: 3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/7.jpg)
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](https://reader036.vdocument.in/reader036/viewer/2022082518/56649f505503460f94c726fc/html5/thumbnails/8.jpg)
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();}