如何将导出.X模型导入C#中
小弟是C#初学者,想知道如何将用3D导出的.X模型导入到C#中!`````
汗````
在线等`````希望有人回答!~~~``
------解决方案--------------------mamange directx
xna game
------解决方案--------------------using System;
using System.Drawing;
using System.ComponentModel;
using System.Windows.Forms;
using System.IO;
using Microsoft.DirectX;
using Microsoft.DirectX.Direct3D;
using Direct3D=Microsoft.DirectX.Direct3D;
namespace MeshesTutorial
{
public class Meshes : Form
{
Device device = null; // Our rendering device
Mesh mesh = null; // Our mesh object in sysmem
Direct3D.Material[] meshMaterials; // Materials for our mesh
Texture[] meshTextures; // Textures for our mesh
PresentParameters presentParams = new PresentParameters();
bool pause = false;
public Meshes()
{
// Set the initial size of our form
this.ClientSize = new System.Drawing.Size(400,300);
// And its caption
this.Text = "Direct3D Tutorial 6 - Meshes ";
}
bool InitializeGraphics()
{
// Get the current desktop display mode, so we can set up a back
// buffer of the same format
try
{
// Set up the structure used to create the D3DDevice. Since we are now
// using more complex geometry, we will create a device with a zbuffer.
presentParams.Windowed = true;
presentParams.SwapEffect = SwapEffect.Discard;
presentParams.EnableAutoDepthStencil = true;
presentParams.AutoDepthStencilFormat = DepthFormat.D16;
// Create the D3DDevice
device = new Device(0, DeviceType.Hardware, this, CreateFlags.SoftwareVertexProcessing, presentParams);
device.DeviceReset += new System.EventHandler(this.OnResetDevice);
this.OnResetDevice(device, null);
pause = false;
}
catch (DirectXException)
{
return false;
}
return true;
}
public void OnResetDevice(object sender, EventArgs e)
{
ExtendedMaterial[] materials = null;
// Set the directory up two to load the right data (since the default build location is bin\debug or bin\release
Directory.SetCurrentDirectory(Application.StartupPath + @ "\..\..\ ");
Device dev = (Device)sender;
// Turn on the zbuffer
dev.RenderState.ZBufferEnable = true;
// Turn on ambient lighting
dev.RenderState.Ambient = System.Drawing.Color.White;
// Load the mesh from the specified file
mesh = Mesh.FromFile( "tiger.x ", MeshFlags.SystemMemory, device, out materials);
if (meshTextures == null)
{
// We need to extract the material properties and texture names
meshTextures = new Texture[materials.Length];
meshMaterials = new Direct3D.Material[materials.Length];
for( int i=0; i <materials.Length; i++ )
{
meshMaterials[i] = materials[i].Material3D;
// Set the ambient color for the material