From ea06a2c65688e25c8e4cfbe0db761c1e8a2592c6 Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Thu, 4 Jul 2013 01:16:20 +0200 Subject: [PATCH] Property values can now be changed. --HG-- branch : gsoc2013-dfighter --- code/nel/include/nel/3d/dynamic_material.h | 2 +- code/nel/src/3d/dynamic_material.cpp | 6 ++-- .../material_editor/nel3d_interface.cpp | 30 +++++++++++++++++++ .../plugins/material_editor/nel3d_interface.h | 3 ++ .../material_editor/prop_browser_ctrl.cpp | 30 +++++++++++++++++++ .../material_editor/prop_browser_ctrl.h | 10 ++++++- 6 files changed, 77 insertions(+), 4 deletions(-) diff --git a/code/nel/include/nel/3d/dynamic_material.h b/code/nel/include/nel/3d/dynamic_material.h index 6e3d24997..98cbfdb42 100644 --- a/code/nel/include/nel/3d/dynamic_material.h +++ b/code/nel/include/nel/3d/dynamic_material.h @@ -54,7 +54,7 @@ namespace NL3D public: void addProperty( const SDynMaterialProp &prop ); void removeProperty( const std::string &name ); - void changeProperty( const std::string &name, const SDynMaterialProp &prop ); + bool changeProperty( const std::string &name, const SDynMaterialProp &prop ); void setName( const std::string &n ){ name = n; } void getName( std::string &n ) const { n = name; } void serial( NLMISC::IStream &f ); diff --git a/code/nel/src/3d/dynamic_material.cpp b/code/nel/src/3d/dynamic_material.cpp index f12e245c1..a712c66c9 100644 --- a/code/nel/src/3d/dynamic_material.cpp +++ b/code/nel/src/3d/dynamic_material.cpp @@ -115,7 +115,7 @@ namespace NL3D properties.erase( itr ); } - void SRenderPass::changeProperty( const std::string &name, const SDynMaterialProp &prop ) + bool SRenderPass::changeProperty( const std::string &name, const SDynMaterialProp &prop ) { std::vector< SDynMaterialProp >::iterator itr = properties.begin(); while( itr != properties.end() ) @@ -125,12 +125,14 @@ namespace NL3D ++itr; } if( itr == properties.end() ) - return; + return false; itr->prop = prop.prop; itr->label = prop.label; itr->type = prop.type; itr->value = prop.value; + + return true; } 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 1efeac4f0..6eb588c1a 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 @@ -97,9 +97,39 @@ namespace MaterialEditor pass->setName( name ); } + bool CRenderPassProxy::getProperty( const std::string &name, SMatProp &p ) + { + uint32 count = pass->count(); + uint32 i = 0; + + for( i = 0; i < count; i++ ) + { + if( pass->getProperty( i )->prop == name ) + break; + } + + if( i == count ) + return false; + + const NL3D::SDynMaterialProp *prop = pass->getProperty( i ); + p.id = prop->prop; + p.label = prop->label; + p.type = prop->type; + p.value = prop->value; + return true; + } + bool CRenderPassProxy::changeProperty( const SMatProp &p ) + { + NL3D::SDynMaterialProp prop; + prop.prop = p.id; + prop.label = p.label; + prop.type = p.type; + prop.value = p.value; + return pass->changeProperty( prop.prop, prop ); + } void CNelMaterialProxy::getPassList( std::vector< std::string > &l ) { 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 d0d3d6f06..c95bcdb3d 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 @@ -72,6 +72,9 @@ namespace MaterialEditor void getName( std::string &name ); void setName( const std::string &name ); + bool getProperty( const std::string &name, SMatProp &p ); + bool changeProperty( const SMatProp &p ); + private: NL3D::SRenderPass *pass; }; 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 a598a2909..9f7cd0542 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 @@ -158,6 +158,8 @@ namespace MaterialEditor nel3dIface = NULL; manager = new QtVariantPropertyManager(); factory = new QtVariantEditorFactory(); + + setupConnections(); } CPropBrowserCtrl::~CPropBrowserCtrl() @@ -183,6 +185,8 @@ namespace MaterialEditor void CPropBrowserCtrl::setupConnections() { + connect( manager, SIGNAL( valueChanged( QtProperty*, const QVariant& ) ), + this, SLOT( onValueChanged( QtProperty*, const QVariant& ) ) ); } void CPropBrowserCtrl::onPropsChanged() @@ -194,6 +198,7 @@ namespace MaterialEditor void CPropBrowserCtrl::clearProps() { browser->clear(); + propToId.clear(); } void CPropBrowserCtrl::loadPropsForPass( const QString &pass ) @@ -228,9 +233,34 @@ namespace MaterialEditor browser->addProperty( vp ); + propToId[ vp ] = prop.id; + ++itr; } } + void CPropBrowserCtrl::onValueChanged( QtProperty *p, const QVariant &v ) + { + QString label = p->propertyName(); + std::string value = p->valueText().toUtf8().data(); + + CNelMaterialProxy m = nel3dIface->getMaterial(); + CRenderPassProxy pass = m.getPass( currentPass.toUtf8().data() ); + + std::map< QtProperty*, std::string >::const_iterator itr + = propToId.find( p ); + if( itr == propToId.end() ) + return; + + SMatProp prop; + bool ok = pass.getProperty( itr->second, prop ); + if( !ok ) + return; + + prop.value = value; + pass.changeProperty( prop ); + + } + } 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 caf8e5824..d602a086c 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 @@ -19,10 +19,13 @@ #define PROP_BROWSER_CTRL_H #include +#include +#include class QtTreePropertyBrowser; class QtVariantPropertyManager; class QtVariantEditorFactory; +class QtProperty; namespace MaterialEditor { @@ -39,7 +42,10 @@ namespace MaterialEditor void setupConnections(); void onPropsChanged(); void clearProps(); - void loadPropsForPass( const QString &pass ); + void loadPropsForPass( const QString &pass ); + + private Q_SLOTS: + void onValueChanged( QtProperty *p, const QVariant &v ); private: QtTreePropertyBrowser *browser; @@ -48,6 +54,8 @@ namespace MaterialEditor CNel3DInterface *nel3dIface; QString currentPass; + + std::map< QtProperty*, std::string > propToId; }; }