Home > other >  About using the Open Asset Import Library reading fang binxing files animation data
About using the Open Asset Import Library reading fang binxing files animation data

Time:09-21

Recently to "the Introduction to 3 d Game Programming with Directx 11" after watching, because individuals interested in 3 d animation comparison, using 3 ds Max 2013 to skin of a model, after to. Fang binxing format export data, considering the use of API I chose Autodesk fang binxing SDK at the beginning, only to find that the API is quite bad to use, the thought of "the Introduction to 3 d Game Programming with Directx 11" have introduced the Open Asset Import Library the SDK, so just to switch to this, although still feel confused in use process, but relatively fang binxing SDK has been a lot better, but when the loading of bone and animation data out of the question, finally the entire model is incorrect matrix transformation into don't know what appearance, only to see a man about upside down to move...
Ok, cut the crap, will I loaded bones and animation data code below post, trouble have read this book or use Open Asset Import Library for fang binxing file conversion player show just a little, (my application framework is used "the Introduction to 3 d Game Programming with Directx 11" chapter 25 routine framework, in order to use this framework I use Open Asset Import Library will. Fang binxing into in the book. M3d format)
 
//
///this function is used to construct the skeletal hierarchy, access to deviation matrix and the weight of each vertex table
//
Void Convertor: : LoadBone (const aiScene * scene, STD: : map & Maps, STD: : vector & Hierarchy, STD: : vector & Are)
{
//
//set up stored in an array of the skeleton tree structure
//
Auto meshs=scene - & gt; MMeshes;
Auto meshnum=scene - & gt; MNumMeshes;
STD: : set Names;
STD: : map//
//this code to find all the bones under the node name
//in order to avoid repeated use the STD: : set The
//at the same time using STD: : map//
For (the decltype (meshnum) I=0; I & lt; Meshnum; I++)
{
Auto bonenum=meshs [I] - & gt; MNumBones;
For (the decltype (bonenum) b=0; B & lt; Bonenum; B++)
{
Names. Insert (meshs [I] - & gt; MBones [b] - & gt; MName. C_Str ());
Matrixmaps [meshs [I] - & gt; mBones [b] - & gt; mName. C_Str ()]=meshs [I] - & gt; MBones [b] - & gt; MOffsetMatrix [0].
}
}
//
//browse the SDK documentation bone node closest to the root node is the root node of the bone
//consider that in order to find root node of the bone, so using the sequence traversal tree structure
//
STD: : queueQueue. Push (scene - & gt; MRootNode);
//
//as a result of the root node of the bone (aiNode *) the parent node is not NULL, so using a tag
//
Bool RootBone=true;
While (queue. The size ()
{
AiNode * n=the queue in front ();
Queue. Pop ();
//
//is bone node
//
If (names. The find (n - & gt; MName. C_Str ())!=names. The end ())
{
//
//the bones in the array subscript linked with name
//
Maps [n - & gt; mName. C_Str ()]=Hierarchy. The size ();
If (RootBone)//bone root node of the
{
Hierarchy. The push_back (1);//there is no parent node, so the parent node in the array index of 1
RootBone=false;
}
The else
{
Hierarchy. The push_back (maps [n - & gt; mParent - & gt; mName. C_Str ()]);
}
}
Auto num=n - & gt; MNumChildren;
For (the decltype (num) I=0; I & lt; Num. I++)
{
Queue. Push (n - & gt; MChildren [I]);
}
}
//
//copy migration matrix in the vector
//
Offsets. The resize (names. The size ());
Matrix4x4 offset.
For (auto & amp; S: names)
{
Auto index=maps [s].
Auto m=matrixmaps [s].
Memcpy (offset.. float1d, m, sizeof (float) * 16);
TransposeMatrix (offset);//according to the SDK documentation, to transpose matrix
Offsets [index]=offset;
}
//
//the following processing weight
//due to vertex depending on the material stored in the corresponding Subset (Subset)
//and in the framework of I, weights and corresponding index of bone is also part of the vertex
//
STD: : vector Prenums (Subsets. The size (), 0).
For (the decltype (meshnum) m=0; M & lt; Meshnum; M++)
{
Auto Bonenum=meshs [m] - & gt; MNumBones;
Auto materialindex=meshs [m] - & gt; MMaterialIndex;//corresponding to the Subsets of subscript
Auto are=& amp; Subsets [materialindex] are [prenums [materialindex]].
For (the decltype (Bonenum) b=0; B & lt; Bonenum; B++)
{
Int BoneIndex=maps [meshs [m] - & gt; mBones [b] - & gt; mName. C_Str ()];//bone in said relationships in the array subscript
Auto weightnum=meshs [m] - & gt; MBones [b] - & gt; MNumWeights;
For (the decltype (weightnum) w=0; W & lt; Weightnum; W++)
{
Auto weight=meshs [m] - & gt; MBones [b] - & gt; MWeights [w];
Auto & amp; V=are [weight mVertexId];
V.w eights. Push_back (STD: : tuple (weight. MWeight, BoneIndex));
}
}
Prenums [materialindex] +=meshs [m] - & gt; MNumVertices;
}

//
//the weight according to descending order
//when the output data only output data, the first four less than four filling to ensure that the weight of each vertex table are only four elements
//
For (auto & amp; S: Subsets)
{
For (auto & amp; V: s.V ertices)
STD: : sort (v.w eights. The begin (), v.w eights. The end (), compare);
}
}

//
///this function frame data read
//
Void Convertor: : LoadAnimation (const aiScene * scene, const STD: : map & IndexMap, STD: : vector & Clips)
{
Auto num=scene - & gt; MNumAnimations;
Auto BoneNum=IndexMap. The size ();
For (the decltype (num) a=0; a {
AnimationClip clip;
Clip. ClipName=scene - & gt; MAnimations [a] - & gt; MName. C_Str ();
//
//to clipname some special processing, avoid. M3d file read error
//
For (auto & amp; C: clip. ClipName)
{
If (c==' ')
C='_';
}
Clip. BoneAnimations. Resize (BoneNum);
Auto animation=scene - & gt; MAnimations [a];
Auto TPS=animation - & gt; MTicksPerSecond;
If (TPS & lt;=0.0 f) TPS=1.0 f;
Auto channelnum=animation - & gt; MNumChannels;
For (the decltype (channelnum) c=0; C & lt; Channelnum; C + +)
{
BoneAnimation BoneAnimation;
Auto channel=animation - & gt; MChannels [c];
Auto keyframenum=channel - & gt; MNumPositionKeys;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related