예제 #1
0
	void MeshMergeTool::addMesh(Ogre::MeshPtr mesh)
	{
		SkeletonPtr meshSkel = mesh->getSkeleton();
		if (meshSkel.isNull() && mesh->hasSkeleton())
		{
			meshSkel = SkeletonManager::getSingleton().getByName(mesh->getSkeletonName());
		}

		if (meshSkel.isNull() && !mBaseSkeleton.isNull())
		{
			throw std::logic_error(
					"Some meshes have a skeleton, but others have none, cannot merge.");
		}

		if (!meshSkel.isNull() && mBaseSkeleton.isNull() && !mMeshes.empty())
		{
			throw std::logic_error(
					"Some meshes have a skeleton, but others have none, cannot merge.");
		}

		if (!meshSkel.isNull() && mBaseSkeleton.isNull() && mMeshes.empty())
		{
			mBaseSkeleton = meshSkel;
			print("Set: base skeleton (" + mBaseSkeleton->getName()+")", V_HIGH);
		}

		if (meshSkel != mBaseSkeleton)
		{
			throw std::logic_error(
					"Some meshes have a skeleton, but others have none, cannot merge.");
		}

		mMeshes.push_back(mesh);
	}
예제 #2
0
int main(int argc, char **argv)
{
		if(argc <= 1 || argc > 2)
		{
			std::cout << "Invalid argument, it sould be : ./ogre_show_animationstate /path/name.mesh !\n";
			return -1;
		}

		std::string nameMesh(argv[1]);
		std::string pathMesh;

		int index = nameMesh.size();
		while(nameMesh[index] != '/')
		{
			index--;
			if(index == 0)
			{
				pathMesh = "./";
				break;
			}
		}

		if(index != 0)
		{
			pathMesh = nameMesh.substr(0, index);
		}

		// Init
		Ogre::Root* mRoot = new Ogre::Root();
		new Ogre::DefaultHardwareBufferManager();

		Ogre::ResourceGroupManager::getSingleton().addResourceLocation("./", "FileSystem", "General");
		Ogre::ResourceGroupManager::getSingleton().addResourceLocation(pathMesh, "FileSystem", "General");
		Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups();

		// load mesh
		Ogre::MeshPtr mesh =
		Ogre::MeshManager::getSingleton().load(nameMesh, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

		// create & load a SkeletonInstance
		Ogre::SkeletonInstance* skelInst = new Ogre::SkeletonInstance(mesh->getSkeleton());
		skelInst->load();

		// create & load an AnimationStateSet
		Ogre::AnimationStateSet* animStateSet = new Ogre::AnimationStateSet();
		mesh->_initAnimationState(animStateSet);

		// show animation state
		std::cout << "Animation states : \n";
		Ogre::AnimationStateIterator iter = animStateSet->getAnimationStateIterator();
		while(iter.hasMoreElements())
		{
			Ogre::AnimationState* animationState = iter.getNext();
			std::cout << "\t- " << animationState->getAnimationName() << "\n";
		}

		return 0;
}
예제 #3
0
    void MergeMesh::addMesh( Ogre::MeshPtr mesh )
	{    
        if( mesh->getSkeleton().isNull() )
        {
			log( "Skipped: " + mesh->getName() + " has no skeleton" );
		    return;
        }

        if( m_BaseSkeleton.isNull() )
        {
            m_BaseSkeleton = mesh->getSkeleton();                    
            log( "Set: base skeleton (" + m_BaseSkeleton->getName()+")" );
        }

        if( mesh->getSkeleton() != m_BaseSkeleton )
        {
	        log( "Skipped: " + mesh->getName() + " has other skeleton ("+ mesh->getSkeleton()->getName() +")" );
            return;
        }

        m_Meshes.push_back( mesh );
	}
예제 #4
0
Ogre::MeshPtr
loadMesh(const Ogre::String& meshName, const Ogre::String& groupName,
         const Ogre::String& baseResourceName, const Ogre::String& baseGroupName)
{
    // Load the mesh
    Ogre::MeshPtr mesh = loadCorrelativeResource(
        meshName, groupName,
        baseResourceName, baseGroupName,
        Ogre::MeshManager::getSingleton());

    if (mesh.isNull())
    {
        OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
            "Unable to load mesh " + meshName,
            "loadMesh");
    }

    // Try to resolve skeleton resource
    if (mesh->hasSkeleton() && mesh->getSkeleton().isNull())
    {
        // resolve correlative with mesh
        Ogre::SkeletonPtr skeleton = loadCorrelativeResource(
            mesh->getSkeletonName(), groupName,
            mesh->getName(), mesh->getGroup(),
            Ogre::SkeletonManager::getSingleton());

        if (skeleton.isNull())
        {
            // resolve correlative with base resource
            skeleton = loadCorrelativeResource(
                mesh->getSkeletonName(), groupName,
                baseResourceName, baseGroupName,
                Ogre::SkeletonManager::getSingleton());
        }

        if (skeleton.isNull())
        {
            OGRE_EXCEPT(Ogre::Exception::ERR_ITEM_NOT_FOUND,
                "Unable to load skeleton " + mesh->getSkeletonName() +
                " for mesh " + mesh->getName(),
                "loadMesh");
        }

        // Set to the actual name
        mesh->setSkeletonName(skeleton->getName());
    }

    return mesh;
}
예제 #5
0
std::vector<std::wstring> ManipulatorEffect::GetMeshAnimNames( const std::string& meshname ) const
{
	Ogre::MeshManager::getSingleton().load(meshname, Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
	Ogre::MeshPtr pMesh = Ogre::MeshManager::getSingleton().getByName(meshname);
	std::vector<std::wstring> vecRet;
	const Ogre::SkeletonPtr& pSkeleton = pMesh->getSkeleton();

	//没有可用动画
	if(!pSkeleton.get() || pSkeleton->getNumAnimations()==0)
		return std::move(vecRet);

	for(size_t i=0; i<pSkeleton->getNumAnimations(); ++i)
		vecRet.push_back(Utility::EngineToUnicode(pSkeleton->getAnimation(i)->getName()));

	return std::move(vecRet);
}
예제 #6
0
파일: EC_Mesh.cpp 프로젝트: katik/naali
const std::string& EC_Mesh::GetSkeletonName() const
{
    static std::string empty_name;
    
    if (!entity_)
        return empty_name;
    else
    {
        Ogre::MeshPtr mesh = entity_->getMesh();
        if (!mesh->hasSkeleton())
            return empty_name;
        Ogre::SkeletonPtr skel = mesh->getSkeleton();
        if (skel.isNull())
            return empty_name;
        return skel->getName();
    }
}