Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support multi-select import and group into collection #1

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 38 additions & 24 deletions io_scene_dos2de/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -1792,6 +1792,9 @@ class DIVINITYEXPORTER_OT_import_collada(Operator, ImportHelper):

filter_glob: StringProperty(default="*.dae;*.gr2", options={"HIDDEN"})

files: CollectionProperty(type=bpy.types.OperatorFileListElement)
directory: StringProperty()

def fixup_bones(self, context):
for obj in context.scene.objects:
if obj.type == "ARMATURE" and obj.select_get():
Expand All @@ -1814,35 +1817,46 @@ def execute(self, context):
current_operator = None

def really_execute(self, context):
input_path = Path(self.properties.filepath)
tempfile_path = None
directory = self.directory

if input_path.suffix.lower() == '.gr2':
addon_prefs = get_prefs(context)
divine = DivineInvoker(addon_prefs, None)
temp = tempfile.NamedTemporaryFile(delete=False)
temp.close()
tempfile_path = Path(temp.name)
collada_path = tempfile_path
if not divine.gr2_to_dae(str(input_path), str(collada_path)):
return{'CANCELLED'}
else:
collada_path = input_path
for f in self.files:
input_path = Path(os.path.join(directory, f.name))
tempfile_path = None

if bpy.app.version >= (3, 4, 0):
bpy.ops.wm.collada_import(filepath=str(collada_path), custom_normals=True, fix_orientation=True)
else:
bpy.ops.wm.collada_import(filepath=str(collada_path), fix_orientation=True)
if input_path.suffix.lower() == '.gr2':
addon_prefs = get_prefs(context)
divine = DivineInvoker(addon_prefs, None)
temp = tempfile.NamedTemporaryFile(delete=False)
temp.close()
tempfile_path = Path(temp.name)
collada_path = tempfile_path
if not divine.gr2_to_dae(str(input_path), str(collada_path)):
return{'CANCELLED'}
else:
collada_path = input_path

meta_loader = ColladaMetadataLoader()
meta_loader.load(context, str(collada_path))
self.fixup_bones(context)
if bpy.app.version >= (3, 4, 0):
bpy.ops.wm.collada_import(filepath=str(collada_path), custom_normals=True, fix_orientation=True)
else:
bpy.ops.wm.collada_import(filepath=str(collada_path), fix_orientation=True)

if tempfile_path is not None:
tempfile_path.unlink()
meta_loader = ColladaMetadataLoader()
meta_loader.load(context, str(collada_path))
self.fixup_bones(context)

report("Import completed successfully.", "INFO")
return{'FINISHED'}
if tempfile_path is not None:
tempfile_path.unlink()

imported = context.selected_objects
collection = bpy.data.collections.new(os.path.splitext(f['name'])[0])
bpy.context.scene.collection.children.link(collection)
for f in imported:
for parent in f.users_collection:
parent.objects.unlink(f)
collection.objects.link(f)

report("Import completed successfully.", "INFO")
return {'FINISHED'}

def export_menu_func(self, context):
self.layout.operator(DIVINITYEXPORTER_OT_export_collada.bl_idname, text="DOS2/BG3 Collada (.dae, .gr2)")
Expand Down