Ogre::SceneNode* ParticleFactory::CreateParticleEntity(Ogre::String object_name, Ogre::String material_name,Ogre::SceneNode* parent, Ogre::Vector3 size){ /* Create one instance of the torus (one entity) */ /* The same object can have multiple instances or entities */ /* Create entity */ Ogre::String name = parent->getName() + object_name; //Ogre::Entity* entity = scene_manager->createEntity(object_name); Ogre::Entity* entity = scene_manager->createEntity(object_name); Ogre::MaterialPtr mat = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(material_name)); //mat = mat->clone(object_name.append("_" +material_name.append("_" + Ogre::StringConverter::toString(materialCounter)))); mat = mat->clone(name.append("_" +material_name.append("_" + Ogre::StringConverter::toString(materialCounter)))); //std::cout << "NAME: " << name << std::endl; //mat = mat->clone(object_name.append(material_name)); /* Apply a material to the entity */ entity->setMaterialName(mat->getName()); //materialArray[numMaterials] = mat->getName(); materialArray.push_back(mat->getName()); /* Create a scene node for the entity */ /* The scene node keeps track of the entity's position */ Ogre::SceneNode* scene_node = parent->createChildSceneNode(mat->getName()); scene_node->attachObject(entity); //scene_node->translate(0.5,0.5,-1); incrementCounter(); /* Scale the entity */ scene_node->scale(size); return scene_node; }
AxisRenderable::AxisRenderable(int lineCount,Ogre::Camera* camera,Ogre::Viewport* viewport) { // Disable cast shadows by default mCastShadows = false; mPrevAxisGizmoSelAxis = -1; mCamera = camera; mViewport = viewport; m_max_line_count = m_line_count = lineCount; m_line_count = 0; mLength = 200; mProjectDistance = mCamera->getFarClipDistance(); m_local = false; m_locked_data = 0; //m_locked_buffer = 0; mRenderOp.vertexData = new Ogre::VertexData(); m_radius = 0; mRenderOp.indexData = 0; mRenderOp.vertexData->vertexCount = m_line_count*2; mRenderOp.vertexData->vertexStart = 0; mRenderOp.operationType = Ogre::RenderOperation::OT_LINE_LIST; mRenderOp.useIndexes = false; Ogre::VertexDeclaration* decl = mRenderOp.vertexData->vertexDeclaration; Ogre::VertexBufferBinding* bind = mRenderOp.vertexData->vertexBufferBinding; decl->addElement(0, 0, Ogre::VET_FLOAT3, Ogre::VES_POSITION); decl->addElement(0, 3*sizeof(Ogre::Real), Ogre::VET_COLOUR, Ogre::VES_DIFFUSE); Ogre::HardwareVertexBufferSharedPtr vbuf = Ogre::HardwareBufferManager::getSingleton().createVertexBuffer( decl->getVertexSize(0), 2*m_max_line_count, Ogre::HardwareBuffer::HBU_WRITE_ONLY); bind->setBinding(0, vbuf); // Obtain the pure colour material Ogre::MaterialPtr pureColourMaterial = createPureColourMaterial(Ogre::ColourValue(1,1,0)); Ogre::String realName = pureColourMaterial->getName() + "_NoDepthBuffer"; Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName(realName); if (material.isNull()) { // Clone to avoid confuse somewhere else that using the same material material = pureColourMaterial->clone(realName); material->setDepthCheckEnabled(false); material->setDepthWriteEnabled(false); } setMaterial(material->getName()); mBox.setExtents(-10,-10,-10,10,10,10); setQueryFlags(0); }
void SoundEditAction::_createIndicatorInstance(void) { Ogre::SceneManager* sceneManager = mSceneManipulator->getSceneManager(); mSoundMovingEntity = sceneManager->createEntity("SoundMovingEntity", "axes.mesh"); mSoundNode = mSceneManipulator->getIndicatorRootSceneNode()->createChildSceneNode(); mSoundNode->setVisible(false); mSoundNode->createChildSceneNode()->attachObject(mSoundMovingEntity); mSoundMovingEntity->getParentSceneNode()->setScale(10,10,10); Real radius = 1; int rings = 16; int segments = 64; Ogre::MeshPtr sphereMesh = WX::createCommonSphere("SoundRadiusEntity", radius, rings, segments); Ogre::MaterialPtr material = WX::createPureColourMaterial( Ogre::ColourValue(1, 0, 0, 0.75) ); material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME); mSoundRadiusEntity = sceneManager->createEntity("SoundRadiusEntity", sphereMesh->getName()); mSoundNode->createChildSceneNode()->attachObject(mSoundRadiusEntity); mSoundRadiusEntity->setMaterialName(material->getName()); mSoundRadiusEntity->getParentSceneNode()->setVisible(false); mFirstInit = true; }
void JunctionPoints::refresh(void) { JunctionSelection* selection = static_cast<JunctionSelection*>( getSceneManipulator()->_getSelection("JunctionSelection")); const JunctionSelection::JunctionMap& junctions = selection->getJunctions(); DisplayNodes newDisplayNodes; // Use existing point if possible for (JunctionSelection::JunctionMap::const_iterator it = junctions.begin(); it != junctions.end(); ++it) { const JunctionSelection::Junction& junction = it->second; Ogre::Vector3 pos = getTerrainData()->_getPosition(junction.x, junction.z); DisplayNodes::iterator found = mDisplayNodes.find(Ogre::Vector4(pos.x, pos.y, pos.z, junction.weight)); Ogre::SceneNode* node = NULL; if (found != mDisplayNodes.end()) { node = found->second; mDisplayNodes.erase(found); } newDisplayNodes.insert(DisplayNodes::value_type(Ogre::Vector4(pos.x, pos.y, pos.z, junction.weight), node)); } // Build new point and adjust position for (DisplayNodes::iterator it = newDisplayNodes.begin(); it != newDisplayNodes.end(); ++it) { if (!it->second) { if (!mDisplayNodes.empty()) { DisplayNodes::iterator found = mDisplayNodes.begin(); it->second = found->second; mDisplayNodes.erase(found); } else { it->second = allocNode(); } it->second->setPosition(it->first.x,it->first.y,it->first.z); // 根据节点的权重来设置节点所挂物体的材质颜色 Ogre::MaterialPtr material = createPureColourMaterial(Ogre::ColourValue(it->first.w,(1.0f-it->first.w),0.0f)); // 设置节点的材质 static_cast<Ogre::Entity *>(it->second->getAttachedObject(0))->setMaterialName(material->getName()); } } // Hide extra points for (DisplayNodes::const_iterator it = mDisplayNodes.begin(); it != mDisplayNodes.end(); ++it) { freeNode(it->second); } std::swap(newDisplayNodes, mDisplayNodes); }
void MeshResourceMarker::reset() { //destroy entity if (entity_) { context_->getSceneManager()->destroyEntity( entity_ ); entity_ = 0; } // destroy all the materials we've created S_MaterialPtr::iterator it; for ( it = materials_.begin(); it!=materials_.end(); it++ ) { Ogre::MaterialPtr material = *it; if (!material.isNull()) { for (size_t i = 0; i < material->getNumTechniques(); ++i) { Ogre::Technique* t = material->getTechnique(i); // hack hack hack, really need to do a shader-based way of picking, rather than // creating a texture for each object if (t->getSchemeName() == "Pick") { Ogre::TextureManager::getSingleton().remove(t->getPass(0)->getTextureUnitState(0)->getTextureName()); } } material->unload(); Ogre::MaterialManager::getSingleton().remove(material->getName()); } } materials_.clear(); }
Ogre::TexturePtr Simple::updateShadowTexture(Ogre::MaterialPtr material, const TerrainPageShadow* terrainPageShadow) { //we need an unique name for our alpha texture std::stringstream shadowTextureNameSS; shadowTextureNameSS << material->getName() << "_shadow"; const Ogre::String shadowTextureName(shadowTextureNameSS.str()); Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr> (Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(shadowTextureName)); if (texture.isNull()) { texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(shadowTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getAlphaTextureSize(), mPage.getAlphaTextureSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY); } Ogre::Image ogreImage; terrainPageShadow->loadIntoImage(ogreImage); texture->loadImage(ogreImage); //blit the whole image to the hardware buffer Ogre::PixelBox sourceBox(ogreImage.getPixelBox()); //blit for each mipmap for (unsigned int i = 0; i <= texture->getNumMipmaps(); ++i) { Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(texture->getBuffer(0, i)); hardwareBuffer->blitFromMemory(sourceBox); } return texture; }
bool Simple::compileMaterial(Ogre::MaterialPtr material) { material->removeAllTechniques(); Ogre::Technique* technique = material->createTechnique(); for (SurfaceLayerStore::const_iterator I = mTerrainPageSurfaces.begin(); I != mTerrainPageSurfaces.end(); ++I) { const TerrainPageSurfaceLayer* surfaceLayer = I->second; if (I == mTerrainPageSurfaces.begin()) { Ogre::Pass* pass = technique->createPass(); pass->setLightingEnabled(false); //add the first layer of the terrain, no alpha or anything Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState(); textureUnitState->setTextureScale(1.0f / surfaceLayer->getScale(), 1.0f / surfaceLayer->getScale()); textureUnitState->setTextureName(surfaceLayer->getDiffuseTextureName()); textureUnitState->setTextureCoordSet(0); } else { if (surfaceLayer->intersects(*mGeometry)) { addPassToTechnique(*mGeometry, technique, surfaceLayer); } } } if (mTerrainPageShadow) { addShadow(technique, mTerrainPageShadow, material); } material->load(); if (material->getNumSupportedTechniques() == 0) { S_LOG_WARNING("The material '" << material->getName() << "' has no supported techniques. The reason for this is: \n" << material->getUnsupportedTechniquesExplanation()); return false; } return true; }
void MeshResourceMarker::reset() { //destroy entity if (entity_) { context_->getSceneManager()->destroyEntity(entity_); entity_ = 0; } // destroy all the materials we've created S_MaterialPtr::iterator it; for (it = materials_.begin(); it != materials_.end(); it++) { Ogre::MaterialPtr material = *it; if (!material.isNull()) { material->unload(); Ogre::MaterialManager::getSingleton().remove(material->getName()); } } materials_.clear(); // the actual passes are deleted by the material color_tint_passes_.clear(); }
IntersectPoint::IntersectPoint(SceneManipulator* sceneManipulator) : HitIndicator(sceneManipulator) , mIntersectNode(NULL) , mIntersectEntity(NULL) { // Create intersection node and entity mIntersectNode = getIndicatorRootSceneNode()->createChildSceneNode(); Real radius = 1; int rings = 16; int segments = 16; Ogre::MeshPtr sphereMesh = createCommonSphere(radius, rings, segments); Ogre::MaterialPtr material = createColourMaterial( Ogre::ColourValue(1, 0, 0, 0.75), Ogre::ColourValue(0, 1, 0), 1); mIntersectEntity = getSceneManager()->createEntity(mIntersectNode->getName(), sphereMesh->getName()); mIntersectEntity->setQueryFlags(0); mIntersectEntity->setNormaliseNormals(true); mIntersectEntity->setMaterialName(material->getName()); mIntersectEntity->setRenderQueueGroup(Ogre::RENDER_QUEUE_7); mIntersectNode->attachObject(mIntersectEntity); mIntersectNode->setVisible(false); reshape(); }
bool Simple::compileMaterial(Ogre::MaterialPtr material, std::set<std::string>& managedTextures) const { material->removeAllTechniques(); Ogre::Technique* technique = material->createTechnique(); if (!mTerrainPageSurfaces.empty()) { //First add a base pass auto surfaceLayer = mTerrainPageSurfaces.begin()->second; Ogre::Pass* pass = technique->createPass(); pass->setLightingEnabled(false); Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState(); textureUnitState->setTextureScale(1.0f / surfaceLayer->getScale(), 1.0f / surfaceLayer->getScale()); textureUnitState->setTextureName(surfaceLayer->getDiffuseTextureName()); textureUnitState->setTextureCoordSet(0); for (auto& layer : mLayers) { addPassToTechnique(*mGeometry, technique, layer, managedTextures); } } if (mTerrainPageShadow) { addShadow(technique, mTerrainPageShadow, material, managedTextures); } // addLightingPass(technique, managedTextures); material->load(); if (material->getNumSupportedTechniques() == 0) { S_LOG_WARNING("The material '" << material->getName() << "' has no supported techniques. The reason for this is: \n" << material->getUnsupportedTechniquesExplanation()); return false; } return true; }
Foundation::ResourcePtr CreateResourceFromMaterial(Ogre::MaterialPtr material) { assert(!material.isNull()); OgreMaterialResource* res = new OgreMaterialResource(material->getName()); res->SetMaterial(material); Foundation::ResourcePtr res_ptr(res); return res_ptr; }
// 设置碰撞小球原来的材质. void IntersectPoint::SetMaterial() { Ogre::MaterialPtr material = createColourMaterial( Ogre::ColourValue(1, 0, 0, 0.75), Ogre::ColourValue(0, 1, 0), 1); mIntersectEntity->setMaterialName(material->getName()); }
void RenderedCompassImpl::_setCompass(Compass* compass) { Ogre::MaterialPtr originalMaterial = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().getByName(mMaterialName)); if (originalMaterial) { originalMaterial->load(); mCompassMaterial = originalMaterial->clone(OgreInfo::createUniqueResourceName(originalMaterial->getName())); if (Ogre::Technique* tech = mCompassMaterial->getBestTechnique()) { Ogre::Pass* pass = nullptr; if (tech->getNumPasses() && (pass = tech->getPass(0))) { mCompassMaterialMapTUS = pass->getTextureUnitState("Background"); if (mCompassMaterialMapTUS) { //Make sure that the compass material is using the map texture for the base rendering mCompassMaterialMapTUS->setTexture(mMap->getTexture()); mTexture = Ogre::TextureManager::getSingleton().createManual("RenderedCompass", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, Ogre::TEX_TYPE_2D, 128, 128, 1, Ogre::PF_A8R8G8B8, Ogre::TU_RENDERTARGET); mRenderTexture = mTexture->getBuffer()->getRenderTarget(); mRenderTexture->removeAllViewports(); mRenderTexture->setAutoUpdated(false); mRenderTexture->setActive(true); mCamera = mSceneManager->createCamera("RenderedCompassCamera"); mViewport = mRenderTexture->addViewport(mCamera); mViewport->setOverlaysEnabled(false); mViewport->setShadowsEnabled(false); mViewport->setSkiesEnabled(false); mViewport->setClearEveryFrame(true); mViewport->setBackgroundColour(Ogre::ColourValue::ZERO); mMapRectangle = OGRE_NEW Ogre::Rectangle2D(true); auto mapMaterialPtr = Ogre::MaterialManager::getSingleton().getByName(mCompassMaterial->getName(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); if (mapMaterialPtr) { mMapRectangle->setMaterial(mapMaterialPtr); } //We need to maximise the rendered texture to cover the whole screen Ogre::RenderSystem* rs = Ogre::Root::getSingleton().getRenderSystem(); Ogre::Real hOffset = rs->getHorizontalTexelOffset() / (0.5 * mViewport->getActualWidth()); Ogre::Real vOffset = rs->getVerticalTexelOffset() / (0.5 * mViewport->getActualHeight()); mMapRectangle->setCorners(-1 + hOffset, 1 - vOffset, 1 + hOffset, -1 - vOffset); //Since a Rectangle2D instance is a moveable object it won't be rendered unless it's in the frustrum. If we set the axis aligned box to be "infinite" it will always be rendered. Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); mMapRectangle->setBoundingBox(aabInf); //We can't attach something to the root node, so we'll attach it to a newly created node. We won't keep a reference to this node since it will be destroyed along with the scene manager when we ourselves are destroyed. mSceneManager->getRootSceneNode()->createChildSceneNode()->attachObject(mMapRectangle); //Return early since everything is good. return; } } } } S_LOG_WARNING("Could not load material '" << mMaterialName << "' for the compass."); }
bool ShaderManager::checkMaterial(const std::string& materialName, const std::string& schemeName) { // OGRE scheme is switched in caller Ogre::MaterialPtr material = static_cast<Ogre::MaterialPtr>(Ogre::MaterialManager::getSingleton().load(materialName, "General")); if (material->getNumSupportedTechniques() == 0) { S_LOG_INFO("The material '" << material->getName() << "' has no supported techniques with scheme " << schemeName << ". The reason for this is: \n" << material->getUnsupportedTechniquesExplanation()); return false; } S_LOG_INFO("The material '" << material->getName() << "' has " << material->getNumSupportedTechniques() << " supported techniques out of " << material->getNumTechniques()); // Check that we use desired scheme, but not fallbacked to default if (material->getBestTechnique()->getSchemeName() != schemeName) { S_LOG_INFO("The material '" << material->getName() << "' has best supported scheme " << material->getBestTechnique()->getSchemeName() << ". Was looking for " << schemeName); return false; } S_LOG_INFO("The material '" << material->getName() << "' supported with scheme " << schemeName); return true; }
//---------------------------------------------------------------------------------------- QImage ImageConverter::fromOgreMaterialName(const Ogre::String& name, const Ogre::String& resourceGroup) { mResourceGroup = resourceGroup; #if (OGRE_VERSION < ((1 << 16) | (9 << 8) | 0)) Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->load(name, mResourceGroup); #else Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->load(name, mResourceGroup).staticCast<Ogre::Material>(); #endif return _getRenderTarget(material->getName()); }
Ogre::MaterialPtr EmberTerrainProfile::getOrCreateMaterialClone(Ogre::MaterialPtr templateMaterial, const std::string& suffix) { std::string name = templateMaterial->getName() + suffix; Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().getByName(name); if (!mat.isNull()) { return mat; } return templateMaterial->clone(name); }
//------------------------------------------------------ void MaterialService::addWorldMaterialTemplate(unsigned int idx, const Ogre::MaterialPtr& material) { assert(!material.isNull()); mTemplateMaterials.insert(make_pair(idx, material)); TextureDimensions2D dimensions; dimensions.first = 64; dimensions.second = 64; if (material->getNumTechniques() > 0) { Pass *shadPass = material->getTechnique(0)->getPass(0); if (shadPass->getNumTextureUnitStates() > 0) { TextureUnitState* tus = shadPass->getTextureUnitState(0); try { // ensure the material is loaded before getting the dimensions material->escalateLoading(); // This is stupid, but can happen - the getTextureDimensions seems buggy in this regard if (tus->getNumFrames() <= 0) { LOG_ERROR("MaterialService: Error getting texture dimensions (Mat. %s) : Zero frame count!", material->getName().c_str()); } else { dimensions = tus->getTextureDimensions(); // register the scale std::pair<float, float> tscale; tscale.first = tus->getTextureUScale(); tscale.second = tus->getTextureVScale(); // register the texture scale... setWRTextureScale(idx, tscale); // reset the scale back, it is canceled out by the fact we UV map with different txt dimensions tus->setTextureUScale(1.0f); tus->setTextureVScale(1.0f); dimensions.first = static_cast<unsigned int> (tscale.first * dimensions.first); dimensions.second = static_cast<unsigned int> (tscale.second * dimensions.second); } } catch (Ogre::Exception &e) { // Nothing, just log it could not be done LOG_ERROR("MaterialService: Error getting texture dimensions : %s", e.getFullDescription().c_str()); } } } LOG_INFO("MaterialService: Registered a WR template material %u - %s", idx, material->getName().c_str()); // insert mTextureDimensionMap.insert(make_pair(idx, dimensions)); }
//--------------------------------------------------------------------- std::list<Ogre::MaterialPtr> MapBlock::cloneMaterials(void) { std::list<Ogre::MaterialPtr> clones; for(unsigned int i=0; i < mEntity->getNumSubEntities(); i++) { Ogre::MaterialPtr realMaterial = mEntity->getSubEntity(i)->getMaterial(); std::stringstream nameStream; nameStream << realMaterial->getName() << " " << mStaticPosition[0] << ":" << mStaticPosition[1]; Ogre::MaterialPtr newMaterial = realMaterial->clone(nameStream.str()); newMaterial->load(); mEntity->getSubEntity(i)->setMaterial(newMaterial); clones.push_back(newMaterial); } return clones; }
//----------------------------------------------------------------------- void Technique::setShadowReceiverMaterial(Ogre::MaterialPtr val) { if (val.isNull()) { mShadowReceiverMaterial.setNull(); mShadowReceiverMaterialName.clear(); } else { mShadowReceiverMaterial = val; mShadowReceiverMaterialName = val->getName(); } }
//---------------------------------------------------------------------------------------- QImage ImageConverter::_imageFromRenderTarget(const Ogre::Image& img) { Ogre::TextureManager::getSingletonPtr()->loadImage("QTTextureName", "QTImageConverter", img); // create our material Ogre::MaterialPtr material = Ogre::MaterialManager::getSingletonPtr()->create("terrainMaterial", "QTImageConverter"); Ogre::Technique * technique = material->getTechnique(0); Ogre::Pass* pass = technique->getPass(0); Ogre::TextureUnitState* textureUnit = pass->createTextureUnitState(); textureUnit->setTextureName("QTTextureName"); return _getRenderTarget(material->getName()); }
//------------------------------------------------------------------------------- Ogre::MaterialPtr CSceneManagerEditor::buildDepthShadowMaterial(Ogre::MaterialPtr cpyMat) { if(mShadowsTechnique->get() >= (int)Ogre::SHADOWTYPE_TEXTURE_ADDITIVE && mShadowsTechnique->get() <= (int)Ogre::SHADOWTYPE_TEXTURE_MODULATIVE_INTEGRATED) { Ogre::String matName = "DepthShadows/" + cpyMat->getName(); Ogre::MaterialPtr ret = Ogre::MaterialManager::getSingleton().getByName(matName); if (ret.isNull()) { ret = cpyMat->clone(matName); Ogre::Technique *t = ret->getTechnique(0); t->setShadowCasterMaterial("Ogre/shadow/depth/caster"); Ogre::Pass *p = t->getPass(0); p->setVertexProgram("Ogre/shadow/receiver/depth/pssm3/vp"); p->setFragmentProgram("Ogre/shadow/receiver/depth/pssm3/fp"); Ogre::TextureUnitState *tu = p->createTextureUnitState(); tu->setName("shadow0"); tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1)); tu = p->createTextureUnitState(); tu->setName("shadow1"); tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1)); tu = p->createTextureUnitState(); tu->setName("shadow2"); tu->setContentType(Ogre::TextureUnitState::CONTENT_SHADOW); tu->setTextureAddressingMode(Ogre::TextureUnitState::TAM_BORDER); tu->setTextureBorderColour(Ogre::ColourValue(1,1,1,1)); Ogre::Vector4 splitPoints; const Ogre::PSSMShadowCameraSetup::SplitPointList& splitPointList = static_cast<Ogre::PSSMShadowCameraSetup*>(mPSSMSetup.get())->getSplitPoints(); for (int i = 0; i < 3; ++i) { splitPoints[i] = splitPointList[i]; } p->getFragmentProgramParameters()->setNamedConstant("pssmSplitPoints", splitPoints); } return ret; } else return cpyMat; }
void OgreOrb::setColour(Ogre::ColourValue colour){ std::string matName = OgreOrb_MATERIAL_NAME; if(Ogre::MaterialManager::getSingleton().resourceExists(matName)){ Ogre::MaterialPtr mat = entity->getSubEntity(0)->getMaterial(); mat->getTechnique(0)->getPass(0)->setAmbient(colour); mat->getTechnique(0)->getPass(0)->setDiffuse(colour); } else{ Ogre::MaterialPtr mat = entity->getSubEntity(0)->getMaterial()->clone(matName); mat->getTechnique(0)->getPass(0)->setAmbient(colour); mat->getTechnique(0)->getPass(0)->setDiffuse(colour); entity->setMaterialName(mat->getName()); } }
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!"); } }
void RemoveMaterial(Ogre::MaterialPtr& material) { if (!material.isNull()) { std::string material_name = material->getName(); material.setNull(); try { Ogre::MaterialManager::getSingleton().remove(material_name); } catch (Ogre::Exception& e) { OgreRenderingModule::LogDebug("Failed to remove Ogre material:" + std::string(e.what())); } } }
MeshPersonVisual::~MeshPersonVisual() { m_sceneManager->destroyEntity( entity_ ); // destroy all the materials we've created std::set<Ogre::MaterialPtr>::iterator it; for ( it = materials_.begin(); it!=materials_.end(); it++ ) { Ogre::MaterialPtr material = *it; if (!material.isNull()) { material->unload(); Ogre::MaterialManager::getSingleton().remove(material->getName()); } } materials_.clear(); m_sceneManager->destroySceneNode(m_childSceneNode->getName()); }
void BasisManager::createInput() // создаем систему ввода { Ogre::LogManager::getSingletonPtr()->logMessage("*** Initializing OIS ***"); OIS::ParamList pl; size_t windowHnd = 0; std::ostringstream windowHndStr; mWindow->getCustomAttribute("WINDOW", &windowHnd); windowHndStr << windowHnd; pl.insert(std::make_pair(std::string("WINDOW"), windowHndStr.str())); mInputManager = OIS::InputManager::createInputSystem( pl ); mKeyboard = static_cast<OIS::Keyboard*>(mInputManager->createInputObject( OIS::OISKeyboard, true )); mKeyboard->setEventCallback(this); mMouse = static_cast<OIS::Mouse*>(mInputManager->createInputObject( OIS::OISMouse, true )); mMouse->setEventCallback(this); mRoot->addFrameListener(this); windowResized(mWindow); // инициализация Ogre::WindowEventUtilities::addWindowEventListener(mWindow, this); Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().getByName("wallpaper"); if (false == material.isNull()) { Ogre::OverlayManager & manager = Ogre::OverlayManager::getSingleton(); Ogre::Overlay * overlay = manager.create("wallpaper"); overlay->setZOrder(0); overlay->show(); Ogre::PanelOverlayElement * panel = static_cast<Ogre::PanelOverlayElement*>(manager.createOverlayElement("Panel", "wallpaper")); panel->setDimensions(1, 1); /*Ogre::FontPtr mpFont = Ogre::FontManager::getSingleton().getByName("MyGUI_font"); mpFont->load(); if (!mpFont.isNull()) { const Ogre::MaterialPtr & material2 = mpFont->getMaterial(); panel->setMaterialName(material2->getName()); }*/ panel->setMaterialName(material->getName()); overlay->add2D(panel); } }
void BallApp::createBall(std::string entName, std::string nodeName, int x, int y, int z, int vx, int vy, int vz) { Ogre::Entity *entity = mSceneMgr->createEntity(entName, "sphere.mesh"); entity->setCastShadows(true); Ogre::SceneNode *newNode = mSceneMgr->getRootSceneNode()->createChildSceneNode(nodeName); newNode->attachObject(entity); mPhysics->addRigidSphere(entity, newNode, 0.1f, 1.0f, btVector3(0,0,0), btVector3(x,y,z), new btQuaternion(1.0f, 1.0f, 0, 0))->setLinearVelocity(btVector3(vx, vy, vz)); // Change Entity Color Ogre::MaterialPtr mat = entity->getSubEntity(0)->getMaterial(); Ogre::Pass *pass = mat->getTechnique(0)->getPass(0); pass->setDiffuse(0,1,0,0.1); pass->setSpecular(1,1,1,0.4); entity->setMaterialName(mat->getName()); }
Indicator(const ObjectPtr &object, SceneManipulator *sceneManipulator) : mProxy(NULL) { assert(sceneManipulator); mUserAny = Ogre::Any(); mProxy = new ObjectProxy(object); // 根据光源位置来定节点位置 Ogre::Vector3 pos = VariantCast<Ogre::Vector3>(object->getProperty("position")); mIndicatorSceneNode = sceneManipulator->getIndicatorRootSceneNode()->createChildSceneNode(pos); Real radius = 5; int rings = 16; int segments = 16; Ogre::MeshPtr sphereMesh = createCommonSphere(radius, rings, segments); Ogre::MaterialPtr material = createPureColourMaterial( Ogre::ColourValue(1, 0, 0, 0.75) ); mIndicatorEntity = sceneManipulator->getSceneManager()->createEntity(mIndicatorSceneNode->getName(), sphereMesh->getName()); //david-<< //mIndicatorEntity->setNormaliseNormals(true); //david->> mIndicatorEntity->setMaterialName(material->getName()); setUserObject(mProxy); mIndicatorSceneNode->attachObject(mIndicatorEntity); // 选择时不考虑粒子系统的包围盒,用的是指示器的包围盒 ParticleSystemObject *particleSystemObject = static_cast<ParticleSystemObject *> (object.get()); Ogre::ParticleSystem *system = particleSystemObject->getParticleSystem(); if (system) system->setQueryFlags(0); // 根据光源类型来挂接模型 showIndicator(false); }
CreateObjectAction::CreateObjectAction(SceneManipulator* sceneManipulator) : Action(sceneManipulator) , mDirty(true) , mObject() , mHasPosition(false) , mRangeSphereEntity(NULL) , mRangeSphereNode(NULL) { // create a entity for indicate the range of a point light mRangeSphereNode = getIndicatorRootSceneNode()->createChildSceneNode(); Ogre::MeshPtr sphereMesh = Fairy::createCommonSphere("PointLightRangeSphere", 100, 16, 16); Ogre::MaterialPtr material = Fairy::createPureColourMaterial(Ogre::ColourValue(0, 1, 0, 0.75)); material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME); material->getTechnique(0)->getPass(0)->setCullingMode(Ogre::CULL_NONE); mRangeSphereEntity = getSceneManager()->createEntity("CreateLightRangeSphere", sphereMesh->getName()); mRangeSphereEntity->setMaterialName(material->getName()); mRangeSphereNode->attachObject(mRangeSphereEntity); mRangeSphereNode->setVisible(false); }
void ImageSelectionToolCustom::onInitialize() { move_tool_->initialize( context_ ); // Create our highlight rectangle Ogre::SceneManager* scene_manager = context_->getSceneManager(); highlight_node_ = scene_manager->getRootSceneNode()->createChildSceneNode(); std::stringstream ss; static int count = 0; ss << "ImageSelectionRect" << count++; highlight_rectangle_ = new Ogre::Rectangle2D(true); const static uint32_t texture_data[1] = { 0xffff0070 }; Ogre::DataStreamPtr pixel_stream; pixel_stream.bind(new Ogre::MemoryDataStream( (void*)&texture_data[0], 4 )); Ogre::TexturePtr tex = Ogre::TextureManager::getSingleton().loadRawData(ss.str() + "Texture", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME, pixel_stream, 1, 1, Ogre::PF_R8G8B8A8, Ogre::TEX_TYPE_2D, 0); Ogre::MaterialPtr material = Ogre::MaterialManager::getSingleton().create(ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME); material->setLightingEnabled(false); //material->getTechnique(0)->getPass(0)->setPolygonMode(Ogre::PM_WIREFRAME); highlight_rectangle_->setMaterial(material->getName()); Ogre::AxisAlignedBox aabInf; aabInf.setInfinite(); highlight_rectangle_->setBoundingBox(aabInf); highlight_rectangle_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY + 4); material->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA); material->setCullingMode(Ogre::CULL_NONE); Ogre::TextureUnitState* tex_unit = material->getTechnique(0)->getPass(0)->createTextureUnitState(); tex_unit->setTextureName(tex->getName()); tex_unit->setTextureFiltering( Ogre::TFO_NONE ); highlight_node_->attachObject(highlight_rectangle_); }