glTF exporter: manage user extension at gltf level

This commit is contained in:
Julien Duroure 2020-03-12 21:59:04 +01:00
parent bd54740ed0
commit 1ae12e6f5d
3 changed files with 15 additions and 5 deletions

View File

@ -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, 2, 41),
"version": (1, 2, 42),
'blender': (2, 82, 7),
'location': 'File > Import-Export',
'description': 'Import-Export as glTF 2.0',

View File

@ -24,6 +24,7 @@ from io_scene_gltf2.blender.exp.gltf2_blender_gltf2_exporter import GlTF2Exporte
from io_scene_gltf2.io.com.gltf2_io_debug import print_console, print_newline
from io_scene_gltf2.io.exp import gltf2_io_export
from io_scene_gltf2.io.exp import gltf2_io_draco_compression_extension
from io_scene_gltf2.io.exp.gltf2_io_user_extensions import export_user_extensions
def save(context, export_settings):
@ -61,6 +62,10 @@ def __export(export_settings):
def __gather_gltf(exporter, export_settings):
active_scene_idx, scenes, animations = gltf2_blender_gather.gather_gltf2(export_settings)
plan = {'active_scene_idx': active_scene_idx, 'scenes': scenes, 'animations': animations}
export_user_extensions('gather_gltf_hook', export_settings, plan)
active_scene_idx, scenes, animations = plan['active_scene_idx'], plan['scenes'], plan['animations']
if export_settings['gltf_draco_mesh_compression']:
gltf2_io_draco_compression_extension.compress_scene_primitives(scenes, export_settings)
exporter.add_draco_extension()

View File

@ -12,11 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.
def export_user_extensions(hook_name, export_settings, gltf2_object, *args):
if gltf2_object.extensions is None:
gltf2_object.extensions = {}
def export_user_extensions(hook_name, export_settings, *args):
if args and hasattr(args[0], "extensions"):
if args[0].extensions is None:
args[0].extensions = {}
for extension in export_settings['gltf_user_extensions']:
hook = getattr(extension, hook_name, None)
if hook is not None:
hook(gltf2_object, *args, export_settings)
try:
hook(*args, export_settings)
except Exception as e:
print(hook_name, "fails on", extension)
print(str(e))