Assets within the Metafold environment refer to all data that is created prior whether externally or internally to a main graph evaluation. This includes images, triangle meshes, 3D data and so on.
Name |
CustomShapeAsset |
LineNetworkAsset |
LineNetworkBvhAsset |
ParameterizationAsset |
MeshBvhAsset |
TriangleMeshAsset |
VolumeAsset |
Metafold is a cloud computation service and our SDK allows users to easily interact with our powerful backend kernel. All files live in the cloud connected to your specific project. This tutorial will walk you through:
- How to define assets and move data between your Metafold project and your local filesystem.
- How to connect assets to graphs for
evaluate_*()
jobs.
We will do this by walking through how to use the SampleBeam
operator.
Defining Assets
Assets are referenced within the SDK using key:value data structures (python dictionary or javascript objects) with a field "path"
. This field contains the path to the asset in the cloud.
To upload an asset into the cloud we use the MetafoldClient()
. Here we upload a lattice network into our project Metafold.
from metafold import MetafoldClient
from metafold.func import GenerateSamplePoints, SampleBeam
from metafold.func_types import (
LatticeNetworkAsset,
LineNetworkBvhAsset,
JSONEvaluator
)
filename = "beams.json"
metafold = MetafoldClient(access_token="...", project_id="...")
network_asset = metafold.assets.create(network_filename)
The metafold.assets.create("...")
returns a reference to the asset in the cloud. We can access the file name using network.filename
.
Sometime we run a script more than once. As a result the asset already exist in the cloud. A safer way to get a reference to a asset is through the following:
network_filename = "beams.json"
if existing := metafold.assets.list(q=f"filename:{network_filename}"):
network = metafold.assets.update(existing[0].id, network_filename)
else:
network = metafold.assets.create(network_filename)
Here we check if an asset exist in the cloud by the same name already and creates it only if it does not.
We now have a copy of our local asset in our project and a reference to it. We can now use it in a job to create a .bvh
file needed to evaluate the line network.
bvh_params = {
"network_filename": network_asset.filename,
"object_type": 0
}
bvh_job = metafold.jobs.run(
"create_bvh_from_network_file",
bvh_params
)
# The create_bvh_from_network_file returns a single asset that we can access
# as follows.
network_bvh = bvh_job.assets[0]
Building Shapes with Assets
Now we have references to two assets one that is a LineNetworkAsset
and another that is a line LineNetworkBvhAsset
, respectively. We need both to use within the SampleBeam
operator. To do so we create an instance of the two classes and with the appropriate filename.
network_asset = LineNetworkAsset()
network_asset["path"] = network.filename
network_bvh_asset = LineNetworkBvhAsset()
network_bvh_asset["path"] = network_bvh.filename
We can now build a shape with our line network and evaluate.
source = GenerateSamplePoints({
"size": [80, 80, 80],
"resolution": [256, 256, 256],
"offset": [-40, -40, -40],
})
shape = SampleBeam(
source,
bvh_data=networ_bvh_asset,
network_data=network_asset
)
lce_graph = JSONEvaluator()
shape (lce_graph)
eval_job = metafold.jobs.run(
"evaluate_graph",
{
"graph": lce_graph.json()
}
)