// ---------------------------------------------------------------------------- void IKSolver::HandleComponentRemoved(StringHash eventType, VariantMap& eventData) { using namespace ComponentRemoved; if (solver_->tree == NULL) return; Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr()); Component* component = static_cast<Component*>(eventData[P_COMPONENT].GetPtr()); /* * When a solver gets added into the scene, any parent solver's tree will * be invalidated. We need to find all parent solvers (by iterating up the * tree) and mark them as such. */ if (component->GetType() == IKSolver::GetTypeStatic()) { for (Node* iterNode = node; iterNode != NULL; iterNode = iterNode->GetParent()) { IKSolver* parentSolver = iterNode->GetComponent<IKSolver>(); if (parentSolver != NULL) parentSolver->MarkTreeNeedsRebuild(); } return; // No need to continue processing effectors or constraints } // If an effector was removed, the tree will have to be rebuilt. if (component->GetType() == IKEffector::GetTypeStatic()) { if (ComponentIsInOurSubtree(component) == false) return; ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID()); assert(ikNode != NULL); ik_node_destroy_effector(ikNode); static_cast<IKEffector*>(component)->SetIKEffectorNode(NULL); effectorList_.RemoveSwap(static_cast<IKEffector*>(component)); ApplyOriginalPoseToScene(); MarkTreeNeedsRebuild(); return; } // Remove the ikNode* reference the IKConstraint was holding if (component->GetType() == IKConstraint::GetTypeStatic()) { if (ComponentIsInOurSubtree(component) == false) return; ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID()); assert(ikNode != NULL); static_cast<IKConstraint*>(component)->SetIKConstraintNode(NULL); constraintList_.RemoveSwap(static_cast<IKConstraint*>(component)); } }
// ---------------------------------------------------------------------------- void IKSolver::HandleComponentRemoved(Scene *,Node *node,Component *component) { if (solver_->tree == nullptr) return; /* * When a solver gets added into the scene, any parent solver's tree will * be invalidated. We need to find all parent solvers (by iterating up the * tree) and mark them as such. */ if (component->GetType() == IKSolver::GetTypeStatic()) { for (Node* iterNode = node; iterNode != nullptr; iterNode = iterNode->GetParent()) { IKSolver* parentSolver = iterNode->GetComponent<IKSolver>(); if (parentSolver != nullptr) parentSolver->MarkTreeNeedsRebuild(); } return; // No need to continue processing effectors or constraints } // If an effector was removed, the tree will have to be rebuilt. if (component->GetType() == IKEffector::GetTypeStatic()) { if (ComponentIsInOurSubtree(component) == false) return; ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID()); assert(ikNode != nullptr); ik_node_destroy_effector(ikNode); static_cast<IKEffector*>(component)->SetIKEffectorNode(nullptr); RemovePopBack(effectorList_,static_cast<IKEffector*>(component)); ApplyOriginalPoseToScene(); MarkTreeNeedsRebuild(); return; } // Remove the ikNode* reference the IKConstraint was holding if (component->GetType() == IKConstraint::GetTypeStatic()) { if (ComponentIsInOurSubtree(component) == false) return; ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID()); assert(ikNode != nullptr); static_cast<IKConstraint*>(component)->SetIKConstraintNode(nullptr); RemovePopBack(constraintList_,static_cast<IKConstraint*>(component)); } }
// ---------------------------------------------------------------------------- void IKSolver::HandleComponentAdded(StringHash eventType, VariantMap& eventData) { using namespace ComponentAdded; (void)eventType; Node* node = static_cast<Node*>(eventData[P_NODE].GetPtr()); Component* component = static_cast<Component*>(eventData[P_COMPONENT].GetPtr()); /* * When a solver gets added into the scene, any parent solver's tree will * be invalidated. We need to find all parent solvers (by iterating up the * tree) and mark them as such. */ if (component->GetType() == IKSolver::GetTypeStatic()) { for (Node* iterNode = node; iterNode != NULL; iterNode = iterNode->GetParent()) { IKSolver* parentSolver = iterNode->GetComponent<IKSolver>(); if (parentSolver != NULL) parentSolver->MarkTreeNeedsRebuild(); } return; // No need to continue processing effectors or constraints } if (solver_->tree == NULL) return; /* * Update tree if component is an effector and is part of our subtree. */ if (component->GetType() == IKEffector::GetTypeStatic()) { // Not interested in components that won't be part of our if (ComponentIsInOurSubtree(component) == false) return; BuildTreeToEffector(static_cast<IKEffector*>(component)); effectorList_.Push(static_cast<IKEffector*>(component)); return; } if (component->GetType() == IKConstraint::GetTypeStatic()) { if (ComponentIsInOurSubtree(component) == false) return; constraintList_.Push(static_cast<IKConstraint*>(component)); } }
// ---------------------------------------------------------------------------- void IKSolver::HandleComponentAdded(Scene *,Node *node,Component *component) { /* * When a solver gets added into the scene, any parent solver's tree will * be invalidated. We need to find all parent solvers (by iterating up the * tree) and mark them as such. */ if (component->GetType() == IKSolver::GetTypeStatic()) { for (Node* iterNode = node; iterNode != nullptr; iterNode = iterNode->GetParent()) { IKSolver* parentSolver = iterNode->GetComponent<IKSolver>(); if (parentSolver != nullptr) parentSolver->MarkTreeNeedsRebuild(); } return; // No need to continue processing effectors or constraints } if (solver_->tree == nullptr) return; /* * Update tree if component is an effector and is part of our subtree. */ if (component->GetType() == IKEffector::GetTypeStatic()) { // Not interested in components that won't be part of our if (ComponentIsInOurSubtree(component) == false) return; BuildTreeToEffector(static_cast<IKEffector*>(component)); effectorList_.push_back(static_cast<IKEffector*>(component)); return; } if (component->GetType() == IKConstraint::GetTypeStatic()) { if (ComponentIsInOurSubtree(component) == false) return; constraintList_.push_back(static_cast<IKConstraint*>(component)); } }