ModraUp Ruby API Documentation Ruby API Reference

Class: Geom::PolygonMesh

Inherits:
Object
  • Object
show all

Overview

Triangulated mesh snapshot for export and use with ModraUp::Face#mesh, not a BRep journal. Points and polygon indices start at 1; negative indices indicate hidden edges.

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([0, 0, 0])
mesh.add_point([1, 0, 0])
mesh.add_point([0, 1, 0])
mesh.add_polygon(1, 2, 3)
mesh.count_polygons  #=> 1

Constants # collapse

Geom::PolygonMesh::NO_SMOOTH_OR_HIDE

NO_SMOOTH_OR_HIDE = 0

The smoothing flag for ModraUp::Entities#add_faces_from_mesh / ModraUp::Entities#fill_from_mesh: no edges are hidden or smoothed.

Returns:

  • (Integer)
Geom::PolygonMesh::HIDE_BASED_ON_INDEX

HIDE_BASED_ON_INDEX = 1

ModraUp::Entities#add_faces_from_mesh / ModraUp::Entities#fill_from_mesh smooth flag: hide edges starting from negative index points.

Returns:

  • (Integer)
Geom::PolygonMesh::SOFTEN_BASED_ON_INDEX

SOFTEN_BASED_ON_INDEX = 2

The smoothing flag for ModraUp::Entities#add_faces_from_mesh / ModraUp::Entities#fill_from_mesh: Soften edges starting from negative-index points.

Returns:

  • (Integer)
Geom::PolygonMesh::AUTO_SOFTEN

AUTO_SOFTEN = 4

ModraUp::Entities#add_faces_from_mesh / ModraUp::Entities#fill_from_mesh smoothing flag: soften edges between nearly coplanar adjacent faces.

Returns:

  • (Integer)
Geom::PolygonMesh::SMOOTH_SOFT_EDGES

SMOOTH_SOFT_EDGES = 8

The smoothing flag for ModraUp::Entities#add_faces_from_mesh / ModraUp::Entities#fill_from_mesh: smooths both the edges and softens them.

Returns:

  • (Integer)

Class Method Summary # collapse

  • .new ⇒ Geom::PolygonMesh
    An empty mesh. Optional parameters only reserve capacity (up to approximately 1 million per item), leaving no points; points can still be added later.

Instance Method Summary # collapse

Class Method Details

PolygonMesh.new ⇒ meshPolygonMesh.new(number_points) ⇒ meshPolygonMesh.new(number_points, number_polygons) ⇒ mesh

An empty mesh. Optional parameters only reserve capacity (up to approximately 1 million per item), leaving no points; points can still be added later.

Parameters:

  • number_points (Integer)
  • number_polygons (Integer)

Returns:

  • (Geom::PolygonMesh)

Examples:

Geom::PolygonMesh.new(8, 6).count_points  #=> 0

Instance Method Details

mesh.add_point(point) ⇒ Integer

Add a point and return the point number starting from 1.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Integer)

Examples:

Geom::PolygonMesh.new.add_point([0, 0, 0])  #=> 1

mesh.add_polygon(i1, i2, i3, ...) ⇒ Integermesh.add_polygon([i1, i2, i3]) ⇒ Integermesh.add_polygon(p1, p2, p3, ...) ⇒ Integermesh.add_polygon([p1, p2, p3]) ⇒ Integer

Add a polygon. Parameters are vertex indices starting from 1 (negative values indicate an implied edge), or at least three points. Returns 0 if the operation fails.

Returns:

  • (Integer)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_polygon([0, 0, 0], [1, 0, 0], [0, 1, 0])  #=> 1

mesh.count_points ⇒ Integer

Number of points.

Returns:

  • (Integer)

Examples:

Geom::PolygonMesh.new.count_points  #=> 0

mesh.count_polygons ⇒ Integer

Number of polygons.

Returns:

  • (Integer)

Examples:

Geom::PolygonMesh.new.count_polygons  #=> 0

mesh.points ⇒ Array<Geom::Point3d>

All points, in order with 1-based indexing.

Returns:

  • (Array<Geom::Point3d>)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([1, 2, 3])
