Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware API
      • ZBrush Python API
      • ZBrush GoZ API
      • Code Examples on Github
    • Forum
    • Downloads
    • Support
      • Support Procedures
      • Registered Developer Program
      • Plugin IDs
      • Contact Us
    • Categories
      • Overview
      • News & Information
      • Cinema 4D SDK Support
      • Cineware SDK Support
      • ZBrush 4D SDK Support
      • Bugs
      • General Talk
    • Recent
    • Tags
    • Users
    • Login

    Triangulate Polygon object

    Scheduled Pinned Locked Moved SDK Help
    9 Posts 0 Posters 690 Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • H Offline
      Helper
      last edited by

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

      On 02/01/2009 at 05:40, xxxxxxxx wrote:

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

      ---------
      Hi,

      since I got the same problem as fused (see this thread), I tried to get a correctly triangulated model like this:

      > \> void TriangulatePolygonObject(PolygonObject \*op, BaseDocument \*doc, PolygonObject \*res) \> { \>      PolygonObject \*cObj = (PolygonObject\* )(op->GetClone(COPY_NO_BRANCHES|COPY_NO_BITS|COPY_NO_INTERNALS, NULL)); \>      cObj->SetMg(op->GetMg()); \> \>      ModelingCommandData cd; \>      cd.doc = doc; \>      cd.op = cObj; \>      if (SendModelingCommand(MCOMMAND_TRIANGULATE, cd)) \>      { \>           PolygonObject \*result = (PolygonObject\* )(cd.result->GetIndex(0)); \>           if(result) \>           { \>                result->CopyTo(res, COPY_NO_BRANCHES|COPY_NO_BITS|COPY_NO_INTERNALS, NULL); \>                PolygonObject::Free(result); \>           } \>      } \>      PolygonObject::Free(cObj); \> }

      But it doesn't work. SendModelingCommand() always returns TRUE, indicating the command was executed. But result is always NULL. Where's the problem? I call the function like this:

      > PolygonObject \*OrgObj = ToPoly(op); \> PolygonObject \*TriObj = PolygonObject::Alloc(OrgObj- >GetPointCount(), OrgObj->GetPolygonCount()); \> TriangulatePolygonObject(OrgObj, doc, TriObj); \>

      Op is a plane, a landscape or any converted polygon object. Always the same NULL result.

      Tahnks for any help!

      Cheers,
      Jack

      1 Reply Last reply Reply Quote 0
      • H Offline
        Helper
        last edited by

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

        On 02/01/2009 at 08:30, xxxxxxxx wrote:

        i believe the object you specify in ModelingCommandData is modified and result is supposed to be NULL.

        1 Reply Last reply Reply Quote 0
        • H Offline
          Helper
          last edited by

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

          On 02/01/2009 at 10:06, xxxxxxxx wrote:

          I don't understand. Modified? You mean it's different from the original object in the document?

          Well, I tried to create a temporary document and insert the polygon object there before calling the modeling command (some example by Matthias showed how to do that). But it didn't change the result at all.

          I really have no idea... Also, I still wonder why the Triangulate() function simply outputs a load of crap.

          Cheers,
          Jack

          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

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

            On 02/01/2009 at 11:22, xxxxxxxx wrote:

            The triangulation occurs directly on the original object.

            1 Reply Last reply Reply Quote 0
            • H Offline
              Helper
              last edited by

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

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

              Ah, OK, that wasn't clear to me. Thanks Robert 🙂

              But it is still not working as expected.
              As I understood it, the following code should work:

              > Bool TriangulatePolygonObject(PolygonObject \*op, BaseDocument \*doc, PolygonObject \*res) \> { \>      res = (PolygonObject\* )(op->GetClone(COPY_NO_ANIMATION|COPY_NO_BITS|COPY_NO_INTERNALS, NULL)); \>      res->SetMg(op->GetMg()); \> \>      ModelingCommandData cd; \>      cd.doc = doc; \>      cd.op = res; \>      return SendModelingCommand(MCOMMAND_TRIANGULATE, cd); \> }

              But if e.g. op is a polygon object containing one quad polygon, performing - >GetPolygonCount() on resulting object res still only returns 1. Even better: If I get the points coordinates of this one polygon, they are all 0.

              Damn, how hard can it be to triangulate a simple object?

              Cheers,
              Jack

              1 Reply Last reply Reply Quote 0
              • H Offline
                Helper
                last edited by

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

                On 02/01/2009 at 12:21, xxxxxxxx wrote:

                Addition: It seems that the object actually IS correctly triangulated. When I add the following line before returning the result...

                > GePrint("Poly count: " + LongToString(res->GetPolygonCount()));

                ...it outputs "Poly count: 2" in the console.

                But when I call the function and try to get the poly count in the main function...

                > PolygonObject \*OrgObj = ToPoly(op); \> \> PolygonObject \*TriObj = PolygonObject::Alloc(OrgObj->GetPointCount(), OrgObj->GetPolygonCount()); \> \> TriangulatePolygonObject(OrgObj, doc, TriObj); \> \> GePrint("Poly count: " + LongToString(TriObj->GetPolygonCount()));

                ...it outputs "Poly count: 1" again. If I declare TriObj as NULL, it is still NULL after calling TriangulatePolygonObject(), but inside TriangulatePolygonObject() the pointer res is not NULL, since it's getting a clone of the original object.

                I really don't understand. Sorry. I bet it's something totally stupid. It seems that everything I do to res just works inside TriangulatePolygonObject(), but the result is not stored in the original object whose pointer was passed to the function.

                Greetings,
                Jack

                1 Reply Last reply Reply Quote 0
                • H Offline
                  Helper
                  last edited by

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

                  On 02/01/2009 at 13:18, xxxxxxxx wrote:

                  Just for the archives: Solved the problem. But I have no idea why it didn't work like I showed in the 2 postings above.

                  Solution is here.

                  > Bool TriangulatePolygonObject(PolygonObject \*op, BaseDocument \*doc)//, PolygonObject \*res) \> { \>      ModelingCommandData cd; \>      cd.doc = doc; \>      cd.op = op; \>      Bool result = SendModelingCommand(MCOMMAND_TRIANGULATE, cd); \>      return result; \> } \>

                  Cloning the original object has to be done *before* the function is called. I now do it like this:

                  > PolygonObject \*OrgObj = ToPoly(op); \> PolygonObject \*TriObj = (PolygonObject\* )(OrgObj->GetClone(COPY_NO_ANIMATION|COPY_NO_BITS|COPY_NO_INTERNALS, NULL)); \> if (!TriangulatePolygonObject(TriObj, doc)) return FALSE; \>

                  Now TriObj contains the triangulated geometry. Don't forget to free it after use 😉

                  Greetings,
                  Jack

                  1 Reply Last reply Reply Quote 0
                  • H Offline
                    Helper
                    last edited by

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

                    On 06/01/2009 at 03:26, xxxxxxxx wrote:

                    Ah, so solved your problem on your own. Glad it worked out.

                    cheers,
                    Matthias

                    1 Reply Last reply Reply Quote 0
                    • H Offline
                      Helper
                      last edited by

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

                      On 06/01/2009 at 05:18, xxxxxxxx wrote:

                      Yeah, but I solved by pure chance.
                      Still don't understand the reason 😉

                      Greetings,
                      Jack

                      1 Reply Last reply Reply Quote 0
                      • First post
                        Last post