Metafold Developer Docs
Metafold Developer Docs
/Shape Function Reference
Shape Function Reference
Shape Function Reference

Shape Function Reference

  • Introduction
  • Source Operators
  • GenerateSamplePoints
  • LoadSamplePoints
  • LoadVolume
  • Transform Operators
  • ComputeNormals
  • TransformCylindricalCoords
  • TransformMirrorCoords
  • TransformSphericalCoords
  • TransformTwistCoords
  • Sample Operators
  • MapTexturePrimitive
  • SampleBox
  • SampleBeam
  • SampleCustomShape
  • SampleTriangleMesh
  • SampleLattice
  • SampleSpinodoid [Under Development]
  • SampleSurfaceLattice
  • SampleVolume
  • Filter Operators
  • CSG
  • Shell
  • LinearFilter
  • Redistance
  • Threshold
  • Assets

Introduction

The Metafold geometry kernel uses a computational directed acyclic graph (DAG) of operators to define shape functions. The DAG can be created through factory functions available in the SDK. By composing these operators you can create expressive implicit representations of arbitrarily complex shapes.

Operators are categorized into three main groups:

  • Sample: TODO
  • Filter: TODO
  • Transform: TODO

These operators are a symbolic representation of functions within the computational graph that are consumed by our backend via jobs like, evaluate_graph. In order to access the data locally you must download the resulting assets using the SDK and import it into your project. For example:

Source Operators

‣

GenerateSamplePoints

GenerateSamplePoints is a fundamental operator within the Metafold SDK that creates a regular grid of sample points in 3D space. It serves as the starting point for many geometric operations and shape definitions in Metafold.

Users need to use GenerateSamplePoints for several important reasons:

  1. Defining the computational domain: It sets up the 3D space where subsequent operations will take place.
  2. Controlling resolution: Users can specify the density of sample points, which affects the accuracy and detail of the resulting shapes for rendering and exporting.
  3. Providing input for other operators: Many other Metafold operators, such as SampleLattice or various primitives, require a set of sample points as input.

By using GenerateSamplePoints, users create the foundation upon which they can build complex geometric structures, perform analyses, and generate 3D models within the Metafold environment.

‣
Output

Vec3f function

‣
Parameters
Parameter
Type
Description
xform
Mat4f
Affine transformation matrix. Applied after offset. Defaults to identity matrix.
offset
Vec3f
Translational offset of minimum grid corner. Defaults to zero vector.
size
Vec3f
Grid extents. Ignored for any axis with a resolution of one. Defaults to zero vector.
resolution
Vec3i
Number of samples along grid extents. Defaults to [1, 1, 1].
‣
Example

The following generates 128^3 grid points within a box of size 20 centered at the origin.

from metafold.func import GenerateSamplePoints
import numpy as np

source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)
‣

LoadSamplePoints

LoadSamplePoints is a flexible operator that allows users to manually define their own set of points for function evaluations. Users can use this to define irregular grids that sample certain regions in space more densely.

‣
Output

Vec3f function

‣
Parameters
Parameter
Type
Description
points (Required)
Array[Vec3f]
Array of sample points.
‣
Example

The following generates a random set 1000 of points within a box of size 20 centered at the origin.

from metafold.func import LoadSamplePoints
import numpy as np

source = LoadSamplePoints(
    {
        "points": np.random.uniform(-10, 20, (1000, 3))
    }
)
‣

LoadVolume

LoadVolume is a handy operator for importing 2D and 3D arrays of data. The data is expected to be stored as 32-bit floats and can consist of 1-, 2-, 3-, or 4- dimensional vector. It is imperative that the resolution accurately matches the size of the data.

LoadVolume does not sample the volume, but allocates and fills memory with the given data to be used by subsequent operators in the graph. SampleVolume is such an operator.

It is recommended to cache an implicit representation of a mesh using SampleTriangleMesh on a grid. You can than use this operator to load in the mesh each time for faster evaluation.

‣
Assets
Parameter
Type
Description
volume_data (Required)
VolumeAsset
Structured reference to a .bin file containing volume data.
‣
Output

ByteFunction

Float function

Vec2i or Vec2f function

Vec3i or Vec3f function

Vec4i or Vec4f function

‣
Parameters
Parameter
Type
Description
component_type (Required)
String
Volume asset component type. Defaults to “Float” . Options include: "Byte", "Float", "Integer", "Vec2f", "Vec2i", "Vec3f", "Vec3i", "Vec4f", "Vec4i”
resolution (Required)
Vec3i
Number of values along each dimension.
‣
Example

Loads in a scalar field cached onto a grid.

from metafold.func import LoadVolume
from metafold.func_types import Volume_Asset
import numpy as np

volume_path = "path/to/binary/volume.bin"
volume_asset = VolumeAsset()
volume_asset["path"] = volume_path

