From b270d9efa9bedb7ca0813acffc1632f84900c0de Mon Sep 17 00:00:00 2001 From: hgn Date: Fri, 21 Jul 2023 21:16:42 +0100 Subject: [PATCH] some niceer ui stuff --- blender_export.py | 71 +++++++++++++++++++++++++++++++++++++---------- 1 file changed, 56 insertions(+), 15 deletions(-) diff --git a/blender_export.py b/blender_export.py index 54a02e8..f9b8f69 100644 --- a/blender_export.py +++ b/blender_export.py @@ -1,9 +1,10 @@ -import bpy, math, gpu, os +import bpy, blf, math, gpu, os import cProfile from ctypes import * from mathutils import * from gpu_extras.batch import batch_for_shader from bpy_extras import mesh_utils +from bpy_extras import view3d_utils bl_info = { "name":"Skaterift .mdl exporter", @@ -2276,9 +2277,12 @@ class SR_INTERFACE(bpy.types.Panel): active_object = context.active_object if not active_object: return - _.layout.operator( 'skaterift.copy_entity_data', \ - text=F'Copy entity data to {len(context.selected_objects)-1} '+\ - F'other objects' ) + amount = max( 0, len(context.selected_objects)-1 ) + + row = _.layout.row() + row.operator( 'skaterift.copy_entity_data', \ + text=F'Copy entity data to {amount} other objects' ) + if amount == 0: row.enabled=False box = _.layout.box() row = box.row() @@ -2286,13 +2290,13 @@ class SR_INTERFACE(bpy.types.Panel): row.label( text=active_object.name ) row.scale_y = 1.5 - def _draw_prop_collection( data ): #{ + def _draw_prop_collection( source, data ): #{ nonlocal box row = box.row() row.alignment = 'CENTER' row.enabled = False row.scale_y = 1.5 - row.label( text=F'{data[0]}' ) + row.label( text=F'{source}' ) if hasattr(type(data[0]),'sr_inspector'):#{ type(data[0]).sr_inspector( box, data ) @@ -2312,7 +2316,9 @@ class SR_INTERFACE(bpy.types.Panel): text=F'Mirror attributes to {mb.name}' ) #} - _draw_prop_collection( [bones.active.SR_data ] ) + _draw_prop_collection( \ + F'bpy.types.Bone["{bones.active.name}"].SR_data',\ + [bones.active.SR_data ] ) #} else: #{ row = box.row() @@ -2323,18 +2329,26 @@ class SR_INTERFACE(bpy.types.Panel): #} #} elif active_object.type == 'LIGHT': #{ - _draw_prop_collection( [active_object.data.SR_data] ) + _draw_prop_collection( \ + F'bpy.types.Light["{active_object.data.name}"].SR_data', \ + [active_object.data.SR_data] ) #} elif active_object.type in ['EMPTY','CURVE','MESH']:#{ box.prop( active_object.SR_data, "ent_type" ) ent_type = active_object.SR_data.ent_type col = getattr( active_object.SR_data, ent_type, None ) - if col != None and len(col)!=0: _draw_prop_collection( col ) + if col != None and len(col)!=0: + _draw_prop_collection( \ + F'bpy.types.Object["{active_object.name}"].SR_data.{ent_type}[0]', \ + col ) if active_object.type == 'MESH':#{ col = getattr( active_object.data.SR_data, ent_type, None ) - if col != None and len(col)!=0: _draw_prop_collection( col ) + if col != None and len(col)!=0: + _draw_prop_collection( \ + F'bpy.types.Mesh["{active_object.data.name}"].SR_data.{ent_type}[0]', \ + col ) #} #} #} @@ -3369,6 +3383,7 @@ class SR_MATERIAL_PROPERTIES(bpy.types.PropertyGroup): # ---------------------------------------------------------------------------- # cv_view_draw_handler = None +cv_view_pixel_handler = None cv_view_shader = gpu.shader.from_builtin('3D_SMOOTH_COLOR') cv_view_verts = [] cv_view_colours = [] @@ -4106,8 +4121,7 @@ def cv_draw_route( route, dij ): #} #} -def cv_draw(): -#{ +def cv_draw():#{ global cv_view_shader global cv_view_verts global cv_view_colours @@ -4340,7 +4354,31 @@ def cv_draw(): #} cv_draw_lines() - return +#} + +def pos3d_to_2d( pos ):#{ + return view3d_utils.location_3d_to_region_2d( \ + bpy.context.region, \ + bpy.context.space_data.region_3d, pos ) +#} + +def cv_draw_pixel():#{ + if not bpy.context.scene.SR_data.gizmos: return + blf.size(0,10) + blf.color(0, 1.0,1.0,1.0,0.9) + blf.enable(0,blf.SHADOW) + blf.shadow(0,3,0.0,0.0,0.0,1.0) + for obj in bpy.context.collection.objects:#{ + ent_type = obj_ent_type( obj ) + + if ent_type != 'none':#{ + co = pos3d_to_2d( obj.location ) + + if not co: continue + blf.position(0,co[0],co[1],0) + blf.draw(0,ent_type) + #} + #} #} classes = [ SR_INTERFACE, SR_MATERIAL_PANEL,\ @@ -4392,9 +4430,11 @@ def register(): bpy.types.Material.SR_data = \ bpy.props.PointerProperty(type=SR_MATERIAL_PROPERTIES) - global cv_view_draw_handler + global cv_view_draw_handler, cv_view_pixel_handler cv_view_draw_handler = bpy.types.SpaceView3D.draw_handler_add(\ cv_draw,(),'WINDOW','POST_VIEW') + cv_view_pixel_handler = bpy.types.SpaceView3D.draw_handler_add(\ + cv_draw_pixel,(),'WINDOW','POST_PIXEL') #} def unregister(): @@ -4402,8 +4442,9 @@ def unregister(): for c in classes: bpy.utils.unregister_class(c) - global cv_view_draw_handler + global cv_view_draw_handler, cv_view_pixel_handler bpy.types.SpaceView3D.draw_handler_remove(cv_view_draw_handler,'WINDOW') + bpy.types.SpaceView3D.draw_handler_remove(cv_view_pixel_handler,'WINDOW') #} # ---------------------------------------------------------------------------- # -- 2.25.1