Friday, August 2, 2013

How to import a 3D object from Maya or 3DMax to XNA

                             First, export the object in FBX file format in Maya or 3DMax. Create a new visual studio project. Then add the fbx file to your visual studio project content folder. You can use add->existing item or just copy and paste the file. Then add a new variable to render this model.
Model model;

                               Then update your LoadContent() method to instantiate this object. My file name is box.fbx but in here we use the file name only.

model = Content.Load<Model>("box");
(model.Meshes[0].Effects[0] as BasicEffect).EnableDefaultLighting();

                            Finally, You have to render the object using a camera. Add the following code to your draw method after the call to clear.

model.Draw(Matrix.Identity, Matrix.CreateLookAt(new Vector3(2, 3, -5), Vector3.Zero, Vector3.Up), Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1.0f, 100.0f));

                              Run the project. Now you will see the 3d object. If you want't to move the camera, change the camera position. For camera look at, I have used Vector3.Zero. You can use any value for this.

No comments:

Post a Comment