CXMeshFileLoader

You discovered a bug in the engine, and you are sure that it is not a problem of your code? Just post it in here. Please read the bug posting guidelines first.
Post Reply
jonasled
Posts: 34
Joined: Sat Aug 26, 2006 5:08 pm
Location: Sweden
Contact:

CXMeshFileLoader

Post by jonasled »

The CXMeshFileLoader has problems parsing models from a game model library that I have purchased. Every other application that I have tried (Ultimate Unwrap, Blitz3D etc.) have no problem loading and correctly displaying these models.

I have tracked the problem down to CXMeshFileLoader::parseDataObjectMeshMaterialList, which reports "Index count per face not equal to face material index count in x file." The data it is trying to parse reads:

Code: Select all

MeshMaterialList {
1;
1;
0;;
{x3ds_mat_Material__1}
}
There is clearly a lot more faces present than one in the mesh! However, all those faces should have the same material so instead of just aborting and returning false, CXMeshFileLoader::parseDataObjectMeshMaterialLis should be able to just assume the same material for all faces. I presume that is what other loaders do. This might even be legitimate, but I have not been able to find any good official file format reference for X.
jonasled
Posts: 34
Joined: Sat Aug 26, 2006 5:08 pm
Location: Sweden
Contact:

Post by jonasled »

This is my hotfix:

Code: Select all

	// read non triangulated face material index count
	//const u32 nFaceIndices = readInt();
	u32 nFaceIndices = readInt();
	
	if (nFaceIndices != mesh.IndexCountPerFace.size())
	{
		os::Printer::log("Index count per face not equal to face material index count in x file. Assuming same material for all faces.", ELL_WARNING);
		nFaceIndices = mesh.IndexCountPerFace.size();
		// read non triangulated face indices and create triangulated ones
		mesh.FaceMaterialIndices.set_used( mesh.Indices.size() / 3);
		u32 triangulatedindex = 0;
		const u32 ind = readInt();
		for (u32 tfi=0; tfi<nFaceIndices; ++tfi)
		{
			const u32 fc = mesh.IndexCountPerFace[tfi]/3;
			for (u32 k=0; k<fc; ++k)
				mesh.FaceMaterialIndices[triangulatedindex++] = ind;
		}
		
		//return false;
	}
	else
	{
		// read non triangulated face indices and create triangulated ones
		mesh.FaceMaterialIndices.set_used( mesh.Indices.size() / 3);
		u32 triangulatedindex = 0;
		for (u32 tfi=0; tfi<nFaceIndices; ++tfi)
		{
			const u32 ind = readInt();
			const u32 fc = mesh.IndexCountPerFace[tfi]/3;
			for (u32 k=0; k<fc; ++k)
				mesh.FaceMaterialIndices[triangulatedindex++] = ind;
		}
	}
Post Reply