02-Surface Lattice

02-Surface Lattice

"""Example script demonstrating generating sample lattice and calculating the realtive denisty and exporting as an STL file 


For more details on the available job types please refer to the Metafold REST API
documentation.
"""
import pandas as pd
import numpy as np
import os
import csv
from numpy.typing import ArrayLike
from pprint import pprint
from scipy.spatial.transform import Rotation as R
from metafold import MetafoldClient
from metafold.func_types import JSONEvaluator, FuncType, Vec3f, Mat4f
from metafold.func import *


project_id = 5701
access_token = "  "
client=MetafoldClient(access_token,project_id)




source = GenerateSamplePoints(       
                              {"offset": [
                                        -15,
                                        -15,
                                        0
                                        ],
                                        "size": [
                                        30,
                                        30,
                                        30
                                        ],
                                        "resolution": [
                                        128,
                                        128,
                                        128
                                        ]
                              }
                            )



shape_func= Threshold(
                Redistance(
                            SampleSurfaceLattice(
                                PointSource,
                                {
                                    "lattice_type": "Gyroid",
                                    "scale": [10, 10 , 10],
                                    "threshold": 0.0,
                                },
                            ),                
                            ),
                {
                    "width": 0.03,
                },
            )      

evaluator = JSONEvaluator(source) 
shape_func(evaluator)
graph_json=evaluator.json()
job= client.jobs.run("evaluate_metrics", {"graph": graph_json, "point_source": 0})
pprint((job.meta["relative_density"]))

export_job = client.jobs.run("export_triangle_mesh", {
        "graph": graph_json,
        "point_source": 0,
    })
export_asset = export_job.assets[0].id
client.assets.download_file(export_asset, "Gyroid.stl")