framework2

Форк
0
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
//----------------------------------------
12
ofxFBXSource::Node::NodeType ofxFBXSkeleton::getType() {
13
    return ofxFBXSource::Node::OFX_FBX_SKELETON;
14
}
15

16
//--------------------------------------------------------------------------------
17
void ofxFBXSkeleton::setup( shared_ptr<ofxFBXSource::Node> anode ) {
18
    ofxFBXNode::setup( anode );
19
    if( anode && anode->getType() == ofxFBXSource::Node::OFX_FBX_SKELETON ) {
20
        auto tskel = dynamic_pointer_cast<ofxFBXSource::Skeleton>(anode);
21
        if( tskel ) {
22
            root = make_shared<ofxFBXBone>();
23
            root->setParent(*this);
24
            //root->setup( anode );
25
            root->setBoneSource( tskel->root, root );
26
            addChild(root);
27
        }
28
    }
29
}
30

31
//--------------------------------------------------------------
32
void ofxFBXSkeleton::setupRoot( shared_ptr<ofxFBXNode> aparent ) {
33
    root->setParentNode( aparent );
34
}
35

36
//--------------------------------------------------------------
37
void ofxFBXSkeleton::update( FbxTime& pTime, FbxPose* pPose ) {
38
    _checkSrcSkel();
39
    if(mSrcSkel) {
40
        mSrcSkel->update( pTime, pPose );
41
        
42
    }
43
}
44

45
//--------------------------------------------------------------
46
void ofxFBXSkeleton::update( int aAnimIndex, signed long aMillis ) {
47
    _checkSrcSkel();
48
//    cout << "ofxFBXSkeleton::update " << getName() << " : src skel: " << ( mSrcSkel ? "Good" : "Bad" ) << " | " << ofGetFrameNum() << endl;
49
    if(mSrcSkel) {
50
        mSrcSkel->update( aAnimIndex, aMillis );
51
    }
52
}
53

54
//--------------------------------------------------------------
55
void ofxFBXSkeleton::update( int aAnimIndex1, signed long aAnim1Millis, int aAnimIndex2, signed long aAnim2Millis, float aMixPct ) {
56
    _checkSrcSkel();
57
    if(mSrcSkel) {
58
        mSrcSkel->update( aAnimIndex1, aAnim1Millis, aAnimIndex2, aAnim2Millis, aMixPct );
59
    }
60
}
61

62
//----------------------------------------------------------------
63
void ofxFBXSkeleton::update() {
64
    root->update();
65
}
66

67
//----------------------------------------------------------------
68
void ofxFBXSkeleton::lateUpdate(FbxTime& pTime, FbxAnimLayer* pAnimLayer, FbxPose* pPose) {
69
    root->lateUpdate();
70
}
71

72
//----------------------------------------------------------------
73
void ofxFBXSkeleton::draw( float aLen, bool aBDrawAxes ) {
74
//    transformGL(); {
75
        root->draw( aLen, aBDrawAxes );
76
//    } restoreTransformGL();
77
}
78

79
//----------------------------------------------------------------
80
int ofxFBXSkeleton::getNumBones() {
81
    return root->getNumBones();
82
}
83

84
//----------------------------------------------------------------
85
shared_ptr<ofxFBXBone> ofxFBXSkeleton::getBone( string aName ) {
86
    if( root->getName() == aName ) return root;
87
    return root->getBone( aName );
88
}
89

90
//----------------------------------------------------------------
91
string ofxFBXSkeleton::getAsString( int aLevel ) {
92
    string tstr = "Skeleton: " + root->getName()+ " total bones: " + ofToString( getNumBones(), 0 ) + "\n ";
93
    return (tstr + root->getAsString(1));
94
}
95

96
//----------------------------------------------------------------
97
void ofxFBXSkeleton::enableAnimationForBone( string aName, bool bRecursive ) {
98
    shared_ptr<ofxFBXBone> bone = getBone( aName );
99
    if(bone == NULL) {
100
        ofLogWarning("Skeleton :: 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
    shared_ptr<ofxFBXBone> bone = getBone( aName );
109
    if(bone == NULL) {
110
        ofLogWarning("Skeleton :: 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
//----------------------------------------------------------------
127
void ofxFBXSkeleton::_checkSrcSkel() {
128
    if( !mSrcSkel && mSrcNode && mSrcNode->getType() == ofxFBXSource::Node::OFX_FBX_SKELETON ) {
129
        mSrcSkel = dynamic_pointer_cast<ofxFBXSource::Skeleton>(mSrcNode);
130
    }
131
}
132

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.