Exemplo n.º 1
0
// 设置正常的外观颜色.
void CEditDobject_NT::SetUnSelLook()
{
	if(0 == m_materilaOldVector.size())
	{
		return;
	}

	int iCount = m_EntityList.size();
	Ogre::Entity* pEntity = NULL;

	int iIndex = 0;

	for(int i = 0; i < iCount; i++)
	{
		pEntity = m_EntityList[i].pEntity;
		if(pEntity)
		{
			Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
			if(pSubEntiy)
			{
				if(iIndex >= (int)m_materilaOldVector.size())
				{
					continue;
				}
			
				std::string strMaterialName = m_materilaOldVector[iIndex]->getName();
				pSubEntiy->setMaterialName(strMaterialName);
				iIndex++;
				
			}

		}
	}

}
void ResourceGroupReloader::UpdateMaterialRenderableVisitor::visit(
	Ogre::Renderable *rend, Ogre::ushort lodIndex, bool isDebug, Ogre::Any *pAny)
{
	const Ogre::MaterialPtr mat = rend->getMaterial();
	if(!mat.isNull())
	{
		std::string newMatName = mat->getName();
		Ogre::MaterialPtr newMat = Ogre::MaterialManager::getSingleton().getByName(newMatName);
		if(newMat.isNull())
		{
			// this can happen if there was error during the reloading of the material.
			// in that case, we keep the ancient one.
			// Ice::Log::Instance().LogMessage(newMatName+" : new material is null!");
			return;
		}

		// unfortunately, the renderable gives access only to a const MaterialPtr.
		// and there is no 'setMaterial' or 'setMaterialName' method on renderables.
		// so I have to try to down cast with known classes...
		{   
			Ogre::SubEntity* lRend = dynamic_cast<Ogre::SubEntity*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
		{
			Ogre::SimpleRenderable* lRend = dynamic_cast<Ogre::SimpleRenderable*>(rend);
			if(lRend){lRend->setMaterial(newMatName);return;} 
		}
		{
			Ogre::ShadowRenderable* lRend = dynamic_cast<Ogre::ShadowRenderable*>(rend);
			if(lRend){lRend->setMaterial(newMat);return;} 
		}
		{   
			Ogre::BillboardChain* lRend = dynamic_cast<Ogre::BillboardChain*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
		{   
			Ogre::BillboardSet* lRend = dynamic_cast<Ogre::BillboardSet*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
		{   
			Ogre::OverlayElement* lRend = dynamic_cast<Ogre::OverlayElement*>(rend);
			if(lRend){lRend->setMaterialName(newMatName);return;} 
		}
	}else{
		// was there for debug...
		// Ice::Log::Instance().LogMessage("material of renderable is null!");
	}
}
Exemplo n.º 3
0
void Level::processEntity(TiXmlElement *XMLNode, Ogre::SceneNode *parent)
{
	Ogre::String name = getAttribute(XMLNode, "name");
	Ogre::String meshFile = getAttribute(XMLNode, "meshFile");

	TiXmlElement *element;
	Ogre::Entity *entity = 0;

	try
	{
		entity = mSceneMgr->createEntity(name, meshFile);
		entity->setCastShadows(true);

		PhysicsManager::instance()->createConvexMesh(entity);

		element = XMLNode->FirstChildElement("subentities");
		if(element)
		{
			element = element->FirstChildElement("subentity");
			while (element)
			{
				Ogre::SubEntity *subEnt;

				Ogre::String materialFile = getAttribute(element, "materialName");
				unsigned int index = Ogre::StringConverter::parseInt(getAttribute(element,"index"));

				subEnt = entity->getSubEntity(index);
				subEnt->setMaterialName(materialFile);

				element = element->NextSiblingElement("subentity");		
			}
		}
		entity->setRenderingDistance(1000);
		parent->attachObject(entity);

	}
	catch(Ogre::Exception e)
	{
		Ogre::LogManager::getSingleton().logMessage("Error loading an entity!");
	}
	element = XMLNode->FirstChildElement("userDataReference");
}
void FvXMLAnimationModelSerializerImpl::ReadEntity( 
	FvXMLSectionPtr spSection, Ogre::SceneNode* pkNode, FvAnimationModel* pkDest )
{
	Ogre::SceneManager *pkSceneManager = Ogre::Root::getSingleton().
		_getCurrentSceneManager();
	FV_ASSERT(pkSceneManager);

	FvString kMeshIdentifier = spSection->ReadString("identifier");
	FvString kMeshFile = spSection->ReadString("mesh");

	Ogre::Entity *pkEntity = pkSceneManager->createEntity(
		pkNode->getName() + "_" + kMeshIdentifier,kMeshFile);
	FV_ASSERT(pkEntity);
	pkEntity->setCastShadows(pkDest->m_bCastShadows);
	pkNode->attachObject(pkEntity);
	
	pkDest->m_akNodes[pkDest->m_u32CurrentLodLevel].m_kEntityList.push_back(pkEntity);
	pkEntity->setRenderQueueGroup(RENDER_QUEUE_MAX);
	AnimationStateSet *pkAnimations = pkEntity->getAllAnimationStates();
	if(pkAnimations)
	{
		AnimationStateIterator kIt = pkAnimations->getAnimationStateIterator();
		while (kIt.hasMoreElements())
		{
			AnimationState *pkAnim= kIt.getNext();
			if(pkDest->GetAnimation(pkAnim->getAnimationName()) == NULL)
				pkDest->m_kModelAnimations.insert(std::make_pair(pkAnim->getAnimationName(),pkAnim));
		}
	}

	std::vector<FvXMLSectionPtr> kSubentities;
	spSection->OpenSections("subentities/subentity",kSubentities);
	std::vector<FvXMLSectionPtr>::iterator kSubIt = kSubentities.begin();
	for(; kSubIt != kSubentities.end(); ++kSubIt)
	{
		int iIndex = (*kSubIt)->ReadInt("index",-1);
		FvString kMaterialName = (*kSubIt)->ReadString("materialName");
		Ogre::SubEntity *pkSubEntity = pkEntity->getSubEntity(iIndex);
		if(pkSubEntity && !kMaterialName.empty())
			pkSubEntity->setMaterialName(kMaterialName);
	}
}
Exemplo n.º 5
0
// 设置选中的外观颜色.
void CEditDobject_NT::SetSelectLook(Ogre::ColourValue color)
{

	if(0 == m_materialSelVector.size())
	{
		// 选中材质的名字.
		Ogre::String strCloneName;
		int iCount = m_EntityList.size();
		Ogre::Entity* pEntity = NULL;

		for(int i = 0; i < iCount; i++)
		{
			pEntity = m_EntityList[i].pEntity;
			if(pEntity)
			{
				Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
				if(pSubEntiy)
				{
					
					Ogre::MaterialPtr pMaterial = pSubEntiy->getMaterial();
					
					if(pMaterial.isNull())
					{
						return;
					}//

					const Ogre::String& strName = pMaterial->getName();

					if("BaseWhite" == strName)
					{
						continue;
					}

					strCloneName = strName;
					strCloneName += "_select";
					
					Ogre::MaterialManager* pMaterialManager = (Ogre::MaterialManager*)(pMaterial->getCreator());

					if(NULL == pMaterialManager)
					{
						return;
					}

					Ogre::MaterialPtr pMaterialClone = pMaterialManager->getByName(strCloneName); 
						
					if(pMaterialClone.isNull())
					{
						pMaterialClone = pMaterial->clone(strCloneName);
					}
					//if(!pMaterialClone)
					//{
					//	return;
					//}//

					Ogre::Technique* pTechnique = pMaterialClone->getBestTechnique();
					Ogre::Pass* pPass = pTechnique->getPass(0);

					//pPass->setSceneBlending(SBT_ADD);
					//pPass->setSceneBlending(SBF_SOURCE_ALPHA , SBF_ONE_MINUS_SOURCE_ALPHA );
					//pTextureState->setAlphaOperation(LBX_MODULATE, LBS_TEXTURE, LBS_MANUAL, 1, Transparence, 1);//
				
					Ogre::TextureUnitState* pTextureState = pPass->getTextureUnitState(0);
					pTextureState->setColourOperationEx(Ogre::LBX_ADD , Ogre::LBS_TEXTURE , Ogre::LBS_MANUAL, color, color );
					pSubEntiy->setMaterialName(strCloneName);
					m_materialSelVector.push_back(pMaterialClone);
					m_materilaOldVector.push_back(pMaterial);
					
				}

			}
		}
	}
	else
	{
		int iIndex = 0;

		int iCount = m_EntityList.size();
		Ogre::Entity* pEntity = NULL;

		for(int i = 0; i < iCount; i++)
		{
			pEntity = m_EntityList[i].pEntity;
			if(pEntity)
			{
				Ogre::SubEntity* pSubEntiy = pEntity->getSubEntity(0);
				
				if(pSubEntiy)
				{
					if(iIndex >= (int)m_materialSelVector.size())
					{
						continue;
					}

					std::string strMaterialName = m_materialSelVector[iIndex]->getName();
					pSubEntiy->setMaterialName(strMaterialName);	
					iIndex++;
				}

			}
		}
	}
}
Exemplo n.º 6
0
bool LevelGeometryLoader::processEntityStaticGeoemtry(TiXmlElement *XMLNode,
		Ogre::StaticGeometry *sgeo)
{
	ASSERT(XMLNode);
	ASSERT(sgeo);

	// Process attributes
	Ogre::String meshFile = Ogre::DotSceneLoader::getAttrib(XMLNode, "meshFile");
	Ogre::Vector3 position = Ogre::Vector3::ZERO;
	Ogre::Quaternion rotation = Ogre::Quaternion::IDENTITY;
	Ogre::Vector3 scale = Ogre::Vector3::UNIT_SCALE;
	std::vector<Ogre::String> subEntities;


	// parse the entity

	// get the origin
	TiXmlElement *auxPElem = XMLNode->FirstChildElement("position");
	if(auxPElem) {
		position = Ogre::DotSceneLoader::parseVector3(auxPElem);
	}

	// get the rotation
	auxPElem = XMLNode->FirstChildElement("rotation");
	if(auxPElem) {
		rotation = Ogre::DotSceneLoader::parseQuaternion(auxPElem);
	}

	// get the scale
	auxPElem = XMLNode->FirstChildElement("scale");
	if(auxPElem) {
		scale = Ogre::DotSceneLoader::parseVector3(auxPElem);
	}

	size_t count = 0;
	// load the subentities
	TiXmlElement *pElement = XMLNode->FirstChildElement("subentities");
	if(pElement){
		auxPElem = pElement->FirstChildElement("subentity");
		// ugly! very
		while(auxPElem) {
			auxPElem = auxPElem->NextSiblingElement("subentity");
			count++;
		}
		subEntities.resize(count);
		pElement = pElement->FirstChildElement("subentity");
		while(pElement){
			int index = Ogre::DotSceneLoader::getAttribInt(pElement, "index");

			subEntities[index] = Ogre::DotSceneLoader::getAttrib(pElement, "materialName");

			pElement = pElement->NextSiblingElement("subentity");
		}
	}

	// creates the entity
	Ogre::Entity *ent = 0;
	try {
		ent = Common::GlobalObjects::sceneManager->createEntity("entity_" + meshFile, meshFile);
	} catch (...) {
		return false;
	}

	// set the subentities config
	size_t subentityCount = std::min(subEntities.size(), (size_t)ent->getNumSubEntities());
	for (size_t subentityIndex = 0; subentityIndex < subentityCount; subentityIndex++)
	{
		Ogre::SubEntity* subentity = ent->getSubEntity((unsigned int)subentityIndex);
		subentity->setMaterialName(subEntities[subentityIndex]);
	}

	// add the entitie to the static geometry
	sgeo->addEntity(ent, position, rotation, scale);
	Common::GlobalObjects::sceneManager->destroyEntity(ent);


	return true;
}
Exemplo n.º 7
0
VBOOL VLogicModel::_setEntityMaterial(const VString &entityName, const VString &matName)
{
    if (matName.empty())
    {
        return VTRUE;
    }
    else
    {
        VEntityMap::iterator itr = mEntities.find(entityName);

        if (itr == mEntities.end())
        {
            Ogre::LogManager::getSingleton().logMessage( "Logic Model Entity with name '" + entityName + "' dosen't exists! " +
                    "LogicModel::_setEntityMaterial " + mName );
            return VFALSE;
        }

        VEntityValue &entValue = itr->second;
        Ogre::Entity *entity = entValue.mEntity;
        assert(entity);

        if (matName.find(";") != VString::npos)
        {
            Ogre::StringVector matNames = Ogre::StringUtil::split(matName, ";");
            assert(matName.size() > 1);

            for (VUINT32 i = 0; i < entity->getNumSubEntities(); ++i)
            {
                Ogre::SubEntity *subEntity = entity->getSubEntity(i);
                assert(subEntity);

                VString subMatName;

                if (i < matNames.size())
                {
                    subMatName = matNames[i];
                }
                else
                {
                    subMatName = matNames[0];
                }

                const Ogre::MaterialPtr subMat = Ogre::MaterialManager::getSingleton().getByName(subMatName);
                if (!subMat.isNull())
                {
                    subEntity->setMaterialName(subMatName);
                }
            }
        }
        else
        {
            const Ogre::MaterialPtr entityMat = Ogre::MaterialManager::getSingleton().getByName(matName);
            if (!entityMat.isNull())
            {
                entity->setMaterialName(matName);
            }
        }
    }

    return VTRUE;
}