Major Terminogy unification and refactor [Needs thorough testing]
This commit is contained in:
@@ -55,9 +55,9 @@ REFERENCE_MAP_TYPES = ["COL", "COL-1", "COL-2"]
|
||||
REFERENCE_RESOLUTION_ORDER = ["1K", "512", "2K", "4K"] # Adjust as needed
|
||||
|
||||
# Assumed filename pattern for processed images.
|
||||
# {asset_name}, {map_type}, {resolution}, {format} will be replaced.
|
||||
# Check Asset Processor Tool's config.py (TARGET_FILENAME_PATTERN) if this is wrong.
|
||||
IMAGE_FILENAME_PATTERN = "{asset_name}_{map_type}_{resolution}.{format}"
|
||||
# [assetname], [maptype], [resolution], [ext] will be replaced.
|
||||
# This should match OUTPUT_FILENAME_PATTERN from app_settings.json.
|
||||
IMAGE_FILENAME_PATTERN = "[assetname]_[maptype]_[resolution].[ext]"
|
||||
|
||||
# Fallback extensions to try if the primary format from metadata is not found
|
||||
# Order matters - first found will be used.
|
||||
@@ -126,10 +126,10 @@ def reconstruct_image_path_with_fallback(asset_dir_path, asset_name, map_type, r
|
||||
if primary_format:
|
||||
try:
|
||||
filename = IMAGE_FILENAME_PATTERN.format(
|
||||
asset_name=asset_name,
|
||||
map_type=map_type,
|
||||
resolution=resolution,
|
||||
format=primary_format.lower() # Ensure format is lowercase
|
||||
assetname=asset_name, # Token is 'assetname'
|
||||
maptype=map_type, # Token is 'maptype'
|
||||
resolution=resolution, # Token is 'resolution'
|
||||
ext=primary_format.lower() # Token is 'ext'
|
||||
)
|
||||
primary_path = asset_dir_path / filename
|
||||
if primary_path.is_file():
|
||||
@@ -151,10 +151,10 @@ def reconstruct_image_path_with_fallback(asset_dir_path, asset_name, map_type, r
|
||||
continue
|
||||
try:
|
||||
fallback_filename = IMAGE_FILENAME_PATTERN.format(
|
||||
asset_name=asset_name,
|
||||
map_type=map_type,
|
||||
resolution=resolution,
|
||||
format=ext.lower()
|
||||
assetname=asset_name, # Token is 'assetname'
|
||||
maptype=map_type, # Token is 'maptype'
|
||||
resolution=resolution, # Token is 'resolution'
|
||||
ext=ext.lower() # Token is 'ext'
|
||||
)
|
||||
fallback_path = asset_dir_path / fallback_filename
|
||||
if fallback_path.is_file():
|
||||
|
||||
@@ -52,9 +52,9 @@ HIGHEST_RESOLUTION_NODE_LABEL = "HighestResolution" # Value node to store highes
|
||||
ENABLE_MANIFEST = False # Disabled based on user feedback in previous run
|
||||
|
||||
# Assumed filename pattern for processed images.
|
||||
# {asset_name}, {map_type}, {resolution}, {format} will be replaced.
|
||||
# Check Asset Processor Tool's config.py (TARGET_FILENAME_PATTERN) if this is wrong.
|
||||
IMAGE_FILENAME_PATTERN = "{asset_name}_{map_type}_{resolution}.{format}"
|
||||
# [assetname], [maptype], [resolution], [ext] will be replaced.
|
||||
# This should match OUTPUT_FILENAME_PATTERN from app_settings.json.
|
||||
IMAGE_FILENAME_PATTERN = "[assetname]_[maptype]_[resolution].[ext]"
|
||||
|
||||
# Fallback extensions to try if the primary format from metadata is not found
|
||||
# Order matters - first found will be used.
|
||||
@@ -150,10 +150,32 @@ def add_tag_if_new(asset_data, tag_name):
|
||||
|
||||
def get_color_space(map_type):
|
||||
"""Returns the appropriate Blender color space name for a given map type string."""
|
||||
# Handle potential numbered variants like COL-1, COL-2
|
||||
base_map_type = map_type.split('-')[0]
|
||||
return PBR_COLOR_SPACE_MAP.get(map_type.upper(), # Check full name first (e.g., NRMRGH)
|
||||
PBR_COLOR_SPACE_MAP.get(base_map_type.upper(), DEFAULT_COLOR_SPACE)) # Fallback to base type
|
||||
# Attempt to map map_type (e.g., "MAP_COL", "COL-1", "NRMRGH") to a standard type for color space lookup.
|
||||
# PBR_COLOR_SPACE_MAP usually contains standard types like "COL", "NRM".
|
||||
map_type_upper = map_type.upper()
|
||||
|
||||
# 1. Direct match (e.g., "NRMRGH", "COL")
|
||||
if map_type_upper in PBR_COLOR_SPACE_MAP:
|
||||
return PBR_COLOR_SPACE_MAP[map_type_upper]
|
||||
|
||||
# 2. Handle variants like "COL-1", "MAP_ROUGH-2"
|
||||
# Try to get the part before a hyphen if a hyphen exists
|
||||
base_type_candidate = map_type_upper.split('-')[0]
|
||||
if base_type_candidate in PBR_COLOR_SPACE_MAP:
|
||||
return PBR_COLOR_SPACE_MAP[base_type_candidate]
|
||||
|
||||
# 3. Handle cases like "MAP_COL" -> "COL"
|
||||
# This is a simple heuristic. A more robust solution would involve access to FILE_TYPE_DEFINITIONS.
|
||||
# For this script, we assume PBR_COLOR_SPACE_MAP might contain the direct standard_type.
|
||||
# Example: if map_type is "MAP_DIFFUSE" and PBR_COLOR_SPACE_MAP has "DIFFUSE"
|
||||
if base_type_candidate.startswith("MAP_") and len(base_type_candidate) > 4:
|
||||
short_type = base_type_candidate[4:] # Get "COL" from "MAP_COL"
|
||||
if short_type in PBR_COLOR_SPACE_MAP:
|
||||
return PBR_COLOR_SPACE_MAP[short_type]
|
||||
|
||||
# Fallback if no specific rule found
|
||||
# print(f" Debug: Color space for '{map_type}' (candidates: '{map_type_upper}', '{base_type_candidate}') not found in PBR_COLOR_SPACE_MAP. Using default: {DEFAULT_COLOR_SPACE}")
|
||||
return DEFAULT_COLOR_SPACE
|
||||
|
||||
def calculate_aspect_correction_factor(image_width, image_height, aspect_string):
|
||||
"""
|
||||
@@ -234,10 +256,10 @@ def reconstruct_image_path_with_fallback(asset_dir_path, asset_name, map_type, r
|
||||
if primary_format:
|
||||
try:
|
||||
filename = IMAGE_FILENAME_PATTERN.format(
|
||||
asset_name=asset_name,
|
||||
map_type=map_type,
|
||||
resolution=resolution,
|
||||
format=primary_format.lower() # Ensure format is lowercase
|
||||
assetname=asset_name, # Token is 'assetname'
|
||||
maptype=map_type, # Token is 'maptype'
|
||||
resolution=resolution, # Token is 'resolution'
|
||||
ext=primary_format.lower() # Token is 'ext'
|
||||
)
|
||||
primary_path = asset_dir_path / filename
|
||||
if primary_path.is_file():
|
||||
@@ -259,10 +281,10 @@ def reconstruct_image_path_with_fallback(asset_dir_path, asset_name, map_type, r
|
||||
continue
|
||||
try:
|
||||
fallback_filename = IMAGE_FILENAME_PATTERN.format(
|
||||
asset_name=asset_name,
|
||||
map_type=map_type,
|
||||
resolution=resolution,
|
||||
format=ext.lower()
|
||||
assetname=asset_name, # Token is 'assetname'
|
||||
maptype=map_type, # Token is 'maptype'
|
||||
resolution=resolution, # Token is 'resolution'
|
||||
ext=ext.lower() # Token is 'ext'
|
||||
)
|
||||
fallback_path = asset_dir_path / fallback_filename
|
||||
if fallback_path.is_file():
|
||||
@@ -493,7 +515,7 @@ def process_library(context, asset_library_root_override=None): # Add override p
|
||||
asset_name = metadata.get("asset_name")
|
||||
supplier_name = metadata.get("supplier_name")
|
||||
archetype = metadata.get("archetype")
|
||||
asset_category = metadata.get("asset_category", "Unknown") # Read asset_category instead of category
|
||||
asset_category = metadata.get("category", "Unknown") # Read "category" key from metadata
|
||||
# Get map info from the correct keys
|
||||
processed_resolutions = metadata.get("processed_map_resolutions", {}) # Default to empty dict
|
||||
merged_resolutions = metadata.get("merged_map_resolutions", {}) # Get merged maps too
|
||||
|
||||
Reference in New Issue
Block a user