diff --git a/code/nel/include/nel/3d/dynamic_material.h b/code/nel/include/nel/3d/dynamic_material.h index 904f56d02..d00a56a0d 100644 --- a/code/nel/include/nel/3d/dynamic_material.h +++ b/code/nel/include/nel/3d/dynamic_material.h @@ -77,10 +77,14 @@ namespace NL3D void addPass( const SRenderPass &pass ); void removePass( const std::string &name ); + void renamePass( const std::string &from, const std::string &to ); + void movePassUp( const std::string &name ); + void movePassDown( const std::string &name ); + SRenderPass* getPass( const std::string &name ); private: - std::vector< SRenderPass > passes; + std::vector< SRenderPass* > passes; }; } diff --git a/code/nel/src/3d/dynamic_material.cpp b/code/nel/src/3d/dynamic_material.cpp index 875992773..0e4a58ce3 100644 --- a/code/nel/src/3d/dynamic_material.cpp +++ b/code/nel/src/3d/dynamic_material.cpp @@ -32,6 +32,9 @@ namespace NL3D if( !f.isReading() ) { + uint32 n = properties.size(); + f.serial( n ); + std::vector< SDynMaterialProp >::iterator itr = properties.begin(); while( itr != properties.end() ) { @@ -41,9 +44,15 @@ namespace NL3D } else { - SDynMaterialProp prop; - prop.serial( f ); - properties.push_back( prop ); + uint32 n; + f.serial( n ); + + for( uint32 i = 0; i < n; i++ ) + { + SDynMaterialProp prop; + prop.serial( f ); + properties.push_back( prop ); + } } } @@ -104,6 +113,13 @@ namespace NL3D CDynMaterial::~CDynMaterial() { + std::vector< SRenderPass* >::iterator itr = passes.begin(); + while( itr != passes.end() ) + { + delete *itr; + ++itr; + } + passes.clear(); } void CDynMaterial::serial( NLMISC::IStream &f ) @@ -112,18 +128,27 @@ namespace NL3D if( !f.isReading() ) { - std::vector< SRenderPass >::iterator itr = passes.begin(); + uint32 n = passes.size(); + f.serial( n ); + + std::vector< SRenderPass* >::iterator itr = passes.begin(); while( itr != passes.end() ) { - itr->serial( f ); + (*itr)->serial( f ); ++itr; } } else { - SRenderPass pass; - pass.serial( f ); - passes.push_back( pass ); + uint32 n; + f.serial( n ); + + for( uint32 i = 0; i < n; n++ ) + { + SRenderPass *pass = new SRenderPass(); + pass->serial( f ); + passes.push_back( pass ); + } } } @@ -133,10 +158,10 @@ namespace NL3D std::string name; pass.getName( name ); - std::vector< SRenderPass >::iterator itr = passes.begin(); + std::vector< SRenderPass* >::iterator itr = passes.begin(); while( itr != passes.end() ) { - itr->getName( n ); + (*itr)->getName( n ); if( n == name ) break; ++itr; @@ -144,32 +169,97 @@ namespace NL3D if( itr != passes.end() ) return; - passes.push_back( pass ); + SRenderPass *p = new SRenderPass(); + *p = pass; + passes.push_back( p ); } void CDynMaterial::removePass( const std::string &name ) { std::string n; - std::vector< SRenderPass >::iterator itr = passes.begin(); + std::vector< SRenderPass* >::iterator itr = passes.begin(); while( itr != passes.end() ) { - itr->getName( n ); + (*itr)->getName( n ); if( n == name ) break; ++itr; } if( itr != passes.end() ) + { + delete *itr; passes.erase( itr ); + } + } + + void CDynMaterial::renamePass( const std::string &from, const std::string &to ) + { + std::string n; + std::vector< SRenderPass* >::iterator itr = passes.begin(); + while( itr != passes.end() ) + { + (*itr)->getName( n ); + if( n == from ) + break; + ++itr; + } + + if( itr != passes.end() ) + (*itr)->setName( to ); + } + + void CDynMaterial::movePassUp( const std::string &name ) + { + std::string n; + uint32 i = 0; + for( i = 0; i < passes.size(); i++ ) + { + passes[ i ]->getName( n ); + if( n == name ) + break; + } + + if( i >= passes.size() ) + return; + + if( i == 0 ) + return; + + SRenderPass *temp = passes[ i ]; + passes[ i ] = passes[ i - 1 ]; + passes[ i - 1 ] = temp; + } + + void CDynMaterial::movePassDown( const std::string &name ) + { + std::string n; + uint32 i = 0; + for( i = 0; i < passes.size(); i++ ) + { + passes[ i ]->getName( n ); + if( n == name ) + break; + } + + if( i >= passes.size() ) + return; + + if( i == ( passes.size() - 1 ) ) + return; + + SRenderPass *temp = passes[ i ]; + passes[ i ] = passes[ i + 1 ]; + passes[ i + 1 ] = temp; } SRenderPass* CDynMaterial::getPass( const std::string &name ) { std::string n; - std::vector< SRenderPass >::iterator itr = passes.begin(); + std::vector< SRenderPass* >::iterator itr = passes.begin(); while( itr != passes.end() ) { - itr->getName( n ); + (*itr)->getName( n ); if( n == name ) break; ++itr; @@ -177,7 +267,7 @@ namespace NL3D if( itr == passes.end() ) return NULL; else - return &( *itr ); + return *itr; } } 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 6e974d8c9..9e3f6d36a 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 @@ -38,9 +38,11 @@ namespace MaterialEditor QMainWindow(parent) { m_ui.setupUi(this); - nl3dIface = new Nel3DInterface(); + nl3dIface = new CNel3DInterface(); shaderWidget = new ShaderWidget(); passesWidget = new RenderPassesWidget(); + passesWidget->setNel3dIface( nl3dIface ); + createMenus(); createDockWidgets(); } 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 63c4d6f1e..1235a376c 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,7 +24,7 @@ namespace MaterialEditor class ShaderWidget; class RenderPassesWidget; - class Nel3DInterface; + class CNel3DInterface; class MaterialEditorWindow: public QMainWindow { @@ -46,7 +46,7 @@ private: void createMenus(); void createDockWidgets(); - Nel3DInterface *nl3dIface; + CNel3DInterface *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 index 624177bf5..d69effcde 100644 --- 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 @@ -22,16 +22,47 @@ namespace MaterialEditor { - Nel3DInterface::Nel3DInterface() + void CNelMaterialProxy::addPass( const char *name ) + { + NL3D::SRenderPass pass; + pass.setName( name ); + material->addPass( pass ); + } + + void CNelMaterialProxy::removePass( const char *name ) + { + material->removePass( name ); + } + + void CNelMaterialProxy::movePassUp( const char *name ) + { + material->movePassUp( name ); + } + + void CNelMaterialProxy::movePassDown( const char *name ) + { + material->movePassDown( name ); + } + + void CNelMaterialProxy::renamePass( const char *from, const char *to ) + { + material->renamePass( from, to ); + } + + + + + + CNel3DInterface::CNel3DInterface() { mat = new NL3D::CDynMaterial(); } - Nel3DInterface::~Nel3DInterface() + CNel3DInterface::~CNel3DInterface() { } - bool Nel3DInterface::loadMaterial( const char *fname ) + bool CNel3DInterface::loadMaterial( const char *fname ) { NLMISC::CIFile file; if( !file.open( fname, true ) ) @@ -48,7 +79,7 @@ namespace MaterialEditor return true; } - bool Nel3DInterface::saveMaterial( const char *fname ) + bool CNel3DInterface::saveMaterial( const char *fname ) { NLMISC::COFile file; if( !file.open( fname, false, true ) ) @@ -65,10 +96,15 @@ namespace MaterialEditor return true; } - void Nel3DInterface::newMaterial() + void CNel3DInterface::newMaterial() { delete mat; mat = new NL3D::CDynMaterial(); } + + CNelMaterialProxy CNel3DInterface::getMaterial() + { + return CNelMaterialProxy( mat ); + } } 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 index 9e9d2f4ad..27f5ca4bf 100644 --- 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 @@ -25,17 +25,40 @@ namespace NL3D namespace MaterialEditor { + class CNelMaterialProxy + { + public: + CNelMaterialProxy( NL3D::CDynMaterial *mat ) + { + material = mat; + } + + ~CNelMaterialProxy(){} + + void addPass( const char *name ); + void removePass( const char *name ); + void movePassUp( const char *name ); + void movePassDown( const char *name ); + void renamePass( const char *from, const char *to ); + + private: + NL3D::CDynMaterial *material; + }; + + /// Proxy class for Nel3D, so the material editor and Nel3D can interface - class Nel3DInterface + class CNel3DInterface { public: - Nel3DInterface(); - ~Nel3DInterface(); + CNel3DInterface(); + ~CNel3DInterface(); bool loadMaterial( const char *fname ); bool saveMaterial( const char *fname ); void newMaterial(); + CNelMaterialProxy getMaterial(); + private: NL3D::CDynMaterial *mat; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp index 4c7927ea7..a44dd48c2 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.cpp @@ -15,6 +15,7 @@ // along with this program. If not, see . #include "render_passes.h" +#include "nel3d_interface.h" #include #include @@ -25,6 +26,7 @@ namespace MaterialEditor { setupUi( this ); setupConnections(); + nl3dIface = NULL; } RenderPassesWidget::~RenderPassesWidget() @@ -104,7 +106,9 @@ namespace MaterialEditor } listWidget->addItem( label ); - Q_EMIT passAdded( label ); + + CNelMaterialProxy material = nl3dIface->getMaterial(); + material.addPass( label.toUtf8().data() ); } void RenderPassesWidget::onRemoveClicked() @@ -118,7 +122,8 @@ namespace MaterialEditor pass = item->text(); delete item; - Q_EMIT passRemoved( pass ); + CNelMaterialProxy material = nl3dIface->getMaterial(); + material.removePass( pass.toUtf8().data() ); } void RenderPassesWidget::onEditClicked() @@ -141,8 +146,9 @@ namespace MaterialEditor return; item->setText( to ); - - Q_EMIT passRenamed( from, to ); + + CNelMaterialProxy material = nl3dIface->getMaterial(); + material.renamePass( from.toUtf8().data(), to.toUtf8().data() ); } void RenderPassesWidget::onUpClicked() @@ -161,7 +167,8 @@ namespace MaterialEditor QString s = item->text(); - Q_EMIT passPushedUp( s ); + CNelMaterialProxy material = nl3dIface->getMaterial(); + material.movePassUp( s.toUtf8().data() ); } void RenderPassesWidget::onDownClicked() @@ -179,8 +186,9 @@ namespace MaterialEditor listWidget->setCurrentRow( row + 1 ); QString s = item->text(); - - Q_EMIT passPushedDown( s ); + + CNelMaterialProxy material = nl3dIface->getMaterial(); + material.movePassDown( s.toUtf8().data() ); } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h index 4608484f0..a3748e371 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/render_passes.h @@ -22,6 +22,8 @@ namespace MaterialEditor { + class CNel3DInterface; + class RenderPassesWidget : public QWidget, public Ui::RenderPassesWidget { Q_OBJECT @@ -31,18 +33,13 @@ namespace MaterialEditor void fillList( const QStringList &list ); void getList( QStringList &list ); void clear(); - - Q_SIGNALS: - void okClicked(); - void passAdded( const QString &pass ); - void passRemoved( const QString &pass ); - void passRenamed( const QString &from, const QString &to ); - void passPushedUp( const QString &pass ); - void passPushedDown( const QString &pass ); + void setNel3dIface( CNel3DInterface *iface ){ nl3dIface = iface; } private: void setupConnections(); + CNel3DInterface *nl3dIface; + private Q_SLOTS: void onOKClicked(); void onAddClicked();