Implemented a basic fog control widget.

--HG--
branch : gsoc2013-dfighter
hg/feature/gsoc2013-dfighter
dfighter1985 11 years ago
parent ed885d3df6
commit 1cc71457eb

@ -197,6 +197,9 @@ public:
virtual void enableFog(bool enable);
/// setup fog parameters. fog must enabled to see result. start and end are in [0,1] range.
virtual void setupFog(float start, float end, CRGBA color);
virtual float getFogStart();
virtual float getFogEnd();
virtual CRGBA getFogColor();
// @}
/// \name Light support.

@ -265,6 +265,9 @@ public:
virtual void enableFog(bool enable)=0;
/// $ fog parameters. fog must enabled to see result. start and end are in [0,1] range.
virtual void setupFog(float start, float end, CRGBA color)=0;
virtual float getFogStart() = 0;
virtual float getFogEnd() = 0;
virtual CRGBA getFogColor() = 0;
// @}
/// \name Light support.

@ -1400,6 +1400,21 @@ void CDriverUser::setupFog(float start, float end, CRGBA color)
_Driver->setupFog(start, end, color);
}
float CDriverUser::getFogStart()
{
return _Driver->getFogStart();
}
float CDriverUser::getFogEnd()
{
return _Driver->getFogEnd();
}
CRGBA CDriverUser::getFogColor()
{
return _Driver->getFogColor();
}
// ***************************************************************************
void CDriverUser::setLight (uint8 num, const ULight& light)

