void UIBatch::AddOrMerge(const UIBatch& batch, PODVector<UIBatch>& batches) { if (batch.vertexEnd_ == batch.vertexStart_) return; if (!batches.Empty() && batches.Back().Merge(batch)) return; batches.Push(batch); }
// ---------------------------------------------------------------------------- bool IKSolver::BuildTreeToEffector(IKEffector* effector) { /* * NOTE: This function makes the assumption that the node the effector is * attached to is -- without a doubt -- in our subtree (by using * ComponentIsInOurSubtree() first). If this is not the case, the program * will abort. */ /* * we need to build tree up to the node where this effector was added. Do * this by following the chain of parent nodes until we hit a node that * exists in the solver's subtree. Then iterate backwards again and add each * missing node to the solver's tree. */ const Node* iterNode = effector->GetNode(); ik_node_t* ikNode; PODVector<const Node*> missingNodes; while ((ikNode = ik_node_find_child(solver_->tree, iterNode->GetID())) == nullptr) { missingNodes.Push(iterNode); iterNode = iterNode->GetParent(); // Assert the assumptions made (described in the beginning of this function) assert(iterNode != nullptr); assert (iterNode->HasComponent<IKSolver>() == false || iterNode == node_); } while (missingNodes.Size() > 0) { iterNode = missingNodes.Back(); missingNodes.Pop(); ik_node_t* ikChildNode = CreateIKNodeFromUrhoNode(iterNode); ik_node_add_child(ikNode, ikChildNode); ikNode = ikChildNode; } return true; }
// ---------------------------------------------------------------------------- void IKSolver::BuildTreeToEffector(const Node* node) { // Check if the component that was added is an IK effector. If not, then it // does not concern us. IKEffector* effector = static_cast<IKEffector*>(node->GetComponent<IKEffector>()); if (effector == NULL || effector->GetType() != IKEffector::GetTypeStatic()) return; // May need to build tree up to the node where this effector was added. Do // this by following the chain of parent nodes until we hit a node that // exists in the solver's tree. Then iterate backwards again and add each // missing node to the solver's tree. PODVector<const Node*> missingNodes; const Node* iterNode = node; ik_node_t* ikNode = ik_node_find_child(solver_->tree, node->GetID()); while (ikNode == NULL) { missingNodes.Push(iterNode); iterNode = iterNode->GetParent(); ikNode = ik_node_find_child(solver_->tree, iterNode->GetID()); } while (missingNodes.Size() > 0) { iterNode = missingNodes.Back(); missingNodes.Pop(); ik_node_t* ikChildNode = CreateIKNode(iterNode); ik_node_add_child(ikNode, ikChildNode); ikNode = ikChildNode; } // The tip of the tree is the effector. The solver library has ownership of // the effector object, but our IKEffector object also needs to know about // it. ik_effector_t* ikEffector = ik_effector_create(); ik_node_attach_effector(ikNode, ikEffector); // ownership of effector effector->SetIKEffector(ikEffector); // "weak" reference to effector effector->SetIKSolver(this); effectorList_.Push(effector); MarkSolverTreeDirty(); }