Assimp не считывает информацию о координатах текстуры из файла слоя

Я пытаюсь загрузить некоторые файлы слоев с помощью assimp. Я получаю расположение вершин, и нормали также загружаются правильно (я вижу, что они появляются на экране, так что все в порядке), однако кажется, что координаты текстуры никогда не загружаются. Это приводит к тому, что текстуры не отображаются на моделях, а мои диффузные цвета чтобы появиться на них вместо текстуры.

Я просмотрел свой код и обнаружил, что проблема в классе загрузчика assimp, который я создал. mTextureCoords [0] [индекс] полностью равен нулю.

Я попытался изменить if вокруг назначаемых координат текстуры, но я считаю, что это правильно?

Вот фрагмент метода загрузчика, который содержит код для получения координат текстуры.

    if (scene->HasMeshes()) {   //Check to see if the filename was valid

        aiMesh* aiMesh = *scene->mMeshes;

        theMesh.numberOfVertices = aiMesh->mNumVertices;

        //Create the number of vertices that this mesh has.
        theMesh.pVertices = new sVertex_xyz_rgba_n_uv2_bt[theMesh.numberOfVertices];

        theMesh.minXYZ.x = aiMesh->mVertices[0].x;
        theMesh.minXYZ.y = aiMesh->mVertices[0].y;
        theMesh.minXYZ.z = aiMesh->mVertices[0].z;

        theMesh.maxXYZ = theMesh.minXYZ;

        for (unsigned int index = 0; index != theMesh.numberOfVertices; index++) {
            theMesh.pVertices[index].x = aiMesh->mVertices[index].x;
            theMesh.pVertices[index].y = aiMesh->mVertices[index].y;
            theMesh.pVertices[index].z = aiMesh->mVertices[index].z;

            if (theMesh.pVertices[index].x < theMesh.minXYZ.x) { theMesh.minXYZ.x = theMesh.pVertices[index].x; }
            if (theMesh.pVertices[index].y < theMesh.minXYZ.y) { theMesh.minXYZ.y = theMesh.pVertices[index].y; }
            if (theMesh.pVertices[index].z < theMesh.minXYZ.z) { theMesh.minXYZ.z = theMesh.pVertices[index].z; }

            if (theMesh.pVertices[index].x > theMesh.maxXYZ.x) { theMesh.maxXYZ.x = theMesh.pVertices[index].x; }
            if (theMesh.pVertices[index].y > theMesh.maxXYZ.y) { theMesh.maxXYZ.y = theMesh.pVertices[index].y; }
            if (theMesh.pVertices[index].z > theMesh.maxXYZ.z) { theMesh.maxXYZ.z = theMesh.pVertices[index].z; }


            theMesh.pVertices[index].nx = aiMesh->mNormals[index].x;
            theMesh.pVertices[index].ny = aiMesh->mNormals[index].y;
            theMesh.pVertices[index].nz = aiMesh->mNormals[index].z;


            int numUVComponents = aiMesh->mNumUVComponents[0];

            if (numUVComponents == 2) {
                theMesh.pVertices[index].u1 = aiMesh->mTextureCoords[0][index].x;
                theMesh.pVertices[index].v1 = aiMesh->mTextureCoords[0][index].y;
            }
        }

        theMesh.numberOfTriangles = scene->mMeshes[0]->mNumFaces;
        theMesh.pTriangles = new cTriangle[theMesh.numberOfTriangles];

        //Copy the triangle vertex information (indices)
        for (int triIndex = 0; triIndex != theMesh.numberOfTriangles; triIndex++) {
            theMesh.pTriangles[triIndex].vertex_ID_0 = aiMesh->mFaces[triIndex].mIndices[0];
            theMesh.pTriangles[triIndex].vertex_ID_1 = aiMesh->mFaces[triIndex].mIndices[1];
            theMesh.pTriangles[triIndex].vertex_ID_2 = aiMesh->mFaces[triIndex].mIndices[2];
        }
    }

и вот фрагмент файла модели, который я пытаюсь загрузить с помощью assimp с заголовком и несколькими строками вершин, нормалей и uvs.

ply
format ascii 1.0
comment VCGLIB generated
element vertex 289
property float x
property float y
property float z
property float nx
property float ny
property float nz
property float texture_u
property float texture_v
element face 512
property list uchar int vertex_indices
end_header
-400 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.000000
-350 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.062500
-300 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.125000
-250 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.187500
-200 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.250000
-150 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.312500
-100 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.375000
-50 1.748456e-05 400 0 0.25 -1.092785e-08 1.000000 0.437500

Надеюсь, кто-нибудь знает, где я лажаю =) Заранее спасибо!


person Kingrune    schedule 01.04.2019    source источник


Ответы (1)


Все еще не уверен, почему assimp не может загрузить слой. Но я подтвердил, что мой код работает для файлов FBX. может ассимп не совместим с этим стилем?

person Kingrune    schedule 08.04.2019