CAD Functions

A CAD Function is reusable function designed to perform a specific task or operation related to CAD.

1. Compile an OpenSCAD Geometry

openscad_async(model: str)

Compile an OpenSCAD geometry asynchronously and return an STL file encoded as a base64 string.

Parameters:

  • model (str): The OpenSCAD model code as a string.

Returns:

  • A str representing the STL file encoded as a base64 string.

Example


stl = await openscad_async("""cube(10);""")
Run

2. Convert an STL model to GLB

convert_stl_to_glb_async(stl: str, r=100: int, g=100: int, b=100: int)

Convert an STL file encoded as a base64 string to a GLB file encoded as a base64 string.

Parameters:

  • stl (str): The STL file encoded as a base64 string.
  • r=100: The red channel value for the color of the model.
  • g=100: The green channel value for the color of the model.
  • b=100: The blue channel value for the color of the model.

Returns:

  • A str representing the GLB file encoded as a base64 string.

Example


import story

ctx = story.get_context()

viewer = ctx.model_viewer()

viewer = await viewer.init_async()

stl = await openscad_async("""
cube(10);
""")


glb = await convert_stl_to_glb_async(stl)


viewer.set_data(glb)
Run