diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp index c21989165..e9262b0a3 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_properties.cpp @@ -43,6 +43,7 @@ namespace MaterialEditor void MatPropWidget::load( CRenderPassProxy *proxy ) { clear(); + changed = false; this->proxy = new CRenderPassProxy( *proxy ); std::string n; @@ -74,7 +75,6 @@ namespace MaterialEditor { treeWidget->clear(); nameEdit->clear(); - changed = false; if( this->proxy != NULL ) { delete this->proxy; diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.cpp index 3bd161dc4..5be742598 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.cpp @@ -47,6 +47,7 @@ namespace MaterialEditor void MaterialSplitter::setupConnections() { connect( materialWidget, SIGNAL( propsChanged() ), this, SLOT( onPropsChanged() ) ); + connect( materialWidget, SIGNAL( passChanged( const QString& ) ), this, SLOT( onPassChanged( const QString& ) ) ); } void MaterialSplitter::setup() @@ -104,5 +105,10 @@ namespace MaterialEditor materialWidget->getCurrentPass( pass ); browserCtrl->onPropsChanged(); } + + void MaterialSplitter::onPassChanged( const QString &pass ) + { + browserCtrl->loadPropsForPass( pass ); + } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.h index 8b259cc19..5e725eacf 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_splitter.h @@ -58,6 +58,8 @@ namespace MaterialEditor private Q_SLOTS: void onPropsChanged(); + void onPassChanged( const QString &pass ); + }; } 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 00d349425..8f2b13e4e 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 @@ -128,6 +128,7 @@ namespace MaterialEditor { connect( passButton, SIGNAL( clicked( bool ) ), this, SLOT( onPassEditClicked() ) ); connect( shaderButton, SIGNAL( clicked( bool ) ), this, SLOT( onShaderEditClicked() ) ); + connect( passCB, SIGNAL( currentIndexChanged( const QString& ) ), this, SLOT( onPassCBChanged( const QString& ) ) ); connect( shaderEditorWidget, SIGNAL( okClicked() ), this, SLOT( onShaderEditOKClicked() ) ); } @@ -153,5 +154,12 @@ namespace MaterialEditor { } + void MaterialWidget::onPassCBChanged( const QString &text ) + { + if( text.isEmpty() ) + return; + + Q_EMIT passChanged( text ); + } } 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 5869eaa92..5e54b2fdb 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 @@ -48,6 +48,7 @@ namespace MaterialEditor Q_SIGNALS: void propsChanged(); + void passChanged( const QString &pass ); private: void setupConnections(); @@ -59,6 +60,7 @@ namespace MaterialEditor void onPassEditClicked(); void onShaderEditClicked(); void onShaderEditOKClicked(); + void onPassCBChanged( const QString &text ); }; } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.cpp index a266cb156..a598a2909 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.cpp @@ -17,24 +17,163 @@ #include "prop_browser_ctrl.h" #include "3rdparty/qtpropertybrowser/qttreepropertybrowser.h" +#include "3rdparty/qtpropertybrowser/qtvariantproperty.h" #include "nel3d_interface.h" namespace MaterialEditor { + int propToQVariant( unsigned char t ) + { + int type = 0; + + switch( t ) + { + case SMatProp::Color: + type = QVariant::String; + break; + + case SMatProp::Double: + type = QVariant::Double; + break; + + case SMatProp::Float: + type = QVariant::Double; + break; + + case SMatProp::Int: + type = QVariant::Int; + break; + + case SMatProp::Matrix4: + type = QVariant::String; + break; + + case SMatProp::Texture: + type = QVariant::String; + break; + + case SMatProp::Uint: + type = QVariant::UInt; + break; + + case SMatProp::Vector4: + type = QVariant::String; + break; + + default: + type = QVariant::String; + break; + } + + return type; + } + + void propValToQVariant( const SMatProp &p, QVariant &v ) + { + bool ok = false; + QString s; + + switch( p.type ) + { + case SMatProp::Color: + v = p.value.c_str(); + break; + + case SMatProp::Double: + double d; + + s = p.value.c_str(); + d = s.toDouble( &ok ); + if( ok ) + v = d; + else + v = 0.0; + + break; + + case SMatProp::Float: + float f; + + s = p.value.c_str(); + f = s.toFloat( &ok ); + if( ok ) + v = f; + else + v = 0.0f; + + break; + + case SMatProp::Int: + int i; + + s = p.value.c_str(); + i = s.toInt( &ok ); + if( ok ) + v = i; + else + v = 0; + + break; + + case SMatProp::Matrix4: + v = p.value.c_str(); + break; + + case SMatProp::Texture: + v = p.value.c_str(); + break; + + case SMatProp::Uint: + unsigned int u; + + s = p.value.c_str(); + u = s.toUInt( &ok ); + if( ok ) + v = u; + else + v = 0u; + + break; + + case SMatProp::Vector4: + v = p.value.c_str(); + break; + + default: + v = ""; + break; + } + } + + + + + + + CPropBrowserCtrl::CPropBrowserCtrl( QObject *parent ) : QObject( parent ) { browser = NULL; nel3dIface = NULL; + manager = new QtVariantPropertyManager(); + factory = new QtVariantEditorFactory(); } CPropBrowserCtrl::~CPropBrowserCtrl() { + browser = NULL; + nel3dIface = NULL; + delete manager; + manager = NULL; + delete factory; + factory = NULL; } void CPropBrowserCtrl::setBrowser( QtTreePropertyBrowser *b ) { browser = b; + browser->setFactoryForManager( manager, factory ); } void CPropBrowserCtrl::setNel3DIface( CNel3DInterface *iface ) @@ -60,8 +199,37 @@ namespace MaterialEditor void CPropBrowserCtrl::loadPropsForPass( const QString &pass ) { currentPass = pass; + clearProps(); + + if( pass.isEmpty() ) + return; + CNelMaterialProxy m = nel3dIface->getMaterial(); CRenderPassProxy p = m.getPass( pass.toUtf8().data() ); + + std::vector< SMatProp > v; + p.getProperties( v ); + + QtVariantProperty *vp = NULL; + int type = 0; + QVariant qv; + + std::vector< SMatProp >::const_iterator itr = v.begin(); + while( itr != v.end() ) + { + const SMatProp &prop = *itr; + + type = propToQVariant( prop.type ); + + vp = manager->addProperty( type, prop.label.c_str() ); + + propValToQVariant( prop, qv ); + vp->setValue( qv ); + + browser->addProperty( vp ); + + ++itr; + } } } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.h index 0b4d69caa..caf8e5824 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/prop_browser_ctrl.h @@ -21,6 +21,8 @@ #include class QtTreePropertyBrowser; +class QtVariantPropertyManager; +class QtVariantEditorFactory; namespace MaterialEditor { @@ -41,6 +43,9 @@ namespace MaterialEditor private: QtTreePropertyBrowser *browser; + QtVariantPropertyManager *manager; + QtVariantEditorFactory *factory; + CNel3DInterface *nel3dIface; QString currentPass; };