Blender から生成された Cube to .obj ファイルを取得しました。このように:o cube_cube.001
v -1.000000 -1.000000 -1.000000
v
1.000000 -1.000000 -1.000000
V 1.000000 -1.000000 1.000000
V
-1.000000 -1.000000 1.000000
V -1.000000 1.0000
-1.0000000000000000000000000000000000000000000000000000000000000000000000 -10000000000000000 1.000000 VN
0.000000 0.000000 -1.000000 VN
1.000000
0.000000 0.000000
VN 0.000000 0.000000 1.000000 VN -1.000000 0.0000 0.000000 VN 0.000000
-1.000000
0.000000 VN 0.0000000000000000000000
USEMTL
NONINE
NONINE
SS OUSEMTLなし7//2 2//2
f 7//3 8//3 3//3
f 8//4 5//4 4//4
f 1//5 2//5 4//5
f 8//6 7//6 5//6
f 6//1 2//1 1/ /1
f 7//2 3//2 2//2
f 8//3 4//3 3//3
f 5//4 1//4 4//4
f 2//5 3//5 4//5
f 7//6 6//6 5//6
頂点を行ごとにロードし、配列に格納します。次に、インデックス(私が推測するように「f」で始まる行)がインデックス配列に格納されるため、{4、5、0、6、7 ...}(配列内の頂点の位置のために1ずつ減少)のようなものになり、配列を作成しますVertexPositionColors.
しかし、プリミティブを描画すると、立方体が奇妙に変形します。描画方法:
GraphicsDevice.Clear(Color.CornflowerBlue);
GraphicsDevice.DepthStencilState = DepthStencilState.Default;
effect.World = world;
effect.View = view;
effect.Projection = projection;
effect.VertexColorEnabled = true;
RasterizerState rs = new RasterizerState();
rs.CullMode = CullMode.None;
rs.FillMode = FillMode.WireFrame;
GraphicsDevice.RasterizerState = rs;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
pass.Apply();
GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, model.VertexPositionColors, 0, model.VertexPositionColors.Length, model.Indicies, 0, model.Indicies.Length / 3, model.VertexDeclarations);
}
出力 http://i.imgur.com/3pLj0U9.png
[解決策] インポート アルゴリズムが生成するものを確認します。繰り返しが悪いため、インデックスが台無しになりました。私の悪い:)