示例#1
0
//------------------------------------------------------------------------------
Background2D::Background2D():
    m_AlphaMaxVertexCount( 0 ),
    m_AddMaxVertexCount( 0 ),

    m_ScrollEntity( NULL ),
    m_ScrollPositionStart( Ogre::Vector2::ZERO ),
    m_ScrollPositionEnd( Ogre::Vector2::ZERO ),
    m_ScrollType( Background2D::NONE ),
    m_ScrollSeconds( 0 ),
    m_ScrollCurrentSeconds( 0 ),
    m_Position( Ogre::Vector2::ZERO ),
    m_PositionReal( Ogre::Vector2::ZERO )

   ,m_range( Ogre::AxisAlignedBox::BOX_INFINITE )
    // for ffvii
   ,m_virtual_screen_size( 320, 240 )
{
    m_SceneManager = Ogre::Root::getSingleton().getSceneManager( "Scene" );
    m_RenderSystem = Ogre::Root::getSingletonPtr()->getRenderSystem();

    CreateVertexBuffers();

    m_AlphaMaterial = Ogre::MaterialManager::getSingleton().create( "Background2DAlpha", "General" );
    Ogre::Pass* pass = m_AlphaMaterial->getTechnique( 0 )->getPass( 0 );
    pass->setVertexColourTracking( Ogre::TVC_AMBIENT );
    pass->setCullingMode( Ogre::CULL_NONE );
    pass->setDepthCheckEnabled( true );
    pass->setDepthWriteEnabled( true );
    pass->setLightingEnabled( false );
    pass->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
    pass->setAlphaRejectFunction( Ogre::CMPF_GREATER );
    pass->setAlphaRejectValue( 0 );
    Ogre::TextureUnitState* tex = pass->createTextureUnitState();
    tex->setTextureName( "system/blank.png" );
    tex->setNumMipmaps( -1 );
    tex->setTextureFiltering( Ogre::TFO_NONE );

    m_AddMaterial = Ogre::MaterialManager::getSingleton().create( "Background2DAdd", "General" );
    pass = m_AddMaterial->getTechnique( 0 )->getPass( 0 );
    pass->setVertexColourTracking( Ogre::TVC_AMBIENT );
    pass->setCullingMode( Ogre::CULL_NONE );
    pass->setDepthCheckEnabled( true );
    pass->setDepthWriteEnabled( true );
    pass->setLightingEnabled( false );
    pass->setSceneBlending( Ogre::SBT_ADD );
    pass->setAlphaRejectFunction( Ogre::CMPF_GREATER );
    pass->setAlphaRejectValue( 0 );
    tex = pass->createTextureUnitState();
    tex->setTextureName( "system/blank.png" );
    tex->setNumMipmaps( -1 );
    tex->setTextureFiltering( Ogre::TFO_NONE );

    m_SceneManager->addRenderQueueListener( this );
}
	void TerrainProjectionMarker::AddMaterial(const string& matName)
	{
		// check if material is already added or there's no material
		if( _targetMaterials.find(matName) != _targetMaterials.end() ||
			matName.empty() )
		{
			return;
		}

		string matName2 = "StoreMat";

		// get the material ptr
		Ogre::MaterialPtr mat = (Ogre::MaterialPtr)Ogre::MaterialManager::getSingleton().getByName(matName);

		// create a new pass in the material to render the decal
		Ogre::Pass* pass = mat->getTechnique(0)->createPass();

		// set up the decal's texture unit
		Ogre::TextureUnitState *texState = pass->createTextureUnitState(GetTextureName());
		texState->setProjectiveTexturing(true, _projectionFrustum);
		texState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
		texState->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_LINEAR, Ogre::FO_NONE);
		texState->setAlphaOperation(Ogre::LBX_ADD);

		// set our pass to blend the decal over the model's regular texture
		pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
		pass->setDepthBias(2.5f, 2.5f);
		pass->setDepthCheckEnabled(false);

		// set the decal to be self illuminated instead of lit by scene lighting
		pass->setLightingEnabled(false);

		// save pass in map
		_targetMaterials[matName] = pass;
	}
示例#3
0
void ImageDisplay::onInitialize()
{
  ImageDisplayBase::onInitialize();
  {
    static uint32_t count = 0;
    std::stringstream ss;
    ss << "ImageDisplay" << count++;
    img_scene_manager_ = Ogre::Root::getSingleton().createSceneManager(Ogre::ST_GENERIC, ss.str());
  }

  img_scene_node_ = img_scene_manager_->getRootSceneNode()->createChildSceneNode();

  {
    static int count = 0;
    std::stringstream ss;
    ss << "ImageDisplayObject" << count++;

    screen_rect_ = new Ogre::Rectangle2D(true);
    screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
    screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);

    ss << "Material";
    material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
    material_->setSceneBlending( Ogre::SBT_REPLACE );
    material_->setDepthWriteEnabled(false);
    material_->setReceiveShadows(false);
    material_->setDepthCheckEnabled(false);

    material_->getTechnique(0)->setLightingEnabled(false);
    Ogre::TextureUnitState* tu = material_->getTechnique(0)->getPass(0)->createTextureUnitState();
    tu->setTextureName(texture_.getTexture()->getName());
    tu->setTextureFiltering( Ogre::TFO_NONE );

    material_->setCullingMode(Ogre::CULL_NONE);
    Ogre::AxisAlignedBox aabInf;
    aabInf.setInfinite();
    screen_rect_->setBoundingBox(aabInf);
    screen_rect_->setMaterial(material_->getName());
    img_scene_node_->attachObject(screen_rect_);
  }

  render_panel_ = new RenderPanel();
  render_panel_->getRenderWindow()->setAutoUpdated(false);
  render_panel_->getRenderWindow()->setActive( false );

  render_panel_->resize( 640, 480 );
  render_panel_->initialize(img_scene_manager_, context_);

  setAssociatedWidget( render_panel_ );

  render_panel_->setAutoRender(false);
  render_panel_->setOverlaysEnabled(false);
  render_panel_->getCamera()->setNearClipDistance( 0.01f );

  updateNormalizeOptions();
}
示例#4
0
//-------------------------------------------------------------------------------------
void BasicTutorial2::createScene(void)
{
    mSceneMgr->setAmbientLight(Ogre::ColourValue(0, 0, 0));
    //mSceneMgr->setShadowTechnique(Ogre::SHADOWTYPE_STENCIL_ADDITIVE);
 
	//Create cube
	    //Create a basic green color texture 
 
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();
 
	tex->setTextureName("grassTexture.png");
	//tex->setNumMipmaps(4);
	tex->setTextureAnisotropy(1);
	tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

	    //Create the one box and the supporting class objects
	Ogre::ManualObject* testBox  = createCubeMesh("TestBox1", "BoxColor");	
    Ogre::SceneNode* headNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
	Ogre::MeshPtr Mesh = testBox->convertToMesh("TestBox2");
	Ogre::StaticGeometry* pGeom = new Ogre::StaticGeometry (mSceneMgr, "Boxes");
	Ogre::Entity* pEnt = mSceneMgr->createEntity("TestBox2");
	
	//testBox->triangle
	pGeom->setRegionDimensions(Ogre::Vector3(300, 300, 300));
 
	World::Instance();
	 
	pGeom->build ();
 
        mSceneMgr->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
	Ogre::Light* l = mSceneMgr->createLight("MainLight");
        l->setPosition(20,80,50);
	//Create Cube

 /*   Ogre::Entity* entNinja = mSceneMgr->createEntity("Ninja", "ninja.mesh");
    entNinja->setCastShadows(true);
    mSceneMgr->getRootSceneNode()->createChildSceneNode()->attachObject(entNinja);*/
 
 
    Ogre::Light* directionalLight = mSceneMgr->createLight("directionalLight");
    directionalLight->setType(Ogre::Light::LT_DIRECTIONAL);
    directionalLight->setDiffuseColour(Ogre::ColourValue(.25, .25, 0));
    directionalLight->setSpecularColour(Ogre::ColourValue(.25, .25, 0));
 
    directionalLight->setDirection(Ogre::Vector3( 0, -1, 1 )); 
 
 
}
示例#5
0
void Simple::addShadow(Ogre::Technique* technique, const TerrainPageShadow* terrainPageShadow, Ogre::MaterialPtr material, std::set<std::string>& managedTextures) const
{
	Ogre::Pass* shadowPass = technique->createPass();

	shadowPass->setSceneBlending(Ogre::SBT_MODULATE);
	shadowPass->setLightingEnabled(false);
//	shadowPass->setFog(true, Ogre::FOG_NONE);

	Ogre::TextureUnitState * textureUnitStateSplat = shadowPass->createTextureUnitState();
	Ogre::TexturePtr texture = updateShadowTexture(material, terrainPageShadow, managedTextures);
	textureUnitStateSplat->setTextureName(texture->getName());

	textureUnitStateSplat->setTextureCoordSet(0);
	textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
	textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
}
示例#6
0
void CubeWorld::createTexture (const TCHAR* pName, const TCHAR* pImageFilename)
{
	Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create(pName, "General", true );
	Ogre::Technique* tech = mat->getTechnique(0);
	Ogre::Pass* pass = tech->getPass(0);
	Ogre::TextureUnitState* tex = pass->createTextureUnitState();

	tex->setTextureName(pImageFilename);
	tex->setNumMipmaps(4);
	tex->setTextureAnisotropy(1);
	tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

	pass->setVertexColourTracking(Ogre::TVC_DIFFUSE);
	tex->setColourOperationEx(Ogre::LBX_MODULATE, Ogre::LBS_DIFFUSE, Ogre::LBS_TEXTURE);

	tech->setLightingEnabled(false);
}
	void Decal::registerPass(Ogre::Pass* _Pass)
	{
		unregister();

		_Pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
		_Pass->setCullingMode(Ogre::CULL_NONE);
        _Pass->setDepthBias(1,1);
        _Pass->setLightingEnabled(false);
		_Pass->setDepthWriteEnabled(false);

		Ogre::TextureUnitState *DecalTexture = _Pass->createTextureUnitState(mTextureName);
        DecalTexture->setProjectiveTexturing(true, mProjector);
		DecalTexture->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
		DecalTexture->setTextureFiltering(Ogre::FO_LINEAR, Ogre::FO_LINEAR, Ogre::FO_NONE);
		DecalTexture->setAlphaOperation(Ogre::LBX_MODULATE, Ogre::LBS_TEXTURE, Ogre::LBS_MANUAL, 1.0, mTransparency);

		mRegisteredPass = _Pass;
	}
	//------------------------------------------------------
	void TextureAtlas::prepareResources() {
		mTexture = Ogre::TextureManager::getSingleton().createManual(mAtlasName,
			Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
			Ogre::TEX_TYPE_2D,
			mAtlasSize.width,
			mAtlasSize.height,
			1,
			Ogre::PF_BYTE_BGRA,
			Ogre::TU_STATIC_WRITE_ONLY);

		Ogre::TextureUnitState* tus = mMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(mTexture->getName());

		tus->setTextureFiltering(Ogre::FO_NONE, Ogre::FO_NONE, Ogre::FO_NONE);

		Ogre::Pass *pass = mMaterial->getTechnique(0)->getPass(0);
		pass->setAlphaRejectSettings(Ogre::CMPF_GREATER, 128);
		pass->setLightingEnabled(false);
	}
