NGons usage [SOLVED]



  • On 07/09/2016 at 02:30, xxxxxxxx wrote:

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

    ---------
    Hi,
    Can somebody please give me an example code or link to code - how to use (read/write) NGons?
    I tried something like this so far - writing NGons:

    1. I have allocated output PolygonObject with quads (works as expected) in "mesh_out"
    2. then I called "mesh_out->GetAndBuildNgon();" to alloc NgonBase (not sure if that's correct)
    3. then for each Ngon I called: "mesh_out->GetNgonBase()->BuildNgon(...);
    Doesn't do anything visible.

    Is that correct? I mean, are these functions sufficient to make NGons? As I said, a working example would be very helpful.

    Thank you.



  • On 08/09/2016 at 02:29, xxxxxxxx wrote:

    Hello,

    the easiest and safest way to handle NGons is not to use the low level API but to use the Modeling library instead. This library takes care that all the data is handled correctly. Here is a simple example:

      
    // create modeling object  
    AutoAlloc<Modeling> modeling;  
    if (!modeling)  
      return false;  
      
    PolygonObject* polyObject = PolygonObject::Alloc(0, 0);  
    if (polyObject == nullptr)  
      return true;  
      
    // set point count to 10  
    const Int32 pointCount = 10;  
      
    // resize polygon object  
    polyObject->ResizeObject(pointCount, 0);  
      
    // init polygon object for modeling  
    modeling->InitObject(polyObject);  
      
    Float64       cos;  
    Float64       sin;  
    Float64       angle = 0.0;  
    const Float64 step  = 2 * PI / Float64(pointCount);  
      
    // prepare array for the indices  
    maxon::BaseArray<Int32> ngonPoints;  
      
    // create points for the polygon object  
    for (Int32 i = 0; i < pointCount; ++i)  
    {  
      // calculate coordinates  
      maxon::SinCos(angle, sin, cos);  
      const Vector coords = Vector(cos * 100.0, sin * 100.0, 0);  
      
      // set coordinates for the given point  
      modeling->SetPoint(polyObject, i, coords);  
      
      // save index for later  
      ngonPoints.Append(i);  
      
      // next step  
      angle = angle + step;  
    }  
      
    // create Ngon  
    modeling->CreateNgon(polyObject, ngonPoints.GetFirst(), (Int32)ngonPoints.GetCount());  
      
    // commit the modeling transformation before inserting the polygon object into the document  
    if (!modeling->Commit())  
      return false;  
      
    // add the polygon object to the document  
    doc->InsertObject(polyObject, nullptr, nullptr);  
      
    EventAdd();  
    

    best wishes,
    Sebastian



  • On 13/09/2016 at 01:36, xxxxxxxx wrote:

    Thank you, that's exactly what I needed.



  • On 22/09/2016 at 19:11, xxxxxxxx wrote:

    This is a blast from the past (2008) post I did that may or may not be useful (it sounds like you already solved the issue).  It has a bit more detail about some of the lower level api and a few comments with additional info by others.

    Cheers,

    Keith



  • On 23/09/2016 at 07:44, xxxxxxxx wrote:

    Nice to see you posting again Keith.
    You've been M.I.A. for a long time.

    -ScottA



  • On 23/09/2016 at 08:51, xxxxxxxx wrote:

    Thanks Scott - I de-lurk from time to time :).


Log in to reply