Share via


Mesh.FromFile

FromFile メソッド

使用例

  • メッシュを基にしたテクスチャの作成
  • ファイルからのメッシュのロード

.x ファイルからメッシュをロードする。

オーバーロード リスト

public Mesh FromFile (String, MeshFlags, Device, EffectInstance)
public Mesh FromFile (String, MeshFlags, Device, GraphicsStream, EffectInstance)
public Mesh FromFile (String, MeshFlags, Device, ExtendedMaterial, EffectInstance)
public Mesh FromFile (String, MeshFlags, Device)
public Mesh FromFile (String, MeshFlags, Device, GraphicsStream)
public Mesh FromFile (String, MeshFlags, Device, ExtendedMaterial)
public Mesh FromFile (String, MeshFlags, Device, GraphicsStream, ExtendedMaterial)
public Mesh FromFile (String, MeshFlags, Device, GraphicsStream, ExtendedMaterial, EffectInstance)

使用例

メッシュを基にしたテクスチャの作成

この例は、メッシュから作成されたテクスチャ オブジェクトに対し、ビットマップ化されたテクスチャ ファイルを適用する方法である。

アプリケーション定義の OnResetMeshDevice メソッドは次の内容を実行する。

  1. メッシュ要素は、Mesh.FromFile(String,MeshFlags,Device,ExtendedMaterial[]) を使ってファイルからロードする。
  2. ExtendedMaterial マテリアル バッファにファイルのデータを書き込む。
  3. テクスチャ名およびマテリアル プロパティは、Material3D を使って、マテリアル バッファから抽出する。
  4. ファイルから取得したテクスチャ値は FromFile(Device,String) を使って、各メッシュ要素に適用する。
using Microsoft.DirectX.Direct3D;

public class Meshes : System.Windows.Forms.Form
{
    // Global variables for this project
    Device device = null;              // Rendering device
    Mesh mesh = null;                  // Mesh object
    Direct3D.Material[] meshMaterials; // Materials structure for mesh
    Texture[] meshTextures;            // Textures structure for mesh

    public bool InitializeGraphics()   // Initialize the Direct3D object
    {
        .
        .
        .
        // Call method to reset mesh device
        device.DeviceReset += new System.EventHandler(this.OnResetMeshDevice);
        .
        .
        .
    }
    
    // Mesh device reset method
    public void OnResetMeshDevice(object sender, EventArgs e) 
    {
        ExtendedMaterial[] materials = null;
        Device dev = (Device)sender;
        
        // Set up the directory to load the proper data
        System.IO.Directory.SetCurrentDirectory(
                 System.Windows.Forms.Application.StartupPath +  @"\..\..\");
        
        // Load the mesh from the specified file
        mesh = Mesh.FromFile("tiger.x", MeshFlags.SystemMem,
                             device, out materials);

        // Extract texture names and material properties from material buffer
        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
            meshMaterials[i].Ambient = meshMaterials[i].Diffuse;
            
            // Create the texture
            meshTextures[i] = TextureLoader.FromFile(dev,
                                            materials[i].TextureFilename);
        }
        .
        .
        .
    }
    
    static void Main()
    {
        Meshes frm = new Meshes();
        if (!frm.InitializeGraphics())
        {
            // Error handling
        }
        System.Windows.Forms.Application.Run(frm);
    }
}

ファイルからのメッシュのロード

この例では、マテリアル構造体を作成し、ファイルからメッシュをロードする。

このコードでは、まず Device と、ロードされたメッシュ データを格納する ExtendedMaterial 構造体を作成する。

Mesh.FromFile(String,MeshFlags,Device,ExtendedMaterial[]) メソッドを使って、ローカル ファイルをロードする。MeshFlags 列挙の SystemMemory 定数は、頂点バッファおよびインデックス バッファのためにシステム メモリ (ページング可能な RAM 以外) を使うように指定する。

FromFile(String,MeshFlags,Device,ExtendedMaterial[]) は、ファイルからメッシュ データをロードするために使う、オーバーロードされた 8 つの FromFile メソッドの内の 1 つである。

using Microsoft.DirectX.Direct3D;

public class Meshes : Form
{
    // Global variables for this project
    Device device = null;   // Rendering device
    PresentParameters presentParams = new PresentParameters();
    .
    .
    .
    // Create the Device object
    device = new Device(0,
                        DeviceType.Hardware,
                        this,
                        CreateFlags.SoftwareVertexProcessing,
                        presentParams);
    ExtendedMaterial[] materials = null;

    // Load the mesh from the specified file
    mesh = Mesh.FromFile("tiger.x",
                        MeshFlags.SystemMemory,
                        device,
                        out materials);
    .
    .
    .
}

© 2002 Microsoft Corporation. All rights reserved. Terms of use.