DzBone and weight maps handling in the SDK

Alessandro MastronardiAlessandro Mastronardi Posts: 2,502
edited December 1969 in Daz SDK Developer Discussion

I wanted to ask if there is any any bit of code or sample in your SDK archives showing the process of creating a DzBone, assign a DzFaceGroup to it, and set the bone properties such as the origin/end/orientation values, rotation order, thus replicating what you usually do manually using the joint tool in Studio.
Also, once the bone is in place, which classes can I use to add a weight map and fill it with a polygon selection group?

Comments

  • dtammdtamm Posts: 126
    edited June 2015

    The following is untested and won't currently compilte, but should show the basic steps.

    
    
    
     // create a DzGraftingFigureShape
     DzGraftingFigureShape* tgtShape = new DzGraftingFigureShape;
     tgtShape->setName( "Your Name" );
     tgtShape->setFacetMesh( yourFacetMesh );
    
     // add material(s) to your shape using something like
     DzMaterial* material = new DzDefaultMaterial;
     material ->setName("material name")
     tgtShape->addMaterial( cur );
    
     // make a figure
     DzFigure* tgtFigure = new DzFigure();
     tgtFigure->setLabel( "Your Figure Label" );
     tgtFigure->setName( "Your Figure Name");
     tgtFigure->setOrigin( DzVec3(0, 0, 0), true );  // probably not the best origin
    
    
     // make an object
     DzObject* tgtObj = new DzObject();
     tgtFigure->setObject( tgtObj );
     tgtObj->addShape( tgtShape );
    
     // set the end point to center of bounding box.
     DzBox3 box = tgtShape->getFacetMesh()->getBoundingBox();
     tgtFigure->setEndPoint( box.getCenter(), true );
    
     // make a selection map
     DzSelectionMap* selMap = new DzSelectionMap();
     tgtFigure->setSelectionMap( selMap );
    
     // skinBining
     DzSkinBinding* skinBinding = tgtFigure->getSkinBinding();
     DzBoneBinding* boneBinding = NULL;
    
     // make a bone
     DzBone* tgtBone = new DzBone();
     tgtBone->setRotationOrder( srcNode->getRotationOrder() );
     tgtBone->setOrigin( DzVec3(0, 0, 0), true );
     tgtBone->setEndPoint( DzVec3(0, 0, 1), true );
     tgtBone->setOrientation( DzQuat(), true );
     tgtBone->setName( "Your Bone Name");
     tgtBone->setLabel( "Your Bone Label");
     tgtBone->setInheritScale( true );
    
     // add the bone
     dzScene->addNode( tgtBone );
     tgtFigure->addNodeChild( tgtBone );
    
     // make a bone binding
     boneBinding = new DzBoneBinding();
     boneBinding->setBone( tgtBone );
    
     // map to face group name to bone
     selMap->addPair( "your face group name", tgtBone );
    
     if(doTriaAxis)
     {
      for( int i = 0; i < 3; i++ )
      {
       DzWeightMapPtr map = new DzWeightMap();
       map->setNumWeights( numVerts );
       initWeightMap( map, numVerts );
       boneBinding->setLocalWeights( map, i );
      }
    
      DzWeightMapPtr map = new DzWeightMap();
      map->setNumWeights( numVerts );
      initWeightMap( map, numVerts );
      boneBinding->setScaleWeights( map );
     }
     else
     {
      DzWeightMapPtr map = new DzWeightMap();
      map->setNumWeights( numVerts );
      initWeightMap( map, numVerts );
      boneBinding->setWeights( map );
    
      skinBinding->setBindingMode( DzSkinBinding::General );
      skinBinding->setScaleMode( DzSkinBinding::BindingMaps );
     }
    
     skinBinding->addBoneBinding( boneBinding );
    
     // setup a presentation
     DzPresentation* pres = new DzPresentation();
     pres->setType( isClothing ? "Follower" : "Actor" );
     pres->setLabel( tgtFigure->getLabel() );
     tgtFigure->setPresentation( pres );
    
     dzScene->addNode( tgtFigure );
    
    
    Post edited by dtamm on
  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,502
    edited December 1969

    Thanks a lot for the information, I'm going to do some testing.

  • Alessandro MastronardiAlessandro Mastronardi Posts: 2,502
    edited July 2015

    Hello dtamm, if possible I'd like some explanation about the initWeightMap function, which doesn't exist in the SDK. If you could tell me what it's supposed to do I'd really appreciate it. (never mind, understood what this function needs to do)...

    Also, I'd like to know how to gather getNumVerts() from the a DzFaceGroup; in dzfacegroup.h there are several commented functions (one of those is indeed getNumVerts()), and so I'm out of options about getting that value. Or, better, how to get the vertex collection out out of a facegroup.

    I think I got to work what I needed.
    Thanks

    Post edited by Alessandro Mastronardi on
Sign In or Register to comment.