[Bf-extensions-cvs] [67e42c79] master: glTF importer: multiple files import feature

Julien Duroure noreply at git.blender.org
Sat Oct 12 17:02:49 CEST 2019


Commit: 67e42c79e5c3f2724d33b7dc2f0fb4ab84d10e7f
Author: Julien Duroure
Date:   Sat Oct 12 17:02:14 2019 +0200
Branches: master
https://developer.blender.org/rBA67e42c79e5c3f2724d33b7dc2f0fb4ab84d10e7f

glTF importer: multiple files import feature

===================================================================

M	io_scene_gltf2/__init__.py

===================================================================

diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py
index 36fda5ce..48574ef4 100755
--- a/io_scene_gltf2/__init__.py
+++ b/io_scene_gltf2/__init__.py
@@ -15,7 +15,7 @@
 bl_info = {
     'name': 'glTF 2.0 format',
     'author': 'Julien Duroure, Norbert Nopper, Urs Hanselmann, Moritz Becher, Benjamin Schmithüsen, Jim Eckerlein, and many external contributors',
-    "version": (1, 0, 4),
+    "version": (1, 0, 5),
     'blender': (2, 81, 6),
     'location': 'File > Import-Export',
     'description': 'Import-Export as glTF 2.0',
@@ -57,7 +57,8 @@ import bpy
 from bpy.props import (StringProperty,
                        BoolProperty,
                        EnumProperty,
-                       IntProperty)
+                       IntProperty,
+                       CollectionProperty)
 from bpy.types import Operator
 from bpy_extras.io_utils import ImportHelper, ExportHelper
 
@@ -730,6 +731,11 @@ class ImportGLTF2(Operator, ImportHelper):
 
     filter_glob: StringProperty(default="*.glb;*.gltf", options={'HIDDEN'})
 
+    files: CollectionProperty(
+        name="File Path",
+        type=bpy.types.OperatorFileListElement,
+    )
+
     loglevel: IntProperty(
         name='Log Level',
         description="Log Level")
@@ -758,14 +764,30 @@ class ImportGLTF2(Operator, ImportHelper):
         return self.import_gltf2(context)
 
     def import_gltf2(self, context):
-        import time
-        from .io.imp.gltf2_io_gltf import glTFImporter
-        from .blender.imp.gltf2_blender_gltf import BlenderGlTF
+        import os
 
         self.set_debug_log()
         import_settings = self.as_keywords()
 
-        self.gltf_importer = glTFImporter(self.filepath, import_settings)
+        if self.files:
+            # Multiple file import
+            ret = {'CANCELLED'}
+            dirname = os.path.dirname(self.filepath)
+            for file in self.files:
+                path = os.path.join(dirname, file.name)
+                if self.unit_import(path, import_settings) == {'FINISHED'}:
+                    ret = {'FINISHED'}
+            return ret
+        else:
+            # Single file import
+            return self.unit_import(self.filepath, import_settings)
+
+    def unit_import(self, filename, import_settings):
+        import time
+        from .io.imp.gltf2_io_gltf import glTFImporter
+        from .blender.imp.gltf2_blender_gltf import BlenderGlTF
+
+        self.gltf_importer = glTFImporter(filename, import_settings)
         success, txt = self.gltf_importer.read()
         if not success:
             self.report({'ERROR'}, txt)



More information about the Bf-extensions-cvs mailing list