Skip to content

Commit

Permalink
Rename metalness to metallic, support alpha input in Alpha bake map
Browse files Browse the repository at this point in the history
  • Loading branch information
oRazeD committed Apr 21, 2024
1 parent dfd586f commit 37ea3dd
Show file tree
Hide file tree
Showing 7 changed files with 128 additions and 130 deletions.
13 changes: 7 additions & 6 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class Global:
COLOR_ID = "color"
EMISSIVE_ID = "emissive"
ROUGHNESS_ID = "roughness"
METALNESS_ID = "metalness"
METALLIC_ID = "metallic"

NORMAL_NAME = NORMAL_ID.capitalize()
CURVATURE_NAME = CURVATURE_ID.capitalize()
Expand All @@ -40,7 +40,7 @@ class Global:
COLOR_NAME = "Base Color"
EMISSIVE_NAME = EMISSIVE_ID.capitalize()
ROUGHNESS_NAME = ROUGHNESS_ID.capitalize()
METALNESS_NAME = METALNESS_ID.capitalize()
METALLIC_NAME = METALLIC_ID.capitalize()

NORMAL_NODE = PREFIX + NORMAL_NAME
CURVATURE_NODE = PREFIX + CURVATURE_NAME
Expand All @@ -50,7 +50,7 @@ class Global:
COLOR_NODE = PREFIX + COLOR_NAME
EMISSIVE_NODE = PREFIX + EMISSIVE_NAME
ROUGHNESS_NODE = PREFIX + ROUGHNESS_NAME
METALNESS_NODE = PREFIX + METALNESS_NAME
METALLIC_NODE = PREFIX + METALLIC_NAME

ALL_MAP_IDS = (
NORMAL_ID,
Expand All @@ -62,7 +62,7 @@ class Global:
COLOR_ID,
EMISSIVE_ID,
ROUGHNESS_ID,
METALNESS_ID
METALLIC_ID
)

ALL_MAP_NAMES = (
Expand All @@ -75,16 +75,17 @@ class Global:
COLOR_NAME,
EMISSIVE_NAME,
ROUGHNESS_NAME,
METALNESS_NAME
METALLIC_NAME
)

SHADER_MAP_NAMES = (
NORMAL_NODE,
CURVATURE_NODE,
ALPHA_NODE,
COLOR_NODE,
EMISSIVE_NODE,
ROUGHNESS_NODE,
METALNESS_NODE
METALLIC_NODE
)

INVALID_BAKE_TYPES = (
Expand Down
6 changes: 2 additions & 4 deletions operators/operators.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
)




################################################
# MISC
################################################
Expand Down Expand Up @@ -587,7 +585,7 @@ def draw(self, _context: Context):


################################################
# CHANNEL PACKING
# TODO: CHANNEL PACKING
################################################


Expand Down Expand Up @@ -626,7 +624,7 @@ def draw(self, _context: Context):
GRABDOC_OT_map_preview,
GRABDOC_OT_leave_map_preview,
GRABDOC_OT_export_current_preview,
GRABDOC_OT_config_maps
GRABDOC_OT_config_maps,
#GRABDOC_OT_map_pack_info
)

Expand Down
36 changes: 8 additions & 28 deletions preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
Curvature,
Height,
Id,
Metalness,
Metallic,
Normals,
Occlusion,
Emissive,
Expand Down Expand Up @@ -113,35 +113,21 @@ class GRABDOC_OT_add_preset(AddPresetBase, Operator):
"gd.color",
"gd.emissive",
"gd.roughness",
"gd.metalness",
"gd.metallic",
]

# Where to store the preset
preset_subdir = "grab_doc"


############################################################
# USER PREFERENCES
# PROPERTY GROUP
############################################################


class GRABDOC_OT_check_for_update(Operator):
"""Check GitHub releases page for newer version"""
bl_idname = "grab_doc.check_for_update"
bl_label = ""
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}

def execute(self, _context: Context):
updater.check_for_update_now()
return {'FINISHED'}


class GRABDOC_AP_preferences(AddonPreferences):
bl_idname = __package__

# NOTE: Special properties stored
# here are saved in User Preferences

marmo_executable: StringProperty(
name="",
description="Path to Marmoset Toolbag 3 or 4 executable",
Expand All @@ -150,11 +136,6 @@ class GRABDOC_AP_preferences(AddonPreferences):
)


############################################################
# PROPERTY GROUP
############################################################


class GRABDOC_property_group(PropertyGroup):
MAP_TYPES = (
('none', "None", ""),
Expand All @@ -167,7 +148,7 @@ class GRABDOC_property_group(PropertyGroup):
('color', "Base Color", ""),
('emissive', "Emissive", ""),
('roughness', "Roughness", ""),
('metalness', "Metalness", "")
('metallic', "Metallic", "")
)

