Skip to content

Commit

Permalink
(#60 ui, shader, props) add: cage shader OT to ui
Browse files Browse the repository at this point in the history
  • Loading branch information
KirilStrezikozin committed Jan 21, 2024
1 parent 024dc63 commit 05ded29
Show file tree
Hide file tree
Showing 4 changed files with 90 additions and 17 deletions.
6 changes: 6 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,26 +53,30 @@
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)
importlib.reload(operators)
importlib.reload(properties)
importlib.reload(operator_bake)
importlib.reload(presets)
importlib.reload(shader)

else:
from .ui_panel import *
from .operators import *
from .properties import *
from .operator_bake import *
from .presets import *
from .shader import BM_OT_Shader_Cage

import bpy

Expand Down Expand Up @@ -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,
Expand Down
20 changes: 20 additions & 0 deletions properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 ###
##################################################
Expand Down
50 changes: 34 additions & 16 deletions shader.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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,
Expand All @@ -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)
31 changes: 30 additions & 1 deletion ui_panel_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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)",
Expand Down Expand Up @@ -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'
Expand All @@ -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)",
Expand Down

0 comments on commit 05ded29

Please sign in to comment.