Skip to content

compas_tf.element ¤

Classes¤

TFElement ¤

TFElement(*args, **kwargs)

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

  1. splice :meth:_baked_data into their __data__ (**self._baked_data()), and
  2. decorate their compute_elementgeometry with :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.

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 ¤
__from_data__(data: dict) -> TFElement

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 ¤
bake(*args, modelgeometry: bool | None = None, **kwargs) -> Mesh

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 compute_elementgeometry (include_features, and types on the elements that support it).

()
**kwargs

Forwarded to compute_elementgeometry (include_features, and types on the elements that support it).

()
modelgeometry bool

Also bake the model-space geometry (see :meth:bake_modelgeometry). By default this happens only when baking the element's DEFAULT variant - model geometry is built from that one, so asking for it while baking a side variant would run the very boolean the call was trying to avoid.

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 ¤
brep_meshes(variant: str | None = None) -> list

The element's model-space mesh - what :meth:get_brep converts.

Parameters:

Name Type Description Default
variant str

A baked variant key (see :func:bakekey and :meth:baked_variants) to convert instead of the finished geometry - e.g. "ColumnAddFeature" for a column's uncut stock. The variant is stored in the local frame, so it is placed here.

None

Returns:

Type Description
list[:class:`compas.datastructures.Mesh`]

Raises:

Type Description
ValueError

If variant is not baked on this element.

default_bakekey ¤
default_bakekey() -> str

The :func:bakekey a plain compute_elementgeometry() resolves to.

Not always :data:ALL: the elements that carry no features declare include_features=False, so their default variant is :data:BASE. This is the variant the elementgeometry property serves.

unbake ¤
unbake() -> None

Drop every baked mesh, so the geometry is recomputed from the parameters.

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 ¤

baked(fn)

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 ¤

bakekey(include_features: bool = True, types: list | None = None) -> str

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