Download presentation
Presentation is loading. Please wait.
Published byNathan Sims Modified over 9 years ago
1
3D Models and Meshes Asst. Prof. Rujchai Ung-arunyawee COE, KKU
2
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.
3
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.
4
Adding a model file
5
Declare a model variable public class Game1 : Microsoft.Xna.Framework.Game { GraphicsDeviceManager graphics; ContentManager content; BasicEffect effect; VertexBuffer vertexBuffer; Model myModel; …………… }
6
Loading model In the LoadContent method myModel = Content.Load ("Cube");
7
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 mesh mesh.Draw(); }
8
Model Transformation foreach (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(); }
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.