volume = LoadVolume(
    volume_asset,  
    {
        "component_type"
        "resolution": [128, 128, 128]
    }
)
‣
Related Operators

SampleVolume, MapTexturePrimitive, ComputeNormals

Transform Operators

‣

ComputeNormals

Compute the gradient of a volume at the given sample points.

Metafold represents shapes as the 0-level set of implicit scalar-field defined on a grid. This means that the normal is defined throughout the domain for all shapes. This function allows you to quickly compute the normals at specific locations in space. The locations do not need to be the original grid created via GenerateSamplePoints. They can be from a secondary grid or another set of points generated via LoadSamplePoints .

‣
Inputs
Name
Type
Description
points (Required)
Vec3f function
Metafold source operator representing the sample point locations.
volume (Required)
Float function
Metafold operator representing the volume of interest.
‣
Output

Vec3f function

‣
Parameters
Parameter
Type
Description
volume_offset
Vec3f
Volume translational offset. Defaults to [0.0, 0.0, 0.0] .
volume_size
Vec3f
Volume extents. Defaults to [0.0, 0.0, 0.0] .
xform
Mat4f
Affine transformation to apply to volume box. Defaults to identity matrix.
‣
Example

Compute the normals on a cylinder with a cap radius of 5 and height of 10.

‣

TransformCylindricalCoords

Apply a cylindrical mapping to the input points. This operator transforms points into a cylindrical coordinate system. When used as input to a sample function for shape creation, it introduces controlled curvature to the shape. This technique is particularly powerful for manipulating lattice structures.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Vec3f function

‣
Parameters
Parameter
Type
Description
xform
Mat4
Affine transformation matrix applied to points before the mapping occurs. Defaults to identity matrix.
radial_scale
Float
Used to control the amount of amount of repetition in the radial direction. Defaults to 1.0.

Radial Divisions

22
2
33
3
44
4
55
5
66
6
💡
Advanced Tip In order to divide the “cylindrically-mapped” shape into a fixed number of radial divisions, the proceeding sampling operator should repeat nnn times in the domain [0,2π][0, 2\pi][0,2π] (i.e. 360°) along the Y axis. This is particularly suited to lattice operators as they tile a given unit cell infinitely along each axis.
‣
Example

Loads in a scalar field cached onto a grid.

from metafold.func import GenerateSamplePoints, TransformCylindricalCoords
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0),
        "size": np.full(3, 20),
        "resolution": np.full(3, 128) 
    }
)

transformed_pts = TransformCylindricalCoords(source, {"radial_scale": 4})
‣

TransformMirrorCoords

Apply a mirror transformation to the input points. This operator mirrors points across a specified plane in 3D space. When used as input to a sample function for shape creation, it enables the creation of symmetrical shapes across a plane. This technique is useful for creating mirrored versions of existing structures.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Vec3f function

‣
Parameters
Parameter
Type
Description
xform
Mat4f
Affine transformation matrix applied to points before the mapping occurs. Defaults to identity matrix.
mirror_normal
Vec3f
Normal vector of mirror plane in world coordinates. Defaults to [0.0, 0.0, 1.0].
mirror_point
Vec3f
Position of the mirror plane in 3D space. Defaults to origin [0.0, 0.0, 0.0].
OffOff
Off
OnOn
On
‣
Example

Loads in a scalar field cached onto a grid.

from metafold.func import GenerateSamplePoints, TransformMirrorCoords
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

transformed_pts = TransformMirrorCoords(source, {"reflection": 0})
‣

TransformSphericalCoords

Apply a spherical mapping to the input points. This operator transforms points into a spherical coordinate system. When used as input to a sample function for shape creation, it introduces controlled curvature to the shape in all directions. This technique is particularly powerful for creating spherical or radially symmetric structures and manipulating objects in a spherical space.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Vec3f function

‣
Parameters
Parameter
Type
Description
xform
Mat4
Affine transformation matrix applied to points before the mapping occurs. Defaults to identity matrix.

Divisions

22
2
33
3
44
4
55
5
66
6
💡
Advanced Tip In order to divide the “spherically-mapped” shape into a fixed number of divisions, the proceeding sampling operator should repeat nnn times in the domain [0,π][0, \pi][0,π] (180°) along the Y axis and in the domain [0,2π][0, 2\pi][0,2π] (360°) along the Z axis. This is particularly suited to lattice operators as they tile a given unit cell infinitely along each axis.
‣
Example

Loads in a scalar field cached onto a grid.

from metafold.func import GenerateSamplePoints, TransformSphericalCoords
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

transformed_pts = TransformSphericalCoords(source)
‣

TransformTwistCoords

Apply a twisting transformation to the input points. This operator rotates points around a specified axis. When used as input to a sample function for shape creation, it introduces a controlled spiral or helical deformation to the shape. This technique is particularly powerful for creating twisted structures or adding rotational effects to existing geometries.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Vec3f function

