Mass-spring system updating

On 25/02/2013 at 02:22, xxxxxxxx wrote:

User Information:
Cinema 4D Version:   R12 
Platform:   Windows  ;   Mac OSX  ; 
Language(s) :     C++  ;

---------
In order to perform some soft-body deformations using a deformer object, I want to use a mass-spring system applied to the vertices and edges of the polygonized mesh sent to ModifyObject().  My problem is that I definitely do not want to create the mass-spring system every time ModifyObject() is called but only initially and when there are changes to the object being deformed that might require a rebuild of the system.  Would GetDirty(DIRTYFLAGS_DATA) be enough?  What if the user edits the mesh in some way (for already polygon objects)?  What messages might I be looking for in my deformer object from its 'parent' (if any)?

Thanks,

On 28/02/2013 at 12:43, xxxxxxxx wrote:

No one?  I had an inkling that checking for DIRTYFLAGS_DATA in ModifyObject() wouldn't work.  It updates the system constantly because it is always dirty.  It only needs to be done if the user changes some property or the mesh - really, not just to kick in ModifyObject().

Any takers?

On 28/02/2013 at 14:01, xxxxxxxx wrote:

Alrighty, then.  After a bit of experimentation, this works the best.  I provide this to alleviate the suffering of others in the future. :)

Note: the mass-spring system is created/recreated in ModifyObject() only because I get a ready-made polygon object.

// ObjectData.CheckDirty  
//*---------------------------------------------------------------------------*  
void DeformerObj::CheckDirty(BaseObject* op, BaseDocument* doc)  
//*---------------------------------------------------------------------------*  
{  
  if (!doc)                        return;  
  if (!op)                        return;  
  
  // Check Deformed object  
  BaseObject*        dop =            op->GetUp();  
  if (dop)  
  {  
      ULONG        dd =            dop->GetDirty(DIRTYFLAGS_MATRIX|DIRTYFLAGS_DATA);  
      if (dd != dDirty)  
      {  
          dDirty =    dd;  
          op->SetDirty(DIRTYFLAGS_DATA);  
          // A data change constitutes a need to recreate Mass-Spring System  
          needInitMassSpring =    TRUE;  
          return;  
      }  
  }  
  
  // Check Collider object  
  BaseContainer*    bc =            op->GetDataInstance();  
  if (!bc)                        return;  
  // - Get linked object  
  BaseObject*        lop =            (BaseObject* )bc->GetLink(DEFORMER_OBJECT, doc, Obase);  
  if (!lop)                        return;  
  ULONG            dirtyness =        lop->GetDirty(DIRTYFLAGS_MATRIX|DIRTYFLAGS_DATA);  
  // - Linked object is not dirty  
  if (dirtyness == cDirty)        return;  
  // - is dirty  
  cDirty =                        dirtyness;  
  op->SetDirty(DIRTYFLAGS_DATA);  
}

On 01/03/2013 at 00:08, xxxxxxxx wrote:

Hi Robert,

Thanks for sharing the solution.