[Bf-extensions-cvs] [51b7d41] fbx_io_development: Finish WIP about importing rootbones-as-armatures FBX files (sorry for the mess in history :/ ).
Bastien Montagne
noreply at git.blender.org
Sun Jul 6 19:16:01 CEST 2014
Commit: 51b7d414596c93fe732914fad8915e25dbc3376a
Author: Bastien Montagne
Date: Sun Jul 6 15:20:56 2014 +0200
https://developer.blender.org/rBA51b7d414596c93fe732914fad8915e25dbc3376a
Finish WIP about importing rootbones-as-armatures FBX files (sorry for the mess in history :/ ).
===================================================================
M io_scene_fbx/import_fbx.py
===================================================================
diff --git a/io_scene_fbx/import_fbx.py b/io_scene_fbx/import_fbx.py
index 98cc395..43f009f 100644
--- a/io_scene_fbx/import_fbx.py
+++ b/io_scene_fbx/import_fbx.py
@@ -432,7 +432,8 @@ def blen_read_armatures_add_bone(bl_obj, bl_arm, bones, b_uuid, matrices, fbx_tm
p_ebo = blen_read_armatures_add_bone(bl_obj, bl_arm, bones, p_uuid, matrices, fbx_tmpl_model)
if clusters:
- # Remember we assume (for now) that one bone only has one cluster, this will have to be checked ultimately.
+ # Note in some cases, one bone can have several clusters (kind of LoD?), in Blender we'll always
+ # use only the first, for now.
fbx_cdata, meshes, objects = clusters[0]
objects = {blen_o for fbx_o, blen_o in objects}
@@ -507,7 +508,7 @@ def blen_read_armatures_add_bone(bl_obj, bl_arm, bones, b_uuid, matrices, fbx_tm
return ebo
-def blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix):
+def blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, global_matrix):
from mathutils import Matrix
if global_matrix is None:
@@ -524,7 +525,14 @@ def blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix):
# Need to create the object right now, since we can only add bones in Edit mode... :/
assert(a_item[1] is None)
- bl_adata = a_item[1] = blen_read_object(fbx_tmpl, fbx_adata, bl_arm)
+
+ if fbx_adata.props[2] in {b'LimbNode', b'Root'}:
+ # rootbone-as-armature case...
+ fbx_bones_to_fake_object[fbx_adata.props[0]] = bl_adata = blen_read_object(fbx_tmpl, fbx_adata, bl_arm)
+ # reset transform.
+ bl_adata.matrix_basis = Matrix()
+ else:
+ bl_adata = a_item[1] = blen_read_object(fbx_tmpl, fbx_adata, bl_arm)
# Instantiate in scene.
obj_base = scene.objects.link(bl_adata)
@@ -1566,6 +1574,10 @@ def load(operator, context, filepath="",
# Armatures pre-processing!
fbx_objects_ignore = set()
fbx_objects_parent_ignore = set()
+ # Arg! In some case, root bone is used as armature as well, in Blender we have to 'insert'
+ # an armature object between them, so to handle possible parents of root bones we need a mapping
+ # from root bone uuid to Blender's object...
+ fbx_bones_to_fake_object = dict()
armatures = []
def _():
nonlocal fbx_objects_ignore, fbx_objects_parent_ignore
@@ -1589,10 +1601,11 @@ def load(operator, context, filepath="",
root_bone = False
if not root_bone:
continue
+ fbx_bones_to_fake_object[a_uuid] = None
bones = {}
- todo_uuids = {} if root_bone else {a_uuid}
- init_uuids = {a_uuid} if root_bone else {}
+ todo_uuids = set() if root_bone else {a_uuid}
+ init_uuids = {a_uuid} if root_bone else set()
done_uuids = set()
while todo_uuids or init_uuids:
if init_uuids:
@@ -1671,6 +1684,8 @@ def load(operator, context, filepath="",
armatures.append((a_item, bones))
fbx_objects_ignore.add(a_uuid)
fbx_objects_ignore |= fbx_objects_parent_ignore
+ # We need to handle parenting at object-level for rootbones-as-armature case :/
+ fbx_objects_parent_ignore -= set(fbx_bones_to_fake_object.keys())
_(); del _
def _():
@@ -1776,7 +1791,7 @@ def load(operator, context, filepath="",
def _():
fbx_tmpl = fbx_template_get((b'Model', b'KFbxNode'))
- blen_read_armatures(fbx_tmpl, armatures, scene, global_matrix)
+ blen_read_armatures(fbx_tmpl, armatures, fbx_bones_to_fake_object, scene, global_matrix)
_(); del _
def _():
@@ -1788,14 +1803,17 @@ def load(operator, context, filepath="",
fbx_obj, blen_data = fbx_item
if fbx_obj.id != b'Model':
continue
- if fbx_item[1] is None:
+ # Handle rootbone-as-armature case :/
+ if fbx_uuid in fbx_bones_to_fake_object:
+ blen_data = fbx_bones_to_fake_object[fbx_uuid]
+ if blen_data is None:
continue # no object loaded.. ignore
for (fbx_lnk,
fbx_lnk_item,
fbx_lnk_type) in connection_filter_forward(fbx_uuid, b'Model'):
- fbx_item[1].parent = fbx_lnk_item
+ blen_data.parent = fbx_lnk_item
_(); del _
def _():
@@ -1808,7 +1826,10 @@ def load(operator, context, filepath="",
fbx_obj, blen_data = fbx_item
if fbx_obj.id != b'Model':
continue
- if fbx_item[1] is None:
+ # Handle rootbone-as-armature case :/
+ if fbx_uuid in fbx_bones_to_fake_object:
+ blen_data = fbx_bones_to_fake_object[fbx_uuid]
+ if blen_data is None:
continue # no object loaded.. ignore
if fbx_item[1].parent is None:
More information about the Bf-extensions-cvs
mailing list