KirilStrezikozin / BakeMaster-Blender-Addon

Welcome to BakeMaster, a powerful and feature-packed baking solution created for Blender - an open-source 3D Computer graphics software.
Other
34 stars 6 forks source link

BUG: Global/Bake Output presets cannot store batch names with mixed caps #90

Closed KirilStrezikozin closed 5 months ago

KirilStrezikozin commented 5 months ago

This bug report is:

Describe the bug __mike_fr__ reported on Discord:

The global preset does not store my [batch name] preference, it stores the letter but not if it is uppercase or lowercase - so maybe it is the reason I thought you cannot mix uppercase and lowercase. So there is a bug in preset storing.

To Reproduce Steps to reproduce the behavior:

  1. Use T-$objectname_$mapname
  2. Save the preset (global)
  3. Load the preset
  4. Bug: you get t-$objectname_$mapname

Expected behavior Mixed cap letters should be allowed in BakeMaster's batch name. The batch name itself does, but presets miss it.

Screenshots Not relevant for now.

Desktop (please complete the following information):

KirilStrezikozin commented 5 months ago

Preset saving works correctly, I can see that a mixed-caps batch name was written down in a bake output preset example below generated in 2.6.2:

import bpy
bm_item = bpy.context.scene.bm_table_of_objects[bpy.context.scene.bm_props.global_active_index]

bm_item.bake_save_internal = True
bm_item.bake_output_filepath = ''
bm_item.bake_create_subfolder = False
bm_item.bake_subfolder_name = 'Maps'
bm_item.bake_batchname = 'T_$materialname_$mapname'
bm_item.bake_batchname_use_caps = False
bm_item.bake_create_material = False
bm_item.bake_assign_modifiers = True
bm_item.bake_device = 'CPU'
bm_item.bake_view_from = 'ABOVE_SURFACE'
bm_item.bake_hide_when_inactive = True
bm_item.bake_vg_index = 0
KirilStrezikozin commented 5 months ago

Interesting. The batch name value gets transformed to lowercase exactly at https://github.com/KirilStrezikozin/BakeMaster-Blender-Addon/blob/acf0b5b1b9dc1f2d77e06d0ac4fbb2b2a74e6808/presets.py#L1548

With a small debug test, the following sample:

print(bpy.data.scenes["Scene"].bm_table_of_objects[1].bake_batchname)
bpy.utils.execfile(filepath)
print(bpy.data.scenes["Scene"].bm_table_of_objects[1].bake_batchname)

Produces:

T_$materialname_$mapname
t_$materialname_$mapname
KirilStrezikozin commented 5 months ago

There is nothing wrong with batchname's update.

KirilStrezikozin commented 5 months ago

The reason for batch name turning to lowercase on preset load is because batchname_use_caps was doing batchanme.lower() on update. batchname_use_caps is also written after batchname, hence it changes batchname's value.

KirilStrezikozin commented 5 months ago

My solution is to update batchname to uppercase only if batchname_use_caps is True, otherwise do nothing. Also, set batchname_use_caps to False whenever the batchname is no longer in uppercase.