Worked a bit more on dynamic material. Also started to rework the material and pass widgets since I've realized I messed it up. Eg.: passes should have properties, not the material itself.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 12 years ago
parent 26fab0c173
commit 85e885f274

@ -25,7 +25,7 @@
namespace NL3D
{
struct CDynMaterialProp
struct SDynMaterialProp
{
enum EPropertyType
{
@ -43,8 +43,30 @@ namespace NL3D
std::string label;
uint8 type;
std::string value;
void serial( NLMISC::IStream &f );
};
struct SRenderPass
{
public:
void addProperty( const SDynMaterialProp &prop );
void removeProperty( const std::string &name );
void 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 );
private:
std::vector< SDynMaterialProp > properties;
std::string name;
};
class CDynMaterial : public NLMISC::IStreamable
{
public:
@ -52,12 +74,12 @@ namespace NL3D
~CDynMaterial();
void serial( NLMISC::IStream &f );
void addProperty( const CDynMaterialProp &prop );
void removeProperty( const std::string &name );
void changeProperty( const std::string &name, const CDynMaterialProp &prop );
void addPass( const SRenderPass &pass );
void removePass( const std::string &name );
SRenderPass* getPass( const std::string &name );
private:
std::vector< CDynMaterialProp > properties;
std::vector< SRenderPass > passes;
};
}

@ -18,33 +18,39 @@
namespace NL3D
{
CDynMaterial::CDynMaterial()
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 ) );
}
CDynMaterial::~CDynMaterial()
void SRenderPass::serial( NLMISC::IStream &f )
{
}
f.serial( std::string( name ) );
void CDynMaterial::serial( NLMISC::IStream &f )
if( !f.isReading() )
{
int version = f.serialVersion( 1 );
std::vector< CDynMaterialProp >::const_iterator itr = properties.begin();
std::vector< SDynMaterialProp >::iterator itr = properties.begin();
while( itr != properties.end() )
{
f.serial( std::string( itr->prop ) );
f.serial( std::string( itr->label ) );
f.serial( uint8( itr->type ) );
f.serial( std::string( itr->value ) );
itr->serial( f );
++itr;
}
}
else
{
SDynMaterialProp prop;
prop.serial( f );
properties.push_back( prop );
}
}
void CDynMaterial::addProperty( const CDynMaterialProp &prop )
void SRenderPass::addProperty( const SDynMaterialProp &prop )
{
std::vector< CDynMaterialProp >::const_iterator itr = properties.begin();
std::vector< SDynMaterialProp >::const_iterator itr = properties.begin();
while( itr != properties.end() )
{
if( itr->prop == prop.prop )
@ -57,9 +63,9 @@ namespace NL3D
properties.push_back( prop );
}
void CDynMaterial::removeProperty( const std::string &name )
void SRenderPass::removeProperty( const std::string &name )
{
std::vector< CDynMaterialProp >::iterator itr = properties.begin();
std::vector< SDynMaterialProp >::iterator itr = properties.begin();
while( itr != properties.end() )
{
if( itr->prop == name )
@ -72,9 +78,9 @@ namespace NL3D
properties.erase( itr );
}
void CDynMaterial::changeProperty( const std::string &name, const CDynMaterialProp &prop )
void SRenderPass::changeProperty( const std::string &name, const SDynMaterialProp &prop )
{
std::vector< CDynMaterialProp >::iterator itr = properties.begin();
std::vector< SDynMaterialProp >::iterator itr = properties.begin();
while( itr != properties.end() )
{
if( itr->prop == name )
@ -90,6 +96,89 @@ namespace NL3D
itr->value = prop.value;
}
CDynMaterial::CDynMaterial()
{
}
CDynMaterial::~CDynMaterial()
{
}
void CDynMaterial::serial( NLMISC::IStream &f )
{
int version = f.serialVersion( 1 );
if( !f.isReading() )
{
std::vector< SRenderPass >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->serial( f );
++itr;
}
}
else
{
SRenderPass pass;
pass.serial( f );
passes.push_back( pass );
}
}
void CDynMaterial::addPass( const SRenderPass &pass )
{
std::string n;
std::string name;
pass.getName( name );
std::vector< SRenderPass >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->getName( n );
if( n == name )
break;
++itr;
}
if( itr != passes.end() )
return;
passes.push_back( pass );
}
void CDynMaterial::removePass( const std::string &name )
{
std::string n;
std::vector< SRenderPass >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->getName( n );
if( n == name )
break;
++itr;
}
if( itr != passes.end() )
passes.erase( itr );
}
SRenderPass* CDynMaterial::getPass( const std::string &name )
{
std::string n;
std::vector< SRenderPass >::iterator itr = passes.begin();
while( itr != passes.end() )
{
itr->getName( n );
if( n == name )
break;
++itr;
}
if( itr == passes.end() )
return NULL;
else
return &( *itr );
}
}

