2012-08-03 2 views
0

마침내 나는 무엇인가가 표시됩니다. 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); 
+0

... 그것은 컬 모드가 아닙니다 ... 그냥 체크 ... 여전히 검색 – zeppeldep

+0

당신은'DrawIndexedPrimitives'에 대한 호출과 인덱스와 버텍스 버퍼를 설정하는 방법을 보여 주어야합니다. – Dervall

+0

ok ... 포함 ... 고통스럽게 ... 미안 ... 도와 주려고. – zeppeldep

답변

0

일반 계산이 정확하고 틀릴지라도 일어날 유일한 일은 삼각형이 잘못된 번개를 받게된다는 것입니다.

그 자체가 중복되는 들어오는 정점의 순서와 정확하게 일치하는 인덱스를 사용하고 있습니다. 인덱스를 전혀 설정하지 않고 기본 카운트 대신 DrawPrimitives을 사용하면 차이가 있습니까?

그 외의 데이터는 귀하가 제공 한 데이터가 유효합니까? 정점 위치가 올바르게 설정되어 있습니까?

+0

thx a stack ... 예. DrawPrimitives를 시도했습니다. 동일한 결과 (오류 메시지 없음)가 생성되었습니다. 버텍스 위치가 정확합니다. 검사를 제공 할 위치를 보여주는 spritebtach 텍스트가 포함되었습니다. 적어도 지금은 삼각형이 하나 있습니다 ... 4 시간 전보다 더 좋은 삼각형입니다. – zeppeldep

+0

MeshBuilder를 시도해 보겠다고 생각합니다.하지만 .. UV도 있습니다. 이러한 불규칙한 삼각형을 사용하여 UV를 설정하는 방법을 모르겠습니다. – zeppeldep

+0

여기에서 샘플 DXF로 프로젝트를 업로드했습니다 : http : //www.4shared. co.kr/zip/cGgGVIAt/KBC3DI08.html ... 제발 내가 어쩌면 당신이 뭘 잘못 본지보십시오 :( – zeppeldep