1
\$\begingroup\$

I'm trying to load a textured 3d model into my scene using assimp model loader.

The problem is that child meshes are not situated correctly (they don't have the correct transformations).

In brief: all the mTansform matrices are identity matrices, why would that be?

I'm using this code to render the model:

void recursive_render (const struct aiScene *sc, const struct aiNode* nd, float scale)
{
    unsigned int i;
    unsigned int n=0, t;
    aiMatrix4x4 m = nd->mTransformation;

    m.Scaling(aiVector3D(scale, scale, scale), m);

    // update transform
    m.Transpose();
    glPushMatrix();
    glMultMatrixf((float*)&m);

    // draw all meshes assigned to this node
    for (; n < nd->mNumMeshes; ++n)
    {
        const struct aiMesh* mesh = scene->mMeshes[nd->mMeshes[n]];
        apply_material(sc->mMaterials[mesh->mMaterialIndex]);

        if (mesh->HasBones()){
            printf("model has bones");
            abort();
        }

        if(mesh->mNormals == NULL)
        {
            glDisable(GL_LIGHTING);
        }
        else
        {
            glEnable(GL_LIGHTING);
        }

        if(mesh->mColors[0] != NULL)
        {
            glEnable(GL_COLOR_MATERIAL);
        }
        else
        {
            glDisable(GL_COLOR_MATERIAL);
        }

        for (t = 0; t < mesh->mNumFaces; ++t) {
            const struct aiFace* face = &mesh->mFaces[t];
            GLenum face_mode;

            switch(face->mNumIndices)
            {
                case 1: face_mode = GL_POINTS; break;
                case 2: face_mode = GL_LINES; break;
                case 3: face_mode = GL_TRIANGLES; break;
                default: face_mode = GL_POLYGON; break;
            }

            glBegin(face_mode);

            for(i = 0; i < face->mNumIndices; i++)// go through all vertices in face
            {
                 int vertexIndex = face->mIndices[i];// get group index for current index
                 if(mesh->mColors[0] != NULL)
                     Color4f(&mesh->mColors[0][vertexIndex]);
                 if(mesh->mNormals != NULL)
                     if(mesh->HasTextureCoords(0))//HasTextureCoords(texture_coordinates_set)
                     {
                         glTexCoord2f(mesh->mTextureCoords[0][vertexIndex].x, 1 - mesh->mTextureCoords[0][vertexIndex].y); //mTextureCoords[channel][vertex]
                     }
                     glNormal3fv(&mesh->mNormals[vertexIndex].x);
                     glVertex3fv(&mesh->mVertices[vertexIndex].x);
             }
             glEnd();
        }
    }
    // draw all children
    for (n = 0; n < nd->mNumChildren; ++n)
    {
         recursive_render(sc, nd->mChildren[n], scale);
    }
    glPopMatrix();
}

What's the problem in my code ?

I've added some code to abort the program if there's any bone in the meshes, but the program doesn't abort, this means : no bones, is that normal?

if (mesh->HasBones()){
    printf("model has bones");
    abort();
}

Note: I am using openGL & SFML & assimp

\$\endgroup\$

1 Answer 1

2
\$\begingroup\$

I figured it out

the problem is in the line:

m.Scaling(aiVector3D(scale, scale, scale), m);

this line makes m always equals to Identity because it generates a Scaling Matrix instead of scaling the matrix "m"

i got my code from assimp examples : https://github.com/assimp/assimp/blob/master/samples/SimpleTexturedOpenGL/SimpleTexturedOpenGL/src/model_loading.cpp

I sent them the fix https://github.com/assimp/assimp/pull/5

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .