Skip to content

Commit

Permalink
Stability adjustments
Browse files Browse the repository at this point in the history
Found some bugs in deeper testing
  • Loading branch information
oRazeD committed Jan 8, 2025
1 parent 9ca7b9e commit 4486964
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 22 deletions.
22 changes: 22 additions & 0 deletions __init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@
import importlib

import bpy
from bpy.app.handlers import persistent

from .ui import register_baker_panels


#########################
# HANDLERS
#########################


@persistent
def load_post_handler(_dummy):
register_baker_panels()


#########################
# REGISTRATION
#########################


module_names = (
"operators.core",
Expand All @@ -19,6 +39,8 @@ def register():
for mod in modules:
mod.register()

bpy.app.handlers.load_post.append(load_post_handler)

def unregister():
for mod in modules:
mod.unregister()
24 changes: 16 additions & 8 deletions baker.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ def __init__(self):
"""Called when `bpy.ops.grab_doc.scene_setup` operator is ran.
This method is NOT called when created via `CollectionProperty`."""
gd = bpy.context.scene.gd
self.index = self.get_unique_index(getattr(gd, self.ID))
self.node_input = None
self.node_output = None

Expand All @@ -63,6 +61,14 @@ def __init__(self):
name="Export Enabled", default=self.MARMOSET_COMPATIBLE
)

if self.index == -1:
gd = bpy.context.scene.gd
self.index = self.get_unique_index(getattr(gd, self.ID))
if self.index > 0:
self.node_name = self.get_node_name(self.NAME, self.index+1)
if not self.suffix[-1].isdigit():
self.suffix = f"{self.suffix}_{self.index+1}"

@staticmethod
def get_unique_index(collection: CollectionProperty) -> int:
"""Get a unique index value based on a given `CollectionProperty`."""
Expand Down Expand Up @@ -383,7 +389,7 @@ class Curvature(Baker):
VIEW_TRANSFORM = "Standard"
MARMOSET_COMPATIBLE = True
REQUIRED_SOCKETS = ()
OPTIONAL_SOCKETS = Baker.OPTIONAL_SOCKETS
OPTIONAL_SOCKETS = ()
SUPPORTED_ENGINES = Baker.SUPPORTED_ENGINES[1:]

def __init__(self):
Expand Down Expand Up @@ -562,7 +568,7 @@ class Height(Baker):
VIEW_TRANSFORM = "Raw"
MARMOSET_COMPATIBLE = True
REQUIRED_SOCKETS = ()
OPTIONAL_SOCKETS = Baker.OPTIONAL_SOCKETS
OPTIONAL_SOCKETS = ()
SUPPORTED_ENGINES = Baker.SUPPORTED_ENGINES[:-1]

def setup(self) -> None:
Expand Down Expand Up @@ -792,7 +798,7 @@ class Roughness(Baker):
VIEW_TRANSFORM = "Raw"
MARMOSET_COMPATIBLE = False
REQUIRED_SOCKETS = (NAME,)
OPTIONAL_SOCKETS = Baker.OPTIONAL_SOCKETS
OPTIONAL_SOCKETS = ()
SUPPORTED_ENGINES = Baker.SUPPORTED_ENGINES[:-1]

def node_setup(self):
Expand Down Expand Up @@ -832,7 +838,7 @@ class Color(Baker):
VIEW_TRANSFORM = "Standard"
MARMOSET_COMPATIBLE = False
REQUIRED_SOCKETS = (NAME,)
OPTIONAL_SOCKETS = Baker.OPTIONAL_SOCKETS
OPTIONAL_SOCKETS = ()
SUPPORTED_ENGINES = Baker.SUPPORTED_ENGINES[:-1]

def node_setup(self):
Expand Down Expand Up @@ -863,7 +869,7 @@ class Emissive(Baker):
VIEW_TRANSFORM = "Standard"
MARMOSET_COMPATIBLE = False
REQUIRED_SOCKETS = ("Emission Color", "Emission Strength")
OPTIONAL_SOCKETS = Baker.OPTIONAL_SOCKETS
OPTIONAL_SOCKETS = ()
SUPPORTED_ENGINES = Baker.SUPPORTED_ENGINES[:-1]

def node_setup(self):
Expand All @@ -883,6 +889,8 @@ def node_setup(self):
links = self.node_tree.links
links.new(emission.inputs["Color"],
self.node_input.outputs["Emission Color"])
links.new(emission.inputs["Strength"],
self.node_input.outputs["Emission Strength"])
links.new(self.node_output.inputs["Shader"],
emission.outputs["Emission"])

