Skip to content

Commit

Permalink
Fix animate1978#351 issues with saving and reloading toon girl
Browse files Browse the repository at this point in the history
  • Loading branch information
Upliner committed Jul 18, 2021
1 parent 8638bd1 commit 7525d18
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 27 deletions.
2 changes: 1 addition & 1 deletion algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ def check_mesh(obj):
config_data = file_ops.get_configuration()
model_config = config_data.get(obj.get("manuellab_id"))
if not model_config:
logger.debug("check_obj %s model %s is not found", obj.name, obj.obj.get("manuellab_id"))
logger.debug("check_obj %s model %s is not found", obj.name, obj.get("manuellab_id"))
return False

templates = {}
Expand Down
41 changes: 22 additions & 19 deletions expressionscreator.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@
logger = logging.getLogger(__name__)

class ExpressionsCreator():

def __init__(self):

self.standard_expressions_list = ["abdomExpansion_min", "abdomExpansion_max",
"browOutVertL_min", "browOutVertL_max", "browOutVertR_min",
"browOutVertR_max", "browsMidVert_min", "browsMidVert_max",
Expand Down Expand Up @@ -181,7 +181,7 @@ def __init__(self):
self.expression_ID_list = [("HU", "Humans", "Standard in MB-Lab"),
("AN", "Anime", "Standard in MB-Lab"),
("OT", "OTHER", "For another model")]

self.forbidden_char_list = '-_²&=¨^$£%µ,?;!§+*/'

self.expression_name = ["", "", 0]
Expand All @@ -200,14 +200,14 @@ def __init__(self):
# and create them only when model is changed.
# Used only BEFORE finalization of the model,
# in the Combined Expression Editor.

self.humanoid = None
# Instance of class Humanoid

#--------------Play with variables
def set_lab_version(self, lab_version):
self.lab_vers = list(lab_version)

def get_standard_expressions_list(self):
return self.standard_expressions_list

Expand Down Expand Up @@ -255,7 +255,7 @@ def get_expression_ID(self):

def get_expression_ID_list(self):
return self.expression_ID_list

def get_next_number(self):
self.expression_name[2] += 1
return str(self.expression_name[2]).zfill(3)
Expand All @@ -272,6 +272,9 @@ def set_expressions_modifiers(self, huma):
if len(self.expressions_modifiers) > 0:
return self.expressions_modifiers
category = self.humanoid.get_category("Expressions")
if not category:
logger.error("Expressions is aren't found in humanoid")
return
self.expressions_modifiers = category.get_modifier_tiny_name(self.body_parts_expr_list)

def get_expressions_modifiers(self):
Expand Down Expand Up @@ -302,7 +305,7 @@ def get_expressions_sub_categories(self):
sorted_list = sorted(list(self.expressions_modifiers.keys()))
self.expressions_sub_categories = algorithms.create_enum_property_items(sorted_list, tip_length=100)
return self.expressions_sub_categories

def is_comb_expression_exists(self, root_model, name):
if len(root_model) < 1 or len(name) < 1:
return False
Expand All @@ -315,7 +318,7 @@ def is_comb_expression_exists(self, root_model, name):
except:
return False
return False

#--------------EnumProperty for expressions in UI
#--------------AFTER finalization of the character

Expand All @@ -332,7 +335,7 @@ def get_expressions_items(self):

def get_expressions_item(self, key):
return algorithms.get_enum_property_item(key, self.editor_expressions_items)

#--------------Loading data
def get_all_expression_files(self, data_path, data_type_path, body_type):
#Get all files in morphs directory, with standard ones.
Expand All @@ -349,7 +352,7 @@ def get_all_expression_files(self, data_path, data_type_path, body_type):
found_files += [os.path.join(dir, item)]
return found_files

#--------------Saving all changed base expression in a filedef
#--------------Saving all changed base expression in a filedef
def save_face_expression(self, filepath):
# Save all expression morphs as a new face expression
# in its dedicated file.
Expand All @@ -365,36 +368,36 @@ def save_face_expression(self, filepath):
with open(filepath, "w") as j_file:
json.dump(char_data, j_file, indent=2)
j_file.close()

# data_source can be a filepath but also the data themselves.
def load_face_expression(self, data_source, reset_unassigned=True):

if self.humanoid == None:
return

obj = self.humanoid.get_object()
log_msg_type = "Expression data"

if isinstance(data_source, str):
log_msg_type = file_ops.simple_path(data_source)
charac_data = file_ops.load_json_data(data_source, "Expression data")
else:
charac_data = data_source

logger.info("Loading expression from {0}".format(log_msg_type))

if "manuellab_vers" in charac_data:
if not utils.check_version(charac_data["manuellab_vers"]):
logger.warning("{0} created with vers. {1}. Current vers is {2}".format(log_msg_type, charac_data["manuellab_vers"], self.lab_vers))
else:
logger.info("No lab version specified in {0}".format(log_msg_type))

if "structural" in charac_data:
char_data = charac_data["structural"]
else:
logger.warning("No structural data in {0}".format(log_msg_type))
char_data = {}

# data are loaded, now update the character.
if char_data is not None:
for name in self.humanoid.character_data.keys():
Expand Down
23 changes: 16 additions & 7 deletions file_ops.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,13 @@ def get_root_directories():
root_directories = []
for dir in rd:
if dir not in fd:
logger.debug("found root dir %s", dir)
root_directories.append(
(dir,
"MB_Lab" if dir == "data" else dir,
dir))
return root_directories

def set_data_path(path):
global data_directory
global configuration_done
Expand All @@ -100,15 +101,20 @@ def get_configuration():
# what's why the variable below exists.
if configuration_done != None:
return configuration_done
data_path = get_data_path()
# Here something to change :
# Allow to load every file that ends with _config.json
if data_path:
configuration_done = {}

addon_directory = os.path.dirname(os.path.realpath(__file__))
configuration_done = {}
for tup in get_root_directories():
data_path = os.path.join(addon_directory, tup[0])
if not os.path.isdir(data_path):
logger.error("get_configuration: %s is not a directury!", data_path)
continue
tmp = {}
logger.debug("Loading config dir %s", data_path)
for list_dir in os.listdir(data_path):
configuration_path = os.path.join(data_path, list_dir)
if os.path.isfile(configuration_path) and configuration_path.endswith("_config.json"):
logger.debug("Loading config json %s", configuration_path)
tmp = load_json_data(configuration_path, "Characters definition")
for prop in tmp:
if prop == 'data_directory':
Expand All @@ -119,7 +125,10 @@ def get_configuration():
configuration_done[prop] += tmp[prop]
else:
configuration_done[prop] = tmp[prop]

if configuration_done:
return configuration_done

logger.critical("Configuration database not found. Please check your Blender addons directory.")
return None

Expand Down Expand Up @@ -275,7 +284,7 @@ def append_object_from_library(lib_filepath, obj_names, suffix=None):
except OSError:
logger.critical("lib %s not found", lib_filepath)
return

for obj in data_to.objects:
link_to_collection(obj)
obj_parent = utils.get_object_parent(obj)
Expand Down

0 comments on commit 7525d18

Please sign in to comment.