Discriminate over different types of DzNode

mattiascibienmattiascibien Posts: 140
edited December 1969 in Daz SDK Developer Discussion

Hello,
work on my thesis finally produced some... wrong results unfortunately.

I have actually worked with DzSkeleton in my Bullet world (I cannot explain much more since the library I am working on is not available to the public now) but I actually need to work with all the other subclasses of DzNode, in particular everything that has a geometry.

How can I discriminate towards these classes? Since if I use DzNode class i get, other than DzSkeleton's geometry, even the geometry of every child (DzBone).

So checking if DzNode has geometry is not an option.

I have read of QtObject metatype system but I am not sure on how to use it.

Comments

  • Richard HaseltineRichard Haseltine Posts: 96,707
    edited December 1969

    You should check the inheritance and className of the node - but I think you are asking about the C++ SDK, not scripting, in which case this needs to be moved.

  • mattiascibienmattiascibien Posts: 140
    edited December 1969

    Yes. I was asking about the C++ SDK. Sorry for the wrong post. So should I use the ->className() in qt? does it return DzSkeleton if i pass a DzNode to it?

  • Richard HaseltineRichard Haseltine Posts: 96,707
    edited December 1969

    Moved to the SDK forum.

    I know only scripting, but if the item is a DzSkeleton then classFactory().className() will return that - as long as it's supported (check it inherits DzBase) - if I understand the DS3 docs I just looked at. (In script classname is directly available in the base class).

  • mattiascibienmattiascibien Posts: 140
    edited December 1969

    I am going to try something... Thank for your help. I will post something when I discover it.

  • samurlesamurle Posts: 94
    edited December 1969

    If you want to know if a node inherits DzSkeleton, you can do this:

    
    if(node->inherits("DzSkeleton")) {
    }
    

    But, I wouldn't do this for the 4.5 SDK. I would instead check for DzFigure:

    
    if(node->inherits("DzFigure")) {
    }
    


    As the figure contains the skeleton, this is what you probably want to use.

    I don't think skeletons can exist without a figure in the 4.5 SDK.
    The SDK does it best to prevent you from allocating an instance of some classes.

    I was able to do it with the 3.x SDK, but not anymore.

  • Richard HaseltineRichard Haseltine Posts: 96,707
    edited December 1969

    There are now two types of figure and they are both sub-classes of DzSkeleton - DzFigure is a TriAx figure, DzLegacyFigure is what would have been a DzSkeleton in DS3.

  • mattiascibienmattiascibien Posts: 140
    edited December 1969

    But whi can't it work using DzSkeleton? Isn't it a class which is inherited by DzFigure and DzLegacyFigure?

  • samurlesamurle Posts: 94
    edited December 1969

    gravity0 said:
    But whi can't it work using DzSkeleton? Isn't it a class which is inherited by DzFigure and DzLegacyFigure?

    You can search for DzSkeleton in nodes if you want. What I'm saying is you can also search for DzFigure instead,
    and cast that to a skeleton. This is because skeletons don't seem to exist by themselves.
    DzFigure also contains access to other useful data, like the skin and bone binding, weights, etc...

  • mattiascibienmattiascibien Posts: 140
    edited December 1969

    For what I need right now (retrieving node's geometry) checking for !DzBone (to prevent from adding both skeleton geometry and bones geometry twice) seems to be my case. Testing ASAP. ;)

  • Richard HaseltineRichard Haseltine Posts: 96,707
    edited December 1969

    coredevel said:
    gravity0 said:
    But whi can't it work using DzSkeleton? Isn't it a class which is inherited by DzFigure and DzLegacyFigure?

    You can search for DzSkeleton in nodes if you want. What I'm saying is you can also search for DzFigure instead,
    and cast that to a skeleton. This is because skeletons don't seem to exist by themselves.
    DzFigure also contains access to other useful data, like the skin and bone binding, weights, etc...

    At the (considerable) risk of misusing terminology I thin DzSkeleton is a virtual class - you can't create members, but you can create members of it's derivatives (DzFigure and DzLegacyFigure). You should, however, use DzSkeleton as an inheritance check if you are in a situation where either derivative type would be relevant.

  • rbtwhizrbtwhiz Posts: 2,178
    edited December 1969

    I haven't compiled this... but if it doesn't, it should be pretty close...

    // Get the primary selection
    DzNode *node = dzScene->getPrimarySelection();
    // If we've got a node selected
    if( node )
    {
     // If the node can be cast to a DzBone
     if( qobject_cast(node) )
     {
      // We want the skeleton node
      node = node->getSkeleton();
     }
    
     // Get the object
     DzObject *object = node->getObject();
     // If we've got an object
     if( object )
     {
      // Get the current shape
      DzShape *shape = object->getCurrentShape();
      // If we've got a shape
      if( shape )
      {
       // Get the geometry
       DzGeometry *geometry = shape->getGeometry();
      }
     }
     // Else if we don't have an object
     else
     {
      // Provide feedback
      QMessageBox::warning(dzApp->getDialogParent(),
       tr("Resource Error"), tr("The selected item has no object."), QMessageBox::Ok );
     }
    }
    // Else if a node is not selected
    else
    {
     // Provide feedback
     QMessageBox::warning(dzApp->getDialogParent(),
       tr("Selection Error"), tr("You must have a node in the scene selected."), QMessageBox::Ok );
    }

    If you want to limit which DzNode subclasses you get the object from, you can use something like...

     // Declare and initialize a DzObject pointer that we'll check for later
     DzObject *object = NULL;
     
     // If the node can be cast to a [weight mapped] DzFigure
     if( DzFigure *figure = qobject_cast(node) )
     {
      // Get the object
      object = figure->getObject();
     }
     // Else if the node can be cast to a [parametric] DzLegacyFigure
     else if( DzLegacyFigure *legacyFigure = qobject_cast(node) )
     {
      // Get the object
      object = legacyFigure->getObject();
     }
     // Else if the node can be cast to a DzSkeleton
     else if( DzSkeleton *skeleton = qobject_cast(node) )
     {
      // Get the object
      object = skeleton->getObject();
     }

    ... in place of...

     // Get the object
     DzObject *object = node->getObject();

    -Rob

Sign In or Register to comment.