差分

ナビゲーションに移動 検索に移動
ページの作成:「テクスチャを貼らなければ頂点カラーで塗られ、テクスチャを貼ればテクスチャマッピングバンプマッピングも...」
[[テクスチャ]]を貼らなければ[[頂点カラー]]で塗られ、テクスチャを貼れば[[テクスチャマッピング]]も[[バンプマッピング]]もされる。
そんな位置と[[頂点カラー]]と[[法線]]と[[UV座標]]を持つゴージャスなカスタム頂点フォーマット。
個人的には[[ゲーム]]ではなく細胞を3D表示するのにMonoGameを使っているので、動的に頂点を生成して、かつテクスチャはほぼ利用しないが、稀にマスク的にテクスチャマッピングとバンプマッピングを使いたいこともある。

MonoGameに標準搭載されている頂点フォーマット構造体たち。
{| class="wikitable"
|-
| VertexPosition || 位置
|-
| VertexPositionColor || 位置と頂点カラー
|-
| VertexPositionColorTexture || 位置と頂点カラーとUV座標
|-
| VertexPositionNormalTexture|| 位置と法線とUV座標
|-
| VertexPositionTexture || 位置とUV座標
|}

無いんだが、これが。

そんなときはIVertexTypeインターフェイスを実装するだけでカスタム頂点フォーマット構造体を作れるそうだ。
<source>
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

public struct VertexPositionColorNormalTexture : IVertexType
{
public Vector3 Position;
public Color Color;
public Vector3 Normal;
public Vector2 TextureCoordinate;

public readonly static VertexDeclaration VertexDeclaration = new VertexDeclaration(
new VertexElement(0, VertexElementFormat.Vector3, VertexElementUsage.Position, 0),
new VertexElement((sizeof(float) * 3), VertexElementFormat.Color, VertexElementUsage.Color, 0),
new VertexElement((sizeof(float) * 3) + (4), VertexElementFormat.Vector3, VertexElementUsage.Normal, 0),
new VertexElement((sizeof(float) * 3 * 2) + (4), VertexElementFormat.Vector2, VertexElementUsage.TextureCoordinate, 0)
);

public VertexPositionColorNormalTexture(Vector3 position, Color color, Vector3 normal, Vector2 textureCoordinate)
{
Position = position;
Color = color;
normal.Normalize();
Normal = normal;
TextureCoordinate = textureCoordinate;
}

VertexDeclaration IVertexType.VertexDeclaration
{
get { return VertexDeclaration; }
}
}
}
</source>

[[category: MonoGame]]
匿名利用者

案内メニュー