diff --git a/addon.py b/addon.py index 3e73095..2941627 100644 --- a/addon.py +++ b/addon.py @@ -231,12 +231,13 @@ class BlenderMCPServer: traceback.print_exc() return {"error": str(e)} - def create_object(self, type="CUBE", name=None, location=(0, 0, 0), rotation=(0, 0, 0), scale=(1, 1, 1)): + def create_object(self, type="CUBE", name=None, location=(0, 0, 0), rotation=(0, 0, 0), scale=(1, 1, 1), + align="WORLD", major_segments=48, minor_segments=12, mode="MAJOR_MINOR", + major_radius=1.0, minor_radius=0.25, abso_major_rad=1.25, abso_minor_rad=0.75, generate_uvs=True): """Create a new object in the scene""" # Deselect all objects bpy.ops.object.select_all(action='DESELECT') - # Create the object based on type if type == "CUBE": bpy.ops.mesh.primitive_cube_add(location=location, rotation=rotation, scale=scale) elif type == "SPHERE": @@ -248,7 +249,19 @@ class BlenderMCPServer: elif type == "CONE": bpy.ops.mesh.primitive_cone_add(location=location, rotation=rotation, scale=scale) elif type == "TORUS": - bpy.ops.mesh.primitive_torus_add(location=location, rotation=rotation, scale=scale) + bpy.ops.mesh.primitive_torus_add( + align=align, + location=location, + rotation=rotation, + major_segments=major_segments, + minor_segments=minor_segments, + mode=mode, + major_radius=major_radius, + minor_radius=minor_radius, + abso_major_rad=abso_major_rad, + abso_minor_rad=abso_minor_rad, + generate_uvs=generate_uvs + ) elif type == "EMPTY": bpy.ops.object.empty_add(location=location, rotation=rotation, scale=scale) elif type == "CAMERA": @@ -261,10 +274,10 @@ class BlenderMCPServer: # Get the created object obj = bpy.context.active_object - # Rename if name is provided + # Rename the object if a name is provided if name: obj.name = name - + return { "name": obj.name, "type": obj.type, @@ -272,7 +285,8 @@ class BlenderMCPServer: "rotation": [obj.rotation_euler.x, obj.rotation_euler.y, obj.rotation_euler.z], "scale": [obj.scale.x, obj.scale.y, obj.scale.z], } - + + def modify_object(self, name, location=None, rotation=None, scale=None, visible=None): """Modify an existing object in the scene""" # Find the object by name @@ -1256,4 +1270,4 @@ def unregister(): print("BlenderMCP addon unregistered") if __name__ == "__main__": - register() \ No newline at end of file + register() diff --git a/src/blender_mcp/server.py b/src/blender_mcp/server.py index 9828220..df7fcb3 100644 --- a/src/blender_mcp/server.py +++ b/src/blender_mcp/server.py @@ -271,7 +271,17 @@ def create_object( name: str = None, location: List[float] = None, rotation: List[float] = None, - scale: List[float] = None + scale: List[float] = None, + # Torus-specific parameters + align: str = "WORLD", + major_segments: int = 48, + minor_segments: int = 12, + mode: str = "MAJOR_MINOR", + major_radius: float = 1.0, + minor_radius: float = 0.25, + abso_major_rad: float = 1.25, + abso_minor_rad: float = 0.75, + generate_uvs: bool = True ) -> str: """ Create a new object in the Blender scene. @@ -281,7 +291,21 @@ def create_object( - name: Optional name for the object - location: Optional [x, y, z] location coordinates - rotation: Optional [x, y, z] rotation in radians - - scale: Optional [x, y, z] scale factors + - scale: Optional [x, y, z] scale factors (not used for TORUS) + + Torus-specific parameters (only used when type == "TORUS"): + - align: How to align the torus ('WORLD', 'VIEW', or 'CURSOR') + - major_segments: Number of segments for the main ring + - minor_segments: Number of segments for the cross-section + - mode: Dimension mode ('MAJOR_MINOR' or 'EXT_INT') + - major_radius: Radius from the origin to the center of the cross sections + - minor_radius: Radius of the torus' cross section + - abso_major_rad: Total exterior radius of the torus + - abso_minor_rad: Total interior radius of the torus + - generate_uvs: Whether to generate a default UV map + + Returns: + A message indicating the created object name. """ try: # Get the global connection @@ -296,18 +320,36 @@ def create_object( "type": type, "location": loc, "rotation": rot, - "scale": sc } if name: params["name"] = name - - result = blender.send_command("create_object", params) - return f"Created {type} object: {result['name']}" + + if type == "TORUS": + # For torus, the scale is not used. + params.update({ + "align": align, + "major_segments": major_segments, + "minor_segments": minor_segments, + "mode": mode, + "major_radius": major_radius, + "minor_radius": minor_radius, + "abso_major_rad": abso_major_rad, + "abso_minor_rad": abso_minor_rad, + "generate_uvs": generate_uvs + }) + result = blender.send_command("create_object", params) + return f"Created {type} object: {result['name']}" + else: + # For non-torus objects, include scale + params["scale"] = sc + result = blender.send_command("create_object", params) + return f"Created {type} object: {result['name']}" except Exception as e: logger.error(f"Error creating object: {str(e)}") return f"Error creating object: {str(e)}" + @mcp.tool() def modify_object( ctx: Context,