마침내 나는 무엇인가가 표시됩니다. graphics.GraphicsDevice.DrawIndexedPrimitives ... 다음 문제는 ... 하나의 삼각형 만 표시됩니다. 데이터 세트는 약 200 삼각형입니다. 세 연속 벡터가 삼각형면을 형성하도록 데이터를 포맷했습니다. 이들은 불규칙한 모양을 형성하는 불규칙한 삼각형입니다. 꼭 꼭지점의 색인 생성을 완전히 이해하지 못합니다. 3 개의 각 인덱스가 삼각형을 이룬 것처럼 보입니다. .불규칙한 삼각형 꼭지점 인덱스
int i4 = -1;
indices = new int[xData1.Count];
for (int i2 = 0; i2 < xData1.Count; i2++)
{
i4++;
cubeVertices[i4].Position = new Vector3((float)xData1[i2][0], (float)xData1[i2][1], (float)xData1[i2][2]);
cubeVertices[i4].Color = Color.LawnGreen;
indices[i4] = i4;
}
이 같은 아마 잘못 .. 그때 법선을 제공하기 위해 라이 머스 정상 CALC를 사용 .. 인덱스가 정점이 들어오는 일치 만들기 : 그 그렇다면 다음 인덱스 데이터가 들어오는 일치이게했다 그의 예는 다음과 같이 인덱스 당 6 정점을 사용하고있었습니다 (0120).
for (int i = 0; i < cubeVertices.Length; i++)
cubeVertices[i].Normal = new Vector3(0, 0, 0);
for (int i = 0; i < indices.Length/3; i++)
{
int index1 = indices[i * 3];
int index2 = indices[i * 3 + 1];
int index3 = indices[i * 3 + 2];
Vector3 side1 = cubeVertices[index1].Position - cubeVertices[index3].Position;
Vector3 side2 = cubeVertices[index1].Position - cubeVertices[index2].Position;
Vector3 normal = Vector3.Cross(side1, side2);
cubeVertices[index1].Normal += normal;
cubeVertices[index2].Normal += normal;
cubeVertices[index3].Normal += normal;
}
for (int i = 0; i < cubeVertices.Length; i++)
cubeVertices[i].Normal.Normalize();
여기에 몇 가지 수정해야 할 사항이 있습니까? 난 단지
private void CopyToBuffers()
{
vertexBuffer = new VertexBuffer(graphics.GraphicsDevice, VertexPositionColorNormal.VertexDeclaration,
cubeVertices.Length, BufferUsage.WriteOnly);
vertexBuffer.SetData(cubeVertices);
myIndexBuffer = new IndexBuffer(graphics.GraphicsDevice, typeof(int), indices.Length, BufferUsage.WriteOnly);
myIndexBuffer.SetData(indices);
}
... 백 개 삼각형 :(양해
public struct VertexPositionColorNormal
{
public Vector3 Position;
public Color Color;
public Vector3 Normal;
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)
);
}
에 대한 들으 몇 가지 중 하나를보고 있어요 ....
foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
{
basicEffect.World = world;
basicEffect.View = view;
basicEffect.Projection = proj;
pass.Apply();
graphics.GraphicsDevice.Indices = myIndexBuffer;
graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer);
graphics.GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0,
cubeVertices.Length, 0, indices.Length/3);
... 그것은 컬 모드가 아닙니다 ... 그냥 체크 ... 여전히 검색 – zeppeldep
당신은'DrawIndexedPrimitives'에 대한 호출과 인덱스와 버텍스 버퍼를 설정하는 방법을 보여 주어야합니다. – Dervall
ok ... 포함 ... 고통스럽게 ... 미안 ... 도와 주려고. – zeppeldep