Added a Nel3D proxy class.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 8c35946010
commit 30f8c9f9e1

@ -73,6 +73,7 @@ namespace NL3D
CDynMaterial();
~CDynMaterial();
void serial( NLMISC::IStream &f );
std::string getClassName(){ return "CDynMaterial"; }
void addPass( const SRenderPass &pass );
void removePass( const std::string &name );

@ -19,6 +19,7 @@
#include "material_widget.h"
#include "shader_widget.h"
#include "render_passes.h"
#include "nel3d_interface.h"
#include "../core/icore.h"
#include "../core/core_constants.h"
@ -29,6 +30,7 @@
#include <QDockWidget>
#include <QFileDialog>
#include <QMessageBox>
namespace MaterialEditor
{
@ -36,6 +38,7 @@ namespace MaterialEditor
QMainWindow(parent)
{
m_ui.setupUi(this);
nl3dIface = new Nel3DInterface();
shaderWidget = new ShaderWidget();
passesWidget = new RenderPassesWidget();
createMenus();
@ -48,6 +51,8 @@ namespace MaterialEditor
shaderWidget = NULL;
delete passesWidget;
passesWidget = NULL;
delete nl3dIface;
nl3dIface = NULL;
}
void MaterialEditorWindow::onOpenClicked()
@ -64,6 +69,7 @@ namespace MaterialEditor
void MaterialEditorWindow::onNewMaterialClicked()
{
nl3dIface->newMaterial();
}
void MaterialEditorWindow::onOpenMaterialClicked()
@ -74,6 +80,20 @@ namespace MaterialEditor
"/",
tr( "Material files ( *.nelmat )" )
);
if( fn.isEmpty() )
return;
bool ok = nl3dIface->loadMaterial( fn.toUtf8().data() );
if( !ok )
{
QMessageBox::critical(
this,
tr( "Error opening material file" ),
tr( "There was an error while trying to open the material file specified!" ),
QMessageBox::Ok
);
}
}
void MaterialEditorWindow::onSaveMaterialClicked()
@ -84,6 +104,21 @@ namespace MaterialEditor
"/",
tr( "Material files ( *.nelmat )" )
);
if( fn.isEmpty() )
return;
bool ok = nl3dIface->saveMaterial( fn.toUtf8().data() );
if( !ok )
{
QMessageBox::critical(
this,
tr( "Error saving material file" ),
tr( "There was an error while trying to open the material file specified!" ),
QMessageBox::Ok
);
}
}
void MaterialEditorWindow::onShadersClicked()

@ -24,6 +24,7 @@ namespace MaterialEditor
class ShaderWidget;
class RenderPassesWidget;
class Nel3DInterface;
class MaterialEditorWindow: public QMainWindow
{
@ -45,6 +46,8 @@ private:
void createMenus();
void createDockWidgets();
Nel3DInterface *nl3dIface;
ShaderWidget *shaderWidget;
RenderPassesWidget *passesWidget;

@ -0,0 +1,74 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "nel3d_interface.h"
#include "nel/3d/dynamic_material.h"
#include "nel/misc/i_xml.h"
#include "nel/misc/o_xml.h"
#include "nel/misc/file.h"
namespace MaterialEditor
{
Nel3DInterface::Nel3DInterface()
{
mat = new NL3D::CDynMaterial();
}
Nel3DInterface::~Nel3DInterface()
{
}
bool Nel3DInterface::loadMaterial( const char *fname )
{
NLMISC::CIFile file;
if( !file.open( fname, true ) )
return false;
NLMISC::CIXml xml;
if( !xml.init( file ) )
return false;
newMaterial();
mat->serial( xml );
file.close();
return true;
}
bool Nel3DInterface::saveMaterial( const char *fname )
{
NLMISC::COFile file;
if( !file.open( fname, false, true ) )
return false;
NLMISC::COXml xml;
if( !xml.init( &file ) )
return false;
mat->serial( xml );
xml.flush();
file.close();
return true;
}
void Nel3DInterface::newMaterial()
{
delete mat;
mat = new NL3D::CDynMaterial();
}
}

@ -0,0 +1,47 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef NEL3D_INTERFACE_H
#define NEL3D_INTERFACE_H
namespace NL3D
{
class CDynMaterial;
}
namespace MaterialEditor
{
/// Proxy class for Nel3D, so the material editor and Nel3D can interface
class Nel3DInterface
{
public:
Nel3DInterface();
~Nel3DInterface();
bool loadMaterial( const char *fname );
bool saveMaterial( const char *fname );
void newMaterial();
private:
NL3D::CDynMaterial *mat;
};
}
#endif
Loading…
Cancel
Save