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
    • Recent
    • Tags
    • Users
    • Login

    Point Normal

    Scheduled Pinned Locked Moved PYTHON Development
    5 Posts 0 Posters 478 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

      On 26/08/2013 at 10:03, xxxxxxxx wrote:

      Hi,

      is there by any chance a function that will return the Point Normal, given a Point Object and a point id? Basically like the xpresso Point node...

      Cheers
      Michael

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

        On 26/08/2013 at 10:31, xxxxxxxx wrote:

        There is no built-in method. You can calculate the vertex normal by taking the average of the normal
        of all adjacent polygons. A vertex without adjacent polygons does simply not have a normal.

        Cheers,
        -Niklas

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

          On 26/08/2013 at 10:35, xxxxxxxx wrote:

          There isn't even really a method to calculate polygon normals. There is PolygonObject.
          CreatePhongNormals(), but it does require a (already cached / executed) phong tag. 
          Calculating the normals yourself might be the fastest way, simply calculate all polygon 
          normals for the mesh.

          > normallist[polyindex] = ((poly.VecB - poly.VecA) % (poly.VecC -poly.VecA)).GetNormalized()

          Then calculate the point normal for each point.

          > pnormal = Vector()
          >
          > cnt = 0
          >
          > for each polygon attached to point:
          >
          > pnormal += normallist[polygon]
          >
          > cnt += 1
          >
          > pnormal *= (1.0/cnt)

          edit : nikklas was faster and FYI, the example is meant for triangles of course, for quads or
          mixed meshes you have to extend the polygon normal calculation for nonplanar quads to the 
          fourth point.

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

            On 26/08/2013 at 10:56, xxxxxxxx wrote:

            Originally posted by xxxxxxxx

            [...] FYI, the example is meant for triangles of course, for quads or
            mixed meshes you have to extend the polygon normal calculation for nonplanar quads to the 
            fourth point.

            You actually only have to replace the C in your calculation with the D and don't take C into
            account at all.

            points = op.GetAllPoints()
                polygons = op.GetAllPolygons()
                normals = []

            for p in polygons:
                    a = points[p.a]
                    b = points[p.b]
                    c = points[p.c]
                    d = points[p.d]

            n = (b - a).Cross(d - a).GetNormalized()
                    normals.append(n)

            The value of D == C for a triangle, therefore the calculation is valid for triangles and quads and
            you do not have to distinguish them explicitly.

            Cheers,
            -Niklas

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

              On 27/08/2013 at 01:13, xxxxxxxx wrote:

              You actually only have to replace the C in your calculation with the D and don't take C into
              account at all.

              points = op.GetAllPoints()
                  polygons = op.GetAllPolygons()
                  normals = []

              for p in polygons:
                      a = points[p.a]
                      b = points[p.b]
                      c = points[p.c]
                      d = points[p.d]

              n = (b - a).Cross(d - a).GetNormalized()
                      normals.append(n)

              The value of D == C for a triangle, therefore the calculation is valid for triangles and quads and
              you do not have to distinguish them explicitly.

              Cheers,
              -Niklas

              Thanks guys! I'll give it a go right away...

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