From: Yotam G. <yo...@yo...> - 2015-11-24 06:47:26
|
Thank you for this thorough library. I am trying to extract rest-pose joint positions from the aiScene data structure. I have tried both recursively walking the nodes and taking the inverse of the mesh's bone's offset matrix. Neither strategy is working. The inverse offset matrix works for some files, but not others. The recursive approach never works (yet it is what all drawing code I can find online seems to use). Here is code to reproduce the problem: import pyassimp from numpy import * def recurse( node, M, print_name ): ## recurse with the composed transform M = dot( node.transformation, M ) if node.name == print_name: return M for child in node.children: result = recurse( child, M, print_name ) if result is not None: return result return None print '====================' scene = pyassimp.load( 'test/models-nonbsd/Ogre/OgreSDK/fish.mesh.xml' ) print ''' fish.mesh.xml has a corresponding skeleton file fish.skeleton.xml containing: ... <bone id="1" name="Bone01"> <position x="-3.95093" y="0" z="0.00265706" /> <rotation angle="1.5708"> <axis x="-1" y="-0" z="-0" /> </rotation> </bone> <bone id="2" name="Bone02"> <position x="2.96562" y="-0.0183002" z="0" /> <rotation angle="0.340339"> <axis x="-0" y="-0" z="1" /> </rotation> </bone> <bone id="3" name="Bone03"> <position x="2.79479" y="-4.94082e-007" z="0" /> <rotation angle="0.305433"> <axis x="-0" y="-0" z="1" /> </rotation> </bone> ... and ... <boneparent bone="zzwxy" parent="Bone01" /> <boneparent bone="Bone02" parent="Bone01" /> <boneparent bone="Bone03" parent="Bone02" /> <boneparent bone="Bone04" parent="Bone03" /> ... ''' print 'Bone01 is x="-3.95093" y="0" z="0.00265706"' print "Inverse of mesh[0]'s Bone01 offsetMatrix:" print linalg.inv( [ bone for bone in scene.meshes[0].bones if bone.name == 'Bone01' ][0].offsetmatrix )[:,3] ## [-3.95093012 0. 0.00265706 1. ] print "recursive Bone01:" print recurse( scene.rootnode, identity(4), 'Bone01' )[:,3] ## [-3.95093012 0. 0.00265706 1. ] print 'Bone02 is x="2.96562" y="-0.0183002" z="0"' print "Inverse of mesh[0]'s Bone02 offsetMatrix:" print linalg.inv( [ bone for bone in scene.meshes[0].bones if bone.name == 'Bone02' ][0].offsetmatrix )[:,3] ## Incorrect :-( ## [-0.98530999 0.00000007 0.02095728 1. ] print "recursive Bone02:" print recurse( scene.rootnode, identity(4), 'Bone02' )[:,3] ## Incorrect :-( ## [-0.75869087 -1.337147 0.00265706 1. ] print 'Bone01 is x="2.79479" y="-4.94082e-007" z="0"' print "Inverse of mesh[0]'s Bone03 offsetMatrix:" print linalg.inv( [ bone for bone in scene.meshes[0].bones if bone.name == 'Bone03' ][0].offsetmatrix )[:,3] ## Incorrect :-( ## [ 1.64917518 -0.00000338 -0.91196164 1. ] print "recursive Bone03:" print recurse( scene.rootnode, identity(4), 'Bone03' )[:,3] ## Incorrect :-( ## [ 2.47330211 -1.50340308 0.00265706 1. ] print '====================' scene = pyassimp.load( 'test/models-nonbsd/MD5/Bob.md5mesh' ) print ''' Bob.md5mesh has: ... "origin" -1 ( -0.000000 0.016430 -0.006044 ) ( 0.707107 0.000000 0.707107 ) // "sheath" 0 ( 11.004813 -3.177138 31.702473 ) ( 0.307041 -0.578614 0.354181 ) // origin "sword" 1 ( 9.809593 -9.361549 40.753730 ) ( 0.305557 -0.578155 0.353505 ) // sheath "pubis" 0 ( 0.014076 2.064442 26.144581 ) ( -0.466932 -0.531013 -0.466932 ) // origin "pelvis" 3 ( 0.014076 2.592741 30.241238 ) ( -0.535591 -0.462288 -0.534983 ) // pubis ... ''' print 'pubis: 0.014076 2.064442 26.144581' print "Inverse of mesh[0]'s pubis offsetMatrix:" print linalg.inv( [ bone for bone in scene.meshes[0].bones if bone.name == 'pubis' ][0].offsetmatrix )[:,3] ## Correct! ## [ 0.014076 2.06444179 26.14458028 1. ] print "recursive pubis:" print recurse( scene.rootnode, identity(4), 'pubis' )[:,3] ## Incorrect :-( ## [ 26.16690503 -2.05011099 0.0080476 1. ] print 'pelvis: 0.014076 2.592741 30.241238' print "Inverse of mesh[0]'s pelvis offsetMatrix:" print linalg.inv( [ bone for bone in scene.meshes[0].bones if bone.name == 'pelvis' ][0].offsetmatrix )[:,3] ## Correct! ## [ 0.014076 2.59274058 30.24123814 1. ] print "recursive pelvis:" print recurse( scene.rootnode, identity(4), 'pelvis' )[:,3] ## Incorrect :-( ## [ 25.74089374 9.26054974 0.01009969 1. ] Any help would be greatly appreciated. Thank you, Yotam |