2012-11-06 5 views
1

lib3ds가 파싱 한 파일에서 정점을 얻으려고하고 있는데 많은 문제가 있습니다. 즉, 저는 정점을 얻지 못했습니다. 나는이 작업을 수행하려고하는 코드는 다음과 같습니다 Lib3ds를 사용하여 정점 배열 얻기

//loop through meshes 
for(int i = 0; i < model->meshes_size; i++) 
{ 
    Lib3dsMesh* mesh = model->meshes[i]; 
    //loop through the faces in that mesh 
    for(int j = 0; j < model->meshes[i]->nfaces; j++) 
    { 
     int testv = mesh->nvertices; 
     Lib3dsFace face = mesh->faces[i]; 
     //loop through the vertices in each face 
     for(int k = 0; k < 3; k++) 
     { 
      myVertices[index] = model->meshes[i]->faces[j].index[0]; 
      myVertices[index + 1] = model->meshes[i]->faces[j].index[1]; 
      myVertices[index + 2] = model->meshes[i]->faces[j].index[2]; 

      index += 3; 
     } 
    } 
} 

불행하게도 lib3ds에 대한 문서가 존재하고 그래서 나는이 알아낼 수 없습니다

. 이 라이브러리를 사용하여 정점 배열을 얻는 방법에 대해 어떻게 생각합니까? 또한 3ds는 오래되었지만 라이브러리가 설정된 형식과 방식이 내 용도에 맞다는 것을 알고 있으므로 다른 형식으로 전환하지 마십시오.

답변

2

누군가이 문제가있는 경우 다음은 lib3ds에서 정점을 가져온 다음 단일 정점 배열에로드하는 코드입니다. 배열은 단지, Z2 등 폼 X, Y, Z, X2, Y2의 데이터를 포함

void Renderer3ds::loadVertices(string fileName) 
{ 
    Lib3dsFile* model = lib3ds_file_open(fileName.c_str()); 

    if(!model) 
    { 
     throw strcat("Unable to load ", fileName.c_str()); 
    } 

    int faces = getNumFaces(model); 
    myNumVertices = faces * 3; 
    myVertices = new double[myNumVertices * 3]; 

    int index = 0; 

    //loop through meshes 
    for(int i = 0; i < model->meshes_size; i++) 
    { 
     Lib3dsMesh* mesh = model->meshes[i]; 
     //loop through the faces in that mesh 
     for(int j = 0; j < mesh->nfaces; j++) 
     { 
      Lib3dsFace face = mesh->faces[j]; 
      //loop through the vertices in each face 
      for(int k = 0; k < 3; k++) 
      { 
       myVertices[index] = mesh->vertices[face.index[k]][0]; 
       myVertices[index + 1] = mesh->vertices[face.index[k]][1]; 
       myVertices[index + 2] = mesh->vertices[face.index[k]][2]; 

       index += 3; 
      } 
     } 
    } 
} 
+0

수정 요청 : nmeshes로 변경 meshes_size이 저자는 이런 맥락에서 무엇을 의미하기 때문이다. –

+0

또한 Lib3dsFile 필드입니까? – Pat

+0

죄송합니다.이 주제에 익숙하지 않지만 익명으로 수정되었습니다. 나는 그것이 거부 될 것이라는 것을 알았 기 때문에이 스레드의 미래 방문자들에게 결코 적은 것을 결코 알리지 않을 것이라고 생각했습니다. –