From 94fe455a1a8e56cde87689f2a58bb665bdab99cf Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Tue, 2 Jul 2013 03:10:34 +0200 Subject: [PATCH] Material widget now retrieves the passes when loading a material. --HG-- branch : gsoc2013-dfighter --- code/nel/include/nel/3d/dynamic_material.h | 1 + code/nel/src/3d/dynamic_material.cpp | 66 +++++++++++++++++-- .../material_editor_window.cpp | 10 ++- .../material_editor/material_editor_window.h | 2 + .../material_editor/material_observer.h | 3 + .../material_editor/material_widget.cpp | 23 +++++++ .../plugins/material_editor/material_widget.h | 7 ++ .../material_editor/nel3d_interface.cpp | 5 ++ .../plugins/material_editor/nel3d_interface.h | 5 ++ 9 files changed, 113 insertions(+), 9 deletions(-) diff --git a/code/nel/include/nel/3d/dynamic_material.h b/code/nel/include/nel/3d/dynamic_material.h index d00a56a0d..6a71e3ca0 100644 --- a/code/nel/include/nel/3d/dynamic_material.h +++ b/code/nel/include/nel/3d/dynamic_material.h @@ -82,6 +82,7 @@ namespace NL3D void movePassDown( const std::string &name ); SRenderPass* getPass( const std::string &name ); + void getPassList( std::vector< std::string > &l ); private: std::vector< SRenderPass* > passes; diff --git a/code/nel/src/3d/dynamic_material.cpp b/code/nel/src/3d/dynamic_material.cpp index 0e4a58ce3..c875f0d49 100644 --- a/code/nel/src/3d/dynamic_material.cpp +++ b/code/nel/src/3d/dynamic_material.cpp @@ -20,20 +20,43 @@ namespace NL3D { void SDynMaterialProp::serial( NLMISC::IStream &f ) { - f.serial( std::string( prop ) ); - f.serial( std::string( label ) ); - f.serial( uint8( type ) ); - f.serial( std::string( value ) ); + f.xmlPush( "property" ); + + f.xmlPush( "id" ); + f.serial( prop ); + f.xmlPop(); + + f.xmlPush( "label" ); + f.serial( label ); + f.xmlPop(); + + f.xmlPush( "type" ); + f.serial( type ); + f.xmlPop(); + + f.xmlPush( "value" ); + f.serial( value ); + f.xmlPop(); + + f.xmlPop(); } void SRenderPass::serial( NLMISC::IStream &f ) { - f.serial( std::string( name ) ); + f.xmlPush( "pass" ); + + f.xmlPush( "name" ); + f.serial( name ); + f.xmlPop(); + + f.xmlPush( "properties" ); if( !f.isReading() ) { uint32 n = properties.size(); + f.xmlPush( "count" ); f.serial( n ); + f.xmlPop(); std::vector< SDynMaterialProp >::iterator itr = properties.begin(); while( itr != properties.end() ) @@ -45,7 +68,9 @@ namespace NL3D else { uint32 n; + f.xmlPush( "count" ); f.serial( n ); + f.xmlPop(); for( uint32 i = 0; i < n; i++ ) { @@ -55,6 +80,9 @@ namespace NL3D } } + f.xmlPop(); + + f.xmlPop(); } void SRenderPass::addProperty( const SDynMaterialProp &prop ) @@ -124,12 +152,18 @@ namespace NL3D void CDynMaterial::serial( NLMISC::IStream &f ) { + f.xmlPush( "Material" ); + int version = f.serialVersion( 1 ); + f.xmlPush( "passes" ); + if( !f.isReading() ) { uint32 n = passes.size(); + f.xmlPush( "count" ); f.serial( n ); + f.xmlPop(); std::vector< SRenderPass* >::iterator itr = passes.begin(); while( itr != passes.end() ) @@ -141,15 +175,21 @@ namespace NL3D else { uint32 n; + f.xmlPush( "count" ); f.serial( n ); + f.xmlPop(); - for( uint32 i = 0; i < n; n++ ) + for( uint32 i = 0; i < n; i++ ) { SRenderPass *pass = new SRenderPass(); pass->serial( f ); passes.push_back( pass ); } } + + f.xmlPop(); + + f.xmlPop(); } void CDynMaterial::addPass( const SRenderPass &pass ) @@ -269,6 +309,20 @@ namespace NL3D else return *itr; } + + void CDynMaterial::getPassList( std::vector< std::string > &l ) + { + std::vector< SRenderPass* >::iterator itr = passes.begin(); + while( itr != passes.end() ) + { + std::string name; + + (*itr)->getName( name ); + l.push_back( name ); + + ++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 0268ad3e6..c494105b6 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 @@ -39,9 +39,11 @@ namespace MaterialEditor { m_ui.setupUi(this); nl3dIface = new CNel3DInterface(); + materialWidget = new MaterialWidget(); shaderWidget = new ShaderWidget(); passesWidget = new RenderPassesWidget(); passesWidget->setNel3dIface( nl3dIface ); + materialWidget->setNel3DIface( nl3dIface ); createMenus(); createDockWidgets(); @@ -72,6 +74,7 @@ namespace MaterialEditor void MaterialEditorWindow::onNewMaterialClicked() { nl3dIface->newMaterial(); + materialWidget->onNewMaterial(); } void MaterialEditorWindow::onOpenMaterialClicked() @@ -96,6 +99,8 @@ namespace MaterialEditor QMessageBox::Ok ); } + + materialWidget->onMaterialLoaded(); } void MaterialEditorWindow::onSaveMaterialClicked() @@ -173,9 +178,8 @@ namespace MaterialEditor QDockWidget *dock = new QDockWidget( tr( "Material" ), this ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); - MaterialWidget *mw = new MaterialWidget(); - passesWidget->setMaterialObserver( mw ); - dock->setWidget( mw ); + passesWidget->setMaterialObserver( materialWidget ); + dock->setWidget( materialWidget ); addDockWidget( Qt::RightDockWidgetArea, dock ); } 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 1235a376c..f032863b8 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 @@ -25,6 +25,7 @@ namespace MaterialEditor class ShaderWidget; class RenderPassesWidget; class CNel3DInterface; + class MaterialWidget; class MaterialEditorWindow: public QMainWindow { @@ -50,6 +51,7 @@ private: ShaderWidget *shaderWidget; RenderPassesWidget *passesWidget; + MaterialWidget *materialWidget; Ui::MaterialEditorWindow m_ui; }; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_observer.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_observer.h index 7f28b0b8b..e73c40aab 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_observer.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_observer.h @@ -25,6 +25,9 @@ namespace MaterialEditor public: CMaterialObserver(){} virtual ~CMaterialObserver(){} + + virtual void onNewMaterial() = 0; + virtual void onMaterialLoaded() = 0; virtual void onPassAdded( const char *name ) = 0; virtual void onPassRemoved( const char *name ) = 0; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp index e97836222..c97c61dfd 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.cpp @@ -17,6 +17,7 @@ #include "material_widget.h" #include "shader_editor.h" #include "material_properties.h" +#include "nel3d_interface.h" namespace MaterialEditor { @@ -38,6 +39,28 @@ namespace MaterialEditor matPropWidget = NULL; } + void MaterialWidget::onNewMaterial() + { + passCB->clear(); + } + + void MaterialWidget::onMaterialLoaded() + { + CNelMaterialProxy mat = this->nl3dIface->getMaterial(); + + std::vector< std::string > l; + mat.getPassList( l ); + + passCB->clear(); + + std::vector< std::string >::const_iterator itr = l.begin(); + while( itr != l.end() ) + { + passCB->addItem( itr->c_str() ); + ++itr; + } + } + void MaterialWidget::onPassAdded( const char *name ) { passCB->addItem( name ); diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h index a7e3a365d..fef1d840a 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_widget.h @@ -24,6 +24,7 @@ namespace MaterialEditor { class ShaderEditorWidget; class MatPropWidget; + class CNel3DInterface; class MaterialWidget : public QWidget, public Ui::MaterialWidget, public CMaterialObserver { @@ -32,16 +33,22 @@ namespace MaterialEditor MaterialWidget( QWidget *parent = NULL ); ~MaterialWidget(); + void onNewMaterial(); + void onMaterialLoaded(); + void onPassAdded( const char *name ); void onPassRemoved( const char *name ); void onPassMovedUp( const char *name ); void onPassMovedDown( const char *name ); void onPassRenamed( const char *from, const char *to ); + void setNel3DIface( CNel3DInterface *iface ){ nl3dIface = iface; } + private: void setupConnections(); ShaderEditorWidget *shaderEditorWidget; MatPropWidget *matPropWidget; + CNel3DInterface *nl3dIface; private Q_SLOTS: void onPassEditClicked(); 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 d69effcde..e605ed250 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,6 +22,11 @@ namespace MaterialEditor { + void CNelMaterialProxy::getPassList( std::vector< std::string > &l ) + { + material->getPassList( l ); + } + void CNelMaterialProxy::addPass( const char *name ) { NL3D::SRenderPass pass; 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 27f5ca4bf..1e3142545 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 @@ -18,6 +18,9 @@ #ifndef NEL3D_INTERFACE_H #define NEL3D_INTERFACE_H +#include +#include + namespace NL3D { class CDynMaterial; @@ -35,6 +38,8 @@ namespace MaterialEditor ~CNelMaterialProxy(){} + void getPassList( std::vector< std::string > &l ); + void addPass( const char *name ); void removePass( const char *name ); void movePassUp( const char *name );