Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
marekzajac97 committed May 1, 2024
1 parent 2e5a3b2 commit 864f73a
Show file tree
Hide file tree
Showing 10 changed files with 44 additions and 21 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
__pycache__/
*.code-workspace
*.pyd
*.pyd
release/
2 changes: 1 addition & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"author" : "Marek Zajac",
"description" : "",
"blender" : (4, 1, 1),
"version" : (0, 7, 2),
"version" : (0, 7, 3),
"location" : "",
"warning" : "",
"category" : "Import-Export"
Expand Down
2 changes: 1 addition & 1 deletion core/mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,7 +813,7 @@ def _export_mesh_lod(self, bf2_lod, lod_obj):
bone_to_id = dict()
rig = find_rig_attached_to_object(lod_obj)
if rig is None:
raise ExportException(f"{lod_obj.name}: does not have 'Armature' modifier or armature does not contain BF2 skeleton metadata")
raise ExportException(f"{lod_obj.name}: does not have 'Armature' modifier or 'Object' in the modifier settings does not point to a BF2 skeleton")
ske_bones = rig['bf2_bones']

for bone_id, ske_bone in enumerate(ske_bones):
Expand Down
4 changes: 2 additions & 2 deletions core/mesh_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -449,8 +449,8 @@ def _link_uv_chan(uv_chan, tex_node):
mult_ndetaila.operation = 'MULTIPLY'
mult_ndetaila.location = (1 * NODE_WIDTH, -1 * NODE_HEIGHT)
mult_ndetaila.hide = True
mult_ndetaila_values = _sockets(mult_detaila.inputs, 'Value')

mult_ndetaila_values = _sockets(mult_ndetaila.inputs, 'Value')
node_tree.links.new(dirt_spec_out, mult_ndetaila_values[1])
node_tree.links.new(ndetail.outputs['Alpha'], mult_ndetaila_values[0])
has_alpha_out = mult_ndetaila.outputs['Value']
Expand Down
7 changes: 4 additions & 3 deletions core/object_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from .collision_mesh import import_collisionmesh, export_collisionmesh
from .skeleton import find_all_skeletons, find_rig_attached_to_object

from .utils import delete_object, check_suffix, DEFAULT_REPORTER
from .utils import delete_object, check_suffix, check_prefix, DEFAULT_REPORTER
from .exceptions import ImportException, ExportException