示例#9
0
void RenderWindow::CreateRenderTargetOverlay(int width, int height)
{
    width = max(1, width);
    height = max(1, height);

    Ogre::TexturePtr renderTarget = Ogre::TextureManager::getSingleton().createManual(
        rttTextureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
        Ogre::TEX_TYPE_2D, width, height, 0, Ogre::PF_A8R8G8B8, Ogre::TU_DYNAMIC_WRITE_ONLY_DISCARDABLE);

    Ogre::MaterialPtr rttMaterial = Ogre::MaterialManager::getSingleton().create(
        rttMaterialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);

    Ogre::TextureUnitState *rttTuState = rttMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();

    rttTuState->setTextureName(rttTextureName);
    rttTuState->setTextureFiltering(Ogre::TFO_NONE);
    rttTuState->setNumMipmaps(1);
    rttTuState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);

    rttMaterial->setFog(true, Ogre::FOG_NONE); ///\todo Check, shouldn't here be false?
    rttMaterial->setReceiveShadows(false);
    rttMaterial->setTransparencyCastsShadows(false);

    rttMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBF_SOURCE_ALPHA, Ogre::SBF_ONE_MINUS_SOURCE_ALPHA);
    rttMaterial->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
    rttMaterial->getTechnique(0)->getPass(0)->setCullingMode(Ogre::CULL_NONE);

    overlayContainer = Ogre::OverlayManager::getSingleton().createOverlayElement("Panel", "MainWindow Overlay Panel");
    overlayContainer->setMaterialName(rttMaterialName);
    overlayContainer->setMetricsMode(Ogre::GMM_PIXELS);
    overlayContainer->setPosition(0, 0);
    overlayContainer->setDimensions((Ogre::Real)width, (Ogre::Real)height);
    overlayContainer->setPosition(0,0);

    overlay = Ogre::OverlayManager::getSingleton().create("MainWindow Overlay");
    overlay->add2D(static_cast<Ogre::OverlayContainer *>(overlayContainer));
    overlay->setZOrder(500);
    overlay->show();

//    ResizeOverlay(width, height);
}
示例#10
0
void Simple::addLightingPass(Ogre::Technique* technique, std::set<std::string>& managedTextures) const
{
	Ogre::Pass* lightingPass = technique->createPass();

	lightingPass->setSceneBlending(Ogre::SBT_MODULATE);
	lightingPass->setLightingEnabled(false);

	Ogre::TextureUnitState * textureUnitStateSplat = lightingPass->createTextureUnitState();

	//we need an unique name for our alpha texture
	std::stringstream lightingTextureNameSS;
	lightingTextureNameSS << technique->getParent()->getName() << "_lighting";
	const Ogre::String lightingTextureName(lightingTextureNameSS.str());

	Ogre::TexturePtr texture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(lightingTextureName));
	if (texture.isNull()) {
		texture = Ogre::Root::getSingletonPtr()->getTextureManager()->createManual(lightingTextureName, "General", Ogre::TEX_TYPE_2D, mPage.getBlendMapSize(), mPage.getBlendMapSize(), 1, Ogre::PF_L8, Ogre::TU_DYNAMIC_WRITE_ONLY);
		managedTextures.insert(texture->getName());
	}

	Ogre::Image ogreImage;
	ogreImage.loadDynamicImage(const_cast<unsigned char*>(mLightingImage->getData()), mLightingImage->getResolution(), mLightingImage->getResolution(), 1, Ogre::PF_L8);

	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);
	}

	textureUnitStateSplat->setTextureName(texture->getName());

	textureUnitStateSplat->setTextureCoordSet(0);
	textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
	textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC);

}
//-----------------------------------------------------------------------
bool RTShaderSRSSegmentedLights::preAddToRenderState(const RenderState* renderState, Pass* srcPass, Pass* dstPass)
{
    if (srcPass->getLightingEnabled() == false)
        return false;

    mUseSegmentedLightTexture = SegmentedDynamicLightManager::getSingleton().isActive();
    setTrackVertexColourType(srcPass->getVertexColourTracking());           

    if (srcPass->getShininess() > 0.0 &&
        srcPass->getSpecular() != ColourValue::Black)
    {
        setSpecularEnable(true);
    }
    else
    {
        setSpecularEnable(false);   
    }

    
    int lightCount[3];
    renderState->getLightCount(lightCount);
    setLightCount(lightCount);

    if (mUseSegmentedLightTexture)
    {
        const_cast<RenderState*>(renderState)->setLightCountAutoUpdate(false);

        Ogre::TextureUnitState* pLightTexture = dstPass->createTextureUnitState();
        pLightTexture->setTextureName(SegmentedDynamicLightManager::getSingleton().getSDLTextureName(), Ogre::TEX_TYPE_2D);
        pLightTexture->setTextureFiltering(Ogre::TFO_NONE);
        mLightSamplerIndex = dstPass->getNumTextureUnitStates() - 1;
    }


    return true;
}
示例#12
0
/****************************************************************************
**
** Copyright (C) 2014
**
** This file is generated by the Magus toolkit
**
** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
**
****************************************************************************/

