The PolygonMesh class contains methods to create polygon mesh structures.
This is useful if you need to write a custom importer/exporter in Ruby that
works at the level of triangulated polygons. For example, you can determine
the triangles that make up a 15-sided SketchUp face by using this class, or
write a SketchupImporter that reads a data file, creates a mesh from it,
and draws faces based on the mesh.
You can construct a mesh manually using the methods of this class, or you
can get a mesh from a face by calling the Face.mesh method. See
Entities.add_faces_from_mesh for an easy way to convert a mesh back into
faces.
# Grab a mesh from a given face.
my_mesh = some_face.mesh
# Create a new group that we will populate with the mesh.
group = Sketchup.active_model.entities.add_group
group.add_faces_from_mesh my_mesh
The add_point method is used to add a point to the mesh.
The index can be used for creating polygons.
Arguments:
Returns:
mesh = Geom::PolygonMesh.new point = Geom::Point3d.new 0,1,2 index = mesh.add_point point
The add_polygon method is used for adding a polygon to a polygon mesh.
Arguments:
Returns:
mesh = Geom::PolygonMesh.new point = Geom::Point3d.new 0,1,2 point1 = Geom::Point3d.new 1,0,2 point2 = Geom::Point3d.new 2,0,1 status = mesh.add_polygon point, point1, point2
The count_points method is used to count the number of points in a mesh.
Returns:
mesh = Geom::PolygonMesh.new point = Geom::Point3d.new 0,1,2 index = mesh.add_point point num = mesh.count_points
The count_polygons count the number of polygons in the mesh.
Returns:
mesh = Geom::PolygonMesh.new point = Geom::Point3d.new 0,1,2 point1 = Geom::Point3d.new 1,0,2 point2 = Geom::Point3d.new 2,0,1 index = mesh.add_polygon point, point1, point2 nump = mesh.count_polygons
Create a new empty polygon mesh. The number of points and polygons are optional and are just used as a hint to decide how much space to pre-allocate to speed up adding points and polygons.
Arguments:
Returns:
mesh = Geom::PolygonMesh.new
The normal_at method is used to determine the normal at a particular index
in the mesh.
Index is 1 based (starts at 1).
Arguments:
Returns:
normal = mesh.normal_at 1
The point_at method is used to retrieve the point at a specific index in the
mesh.
Index is 1 based (starts at 1).
Arguments:
Returns:
mesh = Geom::PolygonMesh.new point1 = Geom::Point3d.new 0,1,2 point2 = Geom::Point3d.new 10,20,30 index = mesh.add_point point1 index = mesh.add_point point2
The point_index method is used to retrieve the index of a point in the mesh.
Returns 0 if point is not found.
Arguments:
Returns:
mesh = Geom::PolygonMesh.new point1 = Geom::Point3d.new 0,1,2 point2 = Geom::Point3d.new 10,20,30 index = mesh.add_point point1 index = mesh.add_point point2 index = mesh.point_index point1
The points method is used to retrieve an array of points (vertices) in the mesh
Returns:
mesh = Geom::PolygonMesh.new point1 = Geom::Point3d.new 0,1,2 point2 = Geom::Point3d.new 10,20,30 index = mesh.add_point point1 index = mesh.add_point point2 # returns array of points in the mesh num = mesh.points
The polygon_at method is used to retrieve an array of vertex index values
for a polygon at a specific index.
Index is 1 based (starts at 1). The returned array can contain negative
values with the sign indicating a hidden edge. For example, a return value
of [-1, 2, 3] indicates that the edge from 1 to 2 is hidden. The negative
values should not be used as an index for point_at, take the positive value
of the index value in the polygon array. So if you get [-1, 2,3] use 1 as
the arg to point_at.
Arguments:
Returns:
mesh = Geom::PolygonMesh.new point = Geom::Point3d.new 0,1,2 point1 = Geom::Point3d.new 1,0,2 point2 = Geom::Point3d.new 2,0,1 status = mesh.add_polygon point, point1, point2 polygon = mesh.polygon_at 1
The polygon_points_at method is used to retrieve the points for a polygon that is at a specific index in the mesh.
Arguments:
Returns:
mesh = Geom::PolygonMesh.new point = Geom::Point3d.new 0,1,2 point1 = Geom::Point3d.new 1,0,2 point2 = Geom::Point3d.new 2,0,1 status = mesh.add_polygon point, point1, point2 points = mesh.polygon_points_at 1
The polygons method is used to retrieve an array of all polygons in the
mesh.
The returned array can contain negative values with the sign indicating a
hidden edge. For example, a return value of [-1, 2, 3] indicates that the
edge from 1 to 2 is hidden.
Returns:
polygons = polygonmesh.polygons
The set_point method is used to set the point at a specific index in the mesh.
Arguments:
Returns:
mesh = Geom::PolygonMesh.new point1 = Geom::Point3d.new 0,1,2 point2 = Geom::Point3d.new 10,20,30 index = mesh.add_point point1 status = mesh.set_point 1, point2
The transform! method is used to apply a transformation to a mesh.
Arguments:
Returns:
point = Geom::Point3d.new 100,200,300 t = Geom::Transformation.new point mesh = Geom::PolygonMesh.new point1 = Geom::Point3d.new 0,1,2 index = mesh.add_point point1 pmesh = mesh.transform! t
The uv_at method is used to access a uv (texture coordinates) at a specific
index.
"UVs" is a way of referring to the u,v texture coordinates (as
opposed to the X, Y, and Z axis that you construct your meshes on), which
are points defining 1-by-1 positions within an image. These coordinates
connect to points in your 3D model, to position an image texture onto it's
surface (similar to virtual "thumb tacks")
These coordinates pin an exact spot on an image that you wish to use to
texture your model to a specific point on an object's surface. Between these
points, your software will stretch the image smoothly. This is what is
referred to as UV mapping.
Arguments:
Returns:
point = mesh.uv_at(1,1)
The uvs method is used to retrieve an array of uv coordinates in the mesh.
Returns:
mesh = Geom::PolygonMesh.new point1 = Geom::Point3d.new 0,1,2 point2 = Geom::Point3d.new 10,20,30 index = mesh.add_point point1 index = mesh.add_point point2 # returns array of points in the mesh uvs = mesh.uvs