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

    Check normals?

    Scheduled Pinned Locked Moved PYTHON Development
    16 Posts 0 Posters 2.0k Views
    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 Offline
      Helper
      last edited by

      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

      On 20/06/2011 at 12:18, xxxxxxxx wrote:

      ahhh, ok, so I have to access the point information. and from that get the normals. But then why does the SDK say:

      "Polygons in CINEMA 4D have their own coordinate system. You cannot see this system in the viewports, but it is important to be aware of it when using modeling tools.
      The origin of the polygon coordinate system is located at the centre of the polygons. The X axis is along the line between A and B. The Z axis is the normal. The Y axis is perpendicular to the XZ plane."
      I'll try to get the info I need from the point information, but it seems to be hinting that there is a way to access the Matrix coordinates of individual polygon faces.

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

        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

        On 20/06/2011 at 12:34, xxxxxxxx wrote:

        hmmmm... getting this error:

        AttributeError: 'c4d.CPolygon' object has no attribute 'GetPoint'

        this is the snippet of code i am using.

        def GetNormalFacing(op) :
          polys = op.GetAllPolygons()#get a list of polygons
          for poly in polys:
              print poly

        gives me:

        (a:0, b:1, c:2, d:3)

        but when i try to access the "a" for example:

        def GetNormalFacing(op) :
          polys = op.GetAllPolygons()#get a list of polygons
            for poly in polys:
                return poly.GetPoint(polygon.a)

        and then i try ti run it, i get an error saying that:

        AttributeError: 'c4d.CPolygon' object has no attribute 'GetPoint'

        This is essentially the problem i am having. CPolygon obejcts have no functions except __init__.

        GetPoint only seems to be for Point Objects. not CPolygon Objects.

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

          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

          On 20/06/2011 at 12:35, xxxxxxxx wrote:

          No, GetPoint is a Method of the PointObject - class.

          print op.GetPoint(polygon.a)
          
          You see ? op is a PointObject, 'polygon' is a CPolygon.  
            
          So, here is a better explanation:  
            
          CPolygon-objects hold indicies of Points in their attributes a,b,c and d.  
          Theese indieces represent the points of a PointObject (PolygonObject inherits from PointObject).  
          
          myPointIndexTakenFromCPolygon = myPolygonTakenFromPointOrPolygonObject.a  
              myPointCoordinate = myPointOrPolygonObject.GetPoint(myPointIndexTakenFromCPolygon)
          
          Ergo, a Polygon is defined by the indieces of points of an object.  
          It would be absolutely redundant saving the Vectors of the Points twice.  
          
          1 Reply Last reply Reply Quote 0
          • H Offline
            Helper
            last edited by

            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

            On 20/06/2011 at 12:47, xxxxxxxx wrote:

            f**king brilliant. it works like a charm. i just needed to replace your "polygon" with the name of my polygon. i didn't understand why i would have to access "op"  at first, but now i see that i HAVE to pass the GetPoint Function on my base object in order to use the fucntion and then use the CPolygon object to tell Python what points to get. awesome.  thanks again man. the working code is:

            def SelectWalls(op) :
              polys = op.GetAllPolygons()#Get a list of all available polygons
              for poly in polys:
                  return op.GetPoint(poly.a)

            and it returns:

            Vector(-325, -331, -99)

            when i print. brilliant.

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

              THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

              On 20/06/2011 at 13:18, xxxxxxxx wrote:

              Np. 🙂
              Just for final correction of your comment:

              Originally posted by xxxxxxxx

              polys = op.GetAllPolygons()#How many polygons does the object have in total?

              Does not (not only actually) return the number of polygons, it returns a list containing all polygons. And the length of the list ( len(polys) ) is the number of Polygons, logically.

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

                THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                On 20/06/2011 at 13:34, xxxxxxxx wrote:

                haha, yeah sorry forgot to change the comment to say #Get All Polygons., I totally understand and will fix it.

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

                  THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                  On 21/06/2011 at 02:55, xxxxxxxx wrote:

                  In case you do search for an algorithm of how to calculate the Normal of a Polygon, here is a very good and easy to reproduce in Python - Pseudocode:

                  http://www.opengl.org/wiki/Calculating_a\_Surface_Normal

                  Cheers,

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

                    THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                    On 21/06/2011 at 05:45, xxxxxxxx wrote:

                    Btw. the cross-product is already implemented. So just use:

                    normal = vec1.Cross(vec2)

                    Be aware that switching the vectors, will switch the direction of the normal.

                    Cheers,
                    maxx

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

                      THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                      On 21/06/2011 at 06:06, xxxxxxxx wrote:

                      But the normal of 2 vectors is not what he searched for. 😉
                      Anyway, very useful ! Didn't know about that Method. Thanks

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

                        THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                        On 21/06/2011 at 08:08, xxxxxxxx wrote:

                        Well, actually, it is.

                        You just take the three points, create two vectors by substraction, calculate the normal by cross-product ... The result is the normal on the polygon-surface (defined by the three points).

                        Cheers,
                        maxx

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

                          THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                          On 21/06/2011 at 10:29, xxxxxxxx wrote:

                          wow! thanks guys and gals! that openGL wiki is exactly what i was looking for. and the little snippet on how to get the cross product of two vectors is super helpful as well. thanks so much!

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

                            THE POST BELOW IS MORE THAN 5 YEARS OLD. RELATED SUPPORT INFORMATION MIGHT BE OUTDATED OR DEPRECATED

                            On 21/06/2011 at 11:38, xxxxxxxx wrote:

                            ok, so thanks to everybody's help i was successfully able to calculate the face normals and find out which way the polygon is facing. It seems to be working so I Thought this might help some people out!

                            def FindNormals(op) : #function to find direction of walls and assign to seperate selection tags
                                polys = op.GetAllPolygons() #get list of polygons in op
                                doc = c4d.documents.BaseDocument()
                                i=0
                                for poly in polys: #find normals

                            pt_a = op.GetPoint(poly.a)
                                    pt_b = op.GetPoint(poly.b)
                                    pt_c = op.GetPoint(poly.c)
                                    pt_d = op.GetPoint(poly.d)
                                    vector1 = pt_a-pt_b
                                    vector2 = pt_b-pt_c
                                    normal = vector1.Cross(vector2)
                                    normal.Normalize()
                                    nx = normal.x
                                    ny = normal.y
                                    nz = normal.z
                                    if(nx!=0) :                                            #check x normal
                                        print "poly",i,poly,"is facing x to a degree of:",nx
                                        i+=1
                                    elif(ny!=0) :                                          #check y normal
                                        print "poly",i,poly,"is facing y to a degree of:",ny
                                        i+=1
                                    elif(nz!=0) :                                          #check z normal
                                        print "poly",i,poly,"is facing z to a degree of:",nz
                                        i+=1
                                    else:
                                        print "something went wrong"

                            update: fixed some minor code output issues.

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