// Include
#include <QMessageBox>
#include "ogre_asset_material.h"
#include "asset_propertywidget_xyz.h"
#include "asset_propertywidget_string.h"
#include "asset_propertywidget_checkbox.h"
#include "asset_propertywidget_select.h"
#include "asset_propertywidget_slider.h"
#include "asset_propertywidget_decimal.h"
#include "asset_propertywidget_color.h"
#include "asset_propertywidget_texture.h"

namespace Magus
{
    //****************************************************************************/
    QtOgreAssetMaterial::QtOgreAssetMaterial(const QString& iconDir, QWidget* parent) : QWidget(parent)
    {
        mOgreMaterial = 0;
        mIconDir = iconDir;

        // Create QtAssetWidget
        QVBoxLayout* mainLayout = new QVBoxLayout;
        mainLayout->setContentsMargins(0, 0, 0, 0);
        mAssetWidget = new QtAssetWidget(QString("Material"),
                                         iconDir + QString("material.png"),
                                         this);
        mAssetWidget->setFileNameIconCollapsed(iconDir + QString("collapse.png"));
        mAssetWidget->setFileNameIconExpanded(iconDir + QString("expand.png"));
        mAssetWidget->setHeaderTitleBold();
        connect(mAssetWidget, SIGNAL(valueChanged(QtProperty*)), this, SLOT(propertyValueChanged(QtProperty*)));

        // Create container - General
        QtContainerWidget* container = 0;
        container = mAssetWidget->createContainer(CONTAINER_GENERAL, QString("General"));
        container->setTitleIcon(iconDir + QString("cube_bold.png"));
        container->setTitleBold();

        mAssetWidget->createProperty(CONTAINER_GENERAL, MATERIAL_NAME, QString("Name"), QtProperty::STRING, true);
        QStringList stringListSceneBlend;
        stringListSceneBlend << QString("Transparent alpha") <<
                      QString("Transparent color") <<
                      QString("Add") <<
                      QString("Modulate")  <<
                      QString("Replace");
        QtSelectProperty* selectProperty = static_cast<QtSelectProperty*>
                                            (mAssetWidget->createProperty(CONTAINER_GENERAL,
                                            MATERIAL_SCENE_BLENDING,
                                            QString("Scene Blending"),
                                            QtProperty::SELECT));
        selectProperty->addValues(stringListSceneBlend);

         // Layout
        mainLayout->addWidget(mAssetWidget);
        setLayout(mainLayout);
    }

    //****************************************************************************/
    QtOgreAssetMaterial::~QtOgreAssetMaterial(void)
    {
    }

    //****************************************************************************/
    void QtOgreAssetMaterial::expandAll(void)
    {
        if (mAssetWidget)
            mAssetWidget->expandAllContainers();
    }

    //****************************************************************************/
    void QtOgreAssetMaterial::collapseAll(void)
    {
        if (mAssetWidget)
            mAssetWidget->collapseAllContainers();
    }

