From f7d2a2893090a9bfb1b7890ca94d0354156b4627 Mon Sep 17 00:00:00 2001 From: scrawl Date: Sun, 19 Apr 2015 14:25:36 +0200 Subject: [PATCH] Port BoneOffset --- apps/openmw/mwrender/creatureanimation.cpp | 26 ---------------------- apps/openmw/mwrender/npcanimation.cpp | 25 --------------------- components/sceneutil/attach.cpp | 23 ++++++++++++++++++- components/sceneutil/visitor.hpp | 2 +- 4 files changed, 23 insertions(+), 53 deletions(-) diff --git a/apps/openmw/mwrender/creatureanimation.cpp b/apps/openmw/mwrender/creatureanimation.cpp index 9ccdf390e..241ea56a3 100644 --- a/apps/openmw/mwrender/creatureanimation.cpp +++ b/apps/openmw/mwrender/creatureanimation.cpp @@ -133,32 +133,6 @@ void CreatureWeaponAnimation::updatePart(PartHolderPtr& scene, int slot) //else //mAmmunition.setNull(); - // FIXME: code duplicated from NpcAnimation - /* - if(scene->mSkelBase) - { - Ogre::SkeletonInstance *skel = scene->mSkelBase->getSkeleton(); - if(scene->mSkelBase->isParentTagPoint()) - { - Ogre::Node *root = scene->mSkelBase->getParentNode(); - if(skel->hasBone("BoneOffset")) - { - Ogre::Bone *offset = skel->getBone("BoneOffset"); - - root->translate(offset->getPosition()); - - // It appears that the BoneOffset rotation is completely bogus, at least for light models. - //root->rotate(offset->getOrientation()); - root->pitch(Ogre::Degree(-90.0f)); - - root->scale(offset->getScale()); - root->setInitialState(); - } - } - updateSkeletonInstance(mSkelBase->getSkeleton(), skel); - } - */ - /* std::vector >::iterator ctrl(scene->mControllers.begin()); for(;ctrl != scene->mControllers.end();++ctrl) diff --git a/apps/openmw/mwrender/npcanimation.cpp b/apps/openmw/mwrender/npcanimation.cpp index eeb5298b8..719fb336b 100644 --- a/apps/openmw/mwrender/npcanimation.cpp +++ b/apps/openmw/mwrender/npcanimation.cpp @@ -698,31 +698,6 @@ bool NpcAnimation::addOrReplaceIndividualPart(ESM::PartReferenceType type, int g } } /* - if(mObjectParts[type]->mSkelBase) - { - Ogre::SkeletonInstance *skel = mObjectParts[type]->mSkelBase->getSkeleton(); - if(mObjectParts[type]->mSkelBase->isParentTagPoint()) - { - Ogre::Node *root = mObjectParts[type]->mSkelBase->getParentNode(); - if(skel->hasBone("BoneOffset")) - { - Ogre::Bone *offset = skel->getBone("BoneOffset"); - - root->translate(offset->getPosition()); - - // It appears that the BoneOffset rotation is completely bogus, at least for light models. - //root->rotate(offset->getOrientation()); - root->pitch(Ogre::Degree(-90.0f)); - - root->scale(offset->getScale()); - root->setInitialState(); - } - } - - if (isSkinned(mObjectParts[type])) - updateSkeletonInstance(mSkelBase->getSkeleton(), skel); - } - std::vector >::iterator ctrl(mObjectParts[type]->mControllers.begin()); for(;ctrl != mObjectParts[type]->mControllers.end();++ctrl) { diff --git a/components/sceneutil/attach.cpp b/components/sceneutil/attach.cpp index f084704c3..26185eb3e 100644 --- a/components/sceneutil/attach.cpp +++ b/components/sceneutil/attach.cpp @@ -165,9 +165,27 @@ namespace SceneUtil if (!find.mFoundNode) throw std::runtime_error(std::string("Can't find attachment node ") + attachNode); + FindByNameVisitor findBoneOffset("BoneOffset"); + toAttach->accept(findBoneOffset); + + osg::ref_ptr trans; + + if (findBoneOffset.mFoundNode) + { + osg::MatrixTransform* boneOffset = dynamic_cast(findBoneOffset.mFoundNode); + if (!boneOffset) + throw std::runtime_error("BoneOffset must be a MatrixTransform"); + + trans = new osg::PositionAttitudeTransform; + trans->setPosition(boneOffset->getMatrix().getTrans()); + // The BoneOffset rotation seems to be incorrect + trans->setAttitude(osg::Quat(-90, osg::Vec3f(1,0,0))); + } + if (attachNode.find("Left") != std::string::npos) { - osg::ref_ptr trans = new osg::PositionAttitudeTransform; + if (!trans) + trans = new osg::PositionAttitudeTransform; trans->setScale(osg::Vec3f(-1.f, 1.f, 1.f)); // Need to invert culling because of the negative scale @@ -176,7 +194,10 @@ namespace SceneUtil osg::FrontFace* frontFace = new osg::FrontFace; frontFace->setMode(osg::FrontFace::CLOCKWISE); trans->getOrCreateStateSet()->setAttributeAndModes(frontFace, osg::StateAttribute::ON); + } + if (trans) + { find.mFoundNode->addChild(trans); trans->addChild(toAttach); return trans; diff --git a/components/sceneutil/visitor.hpp b/components/sceneutil/visitor.hpp index 59c706f11..d26f95116 100644 --- a/components/sceneutil/visitor.hpp +++ b/components/sceneutil/visitor.hpp @@ -28,7 +28,7 @@ namespace SceneUtil traverse(node); } - const std::string& mNameToFind; + std::string mNameToFind; osg::Group* mFoundNode; };