前田稔(Maeda Minoru)の超初心者のプログラム入門
ファイル名 | 説明 |
---|---|
DXCone.cs | コーンのメッシュ(cone.x)を描画する |
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 void OnResetDevice(object sender, EventArgs e) { Device dev = (Device)sender; // Turn on the zbuffer dev.RenderState.ZBufferEnable = true; // Load the mesh from the specified file ExtendedMaterial[] materials = null; Directory.SetCurrentDirectory("c:\\data\\xfile\\"); mesh = Mesh.FromFile("cone.x", MeshFlags.SystemMemory, device, out materials); // Allocate a material/texture arrays meshMaterials = new Material[materials.Length]; meshTextures = new Texture[materials.Length]; // Copy the materials and load the textures for(int i = 0; i < meshMaterials.Length; i++) { meshMaterials[i] = materials[i].Material3D; meshMaterials[i].AmbientColor = meshMaterials[i].DiffuseColor; if ( (materials[i].TextureFilename != null) && (materials[i].TextureFilename.Length > 0) ) { // Create the texture meshTextures[i] = TextureLoader.FromFile(dev, materials[i].TextureFilename); } } } |
private void Render() { if (device == null) return; if (pause) return; //Clear the backbuffer to a blue color device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, System.Drawing.Color.LightGray, 1.0f, 0); //Begin the scene device.BeginScene(); SetupLights(); // Setup the world, view, and projection matrices SetupMatrices(); // Meshes are divided into subsets, one for each material. Render them in for( int i=0; i<meshMaterials.Length; i++ ) { // Set the material and texture for this subset device.Material = meshMaterials[i]; device.SetTexture(0, meshTextures[i]); // Draw the mesh subset mesh.DrawSubset(i); } //End the scene device.EndScene(); device.Present(); } |
C:\Program Files\Microsoft DirectX SDK (December 2006)\Samples\Managed\Direct3D\EnhancedMesh |
BadImageFormatException はハンドルされませんでした。 |
Directory.SetCurrentDirectory(Application.StartupPath + @"\..\..\"); |
Directory.SetCurrentDirectory(Application.StartupPath + @"\..\..\..\"); |
mesh = Mesh.FromFile("c:\\data\\xfile\\cone.x", MeshFlags.SystemMemory, device, out materials); |
Directory.SetCurrentDirectory("c:\\data\\xfile\\"); mesh = Mesh.FromFile("cone.x", MeshFlags.SystemMemory, device, out materials); |