I want to custom export obj file, but mesh.point is not clockwise or anti-clockwise order

I try to get meshes point ,but I find they is not colokwise or anti-clockwise order array.I draw a simple rectangle face,through below code get four points.

These points information is
[Point3d(82.6772, 151.969, 0), Point3d(0, 0, 0), Point3d(0, 151.969, 0), Point3d(82.6772, 0, 0)]
I hope these points have order array.
I know face have a function outer_loop,but I cannot find mesh function similar.
please told me some solution.
Use : I need colokwise or anti_clockwise order point to recalculation face’s normal in obj file.

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}"


"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)"

mesh.points is just the pool of points making up the mesh. There is no order there other than implementation detail determined insertion order. For ordered points you need to look at mesh.polygons or mesh.polygon_at.

1 Like

Thanks your reply.
I use mesh.polygons function get some array.it is have clockwise rule.

Thankes your reply.
First,I’m sorry I cannot use customary face.
My research direction is wrong,mesh.polygons have rule. mesh.normal_at(1) is a point normal,or not a face normal,I have to recalculation a face normal.
Because I need a face normal.

If you get a mesh from face.mesh, then the all the triangles in the mesh will be planar (faces in SketchUp are always planar). So you can use face.normal as the normal for all your triangles.


Thankes your reply;
I will try to this function.