X File child frame workaround

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
JoeWright
Posts: 74
Joined: Mon Dec 08, 2003 3:51 pm

X File child frame workaround

Post by JoeWright »

It seems that some X file exporters (e.g. PandaExporter with 3dsmax 5) create sub child hierachies that can't be processed by Irrlicht.

I present the following workaround. It isn't a complete solution, rather a quick and dirty fix. It works by bypassing a frame/transformation matrix combo that follows an initial frame/transformation combo. This works for me and may for others. It should also be compatible with simpler/flater formats. It may still not accomodate advanced setups where a better child frame processing would be beneficial.

Updates in red:

bool CXFileReader::parseDataObjectFrame(SXFrame& frame)
{
static skip=0;
static skip_closing_brackets=0;


#ifdef _XREADER_DEBUG
os::Printer::log("CXFileReader: Reading frame");
#endif


// A coordinate frame, or "frame of reference." The Frame template
// is open and can contain any object. The Direct3D extensions (D3DX)
// mesh-loading functions recognize Mesh, FrameTransformMatrix, and
// Frame template instances as child objects when loading a Frame
// instance.

if (!readHeadOfDataObject(&frame.Name))
{
os::Printer::log("No opening brace in Frame found in x file", ELL_WARNING);
return false;
}

// jetzt sind wir im frame.
// solange tokens lesen, bis closing brace erreicht

while(true)
{
if (skip>0)
skip--;

core::stringc objectName = getNextToken();

if (objectName.size() == 0)
{
os::Printer::log("Unexpected ending found in Frame in x file.", ELL_WARNING);
return false;
}
else
if (objectName == "}")
{
if (skip_closing_brackets==0)
break; // frame finished
else
skip_closing_brackets--;

}
else
if (objectName == "Frame")
{
if (skip!=0)
{
getNextToken();
}
else
{
frame.ChildFrames.push_back(SXFrame());
if (!parseDataObjectFrame(frame.ChildFrames[frame.ChildFrames.size()-1]))
return false;
}

}
else
if (objectName == "FrameTransformMatrix")
{
if (skip!=0)
{
parseUnknownDataObject();
}
else
{
skip=3;
skip_closing_brackets=1;
if (!parseDataObjectTransformationMatrix(frame.LocalMatrix))
return false;
}

}
else
if (objectName == "Mesh")
{
frame.Meshes.push_back(SXMesh());
if (!parseDataObjectMesh(frame.Meshes[frame.Meshes.size()-1]))
return false;
}
else
{
os::Printer::log("Unknown data object in frame in x file", objectName.c_str());
if (!parseUnknownDataObject())
return false;
}

}

return true;
}

Regards
Joe
billythekid
Posts: 1
Joined: Mon Oct 04, 2004 1:45 am

Post by billythekid »

Is this a replacement of engine source code, or you own code?

And can you give an example of using it? Im having similar problems I think.
JoeWright
Posts: 74
Joined: Mon Dec 08, 2003 3:51 pm

Post by JoeWright »

Its a drop in replacement of the engine code.

Overwrite CXFileReader::parseDataObjectFrame with this one

Joe
Tyn
Posts: 932
Joined: Thu Nov 20, 2003 7:53 pm
Location: England
Contact:

Post by Tyn »

Could you wrap that in

Code: Select all

 tags so that the whitespace isn't lost plz?
JoeWright
Posts: 74
Joined: Mon Dec 08, 2003 3:51 pm

Post by JoeWright »

Here you go:

Code: Select all

bool CXFileReader::parseDataObjectFrame(SXFrame& frame)
{
	static skip=0;
	static skip_closing_brackets=0;

	#ifdef _XREADER_DEBUG
    os::Printer::log("CXFileReader: Reading frame");
	#endif


	// A coordinate frame, or "frame of reference." The Frame template
	// is open and can contain any object. The Direct3D extensions (D3DX)
	// mesh-loading functions recognize Mesh, FrameTransformMatrix, and 
	// Frame template instances as child objects when loading a Frame 
	// instance.

	if (!readHeadOfDataObject(&frame.Name))
	{
		os::Printer::log("No opening brace in Frame found in x file", ELL_WARNING);
		return false;
	}

	// jetzt sind wir im frame.
	// solange tokens lesen, bis closing brace erreicht

	while(true)
	{
		if (skip>0)
			skip--;
		core::stringc objectName = getNextToken();

		if (objectName.size() == 0)
		{
			os::Printer::log("Unexpected ending found in Frame in x file.", ELL_WARNING);
			return false;
		}
		else
		if (objectName == "}")
		{
			if (skip_closing_brackets==0)
				break; // frame finished
			else
				skip_closing_brackets--;
		}
		else
		if (objectName == "Frame")
		{
			if (skip!=0)
			{
				getNextToken();
			}
			else
			{
				frame.ChildFrames.push_back(SXFrame());
				if (!parseDataObjectFrame(frame.ChildFrames[frame.ChildFrames.size()-1]))
					return false;
			}
		}
		else
		if (objectName == "FrameTransformMatrix")
		{
			if (skip!=0)
			{
				parseUnknownDataObject();
			}
			else
			{
				skip=3;
				skip_closing_brackets=1;
				if (!parseDataObjectTransformationMatrix(frame.LocalMatrix))
					return false;
			}
		}
		else
		if (objectName == "Mesh")
		{
			frame.Meshes.push_back(SXMesh());
			if (!parseDataObjectMesh(frame.Meshes[frame.Meshes.size()-1]))
				return false;
		}
		else
		{
			os::Printer::log("Unknown data object in frame in x file", objectName.c_str());
			if (!parseUnknownDataObject())
				return false;
		}

	}
		
	return true;
}
ttom
Posts: 43
Joined: Tue Aug 26, 2003 3:43 am
Location: Taiwan

Post by ttom »

I use your code but i can't solve this problem.
my use the CS to create the man and had tree part of it. I export it and it can show in the meshview but in irrlicht is bad. any can give a hint or just use the d3d's function to parse the xfile
JoeWright
Posts: 74
Joined: Mon Dec 08, 2003 3:51 pm

Post by JoeWright »

Please post your x file

Joe
ttom
Posts: 43
Joined: Tue Aug 26, 2003 3:43 am
Location: Taiwan

Post by ttom »

I put the xfile but it too long. so I can email to u. but i can't find your email
ttom
JoeWright
Posts: 74
Joined: Mon Dec 08, 2003 3:51 pm

Post by JoeWright »

joe@nyrsound.com

Or post a link

Joe
ttom
Posts: 43
Joined: Tue Aug 26, 2003 3:43 am
Location: Taiwan

Post by ttom »

Dear niko:
I find the bug about the load the Xfile, and I send the file to the JoeWright. and below is his reply

I've just had a quick look at it. Even with the bug fixes I put in the forum I don't think Irrlicht will read it because of the frame hierachy. I think my sub frame fix only fixed it if there were two layers but in your's there is 3.

I've left it to Niko to sort the sub frame stuff out. Maybe if you posted a message in the bug forum it would remind him.

Regards
Joe

ttom
Post Reply