Solid types

class scadpy.d3.solid.types.Solid(*args, **kwargs)

Bases: Assembly[Trimesh]

A 3D assembly of Trimesh parts.

Solid is the central 3D modeling object in ScadPy. It wraps one or more colored Trimesh meshes and exposes a fluent API for boolean operations, geometric transforms, topology queries, and 3D export.

Use the primitives (cuboid(), cylinder(), sphere(), …) or importers (Solid.from_stl()) to create solids; do not instantiate this class directly.

Attributes:
bounding_box

Return the axis-aligned bounding box of the solid as a cuboid.

See get_solid_bounding_box() for parameter documentation.

>>> from scadpy import cuboid
>>> cuboid(2).bounding_box.bounds
array([-1., -1., -1.,  1.,  1.,  1.])
bounds

Return the axis-aligned bounding box of the solid.

See get_solid_bounds() for parameter documentation.

>>> from scadpy import cuboid
>>> cuboid(2).bounds
array([-1., -1., -1.,  1.,  1.,  1.])
centroid

Return the geometric centroid of the solid, weighted by part volume.

See get_solid_centroid() for parameter documentation.

>>> from scadpy import cuboid
>>> cuboid(2).centroid
array([0., 0., 0.])
is_empty

Return whether the solid has no vertices.

See is_solid_empty() for parameter documentation.

>>> from scadpy import Solid, cuboid
>>> Solid.from_parts([]).is_empty
True
>>> cuboid(2).is_empty
False
part_colors

For each part in the solid, return its RGBA color.

See get_solid_part_colors() for parameter documentation.

>>> from scadpy import cuboid, DEFAULT_OPACITY
>>> colors = cuboid(2).part_colors
>>> colors.shape
(1, 4)
>>> bool(colors[0, 3] == DEFAULT_OPACITY)
True
triangle_to_vertex

For each triangle in the solid, return the indices of its three vertices.

See get_solid_triangle_to_vertex() for parameter documentation.

>>> from scadpy import cuboid
>>> triangle_to_vertex = cuboid(2).triangle_to_vertex
>>> triangle_to_vertex.shape[1]
3
vertex_coordinates

For each vertex in the solid, return its coordinates.

See get_solid_vertex_coordinates() for parameter documentation.

>>> from scadpy import cuboid
>>> vertex_coordinates = cuboid(2).vertex_coordinates
>>> vertex_coordinates.shape
(8, 3)
vertex_to_part

For each vertex in the solid, return its part index.

See get_solid_vertex_to_part() for parameter documentation.

>>> from scadpy import cuboid
>>> solid = cuboid(2) + cuboid(2).translate(5)
>>> solid.vertex_to_part
array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1])

Methods

color(color)

Set the color of all parts in this solid.

concat(solids)

Concatenate this solid with others without any boolean operation.

convexify([part_filter])

Create a new solid whose selected parts are replaced by their convex hull.

dimensions()

Return the number of spatial dimensions: always 3.

exclude(solids)

Compute the symmetric difference (XOR) of this solid with others.

from_geometries(geometries)

Map a sequence of Trimesh geometries to a solid.

from_geometry(geometry)

Map a single Trimesh geometry to a solid.

from_parts(parts)

Assemble a Solid from a sequence of Part.

from_stl(source)

Load a solid from an STL file.

intersect(solids)

Compute the intersection of this solid with others.

linear_pattern(counts, steps)

Repeat this solid in a linear or grid pattern.

mirror(normal[, pivot])

Mirror this solid across a plane defined by a normal vector and a pivot point.

pull(distance[, pivot, vertex_filter])

Move a subset of vertices of this solid toward a pivot point by a given distance.

push(distance[, pivot, vertex_filter])

Move a subset of vertices of this solid away from a pivot point by a given distance.

radial_pattern(count, axis[, angle, pivot])

Repeat this solid in a radial pattern around an axis.

recoordinate(vertex_coordinates)

Rebuild this solid with new vertex coordinates, preserving topology and colors.

resize(size[, auto, pivot, vertex_filter])

Resize this solid to fit target dimensions.

rotate(angle, axis[, pivot, vertex_filter])

Rotate this solid by a given angle around an axis passing through a pivot point.

scale(scale[, pivot, vertex_filter])

Scale this solid by a given factor, relative to a pivot point.

subtract(to_subtract)

Subtract a solid from this solid using boolean difference.

