How to access nodes within TSStatic
by Vijay · in Torque 3D Professional · 10/08/2013 (11:00 am) · 3 replies
I have a simple house mesh that I placed some dummy nodes inside. I'm loading this mesh as a simple TSStatic so that I can use the built-in collisions. With this approach I cannot find a way to access the nodes within the mesh. Is there a different approach to solve this problem I may be missing? I don't want to turn the house into a StaticShape since not only is that costly but also then I'd have to build collisions for the house. Some of my understanding here and terminology might be wrong but hopefully my point is clear.
As a side note I also need to add that I didn't find a way to query for nodes within a StaticShape object either. A method like setMeshHidden requires a node name so I cannot use more dynamic logic if needed.
Any help is greatly appreciated.
As a side note I also need to add that I didn't find a way to query for nodes within a StaticShape object either. A method like setMeshHidden requires a node name so I cannot use more dynamic logic if needed.
Any help is greatly appreciated.
#2
Maybe this could be adapted to TSStatic, virtually the same as Daniel's link but a bit different in the code.
10/09/2013 (8:19 am)
//change static shape to anything else eg player
void StaticShape::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);
}
ConsoleMethod(StaticShape, getNodePosition, const char*, 3, 3, "(slotname) returns the nodes position")
{
MatrixF mat;
object->getNodeTransform(argv[2], &mat);
Point3F pos(0,0,0);
mat.getColumn(3,&pos);
char* buff = Con::getReturnBuffer(100);
dSprintf(buff, 100,"%g %g %g",pos.x,pos.y,pos.z);
return buff;
}
//in .h after a public:
void getNodeTransform(const char* nodeName, MatrixF* mat);Maybe this could be adapted to TSStatic, virtually the same as Daniel's link but a bit different in the code.
#3
Also, while I like the getNodeTransform method to get a node's position, I need a more general implementation that would let me iterate all the nodes under an object. Like Daniel said, that would enable creating a more dynamic level. That was part of my original motivation for this question.
Any thoughts or suggestions here?
10/09/2013 (4:41 pm)
Thanks for the replies guys! I'm thinking it might make sense to add these methods at the SceneObject level (with a no-op implementation) so that it is more consistent. Derived objects can chose to override this as they see fit.Also, while I like the getNodeTransform method to get a node's position, I need a more general implementation that would let me iterate all the nodes under an object. Like Daniel said, that would enable creating a more dynamic level. That was part of my original motivation for this question.
Any thoughts or suggestions here?
Torque Owner Daniel Buckmaster
T3D Steering Committee
I'd also love to see more functions for messing with nodes from script. It'd make it possible to, for example, design an entire level in something like Blender, then spawn objects at nodes named with a specific pattern.