Menu

What I've found so far...

Andy
2007-06-25
2013-04-22
  • Andy

    Andy - 2007-06-25

    I'm trying to learn to use this plugin to author PhysX assets for my game. Most important is the ragdoll character.  Here are some of my findings thus far, including both solutions and questions:

    1) the visualization of the D6Joint in max does not work as well as the "legacy" version. it only updates when you use the spinner and then swing2 visualization is completely incorrect when you lock the swing1 rotation.  Also, the color chosen for the joint is unfortunate because when inactive it is the same color as the background, thus unselected joints are effectivly invisable.

    2) If you want to load your game assets into a game engine that uses a left-handed coordinate system, (usually directX, like the PhysXViewer that comes with the SDK...) then your assets will be mirrored due to the coordinate system change.  I use this code in my import routine to correctly load PhysX objects in this case:

            void ConvertMatrix(NxMat34 &mat)
        {
            NxMat33 M = mat.M;
            NxVec3 t = mat.t;

            M.setRow(2, -M.getRow(2));
            M.setColumn(2, -M.getColumn(2));
            t.z *= -1;
           
            mat.M = M;
            mat.t = t;
        }

        bool NXU_preNotifyActor(NxActorDesc &actor, const char    *userProperties)
        {
            ConvertMatrix( actor.globalPose );
               
            for (NxU32 i=0; i<actor.shapes.size(); i++)
            {
                NxShapeDesc *s = actor.shapes[i];
                ConvertMatrix( s->localPose );
            }

            return    true;
        };

    Note that this code negates the z coordinate and reverses rotation around the z-axis by negating the 3rd row and column of the rotation matrix for each actor and shape.

    3) D6Joints - I can't quite get a feel for what the anchor and axis data exported is supposed to be used for.  The default data exported does not work for me so I use this code in my importer:
    (NOTE: I use the convention described in the PhysX docs for ragdolls in the D6Joint section.  The anchor of the joint is placed on the "child" actor, the axes of the joint are also co-incident with the "child" actor in the original pose.)

            bool NXU_preNotifyJoint(NxJointDesc &joint,const char *userProperties)                    
        {        
            joint.setGlobalAnchor(joint.actor[1]->getGlobalPosition());

            NxMat34 parentPoseInverse;
            joint.actor[0]->getGlobalPose().getInverse(parentPoseInverse);
            NxMat34 localPose;
            localPose.multiply(parentPoseInverse, joint.actor[1]->getGlobalPose());

            joint.localAxis[0] = localPose.M * NxVec3(1.0f,0.0f,0.0f);
            joint.localAxis[1] = NxVec3(1.0f,0.0f,0.0f);

            joint.localNormal[0] = localPose.M * NxVec3(0.0f,1.0f,0.0f);
            joint.localNormal[1] = NxVec3(0.0f,1.0f,0.0f);
           
            return true;
        }

    3b) The low twist limit appears to me like it should be negative of what it ends up. I've added this code to my import routine:
                            if( d6Desc->twistMotion != NX_D6JOINT_MOTION_LOCKED )
                {
                    d6Desc->twistLimit.low.value *= -1;
                }

    This post is long enough... More to come as I continue to learn...

     
    • Pranav A Tekchand

      You could also rotate the objects before exporting, using MAXScript:
      (In Max, my ragdoll looks in the +Y direction in max, its right is the +X direction and +Z is UP - (world frame))
      [code]
      rot_mat = rotateXMatrix -90
      -- assuming you have array (myPhysicsObjects) full of the objects you wish to export
      for o in myPhysicsObjects do
      (
          o.transform *= rot_mat
      )
      [/code]
      (and then undo it by rotating +90 maybe to simulate in max itself?)

       

Log in to post a comment.

Auth0 Logo