NONVIS_PRFX = 'NONVIS_'
Expand Down Expand Up @@ -72,8 +72,9 @@ def import_object(context, con_filepath, import_collmesh=False, import_rig=('AUT
for col_material_idx, col_material_name in root_template.col_material_map.items():
col_materials[col_material_idx].name = col_material_name

for geom_idx, geom_obj in enumerate(root_geometry_obj.children):
for lod_idx, lod_obj in enumerate(geom_obj.children):
for geom_obj in root_geometry_obj.children:
for lod_obj in geom_obj.children:
geom_idx, lod_idx = check_prefix(lod_obj.name, ('G', 'L'))
if geometry_type != 'BundledMesh':
geom_parts = {'mesh1': lod_obj} # XXX hack
else:
Expand Down
1 change: 1 addition & 0 deletions plugin/import_export/gui_animation.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def execute(self, context):
export_animation(context, self.filepath, bones_to_export=bones_to_export)
except Exception as e:
self.report({"ERROR"}, traceback.format_exc())
self.report({"INFO"}, 'Export complete')
return {'FINISHED'}

FILE_DESC = "Animation (.baf)"
Expand Down
4 changes: 4 additions & 0 deletions plugin/import_export/gui_collisionmesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,12 @@ def execute(self, context):
export_collisionmesh(active_obj, self.filepath)
except Exception as e:
self.report({"ERROR"}, traceback.format_exc())
self.report({"INFO"}, 'Export complete')
return {'FINISHED'}

def invoke(self, context, _event):
self.filepath = context.view_layer.objects.active.name + self.filename_ext
return super().invoke(context, _event)

FILE_DESC = "CollisionMesh (.collisionmesh)"

Expand Down
4 changes: 4 additions & 0 deletions plugin/import_export/gui_mesh.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,12 @@ def execute(self, context):
tangent_uv_map=self.tangent_uv_map)
except Exception as e:
self.report({"ERROR"}, traceback.format_exc())
self.report({"INFO"}, 'Export complete')
return {'FINISHED'}

def invoke(self, context, _event):
self.filepath = context.view_layer.objects.active.name + self.filename_ext
return super().invoke(context, _event)

class EXPORT_OT_bf2_staticmesh(EXPORT_OT_bf2_mesh):
bl_idname = "bf2_mesh.export_staticmesh"
Expand Down
25 changes: 16 additions & 9 deletions plugin/import_export/gui_object_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,14 +160,12 @@ def get_uv_layers(self, context):
active_obj = context.view_layer.objects.active
object_uv_layers = collect_uv_layers(active_obj)
default = None
try:
geom_type, _ = parse_geom_type(active_obj)
if geom_type == 'StaticMesh':
default = 1 # Detail normal
elif geom_type == 'BundledMesh' or geom_type == 'SkinnedMesh':
default = 0 # Diffuse/Normal
except Exception as e:
pass

geom_type, _ = parse_geom_type(active_obj)
if geom_type == 'StaticMesh':
default = 1 # Detail normal
elif geom_type == 'BundledMesh' or geom_type == 'SkinnedMesh':
default = 0 # Diffuse/Normal

# XXX: it is not possible to define a default for dynamic enums
# the only way is to reorder items in such a way that the default one
Expand Down Expand Up @@ -254,7 +252,12 @@ def draw(self, context):

@classmethod
def poll(cls, context):
return context.view_layer.objects.active is not None
try:
active_obj = context.view_layer.objects.active
return active_obj is not None and parse_geom_type(active_obj)
except Exception as e:
cls.poll_message_set(str(e))
return False

def execute(self, context):
active_obj = context.view_layer.objects.active
Expand All @@ -277,9 +280,13 @@ def execute(self, context):
except Exception as e:
self.report({"ERROR"}, traceback.format_exc())
return {'CANCELLED'}
self.report({"INFO"}, 'Export complete')
return {'FINISHED'}

def invoke(self, context, _event):
active_obj = context.view_layer.objects.active
_, obj_name = parse_geom_type(active_obj)
self.filepath = obj_name + self.filename_ext
return super().invoke(context, _event)


Expand Down
13 changes: 9 additions & 4 deletions plugin/import_export/gui_skeleton.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def execute(self, context):
self.report({"ERROR"}, traceback.format_exc())
return {'FINISHED'}

class EXPORT_OT_bf2_cskeleton(bpy.types.Operator, ExportHelper):
class EXPORT_OT_bf2_skeleton(bpy.types.Operator, ExportHelper):
bl_idname = "bf2_skeleton.export"
bl_label = "Export Collision Mesh"

Expand All @@ -36,20 +36,25 @@ def execute(self, context):
export_skeleton(active_obj, self.filepath)
except Exception as e:
self.report({"ERROR"}, traceback.format_exc())
self.report({"INFO"}, 'Export complete')
return {'FINISHED'}

def invoke(self, context, _event):
self.filepath = context.view_layer.objects.active.name + self.filename_ext
return super().invoke(context, _event)

FILE_DESC = "Skeleton (.ske)"

def draw_import(layout):
layout.operator(IMPORT_OT_bf2_skeleton.bl_idname, text=FILE_DESC)

def draw_export(layout):
layout.operator(EXPORT_OT_bf2_cskeleton.bl_idname, text=FILE_DESC)
layout.operator(EXPORT_OT_bf2_skeleton.bl_idname, text=FILE_DESC)

def register():
bpy.utils.register_class(IMPORT_OT_bf2_skeleton)
bpy.utils.register_class(EXPORT_OT_bf2_cskeleton)
bpy.utils.register_class(EXPORT_OT_bf2_skeleton)

def unregister():
bpy.utils.unregister_class(EXPORT_OT_bf2_cskeleton)
bpy.utils.unregister_class(EXPORT_OT_bf2_skeleton)
bpy.utils.unregister_class(IMPORT_OT_bf2_skeleton)

0 comments on commit 864f73a

Please sign in to comment.