void Bone::addChild(DBObject* child){ if(!child) { return; } if(checkIfClass<Bone>(child)) { Bone* bone = (Bone*) child; if(child == this || (bone && bone->contains(this))) { printf("An Bone cannot be added as a child to itself or one of its children (or children's children, etc.) \n"); return; } } if(child->parent) { child->parent->removeChild(child); } _children.push_back(child); child->parent = this; child->setArmature(this->_armature); if(!_slot && checkIfClass<Slot>(child)) { _slot = (Slot*) child; } }
void AnimationState::addMixingTransform(const String &timelineName, int type , bool recursive) { if(_clip && _clip->getTimeline(timelineName)) { if(recursive) { int i = _armature->_boneList.size(); Bone* bone; Bone* currentBone; while(i --) { bone = _armature->_boneList[i]; if(bone->name == timelineName) { currentBone = bone; } if(currentBone && (currentBone == bone || currentBone->contains(bone))) { _mixingTransforms[bone->name] = type; } } } else { _mixingTransforms[timelineName] = type; } updateTimelineStates(); } else { // TODO(hejiangzhou): Shall we disable exception? throw std::invalid_argument("argument error"); } }
AnimationState* AnimationState::removeMixingTransform(const std::string &timelineName, bool recursive) { if (recursive) { Bone *currentBone = nullptr; // From root to leaf for (size_t i = _armature->getBones().size(); i--;) { Bone *bone = _armature->getBones()[i]; if (bone->name == timelineName) { currentBone = bone; } if (currentBone && (currentBone == bone || currentBone->contains(bone))) { auto iterator = std::find(_mixingTransforms.begin(), _mixingTransforms.end(), bone->name); if (iterator != _mixingTransforms.end()) { _mixingTransforms.erase(iterator); } } } } else { auto iterator = std::find(_mixingTransforms.begin(), _mixingTransforms.end(), timelineName); if (iterator != _mixingTransforms.end()) { _mixingTransforms.erase(iterator); } } updateTimelineStates(); return this; }
void AnimationState::removeMixingTransform(const String &timelineName , bool recursive) { if(!timelineName.empty()) { if(recursive) { int i = _armature->_boneList.size(); Bone* bone; Bone* currentBone; while(i --) { bone = _armature->_boneList[i]; if(bone->name == timelineName) { currentBone = bone; } if(currentBone && (currentBone == bone || currentBone->contains(bone))) { std::map<String , int>::iterator iter = _mixingTransforms.find(bone->name); if(iter != _mixingTransforms.end()) { _mixingTransforms.erase(iter); } } } } else { std::map<String , int>::iterator iter = _mixingTransforms.find(timelineName); if(iter != _mixingTransforms.end()) { _mixingTransforms.erase(iter); } } } updateTimelineStates(); }
AnimationState* AnimationState::addMixingTransform(const std::string &timelineName, bool recursive) { if (recursive) { Bone *currentBone = nullptr; // From root to leaf for (size_t i = _armature->getBones().size(); i--;) { Bone *bone = _armature->getBones()[i]; const std::string &boneName = bone->name; if (boneName == timelineName) { currentBone = bone; } if ( currentBone && (currentBone == bone || currentBone->contains(bone)) && _clip->getTimeline(boneName) && std::find(_mixingTransforms.cbegin(), _mixingTransforms.cend(), boneName) == _mixingTransforms.cend() ) { _mixingTransforms.push_back(boneName); } } } else if ( _clip->getTimeline(timelineName) && std::find(_mixingTransforms.cbegin(), _mixingTransforms.cend(), timelineName) == _mixingTransforms.cend() ) { _mixingTransforms.push_back(timelineName); } updateTimelineStates(); return this; }