‣
Parameters
Parameter
Type
Description
axis
String
String representing the main axis of rotation. "X" , "Y" , "Z" . Defaults to "X".
frequency
Float
Approximate number of rotations. Defaults to 1.0

Frequency

-20-20
-20
-13.333-13.333
-13.333
-6.667-6.667
-6.667
00
0
6.6676.667
6.667
13.33313.333
13.333
2020
20
‣
Example

Force the input points to twist about x = 0.

from metafold.func import GenerateSamplePoints, TransformTwistCoords
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

transformed_pts = TransformTwistCoords(source, {"frequency": 3.0})

Sample Operators

‣

MapTexturePrimitive

Generates a perturbation to distort the 0-level sets of shapes. By remapping input points into u, v image space according to a primitive mapping type the new coordinates are used to sample a grayscale texture. The result is a scalar field defined at all points on the grid. When combined with LinearFilter, it creates a texture-mapped surface effect. The mapping allows for precise control over how the image is applied to the primitive shape, enabling complex surface details and patterns. For a comprehensive guide on implementing this technique, refer to our detailed tutorial on texture mapping.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
image (Required)
Float function
Instance of a LoadVolume operator whose VolumeAsset references they.bin file created bt convert_image_to_height_map() .
‣
Type

Float function

‣
Parameters
Parameter
Type
Description
box_width
Vec3f
Used only for "Box" mapping. Creates a rectangular mapping with the given dimensions. Defaults to [1.0, 1.0, 1.0].
scale
Vec2f
Scale of the mapping u, v mapping. Defaults to [1.0, 1.0].
shape_type
String
String Enum representing the mapping. Defaults to "Box".
shape_xform
Mat4f
Affine transformation applied to the underlying primitive. Defaults to identity matrix.
xform
Mat4f
Affine transformation applied to the input points before mapping. Defaults to identity matrix.
‣
Example

See tutorial on mapping textures.

‣
Related Functions

LinearFilter

‣

SampleBox

Sample a primitive shape at the given sample points.

This operator allows users to create common 3D shapes (what we call primitives) for their design needs. Each call allows users to create a single shape that is defined by it’s 0-level of it’s implicit scalar function definition. The primitives here serve as the bedrock for more complicated projects within the Metafold environment. When combined with CSG operations users can define complex geometries for their needs through combining primitives with other sample operators.

A list of all the current available primitives can be found here.

⚠️
The primitives defined by this operator are centered at the origin [0, 0, 0], unlike the other operators that specify a box using minimum corner and size/extents.
‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Float function

‣
Parameters
Parameter
Type
Description
xform
Mat4
Affine transformation matrix. Defaults to identity matrix.
size
Vec3
Primitive box size. Defaults to [0, 0, 0].
shape_type
String
The type of shape. Defaults to Box. All options: "Box", "BoxFrame", "CappedCone", "Capsule" "Cylinder", "Ellipsoid", "Link", "Plane", "Torus"

Shape Types

BoxBox
Box
BoxFrameBoxFrame
BoxFrame
CappedConeCappedCone
CappedCone
CapsuleCapsule
Capsule
CylinderCylinder
Cylinder
EllipsoidEllipsoid
Ellipsoid
LinkLink
Link
PlanePlane
Plane
TorusTorus
Torus
‣
Example

Create a 10x10x10 box rotated 30 degrees about its x-axis

‣

SampleBeam

Sample a complete description of a line network. A line network consists of nodes and edges that define a graph, which can be connected or disconnected. This operator enables sampling and manipulation of line networks, offering customization options similar to those in the SampleLattice operator. Users can adjust various parameters to modify the network's properties and appearance.

This powerful tool allows input of complete beam structures built externally, rather than relying on a unit cell-based definition as in SampleLattice. To optimize line network evaluation, we use a BVH structure. This structure must be created before using this operator by running a create_bvh_from_network_file() job.

The .json file containing the line network must have two fields: "nodes" and "edges". The following example demonstrates how to define a BCC lattice using this format.

{
    "nodes": [
        [0., 0., 0.],
        [1., 0., 0.],
        [0., 1., 0.],
        [1., 1., 0.],
        [1., 0., 1.],
        [0., 1., 1.],
        [1., 1., 1.],
        [.5, .5, .5] 
    ], 
    "edges": [
        [0, 8],
        [1, 8],
        [2, 8],
        [3, 8],
        [4, 8],
        [5, 8],
        [6, 8],
        [7, 9]
    ]
}
‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Assets
Name
Type
Description
bvh_data (Required)
LineNetworkBvhAsset
Structured reference to a .bvh file created by the job create_bvh_from_network_file() .
network_data (Required)
LineNetworkAsset
Structured reference to a .json file detailing the list of nodes and edges in the line network. The json file must be populated by two fields. - nodes : a list of 3D points. - edges : a list of 2D arrays describing the connections between points.
‣
Output

