Exemplo n.º 1
0
NifOgre::EntityList NpcAnimation::insertBoundedPart(const std::string &mesh, int group, const std::string &bonename)
{
    NifOgre::EntityList entities = NifOgre::Loader::createEntities(mEntityList.mSkelBase, bonename,
                                                                   mInsert, mesh);
    std::vector<Ogre::Entity*> &parts = entities.mEntities;
    for(size_t i = 0;i < parts.size();i++)
    {
        parts[i]->getUserObjectBindings().setUserAny(Ogre::Any(group));
        if (mVisibilityFlags != 0)
            parts[i]->setVisibilityFlags(mVisibilityFlags);

        for(unsigned int j=0; j < parts[i]->getNumSubEntities(); ++j)
        {
            Ogre::SubEntity* subEnt = parts[i]->getSubEntity(j);
            subEnt->setRenderQueueGroup(subEnt->getMaterial()->isTransparent() ? RQG_Alpha : RQG_Main);
        }
    }
    if(entities.mSkelBase)
    {
        Ogre::AnimationStateSet *aset = entities.mSkelBase->getAllAnimationStates();
        Ogre::AnimationStateIterator asiter = aset->getAnimationStateIterator();
        while(asiter.hasMoreElements())
        {
            Ogre::AnimationState *state = asiter.getNext();
            state->setEnabled(false);
            state->setLoop(false);
        }
        Ogre::SkeletonInstance *skelinst = entities.mSkelBase->getSkeleton();
        Ogre::Skeleton::BoneIterator boneiter = skelinst->getBoneIterator();
        while(boneiter.hasMoreElements())
            boneiter.getNext()->setManuallyControlled(true);
    }
    return entities;
}
Exemplo n.º 2
0
std::vector<std::wstring> ManipulatorEffect::GetLocatorNames() const
{
	Ogre::Entity* ent = ManipulatorSystem.GetObject().GetSelection();
	assert(ent);

	std::vector<std::wstring> ret;
	//M3模型从max导出时locator命名为Ref_xxx形式
	Ogre::SkeletonPtr skel = ent->getMesh()->getSkeleton();
	Ogre::Skeleton::BoneIterator iter = skel->getBoneIterator();

	while (iter.hasMoreElements())
	{
		Ogre::Bone* pBone = iter.peekNext();
		if(pBone->getName().find("Ref_") != Ogre::String::npos)
			ret.push_back(Utility::EngineToUnicode(pBone->getName()));

		iter.getNext();
	}

	return std::move(ret);
}
void SkeletonMergingWidget::fillCommonBonesList(Ogre::Skeleton * target, Ogre::Skeleton * source)
{
  commonBonesList->clear();
  if (target && source)
  {
    QSet<QString> boneNames[2];
    Ogre::Skeleton* skeletons[2] = {target, source};
    for (int i = 0; i < 2; ++i)
    {
      Ogre::Skeleton::BoneIterator it = skeletons[i]->getBoneIterator();
      while (it.hasMoreElements())
      {
        Ogre::Skeleton::BoneIterator::const_iterator bit = it.current();
        boneNames[i].insert(QString::fromStdString((*bit)->getName()));
        it.moveNext();
      }
    }
    QStringList commonBones = QStringList::fromSet(boneNames[0] & boneNames[1]);
    commonBonesList->addItems(commonBones);
  }
}
Exemplo n.º 4
0
  void RendererSystemComponent::LinkSkeletons(Ogre::SceneNode* sceneNode, RendererSystemComponent::SkeletonList* skeletons)
  {
    SceneNode::ObjectIterator objects = sceneNode->getAttachedObjectIterator();

    while(objects.hasMoreElements())
    {
      MovableObject* object = objects.getNext();

      if(object->getMovableType() == EntityFactory::FACTORY_TYPE_NAME)
      {
        Entity* entity = m_scene->GetSceneManager()->getEntity(object->getName());

        if (entity->hasSkeleton())
        {
          Ogre::Skeleton::BoneIterator boneIterator = entity->getSkeleton()->getBoneIterator();

          while(boneIterator.hasMoreElements())
          {
            Ogre::Bone* oBone = boneIterator.getNext();
            oBone->setManuallyControlled(true);

            /*Entity *axis = m_scene->GetSceneManager()->createEntity(oBone->getName() + "_axis", "/data/entities/meshes/axes.mesh");
            TagPoint* tagPoint = entity->attachObjectToBone(oBone->getName(), axis);
            tagPoint->setScale(0.005f, 0.005f, 0.005f);*/
          }

          skeletons->push_back(entity->getSkeleton());
        }
      }
    }

    Node::ChildNodeIterator children = sceneNode->getChildIterator();

    while(children.hasMoreElements())
    {
      SceneNode* child = static_cast<SceneNode*>(children.getNext());
      this->LinkSkeletons(child, skeletons);
    }
  }