@ -18,7 +18,7 @@
#include "material_editor_constants.h"
#include "material_widget.h"
#include "shader_widget.h"
#include "material_properties.h"
#include "render_passes.h"
#include "../core/icore.h"
#include "../core/core_constants.h"
@ -37,7 +37,7 @@ namespace MaterialEditor
{
m_ui.setupUi(this);
shaderWidget = new ShaderWidget();
matPropWidget = new MatPropWidget();
passesWidget = new RenderPassesWidget();
createMenus();
createDockWidgets();
}
@ -46,8 +46,8 @@ namespace MaterialEditor
{
delete shaderWidget;
shaderWidget = NULL;
delete matPropWidget;
matPropWidget = NULL;
delete passesWidget;
passesWidget = NULL;
}
void MaterialEditorWindow::onOpenClicked()
@ -86,14 +86,14 @@ namespace MaterialEditor
);
}
void MaterialEditorWindow::onEditMaterialClicked()
void MaterialEditorWindow::onShadersClicked()
{
matPropWidget->show();
shaderWidget->show();
}
void MaterialEditorWindow::onShadersClicked()
void MaterialEditorWindow::onPassesClicked()
{
shaderWidget->show();
passesWidget->show();
}
void MaterialEditorWindow::createMenus()
@ -119,16 +119,15 @@ namespace MaterialEditor
a = new QAction( tr( "Save material" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onSaveMaterialClicked() ) );
mm->addAction( a );
a = new QAction( tr( "Edit material" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onEditMaterialClicked() ) );
mm->addAction( a );
}
a = new QAction( tr( "Shaders" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onShadersClicked() ) );
m->addAction( a );
a = new QAction( tr( "Render passes" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onPassesClicked() ) );
m->addAction( a );
}
}

@ -22,8 +22,8 @@
namespace MaterialEditor
{
class MatPropWidget;
class ShaderWidget;
class RenderPassesWidget;
class MaterialEditorWindow: public QMainWindow
{
@ -38,15 +38,15 @@ private Q_SLOTS:
void onNewMaterialClicked();
void onOpenMaterialClicked();
void onSaveMaterialClicked();
void onEditMaterialClicked();
void onShadersClicked();
void onPassesClicked();
private:
void createMenus();
void createDockWidgets();
ShaderWidget *shaderWidget;
MatPropWidget *matPropWidget;
RenderPassesWidget *passesWidget;
Ui::MaterialEditorWindow m_ui;
};

@ -9,15 +9,41 @@
<rect>
<x>0</x>
<y>0</y>
<width>603</width>
<height>320</height>
<width>669</width>
<height>504</height>
</rect>
</property>
<property name="windowTitle">
<string>Material properties</string>
<string>Rendering pass properties</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout_3">
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<widget class="QLabel" name="label">
<property name="text">
<string>Pass name</string>
</property>
</widget>
</item>
<item>
<widget class="QLineEdit" name="nameEdit"/>
</item>
</layout>
</item>
<item row="1" column="0">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="MinimumExpanding" vsizetype="MinimumExpanding">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Pass properties</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QTreeWidget" name="treeWidget">
@ -44,6 +70,12 @@
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QPushButton" name="addButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Add</string>
</property>
@ -51,6 +83,12 @@
</item>
<item>
<widget class="QPushButton" name="removeButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Remove</string>
</property>
@ -58,6 +96,12 @@
</item>
<item>
<widget class="QPushButton" name="editButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>Edit</string>
</property>
@ -82,10 +126,19 @@
</item>
</layout>
</item>
<item>
</layout>
</widget>
</item>
<item row="2" column="0">
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QPushButton" name="okButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string>OK</string>
</property>

Loading…
Cancel
Save