Skip to content

Commit

Permalink
Interim Submit
Browse files Browse the repository at this point in the history
  • Loading branch information
oRazeD committed Jan 1, 2024
1 parent c4ffe90 commit 11fa69a
Show file tree
Hide file tree
Showing 13 changed files with 1,820 additions and 1,969 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ README.md
_temp/

grabdocgit_updater/

utils/temp/
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"author": "Ethan Simon-Law",
"location": "3D View > Sidebar > GrabDoc",
"version": (1, 4, 0),
"blender": (4, 0, 1),
"blender": (4, 0, 2),
"tracker_url": "https://discord.com/invite/wHAyVZG",
"category": "3D View"
}
Expand Down
105 changes: 64 additions & 41 deletions constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,38 +9,66 @@

NAME = "GrabDoc Pro"
VERSION = (1, 4, 0)
BLENDER_VERSION = (4, 0, 1)
BLENDER_VERSION = (4, 0, 2)


class GlobalVariableConstants:
"""A collection of constants used for global variable standardization"""
ID_PREFIX = "grab_doc" # TODO: wrong prefix?

REFERENCE_NAME = "GD_Reference"
TRIM_CAMERA_NAME = "GD_Trim Camera"
BG_PLANE_NAME = "GD_Background Plane"
GD_PREFIX = "GD_"
GD_FLAG_PREFIX = "[GrabDoc] "
GD_LOW_PREFIX = GD_PREFIX + "low"
GD_HIGH_PREFIX = GD_PREFIX + "high"

REFERENCE_NAME = GD_PREFIX + "Reference"
TRIM_CAMERA_NAME = GD_PREFIX + "Trim Camera"
BG_PLANE_NAME = GD_PREFIX + "Background Plane"
HEIGHT_GUIDE_NAME = GD_PREFIX + "Height Guide"
ORIENT_GUIDE_NAME = GD_PREFIX + "Orient Guide"
GD_MATERIAL_NAME = GD_PREFIX + "Material (do not touch contents)"
COLL_NAME = "GrabDoc (do not touch contents)"
COLL_OB_NAME = "GrabDoc Objects (put objects here)"
HEIGHT_GUIDE_NAME = "GD_Height Guide"
ORIENT_GUIDE_NAME = "GD_Orient Guide"
GD_MATERIAL_NAME = "GD_Material (do not touch contents)"

GD_PREFIX = "GD_"
GD_LOW_PREFIX = "GD_low"
GD_HIGH_PREFIX = "GD_high"

MAT_ID_PREFIX = "GD_ID"
MAT_ID_RAND_PREFIX = "GD_RANDOM_ID"
MAT_ID_PREFIX = GD_PREFIX + "ID"
MAT_ID_RAND_PREFIX = GD_PREFIX + "RANDOM_ID"

REIMPORT_MAT_NAME = GD_FLAG_PREFIX + "Render Result"

NORMAL_NAME = "Normal"
AO_NAME = "Ambient Occlusion"
HEIGHT_NAME = "Height"
ALPHA_NAME = "Alpha"
COLOR_NAME = "Base Color"
ROUGHNESS_NAME = "Roughness"
METALNESS_NAME = "Metalness"

NORMAL_NG_NAME = GD_PREFIX + NORMAL_NAME
AO_NG_NAME = GD_PREFIX + AO_NAME
HEIGHT_NG_NAME = GD_PREFIX + HEIGHT_NAME
ALPHA_NG_NAME = GD_PREFIX + ALPHA_NAME
COLOR_NG_NAME = GD_PREFIX + COLOR_NAME
ROUGHNESS_NG_NAME = GD_PREFIX + ROUGHNESS_NAME
METALNESS_NG_NAME = GD_PREFIX + METALNESS_NAME

ALL_MAP_NAMES = (
NORMAL_NAME,
AO_NAME,
HEIGHT_NAME,
ALPHA_NAME,
COLOR_NAME,
ROUGHNESS_NAME,
METALNESS_NAME
)

NG_NORMAL_NAME = "GD_Normal"
NG_AO_NAME = "GD_Ambient Occlusion"
NG_HEIGHT_NAME = "GD_Height"
NG_ALPHA_NAME = "GD_Alpha"
NG_ALBEDO_NAME = "GD_Albedo"
NG_ROUGHNESS_NAME = "GD_Roughness"
NG_METALNESS_NAME = "GD_Metalness"
SHADER_MAP_NAMES = (
COLOR_NG_NAME,
ROUGHNESS_NG_NAME,
METALNESS_NG_NAME,
NORMAL_NG_NAME
)

