Hidden objects will be unhidden after calling evaluated_get, so they must be tracked beforehand when exporting.

This commit is contained in:
William Herald Snyder 2022-10-08 22:10:03 -04:00
parent ba762d9548
commit 432c9ff380
1 changed files with 14 additions and 1 deletions

View File

@ -40,6 +40,10 @@ def gather_models(apply_modifiers: bool, export_target: str, skeleton_only: bool
# Here we just keep track of all names, regardless of origin # Here we just keep track of all names, regardless of origin
exported_object_names: Set[str] = set() exported_object_names: Set[str] = set()
# Me must keep track of hidden objects separately because
# evaluated_get clears hidden status
blender_objects_to_hide: Set[str] = set()
# Armature must be processed before everything else! # Armature must be processed before everything else!
# In this loop we also build a set of names of all objects # In this loop we also build a set of names of all objects
@ -47,6 +51,10 @@ def gather_models(apply_modifiers: bool, export_target: str, skeleton_only: bool
# groups that do not reference exported objects in the main # groups that do not reference exported objects in the main
# model building loop below this one. # model building loop below this one.
for uneval_obj in select_objects(export_target): for uneval_obj in select_objects(export_target):
if get_is_model_hidden(uneval_obj):
blender_objects_to_hide.add(uneval_obj.name)
if uneval_obj.type == "ARMATURE" and not armature_found: if uneval_obj.type == "ARMATURE" and not armature_found:
# Keep track of the armature, we don't want to process > 1! # Keep track of the armature, we don't want to process > 1!
armature_found = uneval_obj.evaluated_get(depsgraph) if apply_modifiers else uneval_obj armature_found = uneval_obj.evaluated_get(depsgraph) if apply_modifiers else uneval_obj
@ -80,7 +88,6 @@ def gather_models(apply_modifiers: bool, export_target: str, skeleton_only: bool
model = Model() model = Model()
model.name = obj.name model.name = obj.name
model.model_type = ModelType.NULL if skeleton_only else get_model_type(obj, armature_found) model.model_type = ModelType.NULL if skeleton_only else get_model_type(obj, armature_found)
model.hidden = get_is_model_hidden(obj)
transform = obj.matrix_local transform = obj.matrix_local
@ -133,6 +140,8 @@ def gather_models(apply_modifiers: bool, export_target: str, skeleton_only: bool
if get_is_collision_primitive(obj): if get_is_collision_primitive(obj):
model.collisionprimitive = get_collision_primitive(obj) model.collisionprimitive = get_collision_primitive(obj)
model.hidden = model.name in blender_objects_to_hide
models_list.append(model) models_list.append(model)
# We removed all composite bones after looking through the objects, # We removed all composite bones after looking through the objects,
@ -290,6 +299,9 @@ def get_model_type(obj: bpy.types.Object, armature_found: bpy.types.Object) -> M
def get_is_model_hidden(obj: bpy.types.Object) -> bool: def get_is_model_hidden(obj: bpy.types.Object) -> bool:
""" Gets if a Blender object should be marked as hidden in the .msh file. """ """ Gets if a Blender object should be marked as hidden in the .msh file. """
if obj.hide_get():
return True
name = obj.name.lower() name = obj.name.lower()
if name.startswith("c_"): if name.startswith("c_"):
@ -482,6 +494,7 @@ def expand_armature(armature: bpy.types.Object) -> Dict[str, Model]:
model.model_type = ModelType.BONE if bone.name in proper_BONES else ModelType.NULL model.model_type = ModelType.BONE if bone.name in proper_BONES else ModelType.NULL
model.name = bone.name model.name = bone.name
model.hidden = True
model.transform.rotation = convert_rotation_space(local_rotation) model.transform.rotation = convert_rotation_space(local_rotation)
model.transform.translation = convert_vector_space(local_translation) model.transform.translation = convert_vector_space(local_translation)