sketchucation logo sketchucation
    • Login
    Oops, your profile's looking a bit empty! To help us tailor your experience, please fill in key details like your SketchUp version, skill level, operating system, and more. Update and save your info on your profile page today!
    πŸ«› Lightbeans Update | Metallic and Roughness auto-applied in SketchUp 2025+ Download

    PolygonMesh#normal_at == [0, 0, 0]?

    Scheduled Pinned Locked Moved Developers' Forum
    10 Posts 4 Posters 424 Views 4 Watching
    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.
    • J Offline
      Jim
      last edited by

      I'm trying to create a PolygonMesh from faces (works,) but does anyone know why the mesh normals are all Vector3d(0, 0, 0)?

      
      model = Sketchup.active_model
      entities = model.entities
      selection = model.selection
      
      mesh = Geom;;PolygonMesh.new
      faces = entities.select{|e| e.is_a?(Sketchup;;Face)}
      
      faces.each { |face|
          verts = face.outer_loop.vertices
          pts = verts.map{|v| v.position}
          mesh.add_polygon(pts)
      }
      
      mesh.count_points.times do |i|
          n = mesh.normal_at(i+1)
          p n
      end
      
      
      

      Hi

      1 Reply Last reply Reply Quote 0
      • thomthomT Offline
        thomthom
        last edited by

        Not sure... maybe it's populated only when you extract a mesh from existing faces....?

        Thomas Thomassen β€” SketchUp Monkey & Coding addict
        List of my plugins and link to the CookieWare fund

        1 Reply Last reply Reply Quote 0
        • TIGT Offline
          TIG Moderator
          last edited by

          I you use mesh=face.mesh 4 what are the normals ?

          TIG

          1 Reply Last reply Reply Quote 0
          • J Offline
            Jim
            last edited by

            Thanks, but how can I get more than a single face into the mesh using this?

            @unknownuser said:

            Why do you expect mesh = Geom::PolygonMesh.new to create normals for you?

            If a mesh exists and has polygons, the normals can be calculated. I was hoping this would be done by SketchUp internally. I'm not even sure of the meaning of "normal" in this case - does it mean vertex normal, face normal, or something else.

            Hi

            1 Reply Last reply Reply Quote 0
            • T Offline
              tomasz
              last edited by

              @unknownuser said:

              Face.mesh
              The mesh method creates a polygon mesh that represents the face. See the PolygonMesh class for more information.

              Valid flags are:

              0: Include PolygonMeshPoints,
              1: Include PolygonMeshUVQFront,
              2: Include PolygonMeshUVQBack,
              4: Include PolygonMeshNormals.

              mesh=face.mesh 4

              Why do you expect mesh = Geom::PolygonMesh.new to create normals for you? You have passed just points. I guess normals simply aren't initialized or default to 0,0,0.

              Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

              1 Reply Last reply Reply Quote 0
              • T Offline
                tomasz
                last edited by

                @jim said:

                Thanks, but how can I get more than a single face into the mesh using this?

                Polygonal mesh is a set of triangles. You could write a method to merge several faces into one polygonal mesh. There is no such a solution in Ruby API.

                Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                1 Reply Last reply Reply Quote 0
                • T Offline
                  tomasz
                  last edited by

                  @jim said:

                  I'm not even sure of the meaning of "normal" in this case - does it mean vertex normal, face normal, or something else.

                  From my experience and understanding the "normal" here is a normal of a vertex in a face. If a face has one edge smoothed, it can result in two normals at those two vertexes different then face.normal.

                  Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                  1 Reply Last reply Reply Quote 0
                  • TIGT Offline
                    TIG Moderator
                    last edited by

                    What I'd normally do is get each face's mesh [with normals etc] then export each face in the mesh with its normals.
                    Why do you want to export a mesh made from a combo of faces ?
                    Aren't you going to export the faces of each face's mesh one by one anyway ??

                    TIG

                    1 Reply Last reply Reply Quote 0
                    • T Offline
                      tomasz
                      last edited by

                      I guess Jim wants to weld all vertices... or at least export one material as one mesh.

                      Author of [Thea Render for SketchUp](http://www.thearender.com/sketchup)

                      1 Reply Last reply Reply Quote 0
                      • J Offline
                        Jim
                        last edited by

                        Just looking for a shortcut way to get vertex normals. I know it can be done in Ruby, but was hoping SketchUp did it faster when using a PolygonMesh.

                        Hi

                        1 Reply Last reply Reply Quote 0
                        • 1 / 1
                        • First post
                          Last post
                        Buy SketchPlus
                        Buy SUbD
                        Buy WrapR
                        Buy eBook
                        Buy Modelur
                        Buy Vertex Tools
                        Buy SketchCuisine
                        Buy FormFonts

                        Advertisement