bool findGroupAnimationNodes(domCOLLADA* dom, std::vector<std::string>& nodesToGroup) { bool groupPossible = false; const domLibrary_controllers_Array& controllersArrays = dom->getLibrary_controllers_array(); size_t controllersArraysCount = controllersArrays.getCount(); for (size_t i = 0; i < controllersArraysCount; ++i) { const domLibrary_controllersRef& libraryController = controllersArrays.get(i); const domController_Array& controllerArray = libraryController->getController_array(); size_t controllerCount = controllerArray.getCount(); for (size_t j = 0; j < controllerCount; ++j) { const domControllerRef& controllerRef = controllerArray.get(j); const domSkinRef& skinRef = controllerRef->getSkin(); if (skinRef.cast() != NULL) { domSkin::domJointsRef joints = skinRef->getJoints(); domInputLocal_Array& jointInputs = joints->getInput_array(); for (unsigned int i = 0; i < jointInputs.getCount(); ++i) { domInputLocalRef input = jointInputs.get(i); std::string inputSemantic = std::string(input->getSemantic()); domURIFragmentType* sourceURI = &input->getSource(); sourceURI->resolveElement(); const domSourceRef source = (domSource*)(daeElement*)sourceURI->getElement(); if (equals(inputSemantic, "JOINT")) { std::list<domChannelRef> channels; std::list<domNodeRef> nodes; findChannelsTargetingJoints(source, channels, nodes); // If the channels don't share the same animation then they can be grouped. if (!sameAnimation(channels)) { groupPossible = true; domNode* parentMost = getCommonNodeAncestor(nodes); nodesToGroup.push_back(parentMost->getId()); } } } } } } return groupPossible; }
void GPBFile::groupMeshSkinAnimations() { for (std::list<Node*>::iterator it = _nodes.begin(); it != _nodes.end(); ++it) { if (Model* model = (*it)->getModel()) { if (MeshSkin* skin = model->getSkin()) { const std::vector<Node*>& joints = skin->getJoints(); Node* commonAncestor = getCommonNodeAncestor(joints); if (commonAncestor) { // group the animation channels that target this common ancestor and its child nodes Animation* animation = new Animation(); animation->setId("animations"); moveAnimationChannels(commonAncestor, animation); _animations.add(animation); } } } } }