Float function

‣
Parameters
Parameter
Type
Description
node_type
String
String enum referencing the spape of lattice nodes. Defaults to "None".
node_radius
Float
Radius of lattice nodes relative to unit cell. Defaults to 0.1.
section_radius
Float
Radius of lattice beam cross sections relative to unit cell. Defaults to 0.05.
section_type
SampleLattice_Enum_section_type
Shape of lattice beam cross sections. Defaults to "Circle".
smoothing
Float
Width to smooth joints between nodes and beams by. Defaults to 0.
xform
Mat4f
Affine transformation matrix for the lattice. Defaults to identity matrix.
‣
Example

Import and sample a custom line network. See Handling Assets using the SDK for a detailed guide on how to handle and create LineNetworkAsset and LineNetworkBvhAsset assets.

‣

SampleCustomShape

SampleCustomShape allows power users to create novel shapes using GLSL shader code. By attaching a SPIRV compiled binary describing a 3D shape, this operator samples it and adds it to your project. This functionality is particularly useful for advanced users who want to:

  1. Create complex, mathematically-defined shapes that are not easily achievable with standard primitives.
  2. Optimize performance for specific shape calculations.
  3. Experiment with procedural shape generation within the Metafold ecosystem.

In order to make use of this tool a user only needs to write GLSL shader code. The job compile_custom_shape() takes this code and converts it to a SPIRV compiled binary digestible by our backend.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Assets
Name
Type
Description
shader_data (Required)
CustomShapeAsset
Structured reference to a .spv file created by the job compile_custom_shape() .
‣
Output

Float function

‣
Parameters
Parameter
Type
Description
xform
Mat4f
Affine transformation matrix for the custom shape. Defaults to identity matrix.
‣
Example

Sample a custom 3D object. See Handling Assets using the SDK for a detailed guide on how to handle and create assets like CustomShapeAsset .

‣

SampleTriangleMesh

Triangle meshes are a widely used representation for 3D geometry. This powerful tool enables you to seamlessly convert triangle mesh geometry into a Metafold implicit representation. By doing so, you can leverage Metafold's advanced capabilities for manipulating and analyzing complex 3D shapes within the implicit framework.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Assets
Name
Type
Description
mesh_data (Required)
TriangleMeshAsset
Structured reference to a triangle mesh. Accepts most common triangle mesh formats.
‣
Output

Float function.

‣
Parameters
Name
Type
Description
cw_winding
Int
Winding order of mesh triangles. Defaults to counter clockwise. 0: Counter Clockwise 1: Clockwise
xform
Mat4f
Affine transformation matrix applied to triangle mesh.
‣
Example

Convert a triangle mesh to a metafold implicit.

‣

SampleLattice

Lattices are formed by infinitely repeating unit cells in all directions. This operator samples beam lattices on a grid specified by GenerateSamplePoints, creating a lattice block that matches the size of the aforementioned operator.

Unit cells are defined via the UnitCell class. They consist of an array of nodes and edges. See below for an example of a BCC unit cell.

Two powerful sets of parameters for lattices are scale_grading_* and section_grading_*. Scale and Section Grading are techniques used to vary the properties of a lattice structure across its volume:

  • Scale Grading varies the unit cell scale of the lattice across the structure.
  • Section Grading varies the cross-sectional properties of lattice beams.

These grading techniques enable the creation of lattice structures with varying properties, which can optimize performance, weight distribution, or other design objectives.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Float function.

‣
Parameters
Parameter
Type
Description
lattice_data (Required)
UnitCell
Dictionary with the following keys: nodes: Positions of lattice nodes. edges: Connectivity of lattice nodes. No default.
node_type
String
Shape of lattice nodes. Defaults to "None". All types: "None", "Sphere"
node_radius
Float
Radius of lattice nodes relative to unit cell. Defaults to 0.1.
scale
Vec3f
Unit cell scale. Defaults to [1.0, 1.0, 1.0].
scale_grading_range
Vec2f
Distances of ScaleGrading scalar field to grade between. Defaults to zero vector.
scale_grading_scale
Vec2f
Scaling to apply to upper/lower grading limits. Defaults to zero vector.
section_radius
Float
Radius of lattice beam cross sections relative to unit cell. Defaults to 0.05.
section_type
String
Shape of lattice beam cross sections. Defaults to "Circle". All types: "Box", "Circle", "Cross”
section_radius_grading_range
Vec2f
Distances of SectionRadiusGrading scalar field to grade between. Defaults to zero vector.
section_radius_grading_scale
Vec2f
Scaling to apply to upper/lower grading limits. Defaults to zero vector.
smoothing
Float
Width to smooth joints between nodes and beams by. Defaults to 0.
xform
Mat4f
Affine transformation matrix for the lattice. Defaults to identity matrix.

