Game Development Community

Find bones!

by Johnny Picciafuochi · in Torque 3D Professional · 11/23/2009 (6:26 am) · 42 replies

Hi again, how can i find a bone and his position on a mesh?
The mesh need to be skinned? (the bone is not animated i use it only as "pivot")

Thanks, Johnny.
Page «Previous 1 2 3 Last »
#1
11/23/2009 (9:44 am)
Just some more infos.
Doesn't matter if is on script or by c++, i only need to find as for example a button on a computer (mesh) or the hole of a door, also the elevator buttons.

If you know other ways other this one i will be very happy to try ;)
I am not sure if there is a way to put some pivot by the editor.

Thanks anyway Johnny.
#2
11/24/2009 (6:13 am)
Hey guys noone known how check data of bones (child or whatever you wann call it??

Well, this isn't good.
#3
11/24/2009 (11:43 am)
I have not tested this,but it looks like the bone transforms are stored in a vector called "sBoneTransforms" - tsMesh.cpp

I don't know if this vector is sorted or not,i don't know how dependences are organized,but it is a good start point.
#4
11/24/2009 (11:48 am)
Thanks man, it's surely a start!
I really like to have a sort of Api documentation in what every class do in torque.. And of course i will pay for that!!
I like this engine but still feel uncofortable with it, i spent too much time just to do simply things..

I don't understand if i am really a bad programmer wich can't find a good way to work with or if simply many user have same my problems.

Anyway thanks for the answer i will check this file immediately in my home!

Johnny.
#5
11/24/2009 (2:40 pm)
I also think that in tsShapeInstance, the bones are represented like nodes in object space.
So you can try to get the node transform also.
But i don't know how to separate the bone nodes from the real nodes.
#6
11/24/2009 (6:15 pm)
You can use a TSShapeInstance to get a node's transform whether the mesh is static or skinned. The node can also be animated if so desired.

// Get the DTS resource and shape instance
const char* dtsFilename = "door.dts";
Resource<TSShape> shape = ResourceManager::get().load( dtsFilename );
TSShapeInstance* tsi = new TSShapeInstance( shape, true );

// Could add an animation thread and animate the model here if desired

// Lookup the node position
const char* nodeName = "button";
S32 nodeIndex = shape->findNode( nodeName );
Point3F nodePos = tsi->mNodeTransforms[nodeIndex].getPosition();
#7
11/25/2009 (4:31 am)
Thanks guys!

It's very helpfull, i'll do that.

@ Chris
THANK YOU SO MUCH!
Just a question in this way you LOAD a mesh right? If this is true i need to thank you twice as i was searching a way to load mesh by c++!!!

Johnny.
#8
11/25/2009 (2:30 pm)
This line:

Resource<TSShape> shape = ResourceManager::get().load( dtsFilename );

Will either load the shape from disk, or from memory if it has already been loaded into the ResourceManager.
#9
11/27/2009 (5:29 am)
Thanks man it's work!!
OMG you make my life easyer i had really many problems to understand torque way to think, i also didn't understand how script work till i bought torsion! (i really suggest it!!)

Anyway now i just need one more step, do you know how to set the position of the object? I mean i have loaded the door so how can i positioning it? Now it's simply loaded at 0,0,0 right?
Did i need to take the mesh? as i searched on shape class but didn't find any setposition or else, also i didn't find any c++ (already did) loading shape as we did, but i can wrong.. I am a bad searcher!

Thanks anyway you helped me a lot!

Johnny.
#10
11/27/2009 (7:15 am)
This is really strange,but there is something wrong here.
I create a shape with animated node "mount0".

In preload() i do this:
mShape = ResourceManager::get().load( shapeName );

	if (bool(mShape) == false)
      {
         AssertFatal(false, "No shape!");
         return false;
      }

	return true;

In onnewdatablock() of the object :
MatrixF transform;

nodeIndex = mDataBlock->mShape->findNode( "mount0" );  

if(nodeIndex != -1)  {transform.mul(mObjToWorld, mShapeInstance->mNodeTransforms[nodeIndex]);  
	transform.getColumn(3,&nodePos);}

if(isServerObject()){
	Con::printf("server nodeindex %d",nodeIndex);
	Con::printf("server nodepos %f %f %f",nodePos.x,nodePos.y,nodePos.z);
	}

Good,i see now the index and the node world position.
Then i placed this in processtick(),but the information is not updating.
I only see the initial node position.
I am trying to get the animated position as well,but it seems impossible.
#11
11/27/2009 (7:22 am)
Mmm well i found the position not sure if correct or not as i can't see the whole mesh.. Probably because is "under" the map.

When i will be able to move it, i'll check if this happend to me too.

Johnny.
#12
11/27/2009 (7:33 am)
This code:
const char* dtsFilename = "door.dts";  
Resource<TSShape> shape = ResourceManager::get().load( dtsFilename );  
TSShapeInstance* tsi = new TSShapeInstance( shape, true );

did not work for me,because some of the nodes (somehow) are not registered and when you pull their information,you're out of bounds.
I believe same happens to you,that's why you don't see them.

I used this instead :
In your datablock declaration :
Resource<TSShape> mShape;

Then in the datablock preload:
mShape = ResourceManager::get().load( shapeName );

This loads the shape with no bugs,the node array seems correct.
I created 5 nodes and i pull information from each transform.
#13
11/27/2009 (7:38 am)
I had just one node so maybe i didn't notice it.

Anyway i'll check that too.

Sorry if i ask it again but.. Do you know how to position the mesh ("door.dts")?

Did i need to call particular command to destroy or just c++ default way?

Thanks again.
Sorry for my english..

Johnny.
#14
11/27/2009 (7:48 am)
I used a simple class (StaticShape),i placed this code there.
I create the shape from the editor.

The object transform is mObjToWorld.
You can print column 3 to check you position in world.
#15
11/27/2009 (7:52 am)
mm well i need to change the position during the game, so the position is unknown untill the game is created..
That's why i need to know how set the position by code, or script too, i still prefer c++ but...

I hope to find a way before 7pm (1 pm here in my country) as unfortunately i don't have internet access on my home and i truly wanna work on it on week-end!

Johnny.
#16
11/27/2009 (7:57 am)
you can change the position using this:
if(bool(mDataBlock->mShape)) setTransform(mat)
to check if it exist.
#17
11/27/2009 (8:01 am)
So just only:

if(bool(mShape)) setTransform(mat)

??
Did i need to include something? Where you get that setTransform?

mat = matrix?

Sorry for all this questions i am a totally noob on torque..

Johnny.
#18
11/27/2009 (8:10 am)
mat is your new transform to set.

If you want to set only a position (100,100,100) for example..:
if(bool(mShape)) {

MatrixF mat = mObjToWorld;
Point3F newpos;
newpos.set(100,100,100);
mat.setColumn(3,newpos);
setTransform(mat);

}
#19
11/27/2009 (8:16 am)
Wow very helpfull!!!
Thanks man! I appreciate it.
I will re-pay in some way, i promise!

Johnny.
#20
11/30/2009 (4:39 am)
Hi guys.
I did everything you said and it's seem to work. I used the break point to check and all and it's enter on the bool check here before, but i still donìt see the mesh.
It's a dae mesh with the cached dts. I can see it form editor.

Here my code.
Cpp file.
#include "platform/platform.h"



#include "RandomMap.h"
#include "core/resourceManager.h"

IMPLEMENT_CONOBJECT(RandomDG);

RandomDG::RandomDG ()
{
	Resource<TSShape> shape;
}

RandomDG::~RandomDG ()
{

}


void RandomDG::LoadPieces()
{
	const char* dtsfilename = "Hallsection.dae";
	Resource<TSShape> shape;
	shape = ResourceManager::get().load( dtsfilename ); 

	//TSShapeInstance* tsi = new TSShapeInstance(shape ,true);
	if(bool(shape)){  
		
	MatrixF mat = mObjToWorld;  
	Point3F newpos;  
	newpos.set(10,10,10);  
	mat.setColumn(3,newpos);  
	setTransform(mat);  

	 
	}  
}

ConsoleFunction( createrandom_d, void, 0, 0, "(Create a piece)")
{
	RandomDG aza;
	aza.LoadPieces();
  return;
}

Header file

#include "T3D/StaticShape.h"

class RandomDG: public StaticShape {
  public:
   typedef StaticShape Parent;
	RandomDG ();
	~RandomDG ();
	Resource<TSShape> shape;
	void LoadPieces ();
	DECLARE_CONOBJECT(RandomDG);
};

Do you see any error?
Thanks Johnny.
Page «Previous 1 2 3 Last »