Advertisement

Blender and rectangles?

Started by January 26, 2011 08:30 PM
15 comments, last by swilkewitz 13 years, 10 months ago
Ok, I noticed that the cube only has one triangle per side. So either I'm not getting half of the faces somehow or they are grouping up and hiding their "partners." Here's my code just in case.

void ModelLoader::loadModel(const std::string &fileName, Model* model)
{

Assimp::Importer importer;

const aiScene* scene = importer.ReadFile(fileName, aiProcess_Triangulate);

if(!scene){
MessageBox(NULL, "Loading Model Failed!", NULL, NULL);
return;
}

aiMesh* tempMesh;
aiFace tempFace;
UINT* index;

for(UINT i = 0; i < scene->mNumMeshes; i++){
tempMesh = scene->mMeshes;

for(UINT x = 0; x < tempMesh->mNumFaces; x++){
tempFace = tempMesh->mFaces[x];


for(UINT y = 0; y < tempFace.mNumIndices; y++){
index = tempFace.mIndices;

Point p0, p1, p2;

p0.x = (GLfloat) tempMesh->mVertices[index[0]].x;
p0.y = (GLfloat) tempMesh->mVertices[index[0]].y;
p0.z = (GLfloat) tempMesh->mVertices[index[0]].z;

p1.x = (GLfloat) tempMesh->mVertices[index[1]].x;
p1.y = (GLfloat) tempMesh->mVertices[index[1]].y;
p1.z = (GLfloat) tempMesh->mVertices[index[1]].z;

p2.x = (GLfloat) tempMesh->mVertices[index[2]].x;
p2.y = (GLfloat) tempMesh->mVertices[index[2]].y;
p2.z = (GLfloat) tempMesh->mVertices[index[2]].z;

Triangle tN = Triangle(p0, p1, p2);
model->triangle.push_back(tN);

}
}
}
}


I just tried loading my actual model and I've come to the conclusion that the triangulate flag isn't creating two triangles out of one square.
Advertisement
Hmm not sure then. You can always check the assimp output log to see if everythings ok. Also you can add the flag
aiProcess_ValidateDataStructure

which does some more self checks of the file structure. What file format are you loading?
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Hmm not sure then. You can always check the assimp output log to see if everythings ok. Also you can add the flag aiProcess_ValidateDataStructure which does some more self checks of the file structure. What file format are you loading?


dxf... I solved the problem temporarily by converting quads to triangles in blender. I don't like this fix, because it bugs me that something is still technically wrong, but it will do.

One last thing, my model is being drawn at a wierd angle, I'm assuming its because I haven't rotated the mesh to match my world axis from the loading axis. Right now I am using quaternions for my object rotation, so does Assimp provide the orientation of the model in a quaternion? I remember seeing a quat class in the reference...

Edit: I noticed another problem just now, my model doesn't rotate on the the point of origin, but I am sure this is just another result of not fixing the orientation first.
There are a bunch of different flags that you can pass in to the ReadFile call that will do things like automatically convert your model to triangles, pre-transform your verticies, etc. Check out the docs for the different options. My current usage looks like this:




const aiScene* pScene = Importer.ReadFile( szFileName, aiProcess_PreTransformVertices | aiProcess_GenUVCoords | aiProcess_JoinIdenticalVertices | aiProcess_TransformUVCoords |
aiProcess_Triangulate | aiProcess_RemoveComponent | aiProcess_SortByPType );


I realized yesterday that the problem was my center of data in blender. Somewhere in the process of creating my model the center got moved.
Advertisement
Bump. Sorry, problem solved.

This topic is closed to new replies.

Advertisement