Attach stuff to a model.. ( weapons, armor etc..)

You are an experienced programmer and have a problem with the engine, shaders, or advanced effects? Here you'll get answers.
No questions about C++ programming or topics which are answered in the tutorials!
erSitzt
Posts: 52
Joined: Sun May 09, 2004 11:59 am

Attach stuff to a model.. ( weapons, armor etc..)

Post by erSitzt »

Hi,

i want to attach different stuff to my models (at this point only weapons... i dont want to try clothing yet.. ) and i want to use skeletal animation, but i am not sure which modelformat i should use.

What experiences do you have with the different modelformats ?
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Post by the_viking »

AFAIK The only way to attach something to joints of models in irrlicht is to use the DirectX (extension "*.x") format. So this would answer your question which format to use ;)
niko
Site Admin
Posts: 1759
Joined: Fri Aug 22, 2003 4:44 am
Location: Vienna, Austria
Contact:

Post by niko »

I think this is also possible with Milkshape .ms3d files.
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Post by the_viking »

okay, as I said, "AFAIK" ;).. remembered just a thing like getXJoint.. but as you're saying, i begin remembering there was something about Milkshape files, too... ;) Hm... anyhow it would be good if there would be support to attach things to vertices, so that the move like the vertices do... have to think about a implementation for my project.. ;)
nitroman

Post by nitroman »

AFAIK The only way to attach something to joints of models in irrlicht is to use the DirectX (extension "*.x") format.
this is exactly what I wanted to know... (it's great that I used the search function of the forums)

how do you do that? Can you give me some code please?

thanks :)
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Post by the_viking »

First you load an x or an ms3d file:

Code: Select all

// the player model
IAnimatedMesh* pPlayerMesh = pSmgr->getMesh("./data/player.ms3d");

// the weapon model
IAnimatedMesh* pWeaponMesh = pSmgr->getMesh("./data/weapon.3ds");

// insert two scene nodes for weapon and player
IAnimatedMeshSceneNode* pnPlayer = pSmgr->addAnimatedMeshSceneNode( pPlayerMesh );
pPlayerMesh->drop();

IAnimatedMeshSceneNode* pnWeapon = pSmgr->addAnimatedMeshSceneNode( pWeaponMesh );
pWeaponMesh->drop();

// this is a scene node where we can attach things to joints
ISceneNode* pJointNode = pnPlayer->getMS3DJointNode("weapon_attach");
if(pJointNode)
{
  pJointNode->addChild( pnWeapon );
}
That's it. This should work (i didn't test it). For detailed documentation visit the Irrlicht Docu. i.e. this page: click

\edit:
As I discovered, it seems to work just with MILKSHAPE files. Or the getMS3DJointNode() method of the IAnimatedMeshSceneNode returns also joints from X files...
erSitzt
Posts: 52
Joined: Sun May 09, 2004 11:59 am

Post by erSitzt »

Thanks a lot !!! After spending several hours with Milkshape i now have a model to try that... i'll post my progress with this... :)

btw. : this is my first model :

http://sh1t.kicks-ass.org/dummy_skel2.jpg
... yes, its ugly ...
bal
Posts: 829
Joined: Fri Jun 18, 2004 5:19 pm
Location: Geluwe, Belgium

Post by bal »

Joints <> bones?

Because in Blender you can only name the bones I think.
General Tools List
General FAQ
System: AMD Barton 2600+, 512MB, 9600XT 256MB, WinXP + FC3
the_viking
Posts: 23
Joined: Fri Aug 06, 2004 12:28 pm

Post by the_viking »

Joints are the connections between the bones... every model has a root joint. So you have a hierarchy like this:

Code: Select all

     o--o
    /
o--o
    \
     o--o

- = bone
o = joint
So i think if you name a bone, you name the joint that is facing away from the Root joint. But so the root joint would have no name... hm.. looks like you have to do some trial & error with blender
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

As I discovered, it seems to work just with MILKSHAPE files. Or the getMS3DJointNode() method of the IAnimatedMeshSceneNode returns also joints from X files...
I have added the function getXJointNode(0 see here http://irrlicht.sourceforge.net/phpBB2/ ... 66e2573262

Unfortunately, according to this thread http://irrlicht.sourceforge.net/phpBB2/ ... 0044#20044
getMatrixOfJoint(used in internally for both ms3d and x joint child nodes) returns an incorrect position for joints not at the bottom of the hierarchy. I haven't tested that myself, and I'm surprised niko wouldn't have noticed a large bug like that, but regardless of whether you chose .x or .ms3d, if you try to attach something to a joint and it seems to be coming out wrong, keep that in mind.
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
etcaptor
Posts: 871
Joined: Fri Apr 09, 2004 10:32 pm
Location: Valhalla
Contact:

Post by etcaptor »

Is this method actual for *.x models or is only for MS3D models?
nitroman

Post by nitroman »

thanks! the _viking for this code ! :D

electron: is there a work-around for this bug? :?:
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

Is this method actual for *.x models or is only for MS3D models?
Not sure if I understand this right. Niko only has a method for .ms3d models. I added one for .X that works exactly the same way, presuming getMatrixOfJoint is working correctly for both

electron: is there a work-around for this bug?
I have not myself confirmed that a bug even exists. The call to getMatrixOfJoint for .x models returns the Combined animation matrix which the engine uses internally for skinning the mesh after skeletal aimation has been performed. If the CombinedAnimationMatrix was incorrect I believe the models would show up incorrectly on the screen (though I took only a very cursory look at the code in CXAnimationPlayer.cpp).
One thing to note is that while the getMatrixOfJoint accepts both the joint number and the frame as parameters, as far as I can tell the frame parameter is actually ignored and the joint transformation returned is that of the joint at the curent frame. For ms3d meshes the frame parameter is actually taken into account.

When I get a chance I will test things myself and try to find a fix if there is in fact a bug.

BLAST IT: I just read the bug thread again and buhatkj just replied with a pic of transformations gone wrong. I guess there is a problem. I'll look into, though complicated matrix transformations are not an area where I'm totally comfortable
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

found this in CXanimationPlayer::animateSkeleton. It might have something to do with our problem. Unfortunately my mathematical skills are not exactly up to the tsk of fixing niko's spherical linear interpolations :cry:

Code: Select all

// animate it
switch(currentSet.Animations[i].keyType)
{
    case 0: // rotation
  {	
  // with this code, rotations are not 100% ok, they are 
   // mirrored.
   core::quaternion q;
   q.Slerp(currentSet.Animations[i].Quaternions[idx1],
    currentSet.Animations[i].Quaternions[idx2], factor);

     joint.LocalAnimatedMatrix *= q.getMatrix();
     joint.WasAnimatedThisFrame = true;
    }
    break;
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Electron
Posts: 874
Joined: Sun Mar 14, 2004 12:05 am
Location: Massachusetts USA

Post by Electron »

found this quaternion thread. Might be useful, though I think the dates are from before 0.6 so the fixes given there might already be in the engine
http://irrlicht.sourceforge.net/phpBB2 ... rp&start=0
You do a lot of programming? Really? I try to get some in, but the debugging keeps me pretty busy.

Crucible of Stars
Post Reply