import bpy from bpy.types import Panel from .. constants import BGCOL, PREFIX class BPM_PT_bg_manager_panel(Panel): bl_idname = 'BPM_PT_bg_manager_panel' bl_space_type = "VIEW_3D" bl_region_type = "UI" bl_category = "View" bl_label = "BG Plane Manager" def draw(self, context): layout = self.layout scn = bpy.context.scene # layout.label(text='Manual tests:') # layout.operator('bpm.import_bg_images') # layout.operator('bpm.convert_planes') ## Camera swapping row = layout.row(align=True) cam = context.scene.camera # cam_name = cam.name if cam else 'None' # if cam and cam_name == 'draw_cam': # cam_name = f'{cam.parent.name} > {cam_name}' # row.operator("bpm.swap_cams", text=cam_name, icon='OUTLINER_OB_CAMERA') if cam: anim_cam_name = 'anim_cam' bg_cam_name = 'bg_cam' in_anim = in_bg = False if cam.name == 'anim_cam': in_anim = True elif cam.name == 'bg_cam': in_bg = True elif cam.name == 'draw_cam' and cam.parent: if cam.parent.name == 'anim_cam': in_anim = True anim_cam_name = anim_cam_name + '> draw_cam' elif cam.parent.name == 'bg_cam': in_bg = True bg_cam_name = bg_cam_name + '> draw_cam' # in_bg_cam = context.scene.camera.name != 'bg_cam' row.operator("bpm.swap_cams", text=anim_cam_name, icon='OUTLINER_OB_CAMERA', depress=in_anim) row.operator("bpm.swap_cams", text=bg_cam_name, icon='OUTLINER_OB_CAMERA', depress=in_bg) planes = [i.plane for i in scn.bg_props.planes] if not planes: ## Show import/reload if nothing is in list row = layout.row() row.operator("bpm.import_bg_images", icon="IMPORT", text="Import Planes") row.operator("bpm.reload_list", icon="FILE_REFRESH", text="") return ## Show settings related to active plane active_item = scn.bg_props.planes[scn.bg_props.index] ob = active_item.plane if not ob: layout.operator("bpm.reload_list", icon="FILE_REFRESH", text="Need refresh") return bg_main_col = context.view_layer.layer_collection.children.get(BGCOL) if not bg_main_col: layout.label(text="No Background collection") layout.label(text="Import plane automatically create hierarchy") return if active_item.type == 'bg': layercol = bg_main_col.children.get(ob.name[len(PREFIX):]) if not layercol: layout.label(text=f"No {ob.name} collection") # return col= layout.column() ## Backgrounds and Objects UI List col.separator() row = col.row() list_row = row.row() list_row.scale_y = scn.bg_props.ui_list_scale # 1.6 minimum_rows = 8 list_row.template_list("BPM_UL_bg_list", "", scn.bg_props, "planes", scn.bg_props, "index", rows=minimum_rows) #https://docs.blender.org/api/blender2.8/bpy.types.UILayout.html#bpy.types.UILayout.template_list col = row.column(align=True) col.operator('bpm.create_and_place_in_camera', icon='OUTLINER_OB_GREASEPENCIL', text='').create = True col.separator() col.menu("BPM_MT_more_option", icon='DOWNARROW_HLT', text='') col.separator() col.operator('bpm.move_plane', icon='TRIA_UP', text='').direction = 'UP' col.operator('bpm.move_plane', icon='TRIA_DOWN', text='').direction = 'DOWN' col.separator() # select toggle # icon = 'RESTRICT_SELECT_ON' if ob.select_get() else 'RESTRICT_SELECT_OFF' # col.operator("bpm.select_swap_active_bg", icon=icon, text='') # lock bg_col = bpy.data.collections.get(BGCOL) if bg_col: # lock_icon = 'LOCKED' if bg_col.hide_select else 'UNLOCKED' col.prop(bg_col, 'hide_select', icon='LOCKED', text='', invert_checkbox=True) # # emboss=False # col.prop(bg_col, 'hide_select', text='') # origin select icon # select all col.operator('bpm.select_all', icon='RESTRICT_SELECT_OFF', text='') col = layout.column() col.use_property_split = True if active_item.type == 'bg': row = col.row() tex_ob = next((o for o in ob.children), None) if not tex_ob: layout.label(text='Missing Image Child', icon='ERROR') return row.prop(scn.bg_props, 'opacity', slider=True) # row.operator("bpm.change_background_type", icon="NODE_TEXTURE", text=text_bg_type) if tex_ob.type == 'MESH' and len(tex_ob.data.materials): text_mode = 'Clip' if tex_ob.data.materials[0].blend_method == 'CLIP' else 'Blend' row.operator("bpm.change_material_alpha_mode", icon="MATERIAL", text=text_mode) # located under list row = layout.row() row.label(text='Move:') if active_item.type == 'bg': row.operator("bpm.set_distance", text=f"Distance {ob['distance']:.1f}m") row.prop(scn.bg_props, 'move_hided', text='Hided') elif active_item.type == 'obj': cam = context.scene.objects.get('bg_cam') or context.scene.camera if hasattr(bpy.types, 'OBJECT_OT_depth_proportional_move'): distance = (ob.matrix_world.to_translation() - cam.matrix_world.to_translation()).length row.operator("object.depth_proportional_move", text=f"Distance {distance:.1f}m") # icon='TRANSFORM_ORIGINS' else: row.label(text=f"Distance {(ob.matrix_world.to_translation() - cam.matrix_world.to_translation()).length:.1f}m") if active_item.type == 'bg': row = layout.row() # row.label(text='Actions:') ## Send object to a plane row = layout.row() row.operator("bpm.send_gp_to_plane") ## parent to object active = context.object if active and active.parent and active not in planes: layout.label(text=f'{active.parent.name} > {active.name}') text='Clear Parent ' else: text='Parent To Plane' row.operator("bpm.parent_to_bg", text=text) def register(): bpy.utils.register_class(BPM_PT_bg_manager_panel) def unregister(): if hasattr(bpy.types, BPM_PT_bg_manager_panel.bl_idname): bpy.utils.unregister_class(BPM_PT_bg_manager_panel)