Expand All @@ -899,7 +907,7 @@ class Metallic(Baker):
VIEW_TRANSFORM = "Raw"
MARMOSET_COMPATIBLE = False
REQUIRED_SOCKETS = (NAME,)
OPTIONAL_SOCKETS = Baker.OPTIONAL_SOCKETS
OPTIONAL_SOCKETS = ()
SUPPORTED_ENGINES = Baker.SUPPORTED_ENGINES[:-1]

def node_setup(self):
Expand Down
2 changes: 1 addition & 1 deletion blender_manifest.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
schema_version = "1.0.0"

id = "GrabDoc"
version = "2.0.1"
version = "2.0.0"
name = "GrabDoc"
tagline = "A trim & tileable baker for Blender"
maintainer = "Ethan Simon-Law <[email protected]>"
Expand Down
19 changes: 12 additions & 7 deletions operators/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def execute(self, context: Context):
for baker_prop in get_baker_collections():
baker_prop.clear()
baker = baker_prop.add()
baker.__init__() # pylint: disable=C2801

register_baker_panels()
scene_setup(self, context)
Expand Down Expand Up @@ -124,7 +123,6 @@ class GRABDOC_OT_baker_add(Operator):
def execute(self, context: Context):
baker_prop = getattr(context.scene.gd, self.map_type)
baker = baker_prop.add()
baker.__init__() # pylint: disable=C2801
register_baker_panels()
baker.node_setup()
return {'FINISHED'}
Expand All @@ -144,7 +142,10 @@ def execute(self, context: Context):
baker = get_baker_by_index(baker_prop, self.baker_index)
if baker.node_tree:
bpy.data.node_groups.remove(baker.node_tree)
baker_prop.remove(self.baker_index)
for idx, bake_map in enumerate(baker_prop):
if bake_map.index == baker.index:
baker_prop.remove(idx)
break
register_baker_panels()
return {'FINISHED'}

Expand Down Expand Up @@ -415,7 +416,7 @@ class GRABDOC_OT_baker_preview(Operator):
"""Preview the selected bake map type"""
bl_idname = "grab_doc.baker_preview"
bl_label = ""
bl_options = {'REGISTER', 'INTERNAL'}
bl_options = {'REGISTER', 'UNDO', 'INTERNAL'}

baker_index: IntProperty()
map_type: StringProperty()
Expand Down Expand Up @@ -491,9 +492,9 @@ def execute(self, context: Context):
# TODO: Necessary to save?
self.saved_properties['bpy.context.scene.gd.engine'] = gd.engine

gd.preview_state = True
gd.preview_map_type = self.map_type
gd.engine = 'grabdoc'
gd.preview_state = True
gd.preview_map_type = self.map_type
gd.engine = 'grabdoc'

self.last_ob_amount = len(bpy.data.objects)
self.disable_binds = not self.user_preferences.disable_preview_binds
Expand Down Expand Up @@ -549,6 +550,10 @@ class GRABDOC_OT_baker_preview_export(Operator):

@classmethod
def poll(cls, context: Context) -> bool:
gd = context.scene.gd
if gd.filepath == "//" and not bpy.data.filepath:
cls.poll_message_set("Relative export path but file not saved")
return False
return not GRABDOC_OT_baker_export_single.poll(context)

def execute(self, context: Context):
Expand Down
10 changes: 4 additions & 6 deletions ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def draw_header(self, context: Context):
row2.prop(self.baker, 'enabled', text="")
preview = row2.operator("grab_doc.baker_preview", text=text)
preview.map_type = self.baker.ID
preview.baker_index = index
preview.baker_index = self.baker.index
row2.operator("grab_doc.baker_export_single",
text="", icon='RENDER_STILL').map_type = self.baker.ID

Expand All @@ -312,7 +312,7 @@ def draw_header(self, context: Context):
return
remove = row.operator("grab_doc.baker_remove", text="", icon='TRASH')
remove.map_type = self.baker.ID
remove.baker_index = index
remove.baker_index = self.baker.index

def draw(self, context: Context):
self.baker.draw(context, self.layout)
Expand All @@ -329,13 +329,11 @@ def create_baker_panels():
baker_classes = []
for baker_prop in get_baker_collections():
for baker in baker_prop:
if baker.index == -1:
baker.__init__() # pylint: disable=C2801
class_name = f"GRABDOC_PT_{baker.ID}_{baker.index}"
panel_cls = type(class_name, (BakerPanel,), {})
panel_cls.baker = baker
if baker.index > 0:
baker.node_name = baker.get_node_name(baker.NAME, baker.index+1)
if not baker.suffix[-1].isdigit():
baker.suffix = f"{baker.suffix}_{baker.index+1}"
baker_classes.append(panel_cls)
return baker_classes

Expand Down

0 comments on commit 4486964

Please sign in to comment.