diff --git a/code/nel/include/nel/3d/dynamic_material.h b/code/nel/include/nel/3d/dynamic_material.h index 172b14149..904f56d02 100644 --- a/code/nel/include/nel/3d/dynamic_material.h +++ b/code/nel/include/nel/3d/dynamic_material.h @@ -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 ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp index 81163dea1..6e974d8c9 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp @@ -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 #include +#include 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() diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h index 4cb9dcd26..63c4d6f1e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h @@ -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; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp new file mode 100644 index 000000000..624177bf5 --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.cpp @@ -0,0 +1,74 @@ +// Object Viewer Qt Material Editor plugin +// 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 . + +#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(); + } +} + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h new file mode 100644 index 000000000..9e9d2f4ad --- /dev/null +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/nel3d_interface.h @@ -0,0 +1,47 @@ +// Object Viewer Qt Material Editor plugin +// 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 . + + +#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 + +