Esempio n. 1
0
    //-----------------------------------------------------------------------------------
    void HlmsManager::saveMaterial( const HlmsDatablock *datablock, const String &filename )
    {
        String jsonString;
        HlmsJson hlmsJson( this );
        hlmsJson.saveMaterial( datablock, jsonString );

        std::ofstream file( filename.c_str(), std::ios::binary | std::ios::out );
        if( file.is_open() )
            file.write( jsonString.c_str(), jsonString.size() );
        file.close();
    }
Esempio n. 2
0
    //-----------------------------------------------------------------------------------
    void HlmsManager::parseScript(DataStreamPtr& stream, const String& groupName)
    {
        vector<char>::type fileData;
        fileData.resize( stream->size() + 1 );
        if( !fileData.empty() )
        {
            stream->read( &fileData[0], stream->size() );

            //Add null terminator just in case (to prevent bad input)
            fileData.back() = '\0';
            HlmsJson hlmsJson( this );
            hlmsJson.loadMaterials( stream->getName(), groupName, &fileData[0] );
        }
    }
Esempio n. 3
0
    //-----------------------------------------------------------------------------------
    void HlmsManager::saveMaterials( HlmsTypes hlmsType, const String &filename )
    {
        assert( hlmsType != HLMS_MAX );
        assert( hlmsType != HLMS_LOW_LEVEL );

        String jsonString;
        HlmsJson hlmsJson( this );
        hlmsJson.saveMaterials( mRegisteredHlms[hlmsType], jsonString );

        std::ofstream file( filename.c_str(), std::ios::binary | std::ios::out );
        if( file.is_open() )
            file.write( jsonString.c_str(), jsonString.size() );
        file.close();
    }
Esempio n. 4
0
    //-----------------------------------------------------------------------------------
    void HlmsManager::loadMaterials( const String &filename, const String &groupName )
    {
        DataStreamPtr stream = ResourceGroupManager::getSingleton().openResource( filename, groupName );

        vector<char>::type fileData;
        fileData.resize( stream->size() + 1 );
        if( !fileData.empty() )
        {
            stream->read( &fileData[0], stream->size() );

            //Add null terminator just in case (to prevent bad input)
            fileData.back() = '\0';
            HlmsJson hlmsJson( this );
            hlmsJson.loadMaterials( stream->getName(), groupName, &fileData[0] );
        }
    }
Esempio n. 5
0
/****************************************************************************
**
** Copyright (C) 2016
**
** 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 "constants.h"
#include <QString>
#include <QFile>
#include <QTextStream>
#include <QMenuBar>
#include "mainwindow.h"
#include "OgreItem.h"
#include "OgreHlmsPbs.h"
#include "OgreHlmsUnlit.h"
#include "OgreHlmsPbsDatablock.h"
#include "OgreHlmsUnlitDatablock.h"
#include "OgreHlmsManager.h"

//****************************************************************************/
MainWindow::MainWindow(void) :
    mIsClosing(false),
    mFirst(true)
{
    installEventFilter(this);

    // Create the Ogre Manager
    mOgreManager = new Magus::OgreManager();
    mHlmsName = QString("");
    mTempString = QString("");
    
	// Perform standard functions
    createActions();
    createMenus();
    createToolBars();
    createStatusBar();
    createDockWindows();
    mMaterialBrowser = new MaterialBrowserDialog(this);
    loadMaterialBrowserCfg();

    mOgreManager->initialize();

    // Set the title
    setWindowTitle(QString("HLMS editor"));

    // Set the stylesheet of the application
    QFile File(QString("dark.qss"));
    File.open(QFile::ReadOnly);
    QString styleSheet = QLatin1String(File.readAll());
    setStyleSheet(styleSheet);
	showMaximized();
}

//****************************************************************************/
MainWindow::~MainWindow(void)
{
    delete mOgreManager;
}

//****************************************************************************/
bool MainWindow::eventFilter(QObject* object, QEvent* event)
{
    if (event->type()==QEvent::KeyPress)
    {
        QKeyEvent* key = static_cast<QKeyEvent*>(event);
        if (key->key() == Qt::Key_F5)
        {
            // F5 was pressed
            mNodeEditorDockWidget->generateDatablock();
        }
        if (key->key() == Qt::Key_S && (QApplication::keyboardModifiers() & Qt::ControlModifier))
        {
            // CTRL+S was pressed
            doSaveDatablockMenuAction();
        }
    }
    return QObject::eventFilter(object, event);
}

//****************************************************************************/
void MainWindow::closeEvent(QCloseEvent* event)
{
    mIsClosing = true;
}

