Getting modelRoot from Actor instance

I have an Actor instance and I want to grab a NodePath to the modelRoot in the Actor so that I can grab the position of the head of my character.

How can I grab a NodePath to the modelRoot of an Actor instance?

Thanks.

Have you tried calling ls() on the actor to see where the ModelRoot is in the hierarchy?

I’m not completely sure how to read the output from ls() but this is what it says:

PandaNode Ralph T:(pos 0 -0.2 0 scale 0.2)
  Character __Actor_modelRoot
    GeomNode (2 geoms: S:(ColorAttrib CullFaceAttrib TextureAttrib))

In the .egg file I just went to the very bottom and added the following:

<Group> head {
  <DCS> { net }
  <Transform> {
    <Matrix4> {
      1 0 0 0
      0 1 0 0
      0 0 1 0
      0 5 0 1
    }
    <Translate> { 0 0 0 }
  }
}

The purpose was simply to reference coordinates at about the character’s head level.

Any ideas?

Why would you want to get the ModelRoot if you want to get the coordinates of the head?

Because the head group is defined in the model? If you have some other way to allow me to get that head group I’m all ears. I just tried finding a way to get there through the Actor API and couldn’t seem to find anything. I tried doing a find("**/head") on the Actor but nothing came back…

If I load the model through loadModel and I do a find("**/find"), I get the correct node and position…so I figured that if I could retrieve the model instance from the Actor then I could do the same thing.

find should work, but you need to explicitly flag model parts in an actor before loading it (using egg-optchar, for example).

Or if you don’t want to get a model part but a joint position, use the controlJoints / exposeJoints interface on the Actor.

I don’t think exposeJoint is what I want because I’m not trying to animate the head - I just want to stick a camera on it as a reference point. What does -optchar do? Is that a flag for the egg exporter?

You could reparent the camera to the head joint.

Ok. I tried exposeJoint() - it still was not correctly handling the “head” group from the egg file (it reported position (0,0,0)), but I went ahead and used exposeJoint and grabbed the HeadBone that was already coded into egg file and it at least returns a non-zero position. I’m hoping this method will work out.

Thanks for the help.

By the way, do you know why Actor has the exposeJoint() method? Why make the developer request access to those constructs explicitly? The model nodes give you access to whatever you want…

Because the geometry in the .egg file is flattened to a single node. The structure is lost. This makes it more efficient to animate it.