Note: Poly meshes and GetVirtualObjects()



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/06/2008 at 02:05, xxxxxxxx wrote:

    User Information:
    Cinema 4D Version:    
    Platform:      
    Language(s) :

    ---------
    Hallo,

    One of the most asked question on the forum is how to get the current state of an object within GetVirtualObjects(), meaning how to get on the polygons. There are some misconceptions floating around so I decided to make this sticky for easy finding.

    First of all if you just want to get on the polygons of object primitives you have allocated within GetVirtualObjects() please use the GeneratePrimitive() function. You can simply cast it to a PolygonObject, see example below.

    > \> BaseObject \*AtomObject::GetVirtualObjects(PluginObject \*op, HierarchyHelp \*hh) \> { \>      BaseContainer bc; \>      bc.SetVector(PRIM_CUBE_LEN, 200.0); \>      bc.SetBool(PRIM_CUBE_DOFILLET, TRUE); \>      bc.SetReal(PRIM_CUBE_FRAD, 40.0); \>      bc.SetLong(PRIM_CUBE_SUBF, 5); \> \>      PolygonObject \*res = NULL; \>      res = (PolygonObject\* )GeneratePrimitive(NULL, Ocube, bc, 1.0, FALSE, hh->GetThread()); \>      if(!res) goto Error; \> \>      return res; \> \> Error: \>      blDelete(res); \>      return NULL; \> } \>

    If you can not use GeneratePrimitive, for instance if the object has been allocated outside of your plugin, you have to make a clone of it and insert into a temporary document. Then use the Current State To Object command on it, see example below.

    > \> BaseObject \*AtomObject::GetVirtualObjects(PluginObject \*op, HierarchyHelp \*hh) \> { \>      BaseContainer bc; \>      bc.SetVector(PRIM_CUBE_LEN, 200.0); \>      bc.SetBool(PRIM_CUBE_DOFILLET, TRUE); \>      bc.SetReal(PRIM_CUBE_FRAD, 40.0); \>      bc.SetLong(PRIM_CUBE_SUBF, 5); \> \>      AutoAlloc<BaseDocument> tdoc; \>      if(!tdoc) return NULL; \> \>      BaseObject \*res, \*cube = NULL; \>      cube = BaseObject::Alloc(Ocube); \>      if(!cube) return NULL; \> \>      tdoc->InsertObject(cube, NULL, NULL, FALSE); \> \>      ModelingCommandData mcd; \>      mcd.doc = tdoc; \>      mcd.op = cube; \>      if(!SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, mcd)) return NULL; \>      res = static_cast<BaseObject\*>(mcd.result->GetIndex(0)); \>      if(res && (res->GetType() == Opolygon)) return res; \> \>      blDelete(res); \>      return NULL; \> } \>

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/06/2008 at 05:19, xxxxxxxx wrote:

    Hmm, what is the reason for insertion into a temp document before using the command?

    I never do this and I also never had an issue or a crash or a memory leak by not using it. Is it really necessary?

    I always use the document passed by the hierarchy help for filling the commanddata.

    btw. I think it´s a good idea to have these sticky threads!

    thanks!



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/06/2008 at 05:57, xxxxxxxx wrote:

    I got the information about the temporary document from the developers. I guess to be really on the safe side the object has to be inserted into a document before CSTO and you shouldn't do this with the original document in GetVirtualObjects().

    cheers,
    Matthias



  • THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

    On 03/06/2008 at 06:04, xxxxxxxx wrote:

    thanks for the info Matthias.


Log in to reply