trimesh.path.packing module

Classes

RectangleBin([bounds, size])

2D BSP tree node.

Functions

multipack(polygons[, sheet_size, …])

Pack polygons into a rectangle by taking each Polygon’s OBB and then packing that as a rectangle.

pack_paths(paths, **kwargs)

Pack a list of Path2D objects into a rectangle.

pack_rectangles(rectangles, sheet_size[, …])

Pack smaller rectangles onto a larger rectangle, using a binary space partition tree.

class trimesh.path.packing.RectangleBin(bounds=None, size=None)

Bases: object

2D BSP tree node. http://www.blackpawn.com/texts/lightmaps/

Attributes

extents

Bounding box size.

Methods

insert(rectangle)

Insert a rectangle into the bin.

split(length[, vertical])

Returns two bounding boxes representing the current bounds split into two smaller boxes.

property extents

Bounding box size.

Returns

extents

Return type

(2,) float, edge lengths of bounding box

insert(rectangle)

Insert a rectangle into the bin.

Parameters

rectangle ((2,) float, size of rectangle to insert) –

split(length, vertical=True)

Returns two bounding boxes representing the current bounds split into two smaller boxes.

Parameters
  • length (float, length to split) –

  • vertical (bool, if True will split box vertically) –

Returns

box – [minx, miny, maxx, maxy]

Return type

(2,4) float, two bounding boxes consisting of:

trimesh.path.packing.multipack(polygons, sheet_size=None, iterations=50, density_escape=0.95, spacing=0.094, quantity=None)

Pack polygons into a rectangle by taking each Polygon’s OBB and then packing that as a rectangle.

Parameters
  • polygons ((n,) shapely.geometry.Polygon) – Source geometry

  • sheet_size ((2,) float) – Size of rectangular sheet

  • iterations (int) – Number of times to run the loop

  • density_escape (float) – When to exit early (0.0 - 1.0)

  • spacing (float) – How big a gap to leave between polygons

  • quantity ((n,) int, or None) – Quantity of each Polygon

Returns

  • overall_inserted ((m,) int) – Indexes of inserted polygons

  • packed ((m, 3, 3) float) – Homogeonous transforms from original frame to packed frame

trimesh.path.packing.pack_paths(paths, **kwargs)

Pack a list of Path2D objects into a rectangle.

Parameters

paths ((n,) Path2D) – Geometry to be packed

Returns

  • packed (trimesh.path.Path2D) – Object containing input geometry

  • inserted ((m,) int) – Indexes of paths inserted into result

trimesh.path.packing.pack_rectangles(rectangles, sheet_size, shuffle=False)

Pack smaller rectangles onto a larger rectangle, using a binary space partition tree.

Parameters
  • rectangles ((n, 2) float) – An array of (width, height) pairs representing the rectangles to be packed.

  • sheet_size ((2,) float) – Width, height of rectangular sheet

  • shuffle (bool) – Whether or not to shuffle the insert order of the smaller rectangles, as the final packing density depends on insertion order.

Returns

  • density (float) – Area filled over total sheet area

  • offset ((m,2) float) – Offsets to move rectangles to their packed location

  • inserted ((n,) bool) – Which of the original rectangles were packed

  • consumed_box ((2,) float) – Bounding box size of packed result