compas_tf.element
¤
Classes¤
TFElement
¤
Base class for every compas_tf element: baked geometry + get_brep.
A compas_tf element is parametric: its geometry is a boolean of its base
shape with its features (capitel unions, cutter differences). Recomputing
that on every load is slow, needs the boolean backends installed, and is not
what a fabrication model is for - the shape is already decided.
:meth:bake runs the booleans once and stores the result ON the element,
and :meth:_baked_data puts it in __data__, so a baked element
round-trips through plain compas.json_dump / compas.json_load and
comes back with its geometry already applied to its base geometry - no
boolean recomputed, and the parameters and features still there beside it.
More than one variant can be baked, because fabrication needs more than the
finished part: :meth:bake is keyed by the same
(include_features, types) arguments compute_elementgeometry takes,
so a column can carry both its uncut stock (types=["ColumnAddFeature"])
and its carved final shape.
get_brep() comes from :class:compas_tf.brep.BrepMixin: meshes to a
solid Brep with coplanar faces merged, via compas_occt.
Subclasses stay ordinary compas_model elements; they only have to
- splice :meth:
_baked_datainto their__data__(**self._baked_data()), and - decorate their
compute_elementgeometrywith :func:baked.
Deserialization is handled here: :meth:__from_data__ pulls the baked
meshes back out and puts them where the elementgeometry /
modelgeometry properties find them, so nothing recomputes.
-
API Reference
element ClassesTFElement Methods:__from_data__
Attributes¤
is_baked
property
¤
is_baked: bool
True if :meth:bake has stored geometry that no longer needs recomputing.
placedgeometry
property
¤
placedgeometry: Mesh
The element geometry in model coordinates, without requiring a model.
Same as modelgeometry for an element inside a model; for a loose
element it is the element geometry moved by its own transformation.
placement
property
¤
placement: Transformation
The transformation that takes the element's local geometry to model space.
The element's modeltransformation when it sits in a model; its own
transformation (or the identity) when it is loose - so features and
baked variants can be placed either way.
Methods:¤
__from_data__
classmethod
¤
Rebuild the element and restore its baked geometry.
The baked keys are popped before the constructor call, so subclasses
keep their plain parametric __init__ signature.
bake
¤
Compute a geometry variant once and store it for serialization.
Takes exactly the arguments compute_elementgeometry takes and passes
them straight through; the result is stored under the matching
:func:bakekey and served from there afterwards - by
compute_elementgeometry (through the :func:baked decorator), by the
elementgeometry property, and by __data__.
Bake more than once to keep more than one variant, e.g. a column's uncut stock next to its carved shape::
column.bake(types=["ColumnAddFeature"]) # stock
column.bake() # finished part
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
*args
|
Forwarded to |
()
|
|
**kwargs
|
Forwarded to |
()
|
|
modelgeometry
|
bool
|
Also bake the model-space geometry (see :meth: |
None
|
Returns:
| Type | Description |
|---|---|
class:`compas.datastructures.Mesh`
|
The baked mesh, in the element's local frame. |
bake_modelgeometry
¤
bake_modelgeometry() -> Mesh
Compute and store the element's geometry in MODEL coordinates.
This is the geometry with the model transformation and any interaction
modifiers already applied - the shape as it sits in the assembly. Stored
in __data__ so a reloaded model draws without touching a boolean
backend. Falls back to the placed element geometry when the element is
not (yet) in a model.
Returns:
| Type | Description |
|---|---|
class:`compas.datastructures.Mesh`
|
|
baked_variants
¤
baked_variants() -> list
The :func:bakekey of every geometry variant stored on the element.
brep_meshes
¤
The element's model-space mesh - what :meth:get_brep converts.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
variant
|
str
|
A baked variant key (see :func: |
None
|
Returns:
| Type | Description |
|---|---|
list[:class:`compas.datastructures.Mesh`]
|
|
Raises:
| Type | Description |
|---|---|
ValueError
|
If |
TFFeature
¤
Base class for every compas_tf feature.
Adds get_brep(), which converts whatever solids the feature carries -
its meshes - into a Brep. For a cut feature that is the cutter solid,
which is exactly what a fabricator needs to see next to the stock.
Functions:¤
baked
¤
Decorator for compute_elementgeometry: serve the baked mesh if there is one.
Reads the (include_features, types) the caller asked for - whatever the
subclass's signature happens to be - turns them into a :func:bakekey, and
returns the stored mesh for that key instead of running the booleans. A miss
falls through to the real implementation, so an unbaked element behaves
exactly as before.
bakekey
¤
Canonical cache key for a geometry variant.
Mirrors the compute_elementgeometry arguments: no features is
:data:BASE, all features is :data:ALL, and a type filter is the sorted
feature-class names joined with + (e.g. "ColumnAddFeature" for a
column's uncut stock).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
include_features
|
bool
|
Whether features are applied. |
True
|
types
|
list[str | type]
|
Feature types applied, as class names or classes. |
None
|
Returns:
| Type | Description |
|---|---|
str
|
|