Class: Geom::PolygonMesh
- Inherits:
-
Object
- Object
- Geom::PolygonMesh
- Defined in:
- lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb
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 collapse
- AUTO_SOFTEN =
Constants
nil
- HIDE_BASED_ON_INDEX =
Stub value.
nil
- NO_SMOOTH_OR_HIDE =
Stub value.
nil
- SMOOTH_SOFT_EDGES =
Stub value.
nil
- SOFTEN_BASED_ON_INDEX =
Stub value.
nil
- MESH_NORMALS =
Stub value.
nil
- MESH_POINTS =
Stub value.
nil
- MESH_UVQ_BACK =
Stub value.
nil
- MESH_UVQ_FRONT =
Stub value.
nil
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) ⇒ PolygonMesh
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.
205 206 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 205 def initialize(*args) end |
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.
57 58 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 57 def add_point(point) end |
#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.
137 138 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 137 def add_polygon(*args) end |
#count_points ⇒ Integer
The #count_points method is used to count the number of points in a mesh.
151 152 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 151 def count_points end |
#count_polygons ⇒ Integer
The #count_polygons count the number of polygons in the mesh.
167 168 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 167 def count_polygons end |
#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.
226 227 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 226 def normal_at(index) end |
#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.
248 249 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 248 def point_at(index) end |
#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.
269 270 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 269 def point_index(point) end |
#points ⇒ Array<Geom::Point3d>
The #points method is used to retrieve an array of points (vertices) in the mesh
287 288 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 287 def points end |
#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.
316 317 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 316 def polygon_at(index) end |
#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.
338 339 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 338 def polygon_points_at(index) end |
#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.
354 355 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 354 def polygons end |
#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.
378 379 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 378 def set_point(index, point) end |
#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.
438 439 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 438 def set_uv(index, point, front) end |
#transform!(transformation) ⇒ Geom::PolygonMesh
The #transform! method is used to apply a transformation to a mesh.
456 457 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 456 def transform!(transformation) end |
#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.
490 491 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 490 def uv_at(index, front) end |
#uvs(front) ⇒ Array<Geom::Point3d>
The #uvs method is used to retrieve an array of uv coordinates in the mesh.
506 507 |
# File 'lib/sketchup-api-stubs/stubs/Geom/PolygonMesh.rb', line 506 def uvs(front) end |