mirror of
https://github.com/Cian-H/simple_blender_server.git
synced 2025-12-22 21:41:56 +00:00
49 lines
1.0 KiB
Cheetah
49 lines
1.0 KiB
Cheetah
import bmesh
|
|
import bpy
|
|
import mathutils
|
|
import numpy
|
|
import scipy
|
|
import trimesh
|
|
|
|
|
|
{{.ModelCode}}
|
|
|
|
|
|
def guarded_model() -> bpy.types.Object:
|
|
try:
|
|
out = model()
|
|
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()
|