    //****************************************************************************/
    void QtOgreAssetMaterial::bindObject (Ogre::Material* material)
    {
        mOgreMaterial = material; // Allow null value materials
        if (!material)
            return;

        QtStringProperty* stringProperty;
        QtDecimalProperty* decimalProperty;
        QtCheckBoxProperty* checkboxProperty;
        QtColorProperty* colorProperty;
        QtSliderProperty* sliderProperty;
        QtSelectProperty* selectProperty;
        Ogre::ColourValue color;

        // Material name
        stringProperty = static_cast<QtStringProperty*>(mAssetWidget->getPropertyWidget(MATERIAL_NAME));
        stringProperty->setString(material->getName().c_str());

        // Create containers - Technique
        const char* ch;
        unsigned int numTechniques = material->getNumTechniques();
        QtContainerWidget* techniqueContainer;
        QtContainerWidget* passContainer;
        QtContainerWidget* textureUnitContainer;
        Ogre::Technique* technique;
        Ogre::Pass* pass;
        Ogre::TextureUnitState* textureUnit;
        for (unsigned int t = 0; t < numTechniques; ++t)
        {
            int techniqueContainerId = t + TECHNIQUE_BASE;
            technique = material->getTechnique(t);
            techniqueContainer = mAssetWidget->createContainer(techniqueContainerId, QString("Technique ") + QVariant(t).toString());
            techniqueContainer->setTitleBold();
            techniqueContainer->setTitleIcon(mIconDir + QString("technique_bold.png"));

            // Create containers - Pass
            unsigned int numPasses = technique->getNumPasses();
            for (unsigned int p = 0; p < numPasses; ++p)
            {
                int passContainerId = p + PASS_BASE;
                pass = technique->getPass(p);
                passContainer = techniqueContainer->createContainer(passContainerId, QString("Pass ") + QVariant(p).toString());
                passContainer->setTitleBold();
                passContainer->setTitleIcon(mIconDir + QString("pass_bold.png"));

                // Name fragment program
                stringProperty = static_cast<QtStringProperty*>
                        (passContainer->createProperty(PASS_FRAGMENT_NAME, QString("Name fragment program"), QtProperty::STRING, true));
                ch = pass->getFragmentProgramName().c_str();
                stringProperty->setString(QString(ch));
                stringProperty->mUserData = pass;

                // Name vertex program
                stringProperty = static_cast<QtStringProperty*>
                        (passContainer->createProperty(PASS_VERTEX_NAME, QString("Name vertex program"), QtProperty::STRING, true));
                ch = pass->getVertexProgramName().c_str();
                stringProperty->setString(QString(ch));
                stringProperty->mUserData = pass;

                // Name geometry program
                stringProperty = static_cast<QtStringProperty*>
                        (passContainer->createProperty(PASS_GEOMETRY_NAME, QString("Name geometry program"), QtProperty::STRING, true));
                ch = pass->getVertexProgramName().c_str();
                stringProperty->setString(QString(ch));
                stringProperty->mUserData = pass;

                // Depth check enabled
                checkboxProperty = static_cast<QtCheckBoxProperty*>
                        (passContainer->createProperty(PASS_DEPTH_CHECK, QString("Depth check"), QtProperty::CHECKBOX));
                checkboxProperty->setValue(pass->getDepthCheckEnabled());
                checkboxProperty->mUserData = pass;

                // Depth write enabled
                checkboxProperty = static_cast<QtCheckBoxProperty*>
                        (passContainer->createProperty(PASS_DEPTH_WRITE, QString("Depth write"), QtProperty::CHECKBOX));
                checkboxProperty->setValue(pass->getDepthWriteEnabled());
                checkboxProperty->mUserData = pass;

                // Lighting enabled
                checkboxProperty = static_cast<QtCheckBoxProperty*>
                        (passContainer->createProperty(PASS_LIGHTING, QString("Lighting"), QtProperty::CHECKBOX));
                checkboxProperty->setValue(pass->getLightingEnabled());
                checkboxProperty->mUserData = pass;

                // Ambient
                colorProperty = static_cast<QtColorProperty*>
                        (passContainer->createProperty(PASS_AMBIENT, QString("Ambient"), QtProperty::COLOR));
                color = pass->getAmbient();
                colorProperty->setColor(255.0f * color.r, 255.0f * color.g, 255.0f * color.b, 255.0f * color.a);
                colorProperty->setAlphaVisible(false);
                colorProperty->mUserData = pass;

                // Diffuse
                colorProperty = static_cast<QtColorProperty*>
                        (passContainer->createProperty(PASS_DIFFUSE, QString("Diffuse"), QtProperty::COLOR));
                color = pass->getDiffuse();
                colorProperty->setColor(255.0f * color.r, 255.0f * color.g, 255.0f * color.b, 255.0f * color.a);
                colorProperty->mUserData = pass;

                // Specular
                colorProperty = static_cast<QtColorProperty*>
                        (passContainer->createProperty(PASS_SPECULAR, QString("Specular"), QtProperty::COLOR));
                color = pass->getSpecular();
                colorProperty->setColor(255.0f * color.r, 255.0f * color.g, 255.0f * color.b, 255.0f * color.a);
                colorProperty->mUserData = pass;

                // Emissive
                colorProperty = static_cast<QtColorProperty*>
                        (passContainer->createProperty(PASS_EMISSIVE, QString("Emissive"), QtProperty::COLOR));
                color = pass->getEmissive();
                colorProperty->setColor(255.0f * color.r, 255.0f * color.g, 255.0f * color.b, 255.0f * color.a);
                colorProperty->setAlphaVisible(false);
                colorProperty->mUserData = pass;

                // Self illumination
                colorProperty = static_cast<QtColorProperty*>
                        (passContainer->createProperty(PASS_SELF_ILLUMINATION, QString("Self illumination"), QtProperty::COLOR));
                color = pass->getSelfIllumination();
                colorProperty->setColor(255.0f * color.r, 255.0f * color.g, 255.0f * color.b, 255.0f * color.a);
                colorProperty->setAlphaVisible(false);
                colorProperty->mUserData = pass;

                // Shininess
                decimalProperty = static_cast<QtDecimalProperty*>
                        (passContainer->createProperty(PASS_SHININESS, QString("Shininess"), QtProperty::DECIMAL));
                decimalProperty->setValue(pass->getShininess());
                decimalProperty->mUserData = pass;

                // Create containers - Texture Unit State
                unsigned int numTus = pass->getNumTextureUnitStates();
                for (unsigned int tus = 0; tus < numTus; ++tus)
                {
                    int tusContainerId = tus + TUS_BASE;
                    textureUnit = pass->getTextureUnitState(tus);
                    textureUnitContainer = passContainer->createContainer(tusContainerId, QString("Texture ") + QVariant(p).toString());
                    textureUnitContainer->setTitleBold();
                    textureUnitContainer->setTitleIcon(mIconDir + QString("texture_bold.png"));

                    // Texture name
                    stringProperty = static_cast<QtStringProperty*>
                            (textureUnitContainer->createProperty(TUS_TEXTURE_NAME, QString("Texture name"), QtProperty::STRING, true));
                    if (textureUnit->getNumFrames() > 0)
                    {
                        ch = textureUnit->getFrameTextureName(0).c_str(); // Get the first one; this is usually ok
                        stringProperty->setString(QString(ch));
                        stringProperty->mUserData = textureUnit;
                    }

                    // Texture filtering
                    QStringList stringListFiltering;
                    stringListFiltering << QString("None") <<
                                           QString("Point") <<
                                           QString("Linear") <<
                                           QString("Anisotropic");
                    selectProperty = static_cast<QtSelectProperty*>
                            (textureUnitContainer->createProperty(TUS_FILTERING, QString("Texture filtering (magnify)"), QtProperty::SELECT));
                    selectProperty->addValues(stringListFiltering);
                    selectProperty->mUserData = textureUnit;
                    Ogre::FilterOptions option = textureUnit->getTextureFiltering(Ogre::FT_MAG);
                    switch (option)
                    {
                        case Ogre::FO_NONE:
                            selectProperty->setCurentIndex(0);
                        break;
                        case Ogre::FO_POINT:
                            selectProperty->setCurentIndex(1);
                        break;
                        case Ogre::FO_LINEAR:
                            selectProperty->setCurentIndex(2);
                        break;
                        case Ogre::FO_ANISOTROPIC:
                            selectProperty->setCurentIndex(3);
                        break;
                    }

                    // Number of mipmaps
                    sliderProperty = static_cast<QtSliderProperty*>
                            (textureUnitContainer->createProperty(TUS_MIPMAPS, QString("Number of mipmaps"), QtProperty::SLIDER, true));
                    sliderProperty->setSliderRange(-1, 20, 1);
                    sliderProperty->setValue(textureUnit->getNumMipmaps());
                    sliderProperty->mUserData = textureUnit;

                    // U-sale
                    decimalProperty = static_cast<QtDecimalProperty*>
                        (textureUnitContainer->createProperty(TUS_USCALE, QString("U-scale"), QtProperty::DECIMAL));
                    decimalProperty->setValue(textureUnit->getTextureUScale());
                    decimalProperty->mUserData = textureUnit;

                    // V-sale
                    decimalProperty = static_cast<QtDecimalProperty*>
                            (textureUnitContainer->createProperty(TUS_VSCALE, QString("V-scale"), QtProperty::DECIMAL));
                    decimalProperty->setValue(textureUnit->getTextureVScale());
                    decimalProperty->mUserData = textureUnit;

                    // U-scroll
                    decimalProperty = static_cast<QtDecimalProperty*>
                            (textureUnitContainer->createProperty(TUS_USCROLL, QString("U-scroll"), QtProperty::DECIMAL));
                    decimalProperty->setValue(textureUnit->getTextureUScroll());
                    decimalProperty->mUserData = textureUnit;

                    // V-scroll
                    decimalProperty = static_cast<QtDecimalProperty*>
                            (textureUnitContainer->createProperty(TUS_VSCROLL, QString("V-scroll"), QtProperty::DECIMAL));
                    decimalProperty->setValue(textureUnit->getTextureVScroll());
                    decimalProperty->mUserData = textureUnit;
                }
            }
        }
    }

