• Categories
    • Overview
    • News & Information
    • Cinema 4D SDK Support
    • Cineware SDK Support
    • ZBrush 4D SDK Support
    • Bugs
    • General Talk
  • Unread
  • Recent
  • Tags
  • Users
  • Register
  • Login
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
  • Register
  • Login

n-gones with python

Cinema 4D SDK
python
2
3
723
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.
  • P
    Passion3D
    last edited by a_block Nov 14, 2018, 10:56 AM Nov 13, 2018, 8:06 PM

    I found that the c ++ sdk had a routine for creating n-gones, but I did not find anything in python. By importing a wavefront that contains n-gones with my plugin, the import is not done properly. Is there a python solution or should I convert my plugin to c ++?

    1 Reply Last reply Reply Quote 0
    • E
      eZioPan
      last edited by Nov 14, 2018, 5:30 AM

      hi @passion3d,
      There is no actual n-gon in the underlying layer of Cinema 4D.
      Adjacent polygons use hidden edge to create n-gon-like shape(s).

      Following code creates a 5-side polygon object:

      import c4d, math
      from c4d import utils
      #Welcome to the world of Python
      
      def main():
          pointCount = 5
          polygonCount = math.ceil(pointCount/4.0)                    # caculate minimum needed polygon number
          polyObj = c4d.BaseObject(c4d.Opolygon)                      # create an empty polygon object
      
          polyObj.ResizeObject(pcnt=pointCount, vcnt=polygonCount)    # resize object to have 5 points, 2 polygons
      
          # manually set all point position
          polyObj.SetPoint(id=0, pos=c4d.Vector(200,0,-200))
          polyObj.SetPoint(id=1, pos=c4d.Vector(-200,0,-200))
          polyObj.SetPoint(id=2, pos=c4d.Vector(-200,0,200))
          polyObj.SetPoint(id=3, pos=c4d.Vector(200,0,200))
          polyObj.SetPoint(id=4, pos=c4d.Vector(300,0,0))
      
          # associate points into polygons
          polygon0 = c4d.CPolygon(t_a=0, t_b=1, t_c=2, t_d=3)
          polygon1 = c4d.CPolygon(t_a=0, t_b=3, t_c=4)
      
          # set polygon in polygon object
          polyObj.SetPolygon(id=0, polygon=polygon0)
          polyObj.SetPolygon(id=1, polygon=polygon1)
      
          # set hidden edge
          nbr = utils.Neighbor()
          nbr.Init(op=polyObj, bs=None)                               # create Neighor counting all polygon in
          edge = c4d.BaseSelect()
          edge.Select(num=3)                                          # set selection, which is the id of the edge to be hidden
          polyObj.SetSelectedEdges(e=nbr, pSel=edge, ltype=c4d.EDGESELECTIONTYPE_HIDDEN)  # hide the edge
      
          polyObj.Message(c4d.MSG_UPDATE)
      
          doc.InsertObject(polyObj)
      
          c4d.EventAdd()
      
      if __name__=='__main__':
          main()
      
      1 Reply Last reply Reply Quote 3
      • P
        Passion3D
        last edited by Nov 14, 2018, 10:11 AM

        Hi @eZioPan
        thank you for this example very clear 😉

        1 Reply Last reply Reply Quote 0
        3 out of 3
        • First post
          Last post