Lattice Types

bcu-xbcu-x
bcu-x
bixbix
bix
body-centered cubicbody-centered cubic
body-centered cubic
dpedpe
dpe
epnepn
epn
eppepp
epp
face-centered cubicface-centered cubic
face-centered cubic
fcbfcb
fcb
iac-diac-d
iac-d
nbo-anbo-a
nbo-a
ocuocu
ocu
pdbpdb
pdb
rhrrhr
rhr
sqc2595sqc2595
sqc2595
sqc3050sqc3050
sqc3050
sqc7060sqc7060
sqc7060
sqc8562sqc8562
sqc8562
sqc9030sqc9030
sqc9030
sqc9046sqc9046
sqc9046
sqc10906sqc10906
sqc10906
sqc10948sqc10948
sqc10948
sqc11615sqc11615
sqc11615
sqc12124sqc12124
sqc12124
sqc13545sqc13545
sqc13545
sst-asst-a
sst-a
tbotbo
tbo
uriuri
uri
xafxaf
xaf
xblxbl
xbl
xbrxbr
xbr
xbrxbr
xbr

Section Types

BoxBox
Box
CircleCircle
Circle
CrossCross
Cross

Section Radius

0.0250.025
0.025
0.0940.094
0.094
0.1620.162
0.162
0.2310.231
0.231
0.30.3
0.3

Node Radius

0.10.1
0.1
0.1750.175
0.175
0.250.25
0.25
0.3250.325
0.325
0.40.4
0.4

Scale

0.20.2
0.2
0.650.65
0.65
1.11.1
1.1
1.551.55
1.55
2.02.0
2.0
‣
Example

Create a 5x5x5 BCC unit cell to populate a 20x20x20 volume.

‣

SampleSpinodoid [Under Development]

Spinodoid structures enhance additive manufacturing by offering customizable, non-periodic designs with tunable anisotropic properties, improving material resilience and functional grading. This operator samples a spinodoid using the given parameters on a grid specified by GenerateSamplePoints, creating a spinodoid block.

Spinodoids are created via computing a Gaussian random field. The parameters of this operator adjust the sampling using to build the field. For deterministic results set seedto a specific value.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Float function.

‣
Parameters
Parameter
Type
Description
angles
Vec3f
Solid angles around the conical axes (e.g. x-, y-, and z-axis). These angles define the spread of wave vectors that shape the underlying Gaussian random field (GRF), which represents the spinodoid topology. All angles must be in {x : 0 or [0.25, pi / 4]}. With at least one angle being non-zero..
density
Float
The relative amount of solid material versus void in the structure. The limit are as follows, for: - anisotropic (angles are different)[0.3, 1,0] - isotropic (angles are the same) [0.16, 1.0]
wave_count
Int
Positive integer that defines the terms in the Fourier series for computing the gaussian random field. Defaults to: 100
seed
Int
Random seed. Set to a specific value for deterministic (repeatable) results. Random by default.
xform
Mat4f
Affine transformation matrix for the lattice. Defaults to identity matrix.
‣
Example

Create a lamellar style spinodoid block in a 20x20x20 volume. Here we scale the spinodoid uniformly in x, y, z by 0.5 units.

‣

SampleSurfaceLattice

image

Lattices are formed by infinitely repeating unit cells in all directions. This operator samples surface lattices on a grid specified by GenerateSamplePoints, creating a lattice block that matches the size of the aforementioned operator. See a list of predefined surface lattices here.

Two powerful sets of parameters for lattices are scale_grading_* and section_grading_*. Scale and Section Grading are techniques used to vary the properties of a lattice structure across its volume:

  • Scale Grading varies the unit cell scale of the lattice across the structure.
  • Section Grading varies the cross-sectional properties of lattice beams.

These grading techniques enable the creation of lattice structures with varying properties, which can optimize performance, weight distribution, or other design objectives.

‣
Input
Name
Type
Description
points (Required)
Vec3f function
Source or transform operator representing point coordinates.
‣
Output

Float function

‣
Parameters
Parameter
Type
Description
lattice_type
String
Type of surface lattice. Defaults to "Gyroid" . Other options are listed here.
scale
Vec3f
Unit cell scale. Defaults to [1.0, 1.0, 1.0].
scale_grading_range
Vec2f
Distances of ScaleGrading scalar field to grade between. Defaults to zero vector.
scale_grading_scale
Vec2f
Scaling to apply to upper/lower grading limits. Defaults to zero vector.
threshold
Float
Value of the zero level set. Defaults to 0.
threshold_grading_range
Vec2f
Distances of ThresholdGrading scalar field to grade between. Defaults to zero vector.
threshold_grading_scale
Vec2f
Offset to apply to upper/lower grading limits. Defaults to zero vector.
xform
Mat4f
Affine transformation matrix. Defaults to identity matrix.

Lattice Types