def update_export_name(self, _context: Context):
Expand Down Expand Up @@ -375,7 +356,7 @@ def update_scale(self, context: Context):
color: CollectionProperty(type=Color)
emissive: CollectionProperty(type=Emissive)
roughness: CollectionProperty(type=Roughness)
metalness: CollectionProperty(type=Metalness)
metallic: CollectionProperty(type=Metallic)

# Marmoset baking
marmo_auto_bake: BoolProperty(name="Auto bake", default=True)
Expand Down Expand Up @@ -425,7 +406,7 @@ def update_scale(self, context: Context):
#)
#channel_B: EnumProperty(
# items=MAP_TYPES,
# default="metalness",
# default="metallic",
# name='B'
#)
#channel_A: EnumProperty(
Expand Down Expand Up @@ -453,10 +434,9 @@ def update_scale(self, context: Context):
Color,
Emissive,
Roughness,
Metalness,
Metallic,
GRABDOC_property_group,
GRABDOC_AP_preferences,
GRABDOC_OT_check_for_update
GRABDOC_AP_preferences
)

def register():
Expand Down
8 changes: 4 additions & 4 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -397,9 +397,9 @@ class GRABDOC_PT_roughness(BakerPanel, PanelInfo, Panel):
NAME = Global.ROUGHNESS_NAME


class GRABDOC_PT_metalness(BakerPanel, PanelInfo, Panel):
ID = Global.METALNESS_ID
NAME = Global.METALNESS_NAME
class GRABDOC_PT_metallic(BakerPanel, PanelInfo, Panel):
ID = Global.METALLIC_ID
NAME = Global.METALLIC_NAME


################################################
Expand All @@ -420,7 +420,7 @@ class GRABDOC_PT_metalness(BakerPanel, PanelInfo, Panel):
GRABDOC_PT_color,
GRABDOC_PT_emissive,
GRABDOC_PT_roughness,
GRABDOC_PT_metalness
GRABDOC_PT_metallic
)
# GRABDOC_PT_pack_maps

Expand Down
109 changes: 56 additions & 53 deletions utils/baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ def update_curvature(self, context: Context):
scene_shading.curvature_ridge_factor = self.ridge
scene_shading.curvature_valley_factor = self.valley

def update_range(self, context: Context):
def update_range(self, _context: Context):
color_ramp = \
bpy.data.node_groups[self.NODE].nodes.get("Color Ramp")
color_ramp.color_ramp.elements[0].position = \
Expand Down Expand Up @@ -554,47 +554,6 @@ def update_guide(self, context: Context):
)


class Alpha(Baker, PropertyGroup):
ID = Global.ALPHA_ID
NAME = Global.ALPHA_NAME
NODE = Global.ALPHA_NODE
COLOR_SPACE = "sRGB"
VIEW_TRANSFORM = "Raw"
VIEW_TRANSFORM = "Standard"
MARMOSET_COMPATIBLE = False
SUPPORTED_ENGINES = (
('blender_eevee', "Eevee", ""),
('cycles', "Cycles", "")
)

def draw_properties(self, context: Context, layout: UILayout):
col = layout.column()
if context.scene.gd.baker_type == 'blender':
col.prop(self, 'invert', text="Invert")

def update_alpha(self, context: Context):
gd_camera_ob_z = bpy.data.objects.get(
Global.TRIM_CAMERA_NAME
).location[2]
map_range = \
bpy.data.node_groups[self.NODE].nodes.get('Map Range')
map_range.inputs[1].default_value = gd_camera_ob_z - .00001
map_range.inputs[2].default_value = gd_camera_ob_z
invert = \
bpy.data.node_groups[self.NODE].nodes.get('Invert')
invert.inputs[0].default_value = 0 if self.invert else 1

invert: BoolProperty(
description="Invert the Alpha mask",
update=update_alpha
)
engine: EnumProperty(
items=SUPPORTED_ENGINES,
name='Render Engine',
update=Baker.apply_render_settings
)


class Id(Baker, PropertyGroup):
ID = Global.MATERIAL_ID
NAME = Global.MATERIAL_NAME
Expand Down Expand Up @@ -671,12 +630,57 @@ def update_method(self, context: Context):
)


class Alpha(Baker, PropertyGroup):
ID = Global.ALPHA_ID
NAME = Global.ALPHA_NAME
NODE = Global.ALPHA_NODE
COLOR_SPACE = "sRGB"
VIEW_TRANSFORM = "Raw"
VIEW_TRANSFORM = "Standard"
MARMOSET_COMPATIBLE = False
SUPPORTED_ENGINES = (
('blender_eevee', "Eevee", ""),
('cycles', "Cycles", "")
)

