API Reference
scadview.Color
Bases: Enum
Enum for common colors used in SCADview visualizations.
Source code in src/scadview/api/colors.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | |
scadview.set_mesh_color(mesh, color, alpha=1.0)
Set the color of a Trimesh object for SCADview visualization.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
mesh
|
Trimesh
|
The input mesh to which the color will be applied. |
required |
color
|
tuple[float, float, float] | list[float] | Color
|
The RGB color to set. Can be a tuple, list, or Color enum. |
required |
alpha
|
float
|
The alpha transparency value for the color (0.0 to 1.0). |
1.0
|
Returns:
| Name | Type | Description |
|---|---|---|
Trimesh |
Trimesh
|
The input mesh with updated color metadata. |
Source code in src/scadview/api/colors.py
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 | |
scadview.surface(file, scale=(1.0, 1.0, 1.0), base=0.0, invert=False, binary_split=False, binary_split_value=0.5)
Create a 3D mesh on a base at z = 0.0 from a file containing heightmap data. The file can be a CSV, TSV, TXT, DAT, or an image file (PNG, JPEG, etc.). Image files are converted to grayscale and generate heights between 0.0 and 1.0
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
file
|
str
|
The file path to get the data from. |
required |
scale
|
tuple[float, float, float]
|
A 3-tuple that scales in each dimension. |
(1.0, 1.0, 1.0)
|
base
|
float
|
The base height of the pedestal upon which the mesh will be placed. |
0.0
|
invert
|
bool
|
If True, inverts the heightmap values between min and max values. |
False
|
binary_split
|
bool
|
Converts the heightmap to 0s or 1s only. based on whether the height is below or equal (changes to 0) or above (changes to 1) the binary_split_value. |
False
|
binary_split_value
|
float
|
Only usedif binary_splt=ut it True. |
0.5
|
Returns:
| Name | Type | Description |
|---|---|---|
Trimesh |
Trimesh
|
A 3d mesh object representing the surface on a pedestal. |
Source code in src/scadview/api/surface.py
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
scadview.mesh_from_heightmap(heightmap, scale=(1.0, 1.0, 1.0))
Create a 3D mesh from a heightmap.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
heightmap
|
NDArray[float32]
|
A 2D numpy array representing the heightmap, where each value corresponds to the height at that point. |
required |
scale
|
tuple[float, float, float]
|
A 3-tuple (X, Y, Z) to scale the mesh in the respective dimensions. |
(1.0, 1.0, 1.0)
|
Returns:
| Type | Description |
|---|---|
Trimesh
|
An object representing the 3D mesh. |
Source code in src/scadview/api/surface.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 | |
scadview.SIZE_MULTIPLIER = 1.374
module-attribute
Used to convert pt size to mesh units.
scadview.text(text, size=10.0, font=DEFAULT_FONT, halign='left', valign='baseline', spacing=0, direction='ltr', language='', script='')
Create a 3D mesh from the given text using the specified font and size. This is based on OpenSCAD's text() function.
Font Loading Time Warning: Loading fonts from the system can be time-consuming, especially if the font cache needs to be rebuilt. The first time this function is called, it may take several seconds to load the font information. Subsequent calls will be faster as the font data is cached.
Font Specification:
The font parameter should be specified in the form "Family:style", e.g. "Arial:style=Bold".
In SCADview, use Help > List System Fonts to see available fonts on your system,
and copy the exact name / style string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to convert to a 3D mesh. |
required |
size
|
float
|
The size of the text in mesh units (per openSCAD). |
10.0
|
font
|
str
|
The font family name to use for the text. This is in the form "Family:style", e.g. "Arial:style=Bold". |
DEFAULT_FONT
|
halign
|
str
|
Horizontal alignment of the text ('left', 'center', 'right'). |
'left'
|
valign
|
str
|
Vertical alignment of the text ('baseline', 'top', 'bottom', 'center'). |
'baseline'
|
spacing
|
float
|
Spacing between characters in mesh units (not used in this implementtion). |
0
|
direction
|
str
|
Text direction (only 'ltr' and 'rtl' are is supported in this implementation). |
'ltr'
|
language
|
str
|
Language of the text (not used in this implementation). |
''
|
script
|
str
|
Script of the text (not used in this implementation). |
''
|
Returns:
| Type | Description |
|---|---|
Trimesh
|
An object representing the 3D mesh of the text. |
Source code in src/scadview/api/text_builder.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 | |
scadview.text_polys(text, size=10.0, font=DEFAULT_FONT, halign='left', valign='baseline', spacing=0, direction='ltr', language='', script='')
Create a list of Polygons from the given text using the specified font and size. This is based on OpenSCAD's text() function, but returns 2D polygons instead of a 3D mesh, suitable for extrusion or other operations.
Font Loading Time Warning: Loading fonts from the system can be time-consuming, especially if the font cache needs to be rebuilt. The first time this function is called, it may take several seconds to load the font information. Subsequent calls will be faster as the font data is cached.
Font Specification:
The font parameter should be specified in the form "Family:style", e.g. "Arial:style=Bold".
In SCADview, use Help > List System Fonts to see available fonts on your system,
and copy the exact name / style string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
text
|
str
|
The text to convert to a polygons. |
required |
size
|
float
|
The size of the text in mesh units. |
10.0
|
font
|
str
|
The font family name and style to use for the text. This is in the form "Family:style", e.g. "Arial:style=Bold". |
DEFAULT_FONT
|
halign
|
str
|
Horizontal alignment of the text ('left', 'center', 'right'). |
'left'
|
valign
|
str
|
Vertical alignment of the text ('baseline', 'top', 'bottom', 'center'). |
'baseline'
|
spacing
|
float
|
Spacing between characters in mesh units (not used in this implementtion). |
0
|
direction
|
str
|
Text direction (only 'ltr' and 'rtl' are is supported in this implementation). |
'ltr'
|
language
|
str
|
Language of the text (not used in this implementation). |
''
|
script
|
str
|
Script of the text (not used in this implementation). |
''
|
Returns:
| Type | Description |
|---|---|
list[Polygon]
|
A list of Polygons represnting the text. There may be multiple polygons per character. |
Source code in src/scadview/api/text_builder.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 | |
scadview.ProfileType = sg.Polygon | NDArray[np.float32] | list[tuple[float, float]] | list[tuple[float, float, float]] | list[list[float]]
module-attribute
The type for the 2D profile for extrusion.
scadview.linear_extrude(profile, height, center=False, convexity=None, twist=0.0, slices=None, scale=1.0, fn=None)
OpenSCAD-like linear_extrude(project-to-XY first).
Signature & defaults mirror OpenSCAD: linear_extrude(height, center=false, convexity, twist=0, slices, scale)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
profile
|
ProfileType
|
The 2D shape to extrude. Can be a shapely Polygon, Nx2 or Nx3 ndarray, or list of 2/3-float tuples/lists. If Nx3 or 3d elements in list, the Z values are ignored. |
required |
height
|
float
|
The extrusion height. |
required |
center
|
bool
|
If true, the solid is centered after extrusion. |
False
|
convexity
|
int | float | None
|
Accepted but ignored (OpenSCAD uses it for preview rays). |
None
|
twist
|
float
|
The extrusion twist in degrees. |
0.0
|
scale
|
float | tuple[float, float] | list[float] | NDArray[float32]
|
Scales the 2D shape by this value over the height of the extrusion. May be scalar or (sx, sy). |
1.0
|
slices
|
int | None
|
Similar to special variable $fn without being passed down to the child 2D shape. |
None
|
fn
|
int | None
|
If |
None
|
Returns:
| Type | Description |
|---|---|
Trimesh
|
The extruded shape. |
Source code in src/scadview/api/linear_extrude.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
scadview.manifold_to_trimesh(manifold)
Convert a manifold object to a Trimesh object. From Manifold
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
manifold
|
Manifold
|
A manifold object with vertex properties and triangle vertices. |
required |
Returns:
| Type | Description |
|---|---|
Trimesh
|
trimesh.Trimesh: A Trimesh object representing the manifold. |
Source code in src/scadview/api/utils.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | |