[Bf-extensions-cvs] [732c190] master: FBX export: write clusters for non-deforming bones too (need their 'rest pose' matrices...)
Bastien Montagne
noreply at git.blender.org
Sat May 3 18:20:10 CEST 2014
Commit: 732c1901d4df0ab75c9cca83d5c85c8f46084b2b
Author: Bastien Montagne
Date: Sat May 3 18:09:40 2014 +0200
https://developer.blender.org/rBA732c1901d4df0ab75c9cca83d5c85c8f46084b2b
FBX export: write clusters for non-deforming bones too (need their 'rest pose' matrices...)
===================================================================
M io_scene_fbx/export_fbx_bin.py
===================================================================
diff --git a/io_scene_fbx/export_fbx_bin.py b/io_scene_fbx/export_fbx_bin.py
index bdd18ea..a71f5c8 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -1861,7 +1861,8 @@ def fbx_data_armature_elements(root, armature, scene_data):
elem_data_single_float64(fbx_skin, b"Link_DeformAcuracy", 50.0) # Only vague idea what it is...
# Pre-process vertex weights (also to check vertices assigned ot more than four bones).
- bo_vg_idx = {bo.name: obj.vertex_groups[bo.name].index for bo in clusters.keys()}
+ bo_vg_idx = {bo.name: obj.vertex_groups[bo.name].index
+ for bo in clusters.keys() if bo.name in obj.vertex_groups}
valid_idxs = set(bo_vg_idx.values())
vgroups = {vg.index: OrderedDict() for vg in obj.vertex_groups}
verts_vgroups = (sorted(((vg.group, vg.weight) for vg in v.groups if vg.weight and vg.group in valid_idxs),
@@ -1873,9 +1874,10 @@ def fbx_data_armature_elements(root, armature, scene_data):
for bo, clstr_key in clusters.items():
# Find which vertices are affected by this bone/vgroup pair, and matching weights.
- vg_idx = bo_vg_idx[bo.name]
- indices = vgroups[vg_idx].keys()
- weights = vgroups[vg_idx].values()
+ # Note we still write a cluster for bones not affecting the mesh, to get 'rest pose' data
+ # (the TransformBlah matrices).
+ vg_idx = bo_vg_idx.get(bo.name, None)
+ indices, weights = ((), ()) if vg_idx is None else zip(*vgroups[vg_idx].items())
# Create the cluster.
fbx_clstr = elem_data_single_int64(root, b"Deformer", get_fbxuid_from_key(clstr_key))
@@ -1886,9 +1888,8 @@ def fbx_data_armature_elements(root, armature, scene_data):
# No idea what that user data might be...
fbx_userdata = elem_data_single_string(fbx_clstr, b"UserData", b"")
fbx_userdata.add_string(b"")
- if indices:
- elem_data_single_int32_array(fbx_clstr, b"Indexes", indices)
- elem_data_single_float64_array(fbx_clstr, b"Weights", weights)
+ elem_data_single_int32_array(fbx_clstr, b"Indexes", indices)
+ elem_data_single_float64_array(fbx_clstr, b"Weights", weights)
# Transform, TransformLink and TransformAssociateModel matrices...
# They seem to be doublons of BindPose ones??? Have armature (associatemodel) in addition, though.
# WARNING! Even though official FBX API presents Transform in global space,
@@ -2123,6 +2124,9 @@ def fbx_skeleton_from_armature(scene, settings, armature, objects, data_meshes,
data_bones[bo] = (key, data_key, armature)
bones[bo.name] = bo
+ if not bones:
+ return
+
for obj in objects.keys():
if not isinstance(obj, Object):
continue
@@ -2144,17 +2148,11 @@ def fbx_skeleton_from_armature(scene, settings, armature, objects, data_meshes,
if not found:
continue
- # Now we have a mesh using this armature. First, find out which bones are concerned!
- # XXX Assuming here non-used bones can have no cluster, this has to be checked!
- used_bones = tuple(bones[vg.name] for vg in obj.vertex_groups if vg.name in bones)
- if not used_bones:
- continue
-
+ # Now we have a mesh using this armature.
# Note: bindpose have no relations at all (no connections), so no need for any preprocess for them.
-
# Create skin & clusters relations (note skins are connected to geometry, *not* model!).
_key, me, _free = data_meshes[obj]
- clusters = OrderedDict((bo, get_blender_bone_cluster_key(armature, me, bo)) for bo in used_bones)
+ clusters = OrderedDict((bo, get_blender_bone_cluster_key(armature, me, bo)) for bo in bones.values())
data_deformers.setdefault(armature, OrderedDict())[me] = (get_blender_armature_skin_key(armature, me),
obj, clusters)
More information about the Bf-extensions-cvs
mailing list