framework2
131 строка · 4.4 Кб
1//
2// ofxFBXSkeleton.cpp
3// ofxFBX-Example-Importer
4//
5// Created by Nick Hardeman on 11/5/13.
6//
7//
8
9#include "ofxFBXSkeleton.h"10
11//----------------------------------------
12ofxFBXSource::Node::NodeType ofxFBXSkeleton::getType() {13return ofxFBXSource::Node::OFX_FBX_SKELETON;14}
15
16//--------------------------------------------------------------------------------
17void ofxFBXSkeleton::setup( shared_ptr<ofxFBXSource::Node> anode ) {18ofxFBXNode::setup( anode );19if( anode && anode->getType() == ofxFBXSource::Node::OFX_FBX_SKELETON ) {20auto tskel = dynamic_pointer_cast<ofxFBXSource::Skeleton>(anode);21if( tskel ) {22root = make_shared<ofxFBXBone>();23root->setParent(*this);24//root->setup( anode );25root->setBoneSource( tskel->root, root );26addChild(root);27}28}29}
30
31//--------------------------------------------------------------
32void ofxFBXSkeleton::setupRoot( shared_ptr<ofxFBXNode> aparent ) {33root->setParentNode( aparent );34}
35
36//--------------------------------------------------------------
37void ofxFBXSkeleton::update( FbxTime& pTime, FbxPose* pPose ) {38_checkSrcSkel();39if(mSrcSkel) {40mSrcSkel->update( pTime, pPose );41
42}43}
44
45//--------------------------------------------------------------
46void ofxFBXSkeleton::update( int aAnimIndex, signed long aMillis ) {47_checkSrcSkel();48// cout << "ofxFBXSkeleton::update " << getName() << " : src skel: " << ( mSrcSkel ? "Good" : "Bad" ) << " | " << ofGetFrameNum() << endl;
49if(mSrcSkel) {50mSrcSkel->update( aAnimIndex, aMillis );51}52}
53
54//--------------------------------------------------------------
55void ofxFBXSkeleton::update( int aAnimIndex1, signed long aAnim1Millis, int aAnimIndex2, signed long aAnim2Millis, float aMixPct ) {56_checkSrcSkel();57if(mSrcSkel) {58mSrcSkel->update( aAnimIndex1, aAnim1Millis, aAnimIndex2, aAnim2Millis, aMixPct );59}60}
61
62//----------------------------------------------------------------
63void ofxFBXSkeleton::update() {64root->update();65}
66
67//----------------------------------------------------------------
68void ofxFBXSkeleton::lateUpdate(FbxTime& pTime, FbxAnimLayer* pAnimLayer, FbxPose* pPose) {69root->lateUpdate();70}
71
72//----------------------------------------------------------------
73void ofxFBXSkeleton::draw( float aLen, bool aBDrawAxes ) {74// transformGL(); {
75root->draw( aLen, aBDrawAxes );76// } restoreTransformGL();
77}
78
79//----------------------------------------------------------------
80int ofxFBXSkeleton::getNumBones() {81return root->getNumBones();82}
83
84//----------------------------------------------------------------
85shared_ptr<ofxFBXBone> ofxFBXSkeleton::getBone( string aName ) {86if( root->getName() == aName ) return root;87return root->getBone( aName );88}
89
90//----------------------------------------------------------------
91string ofxFBXSkeleton::getAsString( int aLevel ) {92string tstr = "Skeleton: " + root->getName()+ " total bones: " + ofToString( getNumBones(), 0 ) + "\n ";93return (tstr + root->getAsString(1));94}
95
96//----------------------------------------------------------------
97void ofxFBXSkeleton::enableAnimationForBone( string aName, bool bRecursive ) {98shared_ptr<ofxFBXBone> bone = getBone( aName );99if(bone == NULL) {100ofLogWarning("Skeleton :: enableExternalControl : can not find bone with name ") << aName;101return;102}103bone->enableAnimation( bRecursive );104}
105
106//----------------------------------------------------------------
107void ofxFBXSkeleton::disableAnimationForBone( string aName, bool bRecursive ) {108shared_ptr<ofxFBXBone> bone = getBone( aName );109if(bone == NULL) {110ofLogWarning("Skeleton :: enableExternalControl : can not find bone with name ") << aName;111return;112}113bone->disableAnimation( bRecursive );114}
115
116//----------------------------------------------------------------
117void ofxFBXSkeleton::enableAnimation() {118root->enableAnimation( true );119}
120
121//----------------------------------------------------------------
122void ofxFBXSkeleton::disableAnimation() {123root->disableAnimation( true );124}
125
126//----------------------------------------------------------------
127void ofxFBXSkeleton::_checkSrcSkel() {128if( !mSrcSkel && mSrcNode && mSrcNode->getType() == ofxFBXSource::Node::OFX_FBX_SKELETON ) {129mSrcSkel = dynamic_pointer_cast<ofxFBXSource::Skeleton>(mSrcNode);130}131}
132