to_html([background_color, foreground_color])

Render this solid as an interactive HTML widget.

to_html_file(path[, background_color, ...])

Save this solid as an HTML file.

to_screen([background_color, foreground_color])

Display this solid in an interactive viewer.

to_stl_file(path)

Export this solid to an STL file.

translate(translation[, vertex_filter])

Translate this solid by a given vector.

unify(solids)

Unite this solid with others using boolean union.

Examples

>>> from scadpy import cuboid, sphere
>>> s = cuboid(4) - sphere(3)
>>> s.is_empty
False
_abc_impl = <_abc._abc_data object>
property bounding_box

Return the axis-aligned bounding box of the solid as a cuboid.

See get_solid_bounding_box() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(2).bounding_box.bounds
array([-1., -1., -1.,  1.,  1.,  1.])
property bounds

Return the axis-aligned bounding box of the solid.

See get_solid_bounds() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(2).bounds
array([-1., -1., -1.,  1.,  1.,  1.])
property centroid

Return the geometric centroid of the solid, weighted by part volume.

See get_solid_centroid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(2).centroid
array([0., 0., 0.])
color(color)

Set the color of all parts in this solid.

See color_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> from scadpy.color.constants import RED
>>> cuboid(4).color(RED)
concat(solids)

Concatenate this solid with others without any boolean operation.

See concat_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid, sphere
>>> cuboid(4).concat([sphere(radius=2).translate([3, 2, 0])])
convexify(part_filter=None)

Create a new solid whose selected parts are replaced by their convex hull.

See convexify_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid, sphere
>>> (cuboid(4) + sphere(radius=2).translate([3, 3, 3])).convexify()
classmethod dimensions()

Return the number of spatial dimensions: always 3.

Returns:
int

Always 3.

Examples

>>> from scadpy import Solid
>>> Solid.dimensions()
3
exclude(solids)

Compute the symmetric difference (XOR) of this solid with others.

See exclude_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid, concat_solid, x
>>> cuboid(4).exclude([cuboid(4).translate(x(2))])
classmethod from_geometries(geometries)

Map a sequence of Trimesh geometries to a solid.

See map_geometries_to_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> Solid.from_geometries([cuboid(4)._parts[0].geometry])
classmethod from_geometry(geometry)

Map a single Trimesh geometry to a solid.

See map_geometry_to_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> Solid.from_geometry(cuboid(4)._parts[0].geometry)
classmethod from_parts(parts)

Assemble a Solid from a sequence of Part.

This is the low-level constructor used internally. In most cases you should use primitives or boolean operations instead.

Parameters:
partsSequence[Part[Trimesh]]

The parts that make up the solid.

Returns:
Solid

A new solid containing exactly the given parts.

Examples

>>> from scadpy import Solid
>>> Solid.from_parts([]).is_empty
True
classmethod from_stl(source)

Load a solid from an STL file.

See map_stl_to_solid() for parameter documentation.

Examples

>>> from scadpy import Solid
>>> Solid.from_stl("model.stl")
intersect(solids)

Compute the intersection of this solid with others.

See intersect_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid, sphere
>>> cuboid(4).intersect([sphere(radius=2).translate(1)])
property is_empty

Return whether the solid has no vertices.

See is_solid_empty() for parameter documentation.

Examples

>>> from scadpy import Solid, cuboid
>>> Solid.from_parts([]).is_empty
True
>>> cuboid(2).is_empty
False
linear_pattern(counts, steps)

Repeat this solid in a linear or grid pattern.

See linear_pattern_solid() for parameter documentation.

Examples

>>> from scadpy import sphere, x, y, z
>>> sphere(1).linear_pattern(counts=4, steps=x(3))
>>> sphere(1).linear_pattern(counts=[3, 2], steps=[x(3), y(3)])
>>> sphere(1).linear_pattern(counts=[3, 2, 4], steps=[x(3), y(3), z(4)])
mirror(normal, pivot=0)

Mirror this solid across a plane defined by a normal vector and a pivot point.

See mirror_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).mirror([1, 0, 0], pivot=[2, 0, 0])
property part_colors

For each part in the solid, return its RGBA color.

See get_solid_part_colors() for parameter documentation.

Examples

