Solid types¶
- class scadpy.d3.solid.types.Solid(*args, **kwargs)¶
Bases:
Assembly[Trimesh]A 3D assembly of
Trimeshparts.Solidis 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.
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
Solidfrom a sequence ofPart.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:
intAlways
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
Solidfrom a sequence ofPart.This is the low-level constructor used internally. In most cases you should use primitives or boolean operations instead.
- Parameters:
- parts
Sequence[Part[Trimesh]] The parts that make up the solid.
- parts
- Returns:
SolidA 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)])