def draw_properties(self, context: Context, layout: UILayout):
col = layout.column()
if context.scene.gd.baker_type == 'blender':
col.prop(self, 'invert_depth', text="Invert Depth")
col.prop(self, 'invert_mask', text="Invert Mask")

def update_alpha(self, _context: Context):
gd_camera_ob_z = \
bpy.data.objects.get(Global.TRIM_CAMERA_NAME).location[2]
map_range = bpy.data.node_groups[self.NODE].nodes.get('Map Range')
map_range.inputs[1].default_value = gd_camera_ob_z - .00001
map_range.inputs[2].default_value = gd_camera_ob_z
invert_depth = bpy.data.node_groups[self.NODE].nodes.get('Invert Depth')
invert_depth.inputs[0].default_value = 0 if self.invert_depth else 1
invert_mask = bpy.data.node_groups[self.NODE].nodes.get('Invert Mask')
invert_mask.inputs[0].default_value = 0 if self.invert_mask else 1

invert_depth: BoolProperty(
description="Invert the global depth mask",
update=update_alpha
)
invert_mask: BoolProperty(
description="Invert the alpha mask",
update=update_alpha
)
engine: EnumProperty(
items=SUPPORTED_ENGINES,
name='Render Engine',
update=Baker.apply_render_settings
)


class Color(Baker, PropertyGroup):
ID = Global.COLOR_ID
NAME = Global.COLOR_NAME
NODE = Global.COLOR_NODE
COLOR_SPACE = "sRGB"
VIEW_TRANSFORM = "Raw"
VIEW_TRANSFORM = "Standard"
MARMOSET_COMPATIBLE = False
SUPPORTED_ENGINES = (
('blender_eevee', "Eevee", ""),
Expand All @@ -695,7 +699,7 @@ class Emissive(Baker, PropertyGroup):
NAME = Global.EMISSIVE_NAME
NODE = Global.EMISSIVE_NODE
COLOR_SPACE = "sRGB"
VIEW_TRANSFORM = "Raw"
VIEW_TRANSFORM = "Standard"
MARMOSET_COMPATIBLE = False
SUPPORTED_ENGINES = (
('blender_eevee', "Eevee", ""),
Expand Down Expand Up @@ -727,8 +731,7 @@ def draw_properties(self, context: Context, layout: UILayout):
col.prop(self, 'invert', text="Invert")

def update_roughness(self, _context: Context):
invert = \
bpy.data.node_groups[self.NODE].nodes.get('Invert')
invert = bpy.data.node_groups[self.NODE].nodes.get('Invert')
invert.inputs[0].default_value = 1 if self.invert else 0

invert: BoolProperty(
Expand All @@ -742,10 +745,10 @@ def update_roughness(self, _context: Context):
)


class Metalness(Baker, PropertyGroup):
ID = Global.METALNESS_ID
NAME = Global.METALNESS_NAME
NODE = Global.METALNESS_NODE
class Metallic(Baker, PropertyGroup):
ID = Global.METALLIC_ID
NAME = Global.METALLIC_NAME
NODE = Global.METALLIC_NODE
COLOR_SPACE = "sRGB"
VIEW_TRANSFORM = "Raw"
MARMOSET_COMPATIBLE = False
Expand Down Expand Up @@ -843,7 +846,7 @@ def reimport_as_material(map_names: list[str]) -> None:
continue
image.image = bpy.data.images.load(export_path, check_existing=True)

# NOTE: Unique exceptions for specific bake maps
# NOTE: Unique bake map exceptions
if name not in (Global.COLOR_ID, Global.EMISSIVE_ID):
image.image.colorspace_settings.name = 'Non-Color'
if name == Global.NORMAL_ID:
Expand All @@ -859,12 +862,12 @@ def reimport_as_material(map_names: list[str]) -> None:
links.new(bsdf.inputs["Base Color"], image.outputs["Color"])
elif name == Global.EMISSIVE_ID:
links.new(bsdf.inputs["Emission Color"], image.outputs["Color"])
elif name == Global.METALNESS_ID:
elif name == Global.METALLIC_ID:
links.new(bsdf.inputs["Metallic"], image.outputs["Color"])
elif name == Global.CURVATURE_ID:
continue
elif name == Global.OCCLUSION_ID:
# TODO: Could mix AO with Base Color in the future, not PBR
# TODO: Could mix AO with Base Color in the future
continue
elif name == Global.HEIGHT_ID:
continue
Expand Down
Loading

0 comments on commit 37ea3dd

Please sign in to comment.