@ -24,6 +24,8 @@ SET(OVQT_PLUGIN_MATERIAL_EDITOR_HDR
shader_widget.h
prop_browser_ctrl.h
viewport_widget.h
fog_widget.h
lights_widget.h
)
SET(OVQT_PLUGIN_MATERIAL_EDITOR_UIS
@ -34,6 +36,8 @@ SET(OVQT_PLUGIN_MATERIAL_EDITOR_UIS
render_passes.ui
shader_editor.ui
shader_widget.ui
fog_widget.ui
lights_widget.ui
)
SET(QT_USE_QTGUI TRUE)

@ -0,0 +1,116 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "fog_widget.h"
#include "nel3d_interface.h"
#include <QColorDialog>
namespace MaterialEditor
{
FogWidget::FogWidget( QWidget *parent ) :
QWidget( parent )
{
iface = NULL;
setupUi( this );
setupConnections();
}
FogWidget::~FogWidget()
{
iface = NULL;
}
void FogWidget::loadValues()
{
SFogSettings s;
iface->getFogSettings( s );
fogCB->setChecked( s.enable );
startSB->setValue( s.start );
endSB->setValue( s.end );
setColorButtonColor( s.color[ 0 ], s.color[ 1 ], s.color[ 2 ] );
}
void FogWidget::setupConnections()
{
connect( fogCB, SIGNAL( clicked( bool ) ), this, SLOT( onFogCBClicked() ) );
connect( startSB, SIGNAL( valueChanged( double ) ), this, SLOT( onStartSBChanged() ) );
connect( endSB, SIGNAL( valueChanged( double ) ), this, SLOT( onEndSBChanged() ) );
connect( colorButton, SIGNAL( clicked( bool ) ), this, SLOT( onColorButtonClicked() ) );
}
void FogWidget::onFogCBClicked()
{
SFogSettings s;
iface->getFogSettings( s );
s.enable = fogCB->isChecked();
iface->setFogSettings( s );
if( !s.enable )
iface->setBGColor( 255, 255, 255, 255 );
}
void FogWidget::onStartSBChanged()
{
SFogSettings s;
iface->getFogSettings( s );
s.start = startSB->value();
iface->setFogSettings( s );
}
void FogWidget::onEndSBChanged()
{
SFogSettings s;
iface->getFogSettings( s );
s.end = endSB->value();
iface->setFogSettings( s );
}
void FogWidget::onColorButtonClicked()
{
QColor c = QColorDialog::getColor();
setColorButtonColor( c.red(), c.green(), c.blue() );
SFogSettings s;
iface->getFogSettings( s );
s.color[ 0 ] = c.red();
s.color[ 1 ] = c.green();
s.color[ 2 ] = c.blue();
s.color[ 3 ] = 255;
iface->setFogSettings( s );
}
void FogWidget::setColorButtonColor( int r, int g, int b )
{
QString sh;
sh = QString( "background-color: rgb(%1, %2, %3);" ).arg( r ).arg( g ).arg( b );
colorButton->setStyleSheet( sh );
}
}

@ -0,0 +1,56 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef FOG_WIDGET_H
#define FOG_WIDGET_H
#include "ui_fog_widget.h"
namespace MaterialEditor
{
class CNel3DInterface;
class FogWidget : public QWidget, public Ui::FogWidget
{
Q_OBJECT
public:
FogWidget( QWidget *parent = NULL );
~FogWidget();
void loadValues();
void setNl3DIface( CNel3DInterface *iface ){ this->iface = iface; }
private Q_SLOTS:
void onFogCBClicked();
void onStartSBChanged();
void onEndSBChanged();
void onColorButtonClicked();
private:
void setupConnections();
void setColorButtonColor( int r, int g, int b );
CNel3DInterface *iface;
};
}
#endif

@ -0,0 +1,83 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>FogWidget</class>
<widget class="QWidget" name="FogWidget">
<property name="windowModality">
<enum>Qt::ApplicationModal</enum>
</property>
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>278</width>
<height>116</height>
</rect>
</property>
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="windowTitle">
<string>Fog settings</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<property name="sizeConstraint">
<enum>QLayout::SetMaximumSize</enum>
</property>
<item row="0" column="0">
<widget class="QCheckBox" name="fogCB">
<property name="text">
<string>Enable fog</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label">
<property name="text">
<string>Start</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="startSB"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>End</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="endSB"/>
</item>
<item row="3" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Color</string>
</property>
</widget>
</item>
<item row="3" column="1">
<widget class="QPushButton" name="colorButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="styleSheet">
<string notr="true"/>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

@ -0,0 +1,22 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "lights_widget.h"
namespace MaterialEditor
{
}

@ -0,0 +1,29 @@
// Object Viewer Qt Material Editor plugin <http://dev.ryzom.com/projects/ryzom/>
// Copyright (C) 2010 Winch Gate Property Limited
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as
// published by the Free Software Foundation, either version 3 of the
// License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#ifndef LIGHTS_WIDGET_H
#define LIGHTS_WIDGET_H
namespace MaterialEditor
{
}
#endif

@ -0,0 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LightsWidget</class>
<widget class="QDialog" name="LightsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
</rect>
</property>
<property name="windowTitle">
<string>Light settings</string>
</property>
</widget>
<resources/>
<connections/>
</ui>

@ -21,6 +21,7 @@
#include "render_passes.h"
#include "nel3d_interface.h"
#include "viewport_widget.h"
#include "fog_widget.h"
#include "../core/icore.h"
#include "../core/core_constants.h"
@ -53,6 +54,8 @@ namespace MaterialEditor
passesWidget = new RenderPassesWidget();
passesWidget->setMaterialObserver( materialSplitter );
passesWidget->setNel3dIface( nl3dIface );
fogWidget = new FogWidget();
fogWidget->setNl3DIface( nl3dIface );
//passesWidget->onMaterialLoaded();
//materialSplitter->onMaterialLoaded();
@ -67,6 +70,8 @@ namespace MaterialEditor
MaterialEditorWindow::~MaterialEditorWindow()
{
delete fogWidget;
fogWidget = NULL;
delete shaderWidget;
shaderWidget = NULL;
delete passesWidget;
@ -267,6 +272,16 @@ namespace MaterialEditor
viewPort->stopTimedUpdates();
}
void MaterialEditorWindow::onFogClicked()
{
fogWidget->loadValues();
fogWidget->show();
}
void MaterialEditorWindow::onLightsClicked()
{
}
void MaterialEditorWindow::createMenus()
{
Core::MenuManager *mm = Core::ICore::instance()->menuManager();
@ -316,6 +331,14 @@ namespace MaterialEditor
a = new QAction( tr( "Clear scene" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onClearSceneClicked() ) );
mm->addAction( a );
a = new QAction( tr( "Fog" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onFogClicked() ) );
mm->addAction( a );
a = new QAction( tr( "Lights" ), NULL );
connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onLightsSceneClicked() ) );
mm->addAction( a );
}
a = new QAction( tr( "Shaders" ), NULL );

