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

    How to create object polygon from spline in C++?

    Cinema 4D SDK
    3
    4
    929
    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.
    • N
      ngvanphong2012
      last edited by

      Hello everyone.
      I have a question that I want to create object solid from spline.
      Can you show code C++ or Python ?.
      Thanks you very much.
      spLineToSolid.PNG

      1 Reply Last reply Reply Quote 0
      • ferdinandF
        ferdinand
        last edited by ferdinand

        Hi,

        welcome to the forum. I am afraid this is not how things are working here. Your question is rather vague and also of such complexity that probably neither the SDK team nor forum members are willing to do the work for you. Some pointers.

        1. Creating a polygon object from a spline is a rather vague description. It could either mean performing a sweep operation along a spline or constructing a surface over a spline.
        2. Cinema has a sweep operator (the Sweep Object) you could use it programmatically. If you do not want to do that for some reason, you will have to segment both the sweep profile and the sweep curve into a set of points, then construct a series of frames (axis) over the sweep curve (for example via parallel transport) and then copy your profile point set to each frame and then triangulate the whole thing.
        3. If you want to construct a surface over a single spline (create a cap) you are pretty much on your own, since Cinema only recently got better tools in this department and they are AFAIK neither being in exposed the C++ nor Python SDK. The principal steps would be:
          a. Segmentize the input spline into a set of points.
          b. This is the hard one: Find a a surface approximation for the generated point set and generate additional points in the projected plane of that surface via for example a poisson distribution.
          c. Triangulate your extended point set (via a delauny triangulation for example, the C++ SDK offers a type for that)
          d. Point b becomes trivial when your spline is planar, i.e. all points of it lie in a plane, but that is not the case for all splines in your screenshot.

        Cheers
        zipit

        MAXON SDK Specialist
        developers.maxon.net

        1 Reply Last reply Reply Quote 0
        • S
          s_bach
          last edited by

          Hello and welcome,

          before posting, please make sure you are familiar with this forum's rules and procedures: How to Post Questions

          What kind of plugin do you want to write? A simple script, a tool or a generator? Are you familiar of the basic concepts of Cinema 4D? Do you have any previous coding experience?

          For simplicity's sake I will present some Python code in form of a Python Script. The concepts can be transferred to C++ as well.

          A polyon object is created by creating an instance of the PolygonObject class. This instance can be modified and then inserted in to the document.

          import c4d
          
          def main():
               
              # create polygon object
              
              numberOfPoints = 4
              numberOfPolygons = 1
              polyObject = c4d.PolygonObject(numberOfPoints, numberOfPolygons)
              if polyObject is None:
                  raise RuntimeError("Could not create PolygonObject.")
              
              # set points
              points = []
              points.append(c4d.Vector(0,0,0))
              points.append(c4d.Vector(0,0,100))
              points.append(c4d.Vector(100,0,100))
              points.append(c4d.Vector(100,0,0))
              
              polyObject.SetAllPoints(points)
              
              # set polygons  
              polygon = c4d.CPolygon(0,1,2,3)
              polyObject.SetPolygon(0, polygon)
              
              # insert object into document
              doc.InsertObject(polyObject, None, None)
              
              # update C4D
              c4d.EventAdd()
          
          if __name__=='__main__':
              main()
          

          Similarly, a spline is represented as a SplineObject. You can use the SplineHelp class to access positions along the spline:

          import c4d
          
          def main():
               
              # access active object
              if op is None:
                  raise RuntimeError("No object selected")
              
              # check if active object is a spline object
              if op.GetType() != c4d.Ospline:
                  raise RuntimeError("Object is no spline object")
              
              # init SplineHelp
              splineHelp  = c4d.utils.SplineHelp()
              res = splineHelp.InitSpline(op)
              if res == False:
                  raise RuntimeError("Could not init SplineHelp.")
              
              # Sample positions along the spline
              for i in xrange(20):
                  offset = i * .05
                  
                  pos = splineHelp.GetPosition(offset, 0)
                  print(pos)
          
          if __name__=='__main__':
              main()
          

          With that information you can build your poylgons.

          You find more complex examples how to create poylgon objects in various generator plugins:

          • py-rounded_tube_r13.pyp
          • objectdata_ruledmesh.cpp

          best wishes,
          Sebastian

          MAXON SDK Specialist

          Development Blog, MAXON Registered Developer

          1 Reply Last reply Reply Quote 0
          • N
            ngvanphong2012
            last edited by

            Thanks everyone.
            

            The purpose of me is export model from revit to cinema 4d.
            I choose other way.
            Thanks you very much.

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