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

    Create Ngon with variable sides count [SOLVED]

    SDK Help
    0
    9
    724
    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 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 🙂

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

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

        Int32 *padr = new Int32[mySides];

        ....

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

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

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

          Thanks a lot Mohamed. It works.

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

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

            glad that it worked Tongue
            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"

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

              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?

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

                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

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

                  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.

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

                    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

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

                      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.

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