My favorites | English | Sign in

Faster apps faster - GWT 2.0 with Speed Tracer New!

Google SketchUp Ruby API

PolygonMesh

class

Parent: Object

Introduction

SketchUp 6.0+

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

Methods

PolygonMesh.add_pointSketchUp 6.0+

The add_point method is used to add a point to the mesh.

The index can be used for creating polygons.

Arguments:

point
A Point3d object.

Returns:

index
the index in the mesh for the point
 mesh = Geom::PolygonMesh.new
 point = Geom::Point3d.new 0,1,2
 index = mesh.add_point point

PolygonMesh.add_polygonSketchUp 6.0+

The add_polygon method is used for adding a polygon to a polygon mesh.

Arguments:

points
A list of points that represent the polygon's vertices.

Returns:

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

PolygonMesh.count_pointsSketchUp 6.0+

The count_points method is used to count the number of points in a mesh.

Returns:

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

PolygonMesh.count_polygonsSketchUp 6.0+

The count_polygons count the number of polygons in the mesh.

Returns:

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

PolygonMesh.newSketchUp 6.0+

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:

numpts
(optional) How many points will be in the mesh.
numpolys
(optional) How many polygons will be in the mesh.

Returns:

mesh
the new PolygonMesh.
 mesh = Geom::PolygonMesh.new

PolygonMesh.normal_atSketchUp 6.0+

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:

index
The index in the mesh where the normal is that you want to retrieve.

Returns:

normal
a normal
 normal = mesh.normal_at 1

PolygonMesh.point_atSketchUp 6.0+

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:

index
The index in the mesh where the point is that you want to retrieve.

Returns:

point
a Point3d object
 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

PolygonMesh.point_indexSketchUp 6.0+

The point_index method is used to retrieve the index of a point in the mesh.

Returns 0 if point is not found.

Arguments:

point
A Point3d object.

Returns:

index
the index in the mesh for the Point3d object
 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

PolygonMesh.pointsSketchUp 6.0+

The points method is used to retrieve an array of points (vertices) in the mesh

Returns:

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

PolygonMesh.polygon_atSketchUp 6.0+

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:

index
The index of the desired polygon.

Returns:

vertices
an array of vertex index values
 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

PolygonMesh.polygon_points_atSketchUp 6.0+

The polygon_points_at method is used to retrieve the points for a polygon that is at a specific index in the mesh.

Arguments:

index
An index for a polygon in the mesh.

Returns:

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

PolygonMesh.polygonsSketchUp 6.0+

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
an array of polygons if successful
 polygons = polygonmesh.polygons

PolygonMesh.set_pointSketchUp 6.0+

The set_point method is used to set the point at a specific index in the mesh.

Arguments:

index
The index where the point will be set.
point
A Point3d object to set at the index.

Returns:

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

PolygonMesh.transform!SketchUp 6.0+

The transform! method is used to apply a transformation to a mesh.

Arguments:

transform
A Transformation object.

Returns:

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

PolygonMesh.uv_atSketchUp 6.0+

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:

index
The index for the texture coordinate.

Returns:

point
a Point3d object where the x equals the u value and the y equals the v value.
 point = mesh.uv_at(1,1)

PolygonMesh.uvsSketchUp 6.0+

The uvs method is used to retrieve an array of uv coordinates in the mesh.

Returns:

points
an array of uv coordinates 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
 uvs = mesh.uvs