VDM brush baker #104580

Merged
Joseph Eagar merged 10 commits from robin.hohni/blender-addons:vdm-brush-baker into main 2023-05-12 15:42:12 +02:00
Showing only changes of commit 36320fc98f - Show all commits

View File

@ -27,7 +27,7 @@ importlib.reload(bakematerial)
bl_info = { bl_info = {
'name': 'VDM Brush Baker', 'name': 'VDM Brush Baker',
'author': 'Robin Hohnsbeen', 'author': 'Robin Hohnsbeen',
'description': 'Bake VDM Brushes from planes easily', 'description': 'Bake vector displacement brushes easily from a plane',
'blender': (3, 5, 0), 'blender': (3, 5, 0),
'version': (1, 0, 2), 'version': (1, 0, 2),
'location': 'Sculpt Mode: View3D > Sidebar > Tool Tab', 'location': 'Sculpt Mode: View3D > Sidebar > Tool Tab',
@ -96,36 +96,45 @@ class PT_VDMBaker(bpy.types.Panel):
def draw(self, context): def draw(self, context):
layout = self.layout layout = self.layout
addon_data = get_addon_data()
layout.operator(create_sculpt_plane.bl_idname) layout.operator(create_sculpt_plane.bl_idname)
addon_data = get_addon_data() layout.separator()
is_occupied, brush_name = get_new_brush_name() is_occupied, brush_name = get_new_brush_name()
layout.prop(addon_data, 'draft_brush_name')
resolution_layout = layout.row(align=True)
resolution_layout.label(text='Map resolution: ')
resolution_layout.prop(addon_data, 'render_resolution')
compression_layout = layout.row(align=True)
compression_layout.label(text='Compression: ')
compression_layout.prop(addon_data, 'compression')
colordepth_layout = layout.row(align=True)
colordepth_layout.label(text='Color depth: ')
colordepth_layout.prop(addon_data, 'color_depth', text='')
button_text = 'Render and create brush' button_text = 'Render and create brush'
createvdmlayout = layout.row()
createvdmlayout.enabled = context.active_object is not None and context.active_object.type == 'MESH'
createvdmlayout.operator(
create_vdm_brush.bl_idname, text=button_text, icon='META_DATA')
if is_occupied: if is_occupied:
layout.label( layout.label(
text='Name taken: overrides Brush.', icon='INFO') text='Name taken: overrides Brush.', icon='INFO')
button_text = 'Overwrite vdm brush' button_text = 'Overwrite vdm brush'
createvdmlayout = layout.row() layout.prop(addon_data, 'draft_brush_name')
createvdmlayout.enabled = context.active_object is not None and context.active_object.type == 'MESH'
createvdmlayout.operator( settings_layout = layout.column(align=True)
create_vdm_brush.bl_idname, text=button_text, icon='META_DATA') settings_layout.label(text='Settings')
layout_box = settings_layout.box()
resolution_layout = layout_box.row(align=True)
resolution_layout.label(text='Map resolution: ')
resolution_layout.prop(addon_data, 'render_resolution')
compression_layout = layout_box.row(align=True)
compression_layout.label(text='Compression: ')
compression_layout.prop(addon_data, 'compression')
colordepth_layout = layout_box.row(align=True)
colordepth_layout.label(text='Color depth: ')
colordepth_layout.prop(addon_data, 'color_depth', text='')
samples_layout = layout_box.row(align=True)
samples_layout.label(text='Samples:')
samples_layout.prop(addon_data, 'render_samples', text='')
layout.separator() layout.separator()
@ -232,17 +241,7 @@ class create_vdm_brush(bpy.types.Operator):
vdm_plane.rotation_euler = (0, 0, 0) vdm_plane.rotation_euler = (0, 0, 0)
vdm_texture_node = vdm_bake_material.node_tree.nodes['VDMTexture'] vdm_texture_node = vdm_bake_material.node_tree.nodes['VDMTexture']
render_resolution = 128 render_resolution = int(addon_data.render_resolution)
if addon_data.render_resolution == '256':
render_resolution = 256
elif addon_data.render_resolution == '512':
render_resolution = 512
elif addon_data.render_resolution == '1024':
render_resolution = 1024
elif addon_data.render_resolution == '2048':
render_resolution = 2048
elif addon_data.render_resolution == '4096':
render_resolution = 4096
bpy.ops.object.select_all(action='DESELECT') bpy.ops.object.select_all(action='DESELECT')
vdm_plane.select_set(True) vdm_plane.select_set(True)
@ -259,11 +258,8 @@ class create_vdm_brush(bpy.types.Operator):
if addon_data.compression == 'zip': if addon_data.compression == 'zip':
scene.render.image_settings.exr_codec = 'ZIP' scene.render.image_settings.exr_codec = 'ZIP'
scene.render.image_settings.color_depth = '32' scene.render.image_settings.color_depth = addon_data.color_depth
vdm_texture_image.use_half_precision = False vdm_texture_image.use_half_precision = addon_data.color_depth == '16'
if addon_data.color_depth == '16':
vdm_texture_image.use_half_precision = True
scene.render.image_settings.color_depth = '16'
vdm_texture_image.colorspace_settings.is_data = True vdm_texture_image.colorspace_settings.is_data = True
vdm_texture_image.colorspace_settings.name = 'Non-Color' vdm_texture_image.colorspace_settings.name = 'Non-Color'
@ -275,7 +271,7 @@ class create_vdm_brush(bpy.types.Operator):
bpy.ops.object.bake(type='EMIT') bpy.ops.object.bake(type='EMIT')
# save as render so we have more control over compression settings # save as render so we have more control over compression settings
vdm_texture_image.save_render( vdm_texture_image.save_render(
filepath=bpy.path.abspath(output_path), scene=scene) filepath=bpy.path.abspath(output_path), scene=scene, quality=0)
# Removes the dirty flag, so the image doesn't have to be saved again by the user. # Removes the dirty flag, so the image doesn't have to be saved again by the user.
vdm_texture_image.pack() vdm_texture_image.pack()
vdm_texture_image.unpack(method='REMOVE') vdm_texture_image.unpack(method='REMOVE')