Material widget now retrieves the passes when loading a material.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 067676c049
commit 94fe455a1a

@ -82,6 +82,7 @@ namespace NL3D
void movePassDown( const std::string &name ); void movePassDown( const std::string &name );
SRenderPass* getPass( const std::string &name ); SRenderPass* getPass( const std::string &name );
void getPassList( std::vector< std::string > &l );
private: private:
std::vector< SRenderPass* > passes; std::vector< SRenderPass* > passes;

@ -20,20 +20,43 @@ namespace NL3D
{ {
void SDynMaterialProp::serial( NLMISC::IStream &f ) void SDynMaterialProp::serial( NLMISC::IStream &f )
{ {
f.serial( std::string( prop ) ); f.xmlPush( "property" );
f.serial( std::string( label ) );
f.serial( uint8( type ) ); f.xmlPush( "id" );
f.serial( std::string( value ) ); 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 ) 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() ) if( !f.isReading() )
{ {
uint32 n = properties.size(); uint32 n = properties.size();
f.xmlPush( "count" );
f.serial( n ); f.serial( n );
f.xmlPop();
std::vector< SDynMaterialProp >::iterator itr = properties.begin(); std::vector< SDynMaterialProp >::iterator itr = properties.begin();
while( itr != properties.end() ) while( itr != properties.end() )
@ -45,7 +68,9 @@ namespace NL3D
else else
{ {
uint32 n; uint32 n;
f.xmlPush( "count" );
f.serial( n ); f.serial( n );
f.xmlPop();
for( uint32 i = 0; i < n; i++ ) for( uint32 i = 0; i < n; i++ )
{ {
@ -55,6 +80,9 @@ namespace NL3D
} }
} }
f.xmlPop();
f.xmlPop();
} }
void SRenderPass::addProperty( const SDynMaterialProp &prop ) void SRenderPass::addProperty( const SDynMaterialProp &prop )
@ -124,12 +152,18 @@ namespace NL3D
void CDynMaterial::serial( NLMISC::IStream &f ) void CDynMaterial::serial( NLMISC::IStream &f )
{ {
f.xmlPush( "Material" );
int version = f.serialVersion( 1 ); int version = f.serialVersion( 1 );
f.xmlPush( "passes" );
if( !f.isReading() ) if( !f.isReading() )
{ {
uint32 n = passes.size(); uint32 n = passes.size();
f.xmlPush( "count" );
f.serial( n ); f.serial( n );
f.xmlPop();
std::vector< SRenderPass* >::iterator itr = passes.begin(); std::vector< SRenderPass* >::iterator itr = passes.begin();
while( itr != passes.end() ) while( itr != passes.end() )
@ -141,15 +175,21 @@ namespace NL3D
else else
{ {
uint32 n; uint32 n;
f.xmlPush( "count" );
f.serial( n ); f.serial( n );
f.xmlPop();
for( uint32 i = 0; i < n; n++ ) for( uint32 i = 0; i < n; i++ )
{ {
SRenderPass *pass = new SRenderPass(); SRenderPass *pass = new SRenderPass();
pass->serial( f ); pass->serial( f );
passes.push_back( pass ); passes.push_back( pass );
} }
} }
f.xmlPop();
f.xmlPop();
} }
void CDynMaterial::addPass( const SRenderPass &pass ) void CDynMaterial::addPass( const SRenderPass &pass )
@ -269,6 +309,20 @@ namespace NL3D
else else
return *itr; 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;
}
}
} }

@ -39,9 +39,11 @@ namespace MaterialEditor
{ {
m_ui.setupUi(this); m_ui.setupUi(this);
nl3dIface = new CNel3DInterface(); nl3dIface = new CNel3DInterface();
materialWidget = new MaterialWidget();
shaderWidget = new ShaderWidget(); shaderWidget = new ShaderWidget();
passesWidget = new RenderPassesWidget(); passesWidget = new RenderPassesWidget();
passesWidget->setNel3dIface( nl3dIface ); passesWidget->setNel3dIface( nl3dIface );
materialWidget->setNel3DIface( nl3dIface );
createMenus(); createMenus();
createDockWidgets(); createDockWidgets();
@ -72,6 +74,7 @@ namespace MaterialEditor
void MaterialEditorWindow::onNewMaterialClicked() void MaterialEditorWindow::onNewMaterialClicked()
{ {
nl3dIface->newMaterial(); nl3dIface->newMaterial();
materialWidget->onNewMaterial();
} }
void MaterialEditorWindow::onOpenMaterialClicked() void MaterialEditorWindow::onOpenMaterialClicked()
@ -96,6 +99,8 @@ namespace MaterialEditor
QMessageBox::Ok QMessageBox::Ok
); );
} }
materialWidget->onMaterialLoaded();
} }
void MaterialEditorWindow::onSaveMaterialClicked() void MaterialEditorWindow::onSaveMaterialClicked()
@ -173,9 +178,8 @@ namespace MaterialEditor
QDockWidget *dock = new QDockWidget( tr( "Material" ), this ); QDockWidget *dock = new QDockWidget( tr( "Material" ), this );
dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea ); dock->setAllowedAreas( Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea );
MaterialWidget *mw = new MaterialWidget(); passesWidget->setMaterialObserver( materialWidget );
passesWidget->setMaterialObserver( mw ); dock->setWidget( materialWidget );
dock->setWidget( mw );
addDockWidget( Qt::RightDockWidgetArea, dock ); addDockWidget( Qt::RightDockWidgetArea, dock );
} }

