fix orange and white
This commit is contained in:
@@ -220,7 +220,8 @@ def replace_cel_materials():
|
||||
"cel WHITE": "BSDF_WHITE",
|
||||
"gray (stone)": "BSDF_gray-3_STONE",
|
||||
"green (oxygen)": "BSDF_green-3_OXYGEN",
|
||||
"orange (smile)": "BSDF_orange-3_SMILE"
|
||||
"orange (smile)": "BSDF_orange-3_SMILE",
|
||||
"orange (blaze)": "BSDF_orange-1_BLAZE"
|
||||
}
|
||||
|
||||
# Get all materials in the scene
|
||||
@@ -238,19 +239,59 @@ def replace_cel_materials():
|
||||
|
||||
# Build a mapping from exact material names to materials
|
||||
exact_material_map = {mat.name: mat for mat in materials}
|
||||
|
||||
# Helpers to normalize names (case-insensitive, ignore numeric suffixes and library suffix)
|
||||
def normalize_base(name):
|
||||
base_name = name.split(".blend")[0] if ".blend" in name else name
|
||||
match = re.match(r"^(.*?)(\.\d{3})?$", base_name)
|
||||
base_name = match.group(1) if match else base_name
|
||||
return base_name.strip().casefold()
|
||||
|
||||
# Map normalized base name -> list of materials
|
||||
materials_by_base = {}
|
||||
for mat in materials:
|
||||
base = normalize_base(mat.name)
|
||||
materials_by_base.setdefault(base, []).append(mat)
|
||||
|
||||
# Normalize BSDF base name map for robust target lookups
|
||||
bsdf_base_map_normalized = {normalize_base(base): mat for base, mat in bsdf_base_map.items()}
|
||||
|
||||
replacements_made = 0
|
||||
missing_targets = []
|
||||
|
||||
# Process custom mappings first
|
||||
# Process custom mappings first (case/suffix-insensitive)
|
||||
for source_name, target_name in custom_mappings.items():
|
||||
# Gather source candidates by exact name or base name (handles .001 etc.)
|
||||
if source_name in exact_material_map:
|
||||
if target_name in exact_material_map:
|
||||
material_mapping[exact_material_map[source_name]] = exact_material_map[target_name]
|
||||
print(f"Found custom mapping: {source_name} -> {target_name}")
|
||||
else:
|
||||
missing_targets.append(f"{source_name} -> {target_name}")
|
||||
print(f"Warning: Target material '{target_name}' not found for custom mapping '{source_name}'")
|
||||
source_candidates = [exact_material_map[source_name]]
|
||||
else:
|
||||
source_candidates = materials_by_base.get(normalize_base(source_name), [])
|
||||
|
||||
if not source_candidates:
|
||||
print(f"Warning: Source material '{source_name}' not found")
|
||||
continue
|
||||
|
||||
# Resolve target BSDF by exact or base name
|
||||
target_material = exact_material_map.get(target_name)
|
||||
if target_material is None:
|
||||
target_material = bsdf_base_map_normalized.get(normalize_base(target_name))
|
||||
if target_material is None:
|
||||
# Final fallback: any BSDF whose base equals target base
|
||||
target_base_norm = normalize_base(target_name)
|
||||
for mat in materials:
|
||||
m = bsdf_pattern.match(mat.name)
|
||||
if m and normalize_base(m.group(1)) == target_base_norm:
|
||||
target_material = mat
|
||||
break
|
||||
|
||||
if target_material is None:
|
||||
missing_targets.append(f"{source_name} -> {target_name}")
|
||||
print(f"Warning: Target material '{target_name}' not found for custom mapping '{source_name}'")
|
||||
continue
|
||||
|
||||
for src_mat in source_candidates:
|
||||
material_mapping[src_mat] = target_material
|
||||
print(f"Found custom mapping: {src_mat.name} -> {target_material.name}")
|
||||
|
||||
# Find all CEL materials and their BSDF counterparts
|
||||
for mat in materials:
|
||||
|
||||
Reference in New Issue
Block a user