Exemple #1
0
	void IntroScene::initScene()
	{
		mSceneMgr = mRoot->createSceneManager( ST_GENERIC , "intro" );
		mCamera = mSceneMgr->createCamera("Cam1");
		mVp = mWindow->addViewport(mCamera);
		mVp->setBackgroundColour(ColourValue(1.0f, 0.0f,0.0f));
		mCamera->setAspectRatio(Real(mVp->getActualWidth())/mVp->getActualHeight());
		mSceneMgr->setAmbientLight( ColourValue( 1, 1, 1 ) );

		Ogre::MaterialManager *matMgr = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialPtr mat = (Ogre::MaterialPtr )matMgr->create("intro2","General");

		mat->getTechnique(0)->getPass(0)->createTextureUnitState("cybernetic.jpg");
		mat->getTechnique(0)->getPass(0)->setDepthCheckEnabled(false);
		mat->getTechnique(0)->getPass(0)->setDepthWriteEnabled(false);
		mat->getTechnique(0)->getPass(0)->setLightingEnabled(false);

		Ogre::Rectangle2D *rect = new Ogre::Rectangle2D(true);
		rect->setCorners( -1.0 , 1.0 , 1.0 , -1.0 );
		rect->setMaterial("intro2");
		rect->setRenderQueueGroup(Ogre::RENDER_QUEUE_BACKGROUND);
		SceneNode* node = mSceneMgr->getRootSceneNode()->createChildSceneNode("Background");
		node->attachObject(rect);
		AxisAlignedBox aabInf;
		aabInf.setInfinite();
		rect->setBoundingBox(aabInf);
	
	}
