|
SketchUp Ruby API Reference |
The PolygonMesh class contains methods to create polygon mesh structures.
Parent: Object
Methods: new, add_point, add_polygon, count_points, count_polygons, normal_at, point_at, point_index, points, polygon_at, polygon_points_at, polygons, set_point, transform!, uv_at, uvs
Example Code: polygonmeshtests.rb
The new method is used to create a new empty polygon mesh.
mesh = Geom::PolygonMesh.new numpoints, numpolygons
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.
mesh = Geom::PolygonMesh.new
The add_point method is used to add a point to the mesh.
index = polygonmesh.add_point point
point - a Point3D object
index - the index in the mesh for the point
The index can be used for creating polygons.
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.
index = polygonmesh.add_polygon polygon
polygon - a polygon
index - the index of the polygon in the mesh if successful
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.
points = mesh.count_points
points - the number of points in a mesh, if successful
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.
polygons = mesh.count_polygons
polygons - the number of polygons in the mesh, if successful
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
The normal_at method is used to determine the normal at a particular index in the mesh.
normal = polygonmesh.normal_at index
index - the index in the mesh where the normal is that you want to retrieve
normal - a normal
Index is 1 based (starts at 1).
normal = mesh.normal_at 1
The point_at method is used to retrieve the point at a specific index in the mesh.
point = polygonmesh.point_at index
index - the index in the mesh where the point is that you want to retrieve
point - a Point3D object
Index is 1 based (starts at 1).
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.
index = polygonmesh.point_index point
point - a Point3d object
index - the index in the mesh for the Point3d object
Returns 0 if point is not found.
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
points = polygonmesh.points
points - an array of points (vertices) if successful
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.
vertices = polygonmesh.polygon_at index
index - the index of the desired polygon
vertices - an array of vertex index values
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.
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.
points = polygonmesh.polygon_points_at index
index - an index for a polygon in the mesh
points - an array of points that make up the polygon if successful
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.
polygons = polygonmesh.polygons
polygons - an array of polygons if successful
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.
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
polygons = mesh.polygons
The set_point method is used to set the point at a specific index in the mesh.
polygonmesh = polygonmesh.set_point index, point
index - the index where the point will be set
point - a Point3d object to set at the index
polygonmesh - a PolygonMesh object
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
polygonmesh = polygonmesh.transform! transformation
transformation - a Transformation object
polygonmesh - the PolygonMesh object
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.
point = polygonmesh.uv_at index
index - the index for the texture coordinate
point - a Poin3d object where the x equals the u value and the y equals the v value.
point = mesh.uv_at(1,1)
The uvs method is used to retrieve a list of uvs.
"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 = polygonmesh.uvs side
side - a boolean. If true, use the front uvs. If false, use the back uvs.
uvs - an array of uvs.
The uvs must be generated with the parameters of 1 (Include PolygonMeshUVQFront) or 2 (Include PolygonMeshUVQBack).
uvs = mesh.uvs 1
|
SketchUp Ruby API Reference: PolygonMesh |
© Google Inc. 2007 sketchup.google.com |