import pytest
import time
from tests.integration.conftest import send_command
def test_real_voxel_remesh(real_blender_connection):
"""
Test voxel remeshing on a real object.
1. Create a UV Sphere (more complex than cube)
2. Voxel remesh it
3. Verify topology changed
"""
# 1. Setup: Create a UV Sphere
setup_code = """
import bpy
print("Clearing scene with bpy.data...")
# robustly delete all objects
for obj in bpy.data.objects:
bpy.data.objects.remove(obj, do_unlink=True)
print("Adding UV Sphere...")
bpy.ops.mesh.primitive_uv_sphere_add(segments=32, ring_count=16)
if bpy.context.object:
bpy.context.view_layer.objects.active = bpy.context.object
print(f"Created active object: {bpy.context.active_object.name}")
"""
send_command(real_blender_connection, "execute_code", {"code": setup_code, "confirm": True})
# Debug: Get scene info
scene_info = send_command(real_blender_connection, "get_scene_info")
print(f"Scene Info: {scene_info}")
# Get initial stats
initial_stats = send_command(real_blender_connection, "mesh_stats", {"active_only": True})
initial_count = initial_stats["result"]["stats"]["face_count"]
print(f"Initial face count: {initial_count}")
# 2. Execute Voxel Remesh
# Voxel size 0.1 should result in a different topology
# Default UV sphere is radius 1.0, so 0.1 is small enough to create many voxels
response = send_command(real_blender_connection, "remesh_voxel", {
"voxel_size": 0.1,
"adaptivity": 0.0,
"preserve_volume": True
})
assert response["status"] == "success"
# 3. Verify Result
final_stats = send_command(real_blender_connection, "mesh_stats", {"active_only": True})
final_count = final_stats["result"]["stats"]["face_count"]
print(f"Final face count: {final_count}")
# Face count should change significantly
assert final_count != initial_count
assert final_count > 0
def test_real_decimate(real_blender_connection):
"""
Test decimation on a real object.
1. Create a UV Sphere
2. Decimate it to 50%
3. Verify face count reduced
"""
# 1. Setup: Create a UV Sphere
setup_code = """
import bpy
print("Clearing scene with bpy.data...")
for obj in bpy.data.objects:
bpy.data.objects.remove(obj, do_unlink=True)
print("Adding UV Sphere...")
bpy.ops.mesh.primitive_uv_sphere_add(segments=32, ring_count=16)
if bpy.context.object:
bpy.context.view_layer.objects.active = bpy.context.object
"""
send_command(real_blender_connection, "execute_code", {"code": setup_code, "confirm": True})
# Get initial stats
initial_stats = send_command(real_blender_connection, "mesh_stats", {"active_only": True})
initial_count = initial_stats["result"]["stats"]["face_count"]
print(f"Initial face count: {initial_count}")
# 2. Execute Decimate (50% ratio)
response = send_command(real_blender_connection, "decimate", {
"ratio": 0.5
})
assert response["status"] == "success"
# 3. Verify Result
final_stats = send_command(real_blender_connection, "mesh_stats", {"active_only": True})
final_count = final_stats["result"]["stats"]["face_count"]
print(f"Final face count: {final_count}")
# Should be roughly 50% of initial (allow some tolerance)
expected_count = initial_count * 0.5
tolerance = initial_count * 0.2 # 20% tolerance
print(f"Expected: {expected_count} +/- {tolerance}")
assert abs(final_count - expected_count) < tolerance