    //****************************************************************************/
    void QtOgreAssetMaterial::propertyValueChanged(QtProperty* property)
    {
        if (!mOgreMaterial || !property)
            return;

        //QtStringProperty* stringProperty;
        QtDecimalProperty* decimalProperty;
        QtCheckBoxProperty* checkboxProperty;
        QtColorProperty* colorProperty;
        //QtSliderProperty* sliderProperty;
        QtSelectProperty* selectProperty;
        Ogre::Pass* pass;
        Ogre::TextureUnitState* textureUnit;
        switch (property->mPropertyId)
        {
            // Material properties
            case MATERIAL_SCENE_BLENDING:
            {
                selectProperty = static_cast<QtSelectProperty*>(property);
                Ogre::SceneBlendType type = Ogre::SBT_ADD;
                if (selectProperty->getCurrentIndex() == 0)
                    type = Ogre::SBT_TRANSPARENT_ALPHA;
                else if (selectProperty->getCurrentIndex() == 1)
                    type = Ogre::SBT_TRANSPARENT_COLOUR;
                else if (selectProperty->getCurrentIndex() == 2)
                    type = Ogre::SBT_ADD;
                else if (selectProperty->getCurrentIndex() == 3)
                    type = Ogre::SBT_MODULATE;
                else if (selectProperty->getCurrentIndex() == 4)
                    type = Ogre::SBT_REPLACE;
                mOgreMaterial->setSceneBlending(type);
            }
            break;

            // Pass properties
            case PASS_DEPTH_CHECK:
            {
                checkboxProperty = static_cast<QtCheckBoxProperty*>(property);
                pass = static_cast<Ogre::Pass*>(checkboxProperty->mUserData);
                if (pass)
                    pass->setDepthCheckEnabled(checkboxProperty->getValue());
            }
            break;
            case PASS_DEPTH_WRITE:
            {
                checkboxProperty = static_cast<QtCheckBoxProperty*>(property);
                pass = static_cast<Ogre::Pass*>(checkboxProperty->mUserData);
                if (pass)
                    pass->setDepthWriteEnabled(checkboxProperty->getValue());
            }
            break;
            case PASS_LIGHTING:
            {
                checkboxProperty = static_cast<QtCheckBoxProperty*>(property);
                pass = static_cast<Ogre::Pass*>(checkboxProperty->mUserData);
                if (pass)
                    pass->setLightingEnabled(checkboxProperty->getValue());
            }
            break;
            case PASS_AMBIENT:
            {
                colorProperty = static_cast<QtColorProperty*>(property);
                pass = static_cast<Ogre::Pass*>(colorProperty->mUserData);
                if (pass)
                    pass->setAmbient(colorProperty->getRed()/255.0f,
                                     colorProperty->getGreen()/255.0f,
                                     colorProperty->getBlue()/255.0f);
            }
            break;
            case PASS_DIFFUSE:
            {
                colorProperty = static_cast<QtColorProperty*>(property);
                pass = static_cast<Ogre::Pass*>(colorProperty->mUserData);
                if (pass)
                    pass->setDiffuse(colorProperty->getRed()/255.0f,
                                     colorProperty->getGreen()/255.0f,
                                     colorProperty->getBlue()/255.0f,
                                     colorProperty->getAlpha()/255.0f);
            }
            break;
            case PASS_SPECULAR:
            {
                colorProperty = static_cast<QtColorProperty*>(property);
                pass = static_cast<Ogre::Pass*>(colorProperty->mUserData);
                if (pass)
                    pass->setSpecular(colorProperty->getRed()/255.0f,
                                      colorProperty->getGreen()/255.0f,
                                      colorProperty->getBlue()/255.0f,
                                      colorProperty->getAlpha()/255.0f);
            }
            break;
            case PASS_EMISSIVE:
            {
                colorProperty = static_cast<QtColorProperty*>(property);
                pass = static_cast<Ogre::Pass*>(colorProperty->mUserData);
                if (pass)
                    pass->setEmissive(colorProperty->getRed()/255.0f,
                                      colorProperty->getGreen()/255.0f,
                                      colorProperty->getBlue()/255.0f);
            }
            break;
            case PASS_SELF_ILLUMINATION:
            {
                colorProperty = static_cast<QtColorProperty*>(property);
                pass = static_cast<Ogre::Pass*>(colorProperty->mUserData);
                if (pass)
                    pass->setSelfIllumination(colorProperty->getRed()/255.0f,
                                              colorProperty->getGreen()/255.0f,
                                              colorProperty->getBlue()/255.0f);
            }
            break;
            case PASS_SHININESS:
            {
                decimalProperty = static_cast<QtDecimalProperty*>(property);
                pass = static_cast<Ogre::Pass*>(decimalProperty->mUserData);
                if (pass)
                    pass->setShininess(decimalProperty->getValue());
            }
            break;

            // Texture unit properties
            case TUS_FILTERING:
            {
                selectProperty = static_cast<QtSelectProperty*>(property);
                textureUnit = static_cast<Ogre::TextureUnitState*>(selectProperty->mUserData);
                if (textureUnit)
                {
                    if (selectProperty->getCurrentIndex() == 0)
                    {
                        textureUnit->setTextureFiltering(Ogre::FT_MIN, Ogre::FO_NONE);
                        textureUnit->setTextureFiltering(Ogre::FT_MAG, Ogre::FO_NONE);
                    }
                    else if (selectProperty->getCurrentIndex() == 1)
                    {
                        textureUnit->setTextureFiltering(Ogre::FT_MIN, Ogre::FO_POINT);
                        textureUnit->setTextureFiltering(Ogre::FT_MAG, Ogre::FO_POINT);
                    }
                    else if (selectProperty->getCurrentIndex() == 2)
                    {
                        textureUnit->setTextureFiltering(Ogre::FT_MIN, Ogre::FO_LINEAR);
                        textureUnit->setTextureFiltering(Ogre::FT_MAG, Ogre::FO_LINEAR);
                    }
                    else if (selectProperty->getCurrentIndex() == 3)
                    {
                        textureUnit->setTextureFiltering(Ogre::FT_MIN, Ogre::FO_ANISOTROPIC);
                        textureUnit->setTextureFiltering(Ogre::FT_MAG, Ogre::FO_ANISOTROPIC);
                    }
                }
            }
            break;

            case TUS_USCALE:
            {
                decimalProperty = static_cast<QtDecimalProperty*>(property);
                textureUnit = static_cast<Ogre::TextureUnitState*>(decimalProperty->mUserData);
                if (textureUnit)
                    textureUnit->setTextureUScale(decimalProperty->getValue());
            }
            break;

            case TUS_VSCALE:
            {
                decimalProperty = static_cast<QtDecimalProperty*>(property);
                textureUnit = static_cast<Ogre::TextureUnitState*>(decimalProperty->mUserData);
                if (textureUnit)
                    textureUnit->setTextureVScale(decimalProperty->getValue());
            }
            break;

            case TUS_USCROLL:
            {
                decimalProperty = static_cast<QtDecimalProperty*>(property);
                textureUnit = static_cast<Ogre::TextureUnitState*>(decimalProperty->mUserData);
                if (textureUnit)
                    textureUnit->setTextureUScroll(decimalProperty->getValue());
            }
            break;

            case TUS_VSCROLL:
            {
                decimalProperty = static_cast<QtDecimalProperty*>(property);
                textureUnit = static_cast<Ogre::TextureUnitState*>(decimalProperty->mUserData);
                if (textureUnit)
                    textureUnit->setTextureVScroll(decimalProperty->getValue());
            }
            break;
        }
    }
CRosRttTexture::CRosRttTexture(unsigned width, unsigned height, Ogre::Camera * camera, bool isDepth /*= false*/ )
: m_materialName("MyRttMaterial")
, width_(width)
, height_(height)
, frame_("/map")
, m_bIsDepth( isDepth )
{
  assert( height > 0 && width > 0 );

  {
    // Set encoding
    current_image_.encoding = ROS_IMAGE_FORMAT;

    // Set image size
    current_image_.width = width;
    current_image_.height = height;

    // Set image row length in bytes (row length * 3 bytes for a color)
    current_image_.step = width * BPP;

#if OGRE_ENDIAN == ENDIAN_BIG
    current_image_.is_bigendian = true;
#else
        current_image_.is_bigendian = false;
#endif

    // Resize data
    current_image_.data.resize( width_ * height_ * BPP);

  }

  Ogre::TextureManager & lTextureManager( Ogre::TextureManager::getSingleton() );
  Ogre::String textureName("RVIZ_CamCast_Texture");
  bool lGammaCorrection( false );
  unsigned int lAntiAliasing( 0 );
  unsigned int lNumMipmaps( 0 );

  if( isDepth )
  {
	  texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
		  Ogre::TEX_TYPE_2D, width, height, lNumMipmaps,
		  OGRE_DEPTH_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing);
  }
  else
  {
	  texture_ = lTextureManager.createManual(textureName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
	  		  Ogre::TEX_TYPE_2D, width, height, lNumMipmaps,
	  		  OGRE_TEXTURE_FORMAT, Ogre::TU_RENDERTARGET, 0, lGammaCorrection, lAntiAliasing);
  }

  // Create render target
  Ogre::RenderTexture* lRenderTarget = NULL;

  Ogre::HardwarePixelBufferSharedPtr lRttBuffer = texture_->getBuffer();
  lRenderTarget = lRttBuffer->getRenderTarget();
  lRenderTarget->setAutoUpdated(true);

  // Create and attach viewport

  Ogre::Viewport* lRttViewport1 = lRenderTarget->addViewport(camera, 50, 0.00f, 0.00f, 1.0f, 1.0f);
  lRttViewport1->setAutoUpdated(true);
  Ogre::ColourValue lBgColor1(0.0,0.0,0.0,1.0);
  lRttViewport1->setBackgroundColour(lBgColor1);

  // create a material using this texture.

