Using the Physique Export Interface
 
 
 

Below is a code example using the physique export interface (IPhysiqueExport) which uses the function FindPhysiqueModifier() from the topic Finding a Physique Modifier.

void ExportPhysiqueData(TimeValue t, ModContext &mc, ObjectState *os, INode *node)
{
  Modifier *phyMod = FindPhysiqueModifier(node);
  if (!phyMod) return;    // Physique Modifier does not exist for given Node
 
  // create a Physique Export Interface for the given Physique Modifier        
   IPhysiqueExport *phyExport = ( IPhysiqueExport*)phyMod->GetInterface(I_PHYINTERFACE);
  if (phyExport)
  {
    // create a ModContext Export Interface for the specific node of the Physique Modifier
     IPhyContextExport *mcExport = ( IPhyContextExport *)phyExport->GetContextInterface(node);
    if (mcExport)
    {
      // we convert all vertices to Rigid in this example
      mcExport->ConvertToRigid(TRUE);
      
      // compute the transformed Point3 at time t
      for (int i = 0; i < os->obj->NumPoints();  i++)
      {
          IPhyVertexExport *vtxExport = mcExport->GetVertexInterface(i);
         if (vtxExport)
         {
             //need to check if vertex has blending
             if (vtxExport->GetVertexType() & BLENDED_TYPE)
            {
               IPhyBlendedRigidVertex *vtxBlend = ( IPhyBlendedRigidVertex *)vtxExport;
               Point3 BlendP(0.0f, 0.0f, 0.0f);
                for (int n = 0; n < vtxBlend->GetNumberNodes(); n++)
               {
                 INode *Bone = vtxBlend->GetNode(n);
                 Point3 Offset = vtxBlend->GetOffsetVector(n);
                  float Weight = vtxBlend->GetWeight(n);
                  BlendP += (Bone->GetNodeTM(t) * Offset) * Weight;
               }
             
                // set the Point of the object (to test the export is correct)
                os->obj->SetPoint(i, BlendP);
                mcExport->ReleaseVertexInterface(vtxExport);
                vtxExport = NULL;
            }
             else
            {
               IPhyRigidVertex *vtxNoBlend = ( IPhyRigidVertex *)vtxExport;
               INode *Bone = vtxNoBlend->GetNode();
               Point3 Offset = vtxNoBlend->GetOffsetVector();
                                        
                // set the Point of the object (to test the export is correct)
                os->obj->SetPoint(i, Bone->GetNodeTM(t) * Offset);
                mcExport->ReleaseVertexInterface(vtxExport);
                vtxExport = NULL;
            }
          }
        }
        phyExport->ReleaseContextInterface(mcExport);
      }
      phyMod->ReleaseInterface(I_PHYINTERFACE, phyExport);
    }