framework2
146 строк · 4.7 Кб
1//
2// ofxFBXSkeleton.cpp
3// ofxFBX-Example-Importer
4//
5// Created by Nick Hardeman on 11/5/13.
6//
7//
8
9#include "ofxFBXSrcSkeleton.h"
10using namespace ofxFBXSource;
11
12ofxFBXSource::Bone dummyBone;
13
14//--------------------------------------------------------------
15Skeleton::Skeleton() {
16
17}
18
19//--------------------------------------------------------------
20Skeleton::~Skeleton() {
21
22}
23
24//--------------------------------------------------------------
25void Skeleton::setup( FbxNode *pNode ) {
26ofxFBXSource::Node::setup( pNode );
27root->setup( pNode );
28root->setParent(*this);
29root->setAsRoot();
30}
31
32//--------------------------------------------------------------
33//void ofxFBXSkeleton::reconstructNodeParenting() {
34//
35//// cout << "ofxFBXSkeleton :: rootSounce->hasParent() : " << (rootSource->getParent()==NULL) << " | " << ofGetFrameNum() << endl;
36//
37// ofxFBXBone tbone = *rootSource;
38// root = tbone;
39//
40// root.setAsRoot();
41// root.sourceBone = rootSource;
42// root.setupFromSourceBones();
43//
44// // now we need to reassociate the bone parent pointers, so they are not pointing to the source bones //
45// // we need a way to get all of the bones as pointers, so we can easily make the association //
46// map< string, ofxFBXBone* > tempBones = root.getAllBones();
47// map< string, ofxFBXBone* >::iterator it;
48//
49// // clear the parents to remove the previous listeners //
50// for( it = tempBones.begin(); it != tempBones.end(); ++it ) {
51// if( it->second->getParent() != NULL ) {
52// it->second->clearParent();
53// }
54// }
55//
56// for( it = tempBones.begin(); it != tempBones.end(); ++it ) {
57// if( it->second->hasSkeletonParent() ) {
58// if( tempBones.count(it->second->parentBoneName) ) {
59// it->second->setParent( *tempBones[it->second->parentBoneName] );
60// }
61// }
62// }
63//}
64
65//--------------------------------------------------------------
66void Skeleton::update( FbxTime& pTime, FbxPose* pPose ) {
67root->update( pTime, pPose );
68}
69
70//--------------------------------------------------------------
71void Skeleton::update( int aAnimIndex, signed long aMillis ) {
72root->update( aAnimIndex, aMillis );
73}
74
75//--------------------------------------------------------------
76void Skeleton::update( int aAnimIndex1, signed long aAnim1Millis, int aAnimIndex2, signed long aAnim2Millis, float aMixPct ) {
77root->update( aAnimIndex1, aAnim1Millis, aAnimIndex2, aAnim2Millis, aMixPct );
78}
79
80//--------------------------------------------------------------
81void Skeleton::lateUpdate() {
82root->lateUpdate();
83}
84
85//--------------------------------------------------------------
86//void Skeleton::draw( float aLen, bool aBDrawAxes ) {
87// root->draw( aLen, aBDrawAxes );
88//}
89
90//--------------------------------------------------------------
91shared_ptr<ofxFBXSource::Bone> Skeleton::getBone( string aName ) {
92if( root->getName() == aName ) return root;
93return root->getBone( aName );
94}
95
96//--------------------------------------------------------------
97//void ofxFBXSkeleton::enableAnimationForBone( string aName, bool bRecursive ) {
98// ofxFBXBone* bone = getBone( aName );
99// if(bone == NULL) {
100// ofLogWarning("ofxFBXSkeleton :: enableExternalControl : can not find bone with name ") << aName;
101// return;
102// }
103// bone->enableAnimation( bRecursive );
104//}
105//
106////--------------------------------------------------------------
107//void ofxFBXSkeleton::disableAnimationForBone( string aName, bool bRecursive ) {
108// ofxFBXBone* bone = getBone( aName );
109// if(bone == NULL) {
110// ofLogWarning("ofxFBXSkeleton :: enableExternalControl : can not find bone with name ") << aName;
111// return;
112// }
113// bone->disableAnimation( bRecursive );
114//}
115//
116////--------------------------------------------------------------
117//void ofxFBXSkeleton::enableAnimation() {
118// root.enableAnimation( true );
119//}
120//
121////--------------------------------------------------------------
122//void ofxFBXSkeleton::disableAnimation() {
123// root.disableAnimation( true );
124//}
125
126//--------------------------------------------------------------
127void Skeleton::clearKeyFrames() {
128root->clearKeyFrames();
129}
130
131//--------------------------------------------------------------
132int Skeleton::getNumBones() {
133return root->getNumBones();
134}
135
136//--------------------------------------------------------------
137string Skeleton::toString() {
138string tstr = "Skeleton: " + root->getName()+ " total bones: " + ofToString( getNumBones(), 0 ) + "\n ";
139tstr += root->getAsString();
140return tstr;
141}
142
143//--------------------------------------------------------------
144//map< string, shared_ptr<ofxFBXSource::Bone> > Skeleton::getAllBones() {
145// return root->getAllBones();
146//}
147
148
149
150
151
152
153
154
155
156
157