mesh.points[0].to_a  #=> [1.0, 2.0, 3.0]

mesh.polygons ⇒ Array<Array<Integer>>

The vertex indices for all polygons (starting at 1; negative values indicate hidden edges).

Returns:

  • (Array<Array<Integer>>)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_polygon([0, 0, 0], [1, 0, 0], [0, 1, 0])
mesh.polygons.length  #=> 1

mesh.point_at(index) ⇒ Geom::Point3d, nil

The starting point. Out-of-bounds is nil.

Parameters:

  • index (Integer)

Returns:

  • (Geom::Point3d, nil)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([0, 1, 0])
mesh.point_at(1).to_a  #=> [0.0, 1.0, 0.0]

mesh.point_index(point) ⇒ Integer

The point index starts at 1; if there is no point, it is 0.

Parameters:

  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Integer)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([0, 0, 0])
mesh.point_index([0, 0, 0])  #=> 1

mesh.polygon_at(index) ⇒ Array<Integer>, nil

The starting vertex index of the polygon. Out-of-bounds returns nil.

Parameters:

  • index (Integer)

Returns:

  • (Array<Integer>, nil)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_polygon([0, 0, 0], [1, 0, 0], [0, 1, 0])
mesh.polygon_at(1).length  #=> 3

mesh.polygon_points_at(index) ⇒ Array<Geom::Point3d>, nil

Polygon vertex coordinates. Out-of-bounds is nil.

Parameters:

  • index (Integer)

Returns:

  • (Array<Geom::Point3d>, nil)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_polygon([0, 0, 0], [1, 0, 0], [0, 1, 0])
mesh.polygon_points_at(1).length  #=> 3

mesh.set_point(index, point) ⇒ self

Updates an existing point. An out-of-range index is ignored.

Parameters:

  • index (Integer)
  • point (Geom::Point3d, Array<Numeric>)

Returns:

  • (Geom::PolygonMesh)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([0, 0, 0])
mesh.set_point(1, [2, 0, 0])
mesh.point_at(1).to_a  #=> [2.0, 0.0, 0.0]

mesh.set_uv(index, uv) ⇒ selfmesh.set_uv(index, uv, front) ⇒ self

Sets the UV for the point (using Point3d x/y coordinates). The default front face is assumed.

Parameters:

  • index (Integer)
  • uv (Geom::Point3d, Array<Numeric>)
  • front (Boolean) Default true

Returns:

  • (Geom::PolygonMesh)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([0, 0, 0])
mesh.set_uv(1, [0.5, 0.25, 0])
mesh.uv_at(1).x  #=> 0.5

mesh.uv_at(index) ⇒ Geom::Point3d, nilmesh.uv_at(index, front) ⇒ Geom::Point3d, nil

The UV of the point. Returns nil if not set.

Parameters:

  • index (Integer)
  • front (Boolean) Default true

Returns:

  • (Geom::Point3d, nil)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([0, 0, 0])
mesh.set_uv(1, [1, 0, 0])
mesh.uv_at(1).to_a  #=> [1.0, 0.0, 0.0]

mesh.uvs ⇒ Array<Geom::Point3d>mesh.uvs(front) ⇒ Array<Geom::Point3d>

Array of UVs for all points; is empty if not set.

Parameters:

  • front (Boolean) Default true

Returns:

  • (Array<Geom::Point3d>)

Examples:

Geom::PolygonMesh.new.uvs.length  #=> 0

mesh.normal_at(index) ⇒ Geom::Vector3d, nil

The normal at the point. Returns nil if not set.

Parameters:

  • index (Integer)

Returns:

  • (Geom::Vector3d, nil)

Examples:

Geom::PolygonMesh.new.normal_at(1)  #=> nil

mesh.transform!(transformation) ⇒ self

Transform all points in place.

Parameters:

  • transformation (Geom::Transformation)

Returns:

  • (Geom::PolygonMesh)

Examples:

mesh = Geom::PolygonMesh.new
mesh.add_point([1, 0, 0])
mesh.transform!(Geom::Transformation.scaling(2))
mesh.point_at(1).to_a  #=> [2.0, 0.0, 0.0]