//****************************************************************************/
void MainWindow::createActions(void)
{
    // File menu
    mNewHlmsPbsAction = new QAction(QString("Pbs"), this);
    connect(mNewHlmsPbsAction, SIGNAL(triggered()), this, SLOT(doNewHlmsPbsAction()));
    mNewHlmsUnlitAction = new QAction(QString("Unlit"), this);
    connect(mNewHlmsUnlitAction, SIGNAL(triggered()), this, SLOT(doNewHlmsUnlitAction()));
    mOpenDatablockMenuAction = new QAction(QString("Open Hlms"), this);
    connect(mOpenDatablockMenuAction, SIGNAL(triggered()), this, SLOT(doOpenDatablockMenuAction()));
    mSaveDatablockMenuAction = new QAction(QString("Save Hlms"), this);
    connect(mSaveDatablockMenuAction, SIGNAL(triggered()), this, SLOT(doSaveDatablockMenuAction()));
    mSaveAsDatablockMenuAction = new QAction(QString("Save Hlms as"), this);
    connect(mSaveAsDatablockMenuAction, SIGNAL(triggered()), this, SLOT(doSaveAsDatablockMenuAction()));
    mQuitMenuAction = new QAction(QString("Quit"), this);
    connect(mQuitMenuAction, SIGNAL(triggered()), this, SLOT(doQuitMenuAction()));

    // Materials menu
    mMaterialBrowserOpenMenuAction = new QAction(QString("Open browser"), this);
    connect(mMaterialBrowserOpenMenuAction, SIGNAL(triggered()), this, SLOT(doMaterialBrowserOpenMenuAction()));
    mMaterialBrowserAddMenuAction = new QAction(QString("Add Hlms to browser"), this);
    connect(mMaterialBrowserAddMenuAction, SIGNAL(triggered()), this, SLOT(doMaterialBrowserAddMenuAction()));

    // Window menu
    mResetWindowLayoutMenuAction = new QAction(QString("Reset Window Layout"), this);
    connect(mResetWindowLayoutMenuAction, SIGNAL(triggered()), this, SLOT(doResetWindowLayoutMenuAction()));
}

//****************************************************************************/
void MainWindow::createMenus(void)
{
    mFileMenu = menuBar()->addMenu(QString("&File"));
    mMaterialBrowserMenu = menuBar()->addMenu(QString("&Materials"));
    QMenu* fileMenuAction = mFileMenu->addMenu("New Hlms");
    fileMenuAction->addAction(mNewHlmsPbsAction);
    fileMenuAction->addAction(mNewHlmsUnlitAction);
    mFileMenu->addAction(mOpenDatablockMenuAction);
    mFileMenu->addAction(mSaveDatablockMenuAction);
    mFileMenu->addAction(mSaveAsDatablockMenuAction);
    mFileMenu->addAction(mQuitMenuAction);
    mMaterialBrowserMenu->addAction(mMaterialBrowserOpenMenuAction);
    mMaterialBrowserMenu->addAction(mMaterialBrowserAddMenuAction);
    mWindowMenu = menuBar()->addMenu(QString("&Window"));
    mWindowMenu->addAction(mResetWindowLayoutMenuAction);

}

//****************************************************************************/
void MainWindow::createToolBars(void)
{

}

//****************************************************************************/
void MainWindow::createStatusBar(void)
{

}

//****************************************************************************/
void MainWindow::createDockWindows(void)
{
    mRenderwindowDockWidget = new RenderwindowDockWidget("Renderwindow", this);
    addDockWidget(Qt::LeftDockWidgetArea, mRenderwindowDockWidget);
    mPropertiesDockWidget = new PropertiesDockWidget("Properties", this);
    addDockWidget(Qt::LeftDockWidgetArea, mPropertiesDockWidget);
    mNodeEditorDockWidget = new NodeEditorDockWidget("NodeEditor", this);
    setCentralWidget(mNodeEditorDockWidget);
}

//****************************************************************************/
void MainWindow::doNewHlmsPbsAction(void)
{
    initDatablocks();
    mPropertiesDockWidget->clear();
    mNodeEditorDockWidget->newHlmsPbsAndSampler();
}

//****************************************************************************/
void MainWindow::doNewHlmsUnlitAction(void)
{
    initDatablocks();
    mPropertiesDockWidget->clear();
    mNodeEditorDockWidget->newHlmsUnlitAndSampler();
}

//****************************************************************************/
void MainWindow::doOpenDatablockMenuAction(void)
{
    // Load the materials
    QString fileName;
    fileName = QFileDialog::getOpenFileName(this, QString("Open Hlms file"),
                                            QString(""),
                                            QString("Json material (*.json)"));
    loadDatablock(fileName);
}

//****************************************************************************/
void MainWindow::loadDatablock(const QString jsonFileName)
{
    // Load the materials
    if (!jsonFileName.isEmpty())
    {
        // Read the json file as text file and feed it to the HlmsManager::loadMaterials() function
        // Note, that the resources (textures, etc.) must be present

        // First, delete all datablocks before loading the new ones
        initDatablocks();
        mPropertiesDockWidget->clear();

        // Read the json file
        Ogre::HlmsManager* hlmsManager = mOgreManager->getOgreRoot()->getHlmsManager();
        QFile file(jsonFileName);
        file.open(QFile::ReadOnly | QFile::Text);
        QTextStream readFile(&file);
        QString jsonString = readFile.readAll();
        QByteArray ba = jsonString.toLatin1();
        char* jsonChar = ba.data();
        Ogre::String fname = jsonFileName.toStdString();
        Ogre::HlmsJson hlmsJson(hlmsManager);
        try
        {
            // Load the datablocks (which also creates them)
            hlmsJson.loadMaterials(fname, jsonChar);
        }
        catch (Ogre::Exception e)
        {
            Ogre::LogManager::getSingleton().logMessage("MainWindow::doOpenDatablockMenuAction(); Could not load the materials\n");
        }
        file.close();
        mHlmsName = jsonFileName;

        // Get the (list of) datablocks and assign the first one to the current 'item' to be rendered
        getAndSetFirstDatablock();
    }
}