C_YC_Y
C_Y
CDCD
CD
CI2YCI2Y
CI2Y
CPCP
CP
CPM_YCPM_Y
CPM_Y
CSCS
CS
DD
D
FF
F
FRDFRD
FRD
GyroidGyroid
Gyroid
I2YI2Y
I2Y
IWPIWP
IWP
PP
P
PM_YPM_Y
PM_Y
SS
S
SchwarzSchwarz
Schwarz
SchwarzDSchwarzD
SchwarzD
SchwarzNSchwarzN
SchwarzN
SchwarzPWSchwarzPW
SchwarzPW
SchwarzWSchwarzW
SchwarzW
SD1SD1
SD1
WW
W
YY
Y

Threshold

-1.0-1.0
-1.0
-0.5-0.5
-0.5
0.00.0
0.0
0.50.5
0.5
1.01.0
1.0

Scale

0.20.2
0.2
0.650.65
0.65
1.11.1
1.1
1.551.55
1.55
2.02.0
2.0
‣
Example

Create a 5x5x5 Schwarz unit cell in a 20x20x20 volume.

from metafold.func import GenerateSamplePoints, SampleSurfaceLattice


source = GenerateSamplePoints(
    {
        "offset": [10.0, 10.0, 10.0],
        "size": [20.0, 20.0, 20.0],
        "resolution": [128, 128, 128], 
    }
)

schwarz_volume = SampleSurfaceLattice(
    source,
    {
        "lattice_type": "Schwarz",
        "scale": [5, 5, 5]
    }
)
‣

SampleVolume

Given a volume of whether this operator samples that volume at specific points. This is very useful when combined with the LoadVolume operator. LoadVolume connects a volume asset to the backend but does not make it usable as is. To bring the volume into the Metafold computation space it must be sampled on the grid of points you are using for your project (see GenerateSamplePoints).

This operator can be used to sample 1D, 2D, and 3D dimensional arrays from LoadVolume .

‣
Inputs
Name
Type
Description
points (Required)
Vec3f function
Metafold source operator representing the sample point locations.
volume (Required)
Float function, Vec2f function, Vec3f function, Vec4f function
A Metafold operator representing the volume of interest.
‣
Output

Float function

‣
Parameters
Name
Type
Description
volume_size (Required)
Vec3f
Extents of the volume. Defaults to [0.0, 0.0, 0.0].
volume_offset
Vec3f
New position of grid origin. Defaults to [0.0, 0.0, 0.0].
xform
Mat4f
Affine transformation matrix applied to points before sampling. Defaults to identity matrix.
‣
Example

Reamples a stored volume that is contained in a 25^3 cube.

‣
Related Operators

SampleVolume, MapTexturePrimitive, ComputeNormals

Filter Operators

‣

CSG

Constructive Solid Geometry (CSG) operations are powerful tools in 3D modeling and computer-aided design. They allow for complex shapes to be created by combining simpler primitive shapes using boolean operations. The three main types of CSG operations are:

  • "Union": Combines two shapes into a single object
  • "Intersect": Creates a new shape from the overlapping portions of two objects
  • "Subtract": Removes one shape from another

The power and usefulness of CSG operations lie in their ability to:

  • Create complex geometries quickly and efficiently
  • Simplify the design process for intricate parts
‣
Input
Name
Type
Description
Aa (Required)
Float function
An operator representing the volume of interest.
Bb (Required)
Float function
An operator representing the volume of interest.
‣
Output

Float function

‣
Parameters
Name
Type
Description
operation
String
Type of CSG operation to apply. Defaults to "Union". Other operations: "Intersect", "Subtract" , "Union" When using "Subtract", input A is subtracted from input B.
smoothing
Float
Width of smooth CSG function by. Defaults to 0.0.

Operation

UnionUnion
Union
SubtractSubtract
Subtract
IntersectIntersect
Intersect
‣
Example

Union a box and a sphere.

‣

Shell

This operator creates a shell of a given thickness around the center of a level set given. The location of the level set is controlled by the offset parameter.

There are many creative and powerful ways to employ the Shell operator within the Metafold environment. The most common use is to make volumes hollow.

‣
Input
Name
Type
Description
samples (Required)
Float function
An operator representing the volume of interest.
‣
Output

Float function

‣
Parameters
Parameter
Type
Description
offset
Float
Value at which the shell is centered.
thickness
Float
Thickness of the shell.

Thickness

0.050.05
0.05
0.2120.212
0.212
0.3750.375
0.375
0.5370.537
0.537
0.70.7
0.7

Offset

0.10.1
0.1
0.00.0
0.0
-0.1-0.1
-0.1
‣
Example

Create a cube that is hollow inside and has a wall thickness of 2.0.

from metafold.func import GenerateSamplePoints, BoxPrimitive, Shell
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -100.0)
        "size": np.full(3, 200)
        "resolution": np.full(3, 512) 
    }
)

