Material 構造体

Material 構造体

使用例

  • メッシュを基にしたテクスチャの作成
  • デバイスのマテリアル プロパティの設定

マテリアルのプロパティを指定する。

定義

Visual Basic Public Structure Material
C# public struct Material
Managed C++ public __value struct Material
JScript 構造体は使えるが、独自に定義することはできない。

メンバ テーブル

次のテーブルは、Material オブジェクトによって公開されているメンバの一覧である。左側のタブをクリックし、表示したいメンバの種類を選ぶこと。

メソッド

メソッド 説明
Material オブジェクトの新しいインスタンスを初期化する。
ToString このインスタンスの文字列表現を取得する。

プロパティ

プロパティ 説明
Ambient アンビエント色を指定する値を取得または設定する。
Diffuse ディフューズ色を指定する値を取得または設定する。
Emissive エミッション色を指定する値を取得または設定する。
Specular スペキュラ色を指定する値を取得または設定する。
SpecularSharpness スペキュラ ハイライトの鮮明度を指定する浮動小数点値を取得または設定する。値が大きくなるにつれて、ハイライトはより鮮明になる。

使用例

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

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

アプリケーション定義の 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);
    }
}

デバイスのマテリアル プロパティの設定

この例では、Microsoft® Direct3D® オブジェクトのマテリアル プロパティを設定する方法を示す。

このコードでは、最初に Material 構造体を作成する。次に、構造体の Diffuse プロパティおよび Ambient プロパティを、システム定義の白色に設定する。最後に、Device.Material プロパティが白色の Diffuse および Ambient カラー プロパティを受け取る。

using Microsoft.DirectX.Direct3D;

public class Lights : Form
{
    // Global variables for this project
    Device device = null; // Rendering device
    .
    .
    .
    private void SetupLights() //  Method to set up lighting of the object
    {
        // Set col to system-defined white color
        System.Drawing.Color col = System.Drawing.Color.White; 

        // Set up a material.
        // The material here has the diffuse and ambient colors set to white.
        // Note that only one material can be used at a time.
        Direct3D.Material mtrl = new Direct3D.Material();
        mtrl.Diffuse = col;
        mtrl.Ambient = col;
        device.Material = mtrl;
    }
}

構造体の情報

名前空間 Microsoft.DirectX.Direct3D
アセンブリ Microsoft.DirectX.Direct3D (microsoft.directx.direct3d.dll)
厳密名 Microsoft.DirectX.Direct3D,  Version=0293,  Culture=neutral,  PublicKeyToken=d3231b57b74a1492

参照

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