Jump to content
  • Advertisement
Sign in to follow this  
Krauser

Assimp issue

This topic is 1953 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to load a mesh in my application using assimp. But this work well only with the format .stl, but with other format only a part of mesh is displayed. This is my code:

 

bool ModelClass::LoadModel(char* filename)
{
	Assimp::Importer m_LocalImporter;

	// Important! Makes sure that if the angle between two face normals is > 80 they are not smoothed together.
	// Since the angle between a cubes face normals is 90 the lighting looks very bad if we don't specify this.
	m_LocalImporter.SetPropertyFloat(AI_CONFIG_PP_GSN_MAX_SMOOTHING_ANGLE, 80.0f);	
	m_LocalImporter.SetPropertyInteger(AI_CONFIG_IMPORT_TER_MAKE_UVS, 1);
	m_LocalImporter.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE);

	const aiScene* scene = NULL;
	UINT NumMeshes;
	UINT NumFaces;
	scene = m_LocalImporter.ReadFile(filename,
	aiProcess_CalcTangentSpace |
	aiProcess_Triangulate |
	aiProcess_GenSmoothNormals |
	aiProcess_SplitLargeMeshes |
	aiProcess_ConvertToLeftHanded |
	aiProcess_SortByPType);
 

	if(scene)
	{
		NumMeshes = scene->mNumMeshes;

			for(DWORD nMesh=0; nMesh < NumMeshes; nMesh++)
			{
				aiMesh* mesh = scene->mMeshes[nMesh];

				for(DWORD nVertex = 0; nVertex < mesh->mNumVertices; nVertex++)
				{
					VertexType vertex;
					vertex.position.x = mesh->mVertices[nVertex].x;
					vertex.position.y = mesh->mVertices[nVertex].y;
					vertex.position.z = mesh->mVertices[nVertex].z;

					vertex.normal.x = mesh->mNormals[nVertex].x;
					vertex.normal.y = mesh->mNormals[nVertex].y;
					vertex.normal.z = mesh->mNormals[nVertex].z;

					if(mesh->HasTextureCoords(0))
					{
						vertex.texture.x = mesh->mTextureCoords[0][nVertex].x;
						vertex.texture.y = mesh->mTextureCoords[0][nVertex].y;
					}

					vVertices.push_back(vertex);
				}

				for(DWORD nFaces = 0; nFaces < mesh->mNumFaces; nFaces++)
				for(int nIndex = 0; nIndex < mesh->mFaces[nFaces].mNumIndices; nIndex++)
				vIndices.push_back(mesh->mFaces[nFaces].mIndices[nIndex]);
		
		}

	}
	else
	{
		return false;
	}

	return true;
}

Screen:

OBJ format:

1el0eq.png

 

STL format:

2dlu7ax.png

 

My obj file:

http://rs513p2.rapidshare.com/cgi-bin/rsapi.cgi?sub=download&fileid=1246163158&filename=Car.obj&cookie=D43D984F2E4AAF9B40F185DD2D28279357615E833B8E80DC2D92A141C94A16B373D0E30E4AE683200DF2331CE0130B0B&directstart=1

Edited by Krauser

Share this post


Link to post
Share on other sites
Advertisement

Are the number of aiMeshes (mNumMeshes) the same when loading .obj and .stl? It looks like the wheels/lower parts of the mesh aren't rendered for .obj files.

 

Have you tried other 3d models than this one?

Share this post


Link to post
Share on other sites

Thanks for reply.

No they aren't, the number of mesh change because the model has been converted. This is my problem, my application don't display all meshes of model.

Share this post


Link to post
Share on other sites

Yes, both of these meshes with the Assimp Viewer are displayed correctly. I don't understand because my engine doesn't load all the meshes

Share this post


Link to post
Share on other sites

hm it displayed correctly in my engine, and i cant find error in your code o.0 only thing im not sure is flag "aiProcess_SplitLargeMeshes" maybe it just not working? 

I think you can just get correct indices and vertices count for each part of mesh, and draw it via separate drawcall tongue.png

Edited by x6itru

Share this post


Link to post
Share on other sites

Just suggesting, can you try to remove these and check the results:

 

aiProcess_SplitLargeMeshes
aiProcess_SortByPType

 

and

 


m_LocalImporter.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE);
 
Sometimes these can cause problems to me...

Share this post


Link to post
Share on other sites

The problem should be the hierarchy of your object. In your code-snippet you don't traverse the node-objects. In every node a local matrix is stored which you can use to transform your vertices. In the stl-file the matrices should all be an identity-matrix so your modell is displayed correctly without transforming. In .obj there should be differences.

In my own model-loader I'm also struggling with transforming the vertices with the local matrices. There are all interpreted but I think the local positions and matrices don't match in my case. Or my hierarchy is wrong.

So when you figured out how to display it correctly, you could post your code here.

 

Update: Your car.obj works fine in my application

2r7lpo8.png

Edited by Auskennfuchs

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!