- Implemented viewport.py for handling 3D view projections, gestures, and overlay drawing. - Created refine_image_selection.py to manage the refinement of gesture masks and output image bounds. - Added selection module with refine_selection.py to process and crop images based on alpha channel visibility. - Introduced __init__.py for selection module to expose refine_selection function.
69 lines
2.0 KiB
Python
69 lines
2.0 KiB
Python
import bpy
|
||
|
||
from .common.image import is_image_empty
|
||
from .operators.upscale import upscale_output_size
|
||
|
||
|
||
class AnyImageImageMenu(bpy.types.Menu):
|
||
bl_idname = "ANYIMAGE_MT_image_context"
|
||
bl_label = "AnyImage"
|
||
|
||
def draw(self, context):
|
||
from .properties import ai_setup_label, ai_status
|
||
|
||
layout = self.layout
|
||
layout.operator_context = "INVOKE_DEFAULT"
|
||
layout.operator(
|
||
"anyimage.convert_to_plane",
|
||
text="Convert to Plane",
|
||
icon="MESH_PLANE",
|
||
)
|
||
layout.operator(
|
||
"anyimage.convert_to_depth_plane",
|
||
text="Convert to Depth Plane",
|
||
icon="MOD_DISPLACE",
|
||
)
|
||
layout.separator()
|
||
layout.operator(
|
||
"anyimage.remove_image_background",
|
||
text="Remove Background",
|
||
icon="IMAGE_ALPHA",
|
||
)
|
||
layout.operator(
|
||
"anyimage.upscale_image",
|
||
text=upscale_menu_label(context),
|
||
icon="FULLSCREEN_ENTER",
|
||
)
|
||
layout.separator()
|
||
status = ai_status()
|
||
if status["ready"]:
|
||
layout.operator(
|
||
"anyimage.open_ai_environment_settings",
|
||
text="AI Environment Settings",
|
||
icon="PREFERENCES",
|
||
)
|
||
else:
|
||
layout.operator(
|
||
"anyimage.setup_ai_environment",
|
||
text=ai_setup_label(status),
|
||
icon="IMPORT",
|
||
)
|
||
|
||
|
||
def upscale_menu_label(context):
|
||
source_object = getattr(context, "object", None)
|
||
if not is_image_empty(source_object):
|
||
return "Upscale"
|
||
output_size = upscale_output_size(source_object.data)
|
||
if output_size is None:
|
||
return "Upscale"
|
||
width, height = output_size
|
||
return f"Upscale ({width} × {height})"
|
||
|
||
|
||
def draw_image_context_menu(self, context):
|
||
if not is_image_empty(context.object):
|
||
return
|
||
self.layout.menu(AnyImageImageMenu.bl_idname, text="AnyImage", icon="PLUGIN")
|
||
self.layout.separator()
|