Crystal Space
Welcome, Guest. Please login or register.
December 21, 2014, 04:24:45 pm

Login with username, password and session length
Search:     Advanced search
9032 Posts in 2046 Topics by 9297 Members
Latest Member: Adrihjapa
* Home Help Search Login Register
+  Crystal Space
|-+  Crystal Space Development
| |-+  Support
| | |-+  Attach a mesh to a Socket
« previous next »
Pages: [1] Print
Author Topic: Attach a mesh to a Socket  (Read 1986 times)
Lonewolf
Newbie
*
Posts: 10


View Profile Email
« on: September 05, 2008, 11:37:03 am »

Hi,
I'm trying to attach a mesh to a socket, what I want is that this mesh can follow the movement of
the socket positioned on another mesh. I followed this link http://www.crystalspace3d.org/trac/CS/attachment/ticket/340/sockets.txi
but there a thing that I don't understand on the source code (that I report hereunder):


bool AttachMesh (iMeshWrapper* actorMesh, const char* socketName,
106           const char* objectFactoryName)
107   @{
108     iMeshFactoryWrapper* objectFactory = engine->GetMeshFactories ()
109           ->FindByName (objectFactoryName);
110     if (!objectFactory) return false;
111     csRef<iMeshWrapper> object = engine->CreateMeshWrapper (objectFactory,
112           objectFactoryName);
113     csRef<iGeneralMeshState> genstate = scfQueryInterface<iGeneralMeshState> (
114           GetMesh ()->GetMeshObject ());
115     if (genstate)
116     {
117       csRef<iGenMeshAnimationControl> skelstate = genstate
118           ->GetAnimationControl ();
119       if (skelstate)
120       {
121         csRef<iGenMeshSkeletonControlState> ctlstate =
122           scfQueryInterface<iGenMeshSkeletonControlState> (skelstate);
123         if (ctlstate)
124         {
125           csRef<iSkeleton> skel = ctlstate->GetSkeleton ();
126           if (skel)
127           {
128             iSkeletonSocket* skelsocket = skel->FindSocket (socketName);
129             if (!skelsocket) return false;
130             object->QuerySceneNode ()->SetParent (actorMesh->QuerySceneNode ());
131             skelsocket->SetSceneNode (object->QuerySceneNode ());
132             return true;
133           }
134         }
135       }
136     }
137   @}


This method get three parameters, the name of the mesh with socket, the name
of the socket, and the objectFactoryName that really I have no idea what
is......can be the name of the mesh that I want to attach? I tryed to put this name
but without success...

Any Suggest? Wink

Thanks!

Logged
Lonewolf
Newbie
*
Posts: 10


View Profile Email
« Reply #1 on: September 06, 2008, 03:49:41 pm »

Guys A fixed my problem! Wink

However Thanks! Wink

Logged
Shimon
Newbie
*
Posts: 8


View Profile Email
« Reply #2 on: September 22, 2008, 03:40:43 pm »

Could you please share the solution?

Others might have the same problem you had.

For example, I do wink

Thank you.
Logged
Shimon
Newbie
*
Posts: 8


View Profile Email
« Reply #3 on: September 22, 2008, 04:17:08 pm »

Ok, I think I got the solution.

IMHO the code to attach a mesh to a skeleton socket should be:


/**
  * actorMesh: the mesh to whose skeleton you want to attach another mesh
  * socketName: the name of the socket where you want to attach the mesh
  * objectFactoryName: the name of the factory of the mesh you want to attach to the socket
  * engine: a reference to the engine
  */
bool AttachMesh (iMeshWrapper* actorMesh, const char* socketName,
       const char* objectFactoryName, csRef<iEngine> engine){

  iMeshFactoryWrapper* objectFactory = engine->GetMeshFactories()
    ->FindByName (objectFactoryName);

  if (!objectFactory) return false;

  csRef<iMeshWrapper> object = engine->CreateMeshWrapper (objectFactory,
                       objectFactoryName);

  csRef<iGeneralMeshState> genstate = scfQueryInterface<iGeneralMeshState> (
    actorMesh->GetMeshObject ());

  if(genstate){
    csRef<iGenMeshAnimationControl> skelstate = genstate->GetAnimationControl();
 
   if(skelstate){
      csRef<iGenMeshSkeletonControlState> ctlstate =
   scfQueryInterface<iGenMeshSkeletonControlState> (skelstate);

      if (ctlstate){
   csRef<iSkeleton> skel = ctlstate->GetSkeleton ();

   if(skel){
     iSkeletonSocket* skelsocket = skel->FindSocket (socketName);
     if (!skelsocket) return false;
     object->QuerySceneNode ()->SetParent (actorMesh->QuerySceneNode ());
     skelsocket->SetSceneNode (object->QuerySceneNode ());
     return true;
   }
      }
    }
  }
  return true;
}


At least it works for me!
Logged
Pages: [1] Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.2 | SMF © 2006-2007, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 7.345 seconds with 16 queries.