  //Get a reference on the material manager, which is a singleton.
  Ogre::MaterialManager& lMaterialManager = Ogre::MaterialManager::getSingleton();
  Ogre::MaterialPtr lMaterial = lMaterialManager.create(m_materialName, Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
  Ogre::Technique * lTechnique = lMaterial->getTechnique(0);
  Ogre::Pass* lPass = lTechnique->getPass(0);

  if( isDepth )
  {
	  lPass->setLightingEnabled(false);
  }

  Ogre::TextureUnitState* lTextureUnit = lPass->createTextureUnitState();
  lTextureUnit->setTextureName(textureName);

  lTextureUnit->setNumMipmaps(0);
  lTextureUnit->setTextureFiltering(Ogre::TFO_BILINEAR);

  update();
}
示例#14
0
void RenderState::createScene()
{
        ////////////////////// Volume texture
        // breadVolume.createTexture("media/fields/imagen3-1.field", "volumeTex");
        // breadVolume.createTexture("media/fields/mengel3d.field", "volumeTex");
        // breadVolume.createTexture("media/fields/3Dbread.256.field", "volumeTex");
        breadDensityVolume.createTexture("media/fields/warped.field", "densityTex");
        breadDensityTex = breadDensityVolume.getTexturePtr();
        if (breadDensityTex.isNull()) {
                printf("Error generating density texture");
                exit();
        }

        breadCrustVolume.createTexture("media/fields/warpedC.field", "crustTex");
        breadCrustTex = breadCrustVolume.getTexturePtr();
        if (breadCrustTex.isNull()) {
                printf("Error generating crust texture");
                exit();
        }

        breadOcclusionVolume.createTexture("media/fields/warpedO.field", "occlusionTex");
        breadOcclusionTex = breadOcclusionVolume.getTexturePtr();
        if (breadOcclusionTex.isNull()) {
                printf("Error generating occlusion texture");
                exit();
        }

        ///////////////////// Volume bounding cubes
        breadVolumeBoundingCubes.create(breadDensityVolume, 32, 1, 255, _sceneMgr);

        //////////// Background color
        Ogre::Viewport* vp = OgreFramework::getSingletonPtr()->_viewport;
        vp->setBackgroundColour (ColourValue(0.1,0.1,0.1));

        //////////// Light
        _sceneMgr->setAmbientLight(ColourValue(0.1,0.1,0.1));

        light = _sceneMgr->createLight("Light");
        // light->setType(Light::LT_POINT);
        light->setType(Light::LT_SPOTLIGHT);
        light->setPosition(100,100,100);
        light->setDirection(100,-100,100);
        light->setDiffuseColour(1,1,1);
        light->setSpecularColour(1.0,1.0,1.0);
        light->setSpotlightRange(Radian(M_PI/2), Radian(M_PI/3));
        // light->setAttenuation(20, 0.5, 1, 1);
        
        //////////// Shadows
        // _sceneMgr->setShadowTechnique(SHADOWTYPE_STENCIL_ADDITIVE);
        // _sceneMgr->setShadowTextureSettings( 256, 2);
        // _sceneMgr->setShadowTextureConfig( 0, 512, 512, PF_FLOAT16_R, 50 );

        ////////////////////// BREAD
        breadEntity = _sceneMgr->createEntity("BreadEntity", "Cube01.mesh");
        breadNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("BreadNode");
        breadNode->attachObject(breadEntity);
        breadNode->setOrientation(Quaternion::IDENTITY);
        breadNode->setPosition(Vector3(0, 0, 0));
        breadNode->setScale(Vector3(20,20,20));
        // breadEntity->setRenderQueueGroup(RENDER_QUEUE_8);
        breadEntity->setCastShadows(true);

        breadEntity->getSubEntity(0)->setMaterialName("Bread","General");
        breadMat = breadEntity->getSubEntity(0)->getMaterial();

        Ogre::Pass* breadPass = breadMat->getTechnique(0)->getPass(0);

        Ogre::TextureUnitState* posTU = breadPass->createTextureUnitState("rayPos");
        Ogre::TextureUnitState* dirTU = breadPass->createTextureUnitState("rayDir");

        posTU->setTextureName("rayPos");
        dirTU->setTextureName("rayDir");

        posTU->setTextureFiltering(TFO_NONE);
        dirTU->setTextureFiltering(TFO_NONE);

        posTU->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
        dirTU->setTextureAddressingMode(TextureUnitState::TAM_CLAMP);
        
        /////////////////////// TABLE
        tableEntity = _sceneMgr->createEntity("PlaneEntity", "Plane.mesh");
        tableEntity->getSubEntity(0)->setMaterialName("Table","General");
        tableEntity->setCastShadows(false);
        tableNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("PlaneNode");
        tableNode->attachObject(tableEntity);
        tableNode->setOrientation(Quaternion::IDENTITY);
        tableNode->setPosition(Vector3(0, 0, 0));
        tableNode->setScale(Vector3(10,10,10));

        /////////////////////// KNIFE
        knifeEntity = _sceneMgr->createEntity("KnifeEntity", "knife.mesh");
        knifeEntity->getSubEntity(0)->setMaterialName("Knife","General");
        knifeEntity->setCastShadows(false);
        knifeNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("KnifeNode");
        knifeNode->attachObject(knifeEntity);
        Quaternion ori(Radian(-0.5), Vector3(0,1,0));
        knifeNode->setOrientation(ori);
        knifeNode->setPosition(Vector3(30, 1, -30));
        knifeNode->setScale(Vector3(50,50,50));

        // Create background rectangle covering the whole screen
        Rectangle2D* rect = new Rectangle2D(true);
        rect->setCorners(-1.0, 1.0, 1.0, -1.0);
        rect->setMaterial("Degrade");
        rect->setCastShadows(false);
 
        // Render the background before everything else
        rect->setRenderQueueGroup(RENDER_QUEUE_BACKGROUND);
 
        // Use infinite AAB to always stay visible
        AxisAlignedBox aabInf;
        aabInf.setInfinite();
        rect->setBoundingBox(aabInf);
 
        // Attach background to the scene
        backgroundNode =_sceneMgr->getRootSceneNode()->createChildSceneNode("Background");
        backgroundNode->attachObject(rect);

        /////////////// Light obj
        // Create background rectangle covering the whole screen
        lightEntity = _sceneMgr->createEntity("LightEntity", "Cube01.mesh");
        lightNode = _sceneMgr->getRootSceneNode()->createChildSceneNode("Light");
        lightEntity->getSubEntity(0)->setMaterialName("White","General");
        lightEntity->setCastShadows(false);
        lightNode->attachObject(lightEntity);
        lightNode->setPosition(light->getPosition());
        lightNode->showBoundingBox(false);

        ///////////////////////// Set visibility masks for all entities
        lightEntity->setVisibilityFlags(RF_MAIN);
        rect->setVisibilityFlags(RF_MAIN);
        knifeEntity->setVisibilityFlags(RF_MAIN);
        tableEntity->setVisibilityFlags(RF_MAIN);
        breadEntity->setVisibilityFlags(RF_MAIN);
}
示例#15
0
void CameraDisplay::onInitialize()
{
  caminfo_tf_filter_ = new tf::MessageFilter<sensor_msgs::CameraInfo>(*vis_manager_->getTFClient(), "", 2, update_nh_);

  bg_scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();
  fg_scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();

  {
    static int count = 0;
    UniformStringStream ss;
    ss << "CameraDisplayObject" << count++;

    //background rectangle
    bg_screen_rect_ = new Ogre::Rectangle2D(true);
    bg_screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);

    ss << "Material";
    bg_material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
    bg_material_->setDepthWriteEnabled(false);

    bg_material_->setReceiveShadows(false);
    bg_material_->setDepthCheckEnabled(false);

    bg_material_->getTechnique(0)->setLightingEnabled(false);
    Ogre::TextureUnitState* tu = bg_material_->getTechnique(0)->getPass(0)->createTextureUnitState();
    tu->setTextureName(texture_.getTexture()->getName());
    tu->setTextureFiltering( Ogre::TFO_NONE );
    tu->setAlphaOperation( Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.0 );

    bg_material_->setCullingMode(Ogre::CULL_NONE);
    bg_material_->setSceneBlending( Ogre::SBT_REPLACE );

    Ogre::AxisAlignedBox aabInf;
    aabInf.setInfinite();

    bg_screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
    bg_screen_rect_->setBoundingBox(aabInf);
    bg_screen_rect_->setMaterial(bg_material_->getName());

    bg_scene_node_->attachObject(bg_screen_rect_);
    bg_scene_node_->setVisible(false);

    //overlay rectangle
    fg_screen_rect_ = new Ogre::Rectangle2D(true);
    fg_screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);

    fg_material_ = bg_material_->clone( ss.str()+"fg" );
    fg_screen_rect_->setBoundingBox(aabInf);
    fg_screen_rect_->setMaterial(fg_material_->getName());

