48 lines
908 B
Python
48 lines
908 B
Python
|
|
import bpy
|
||
|
|
import sys
|
||
|
|
import os
|
||
|
|
|
||
|
|
argv = sys.argv
|
||
|
|
argv = argv[argv.index("--") + 1:]
|
||
|
|
|
||
|
|
glb_input = argv[0]
|
||
|
|
obj_output = argv[1]
|
||
|
|
|
||
|
|
|
||
|
|
def clean():
|
||
|
|
bpy.ops.object.select_all(action='SELECT')
|
||
|
|
bpy.ops.object.delete(use_global=False)
|
||
|
|
|
||
|
|
|
||
|
|
clean()
|
||
|
|
|
||
|
|
bpy.ops.import_scene.gltf(filepath=glb_input)
|
||
|
|
|
||
|
|
meshes = [o for o in bpy.context.scene.objects if o.type == "MESH"]
|
||
|
|
|
||
|
|
if not meshes:
|
||
|
|
raise RuntimeError("No mesh objects found in GLB/GLTF.")
|
||
|
|
|
||
|
|
bpy.ops.object.select_all(action='DESELECT')
|
||
|
|
|
||
|
|
for o in meshes:
|
||
|
|
o.select_set(True)
|
||
|
|
|
||
|
|
bpy.context.view_layer.objects.active = meshes[0]
|
||
|
|
|
||
|
|
if len(meshes) > 1:
|
||
|
|
bpy.ops.object.join()
|
||
|
|
|
||
|
|
obj = bpy.context.view_layer.objects.active
|
||
|
|
obj.select_set(True)
|
||
|
|
|
||
|
|
os.makedirs(os.path.dirname(obj_output), exist_ok=True)
|
||
|
|
|
||
|
|
bpy.ops.wm.obj_export(
|
||
|
|
filepath=obj_output,
|
||
|
|
export_selected_objects=True,
|
||
|
|
export_normals=True,
|
||
|
|
export_uv=True,
|
||
|
|
)
|
||
|
|
|
||
|
|
print("OBJ exported:", obj_output)
|