INVALID_RENDER_TYPES = (
INVALID_BAKE_TYPES = (
'EMPTY',
'VOLUME',
'ARMATURE',
Expand All @@ -50,7 +78,7 @@ class GlobalVariableConstants:
'CAMERA'
)

FORMAT_MATCHED_EXTENSIONS = {
IMAGE_FORMATS = {
'TIFF': 'tif',
'TARGA': 'tga',
'OPEN_EXR': 'exr',
Expand All @@ -64,11 +92,12 @@ class GlobalVariableConstants:
only happens when you use the `Remove Setup` operator."""

PACK_MAPS_WARNING = \
"""Map Packing is a new feature in GrabDoc for optimizing textures being exported (usually
directly to engine) by cramming grayscale baked maps into each RGBA channel of a single
texture reducing the amount of texture samples used and by extension the memory footprint.
This is meant to be a simple alternative to pit-stopping over to compositing software to
finish the job, but its usability is limited.
"""Map Packing is a new feature in GrabDoc for optimizing textures being
exported (usually directly to engine) by cramming grayscale baked maps into
each RGBA channel of a single texture reducing the amount of texture samples
used and by extension the memory footprint. This is meant to be a simple
alternative to pit-stopping over to compositing software to finish the job
but its usability is limited.
Map Packing in GrabDoc is new, so here's a few things to keep note of:
\u2022 Only grayscale maps can currently be packed
Expand All @@ -79,41 +108,35 @@ class GlobalVariableConstants:
bake maps, meaning without intervention G, B, and A channels will be empty."""

PREVIEW_WARNING = \
"""Live Material Preview allows you to visualize your bake maps in real-time!
This feature is intended for previewing your materials, NOT for working while inside
the preview. Once finished please exit previews to avoid scene altering changes.
Pressing `OK` will dismiss this warning permanently for the current project file."""
"""Material Preview allows you to visualize your bake maps in real-time!
\u2022 This feature is intended for previewing your materials before baking, NOT
\u2022 for working while inside a preview. Once finished, please exit previews
\u2022 to avoid scene altering changes.
\u2022 Pressing OK will dismiss this warning permanently for the project."""


class ErrorCodeConstants:
"""A collection of constants used for error code/message standardization"""

NO_OBJECTS_SELECTED = "There are no objects selected"

TRIM_CAM_NOT_FOUND = \
"Trim Camera not found, refresh the scene to set everything up properly"
"GrabDoc Camera not found, please run the Refresh Scene operator"
NO_OBJECTS_BAKE_GROUPS = \
"You have 'Use Bake Group' turned on, but no objects are inside the corresponding collection"
"No objects found in bake collections"
NO_VALID_PATH_SET = \
"There is no export path set"

MAT_SLOTS_WITHOUT_LINKS = \
"Material slots found without links & will be rendered using the sockets default value"

"Material slots were found without links, using default values"
MARMOSET_EXPORT_COMPLETE = \
"Export completed! Opening Marmoset Toolbag..."
MARMOSET_RE_EXPORT_COMPLETE = \
"Models re-exported! Check Marmoset Toolbag"

OFFLINE_RENDER_COMPLETE = \
"Offline render completed!"
EXPORT_COMPLETE = \
"Export completed!"



# ##### BEGIN GPL LICENSE BLOCK #####
#
# This program is free software; you can redistribute it and/or
Expand Down
81 changes: 41 additions & 40 deletions operators/marmoset.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
from ..constants import ErrorCodeConstants as Error
from ..utils.generic import (
bad_setup_check,
export_bg_plane,
export_plane,
get_create_addon_temp_dir
)
from ..utils.render import set_guide_height
from ..utils.render import set_guide_height, get_rendered_objects


################################################
Expand All @@ -40,49 +40,48 @@ class GrabDoc_OT_send_to_marmo(OpInfo, Operator):
@classmethod
def poll(cls, context: Context) -> bool:
return os.path.exists(
context.preferences.addons[__package__].preferences.marmoEXE
context.preferences.addons[__package__].preferences.marmoset_executable
)

def open_marmoset(self, context: Context, temps_path, addon_path):
gd = context.scene.grabDoc
marmo_exe = context.preferences.addons[__package__].preferences.marmoEXE
gd = context.scene.gd
marmo_exe = context.preferences.addons[__package__].preferences.marmoset_executable

# Create a dictionary of variables to transfer into Marmoset
marmo_vars = {
'file_path': f'{bpy.path.abspath(gd.exportPath)}{gd.exportName}.{gd.imageType_marmo.lower()}',
'file_ext': gd.imageType_marmo.lower(),
'file_path_no_ext': bpy.path.abspath(gd.exportPath),
'file_path': f'{bpy.path.abspath(gd.export_path)}{gd.export_name}.{gd.marmoset_format.lower()}',
'file_ext': gd.marmoset_format.lower(),
'file_path_no_ext': bpy.path.abspath(gd.export_path),
'marmo_sky_path': f'{os.path.dirname(marmo_exe)}\\data\\sky\\Evening Clouds.tbsky',

'resolution_x': gd.exportResX,
'resolution_y': gd.exportResY,
'bits_per_channel': int(gd.colorDepth),
'samples': int(gd.marmoSamples),
'resolution_x': gd.export_res_x,
'resolution_y': gd.export_res_y,
'bits_per_channel': int(gd.depth),
'samples': int(gd.marmoset_samples),

'auto_bake': gd.marmoAutoBake,
'close_after_bake': gd.marmoClosePostBake,
'open_folder': gd.openFolderOnExport,
'auto_bake': gd.metalness_auto_bake,
'close_after_bake': gd.marmoset_auto_close,

'export_normal': gd.exportNormals & gd.uiVisibilityNormals,
'flipy_normal': gd.flipYNormals,
'suffix_normal': gd.suffixNormals,
'export_normal': gd.normals[0].enabled & gd.normals[0].ui_visibility,
'flipy_normal': gd.normals[0].flip_y,
'suffix_normal': gd.normals[0].suffix,

'export_curvature': gd.exportCurvature & gd.uiVisibilityCurvature,
'suffix_curvature': gd.suffixCurvature,
'export_curvature': gd.curvature[0].enabled & gd.curvature[0].ui_visibility,
'suffix_curvature': gd.curvature[0].suffix,

'export_occlusion': gd.exportOcclusion & gd.uiVisibilityOcclusion,
'ray_count_occlusion': gd.marmoAORayCount,
'suffix_occlusion': gd.suffixOcclusion,
'export_occlusion': gd.occlusion[0].enabled & gd.occlusion[0].ui_visibility,
'ray_count_occlusion': gd.marmoset_occlusion_ray_count,
'suffix_occlusion': gd.occlusion[0].suffix,

'export_height': gd.exportHeight & gd.uiVisibilityHeight,
'cage_height': gd.guideHeight * 100 * 2,
'suffix_height': gd.suffixHeight,
'export_height': gd.height[0].enabled & gd.height[0].ui_visibility,
'cage_height': gd.height[0].distance * 100 * 2,
'suffix_height': gd.height[0].suffix,

'export_alpha': gd.exportAlpha & gd.uiVisibilityAlpha,
'suffix_alpha': gd.suffixAlpha,
'export_alpha': gd.alpha[0].enabled & gd.alpha[0].ui_visibility,
'suffix_alpha': gd.alpha[0].suffix,

'export_matid': gd.exportMatID & gd.uiVisibilityMatID,
'suffix_id': gd.suffixID
'export_matid': gd.id[0].enabled & gd.id[0].ui_visibility,
'suffix_id': gd.id[0].suffix
}

# Flip the slashes of the first Dict value (It's
Expand All @@ -103,8 +102,8 @@ def open_marmoset(self, context: Context, temps_path, addon_path):

path_ext_only = os.path.basename(os.path.normpath(marmo_exe)).encode()

if gd.exportPlane:
export_bg_plane(context)
if gd.export_plane:
export_plane(context)

subproc_args = [
marmo_exe,
Expand All @@ -128,9 +127,10 @@ def open_marmoset(self, context: Context, temps_path, addon_path):
return {'FINISHED'}

def execute(self, context: Context):
gd = context.scene.grabDoc
gd = context.scene.gd

report_value, report_string = bad_setup_check(self, context, active_export=True)
report_value, report_string = \
bad_setup_check(context, active_export=True)
if report_value:
self.report({'ERROR'}, report_string)
return {'CANCELLED'}
Expand All @@ -142,14 +142,15 @@ def execute(self, context: Context):
if bpy.ops.object.mode_set.poll():
bpy.ops.object.mode_set(mode='OBJECT')

if gd.exportHeight and gd.rangeTypeHeight == 'AUTO':
set_guide_height()
rendered_obs = get_rendered_objects()
if gd.height[0].enabled and gd.height[0].method == 'AUTO':
set_guide_height(rendered_obs)

# Set high poly naming
for ob in context.view_layer.objects:
ob.select_set(False)

if ob.name in self.rendered_obs \
if ob.name in rendered_obs \
and ob.visible_get() and ob.name != Global.BG_PLANE_NAME:
ob.select_set(True)

Expand All @@ -165,7 +166,8 @@ def execute(self, context: Context):
# Copy the object, link into the scene & rename as high poly
bg_plane_ob_copy = bg_plane_ob.copy()
context.collection.objects.link(bg_plane_ob_copy)
bg_plane_ob_copy.name = f"{Global.GD_HIGH_PREFIX} {Global.BG_PLANE_NAME}"
bg_plane_ob_copy.name = \
f"{Global.GD_HIGH_PREFIX} {Global.BG_PLANE_NAME}"
bg_plane_ob_copy.select_set(True)

# Remove reference material
Expand All @@ -185,13 +187,12 @@ def execute(self, context: Context):

for ob in context.selected_objects:
ob.select_set(False)

if ob.name == f"{Global.GD_LOW_PREFIX} {Global.BG_PLANE_NAME}":
ob.name = Global.BG_PLANE_NAME
else:
ob.name = ob.name[8:] # TODO: what does this represent?

if not gd.collSelectable:
if not gd.coll_selectable:
bpy.data.collections[Global.COLL_NAME].hide_select = True

for ob_name in saved_selected:
Expand Down
Loading

0 comments on commit 11fa69a

Please sign in to comment.