Create plane as polygon object



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

    On 28/02/2009 at 14:07, xxxxxxxx wrote:

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

    ---------
    Hi,

    in a generator object plugin (function GetVirtualObjects()), I create a plane primitive.

    > \> BaseObject \*plane = BaseObject::Alloc(Oplane); \>

    Now I want to get an editable PolygonObject from that, because I have to do several operation on the plane's points. How do I do that?

    I have tried just calling plane->GetCache(), but the Cache is always NULL (I guess this is because the "plane" object is not in the document).

    I also tried using the Modeling Command MCOMMAND_MAKEEDITABLE but it doesn't work. Same with MCOMMAND_CURRENTSTATETOOBJECT. After calling the command, the object "res" contains something, but whatever it is, it doesn't have any polygons or points. I guess this is again the case because the "plane" object is not in the document.

    > \> BaseObject \*res = NULL; \> ModelingCommandData cd; \> cd.doc = doc; \> cd.op = plane; \> if (SendModelingCommand(MCOMMAND_MAKEEDITABLE, cd)) \> { \> BaseObject \*result = static_cast<BaseObject\*>(cd.result->GetIndex(0)); \> result->CopyTo(res, COPY_NO_ANIMATION|COPY_NO_BITS|COPY_NO_INTERNALS, NULL); \> BaseObject::Free(result); \> } \>

    Much talk, little question: How do I create a plane mesh which I can manipulate?

    Thanks in advanced for any help!

    Greetings,
    Jack



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

    On 28/02/2009 at 14:29, xxxxxxxx wrote:

    Addition:

    When I try to retrieve the PointCount from the plane, the result is always 0. It seems, the plane doesn't have any points or polygons at all.

    > PointCount = ToPoly(plane)->GetPointCount();

    Anyway, when I just return the plane object from GetVirtualObjects(), it appears in the editor without any problems. It seems, the plane generates its points and polygons when it is returned, and not when it is created.

    Still, I need to get access to the points before returning it.

    Cheers,
    Jack



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

    On 28/02/2009 at 16:05, xxxxxxxx wrote:

    Hi Jack,

    the current state to object modeling command fills the atomarray "result" with the converted polygon object. Simply retrieve it from the AtomArray and make sure to free the object yourself (you take over the ownership).

    See the ModelingCommandData class docs for more information.

    Edit: Oops, sorry, haven´t seen that you are already doing so! Maybe the object is a null object with the poly object being the first child of it? Cannot think of anything else. Works fine here (but only MCOMMAND_CURRENTSTATETOOBJECT, EDITABLE doesn´t work here either). It shouldn´t make a difference if hte plane is in the scene or not, the doc from the HierarchyHelp is a virtual scene anyway and not the real document. It should work fine I think.



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

    On 01/03/2009 at 03:48, xxxxxxxx wrote:

    Hi Samir. No, there are definitely no polygons in the command's result. If they were in some child object, they should appear when I return the result in GetVirtualObjects(). But nothing happens.

    Maybe I do something wrong with the MCOMMAND_CURRENTSTATETOOBJECT. It works fine if I use it on an object in the document, but it does not work on an object that I created in the code. Do you have a little example code, maybe? *smile*

    Cheers,
    Jack



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

    On 01/03/2009 at 03:58, xxxxxxxx wrote:

    Hm, I still can't get it to work. It always crashes when I try to use CopyTo() on the modeling command's result. Here's the code:

    > ModelingCommandData cd; \>      PolygonObject     \*geom = NULL;          // Result of CSTO should ge here \>      BaseObject          \*plane = BaseObject::Alloc(Oplane);     // The plane primitive \>      if (!plane) goto GenerateError;          // Error handling \> \>      // Set standard values for plane \>      BaseContainer \*pd = plane->GetDataInstance(); \>      pd->SetReal(PRIM_PLANE_WIDTH, bc->GetReal(SURFACESPREAD_LANDSCAPE_SIZE_X)); \>      pd->SetReal(PRIM_PLANE_HEIGHT, bc->GetReal(SURFACESPREAD_LANDSCAPE_SIZE_Y)); \>      pd->SetLong(PRIM_PLANE_SUBW, bc->GetLong(SURFACESPREAD_LANDSCAPE_SUB_X)); \>      pd->SetLong(PRIM_PLANE_SUBH, bc->GetLong(SURFACESPREAD_LANDSCAPE_SUB_Y)); \> \>      cd.doc = hh->GetDocument(); \>      cd.op = plane; \>      if (SendModelingCommand(MCOMMAND_CURRENTSTATETOOBJECT, cd)) \>      { \>           BaseObject \*result = static_cast<BaseObject\*>(cd.result->GetIndex(0)); \>           result->CopyTo(geom, COPY_NO_ANIMATION|COPY_NO_BITS|COPY_NO_INTERNALS, NULL);   // CRASH!! \>           BaseObject::Free(result); \>      } \> \>      // Return result \>      return geom; \> \> GenerateError: \>      // Delete & free stuff \>      if (plane) blDelete(plane); \> \>      // Return NULL \>      return NULL; \>

    :-(

    Greetings,
    Jack



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

    On 01/03/2009 at 04:10, xxxxxxxx wrote:

    Hi,

    I do just the same as you do! But why are you copying it to res? Simply directly use the result!! also if you use a non-document related object and it doesn´t work, create a copy of the current scene (or create an empty new one), insert the plane in that doc and then convert.

    HTH!



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

    On 01/03/2009 at 04:12, xxxxxxxx wrote:

    YESSS, I got it :-)

    My mistake was to declare the resulting object as:
    PolygonObject *geom = NULL;

    Cloning into an uninitialized object causes the crash. When I declare it as follows, it works fine:
    PolygonObject *geom = PolygonObject::Alloc(0,0);

    It also works with:
    BaseObject *geom = BaseObject::Alloc(Opolygon);

    OK, my mistake. Thanks for help! :)

    Greetings,
    Jack



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

    On 01/03/2009 at 04:18, xxxxxxxx wrote:

    Quote: Originally posted by 3D Designer on 01 March 2009
    >
    > * * *
    >
    > But why are you copying it to res? Simply directly use the result!!
    >
    >
    > * * *

    I could do that, but then the result nested in "cd" would stay unfreed. I get looooots of memory leaks when I use result directly. When I do it with another CopyTo(), I can free the cd result afterwards.

    > Quote: Originally posted by 3D Designer on 01 March 2009
    >
    > * * *
    >
    > also if you use a non- document related object and it doesn´t work, create a copy of the current scene (or create an empty new one), insert the plane in that doc and then convert.
    >
    >
    > * * *

    No necessary. Works fine now (see above post).

    Again, lots of thanks.

    Greetings,
    Jack



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

    On 03/03/2009 at 02:12, xxxxxxxx wrote:

    You can do this even more simple. Just use the GeneratePrimitive() function. It can be casted directly into a polygon obejct.

    See also this thread:

    Poly Meshes and GetVirtualObject

    cheers,
    Matthias


Log in to reply