Skip to main content
Glama
ujs204

BlenderMCP

by ujs204

set_texture

Apply Polyhaven textures to 3D objects in Blender by specifying object name and texture ID to enhance visual appearance.

Instructions

Apply a previously downloaded Polyhaven texture to an object.

Parameters:

  • object_name: Name of the object to apply the texture to

  • texture_id: ID of the Polyhaven texture to apply (must be downloaded first)

Returns a message indicating success or failure.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
object_nameYes
texture_idYes

Implementation Reference

  • The handler function for the 'set_texture' MCP tool. It is registered via @mcp.tool() decorator and implements the logic to apply a Polyhaven texture to a specified Blender object by forwarding parameters to the Blender addon via socket command.
    @mcp.tool()
    def set_texture(
        ctx: Context,
        object_name: str,
        texture_id: str
    ) -> str:
        """
        Apply a previously downloaded Polyhaven texture to an object.
        
        Parameters:
        - object_name: Name of the object to apply the texture to
        - texture_id: ID of the Polyhaven texture to apply (must be downloaded first)
        
        Returns a message indicating success or failure.
        """
        try:
            # Get the global connection
            blender = get_blender_connection()
            result = blender.send_command("set_texture", {
                "object_name": object_name,
                "texture_id": texture_id
            })
            
            if "error" in result:
                return f"Error: {result['error']}"
            
            if result.get("success"):
                material_name = result.get("material", "")
                maps = ", ".join(result.get("maps", []))
                
                # Add detailed material info
                material_info = result.get("material_info", {})
                node_count = material_info.get("node_count", 0)
                has_nodes = material_info.get("has_nodes", False)
                texture_nodes = material_info.get("texture_nodes", [])
                
                output = f"Successfully applied texture '{texture_id}' to {object_name}.\n"
                output += f"Using material '{material_name}' with maps: {maps}.\n\n"
                output += f"Material has nodes: {has_nodes}\n"
                output += f"Total node count: {node_count}\n\n"
                
                if texture_nodes:
                    output += "Texture nodes:\n"
                    for node in texture_nodes:
                        output += f"- {node['name']} using image: {node['image']}\n"
                        if node['connections']:
                            output += "  Connections:\n"
                            for conn in node['connections']:
                                output += f"    {conn}\n"
                else:
                    output += "No texture nodes found in the material.\n"
                
                return output
            else:
                return f"Failed to apply texture: {result.get('message', 'Unknown error')}"
        except Exception as e:
            logger.error(f"Error applying texture: {str(e)}")
            return f"Error applying texture: {str(e)}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/ujs204/CLAUDE-BLENDER-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server