shelled_box = Shell(
    BoxPrimitive(source, {"size": [50, 50, 50]}),
    {"thickness": 2.0}
)
‣

LinearFilter

Metafold shapes are implicitly defined on a grid of points, such that their surface is the 0-level set of the implicit function. The LinearFilter allows you to combine two fields from different shapes to distort their 0-level set in a controlled manner by addition and scalar multiplication. The common use case is for mapping a texture to a surface. See Mapping Textures to Shapes here for a step by step guide.

‣
Input
Name
Type
Description
a (Required)
Float function
An operator representing the volume of interest.
b (Required)
Float function
An operator representing the volume of interest.
‣
Output

Float function

‣
Parameters
Parameter
Type
Description
scale_a
Float
Factor to multiply the values of a .
scale_b
Float
Factor to multiply the values of b .
‣
Example

See tutorial on mapping textures.

‣

Redistance

This operator computes an exact signed distance field from a given pseudo distance field. We recommend applying this filter to shapes prior to CSG operations to ensure accurate booleans. It is also typically appended to the end of shape functions so that we can be sure the shape function is generating an exact SDF. For more details, see Redistancing: What is it and why is it important?

Within the Metafold backend shapes live as implicit-fields, that are pseudo signed distance fields. Their surfaces are defined via their 0-level set. Some operators like SampleBox and SampleTriangleMesh provide the true signed distances to the object at the time of evaluation. But once they are combined with other operators this guarantee no longer holds. In order to ensure we are working with true signed distance fields only, this operator should be appended to the end of all graphs that are evaluated. See <> for more details.

‣
Input
Name
Type
Description
samples (Required)
Float function
An operator representing the volume of interest.
‣
Output

Float function

‣
Parameters
Parameter
Type
Description
pre_offset
Float
Offset to apply before redistancing. Positive values result in an erosion and negative values result in a dilation. Defaults to: 0.
post_offset
Float
Offset to apply after redistancing. Positive values result in an erosion and negative values result in a dilation. Defaults to 0.
‣
Example

Apply apply a distance transform to a gyroid filled volume.

‣

Threshold

To export a graph, this operator must be appended to the end. It compresses the graph's final output by remapping all sample values from the underlying implicit scalar field to the range [-1, 1]. Sample values with an absolute value exceeding the specified width are clamped to -1 or 1, depending on whether they are inside or outside the volume. The remapped values are then packed, with each float being represented as a single byte. Export functions, such as export_triangle_mesh(), require binary files in this format."

‣
Input
Name
Type
Description
samples (Required)
Float function
A Metafold operator representing the volume of interest.
‣
Output

Bytes function

‣
Parameters
Parameter
Type
Description
width
Float
Width of the range on either size of zero.
‣
Example

Apply apply a threshold to a gyroid filled volume to later be exported as a triangle mesh.

Assets

Assets are handled using a Python dictionary or Javascript object. Each asset class has a field path where a user references the file containing the asset.

# ...

triangle_mesh_path = "path/to/mesh"
line_network_asset = TriangleMeshAsset()
line_network_asset["path"] = triangle_mesh_path

f = SampleTriangleMesh(source, mesh_data=line_network_asset)

# ...
# ...

metafold = MetafoldClient(access_token, project_id)

# Symbolic representation.
source = GenerateSamplePoints(
    {
        "offset": [-60, -60, -60],
        "size": [120, 120, 120],
        "resolution": [512, 512, 512]
    }
)

# Convert representation to json format which is consumable by the backend.
source_graph = JSONEvaluator()
source(source_graph)
evaluation = metafold.jobs.run("evaluate_graph", {"graph": source_graph.json()})

# Download the created asset.
metafold.assets.download_file(evaluation.assets[0].id, "grid_points.bin")

# Load the results. This is an explicit, discretized representation of the shape.
grid_points = np.fromfile("grid_points.bin", dtype=np.float32)

# Print the first grid point.
print(grid_points[0:3])
# np.array([-60., -60., -60.])
from metafold.func import GenerateSamplePoints, ComputeNormals, CylinderPrimitive
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": [-10.0, -10.0, -10.0],
        "size": [20, 20, 20],
        "resolution": [128, 128, 128]
    }
)
cylinder = CylinderPrimitive(source, {"size": [5, 5, 10]})
normals = ComputeNormals(
    source, 
    cylinder,
    {
        "volume_size": [20, 20, 20]
    }
)
from metafold.func import GenerateSamplePoints, SampleBox
from metafold.utils import xform
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0),
        "size": np.full(3, 20),
        "resolution": np.full(3, 128),
    }
)

