Extracting the Mesh from a Node
 
 
 

The INode::EvalWorldState() method should be called when a developer needs to work with an object that is the result of the node's pipeline. This is the object that appears in the scene. This may be an object that is not referenced - it may just be an object that has flowed down the pipeline.

For example, if there is a Sphere object in the scene that has a Bend modifier and Taper modifier applied, INode::EvalWorldState() would return an ObjectState containing a TriObject. This is the result of the sphere turning into a TriObject and being bent and tapered (just as it appeared in the scene). For more information on the ObjectState see the topic ObjectState.

If a developer needs to access the object that the node in the scene references, then the method INode::GetObjectRef() should be used instead.

// Get the object from the node
ObjectState os = node->EvalWorldState(ip->GetTime());
if (os.obj->SuperClassID()==GEOMOBJECT_CLASS_ID)
{
  obj = (GeomObject*)os.obj;
  //...
}

The following code shows how a TriObject can be retrieved from a node. Note on the code that if you call Object::ConvertToType() on an object and it returns a pointer other than itself, you are responsible for deleting that object.

// Return a pointer to a TriObject given an INode or return NULL
// if the node cannot be converted to a TriObject
TriObject *Utility::GetTriObjectFromNode(INode *node, BOOL &deleteIt)
{
  deleteIt = FALSE;
  Object *obj = node->EvalWorldState(ip->GetTime()).obj;
  if (obj->CanConvertToType(Class_ID(TRIOBJ_CLASS_ID, 0)))
  {
    TriObject *tri = (TriObject *) obj->ConvertToType(ip->GetTime(),
    Class_ID(TRIOBJ_CLASS_ID, 0));
 
    // Note that the TriObject should only be deleted
    // if the pointer to it is not equal to the object
    // pointer that called ConvertToType()
    if (obj != tri) deleteIt = TRUE;
    return tri;
  }
  else
  {
    return NULL;
  }
}

The following code demonstrates usage of the above function.

// Retrieve the TriObject from the node
BOOL deleteIt = FALSE;
TriObject *triObject = GetTriObjectFromNode(ip->GetSelNode(0), deleteIt);
 
// Use the TriObject if available
if (!triObject) return;
 
// perform processing
// ...
 
// Delete it when done if we own it
if (deleteIt) triObject->DeleteMe();