Welcome to the new Ogre Wiki!
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
If you haven't done so already, be sure to visit the Wiki Portal to read about how the wiki works. Especially the Ogre Wiki Overview page.
the following code has some dependancies:
- you have available the AxisObject or one like it.
- tinyxml is available.
- the bones referenced in the xml file do indeed exist on the entity.
- the format of your xml file match's the data from MountNodeSet MaxScript
bool loadMountXML(Ogre::String filename, Ogre::SceneManager *scene, Ogre::Entity *entity) { if(!scene || !entity) return false; TiXmlDocument *xmlDoc=0; TiXmlElement *xmlRoot=0, *xmlNodes=0; Ogre::ResourceGroupManager & rgm = Ogre::ResourceGroupManager::getSingleton(); Ogre::FileInfoListPtr xmlInfo = rgm.findResourceFileInfo("General", filename); if(!xmlInfo.get()) return false; Ogre::FileInfoList &info = *xmlInfo.get(); if(!info.size()) return false; Ogre::FileInfo finfo = info[0]; Ogre::String fileName = finfo.archive->getName(); fileName += "/" + finfo.filename; xmlDoc = new TiXmlDocument(); xmlDoc->LoadFile(fileName); xmlInfo.setNull(); xmlRoot = xmlDoc->RootElement(); if(Ogre::String(xmlRoot->Value()) != "MountNodes") { Ogre::LogManager::getSingleton().logMessage( "Error: Invalid .xml File. Missing <MountNodes>" ); delete xmlDoc; return false; } xmlNodes = xmlRoot->FirstChildElement("Node"); while(xmlNodes) { Ogre::String nodeName = xmlNodes->Attribute("Name"); Ogre::String nodeParentName = xmlNodes->Attribute("Parent"); Ogre::String nodeParentType = xmlNodes->Attribute("ParentType"); TiXmlElement *xmlPos, *xmlRot; Ogre::Vector3 pos; Ogre::Quaternion rot; Ogre::String str; xmlPos = xmlNodes->FirstChildElement("Position"); if(xmlPos) { str = xmlPos->Attribute("x"); pos.x = Ogre::StringConverter::parseReal(str); str = xmlPos->Attribute("y"); pos.y = Ogre::StringConverter::parseReal(str); str = xmlPos->Attribute("z"); pos.z = Ogre::StringConverter::parseReal(str); } xmlRot = xmlNodes->FirstChildElement("Rotation"); if(xmlRot) { str = xmlRot->Attribute("x"); rot.x = Ogre::StringConverter::parseReal(str); str = xmlRot->Attribute("y"); rot.y = Ogre::StringConverter::parseReal(str); str = xmlRot->Attribute("z"); rot.z = -Ogre::StringConverter::parseReal(str); str = xmlRot->Attribute("w"); rot.w = Ogre::StringConverter::parseReal(str); } xmlNodes = xmlNodes->NextSiblingElement("Node"); static int hackid=0; Ogre::String oname = nodeParentName + ":" + Ogre::StringConverter::toString(hackid++); AxisObject axisObj; Ogre::ManualObject*o=axisObj.createAxis(scene, oname, 1); Bone* bone = entity->getSkeleton()->getBone(nodeParentName); Matrix4 boneMat4; bone->getWorldTransforms(&boneMat4); Matrix3 boneMat3; boneMat4.extract3x3Matrix(boneMat3); // calculate offset in bone space Vector3 offsetPos = pos * boneMat3; // calculate orientation in bone space Quaternion quat = bone->getWorldOrientation().Inverse() * rot; entity->attachObjectToBone(nodeParentName, o, quat, offsetPos); } delete xmlDoc; return true; }
Contributors to this page: jacmoe
and
OgreWikiBot
.
Page last modified on Thursday 31 of December, 2009 15:08:28 UTC by jacmoe
.
The content on this page is licensed under the terms of the Creative Commons Attribution-ShareAlike License.
As an exception, any source code contributed within the content is released into the Public Domain.
Sidebar
Search box
Online users
41
online users

