Maxon Developers Maxon Developers
    • Documentation
      • Cinema 4D Python API
      • Cinema 4D C++ API
      • Cineware 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

    Converting Polygons Into Objects

    SDK Help
    0
    7
    651
    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

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

      On 19/11/2007 at 05:49, xxxxxxxx wrote:

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

      ---------
      Hello,

      I´m a totally new to COFFEE, but I´d like to create a script doing the following:

      1. Call an object
      2. Get the polygons from 1.
      3. Convert each polygon into an individual object

      I thought, something like this would do the job:

      > _var object = doc- >FindObject("Cube");
      > var currentDoc = GetActiveDocument();
      >
      > var NoOfPolygons = object->GetPolygonCount();
      > var i = 0;
      >
      > while (i <= NoOfPolygons) {
      >
      >      var singlePolygon = object->GetPolygon(i);
      >
      >      var newPolygon = new(PolygonObject);
      >          newPolygon->SetPolygon(singlePolygon);
      >
      >       currentDoc->InsertObject(newPolygon, NULL, NULL);
      >      
      >      i++;
      > }
      >
      > _

      The polygon objects are created, but they don´t contain any points or position data. Currently I just don´t know what do, because the entire COFFEE construction is a bit confusing for me...

      Thanks a lot in advance for your help and hints.

      Best,
      t.

      P.S.: I´m on C4D 9.6

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

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

        On 19/11/2007 at 07:24, xxxxxxxx wrote:

        The object has to be a Polygon object first. If it's not, it doesn't have any *real* polygons to get. Convert it first (SendModelingCommand() with CurrentStateToObject).

        if (object->GetType() != Opolygon) // convert
        // then continue

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

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

          On 19/11/2007 at 07:41, xxxxxxxx wrote:

          Hello Robert,

          thanks for your message. The cube has been made editable (converted into polygons) before executing the script - so the object already consists of polygons. Also the expression

          > println(singlePolygon);

          displays a result, e.g. [Object - 0x0fg5ffe]. That´s why I thought I´d be able to simply transfer the data to a new polygon.

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

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

            On 19/11/2007 at 10:19, xxxxxxxx wrote:

            Okay, that's out of the way. 🙂

            First, SetPolygon() takes two paramters: SetPolygon(num, p).

            Second, you'll need to get and set the points as well (see PointObject from which PolygonObject is derived). Polygons don't store the points, they only store indices into the point array.

            Third, you'll need to specify the point and polygon counts for the new polygon object. This example is from the archived forum:

            > NewPolygonObject(pointCount, polygonCount)
            > {
            > if (pointCount < 0 || polygonCount < 0) return FALSE;
            >
            > var newObject = new(PolygonObject);
            >
            > var pointArray = new(array, pointCount);
            > var polygonArray = new(array, polygonCount * 4);
            >
            > // Modify the arrays here if you want!
            >
            > newObject->SetPoints(pointArray);
            > newObject->SetPolygons(polygonArray);
            >
            > var variableChanged = new(VariableChanged);
            > var backupTags = new(BackupTags);
            >
            > backupTags->Init(newObject);
            > variableChanged->Init(0, pointCount);
            > if (!newObject->Message(MSG_POINTS_CHANGED, variableChanged))
            > {
            >     backupTags->Restore();
            >     return FALSE;
            > }
            >
            > backupTags->Init(newObject);
            > variableChanged->Init(0, polygonCount);
            > if (!newObject->Message(MSG_POLYGONS_CHANGED, variableChanged))
            > {
            >     backupTags->Restore();
            >     return FALSE;
            > }
            >
            > newObject->Message(MSG_UPDATE);
            > return newObject;
            > }

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

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

              On 19/11/2007 at 14:49, xxxxxxxx wrote:

              Robert -

              thank you so much for your friendly help. I´ll give a go tomorrow...

              Best,
              t.

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

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

                On 20/11/2007 at 03:55, xxxxxxxx wrote:

                Thanks for your help so far, but I just can´t get along with coffee´s construction methods. I´m able to read out the coordinates of a vertex, but I have no clue how to transform these values into a new polygon object.

                > var object = doc- >FindObject("Cube");
                > var currentDoc = GetActiveDocument();
                >
                > var polys = object->GetPolygons();
                > var points = object->GetPoints();
                > var polynum = object->GetPolygonCount() * 4;
                > var counter = 0;
                > var i,vertexRef, pointCoord;
                >
                > for (i=0; i<polynum; i++) {
                >
                >      if (counter == 0) {
                >           println ("Polygon #", i/4);
                >           println ("------------------------");
                >      }
                >
                >      vertexRef = polys[i];
                >      pointCoord = points[vertexRef];
                >
                >      println (pointCoord);
                >
                >      counter++;
                >
                >      if (counter == 4) {
                >           counter = 0;
                >      }
                >
                > }

                I really appreciate your help!

                Thanks,
                t.

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

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

                  On 20/11/2007 at 06:24, xxxxxxxx wrote:

                  As is shown in the example code, you have to create two new arrays for the new Polyon object (point and polygon arrays) and set them on the Polygon object.

                  As for setting up the polygon and points, since you are only creating one polygon with, at most, four points the indices for the four points will be 0,1,2,3 for a quadrangle and 0,1,2,2 for a triangle. Doesn't matter what these indices are in the old polygon object since you are only creating one polygon and one three/four point array.

                  So, you'll set the points as:

                  > var pointArray;
                  >
                  > // inside polygon traversal loop
                  > // - Quadrangle
                  > if (polys[p].c != polys[p].d)
                  > {
                  > pointArray = new(array, 4);
                  > pointArray[0] = points[polys[p].a];
                  > pointArray[1] = points[polys[p].b];
                  > pointArray[2] = points[polys[p].c];
                  > pointArray[3] = points[polys[p].d];
                  > }
                  > // - Triangle
                  > else
                  > {
                  > pointArray = new(array, 3);
                  > pointArray[0] = points[polys[p].a];
                  > pointArray[1] = points[polys[p].b];
                  > pointArray[2] = points[polys[p].c];
                  > }
                  > object- >SetPoints(pointArray);

                  When you are setting the polygon vertex indices, if it's a triangle, set polyArray[n].d = polyArray[n].c. I'm not so sure why the old code there allocates polyCount*4 instead of just polyCount Polygons as I'm not a COFFEE coder as much as a CPP coder. Being new at this, you should consider Rui Batista s COFFEE book. He is very knowledgeable with COFFEE.

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