Need Help parsing the X file using D3DX?

Started by
3 comments, last by Norman Barrows 7 years, 11 months ago

I know it's old. But I need to complete some tasks before upgrading. So please bear with me If I use this code snippet to parse the x frame hierarchy


void MeshX::ParseParents(/*FRAME* root, FRAME* parent, FRAME* pCurFrame*/)
{	 

	// get all first child first, then the first child's 

	FRAME* pCurFrame = (FRAME*)m_pFrameRoot;
	LPD3DXMESHCONTAINER pCurMesh;
	stack st;
	st.push(pCurFrame);
	while (!st.empty())
	{
		pCurFrame = st.top();
		st.pop();
		if (pCurFrame != NULL)
		{

			FRAME* p = (FRAME*)pCurFrame;
			FRAME* c = (FRAME*)pCurFrame->pFrameFirstChild;
			FRAME* s = (FRAME*)pCurFrame->pFrameSibling;
 
			if (c && p->Id < m_frames.size())
				_linkFrame(p->Id, c->Id, -1);
			
			if (s && p->Id < m_frames.size())
				_linkFrame(p->Id, -1, s->Id);


			 
			st.push((FRAME*)pCurFrame->pFrameFirstChild);
			st.push((FRAME*)pCurFrame->pFrameSibling);
		}
	}
}
void MeshX::_linkFrame(BONE_ID parentFrameId, BONE_ID childFrameId, BONE_ID siblingID)
{

	if (parentFrameId != -1 && childFrameId != -1)
	{
		m_frames[parentFrameId].childId = childFrameId;
		m_frames[childFrameId].parentId = parentFrameId;
	}
	else if (parentFrameId != -1 && siblingID != -1)
	{
		m_frames[parentFrameId].siblingId = siblingID;
		//m_frames[siblingID].parentId = parentFrameId;
	}
 
	 
}

I will get these


0	Bip001	no parent	Bip001_Pelvis	Body01
1	Bip001_Pelvis	        Bip001	        Bip001_Spine	no sibling
2	 Bip001_Spine	        Bip001_Pelvis	Bip001_Spine1	Bip001_L_Thigh
3	 Bip001_Spine1         	Bip001_Spine	Bip001_Spine2	no sibling
4	 Bip001_Spine2	        Bip001_Spine1	Bip001_Spine3	no sibling
5	 Bip001_Spine3	        Bip001_Spine2	Bip001_Neck	no sibling
6	 Bip001_Neck	        Bip001_Spine3	Bip001_Head	Bip001_L_Clavicle
7	 Bip001_Head	        Bip001_Neck	no child	no sibling
8	Bip001_L_Clavicle	no parent	Bip001_L_UpperArm	Bip001_R_Clavicle
9	Bip001_L_UpperArm	Bip001_L_Clavicle	Bip001_L_Forearm	no sibling
10	Bip001_L_Forearm	Bip001_L_UpperArm	Bip001_L_Hand	no sibling
11	Bip001_L_Hand          	Bip001_L_Forearm	Bip001_L_Finger0	no sibling
12	Bip001_L_Finger0	Bip001_L_Hand	no child	no sibling
13	Bip001_R_Clavicle	no parent	Bip001_R_UpperArm	no sibling
14	Bip001_R_UpperArm	Bip001_R_Clavicle	Bip001_R_Forearm	no sibling
15	Bip001_R_Forearm	Bip001_R_UpperArm	Bip001_R_Hand	no sibling
16	Bip001_R_Hand	        Bip001_R_Forearm	Bip001_R_Finger0	no sibling
17	Bip001_R_Finger0	Bip001_R_Hand	no child	no sibling
18	Bip001_L_Thigh	        no parent	Bip001_L_Calf	Bip001_R_Thigh
19	Bip001_L_Calf	        Bip001_L_Thigh	Bip001_L_Foot	no sibling
20	Bip001_L_Foot	        Bip001_L_Calf	Bip001_L_Toe0	no sibling
21	Bip001_L_Toe0	        Bip001_L_Foot	Bip001_L_Toe01	no sibling
22	Bip001_L_Toe01	        Bip001_L_Toe0	Bip001_L_Toe02	no sibling
23	Bip001_L_Toe02	        Bip001_L_Toe01	no child	no sibling
24	Bip001_R_Thigh        	no parent	Bip001_R_Calf	no sibling
25	Bip001_R_Calf	        Bip001_R_Thigh	Bip001_R_Foot	no sibling
26	Bip001_R_Foot	        Bip001_R_Calf	Bip001_R_Toe0	no sibling
27	Bip001_R_Toe0	        Bip001_R_Foot	Bip001_R_Toe01	no sibling
28	Bip001_R_Toe01	        Bip001_R_Toe0	Bip001_R_Toe02	no sibling
29	Bip001_R_Toe02	        Bip001_R_Toe01	no child	no sibling
30	Body01	no parent	no child	no sibling

Assuming nothing wrong with the x file. You can see Bip001_L_Clavicle,

Bip001_R_Clavicle has no parents But their parents are supposed to be Bip001_Spine3

I test it in some other parser, it does indicate that

And Bip001_L_Thigh and R_Thigh should get the parent of Bip001_Pelvis

Any ideas how to fix this?

Thanks

Jack

Advertisement

This seems like something easily done using a debugger.

Also, it seems like parents can have only one child, but multiple childs can have the same parent?

>> Assuming nothing wrong with the x file.

confirm that first.

the .x file format specification can be found in the june 2010 DX SDK download. from that you can simply read the .x file manually to determine if its correct with respect to the bones (frames) in question.

if it is correct, having now looked at the file, odds are you'll see where you are parsing incorrectly.

me personally, i'd probably just use the DX API calls to load the model into a mesh (and controller), then just copy out the data needed, and release the model and controller. no need to get into parsing complex file formats. parsing code's already been written, all you need is the data.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

I've solved it myself. I actually retrieve the parent of the parent and pass the sibling ID as the childID

to the _linkframe function, and it solved the problem

BTW, I've rewritten the _linkframe function significantly. But you can find it here

https://github.com/yorung/dx11bvh

Thanks

Jack

>> and pass the sibling ID as the childID

yes, as i recall, you have to follow the siblings before the children. the current frame and its siblings are the children of the parent. the child of the current frame and its siblings are the children of the current frame. the advantage of this way of doing it is you only need two pointers per node, one for siblings, and one for fist child. and you can still implement an N-way tree structure.

Norm Barrows

Rockland Software Productions

"Building PC games since 1989"

rocklandsoftware.net

PLAY CAVEMAN NOW!

http://rocklandsoftware.net/beta.php

This topic is closed to new replies.

Advertisement