@ -25,6 +25,7 @@ namespace MaterialEditor
class ShaderWidget; class ShaderWidget;
class RenderPassesWidget; class RenderPassesWidget;
class CNel3DInterface; class CNel3DInterface;
class MaterialWidget;
class MaterialEditorWindow: public QMainWindow class MaterialEditorWindow: public QMainWindow
{ {
@ -50,6 +51,7 @@ private:
ShaderWidget *shaderWidget; ShaderWidget *shaderWidget;
RenderPassesWidget *passesWidget; RenderPassesWidget *passesWidget;
MaterialWidget *materialWidget;
Ui::MaterialEditorWindow m_ui; Ui::MaterialEditorWindow m_ui;
}; };

@ -25,6 +25,9 @@ namespace MaterialEditor
public: public:
CMaterialObserver(){} CMaterialObserver(){}
virtual ~CMaterialObserver(){} virtual ~CMaterialObserver(){}
virtual void onNewMaterial() = 0;
virtual void onMaterialLoaded() = 0;
virtual void onPassAdded( const char *name ) = 0; virtual void onPassAdded( const char *name ) = 0;
virtual void onPassRemoved( const char *name ) = 0; virtual void onPassRemoved( const char *name ) = 0;

@ -17,6 +17,7 @@
#include "material_widget.h" #include "material_widget.h"
#include "shader_editor.h" #include "shader_editor.h"
#include "material_properties.h" #include "material_properties.h"
#include "nel3d_interface.h"
namespace MaterialEditor namespace MaterialEditor
{ {
@ -38,6 +39,28 @@ namespace MaterialEditor
matPropWidget = NULL; 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 ) void MaterialWidget::onPassAdded( const char *name )
{ {
passCB->addItem( name ); passCB->addItem( name );

@ -24,6 +24,7 @@ namespace MaterialEditor
{ {
class ShaderEditorWidget; class ShaderEditorWidget;
class MatPropWidget; class MatPropWidget;
class CNel3DInterface;
class MaterialWidget : public QWidget, public Ui::MaterialWidget, public CMaterialObserver class MaterialWidget : public QWidget, public Ui::MaterialWidget, public CMaterialObserver
{ {
@ -32,16 +33,22 @@ namespace MaterialEditor
MaterialWidget( QWidget *parent = NULL ); MaterialWidget( QWidget *parent = NULL );
~MaterialWidget(); ~MaterialWidget();
void onNewMaterial();
void onMaterialLoaded();
void onPassAdded( const char *name ); void onPassAdded( const char *name );
void onPassRemoved( const char *name ); void onPassRemoved( const char *name );
void onPassMovedUp( const char *name ); void onPassMovedUp( const char *name );
void onPassMovedDown( const char *name ); void onPassMovedDown( const char *name );
void onPassRenamed( const char *from, const char *to ); void onPassRenamed( const char *from, const char *to );
void setNel3DIface( CNel3DInterface *iface ){ nl3dIface = iface; }
private: private:
void setupConnections(); void setupConnections();
ShaderEditorWidget *shaderEditorWidget; ShaderEditorWidget *shaderEditorWidget;
MatPropWidget *matPropWidget; MatPropWidget *matPropWidget;
CNel3DInterface *nl3dIface;
private Q_SLOTS: private Q_SLOTS:
void onPassEditClicked(); void onPassEditClicked();

@ -22,6 +22,11 @@
namespace MaterialEditor namespace MaterialEditor
{ {
void CNelMaterialProxy::getPassList( std::vector< std::string > &l )
{
material->getPassList( l );
}
void CNelMaterialProxy::addPass( const char *name ) void CNelMaterialProxy::addPass( const char *name )
{ {
NL3D::SRenderPass pass; NL3D::SRenderPass pass;

@ -18,6 +18,9 @@
#ifndef NEL3D_INTERFACE_H #ifndef NEL3D_INTERFACE_H
#define NEL3D_INTERFACE_H #define NEL3D_INTERFACE_H
#include <vector>
#include <string>
namespace NL3D namespace NL3D
{ {
class CDynMaterial; class CDynMaterial;
@ -35,6 +38,8 @@ namespace MaterialEditor
~CNelMaterialProxy(){} ~CNelMaterialProxy(){}
void getPassList( std::vector< std::string > &l );
void addPass( const char *name ); void addPass( const char *name );
void removePass( const char *name ); void removePass( const char *name );
void movePassUp( const char *name ); void movePassUp( const char *name );

Loading…
Cancel
Save