diff options
author | Julien Duroure <julien.duroure@gmail.com> | 2020-01-29 23:44:09 +0300 |
---|---|---|
committer | Julien Duroure <julien.duroure@gmail.com> | 2020-01-29 23:44:09 +0300 |
commit | 09bbef319f5e05e48cbf3614408ecaae424308c4 (patch) | |
tree | baa5d4cea1e1bec2bc38c56b9b359a277b502ac6 /io_scene_gltf2 | |
parent | 5021c0955d8c57a76e15bedea834d012c653bf1c (diff) |
glTF importer: avoid "husks" left behind when moving skinned meshes
Diffstat (limited to 'io_scene_gltf2')
-rwxr-xr-x | io_scene_gltf2/__init__.py | 2 | ||||
-rw-r--r-- | io_scene_gltf2/blender/imp/gltf2_blender_vnode.py | 45 |
2 files changed, 42 insertions, 5 deletions
diff --git a/io_scene_gltf2/__init__.py b/io_scene_gltf2/__init__.py index 25b4edcd..7cecb34e 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, 2, 12), + "version": (1, 2, 13), 'blender': (2, 81, 6), 'location': 'File > Import-Export', 'description': 'Import-Export as glTF 2.0', diff --git a/io_scene_gltf2/blender/imp/gltf2_blender_vnode.py b/io_scene_gltf2/blender/imp/gltf2_blender_vnode.py index 114d7193..4e1c6235 100644 --- a/io_scene_gltf2/blender/imp/gltf2_blender_vnode.py +++ b/io_scene_gltf2/blender/imp/gltf2_blender_vnode.py @@ -178,12 +178,11 @@ def move_skinned_meshes(gltf): joints in its skin affect it. To do this in Blender: - * Move a skinned mesh to become a child of the armature that affects it + * Move a skinned mesh to become a child of the armature that skins it. + Have to ensure the mesh and arma have the same world transform. * When we do mesh creation, we will also need to put all the verts in their rest pose (ie. the pose the edit bones are in) """ - # TODO: this leaves behind empty "husk" nodes where the skinned meshes - # used to be, which is ugly. ids = list(gltf.vnodes.keys()) for id in ids: vnode = gltf.vnodes[id] @@ -199,15 +198,53 @@ def move_skinned_meshes(gltf): pyskin = gltf.data.skins[skin] arma = gltf.vnodes[pyskin.joints[0]].bone_arma + # First try moving the whole node if we can do it without + # messing anything up. + is_animated = ( + gltf.data.animations and + isinstance(id, int) and + gltf.data.nodes[id].animations + ) + ok_to_move = ( + not is_animated and + vnode.type == VNode.Object and + not vnode.is_arma and + not vnode.children and + vnode.camera_node_idx is None and + vnode.light_node_idx is None + ) + if ok_to_move: + reparent(gltf, id, new_parent=arma) + vnode.trs = ( + Vector((0, 0, 0)), + Quaternion((1, 0, 0, 0)), + Vector((1, 1, 1)), + ) + continue + + # Otherwise, create a new child of the arma and move + # the mesh instance there, leaving the node behind. new_id = str(id) + '.skinned' gltf.vnodes[new_id] = VNode() gltf.vnodes[new_id].name = gltf.data.meshes[mesh].name or 'Mesh_%d' % mesh gltf.vnodes[new_id].parent = arma gltf.vnodes[arma].children.append(new_id) - gltf.vnodes[new_id].mesh_node_idx = vnode.mesh_node_idx vnode.mesh_node_idx = None +def reparent(gltf, vnode_id, new_parent): + """Moves a VNode to a new parent.""" + vnode = gltf.vnodes[vnode_id] + if vnode.parent == new_parent: + return + if vnode.parent is not None: + parent_vnode = gltf.vnodes[vnode.parent] + index = parent_vnode.children.index(vnode_id) + del parent_vnode.children[index] + vnode.parent = new_parent + gltf.vnodes[new_parent].children.append(vnode_id) + + def fixup_multitype_nodes(gltf): """ |