1

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 が古いことは認識していますが、フォーマットとライブラリのセットアップ方法は私の目的に合っているため、別のフォーマットに切り替えることは提案しないでください。

4

1 に答える 1

2

誰かがこの問題を抱えている場合に備えて、lib3ds から頂点を取得し、それらを単一の頂点配列にロードするコードを次に示します。配列には、x、y、z、x2、y2、z2 などの形式のデータが含まれているだけです。

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;
            }
        }
    }
}
于 2012-11-06T20:15:47.820 に答える