[Bf-extensions-cvs] [c786b20] fbx_io_development: FBX export: working shape keys at last.

Bastien Montagne noreply at git.blender.org
Thu Jun 12 15:56:55 CEST 2014


Commit: c786b201add7a0dc396e2b0ce08ab17d84e96909
Author: Bastien Montagne
Date:   Thu Jun 12 15:54:23 2014 +0200
https://developer.blender.org/rBAc786b201add7a0dc396e2b0ce08ab17d84e96909

FBX export: working shape keys at last.

Tested with Unity (looks like FBX does not like empty shapes...).

Also, we need to store diff from org mesh, quite obviously. :/

Next step: add animation support for those, and probably some more tweaking.
And then, import...

===================================================================

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 dd2cbac..c684805 100644
--- a/io_scene_fbx/export_fbx_bin.py
+++ b/io_scene_fbx/export_fbx_bin.py
@@ -703,15 +703,7 @@ def fbx_data_mesh_shapes_elements(root, me_obj, me, scene_data, fbx_me_tmpl, fbx
 
     channels = []
 
-    for shape, (channel_key, geom_key) in shapes.items():
-        # Only write vertices really different from org coordinates!
-        shape_verts_co = []
-        shape_verts_idx = []
-        for idx, (sv, v) in enumerate(zip(shape.data, me.vertices)):
-            if similar_values_iter(sv.co, v.co):
-                continue
-            shape_verts_co.extend(sv.co);
-            shape_verts_idx.append(idx);
+    for shape, (channel_key, geom_key, shape_verts_co, shape_verts_idx) in shapes.items():
         shape_verts_weights = [100.0] * (len(shape_verts_co) // 3)  # for now, we can use vgroup later here!
         channels.append((channel_key, shape, shape_verts_weights))
 
@@ -2033,8 +2025,22 @@ def fbx_data_from_scene(scene, settings):
             continue
         shapes_key = get_blender_mesh_shape_key(me)
         for shape in me.shape_keys.key_blocks:
+            # Only write vertices really different from org coordinates!
+            # XXX FBX does not like empty shapes (makes Unity crash e.g.), so we have to do this here... :/
+            shape_verts_co = []
+            shape_verts_idx = []
+            for idx, (sv, v) in enumerate(zip(shape.data, me.vertices)):
+                if similar_values_iter(sv.co, v.co):
+                    # Note: Maybe this is a bit too simplistic, should we use real shape base here? Though FBX does not
+                    #       have this at all... Anyway, this should cover most common cases imho.
+                    continue
+                shape_verts_co.extend(sv.co - v.co);
+                shape_verts_idx.append(idx);
+            if not shape_verts_co:
+                continue
             channel_key, geom_key = get_blender_mesh_shape_channel_key(me, shape)
-            data_deformers_shape.setdefault(me, (me_key, shapes_key, OrderedDict()))[2][shape] = (channel_key, geom_key)
+            data = (channel_key, geom_key, shape_verts_co, shape_verts_idx)
+            data_deformers_shape.setdefault(me, (me_key, shapes_key, OrderedDict()))[2][shape] = data
 
     # Armatures!
     data_deformers_skin = OrderedDict()
@@ -2243,7 +2249,7 @@ def fbx_data_from_scene(scene, settings):
     for me_key, shapes_key, shapes in data_deformers_shape.values():
         # shape -> geometry
         connections.append((b"OO", get_fbx_uuid_from_key(shapes_key), get_fbx_uuid_from_key(me_key), None))
-        for channel_key, geom_key in shapes.values():
+        for channel_key, geom_key, _shape_verts_co, _shape_verts_idx in shapes.values():
             # shape channel -> shape
             connections.append((b"OO", get_fbx_uuid_from_key(channel_key), get_fbx_uuid_from_key(shapes_key), None))
             # geometry (keys) -> shape channel



More information about the Bf-extensions-cvs mailing list