diff --git a/__init__.py b/__init__.py index 170282b..b0ee7c5 100644 --- a/__init__.py +++ b/__init__.py @@ -53,12 +53,14 @@ from .properties import * from .operator_bake import * from .presets import * + from .shader import BM_OT_Shader_Cage from . import ui_panel from . import operators from . import properties from . import operator_bake from . import presets + from . import shader import importlib importlib.reload(ui_panel) @@ -66,6 +68,7 @@ importlib.reload(properties) importlib.reload(operator_bake) importlib.reload(presets) + importlib.reload(shader) else: from .ui_panel import * @@ -73,6 +76,7 @@ from .properties import * from .operator_bake import * from .presets import * + from .shader import BM_OT_Shader_Cage import bpy @@ -177,6 +181,8 @@ BM_OT_BAKE_Preset_Add, BM_OT_CM_Preset_Add, + BM_OT_Shader_Cage, + BM_ALEP_Object, BM_ALEP_Map, BM_CAUC_Object, diff --git a/properties.py b/properties.py index e6d7e46..6d0a88f 100644 --- a/properties.py +++ b/properties.py @@ -567,6 +567,26 @@ class BM_SceneProps(bpy.types.PropertyGroup): ('MAP_TYPE', "Maps Types", "If Objects are in the texture set for ex., maps of identical types will be baked onto the same image file"), ('MAP_PREFIX_AND_TYPE', "Both Type and Prefix", "If Objects are in the texture set for ex., maps with identical prefixes will be baked onto the same image file.\nIf no identical prefixes found, BakeMaster will try to match maps of the same type")]) + global_cage_color_solid: bpy.props.FloatVectorProperty( + name="Face", # noqa: F405 + description="Face color for real-time cage preview", + default=(1, 0.5, 0, 0.1), + size=4, + min=0, + max=1, + precision=3, + subtype='COLOR') # noqa: F405 + + global_cage_color_wire: bpy.props.FloatVectorProperty( + name="Wireframe", # noqa: F405 + description="Wireframe color for real-time cage preview", + default=(0.95, 0.45, 0, 0.1), + size=4, + min=0, + max=1, + precision=3, + subtype='COLOR') # noqa: F405 + ################################################## ### MAP PROPS ### ################################################## diff --git a/shader.py b/shader.py index ed51680..8507b9c 100644 --- a/shader.py +++ b/shader.py @@ -157,42 +157,57 @@ def cage_draw( return None -class BM_OT_Cage_Shader(bpy_t.Operator): - bl_idname = 'bakemaster.shaders_cage' - bl_label = "" +class BM_OT_Shader_Cage(bpy_t.Operator): + bl_idname = 'bakemaster.shader_cage' + bl_label = "Cage Preview" + bl_description = "Preview extruded cage in the viewport" bl_options = {'INTERNAL'} + obj_name: bpy.props.StringProperty( + default="", + options={'SKIP_SAVE'}) # noqa: F821 + + extrusion: bpy.props.FloatProperty( + default=0, + options={'SKIP_SAVE'}) # noqa: F821 + __obj = None __shader = None __batch_solid = None __batch_wire = None __draw_handle = None - def cancel(self, _: bpy_t.Context): + def get_colors(self, context: bpy_t.Context + ) -> Tuple[Tuple[float, float, float, float], + Tuple[float, float, float, float]]: + color_solid = context.scene.bm_props.global_cage_color_solid + color_wire = context.scene.bm_props.global_cage_color_wire + return color_solid, color_wire + + def draw_cancel(self, _: bpy_t.Context) -> None: bpy_t.SpaceView3D.draw_handler_remove(self.__draw_handle, 'WINDOW') - print("ca") - return {'CANCELLED'} + return None def modal(self, context: bpy_t.Context, event: bpy_t.Event) -> Set[str]: if (event.type == 'ESC'): - return self.cancel(context) + self.draw_cancel(context) + return {'CANCELLED'} return {'PASS_THROUGH'} def invoke(self, context: bpy_t.Context, _: bpy_t.Event) -> Set[str]: - print("sa") - if (not context.active_object or context.active_object.type != 'MESH'): + self.__obj = context.scene.objects.get(self.obj_name, None) + + if (self.__obj is None or self.__obj.type != 'MESH'): + self.report({'ERROR'}, "Expected Mesh object") return {'CANCELLED'} - self.__obj = context.active_object self.__shader = cage() co, nm, i, e = eval_mesh_data(context, self.__obj) self.__batch_solid = cage_batch(self.__shader, co, nm, i, 'TRIS') self.__batch_wire = cage_batch(self.__shader, co, nm, e, 'LINES') - color_solid = (1, 0.5, 0, 0.1) - color_wire = (0.95, 0.45, 0, 0.1) - extrusion = 0.1 + color_solid, color_wire = self.get_colors(context) draw_args = ( context, @@ -202,7 +217,7 @@ def invoke(self, context: bpy_t.Context, _: bpy_t.Event) -> Set[str]: self.__shader, color_solid, color_wire, - extrusion) + self.extrusion) self.__draw_handle = bpy_t.SpaceView3D.draw_handler_add( cage_draw, @@ -215,5 +230,8 @@ def invoke(self, context: bpy_t.Context, _: bpy_t.Event) -> Set[str]: if __name__ == "__main__": - bpy.utils.register_class(BM_OT_Cage_Shader) - bpy.ops.bakemaster.shaders_cage('INVOKE_DEFAULT') + bpy.utils.register_class(BM_OT_Shader_Cage) + bpy.ops.bakemaster.shader_cage( + 'INVOKE_DEFAULT', + obj_name=bpy.context.active_object.name, + extrusion=0.1) diff --git a/ui_panel_base.py b/ui_panel_base.py index 88e5036..e8c3b82 100644 --- a/ui_panel_base.py +++ b/ui_panel_base.py @@ -61,6 +61,13 @@ def draw(self, context): layout = self.layout.column(align=True) layout.prop(bm_props, 'global_bake_match_maps_type') + layout = self.layout.column(align=True) + split = layout.split(factor=0.4) + split.row() + split.label(text="Cage Preview colors") + layout.prop(bm_props, 'global_cage_color_solid') + layout.prop(bm_props, 'global_cage_color_wire') + class BM_ALEP_UL_Objects_Item(bpy.types.UIList): def draw_item(self, context, layout, data, item, active_data, active_propname, index): source_object = [object for object in context.scene.bm_table_of_objects if object.global_object_name == item.object_name] @@ -775,6 +782,17 @@ def draw(self, context): if bpy.app.version >= (2, 90, 0): hl_box_cage.prop(object, 'hl_max_ray_distance') + split = hl_box_cage.row().split(factor=0.4) + split.row() + ot = split.operator( + BM_OT_Shader_Cage.bl_idname, + icon='HIDE_OFF') + obj_name = object.global_object_name + ot.obj_name = object.hl_cage if li else obj_name + ot.extrusion = object.hl_cage_extrusion + + hl_box_cage.separator(factor=0.4) + hl_box_cage.prop( object, 'hl_use_cage', text=("Use Cage Object (auto)", @@ -1383,7 +1401,7 @@ def draw(self, context): # cage if len(map.hl_highpoly_table) or hl_draw is False: hl_box_cage = hl_box.column(align=True) - hl_box_cage.prop(map, 'hl_cage_type') + # hl_box_cage.prop(map, 'hl_cage_type') # if map.hl_cage_type == 'STANDARD': li = map.hl_use_cage and map.hl_cage != 'NONE' @@ -1397,6 +1415,17 @@ def draw(self, context): if bpy.app.version >= (2, 90, 0): hl_box_cage.prop(map, 'hl_max_ray_distance') + split = hl_box_cage.row().split(factor=0.4) + split.row() + ot = split.operator( + BM_OT_Shader_Cage.bl_idname, + icon='HIDE_OFF') + obj_name = object.global_object_name + ot.obj_name = map.hl_cage if li else obj_name + ot.extrusion = map.hl_cage_extrusion + + hl_box_cage.separator(factor=0.4) + hl_box_cage.prop( map, 'hl_use_cage', text=("Use Cage Object (auto)",