# We can create an affine transform by defining the euler angles 
# in a ArrayLike object.
rotation = [30.0, 0.0, 0.0]
xform = xform(rotation)
transformed_pts = TransformSphericalCoords(
    source, 
    {
        "shape_type": "Box",
        "xform": xform,
        "size": [10.0, 10.0, 10.0]
    }
)
from metafold.func import GenerateSamplePoints, SampleBeam
from metafold.func_types import LineNetworkBvh, LineNetworkBvhAsset
import numpy as np

network_path = "path/to/line_network/in/cloud/network.json"
network_asset = LineNetworkAsset()
network_asset["path"] = network_path

network_bvh_path = "path/to/mesh/in/cloud/mesh.ply"
network_bvh_asset = LineNetworkBvhAsset()
network_bvh_asset["path"] = network_bvh_path

source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0),
        "size": np.full(3, 20),
        "resolution": np.full(3, 128) 
    }
)

line_network = SampleBeam(
    source,
    network_asset,
    network_bvh_asset
)
from metafold.func import GenerateSamplePoints, SampleCustomShape
from metafold.func_types import CustomShapeAsset
import numpy as np

spv_path = "path/to/spirv_binary/in/cloud/shader.spv"
spv_asset = CustomShapeAsset()
spv_asset["path"] = spv_path

source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0),
        "size": np.full(3, 20),
        "resolution": np.full(3, 128) 
    }
)

custom_shape = SampleCustomShape(
    source,
    spv_asset
)
from metafold.func import GenerateSamplePoints, SampleTriangleMesh
from metafold.func_types import TriangleMeshAsset

triangle_mesh_path = "path/to/mesh/in/cloud/mesh.ply"
triangle_mesh_asset = TriangleMeshAsset()
triangle_mesh_asset["path"] = triangle_mesh_path

source = GenerateSamplePoints(
    {
        "offset": [-10.0, -10.0, -10.0],
        "size": [20.0, 20.0, 20.0],
        "resolution": [128, 128, 128] 
    }
)

implicit_mesh = SampleTriangleMesh(
    source,
    triangle_mesh_asset
)
from metafold.func import GenerateSamplePoints, SampleLattice
from metafold.func_types import UnitCell
import numpy as np

unit_cell = UnitCell()
unit_cell["nodes"] = [
    [0., 0., 0.],
    [1., 0., 0.],
    [0., 1., 0.],
    [1., 1., 0.],
    [1., 0., 1.],
    [0., 1., 1.],
    [1., 1., 1.],
    [.5, .5, .5] 
]
unit_cell["edges"] = [
    [0, 8],
    [1, 8],
    [2, 8],
    [3, 8],
    [4, 8],
    [5, 8],
    [6, 8],
    [7, 9]
]
source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

bcc_volume = SampleLattice(
    source,
    {
        "lattice_data": unit_cell,
        "scale": [5, 5, 5]
    }
)
from metafold.func import GenerateSamplePoints, SampleSpinodoids
from metafold.utils import xform
import numpy as np

source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

lamellar_volume = SampleSpinodoid(
    source,
    {
        "xform": xform(scale=[0.5, 0.5, 0.5]),
        "angles": [0.0, 0.0, 0.25],
        "density": 0.5
    }
)
from metafold.func import GenerateSamplePoints, LoadVolume, SampleVolume
from metafold.func_types import VolumeAsset
import numpy as np

volume_path = "path/to/binary/in/cloud/volume.bin"
volume_asset = VolumeAsset()
volume_asset["path"] = volume_path

volume = LoadVolume(
    volume_asset,  
    {
        "component_type"
        "resolution": [128, 128, 128]
    }
)

source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 64) 
    }
)

resampled_volume = SampleVolume(
    source,
    volume, 
    {
        "volume_size": [25.0, 25.0, 25.0]
    }
)
from metafold.func import (
    GenerateSamplePoints, BoxPrimitive, 
    SpherePrimitive, CSG, xform
)
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

box_params = {
    "size": [10, 10, 10],
    "xform": xform(translation=[0, 0, 5])
}

sphere_params = {
    "size": [10, 10, 10]
}

 unioned_shapes = CSG(
     BoxPrimitive(source, box_params), 
     ElipsoidPrimitive(source, sphere_params),
    {
        "operation": "Union",
    }
))
from metafold.func import GenerateSamplePoints, SampleSurfaceLattice, Redistance
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

true_gyroid_volume = Redistance(SampleSurfaceLattice(
    source,
    {
        "lattice_type": "Gyroid",
        "scale": [5, 5, 5]
    }
))
from metafold.func import GenerateSamplePoints, SampleSurfaceLattice, Threshold
import numpy as np


source = GenerateSamplePoints(
    {
        "offset": np.full(3, -10.0)
        "size": np.full(3, 20)
        "resolution": np.full(3, 128) 
    }
)

snorm_gyroid_volume = Threshold(SampleSurfaceLattice(
    source,
    {
        "lattice_type": "Gyroid",
        "scale": [5, 5, 5]
    }
))