Jump to content

  • Log In with Google      Sign In   
  • Create Account


Assimp issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
16 replies to this topic

#1 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 12 May 2013 - 08:40 AM

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, 13 May 2013 - 09:16 AM.


Sponsor:

#2 Corvwyn   Members   -  Reputation: 331

Like
0Likes
Like

Posted 13 May 2013 - 03:20 AM

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?



#3 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 13 May 2013 - 05:09 AM

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.



#4 MiniMigi   Crossbones+   -  Reputation: 1445

Like
0Likes
Like

Posted 13 May 2013 - 05:55 AM

Have you tried to open both of these meshes with the Assimp Viewer?



#5 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 13 May 2013 - 07:40 AM

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



#6 x6itru   Members   -  Reputation: 149

Like
0Likes
Like

Posted 13 May 2013 - 07:56 AM

I can check it in my application, just upload this .obj model if you can.

#7 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 13 May 2013 - 09:15 AM

Thanks :D,

Direct link:

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



#8 x6itru   Members   -  Reputation: 149

Like
0Likes
Like

Posted 13 May 2013 - 10:07 AM

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, 13 May 2013 - 11:19 AM.


#9 MiniMigi   Crossbones+   -  Reputation: 1445

Like
0Likes
Like

Posted 13 May 2013 - 02:38 PM

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...


#10 Auskennfuchs   Members   -  Reputation: 536

Like
0Likes
Like

Posted 14 May 2013 - 11:23 AM

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, 14 May 2013 - 04:21 PM.


#11 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 14 May 2013 - 02:36 PM

Ok Thanks for advise,

It doesn't work removing: sad.png

aiProcess_SplitLargeMeshes
aiProcess_SortByPType

m_LocalImporter.SetPropertyInteger(AI_CONFIG_PP_SBP_REMOVE, aiPrimitiveType_LINE);
 

But I am sure that work with separate drawcall, I'm trying tomorrow.

If I find an alternative solution I share here.



#12 MiniMigi   Crossbones+   -  Reputation: 1445

Like
0Likes
Like

Posted 14 May 2013 - 02:49 PM

I know the car is a bit transparent, but the mesh you provided loaded correctly, so I believe that something is wrong with your rendering code as others suggested, prof:

 

ao74td.png

 

Maybe you can show us your rendering, if you want? huh.png

 

I can relate to your problems, as when I tried to integrate Assimp wacko.png . Didn't go so well the first time...


Edited by Migi0027, 14 May 2013 - 02:51 PM.


#13 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 15 May 2013 - 06:40 AM

Rendering code:

void ModelClass::Render(ID3D11DeviceContext* deviceContext)
{
    unsigned int stride;
    unsigned int offset;


    // Set vertex buffer stride and offset.
    stride = sizeof(VertexType);
    offset = 0;
    
    // Set the vertex buffer to active in the input assembler so it can be rendered.
    deviceContext->IASetVertexBuffers(0, 1, &m_vertexBuffer, &stride, &offset);

    // Set the index buffer to active in the input assembler so it can be rendered.
    deviceContext->IASetIndexBuffer(m_indexBuffer, DXGI_FORMAT_R32_UINT, 0);

    // Set the type of primitive that should be rendered from this vertex buffer, in this case triangles.
    deviceContext->IASetPrimitiveTopology(D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

    return;
}

void ShaderClass::Render(ID3D11DeviceContext* deviceContext, int indexCount)
{
    // Set the vertex input layout.
    deviceContext->IASetInputLayout(m_layout);

    // Set the vertex and pixel shaders that will be used to render this triangle.
    deviceContext->VSSetShader(m_vertexShader, NULL, 0);
    deviceContext->PSSetShader(m_pixelShader, NULL, 0);

    // Set the sampler state in the pixel shader.
    deviceContext->PSSetSamplers(0, 1, &m_sampleState);

    // Render the triangle.
    deviceContext->DrawIndexed(indexCount, 0, 0);

    return;
}

Edited by Krauser, 15 May 2013 - 06:52 AM.


#14 NightCreature83   Crossbones+   -  Reputation: 2674

Like
0Likes
Like

Posted 15 May 2013 - 09:28 AM

You want to pass this flag to your read function "aiProcess_PreTransformVertices" (http://assimp.sourceforge.net/lib_html/postprocess_8h.html#a64795260b95f5a4b3f3dc1be4f52e410) this will pretransform all of the sub nodes and all of the meshes will just be below the root node. No need to traverse the object any more if you don't care about the scene graph in the file.

Other flags of interest to a DX app is aiProcess_MakeLeftHanded which applies all the transforms needed for DX applications.

Also be careful with just assuming that an assimp mesh has normals by default they only guarantee that an aiMesh will have verts and faces.

Edited by NightCreature83, 15 May 2013 - 09:31 AM.

Worked on titles: CMR:DiRT2, DiRT 3, DiRT: Showdown, GRID 2, Mad Max

#15 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 15 May 2013 - 01:39 PM

Great now it work! Problem solved. Thanks biggrin.png .



#16 MiniMigi   Crossbones+   -  Reputation: 1445

Like
0Likes
Like

Posted 15 May 2013 - 03:41 PM

So what was the problem? Just curious huh.png



#17 Krauser   Members   -  Reputation: 124

Like
0Likes
Like

Posted 16 May 2013 - 05:08 AM

I added the flag "aiProcess_PreTransformVertices" in my read function smile.png .


Edited by Krauser, 17 May 2013 - 07:42 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS