Mesh.FromFile(String,MeshFlags,Device,EffectInstance)
FromFile メソッド
使用例
- メッシュを基にしたテクスチャの作成
- ファイルからのメッシュのロード
.x ファイルからメッシュをロードする。
定義
Visual Basic | Public Shared Function FromFile( _ ByVal filename As String, _ ByVal options As MeshFlags, _ ByVal device As Device, _ ByRef effects As EffectInstance _ ) As Mesh |
C# | public static Mesh FromFile( string filename, MeshFlags options, Device device, ref EffectInstance effects ); |
Managed C++ | public: static Mesh* FromFile( String* filename, MeshFlags options, Device* device, EffectInstance* effects ); |
JScript | public static function FromFile( filename : String, options : MeshFlags, device : Device, effects : EffectInstance ) : Mesh; |
パラメータ
filename | System.String. |
options | Microsoft.DirectX.Direct3D.MeshFlags. |
device | Microsoft.DirectX.Direct3D.Device. |
effects | Microsoft.DirectX.Direct3D.EffectInstance. |
戻り値
Microsoft.DirectX.Direct3D.Mesh.
使用例
メッシュを基にしたテクスチャの作成
この例は、メッシュから作成されたテクスチャ オブジェクトに対し、ビットマップ化されたテクスチャ ファイルを適用する方法である。
アプリケーション定義の OnResetMeshDevice メソッドは次の内容を実行する。
メッシュ要素は、Mesh.FromFile(String,MeshFlags,Device,ExtendedMaterial[]) を使ってファイルからロードする。
ExtendedMaterial マテリアル バッファにファイルのデータを書き込む。
テクスチャ名およびマテリアル プロパティは、Material3D を使って、マテリアル バッファから抽出する。
ファイルから取得したテクスチャ値は 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.