Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJulien Duroure <julien.duroure@gmail.com>2022-01-20 21:05:09 +0300
committerJulien Duroure <julien.duroure@gmail.com>2022-01-20 21:05:09 +0300
commita5205b0289717dc418c1a6070c89039204a2e951 (patch)
tree6ed3a68f179c914e9dd352b74ea66bd02da9f24e /io_scene_gltf2/io
parent19385dbc57f566e27914a361768d3aa6dad95ec6 (diff)
glTF importer: Implement a user extension system
Diffstat (limited to 'io_scene_gltf2/io')
-rwxr-xr-xio_scene_gltf2/io/imp/gltf2_io_gltf.py8
-rw-r--r--io_scene_gltf2/io/imp/gltf2_io_user_extensions.py23
2 files changed, 31 insertions, 0 deletions
diff --git a/io_scene_gltf2/io/imp/gltf2_io_gltf.py b/io_scene_gltf2/io/imp/gltf2_io_gltf.py
index aa9bda38..407afccd 100755
--- a/io_scene_gltf2/io/imp/gltf2_io_gltf.py
+++ b/io_scene_gltf2/io/imp/gltf2_io_gltf.py
@@ -38,6 +38,7 @@ class glTFImporter():
self.buffers = {}
self.accessor_cache = {}
self.decode_accessor_cache = {}
+ self.import_user_extensions = import_settings['import_user_extensions']
if 'loglevel' not in self.import_settings.keys():
self.import_settings['loglevel'] = logging.ERROR
@@ -57,6 +58,13 @@ class glTFImporter():
'KHR_draco_mesh_compression'
]
+ # Add extensions required supported by custom import extensions
+ for import_extension in self.import_user_extensions:
+ if hasattr(import_extension, "extensions"):
+ for custom_extension in import_extension.extensions:
+ if custom_extension.required:
+ self.extensions_managed.append(custom_extension.name)
+
@staticmethod
def load_json(content):
def bad_constant(val):
diff --git a/io_scene_gltf2/io/imp/gltf2_io_user_extensions.py b/io_scene_gltf2/io/imp/gltf2_io_user_extensions.py
new file mode 100644
index 00000000..0c439251
--- /dev/null
+++ b/io_scene_gltf2/io/imp/gltf2_io_user_extensions.py
@@ -0,0 +1,23 @@
+# Copyright 2018-2021 The glTF-Blender-IO authors.
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+def import_user_extensions(hook_name, gltf_importer, *args):
+ for extension in gltf_importer.import_user_extensions:
+ hook = getattr(extension, hook_name, None)
+ if hook is not None:
+ try:
+ hook(*args, gltf_importer)
+ except Exception as e:
+ print(hook_name, "fails on", extension)
+ print(str(e))