Exemplo n.º 5
0
void Animation::setObjectRoot(const std::string &model, bool baseonly)
{
    OgreAssert(mAnimSources.empty(), "Setting object root while animation sources are set!");

    mSkelBase = NULL;
    mObjectRoot.setNull();

    if(model.empty())
        return;

    std::string mdlname = Misc::StringUtils::lowerCase(model);
    std::string::size_type p = mdlname.rfind('\\');
    if(p == std::string::npos)
        p = mdlname.rfind('/');
    if(p != std::string::npos)
        mdlname.insert(mdlname.begin()+p+1, 'x');
    else
        mdlname.insert(mdlname.begin(), 'x');
    if(!Ogre::ResourceGroupManager::getSingleton().resourceExistsInAnyGroup(mdlname))
    {
        mdlname = model;
        Misc::StringUtils::toLower(mdlname);
    }

    mObjectRoot = (!baseonly ? NifOgre::Loader::createObjects(mInsert, mdlname) :
                               NifOgre::Loader::createObjectBase(mInsert, mdlname));
    if(mObjectRoot->mSkelBase)
    {
        mSkelBase = mObjectRoot->mSkelBase;

        Ogre::AnimationStateSet *aset = mObjectRoot->mSkelBase->getAllAnimationStates();
        Ogre::AnimationStateIterator asiter = aset->getAnimationStateIterator();
        while(asiter.hasMoreElements())
        {
            Ogre::AnimationState *state = asiter.getNext();
            state->setEnabled(false);
            state->setLoop(false);
        }

        // Set the bones as manually controlled since we're applying the
        // transformations manually
        Ogre::SkeletonInstance *skelinst = mObjectRoot->mSkelBase->getSkeleton();
        Ogre::Skeleton::BoneIterator boneiter = skelinst->getBoneIterator();
        while(boneiter.hasMoreElements())
            boneiter.getNext()->setManuallyControlled(true);

        // Reattach any objects that have been attached to this one
        ObjectAttachMap::iterator iter = mAttachedObjects.begin();
        while(iter != mAttachedObjects.end())
        {
            if(!skelinst->hasBone(iter->second))
                mAttachedObjects.erase(iter++);
            else
            {
                mSkelBase->attachObjectToBone(iter->second, iter->first);
                ++iter;
            }
        }
    }
    else
        mAttachedObjects.clear();

    for(size_t i = 0;i < mObjectRoot->mControllers.size();i++)
    {
        if(mObjectRoot->mControllers[i].getSource().isNull())
            mObjectRoot->mControllers[i].setSource(mAnimationTimePtr[0]);
    }
}
Exemplo n.º 6
0
void Animation::updateSkeletonInstance(const Ogre::SkeletonInstance *skelsrc, Ogre::SkeletonInstance *skel)
{
    Ogre::Skeleton::BoneIterator boneiter = skel->getRootBoneIterator();
    while(boneiter.hasMoreElements())
        updateBoneTree(skelsrc, boneiter.getNext());
}