diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2019-06-14 00:48:57 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2019-06-14 00:48:57 +0300 |
commit | a30fce5376c5a70cb64cff58298b8a392512ef2d (patch) | |
tree | 19e896b7e8d4395e334855b267af463a1d2c3980 | |
parent | 4579db103294ac8b6b81549c6b9cfc91b37e5847 (diff) |
glTF exporter: fix regression about exporting with applied modifiers, cache enhancement
5 files changed, 37 insertions, 26 deletions
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index afd1d7ad..b3662b15 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": (0, 9, 27), + "version": (0, 9, 28), 'blender': (2, 80, 0), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py index 5b00a98b..99286aea 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_cache.py @@ -13,7 +13,7 @@ # limitations under the License. import functools - +import bpy def cached(func): """ @@ -37,8 +37,20 @@ def cached(func): export_settings = args[-1] cache_key_args = args[:-1] + __by_name = [bpy.types.Object, bpy.types.Scene, bpy.types.Material, bpy.types.Action, bpy.types.Mesh] + # we make a tuple from the function arguments so that they can be used as a key to the cache - cache_key = tuple(cache_key_args + tuple(cache_key_kwargs.values())) + cache_key = () + for i in cache_key_args: + if type(i) in __by_name: + cache_key += (i.name,) + else: + cache_key += (i,) + for i in cache_key_kwargs.values(): + if type(i) in __by_name: + cache_key += (i.name,) + else: + cache_key += (i,) # invalidate cache if export settings have changed if not hasattr(func, "__export_settings") or export_settings != func.__export_settings: diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py index c2202b9e..9af47f45 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_mesh.py @@ -23,22 +23,22 @@ from io_scene_gltf2.io.com.gltf2_io_debug import print_console @cached -def gather_mesh(blender_mesh_name: str, +def gather_mesh(blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], skip_filter: bool, material_names: Tuple[str], export_settings ) -> Optional[gltf2_io.Mesh]: - if not skip_filter and not __filter_mesh(blender_mesh_name, vertex_groups, modifiers, export_settings): + if not skip_filter and not __filter_mesh(blender_mesh, vertex_groups, modifiers, export_settings): return None mesh = gltf2_io.Mesh( - extensions=__gather_extensions(blender_mesh_name, vertex_groups, modifiers, export_settings), - extras=__gather_extras(blender_mesh_name, vertex_groups, modifiers, export_settings), - name=__gather_name(blender_mesh_name, vertex_groups, modifiers, export_settings), - primitives=__gather_primitives(blender_mesh_name, vertex_groups, modifiers, material_names, export_settings), - weights=__gather_weights(blender_mesh_name, vertex_groups, modifiers, export_settings) + extensions=__gather_extensions(blender_mesh, vertex_groups, modifiers, export_settings), + extras=__gather_extras(blender_mesh, vertex_groups, modifiers, export_settings), + name=__gather_name(blender_mesh, vertex_groups, modifiers, export_settings), + primitives=__gather_primitives(blender_mesh, vertex_groups, modifiers, material_names, export_settings), + weights=__gather_weights(blender_mesh, vertex_groups, modifiers, export_settings) ) if len(mesh.primitives) == 0: @@ -47,18 +47,18 @@ def gather_mesh(blender_mesh_name: str, return mesh -def __filter_mesh(blender_mesh_name: str, +def __filter_mesh(blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], export_settings ) -> bool: - blender_mesh = bpy.data.meshes[blender_mesh_name] + if blender_mesh.users == 0: return False return True -def __gather_extensions(blender_mesh_name: str, +def __gather_extensions(blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], export_settings @@ -66,12 +66,12 @@ def __gather_extensions(blender_mesh_name: str, return None -def __gather_extras(blender_mesh_name: str, +def __gather_extras(blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], export_settings ) -> Optional[Dict[Any, Any]]: - blender_mesh = bpy.data.meshes[blender_mesh_name] + extras = {} if export_settings['gltf_extras']: @@ -92,33 +92,33 @@ def __gather_extras(blender_mesh_name: str, return None -def __gather_name(blender_mesh_name: str, +def __gather_name(blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], export_settings ) -> str: - return blender_mesh_name + return blender_mesh.name -def __gather_primitives(blender_mesh_name: str, +def __gather_primitives(blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], material_names: Tuple[str], export_settings ) -> List[gltf2_io.MeshPrimitive]: - return gltf2_blender_gather_primitives.gather_primitives(blender_mesh_name, + return gltf2_blender_gather_primitives.gather_primitives(blender_mesh, vertex_groups, modifiers, material_names, export_settings) -def __gather_weights(blender_mesh_name: str, +def __gather_weights(blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], export_settings ) -> Optional[List[float]]: - blender_mesh = bpy.data.meshes[blender_mesh_name] + if not export_settings[MORPH] or not blender_mesh.shape_keys: return None diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py index 1889154d..e6a93553 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_nodes.py @@ -242,7 +242,7 @@ def __gather_mesh(blender_object, export_settings): skip_filter = False material_names = tuple([ms.material.name for ms in blender_object.material_slots if ms.material is not None]) - result = gltf2_blender_gather_mesh.gather_mesh(blender_mesh.name, + result = gltf2_blender_gather_mesh.gather_mesh(blender_mesh, vertex_groups, modifiers, skip_filter, diff --git a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py index 403ca5eb..2c4ee91f 100755 --- a/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py +++ b/io_scene_gltf2/blender/exp/gltf2_blender_gather_primitives.py @@ -32,7 +32,7 @@ from io_scene_gltf2.io.com.gltf2_io_debug import print_console @cached def gather_primitives( - blender_mesh_name: str, + blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], material_names: Tuple[str], @@ -45,7 +45,7 @@ def gather_primitives( """ primitives = [] - blender_primitives = __gather_cache_primitives(blender_mesh_name, + blender_primitives = __gather_cache_primitives(blender_mesh, vertex_groups, modifiers, export_settings) for internal_primitive in blender_primitives: @@ -78,7 +78,7 @@ def gather_primitives( @cached def __gather_cache_primitives( - blender_mesh_name: str, + blender_mesh: bpy.types.Mesh, vertex_groups: Optional[bpy.types.VertexGroups], modifiers: Optional[bpy.types.ObjectModifiers], export_settings @@ -86,7 +86,6 @@ def __gather_cache_primitives( """ Gather parts that are identical for instances, i.e. excluding materials """ - blender_mesh = bpy.data.meshes[blender_mesh_name] primitives = [] blender_primitives = gltf2_blender_extract.extract_primitives( |