Create Ngon with variable sides count [SOLVED]



  • On 21/08/2014 at 23:06, xxxxxxxx wrote:

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

    ---------
    Hi, I can create Ngons fine with the example from the SDK. The question is, how can I create an Ngon with a user controlled number of points.

    //Generate N-Gon    
    int mySides = 7; //this is a dynamic value, and therefore cannot be used with padr
           
    AutoAlloc<PolygonObject> obj(0,0);
    if (!obj) return FALSE;
    AutoAlloc<Modeling> mod;
    if (!mod || !mod->InitObject(obj)) return FALSE;
      
    //Create a circular point array
    maxon::BaseArray<Int32>myPoints; Matrix m;
    for (int i=0; i<mySides; i++)
    {
    	m = MatrixRotY(Rad(i*360/ mySides));
    	int temp = mod->AddPoint(obj, m*Vector(100,0,0));
    	myPoints.Append(temp); 
    }
      
    Int32 padr[] = {-1, -2, -3, -4, -5, -6, -7}; // I want padr to use mySides for its size!!
    Int32 cnt = mySides;
    Int32 i = mod->CreateNgon(obj, padr, cnt);
    if (!i) return FALSE;
    if (!mod->Commit()) return FALSE;
    doc->InsertObject(obj.Release(), NULL, NULL);
    EventAdd();  
    

    Please excuse the r15 code style :)



  • On 21/08/2014 at 23:19, xxxxxxxx wrote:

    Int32 *padr = new Int32[mySides];

    ....

    if(padr) { delete padr; padr = NULL}



  • On 21/08/2014 at 23:58, xxxxxxxx wrote:

    Thanks a lot Mohamed. It works.



  • On 22/08/2014 at 00:20, xxxxxxxx wrote:

    glad that it worked 
    don't forget to delete the pointer once you finish working with it (or it will create a memory leak), read more about heap memory in C++ on stackoverflow "google is your friend"



  • On 22/08/2014 at 01:21, xxxxxxxx wrote:

    I did, thanks!

    A follow up question if you don't mind. I need to assign a different material tag (plus restriction and projection) to that created Ngon.
    With regular polygons, I use this, where ret is the returned generator object:

    	BaseTag* t = NULL;
    	t = (static_cast<BaseTag*>(tex->GetClone(COPYFLAGS_0, NULL)));  //get a copy of the texture tag defined in Init
    	ret->InsertTag(t);
      
    	sT = SelectionTag::Alloc(Tpolygonselection);  //defined as a class variable
    	ret->InsertTag(sT);
    	sT->SetName("Selected Polygons 0");
    BaseSelect* bs = sT->GetBaseSelect();
    	bs->SelectAll(0,10);	    //selecting forst 11 polygons 
      
    	t->SetParameter(DescID(TEXTURETAG_RESTRICTION), GeData(sT->GetName()), DESCFLAGS_SET_0);
    	t->SetParameter(DescID(TEXTURETAG_PROJECTION),  GeData(TEXTURETAG_PROJECTION_UVW), DESCFLAGS_SET_0);
      
    
    

    Now how can I do this for the Ngon?



  • On 22/08/2014 at 01:30, xxxxxxxx wrote:

    I'm not sure how it works "still my experience with the SDK near 0"

    but I think this line:
    bs->SelectAll(0,10);     //try to select last polygon



  • On 22/08/2014 at 08:36, xxxxxxxx wrote:

    I just read the Ngons do not support UVs, so using them is moot.
    I would have to build the cap manually with regular polygons and tris.



  • On 22/08/2014 at 10:37, xxxxxxxx wrote:

    I guess you can triangulate the NGons and use this, there must be a way to work with them similar to polygon containers



  • On 22/08/2014 at 17:08, xxxxxxxx wrote:

    Yes, underneath, NGons are 'collections of polygon edges'.  So, you will need to get the underlying polygons to work on the UVs.  PolygonObject has a method, GetNGonTranslationMap() which will return a set of polygon indices.  The NGon stuff is a bit complicated and there are several underlying classes, such as Pgon, to go between NGons and polygons.


Log in to reply