>>> from scadpy import cuboid, DEFAULT_OPACITY
>>> colors = cuboid(2).part_colors
>>> colors.shape
(1, 4)
>>> bool(colors[0, 3] == DEFAULT_OPACITY)
True
pull(distance, pivot=0, vertex_filter=None)

Move a subset of vertices of this solid toward a pivot point by a given distance.

See pull_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).pull(distance=1.0, pivot=[2, 2, 2], vertex_filter=cuboid(4).vertex_coordinates[:, 0] < 1)
push(distance, pivot=0, vertex_filter=None)

Move a subset of vertices of this solid away from a pivot point by a given distance.

See push_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).push(distance=1.0, pivot=[2, 2, 2], vertex_filter=cuboid(4).vertex_coordinates[:, 0] < 1)
radial_pattern(count, axis, angle=360, pivot=0)

Repeat this solid in a radial pattern around an axis.

See radial_pattern_solid() for parameter documentation.

Examples

>>> from scadpy import sphere, x
>>> sphere(1).translate(x(3)).radial_pattern(count=6, axis=z())
recoordinate(vertex_coordinates)

Rebuild this solid with new vertex coordinates, preserving topology and colors.

See recoordinate_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).recoordinate(cuboid(4).vertex_coordinates + [2.0, 1.0, 0.0])
resize(size, auto=False, pivot=None, vertex_filter=None)

Resize this solid to fit target dimensions.

See resize_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> # resize to an exact size on all axes:
>>> cuboid([4, 2, 1]).resize([6, 6, 6])
>>> # freeze two axes (``None``) and scale only the first:
>>> cuboid([4, 2, 1]).resize([6, None, None])
>>> # scale frozen axes proportionally with ``auto=True``:
>>> cuboid([4, 2, 1]).resize([6, None, None], auto=True)
rotate(angle, axis, pivot=0, vertex_filter=None)

Rotate this solid by a given angle around an axis passing through a pivot point.

See rotate_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).rotate(angle=45, axis=[0, 0, 1], pivot=[2, 2, 2])
scale(scale, pivot=0, vertex_filter=None)

Scale this solid by a given factor, relative to a pivot point.

See scale_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).scale(2, pivot=[2, 2, 2])
subtract(to_subtract)

Subtract a solid from this solid using boolean difference.

See subtract_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid, sphere
>>> cuboid(4).subtract(sphere(radius=2))
to_html(background_color=[0.95, 0.95, 0.95, 1], foreground_color=[0.05, 0.05, 0.05, 1])

Render this solid as an interactive HTML widget.

See map_solid_to_html() for parameter documentation.

Examples

>>> from IPython.core.display import HTML
>>> from scadpy import cuboid
>>> html = cuboid(4).to_html()
>>> isinstance(html, HTML)
True
to_html_file(path, background_color=[0.95, 0.95, 0.95, 1], foreground_color=[0.05, 0.05, 0.05, 1])

Save this solid as an HTML file.

See map_solid_to_html_file() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).to_html_file(path="output.html")
to_screen(background_color=[0.95, 0.95, 0.95, 1], foreground_color=[0.05, 0.05, 0.05, 1])

Display this solid in an interactive viewer.

See map_solid_to_screen() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).to_screen()
to_stl_file(path)

Export this solid to an STL file.

See map_solid_to_stl_file() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).to_stl_file(path="output.stl")
translate(translation, vertex_filter=None)

Translate this solid by a given vector.

See translate_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> cuboid(4).translate([3, 2, 1])
property triangle_to_vertex

For each triangle in the solid, return the indices of its three vertices.

See get_solid_triangle_to_vertex() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> triangle_to_vertex = cuboid(2).triangle_to_vertex
>>> triangle_to_vertex.shape[1]
3
unify(solids)

Unite this solid with others using boolean union.

See unify_solid() for parameter documentation.

Examples

>>> from scadpy import cuboid, sphere, x
>>> cuboid(4).unify([sphere(radius=2).translate(x(2))])
property vertex_coordinates

For each vertex in the solid, return its coordinates.

See get_solid_vertex_coordinates() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> vertex_coordinates = cuboid(2).vertex_coordinates
>>> vertex_coordinates.shape
(8, 3)
property vertex_to_part

For each vertex in the solid, return its part index.

See get_solid_vertex_to_part() for parameter documentation.

Examples

>>> from scadpy import cuboid
>>> solid = cuboid(2) + cuboid(2).translate(5)
>>> solid.vertex_to_part
array([0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1])