Implement normal map generator
This commit is contained in:
+118
@@ -1253,6 +1253,117 @@ class IMAGE_EDITOR_PLUS_OT_make_seamless_dialog(bpy.types.Operator):
|
||||
row.column()
|
||||
row.prop(self, 'preview', text='Preview', toggle=True, icon='VIEWZOOM')
|
||||
|
||||
def preview_normal_map_properties(self, context):
|
||||
if self.preview:
|
||||
update_normal_map_properties(self, context)
|
||||
else:
|
||||
img = app.get_target_image(context)
|
||||
if img:
|
||||
app.revert_image_cache(img)
|
||||
app.refresh_image(context)
|
||||
|
||||
def reset_normal_map_properties(self, context):
|
||||
if self.reset:
|
||||
self.property_unset('scale')
|
||||
self.property_unset('flip_x')
|
||||
self.property_unset('flip_y')
|
||||
self.property_unset('full_z')
|
||||
update_normal_map_properties(self, context)
|
||||
|
||||
self.reset = False
|
||||
|
||||
def update_normal_map_properties(self, context):
|
||||
if self.preview:
|
||||
bpy.ops.image_editor_plus.normal_map('EXEC_DEFAULT', False,
|
||||
scale=self.scale,
|
||||
flip_x=self.flip_x,
|
||||
flip_y=self.flip_y,
|
||||
full_z=self.full_z)
|
||||
|
||||
class IMAGE_EDITOR_PLUS_OT_normal_map_dialog(bpy.types.Operator):
|
||||
"""Generate a normal map"""
|
||||
bl_idname = 'image_editor_plus.normal_map_dialog'
|
||||
bl_label = "Normal Map"
|
||||
preview: bpy.props.BoolProperty(default=True, options={'SKIP_SAVE'},
|
||||
update=preview_normal_map_properties)
|
||||
reset: bpy.props.BoolProperty(options={'SKIP_SAVE'}, update=reset_normal_map_properties)
|
||||
scale: bpy.props.FloatProperty(name='Scale', subtype='FACTOR',
|
||||
min=0, soft_max=250.0, default=10.0, options={'SKIP_SAVE'},
|
||||
update=update_normal_map_properties)
|
||||
flip_x: bpy.props.BoolProperty(name='Flip X', default=False, options={'SKIP_SAVE'},
|
||||
update=update_normal_map_properties)
|
||||
flip_y: bpy.props.BoolProperty(name='Flip Y', default=False, options={'SKIP_SAVE'},
|
||||
update=update_normal_map_properties)
|
||||
full_z: bpy.props.BoolProperty(name='Full Range for Z', default=False, options={'SKIP_SAVE'},
|
||||
update=update_normal_map_properties)
|
||||
|
||||
def invoke(self, context, event):
|
||||
session = app.get_session()
|
||||
|
||||
wm = context.window_manager
|
||||
|
||||
img = app.get_target_image(context)
|
||||
if not img:
|
||||
return {'CANCELLED'}
|
||||
|
||||
app.cache_image(img, need_hsl=True)
|
||||
|
||||
layer = app.get_active_layer(context)
|
||||
if layer:
|
||||
session.cached_layer_location = layer.location[:]
|
||||
|
||||
update_normal_map_properties(self, context)
|
||||
|
||||
return wm.invoke_props_dialog(self)
|
||||
|
||||
def execute(self, context):
|
||||
bpy.ops.image_editor_plus.normal_map('EXEC_DEFAULT', False,
|
||||
scale=self.scale,
|
||||
flip_x=self.flip_x,
|
||||
flip_y=self.flip_y,
|
||||
full_z=self.full_z)
|
||||
|
||||
return {'FINISHED'}
|
||||
|
||||
def cancel(self, context):
|
||||
img = app.get_target_image(context)
|
||||
if not img:
|
||||
return {'CANCELLED'}
|
||||
|
||||
app.revert_image_cache(img)
|
||||
app.clear_image_cache()
|
||||
app.refresh_image(context)
|
||||
|
||||
def draw(self, context):
|
||||
layout = self.layout
|
||||
|
||||
row = layout.split(align=True)
|
||||
row.column()
|
||||
row.prop(self, 'preview', text='Preview', toggle=True, icon='VIEWZOOM')
|
||||
|
||||
layout.separator()
|
||||
|
||||
row = layout.split(align=True)
|
||||
row.alignment = 'RIGHT'
|
||||
row.label(text='Scale')
|
||||
row.prop(self, 'scale', text='')
|
||||
|
||||
row = layout.split(align=True)
|
||||
row.column()
|
||||
row.prop(self, 'flip_x')
|
||||
|
||||
row = layout.split(align=True)
|
||||
row.column()
|
||||
row.prop(self, 'flip_y')
|
||||
|
||||
row = layout.split(align=True)
|
||||
row.column()
|
||||
row.prop(self, 'full_z')
|
||||
|
||||
row = layout.split(factor=0.7)
|
||||
row.column()
|
||||
row.prop(self, 'reset', text='Reset', toggle=True)
|
||||
|
||||
class IMAGE_EDITOR_PLUS_UL_layer_list(bpy.types.UIList):
|
||||
def draw_item(self, context, layout, data, item, icon, active_data, active_propname):
|
||||
icon_value = 0
|
||||
@@ -1432,6 +1543,9 @@ class IMAGE_EDITOR_PLUS_MT_filter_menu(bpy.types.Menu):
|
||||
layout.operator(IMAGE_EDITOR_PLUS_OT_make_seamless_dialog.bl_idname, text='Make Seamless...',
|
||||
icon_value=get_icon_id('filter'))
|
||||
|
||||
layout.operator(IMAGE_EDITOR_PLUS_OT_normal_map_dialog.bl_idname, text='Normal Map...',
|
||||
icon_value=get_icon_id('filter'))
|
||||
|
||||
class IMAGE_EDITOR_PLUS_PT_select_panel(bpy.types.Panel):
|
||||
bl_label = "Select"
|
||||
bl_space_type = "IMAGE_EDITOR"
|
||||
@@ -1793,3 +1907,7 @@ class IMAGE_EDITOR_PLUS_PT_filter_panel(bpy.types.Panel):
|
||||
row = layout.row()
|
||||
row.operator(IMAGE_EDITOR_PLUS_OT_make_seamless_dialog.bl_idname, text='Make Seamless...',
|
||||
icon_value=get_icon_id('filter'))
|
||||
|
||||
row = layout.row()
|
||||
row.operator(IMAGE_EDITOR_PLUS_OT_normal_map_dialog.bl_idname, text='Normal Map...',
|
||||
icon_value=get_icon_id('filter'))
|
||||
|
||||
Reference in New Issue
Block a user