<commit_before>//
//  ofxFBXSkeleton.cpp
//  ofxFBX-Example-Importer
//
//  Created by <NAME> on 11/5/13.
//
//

#include "ofxFBXSkeleton.h"
ofxFBXBone dummyBone;

//--------------------------------------------------------------
ofxFBXSkeleton::ofxFBXSkeleton() {
    numBones = 0;
}

//--------------------------------------------------------------
ofxFBXSkeleton::~ofxFBXSkeleton() {
    
}

//--------------------------------------------------------------
void ofxFBXSkeleton::setup( FbxNode *pNode ) {
    ofxFBXNode::setup( pNode );
}

//--------------------------------------------------------------
void ofxFBXSkeleton::reconstructNodeParenting() {
    
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        if( bone->parentBoneName == "" ) continue;
//        ofxFBXBone* pbone   = getBone( bone->parentBoneName );
//        if( bone->parentBoneName == "Armature|FootIK.L" || bone->parentBoneName == "Armature|FootIK.R" ) {
//            cout << "removing parent with name " << bone->parentBoneName << endl;
//            bone->clearParent( false );
//        }
//
//        if( pbone == NULL ) continue;
//        
//        cout << "reconstructNodeParenting :: " << bone->getName() << " parent: " << bone->parentBoneName << endl;
//        
//        if( bone->getParent() != NULL ) {
//            bone->clearParent( false );
//        }
//        
//        bone->setParent( *pbone, false );
//        bone->setGlobalPosition( bone->origNode.getGlobalPosition() );
//        bone->setGlobalOrientation( bone->origNode.getGlobalOrientation() );
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::update( FbxTime& pTime, FbxPose* pPose ) {
    
    
    updateBoneProperties();
//    map<string, ofxFBXBone >::iterator it;
//    for(it = bones.begin(); it != bones.end(); ++it ) {
//        ofxFBXBone* bone    = &it->second;
//        ofxFBXBone* sbone   = getSourceBone( it->first );
//        if( sbone != NULL ) {
//            if( bone->isExternalControlEnabled() ) {
//                sbone->enableExternalControl();
//            } else {
//                sbone->disableExternalControl();
//            }
//            
//            if( bone->isAnimationEnabled() ) {
//                sbone->enableAnimation();
//            } else {
//                sbone->disableAnimation();
//            }
//        }
//    }
    
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->update( pTime, pPose );
        }
    }
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            bone->setTransformMatrix( sbone->getLocalTransformMatrix() );
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::lateUpdate() {
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->setGlobalOrientation( bone->getGlobalOrientation() );
            sbone->setGlobalPosition( bone->getGlobalPosition() );
        }
    }
    
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->updateFbxTransform();
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::updateWithAnimation( FbxTime& pTime, FbxPose* pPose ) {
    
    updateBoneProperties();
//    map<string, ofxFBXBone >::iterator it;
//    for(it = bones.begin(); it != bones.end(); ++it ) {
//        ofxFBXBone* bone    = &it->second;
//        ofxFBXBone* sbone   = getSourceBone( it->first );
//        if( sbone != NULL ) {
//            if( bone->isExternalControlEnabled() ) {
//                sbone->enableExternalControl();
//            } else {
//                sbone->disableExternalControl();
//            }
//            
//            if( bone->isAnimationEnabled() ) {
//                sbone->enableAnimation();
//            } else {
//                sbone->disableAnimation();
//            }
//        }
//    }
    
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->update( pTime, pPose );
            bone->setTransformMatrix( sbone->getLocalTransformMatrix() );
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::lateUpdateWithAnimation() {
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
//            sbone->setTransformMatrix( bone->getLocalTransformMatrix() );
            sbone->localTransformMatrix = bone->localTransformMatrix;
            sbone->setPosition( bone->getPosition() );
            sbone->setOrientation( bone->getOrientationQuat() );
            sbone->setScale( bone->getScale() );
        }
    }
    
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->updateFbxTransform();
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::updateFromCachedSkeleton( shared_ptr< ofxFBXSkeleton> aSkeleton ) {
    
//    updateBoneProperties();
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
//        ofxFBXBone* sbone   = getSourceBone( it->first );
//        ofxFBXBone* sbone = aSkeleton->getSourceBone( it->first );
        ofxFBXBone* obone = aSkeleton->getBone( it->first );
        if( obone != NULL ) {
//            
//            localTransformMatrix = m44;
//
//            ofQuaternion so;
//            localTransformMatrix.decompose(position, orientation, scale, so);
//
//            onPositionChanged();
//            onOrientationChanged();
//            onScaleChanged();
            
//            sbone->update( pTime, NULL );
//            bone->setTransformMatrix( obone->getLocalTransformMatrix() );
            bone->localTransformMatrix = obone->localTransformMatrix;
            bone->setPosition( obone->getPosition() );
            bone->setOrientation( obone->getOrientationQuat() );
            bone->setScale( obone->getScale() );
            
        } else {
            ofLogWarning() << "updateFromCachedSkeleton: " << it->first << " is null !!" << endl;
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::updateBoneProperties() {
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );<commit_msg>fix for node private member<commit_after>//
//  ofxFBXSkeleton.cpp
//  ofxFBX-Example-Importer
//
//  Created by <NAME> on 11/5/13.
//
//

#include "ofxFBXSkeleton.h"
ofxFBXBone dummyBone;

//--------------------------------------------------------------
ofxFBXSkeleton::ofxFBXSkeleton() {
    numBones = 0;
}

//--------------------------------------------------------------
ofxFBXSkeleton::~ofxFBXSkeleton() {
    
}

//--------------------------------------------------------------
void ofxFBXSkeleton::setup( FbxNode *pNode ) {
    ofxFBXNode::setup( pNode );
}

//--------------------------------------------------------------
void ofxFBXSkeleton::reconstructNodeParenting() {
    
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        if( bone->parentBoneName == "" ) continue;
//        ofxFBXBone* pbone   = getBone( bone->parentBoneName );
//        if( bone->parentBoneName == "Armature|FootIK.L" || bone->parentBoneName == "Armature|FootIK.R" ) {
//            cout << "removing parent with name " << bone->parentBoneName << endl;
//            bone->clearParent( false );
//        }
//
//        if( pbone == NULL ) continue;
//        
//        cout << "reconstructNodeParenting :: " << bone->getName() << " parent: " << bone->parentBoneName << endl;
//        
//        if( bone->getParent() != NULL ) {
//            bone->clearParent( false );
//        }
//        
//        bone->setParent( *pbone, false );
//        bone->setGlobalPosition( bone->origNode.getGlobalPosition() );
//        bone->setGlobalOrientation( bone->origNode.getGlobalOrientation() );
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::update( FbxTime& pTime, FbxPose* pPose ) {
    
    
    updateBoneProperties();
//    map<string, ofxFBXBone >::iterator it;
//    for(it = bones.begin(); it != bones.end(); ++it ) {
//        ofxFBXBone* bone    = &it->second;
//        ofxFBXBone* sbone   = getSourceBone( it->first );
//        if( sbone != NULL ) {
//            if( bone->isExternalControlEnabled() ) {
//                sbone->enableExternalControl();
//            } else {
//                sbone->disableExternalControl();
//            }
//            
//            if( bone->isAnimationEnabled() ) {
//                sbone->enableAnimation();
//            } else {
//                sbone->disableAnimation();
//            }
//        }
//    }
    
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->update( pTime, pPose );
        }
    }
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            bone->setTransformMatrix( sbone->getLocalTransformMatrix() );
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::lateUpdate() {
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->setGlobalOrientation( bone->getGlobalOrientation() );
            sbone->setGlobalPosition( bone->getGlobalPosition() );
        }
    }
    
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->updateFbxTransform();
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::updateWithAnimation( FbxTime& pTime, FbxPose* pPose ) {
    
    updateBoneProperties();
//    map<string, ofxFBXBone >::iterator it;
//    for(it = bones.begin(); it != bones.end(); ++it ) {
//        ofxFBXBone* bone    = &it->second;
//        ofxFBXBone* sbone   = getSourceBone( it->first );
//        if( sbone != NULL ) {
//            if( bone->isExternalControlEnabled() ) {
//                sbone->enableExternalControl();
//            } else {
//                sbone->disableExternalControl();
//            }
//            
//            if( bone->isAnimationEnabled() ) {
//                sbone->enableAnimation();
//            } else {
//                sbone->disableAnimation();
//            }
//        }
//    }
    
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->update( pTime, pPose );
            bone->setTransformMatrix( sbone->getLocalTransformMatrix() );
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::lateUpdateWithAnimation() {
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->setTransformMatrix( bone->getLocalTransformMatrix() );
//            sbone->localTransformMatrix = bone->localTransformMatrix;
            sbone->setPosition( bone->getPosition() );
            sbone->setOrientation( bone->getOrientationQuat() );
            sbone->setScale( bone->getScale() );
        }
    }
    
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
        if( sbone != NULL ) {
            sbone->updateFbxTransform();
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::updateFromCachedSkeleton( shared_ptr< ofxFBXSkeleton> aSkeleton ) {
    
//    updateBoneProperties();
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
//        ofxFBXBone* sbone   = getSourceBone( it->first );
//        ofxFBXBone* sbone = aSkeleton->getSourceBone( it->first );
        ofxFBXBone* obone = aSkeleton->getBone( it->first );
        if( obone != NULL ) {
//            
//            localTransformMatrix = m44;
//
//            ofQuaternion so;
//            localTransformMatrix.decompose(position, orientation, scale, so);
//
//            onPositionChanged();
//            onOrientationChanged();
//            onScaleChanged();
            
//            sbone->update( pTime, NULL );
            bone->setTransformMatrix( obone->getLocalTransformMatrix() );
//            bone->localTransformMatrix = obone->localTransformMatrix;
            bone->setPosition( obone->getPosition() );
            bone->setOrientation( obone->getOrientationQuat() );
            bone->setScale( obone->getScale() );
            
        } else {
            ofLogWarning() << "updateFromCachedSkeleton: " << it->first << " is null !!" << endl;
        }
    }
}

//--------------------------------------------------------------
void ofxFBXSkeleton::updateBoneProperties() {
    map<string, ofxFBXBone >::iterator it;
    for(it = bones.begin(); it != bones.end(); ++it ) {
        ofxFBXBone* bone    = &it->second;
        ofxFBXBone* sbone   = getSourceBone( it->first );
{'fraction_non_alphanumeric': 0.23319272343791195, 'fraction_numerical': 0.0010545742156604272, 'mean_word_length': 1.5267277268942547, 'pattern_counts': {'":': 0, '<': 73, '<?xml version=': 0, '>': 201, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3182459', 'n_tokens_mistral': 4665, 'n_tokens_neox': 4516, 'n_words': 772}