PolygonMesh#normal_at == [0, 0, 0]?
-
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
-
Not sure... maybe it's populated only when you extract a mesh from existing faces....?
-
I you use
mesh=face.mesh 4
what are the normals ? -
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.
-
@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. -
@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.
-
@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.
-
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 ?? -
I guess Jim wants to weld all vertices... or at least export one material as one mesh.
-
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.
Advertisement