Files
simple_blender_server/main.py.tmpl

44 lines
1013 B
Cheetah

import bpy # type: ignore
{{.ModelCode}}
def guarded_model() -> bpy.types.Object:
try:
out = model() # type: ignore
if out is None:
raise TypeError("Function `model` cannot return type `None`.")
return out
except NameError:
raise NotImplementedError("No function named `model` was provided!")
def export_to_glb(obj: bpy.types.Object):
"""
Export a Blender object as a GLB binary blob.
Parameters:
obj (bpy.types.Object): The object to export
"""
# Ensure the object is the only object, is selected, and is active
bpy.ops.object.select_all(action="SELECT")
obj.select_set(False)
bpy.ops.object.delete()
obj.select_set(True)
bpy.context.view_layer.objects.active = obj
bpy.ops.export_scene.gltf(
filepath="{{.Filename}}",
export_format="GLB",
export_draco_mesh_compression_enable=True,
export_apply=True,
)
def main():
export_to_glb(guarded_model())
main()