From a0a6371c29eb58eda18f6551cc22d70b713e007c Mon Sep 17 00:00:00 2001 From: MayaTheShy Date: Sat, 8 Nov 2025 23:11:47 -0500 Subject: [PATCH] feat: enhance export process by improving object deletion and output messages --- tools/blender_export_primitives.py | 41 ++++++++++++++++++++---------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/tools/blender_export_primitives.py b/tools/blender_export_primitives.py index 6ef14dd..21a4697 100644 --- a/tools/blender_export_primitives.py +++ b/tools/blender_export_primitives.py @@ -3,7 +3,7 @@ import os # Clear existing objects bpy.ops.object.select_all(action='SELECT') -bpy.ops.object.delete() +bpy.ops.object.delete(use_global=False) # Output directory output_dir = os.path.expanduser("~/.cache/starworld/primitives") @@ -33,54 +33,69 @@ def create_material(name, base_color): return mat +print("Creating GREEN sphere...") # Create and export UV Sphere with GREEN material bpy.ops.mesh.primitive_uv_sphere_add(segments=32, ring_count=16, radius=0.5, location=(0, 0, 0)) sphere = bpy.context.active_object sphere.name = "Sphere" +sphere.select_set(True) +bpy.context.view_layer.objects.active = sphere bpy.ops.object.shade_smooth() # Apply green material green_mat = create_material("SphereMaterial", (0.2, 1.0, 0.2, 1.0)) # Green sphere.data.materials.append(green_mat) +sphere_path = os.path.join(output_dir, "sphere.glb") bpy.ops.export_scene.gltf( - filepath=os.path.join(output_dir, "sphere.glb"), + filepath=sphere_path, export_format='GLB', use_selection=True ) -print(f"Exported sphere.glb (GREEN) to {output_dir}") +print(f"✓ Exported sphere.glb (GREEN) to {sphere_path}") +print("Creating RED cube...") # Delete sphere and create cube with RED material -bpy.ops.object.delete() +bpy.ops.object.delete(use_global=False) bpy.ops.mesh.primitive_cube_add(size=1.0, location=(0, 0, 0)) cube = bpy.context.active_object cube.name = "Cube" +cube.select_set(True) +bpy.context.view_layer.objects.active = cube bpy.ops.object.shade_smooth() # Apply red material red_mat = create_material("CubeMaterial", (1.0, 0.2, 0.2, 1.0)) # Red cube.data.materials.append(red_mat) +cube_path = os.path.join(output_dir, "cube.glb") bpy.ops.export_scene.gltf( - filepath=os.path.join(output_dir, "cube.glb"), + filepath=cube_path, export_format='GLB', use_selection=True ) -print(f"Exported cube.glb (RED) to {output_dir}") +print(f"✓ Exported cube.glb (RED) to {cube_path}") +print("Creating BLUE icosphere...") # Delete cube and create ico sphere for the "model" placeholder with BLUE material -bpy.ops.object.delete() +bpy.ops.object.delete(use_global=False) bpy.ops.mesh.primitive_ico_sphere_add(subdivisions=2, radius=0.5, location=(0, 0, 0)) ico = bpy.context.active_object ico.name = "IcoSphere" +ico.select_set(True) +bpy.context.view_layer.objects.active = ico bpy.ops.object.shade_smooth() # Apply blue material blue_mat = create_material("IcoSphereMaterial", (0.2, 0.2, 1.0, 1.0)) # Blue ico.data.materials.append(blue_mat) +model_path = os.path.join(output_dir, "model.glb") bpy.ops.export_scene.gltf( - filepath=os.path.join(output_dir, "model.glb"), + filepath=model_path, export_format='GLB', use_selection=True ) -print(f"Exported model.glb (BLUE) to {output_dir}") +print(f"✓ Exported model.glb (BLUE) to {model_path}") -print("\n✓ All primitive models with colors exported successfully!") -print(f" - RED Cube: {os.path.join(output_dir, 'cube.glb')}") -print(f" - GREEN Sphere: {os.path.join(output_dir, 'sphere.glb')}") -print(f" - BLUE IcoSphere: {os.path.join(output_dir, 'model.glb')}") +print("\n" + "="*60) +print("✓ ALL PRIMITIVE MODELS WITH COLORS EXPORTED SUCCESSFULLY!") +print("="*60) +print(f" RED Cube: {os.path.join(output_dir, 'cube.glb')}") +print(f" GREEN Sphere: {os.path.join(output_dir, 'sphere.glb')}") +print(f" BLUE IcoSphere: {os.path.join(output_dir, 'model.glb')}") +print("="*60)