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
    • Unread
    • Recent
    • Tags
    • Users
    • Login

    Non-destructive Triangulation

    SDK Help
    0
    5
    569
    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
      Helper
      last edited by

      On 08/11/2016 at 13:16, xxxxxxxx wrote:

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

      ---------
      Hello. SDK Newbie here 🙂

      I'm working on a exporter and need to triangulate the polygons, but I don't want to destroy the polygon
      object so I guess I must make a clone of the object and work on that. I found some functions that may
      do that ? GetAndCheckHierarchyClone and GetHierarchyClone, but I don't really understand how to
      use them. Can't find any example. Its the HierarchyHelp argument that I don't understand.

      So first of all. Is this the correct approach to do my triangulation before saving out the point-list and
      secondly, is there any example on how to clone the polygon object (and its childs) around. I don't need to
      clone any materials, just the polys

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

        On 09/11/2016 at 02:52, xxxxxxxx wrote:

        Hi Roland,

        welcome to the Plugin Café community 🙂

        GetAndCheckHierarchyClone() and GetHierarchyClone() functions are the wrong approach. These functions are meant to be used in ObjectData plugins (e.g. in GetVirtualObjects()) and there C4D provides the HierarchyHelp object, which you usually don't have to worry about.

        For more information on this topic, I recommend the BaseObject manual in the SDK docs, especially the Generating sub-chapter.

        Now, in your case (most likely a SceneSaverData plugin) you have two options for the first step (getting the actual polygonal data).
        a) Use SendModelingCommand() with MCOMMAND_MAKEEDITABLE. This is probably the easier solution
        b) Get the cache(s) for the object in question, via GetCache() and GetDeformCache(). Please see the notes and the code snippets provided in the docs of these two functions for more information. Again also the BaseObject manual has a chapter about object caches.

        Second step is then the actual triangulation. Here SendModelingCommand() comes to help again, this time with MCOMMAND_TRIANGULATE.

        On the question of cloning objects (doesn't matter if polygonal or not, if they have children or not, actually almost every entity in C4D), see C4DAtom::GetClone() function.

        I hope, this helps to get you going.

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

          On 09/11/2016 at 03:31, xxxxxxxx wrote:

          Thank a lot Andreas. That worked just great!

          Tested with this code on s simple cube and
          got polycount=6 before triangulation and
          polycount=12 after.

          --- CODE
              //  Create clone to work on
            auto pclone = static_cast<PolygonObject*>(po->GetClone(COPYFLAGS_0, nullptr));
           
            //  Make it editable
            ModelingCommandData cmd;
            cmd.doc = _doc;
            cmd.op = pclone;
            if (!SendModelingCommand(MCOMMAND_MAKEEDITABLE, cmd))
            {
                return;
            }
              //  debug: polygon count before triangulation
            auto numpolys = pclone->GetPolygonCount();
              //  Triangulate
            if (!SendModelingCommand(MCOMMAND_TRIANGULATE, cmd))
            {
                return;
            }
              //  debug: polygon count after triangulation
            numpolys = pclone->GetPolygonCount();

          Thanks a bunch !Thumbs Up[URL-REMOVED]

          ****__~~~~


          [URL-REMOVED] @maxon: This section contained a non-resolving link which has been removed.

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

            On 09/11/2016 at 04:56, xxxxxxxx wrote:

            Hi Roland,

            glad I was able to help.
            Just one note, you need to check the result of GetClone() for nullptr.
            I'm getting picky on this, as we had some discussion in other threads lately.

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

              On 09/11/2016 at 05:01, xxxxxxxx wrote:

              Yes I will certainly do that in the real exporter code. This was just a quick test of cloning and triangulation. I will now start building the exporter step by step. Will then test all return values for validity. Thanks again

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