Class: Geom::PolygonMesh
- Inherits:
-
Object
- Object
- Geom::PolygonMesh
Overview
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 Sketchup::Importer 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 Sketchup::Face#mesh method. See Sketchup::Entities#add_faces_from_mesh for an easy way to convert a mesh back into faces.
Constant Summary #
- Geom::PolygonMesh::NO_SMOOTH_OR_HIDE
- Geom::PolygonMesh::HIDE_BASED_ON_INDEX
- Geom::PolygonMesh::SOFTEN_BASED_ON_INDEX
- Geom::PolygonMesh::AUTO_SOFTEN
- Geom::PolygonMesh::SMOOTH_SOFT_EDGES
- Geom::PolygonMesh::MESH_POINTS
- Geom::PolygonMesh::MESH_UVQ_FRONT
- Geom::PolygonMesh::MESH_UVQ_BACK
- Geom::PolygonMesh::MESH_NORMALS
Instance Method Summary # collapse
-
#add_point(point) ⇒ Integer
The #add_point method is used to add a point to the mesh.
-
#add_polygon(*args) ⇒ Integer, 0
The
add_polygon
method is used for adding a polygon to a PolygonMesh. -
#count_points ⇒ Integer
The #count_points method is used to count the number of points in a mesh.
-
#count_polygons ⇒ Integer
The #count_polygons count the number of polygons in the mesh.
-
#initialize(*args) ⇒ Object
constructor
Create a new empty polygon mesh.
-
#normal_at(index) ⇒ Geom::Vector3d?
The #normal_at method is used to determine the vertex normal at a particular index in the mesh.
-
#point_at(index) ⇒ Geom::Point3d?
The #point_at method is used to retrieve the point at a specific index in the mesh.
-
#point_index(point) ⇒ Integer
The #point_index method is used to retrieve the index of a point in the mesh.
-
#points ⇒ Array<Geom::Point3d>
The #points method is used to retrieve an array of points (vertices) in the mesh.
-
#polygon_at(index) ⇒ Array<Geom::Point3d>?
The #polygon_at method is used to retrieve an array of vertex index values for a polygon at a specific index.
-
#polygon_points_at(index) ⇒ Array<Geom::Point3d>?
The #polygon_points_at method is used to retrieve the points for a polygon that is at a specific index in the mesh.
-
#polygons ⇒ Array<Array<Integer>>, Array<nil>
The #polygons method is used to retrieve an array of all polygons in the mesh.
-
#set_point(index, point) ⇒ Geom::PolygonMesh
The #set_point method is used to set the point at a specific index in the mesh.
-
#set_uv(index, point, front) ⇒ nil
The #set_uv method is used to define UV mapping coordinates to points in the mesh.
-
#transform!(transformation) ⇒ Geom::PolygonMesh
The #transform! method is used to apply a transformation to a mesh.
-
#uv_at(index, front) ⇒ Geom::Point3d?
The #uv_at method is used to access a uv (texture coordinates) at a specific index.
-
#uvs(front) ⇒ Array<Geom::Point3d>
The #uvs method is used to retrieve an array of uv coordinates in the mesh.
Constructor Details
↑ #initialize ⇒ Geom::PolygonMesh #initialize(numpts) ⇒ Geom::PolygonMesh #initialize(numpts, numpolys) ⇒ Geom::PolygonMesh
When creating a mesh with normals and/or UVQ data it's critical that the number of points estimated is equal to or higher than the final number of points added. If fewer points are estimated the normals and UVQ data might end up out of sync.
Create a new empty polygon mesh.
The number of points and polygons are optional and are used as a hint to decide how much space to pre-allocate to speed up adding points and polygons.
As of SketchUp 2021.1 the performance of looking up and inserting points is significantly better provided the mesh was initialized with roughly the correct number of total points.
Instance Method Details
↑ #add_point(point) ⇒ Integer
The #add_point method is used to add a point to the mesh.
The index can be used for creating polygons.
↑ #add_polygon(index, index, index, ...) ⇒ Integer, 0 #add_polygon(index_array) ⇒ Integer, 0 #add_polygon(point3d, point3d, point3d, ...) ⇒ Integer, 0 #add_polygon(point3d_array) ⇒ Integer, 0 #add_polygon(array) ⇒ Integer, 0
The add_polygon
method is used for adding a polygon to a PolygonMesh. All variations of this method require at least 3 elements to define a polygon, although more may be given.
↑ #count_points ⇒ Integer
The #count_points method is used to count the number of points in a mesh.
↑ #count_polygons ⇒ Integer
The #count_polygons count the number of polygons in the mesh.
↑ #normal_at(index) ⇒ Geom::Vector3d?
Index starts at 1.
The #normal_at method is used to determine the vertex normal at a particular index in the mesh. This only works for meshes retrieved from Sketchup::Face#mesh with the PolygonMeshNormals
flag.
↑ #point_at(index) ⇒ Geom::Point3d?
Index starts at 1.
The #point_at method is used to retrieve the point at a specific index in the mesh.
↑ #point_index(point) ⇒ Integer
Returns 0 if point is not found.
The #point_index method is used to retrieve the index of a point in the mesh.
↑ #points ⇒ Array<Geom::Point3d>
The #points method is used to retrieve an array of points (vertices) in the mesh
↑ #polygon_at(index) ⇒ Array<Geom::Point3d>?
Index 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 absolute value of the index value in the polygon array. So if you get [-1, 2,3] use 1
as the argument to #point_at.
The #polygon_at method is used to retrieve an array of vertex index values for a polygon at a specific index.
↑ #polygon_points_at(index) ⇒ Array<Geom::Point3d>?
Index starts 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.
↑ #polygons ⇒ Array<Array<Integer>>, Array<nil>
The #polygons method is used to retrieve an array of all polygons in the mesh.
The returned array contains an array that can have a negative value 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.
↑ #set_point(index, point) ⇒ Geom::PolygonMesh
Index starts at 1.
The #set_point method is used to set the point at a specific index in the mesh.
↑ #set_uv(index, point, front) ⇒ nil
If you don't specify how many points you will be adding to the mesh when you initiate it you may risk the UV data becoming out of sync.
Index starts at 1.
The #set_uv method is used to define UV mapping coordinates to points in the mesh.
Beware that the polygons connected to the point will share UV coordiates so UV mapping coordinates needs to be continuous across the polygon mesh.
When setting the UV for a point one need to make sure to have the correct index for the point. It's therefore best to add the points using #add_point and use the index it returns for following calls to set_uv and #add_polygon.
If you are not able to calculate how many points there will be in your mesh make sure to not specify an index in #set_uv higher than the number of times you have called #set_uv.
↑ #transform!(transformation) ⇒ Geom::PolygonMesh
The #transform! method is used to apply a transformation to a mesh.
↑ #uv_at(index, front) ⇒ Geom::Point3d?
Index starts at 1.
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.
↑ #uvs(front) ⇒ Array<Geom::Point3d>
The #uvs method is used to retrieve an array of uv coordinates in the mesh.