Hi!
I've written an OpenGL tool to visualize .3ds files. To import a 3ds file I use Assimp (http://assimp.sourceforge.net/). I use Blender to create example 3ds files. The problem is now that when I read a mesh from the .3ds file it's transformation matrix is always identity. However the coordinates of the vertices are in world space.
The source code to load a mesh looks like this.
m is always identity but i don't know why.
[source lang="cpp"]void recursive_render (const struct aiScene *sc, const struct aiNode* nd)
{
int i;
unsigned int n = 0, t;
struct aiMatrix4x4 m = nd->mTransformation;
// update transform
aiTransposeMatrix4(&m);
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->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];
glBegin(GL_TRIANGLES);
for(i = 0; i < face->mNumIndices; i++) {
int index = face->mIndices;
if(mesh->mColors[0] != NULL)
Color4f(&mesh->mColors[0][index]);
if(mesh->mNormals != NULL)
glNormal3fv(&mesh->mNormals[index].x);
glVertex3fv(&mesh->mVertices[index].x);
}
glEnd();
}
}
// draw all children
for (n = 0; n < nd->mNumChildren; ++n) {
recursive_render(sc, nd->mChildren[n]);
}
glPopMatrix();
}[/source]
Maybe someone could helpt.
Thanks!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement