I just think out loud because I don’t have much experience with mesh…
(IDEA 1: Can’t you use the original face normal? )
My other 2 ideas are here:
def test_mesh
# craete face
point1 = Geom::Point3d.new(8, 15, 0)
point2 = Geom::Point3d.new(0, 15, 0)
point3 = Geom::Point3d.new(0, 0, 0)
point4 = Geom::Point3d.new(8, 0, 0)
model = Sketchup.active_model
entities = model.active_entities
face = entities.add_face(point1, point2, point3, point4)
# creates a polygon mesh that represents the face
# use flags 4: Include PolygonMeshNormals.
mesh = face.mesh(4)
# ### idea 2 #####
# determine the vertex normal at a particular index
# This only works for meshes retrieved from
# Sketchup::Face#mesh with the PolygonMeshNormals flag.
# for example at index 1
normal = mesh.normal_at(1)
p "mesh normal at index 1 #{normal}"
# ### idea 3 #####
# in this particular example there will be 2 polygons (triangles)
# we can get polygon points, so they are in "ordered form"
# one of it should be enough, but let see both for now
p pol1_points = mesh.polygon_points_at(1)
p pol2_points = mesh.polygon_points_at(2)
# calculate the normals
v101 = pol1_points[0].vector_to( pol1_points[1] )
v112 = pol1_points[1].vector_to( pol1_points[2] )
norm_pol1 = ( v101 * v112 ).normalize
p "mesh normal by poly1 #{norm_pol1}"
v201 = pol2_points[0].vector_to( pol2_points[1] )
v212 = pol2_points[1].vector_to( pol2_points[2] )
norm_pol2 = ( v201 * v212 ).normalize
p "mesh normal by poly2 #{norm_pol2}"
return
end
test_mesh
Returns:
"mesh normal at index 1 (0, 0, -1)"
[Point3d(8, 15, 0), Point3d(0, 0, 0), Point3d(0, 15, 0)]
[Point3d(0, 0, 0), Point3d(8, 15, 0), Point3d(8, 0, 0)]
"mesh normal by poly1 (-0, 0, -1)"
"mesh normal by poly2 (0, 0, -1)"