@ -27,6 +27,7 @@ namespace MaterialEditor
class CNel3DInterface;
class MaterialSplitter;
class ViewPortWidget;
class FogWidget;
class MaterialEditorWindow: public QMainWindow
{
@ -52,6 +53,8 @@ private Q_SLOTS:
void onAddTeaPotClicked();
void onClearSceneClicked();
void onFogClicked();
void onLightsClicked();
private:
void createMenus();
@ -64,6 +67,7 @@ private:
RenderPassesWidget *passesWidget;
MaterialSplitter *materialSplitter;
ViewPortWidget *viewPort;
FogWidget *fogWidget;
Ui::MaterialEditorWindow m_ui;

@ -234,6 +234,7 @@ namespace MaterialEditor
scene = NULL;
mouseListener = NULL;
subMatId = 0;
std::fill( bgColor, bgColor + 4, 255 );
}
CNel3DInterface::~CNel3DInterface()
@ -425,7 +426,8 @@ namespace MaterialEditor
driver->enableFog( true );
driver->setupFog( 1.0f, 5.0f, NLMISC::CRGBA::White );
driver->setupFog( 5.0f, 15.0f, NLMISC::CRGBA::White );
NL3D::ULight *ld;
@ -533,7 +535,13 @@ namespace MaterialEditor
if( driver == NULL )
return;
driver->clearBuffers();
NLMISC::CRGBA c;
c.R = bgColor[ 0 ];
c.G = bgColor[ 1 ];
c.B = bgColor[ 2 ];
c.A = bgColor[ 3 ];
driver->clearBuffers( c );
driver->swapBuffers();
}
@ -548,8 +556,14 @@ namespace MaterialEditor
{
scene->getCam().setTransformMode( NL3D::UTransformable::DirectMatrix );
scene->getCam().setMatrix( mouseListener->getViewMatrix() );
driver->clearBuffers();
NLMISC::CRGBA c;
c.R = bgColor[ 0 ];
c.G = bgColor[ 1 ];
c.B = bgColor[ 2 ];
c.A = bgColor[ 3 ];
driver->clearBuffers( c );
scene->render();
driver->swapBuffers();
}
@ -563,6 +577,31 @@ namespace MaterialEditor
return currentShape.getNumMaterials();
}
void CNel3DInterface::getFogSettings( SFogSettings &s )
{
s.enable = driver->fogEnabled();
s.start = driver->getFogStart();
s.end = driver->getFogEnd();
NLMISC::CRGBA c = driver->getFogColor();
s.color[ 0 ] = c.R;
s.color[ 1 ] = c.G;
s.color[ 2 ] = c.B;
s.color[ 3 ] = c.A;
}
void CNel3DInterface::setFogSettings( const SFogSettings &s )
{
driver->enableFog( s.enable );
NLMISC::CRGBA c;
c.R = s.color[ 0 ];
c.G = s.color[ 1 ];
c.B = s.color[ 2 ];
c.A = 255;
driver->setupFog( s.start, s.end, c );
setBGColor( c.R, c.G, c.B, c.A );
}
void CNel3DInterface::setupCamera()
{
NLMISC::CAABBox bbox;

@ -159,6 +159,26 @@ namespace MaterialEditor
std::string fp;
};
struct SFogSettings
{
bool enable;
float start;
float end;
unsigned char color[ 4 ];
SFogSettings()
{
enable = false;
start = 0.0f;
end = 0.0f;
color[ 0 ] = 0.0f;
color[ 1 ] = 0.0f;
color[ 2 ] = 0.0f;
color[ 3 ] = 0.0f;
}
};
/// Proxy class for Nel3D, so the material editor and Nel3D can interface
class CNel3DInterface
{
@ -245,6 +265,16 @@ namespace MaterialEditor
unsigned long getShapeMatCount() const;
void getFogSettings( SFogSettings &s );
void setFogSettings( const SFogSettings &s );
void setBGColor( unsigned char R, unsigned char G, unsigned char B, unsigned char A ){
bgColor[ 0 ] = R;
bgColor[ 1 ] = G;
bgColor[ 2 ] = B;
bgColor[ 3 ] = A;
}
private:
void setupCamera();
@ -254,6 +284,7 @@ namespace MaterialEditor
NL3D::UDriver *driver;
NL3D::UScene *scene;
NL3D::U3dMouseListener *mouseListener;
unsigned char bgColor[ 4 ];
};
}

Loading…
Cancel
Save