Game Development Community

dev|Pro Game Development Curriculum

Rendering Bones and Nodes in TGE (Resurrected Resource)

by BrokeAss Games · 03/15/2009 (8:14 pm) · 4 comments

in TSShapeInstance.cc under
bool                          TSShapeInstance::smSkipFog = false;
add
bool                          TSShapeInstance::smRenderBones = false;
at the bottom of void TSShapeInstance::init() add
Con::addVariable("$pref::TS::renderBones",   TypeBool, &TSShapeInstance::smRenderBones);
at the bottom of
void TSShapeInstance::render(S32 dl, F32 intraDL, const Point3F * objectScale)
above
clearStatics();
add
if (smRenderBones) {
	glDisable(GL_LIGHTING);
	glDisable(GL_DEPTH_TEST);
	glLineWidth(2.f);
	glPointSize(6.f);
	for (U32 i=0;i<mShape->nodes.size();i++)
		renderBone(i);
	glPointSize(.1f);
	glLineWidth(.1f);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_LIGHTING);
   }
at the bottom of the file add
void TSShapeInstance::renderBone(U32 idx)
{
	Point3F pos;
	pos = mNodeTransforms[idx].getPosition();
	
	// Draw point
	glBegin(GL_POINTS);
	glColor3f(1.0,0.0,0.0); // red for the dots
	glVertex3f(pos.x, pos.y, pos.z);
	glEnd();
	
	// And now the line to the parent
	if (mShape->nodes[idx].parentIndex != -1) {
		glBegin(GL_LINES);
		glColor3f(0.0,1.0,0.0); // green for the lines
		glVertex3f(pos.x, pos.y, pos.z);
		pos = mNodeTransforms[mShape->nodes[idx].parentIndex].getPosition();
		glVertex3f(pos.x, pos.y, pos.z);
		glEnd();
	}
}
in tsshapeinstance.h after
class TSShapeInstance
{
   public:
add
static bool smRenderBones;
   void renderBone(U32 idx);
then in defaults.cs or prefs.cs add
$pref::TS::renderBones = "1"; //on
or
$pref::TS::renderBones = "0"; //off

Hope this helps some modelers/coders.
If you are the author of this resource please let me know so I can give credit where credit is due.

#1
03/16/2009 (12:36 am)
Simple and clear. Thank you.
#2
04/03/2009 (3:58 pm)
Reply from here.
@deepscratch
Thx for the help, I think I almost got it but I'm confused at your use of mDots (mDot?).
It's a GFXVertexBufferHandle<GFXVertexPC> right?
#3
04/04/2009 (5:38 pm)
Almost got it ported for TGEA 1.8.1 thx to deepscratch and a basic understanding of stateblocks.

There is just one problem left, the transforms of the rendered skeleton are not synced with the actual skeleton, you have to run around a bit to find your skeleton.

here's what I have so far:
if (smRenderBones) {
	GFXStateBlockDesc desc;
	GFXStateBlockRef myState = GFX->createStateBlock(desc);
    desc.setZEnable(false);
    //GFX->setLightingEnable(false);
	PrimBuild::begin(GFXLineList, 2);
	PrimBuild::begin( GFXPointList, 6.f);
	for (U32 i=0;i<mShape->nodes.size();i++)
		renderBone(i);
	PrimBuild::begin( GFXPointList, .1f);
	PrimBuild::begin(GFXLineList, 1);
	//GFX->setLightingEnable(true);
    desc.setZEnable(true);
	// Render time code
	GFX->setStateBlock(myState);
   }
and
void TSShapeInstance::renderBone(U32 idx)
{
	Point3F pos;
	pos = mNodeTransforms[idx].getPosition();
	
	// Draw point
    //    GFX->setVertexBuffer( mDots );
	//PrimBuild::begin( GFXPointList, mDots->mNumVerts);
	//PrimBuild::color3f(1, 0, 0); // red for the dots
	//PrimBuild::vertex3f(pos.x, pos.y, pos.z);
	//PrimBuild::end();
	
	// And now the line to the parent
	if (mShape->nodes[idx].parentIndex != -1) {
		PrimBuild::begin(GFXLineList,2);
		PrimBuild::color3f(0.0,1.0,0.0); // green for the lines
		PrimBuild::vertex3f(pos.x, pos.y, pos.z);
		pos = mNodeTransforms[mShape->nodes[idx].parentIndex].getPosition();
		PrimBuild::vertex3f(pos.x, pos.y, pos.z);
		PrimBuild::end();
	}
}

Any help would be much appreciated.
#4
04/08/2009 (4:31 am)
The nodes are in object space, so either put the renderBone () calls before popping the world matrix, or grab the transform from mNodeTransform and multiply it with the shapes matrix to get it out in world space, Ari.

There are better spots to do this, though. We have it at the end of ShapeBase::prepBatchRender ().