    fg_material_->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
    fg_screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);

    fg_scene_node_->attachObject(fg_screen_rect_);
    fg_scene_node_->setVisible(false);
  }

  setAlpha( 0.5f );

  render_panel_ = new RenderPanel();
  render_panel_->getRenderWindow()->addListener( this );
  render_panel_->getRenderWindow()->setAutoUpdated(false);
  render_panel_->getRenderWindow()->setActive( false );
  render_panel_->resize( 640, 480 );
  render_panel_->initialize(vis_manager_->getSceneManager(), vis_manager_);

  WindowManagerInterface* wm = vis_manager_->getWindowManager();
  if( wm )
  {
    panel_container_ = wm->addPane(name_, render_panel_);
  }
  render_panel_->setAutoRender(false);
  render_panel_->setOverlaysEnabled(false);
  render_panel_->getCamera()->setNearClipDistance( 0.01f );

  caminfo_tf_filter_->connectInput(caminfo_sub_);
  caminfo_tf_filter_->registerCallback(boost::bind(&CameraDisplay::caminfoCallback, this, _1));
  vis_manager_->getFrameManager()->registerFilterForTransformStatusCheck(caminfo_tf_filter_, this);

  if( panel_container_ )
  {
    // TODO: wouldn't it be better to connect this straight to the wrapper?
    connect( panel_container_, SIGNAL( visibilityChanged( bool ) ), this, SLOT( setWrapperEnabled( bool )));
  }
}
示例#16
0
// void TerrainPageSurfaceCompiler::addTextureUnitsToPass(Ogre::Pass* pass, const Ogre::String& splatTextureName) {
//
// 	if (getMaxTextureUnits() - pass->getNumTextureUnitStates() < 2 || pass->getParent()->getNumPasses() > 1)  {
// 		addPassToTechnique(pass->getParent(), splatTextureName);
// // 		S_LOG_WARNING("Trying to add texture units to pass with too few available texture unit states.");
// 		return;
// 	}
//
// 	S_LOG_VERBOSE("Adding new texture unit (detailtexture: " << mTextureName << " alphatexture: " << splatTextureName << ") to pass nr " << pass->getIndex() << " in technique for material " << pass->getParent()->getParent()->getName());
//
// /*	pass->setSelfIllumination(Ogre::ColourValue(1,1,1));
// 	pass->setAmbient(Ogre::ColourValue(1,1,1));
// 	pass->setDiffuse(Ogre::ColourValue(1,1,1));
// 	pass->setLightingEnabled(true);*/
// 	Ogre::TextureUnitState * textureUnitStateSplat = pass->createTextureUnitState();
//     textureUnitStateSplat->setTextureName(splatTextureName);
//
//     textureUnitStateSplat->setTextureCoordSet(0);
// 	textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
// 	textureUnitStateSplat->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE);
// 	textureUnitStateSplat->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
//     textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
// // 	textureUnitStateSplat->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE);
// //	textureUnitStateSplat->setColourOperationEx(Ogre::LBX_BLEND_TEXTURE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE);
//
// 	Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState();
//     textureUnitState->setTextureName(mTextureName);
//     textureUnitState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
// /*	textureUnitState->setTextureCoordSet(0);*/
// 	textureUnitState->setTextureScale(0.025, 0.025);
// 	textureUnitState->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);
//
// /*	Ogre::TextureUnitState * alphaTextureState= pass->createTextureUnitState();
//     alphaTextureState->setTextureName(mTextureName);
// //     alphaTextureState->setTextureName(splatTextureName);
//     alphaTextureState->setTextureCoordSet(0);
// 	alphaTextureState->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
//     alphaTextureState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
//  	alphaTextureState->setColourOperationEx(Ogre::LBX_BLEND_DIFFUSE_ALPHA, Ogre::LBS_CURRENT, Ogre::LBS_TEXTURE);
//
//
//
// // 	detailTextureState->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE);
// // 	detailTextureState->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
//
// 	Ogre::TextureUnitState * detailTextureState  = pass->createTextureUnitState();
//     detailTextureState ->setTextureName(splatTextureName);
// //     detailTextureState ->setTextureName(mTextureName);
//     detailTextureState ->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
// 	detailTextureState ->setTextureCoordSet(0);
// 	detailTextureState ->setTextureScale(0.01, 0.01);
// 	//detailTextureState ->setColourOperationEx(Ogre::LBX_BLEND_CURRENT_ALPHA, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);*/
//
// }
//
Ogre::Pass* Simple::addPassToTechnique(const TerrainPageGeometry& geometry, Ogre::Technique* technique, const Layer& layer, std::set<std::string>& managedTextures) const
{
	//check if we instead can reuse the existing pass
	// 	if (technique->getNumPasses() != 0) {
	// 		Ogre::Pass* pass = technique->getPass(technique->getNumPasses() - 1);
	// 		if (4 - pass->getNumTextureUnitStates() >= 2) {
	// 			//there's more than two texture units available, use those instead of creating a new pass
	// 			S_LOG_VERBOSE("Reusing existing pass. ("<< pass->getNumTextureUnitStates() << " of "<< mNumberOfTextureUnitsOnCard << " texture unit used)");
	// 			addTextureUnitsToPass(pass, splatTextureName);
	// 			return pass;
	// 		}
	//
	// 	}

	const OgreImage& ogreImage = *layer.blendMap;
	Ogre::Image image;

	image.loadDynamicImage(const_cast<unsigned char*>(ogreImage.getData()), ogreImage.getResolution(), ogreImage.getResolution(), 1, Ogre::PF_A8);

	std::stringstream splatTextureNameSS;
	splatTextureNameSS << "terrain_" << mPage.getWFPosition().x() << "_" << mPage.getWFPosition().y() << "_" << technique->getNumPasses();
	const Ogre::String splatTextureName(splatTextureNameSS.str());
	Ogre::TexturePtr blendMapTexture;
	if (Ogre::Root::getSingletonPtr()->getTextureManager()->resourceExists(splatTextureName)) {
		blendMapTexture = static_cast<Ogre::TexturePtr>(Ogre::Root::getSingletonPtr()->getTextureManager()->getByName(splatTextureName));
		blendMapTexture->loadImage(image);

		Ogre::HardwarePixelBufferSharedPtr hardwareBuffer(blendMapTexture->getBuffer());
		//blit the whole image to the hardware buffer
		Ogre::PixelBox sourceBox(image.getPixelBox());
		hardwareBuffer->blitFromMemory(sourceBox);
	} else {
		blendMapTexture = Ogre::Root::getSingletonPtr()->getTextureManager()->loadImage(splatTextureName, "General", image, Ogre::TEX_TYPE_2D, 0);
		managedTextures.insert(blendMapTexture->getName());
	}

	//we need to create the image, update it and then destroy it again (to keep the memory usage down)
	//	if (layer->getBlendMapTextureName() == "") {
	//		//no texture yet; let's create one
	//		layer->createBlendMapImage();
	//		layer->updateBlendMapImage(geometry);
	//		layer->createTexture();
	//	} else {
	//		//a texture exists, so we just need to update the image
	//		layer->updateBlendMapImage(geometry); //calling this will also update the texture since the method will blit the image onto it
	//	}

	Ogre::Pass* pass = technique->createPass();

	pass->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
	pass->setAmbient(1, 1, 1);
	pass->setDiffuse(1, 1, 1, 1);
	pass->setLightingEnabled(false);

	Ogre::TextureUnitState * textureUnitState = pass->createTextureUnitState();
	textureUnitState->setTextureName(layer.surfaceLayer.getDiffuseTextureName());
	textureUnitState->setTextureAddressingMode(Ogre::TextureUnitState::TAM_WRAP);
	textureUnitState->setTextureCoordSet(0);
	textureUnitState->setTextureScale(1.0f / layer.surfaceLayer.getScale(), 1.0f / layer.surfaceLayer.getScale());

	Ogre::TextureUnitState * textureUnitStateSplat = pass->createTextureUnitState();
	textureUnitStateSplat->setTextureName(blendMapTexture->getName());

	textureUnitStateSplat->setTextureCoordSet(0);
	textureUnitStateSplat->setTextureAddressingMode(Ogre::TextureUnitState::TAM_CLAMP);
	textureUnitStateSplat->setTextureFiltering(Ogre::TFO_ANISOTROPIC);
	//	textureUnitStateSplat->setAlphaOperation(Ogre::LBX_SOURCE1, Ogre::LBS_TEXTURE, Ogre::LBS_TEXTURE);
	textureUnitStateSplat->setAlphaOperation(Ogre::LBX_BLEND_DIFFUSE_COLOUR, Ogre::LBS_TEXTURE, Ogre::LBS_CURRENT);
	textureUnitStateSplat->setColourOperationEx(Ogre::LBX_SOURCE1, Ogre::LBS_CURRENT, Ogre::LBS_CURRENT);
	return pass;

}
CameraDisplaySave::CameraDisplaySave( const std::string& name, VisualizationManager* manager )
: Display( name, manager )
, transport_("raw")
, caminfo_tf_filter_(*manager->getTFClient(), "", 2, update_nh_)
, new_caminfo_(false)
, texture_(update_nh_)
, frame_(0)
, force_render_(false)
, render_listener_(this)
{
  scene_node_ = scene_manager_->getRootSceneNode()->createChildSceneNode();

  {
    static int count = 0;
    std::stringstream ss;
    ss << "CameraDisplaySaveObject" << count++;

    screen_rect_ = new Ogre::Rectangle2D(true);
    screen_rect_->setRenderQueueGroup(Ogre::RENDER_QUEUE_OVERLAY - 1);
    screen_rect_->setCorners(-1.0f, 1.0f, 1.0f, -1.0f);

    ss << "Material";
    material_ = Ogre::MaterialManager::getSingleton().create( ss.str(), Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME );
    material_->setSceneBlending( Ogre::SBT_TRANSPARENT_ALPHA );
    material_->setDepthWriteEnabled(false);

    material_->setReceiveShadows(false);
    material_->setDepthCheckEnabled(false);


#if 1
    material_->getTechnique(0)->setLightingEnabled(false);
    Ogre::TextureUnitState* tu = material_->getTechnique(0)->getPass(0)->createTextureUnitState();
    tu->setTextureName(texture_.getTexture()->getName());
    tu->setTextureFiltering( Ogre::TFO_NONE );
    tu->setAlphaOperation( Ogre::LBX_SOURCE1, Ogre::LBS_MANUAL, Ogre::LBS_CURRENT, 0.0 );
#else
    material_->getTechnique(0)->setLightingEnabled(true);
    material_->setAmbient(Ogre::ColourValue(0.0f, 1.0f, 1.0f, 1.0f));
#endif

    material_->setCullingMode(Ogre::CULL_NONE);
    Ogre::AxisAlignedBox aabInf;
    aabInf.setInfinite();
    screen_rect_->setBoundingBox(aabInf);
    screen_rect_->setMaterial(material_->getName());
    scene_node_->attachObject(screen_rect_);

  }

  setAlpha( 0.5f );

  wxWindow* parent = 0;

  WindowManagerInterface* wm = vis_manager_->getWindowManager();
  if (wm)
  {
    parent = wm->getParentWindow();
  }
  else
  {
    frame_ = new wxFrame(0, wxID_ANY, wxString::FromAscii(name.c_str()), wxPoint(100,100), wxDefaultSize, wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxRESIZE_BORDER | wxCAPTION | wxCLIP_CHILDREN);
    parent = frame_;
  }

  render_panel_ = new RenderPanel(parent, false);
  render_panel_->SetSize(wxSize(640, 480));
  if (wm)
  {
    wm->addPane(name, render_panel_);
  }

  render_panel_->createRenderWindow();
  render_panel_->initialize(vis_manager_->getSceneManager(), vis_manager_);

  render_panel_->setAutoRender(false);
  render_panel_->getRenderWindow()->addListener(&render_listener_);
  render_panel_->getViewport()->setOverlaysEnabled(false);
  render_panel_->getViewport()->setClearEveryFrame(true);
  render_panel_->getRenderWindow()->setActive(false);
  render_panel_->getRenderWindow()->setAutoUpdated(false);
  render_panel_->getCamera()->setNearClipDistance( 0.1f );

  caminfo_tf_filter_.connectInput(caminfo_sub_);
  caminfo_tf_filter_.registerCallback(boost::bind(&CameraDisplaySave::caminfoCallback, this, _1));
  vis_manager_->getFrameManager()->registerFilterForTransformStatusCheck(caminfo_tf_filter_, this);
}
示例#18
0
void UniversePlanet::create() {
    Ogre::MaterialPtr mat = Ogre::MaterialManager::getSingleton().create("BoxColor", "General", true);
    Ogre::Technique* tech = mat->getTechnique(0);
    Ogre::Pass* pass = tech->getPass(0);
    Ogre::TextureUnitState* tex = pass->createTextureUnitState();

    tex->setTextureName("materials/textures/grass.png");
    tex->setNumMipmaps(4);
    tex->setTextureAnisotropy(1);
    tex->setTextureFiltering(Ogre::FO_POINT, Ogre::FO_POINT, Ogre::FO_POINT);

    ManualObject *meshChunk = new ManualObject("meshChunk_" + getName());
    int iVertex = 0;
    block_t currentBlock;
    block_t nextBlock;
    Ogre::Vector3 v;

    meshChunk->begin("BoxColor");

    for(int w = 0; w < 6; ++w)
        for(int z = 0; z < mWorldHeight; ++z)
            for(int y = 0; y < mWorldSize; ++y)
                for(int x = 0; x < mWorldSize; ++x) {
                    currentBlock = getBlock(w, x, y, z);
                    if(currentBlock == 0) continue;

                    //x-1
                    nextBlock = 0;
                    nextBlock = getBlock(w, x - 1, y, z);
                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y, z + 1));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x, y + 1, z + 1));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x, y + 1, z));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y, z));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //x+1

                    nextBlock = 0;
                    nextBlock = getBlock(w, x + 1, y, z);
                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x + 1, y, z));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z + 1));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x + 1, y, z + 1));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //y-1
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y - 1, z);

                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y, z));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y, z));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y, z + 1));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y, z + 1));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //y+1
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y + 1, z);

                    if(nextBlock == 0) {

                        meshChunk->position(map(w, x, y + 1, z + 1));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z + 1));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y + 1, z));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);
                        else meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);

                        iVertex += 4;
                    }

                    //z-1 ok
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y, z - 1);

                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y + 1, z));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y, z));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y, z));
                        meshChunk->textureCoord(0, 0);

                        if(w == 0 || w == 3 || w == 5) meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);
                        else meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);

                        iVertex += 4;
                    }

                    //z+1 ok
                    nextBlock = 0;
                    nextBlock = getBlock(w, x, y, z + 1);

                    if(nextBlock == 0) {
                        meshChunk->position(map(w, x, y, z + 1));
                        meshChunk->textureCoord(0, 1);
                        meshChunk->position(map(w, x + 1, y, z + 1));
                        meshChunk->textureCoord(1, 1);
                        meshChunk->position(map(w, x + 1, y + 1, z + 1));
                        meshChunk->textureCoord(1, 0);
                        meshChunk->position(map(w, x, y + 1, z + 1));
                        meshChunk->textureCoord(0, 0);

                        if(w == 1 || w == 2 || w == 4) meshChunk->quad(iVertex, iVertex + 1, iVertex + 2, iVertex + 3);
                        else meshChunk->quad(iVertex + 3, iVertex + 2, iVertex + 1, iVertex);

                        iVertex += 4;
                    }

                }
    meshChunk->end();
    Application::getSceneMgr()->getRootSceneNode()->createChildSceneNode()->attachObject(meshChunk);

    Application::getSceneMgr()->setAmbientLight(Ogre::ColourValue(0.5, 0.5, 0.5));
    Ogre::Light* l = Application::getSceneMgr()->createLight("MainLight");
    l->setPosition(20, 80, 50);
}