Page 1 of 1

Get Node/Bone Position

Posted: Mon Sep 24, 2018 9:34 pm
by Steve_Yorkshire
Need to find the position of the Eye node? No problem! GetEyePoint()!
Need to find the position of any other node or bone in the player model? Errr ...

Introducing getNodePoint! (original from Tim-MGT but I updated it just now to work engineDefines).

In shapeBase.h near getEyeTransform in the "public" section add:
   virtual void getNodeTransform(const char* nodeName, MatrixF* mat);
   virtual void getNodeVector(const char* nodeName, VectorF* vec);
   void getNodePoint(const char* nodeName, Point3F* pos);
In shapeBase.cpp
//yorks for node transforms
void ShapeBase::getNodeTransform(const char* nodeName, MatrixF* mat)
{
	S32 node = getShape()->findNode(nodeName);

	MatrixF pmat;
	pmat.identity();

	F32 *dp = pmat;

	if (node != -1)
	{
		F32* sp;
		sp = mShapeInstance->mNodeTransforms[node];
		const Point3F& scale = getScale();
		dp[3] = sp[3] * scale.x;
		dp[7] = sp[7] * scale.y;
		dp[11] = sp[11] * scale.z;
	}

	mat->mul(getTransform(), pmat);
}

void ShapeBase::getNodeVector(const char* nodeName, VectorF* vec)
{
	MatrixF mat;
	getNodeTransform(nodeName, &mat);

	mat.getColumn(1, vec);
}

void ShapeBase::getNodePoint(const char* nodeName, Point3F* pos)
{
	MatrixF mat;
	getNodeTransform(nodeName, &mat);
	mat.getColumn(3, pos);
}
//yorks end
And then down at the bottom expose it to glorious Torquescript.
DefineEngineMethod(ShapeBase, getNodeTransform, MatrixF, (const char* nodeName), ,
	"@brief Get the node/bone transform.\n\n"

	"@param node/bone name to query\n"
	"@return the node position\n\n")
{
	MatrixF mat;
	object->getNodeTransform(nodeName, &mat);
	return mat;
}

DefineEngineMethod(ShapeBase, getNodeVector, VectorF, (const char* nodeName), ,
	"@brief Get the node/bone vector.\n\n"

	"@param node/bone name to query\n"
	"@return the node vector\n\n")
{
	VectorF vec(0, 1, 0);
	object->getNodeVector(nodeName, &vec);

	return vec;
}

DefineEngineMethod(ShapeBase, getNodePoint, Point3F, (const char* nodeName), ,
	"@brief Get the node/bone position.\n\n"

	"@param node/bone name to query\n"
	"@return the node position\n\n")
{
	Point3F pos(0, 0, 0);
	object->getNodePoint(nodeName, &pos);

	return pos;
}

Re: Get Node/Bone Position

Posted: Tue Sep 25, 2018 9:23 pm
by Steve_Yorkshire
Just to point out that %obj.getBoneVector(%bone); returns the current transform/vector of that bone/node alone and not inherited vectors from other bones. So if the bone is not moved during an animation it will return "0 1 0" and will not return the change from it's original position in the restPose.

Re: Get Node/Bone Position

Posted: Fri Sep 28, 2018 4:00 am
by Jason Campbell
That is cool. This come up in a project your working on? If so, what required its use? Also, is there anything stopping this from working with a vehicle?

Re: Get Node/Bone Position

Posted: Tue Oct 09, 2018 6:24 pm
by Steve_Yorkshire
I had it for "reasons" ... can't actually remember why. Nothing stopping it from working with any object type/class.