Advertisement

Importing a mesh, using FBX SDK

Started by June 11, 2015 06:16 AM
5 comments, last by L. Spiro 9 years, 8 months ago

Hi,

I got a question about importing meshes using C++.

Currently I'm working on my own game-engine and I'd like to import meshes using the FBX SDK of autodesk.

I'v got a whole environment setup but something is not quite right.

These are some screenshots:

https://www.dropbox.com/s/3i57g8zyredn63r/00.png?dl=0

https://www.dropbox.com/s/4cn8a6v7i463ovu/01.png?dl=0

https://www.dropbox.com/s/8pej50sz7np3f6h/02.png?dl=0

it's supposed to be a cube but as you can see what the engine outputs is not exactly a cube.

I know it has probably something to do with the vertex ordering or indices of my mesh but I checked everything over and over again and I cannot find what I'm doing wrong.

Here a link to my code:

http://pastebin.com/MRK4Fwru

Kind Regards,

Dave

First, take a look through the Beginner's FAQ, particularly the guidelines suggesting that, before posting, you first try to determine what the problem is yourself. Just staring at 100s of lines of code doesn't qualify! wink.png


has probably something to do with the vertex ordering or indices of my mesh but I checked everything over and over again

For a program to produce the results you want, both the data and the code need to be correct.

From your post, it appears you're not sure how to debug your program. I suggest you learn how to Follow The Data. I.e., rather than post all your code (I didn't look at it because you need to do some work first), do some testing to determine at least the general area (a few lines of code, or at most a routine) where you know the problem occurs.

Choose a point in your code somewhere and look at the data you import - actually examine the data you use at run-time. Are the values what you expect? If so, examine your code to determine where it uses that data incorrectly. If the data at that point is incorrect, the problem occurs somewhere in your code earlier in the process. Pick another location earlier in the process and repeat the examination.

At some point you will find a location where the data you're reading from file is incorrect (fix the file), or correct data is sent to a routine, but the routine does not produce the data you expect.

Then, if you don't understand why the code doesn't produces the correct results with good data, you'll be able to post something more like: "I've verified the data [at a specified point] is correct, but the XXX routine [here's 12 lines of code] doesn't produce [this type of] data, which I expect the code to do."

Help others help you by providing information about the problem that you've already determined.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Advertisement

I already narrowed it down to the position where the error occurs, but when I'm helping somebody I'd like to have as much code as possible to seek out a problem.
In my post I metioned that it had to do something with the indices of my mesh but did not know exactly what was going wrong.

I also know how to debug my code, I went over it 20000 times and everything seems valid to me that the issue that I don't understand.

I checked everything step by step, used a more simple mesh like a cube because the first mesh was much more complex.

All my values are correctly but I cannot get the right result, and I don't know why.

That's why I posted my question over here.

But if you want "12 lines of code". here they are.


//For each vertex in a polygon
					for (int k = 0; k < iNumVertices; ++k)
					{
						FbxVector4 vertexNormal = FbxVector4(0, 0, 0);
						FbxVector2 vertexUV = FbxVector2(0, 0);

						bool unmappedUV;

						int iControlPointIndex = pMesh->GetPolygonVertex(j, k);
						pMesh->GetPolygonVertexNormal(j, k, vertexNormal);
						pMesh->GetPolygonVertexUV(j, k, UVNames[0], vertexUV, unmappedUV);

						int polygonindex = pMesh->GetPolygonVertexIndex(j);
						if (polygonindex == -1)
							return false;

						int* VerticesIndices = pMesh->GetPolygonVertices();

...

All my values are correctly but I cannot get the right result

That cannot be the case. If you've verified 20000 times that the values you send to the rendering portion of your engine are correct (all vertex positions, texcoords, indices, etc.), then something in the rendering code must be incorrect, and your rendering code does not produce the correct data to send to the GPU (or whatever you're using to draw). EDIT: a good graphics debugger will quickly let you determine if the input values are what you expect.

Re: rendering a simple mesh like a cube - an excellent approach. You should easily be able to verify that the data starts out with (for instance) 24 vertices at correct positions, and that the 36 indices are correctly specified, in the correct order, and should produce the correct facing triangles. After you've verified that, follow the data from there.

Re: "12 lines of code" - if you've verified 20000 times that the posted code results in correct values, follow the data output from that routine.

Please don't PM me with questions. Post them in the forums for everyone's benefit, and I can embarrass myself publicly.

You don't forget how to play when you grow old; you grow old when you forget how to play.

Your 12 lines are incorrect; you did not check the mapping mode and branch into each of the 4 possibilities. This would definitely cause vertices to be wrong.
Index data does not exist in FBX files; you have to generate it by yourself.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

Looks like the view matrix to me
Advertisement

int* VerticesIndices = pMesh->GetPolygonVertices();

And then?

It should be:

		LSUINT32 ui32FaceCount = m_pfmMesh->GetPolygonCount();
		LSX_ADD_VERTEX favAddVertex = { 0UL };
		for ( LSUINT32 I = 0; I < ui32FaceCount; ++I ) {
…
			if ( !AddFace( I, … ) ) {
				return false;
			}
		}


	LSBOOL LSE_CALL CMesh::AddFace( LSUINT32 _ui32FaceIndex, … ) const {

		LSUINT32 ui32PolyTotal = m_pfmMesh->GetPolygonSize( _ui32FaceIndex );
		LSUINT32 ui32PolyStart = m_pfmMesh->GetPolygonVertexIndex( _ui32FaceIndex );
		int * piFacePool = m_pfmMesh->GetPolygonVertices();			// Get the face pool.

		// Go over each vertex in the face.
		for ( LSUINT32 I = 0UL; I < ui32PolyTotal; ++I ) {
			LSX_FACE::LSX_FACE_VERTEX ffvThisVert;
			LSUINT32 ui32VertIndex = piFacePool[ui32PolyStart+I];		// Vertex is found by dereferencing from the pool.
			ffvThisVert.ui32VertexIndex = ui32VertIndex;
I don’t see where you dereference the vertex pool to get the correct vertex, nor do you go over faces, only over the pool of vertex indices.
It is always a nested-loop operation.
#1: For every face…
#2: For every point in that face…


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

This topic is closed to new replies.

Advertisement