//-----------------------------------------------------------------------
void MaterialTab::OnNewMaterial(wxCommandEvent& event)
{
	if (mMaterialListBox)
	{
		wxString name = wxT("Material") + ogre2wx(ParticleUniverse::StringConverter::toString(mNewMaterialCounter));
		mMaterialListBox->addMaterialName(name);
		mNewMaterialCounter++;
		Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::String nameString = wx2ogre(name);
		materialManager->create(nameString, TEMP_MATERIAL_GROUP);
		Ogre::MaterialPtr material = materialManager->getByName(nameString, TEMP_MATERIAL_GROUP);
		selectMaterial(name);
	}
}
Exemple #3
0
	void OgreModule::initEnd()
	{
		Ogre::CompositorManager2* compositorManager = mOgreRoot.getCompositorManager2();
		compositorManager->createBasicWorkspaceDef("Basic Workspace", Ogre::ColourValue(0.15f, 0.15f, 0.15f));
		compositorManager->createBasicWorkspaceDef("Black Workspace", Ogre::ColourValue::Black);

		Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
		Ogre::MaterialPtr material = materialManager->create("debug_invisible", Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		material->setReceiveShadows(false);
		Ogre::Pass* pass = material->getTechnique(0)->getPass(0);
#if OGRE_VERSION_MAJOR == 2 && OGRE_VERSION_MINOR > 0
#else
		pass->setCullingMode(Ogre::CULL_NONE);
		pass->setColourWriteEnabled(false);
		pass->setDepthWriteEnabled(false);
#endif

		this->loadResources();
	}
void MilkshapePlugin::doExportMaterials(msModel* pModel)
{
	Ogre::LogManager& logMgr = Ogre::LogManager::getSingleton();
	Ogre::MaterialManager matMgrSgl;
	Ogre::String msg;

    matMgrSgl.initialise();

	int numMaterials = msModel_GetMaterialCount(pModel);
	msg = "Number of materials: " + Ogre::StringConverter::toString(numMaterials);
	logMgr.logMessage(msg);

	OPENFILENAME ofn;
	memset (&ofn, 0, sizeof (OPENFILENAME));

	char szFile[MS_MAX_PATH];
	char szFileTitle[MS_MAX_PATH];
	char szDefExt[32] = "material";
	char szFilter[128] = "OGRE .material Files (*.material)\0*.material\0All Files (*.*)\0*.*\0\0";
	szFile[0] = '\0';
	szFileTitle[0] = '\0';

	ofn.lStructSize = sizeof (OPENFILENAME);
	ofn.lpstrDefExt = szDefExt;
	ofn.lpstrFilter = szFilter;
	ofn.lpstrFile = szFile;
	ofn.nMaxFile = MS_MAX_PATH;
	ofn.lpstrFileTitle = szFileTitle;
	ofn.nMaxFileTitle = MS_MAX_PATH;
	ofn.Flags = OFN_HIDEREADONLY | OFN_OVERWRITEPROMPT | OFN_PATHMUSTEXIST;
	ofn.lpstrTitle = "Export to OGRE Material";

	if (!::GetSaveFileName (&ofn))
		return;

	// Strip off the path
	Ogre::String matName = szFile;
	size_t lastSlash = matName.find_last_of("\\");
	matName = matName.substr(lastSlash+1);

	// Set up
	logMgr.logMessage("Trying to create Material object");

	Ogre::MaterialSerializer matSer;

	for (int i = 0; i < numMaterials; ++i)
	{
		msMaterial *mat = msModel_GetMaterialAt(pModel, i);

		msg = "Creating material " + Ogre::String(mat->szName);
		logMgr.logMessage(msg);
        Ogre::MaterialPtr ogremat = matMgrSgl.create(mat->szName, 
            Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
		logMgr.logMessage("Created.");

		ogremat->setAmbient(msVec4ToColourValue(mat->Ambient));
		ogremat->setDiffuse(msVec4ToColourValue(mat->Diffuse));
		ogremat->setSpecular(msVec4ToColourValue(mat->Specular));
		ogremat->setShininess(mat->fShininess);

		if (0 < strlen(mat->szDiffuseTexture))
			ogremat->getTechnique(0)->getPass(0)->createTextureUnitState(mat->szDiffuseTexture);

        if (0 < strlen(mat->szAlphaTexture))
			ogremat->getTechnique(0)->getPass(0)->createTextureUnitState(mat->szAlphaTexture);


		matSer.queueForExport(ogremat);
	}

	msg = "Exporting materials to " + matName;
	logMgr.logMessage(msg);
	matSer.exportQueued(matName);
}
void OGKSceneManager::_initRTT()
{
    if(mTransitionTexture.isNull()) {
        Ogre::TextureManager *mgr = Ogre::TextureManager::getSingletonPtr();
        
        mTransitionTexture = mgr->createManual(kTransitionTextureName,
                                               Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME,
                                               Ogre::TEX_TYPE_2D,
                                               OGKGame::getSingletonPtr()->mRenderWindow->getWidth(),
                                               OGKGame::getSingletonPtr()->mRenderWindow->getHeight(),
                                               0,
                                               Ogre::PF_R8G8B8A8,
                                               Ogre::TU_RENDERTARGET);
    }
    
    if(!mRenderTexture) {
        mRenderTexture = mTransitionTexture->getBuffer()->getRenderTarget();
        mRenderTexture->setAutoUpdated(false);
        mRenderTexture->addListener(this);
    }
    
    if(!mPanel) {
        Ogre::MaterialManager *mgr = Ogre::MaterialManager::getSingletonPtr();
        
#ifdef OGRE_IS_IOS
        mTransitionMaterial = mgr->getByName("OGK/SceneTransitionMaterial");
        
        //mTransitionMaterial->getTechnique(0)->getPass(0)->removeAllTextureUnitStates();
        //Ogre::TextureUnitState* state = mTransitionMaterial->getTechnique(0)->getPass(0)->createTextureUnitState();
#else
        mTransitionMaterial = mgr->create(kTransitionMaterialName,
                                          Ogre::ResourceGroupManager::DEFAULT_RESOURCE_GROUP_NAME);
        mTransitionMaterial->getTechnique(0)->getPass(0)->setLightingEnabled(false);
        mTransitionMaterial->getTechnique(0)->getPass(0)->setSceneBlending(Ogre::SBT_TRANSPARENT_ALPHA);
        mTransitionMaterial->getTechnique(0)->getPass(0)->createTextureUnitState(kTransitionTextureName);
        
#endif
        mTransitionTextureUnitState = mTransitionMaterial->getTechnique(0)->getPass(0)->getTextureUnitState(0);
        
#ifdef OGRE_IS_IOS
//        mTransitionTextureUnitState->setTextureFiltering( Ogre::FO_ANISOTROPIC, Ogre::FO_ANISOTROPIC, Ogre::FO_LINEAR );
//        mTransitionTextureUnitState->setTextureAnisotropy( 8 );
//        mTransitionTextureUnitState->setTextureName( kTransitionTextureName );
        mTransitionTextureUnitState->setTexture(mTransitionTexture);
#endif
        
        mPanel = static_cast<Ogre::PanelOverlayElement*>(Ogre::OverlayManager::getSingleton().createOverlayElement( "Panel", kTransitionOverlayPanelName));
        mPanel->setMetricsMode(Ogre::GMM_RELATIVE);
        mPanel->setPosition(0.0, 0.0);
        mPanel->setDimensions(1.0, 1.0);
#ifdef OGRE_IS_IOS
        mPanel->setMaterialName( "OGK/SceneTransitionMaterial" );
#else
        mPanel->setMaterialName( kTransitionMaterialName );
#endif
//        mPanel->setMaterialName( "OGK/Debug/Yellow" );
//        mPanel->setMaterialName( "BaseWhiteNoLighting" );
        mOverlay->add2D(mPanel);
        mOverlay->show();
    }
}
Exemple #6
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 "mainwindow.h"
#include "Editor_dockwidget.h"
#include "constants.h"
#include "sme_asset_material.h"
#include "sme_node_material.h"
#include "sme_asset_technique.h"
#include "sme_node_technique.h"
#include "sme_asset_pass.h"
#include "sme_node_pass.h"
#include "sme_asset_texture_unit.h"
#include "sme_node_texture_unit.h"

//****************************************************************************/
EditorDockWidget::EditorDockWidget(QString title, MainWindow* parent, Qt::WindowFlags flags) : 
	QDockWidget (title, parent, flags), 
	mParent(parent)
{
    mInnerMain = new QMainWindow();
    setWidget(mInnerMain);

    // Perform standard functions
    createActions();
    createMenus();
    createToolBars();

    // Create the node editor widget.
    mNodeEditor = new Magus::QtNodeEditor(this);
    mNodeEditor->setMenuSelectionToCompoundEnabled(false); // Enabling this makes it a bit more complicated
    mNodeEditor->setMenuExpandCompoundsEnabled(false); // No compounds are used
    connect(mNodeEditor, SIGNAL(nodeRemoved(QtNode*)), this, SLOT(nodeDeleted()));
    connect(mNodeEditor, SIGNAL(nodeSelected(QtNode*)), this, SLOT(nodeSelected(QtNode*)));
    mInnerMain->setCentralWidget(mNodeEditor);
    mMaterialNode = 0;
}

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

//****************************************************************************/
void EditorDockWidget::createActions(void)
{
    mMaterialHToolbarAction = new QAction(QIcon(ICON_MATERIAL), QString("Add a material node to the editor"), this);
    connect(mMaterialHToolbarAction, SIGNAL(triggered()), this, SLOT(doMaterialHToolbarAction()));
    mTechniqueHToolbarAction = new QAction(QIcon(ICON_TECHNIQUE), QString("Add a technique node to the editor"), this);
    connect(mTechniqueHToolbarAction, SIGNAL(triggered()), this, SLOT(doTechniqueHToolbarAction()));
    mPassHToolbarAction = new QAction(QIcon(ICON_PASS), QString("Add a pass node to the editor"), this);
    connect(mPassHToolbarAction, SIGNAL(triggered()), this, SLOT(doPassHToolbarAction()));
    mTextureHToolbarAction = new QAction(QIcon(ICON_TEXTURE), QString("Add a texture unit node to the editor"), this);
    connect(mTextureHToolbarAction, SIGNAL(triggered()), this, SLOT(doTextureHToolbarAction()));
    mCogHToolbarAction = new QAction(QIcon(ICON_COG), QString("Generate material"), this);
    connect(mCogHToolbarAction, SIGNAL(triggered()), this, SLOT(doCogHToolbarAction()));
}

//****************************************************************************/
void EditorDockWidget::createMenus(void)
{

}

//****************************************************************************/
void EditorDockWidget::createToolBars(void)
{
    mHToolBar = new QToolBar();
    mInnerMain->addToolBar(Qt::TopToolBarArea, mHToolBar);
    mHToolBar->setMinimumHeight(TB_ICON_AND_SPACING);
    mHToolBar->setMinimumWidth(1200);
    mHToolBar->addAction(mMaterialHToolbarAction);
    mHToolBar->addAction(mTechniqueHToolbarAction);
    mHToolBar->addAction(mPassHToolbarAction);
    mHToolBar->addAction(mTextureHToolbarAction);
    mHToolBar->addAction(mCogHToolbarAction);
}

//****************************************************************************/
void EditorDockWidget::doMaterialHToolbarAction(void)
{
    // Add a material node; only 1 is allowed
    if (!mMaterialNode)
    {
        mMaterialNode = new Magus::QtNodeMaterial(NODE_TITLE_MATERIAL);
        mNodeEditor->addNode(mMaterialNode);
    }
}

//****************************************************************************/
void EditorDockWidget::doTechniqueHToolbarAction(void)
{
    // Add a technique node
    Magus::QtNodeTechnique* techniqueNode = new Magus::QtNodeTechnique(NODE_TITLE_TECHNIQUE);
    mNodeEditor->addNode(techniqueNode);
}

//****************************************************************************/
void EditorDockWidget::doPassHToolbarAction(void)
{
    // Add a pass node
    Magus::QtNodePass* passNode = new Magus::QtNodePass(NODE_TITLE_PASS);
    mNodeEditor->addNode(passNode);
}

//****************************************************************************/
void EditorDockWidget::doTextureHToolbarAction(void)
{
    // Add a texture unit node
    Magus::QtNodeTextureUnit* textureUnitNode = new Magus::QtNodeTextureUnit(NODE_TITLE_TEXTURE_UNIT);
    mNodeEditor->addNode(textureUnitNode);
}

//****************************************************************************/
void EditorDockWidget::doCogHToolbarAction(void)
{
    if (!mMaterialNode)
        return;

    if (mMaterialNode->getMaterialName().isEmpty())
        return;

    // ---------------------------------------- Create a material ----------------------------------------
    Ogre::LogManager* logManager = Ogre::LogManager::getSingletonPtr();
    Ogre::MaterialManager* materialManager = Ogre::MaterialManager::getSingletonPtr();
    Ogre::String materialName = mMaterialNode->getMaterialName().toStdString(); // Convert to std format
    logManager->logMessage("SME: create Ogre material: " + materialName);
    Ogre::MaterialPtr material = materialManager->create(materialName, "General");

    // Remark: Sceneblending is done for each pass individually, although it is defined on material level

    // ---------------------------------------- Add the technique ----------------------------------------
    Magus::QtNode* node = mMaterialNode->getNodeConnectedToPort(PORT_TECHNIQUE_OUT);
    if (!node)
    {
        logManager->logMessage("SME: No technique node available");
        return;
    }

    Magus::QtNodeTechnique* techniqueNode = static_cast<Magus::QtNodeTechnique*>(node);
    material->removeAllTechniques();
    Ogre::Technique* technique = material->createTechnique();
    technique->removeAllPasses();
    logManager->logMessage("SME: Technique created" + Ogre::StringConverter::toString(material->getNumTechniques()));

    // ---------------------------------------- Add the passes ----------------------------------------
    Magus::QtNodePass* passNode;
    Magus::QtNodeTextureUnit* textureUnitNode;
    Ogre::Pass* pass;
    Ogre::TextureUnitState* textureUnit;
    for (unsigned int i = 1; i < 5; ++i)
    {
        node = techniqueNode->getNodeConnectedToPort(PORT_PASS_OUT, i); // node with the same name
        if (node)
        {
            passNode = static_cast<Magus::QtNodePass*>(node);
            pass = technique->createPass();
            pass->removeAllTextureUnitStates();
            logManager->logMessage("SME: Pass on port nr. " + Ogre::StringConverter::toString(i) + " created");
            propagatePassNodeData(passNode, pass);

            // ---------------------------------------- Add the texture units ----------------------------------------
            for (unsigned int j = 1; j < 9; ++j)
            {
                node = passNode->getNodeConnectedToPort(PORT_TEXTURE_OUT, j);
                if (node)
                {
                    logManager->logMessage("SME: Texture unit on port nr. " +
                                           Ogre::StringConverter::toString(j) +
                                           " of Pass port nr. " +
                                           Ogre::StringConverter::toString(i) +
                                           " created");
                    textureUnitNode = static_cast<Magus::QtNodeTextureUnit*>(node);
                    textureUnit = pass->createTextureUnitState();
                    propagateTextureUnitNodeData(textureUnitNode, textureUnit);
                }
            }
        }
    }

    // Assign the material to the ogrehead
    material->compile();
    material->load();
    mParent->getOgreManager()->getOgreWidget(1)->mEntity->setMaterial(material);
}