From eb9b3e4f0f9af285f1373d097d6d92adf526e28e Mon Sep 17 00:00:00 2001 From: dfighter1985 Date: Mon, 11 Nov 2013 23:54:31 +0100 Subject: [PATCH] Implemented light controls. --HG-- branch : gsoc2013-dfighter --- code/CMakeLists.txt | 4 + code/nel/include/nel/3d/driver.h | 5 + code/nel/include/nel/3d/driver_user.h | 3 + code/nel/include/nel/3d/u_driver.h | 3 + .../src/3d/driver/direct3d/driver_direct3d.h | 2 + .../driver/direct3d/driver_direct3d_light.cpp | 17 ++ code/nel/src/3d/driver/opengl/driver_opengl.h | 4 + .../3d/driver/opengl/driver_opengl_light.cpp | 16 ++ .../nel/src/3d/driver/opengl3/driver_opengl.h | 4 + .../3d/driver/opengl3/driver_opengl_light.cpp | 14 + code/nel/src/3d/driver_user.cpp | 24 ++ .../plugins/material_editor/lights_widget.cpp | 248 ++++++++++++++++++ .../plugins/material_editor/lights_widget.h | 43 +++ .../plugins/material_editor/lights_widget.ui | 216 ++++++++++++++- .../material_editor_window.cpp | 10 +- .../material_editor/material_editor_window.h | 2 + .../material_editor/nel3d_interface.cpp | 114 +++++++- .../plugins/material_editor/nel3d_interface.h | 37 +++ 18 files changed, 760 insertions(+), 6 deletions(-) diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 926d28345..bbf0431d2 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -53,6 +53,10 @@ SET(NL_VERSION_MINOR 9) SET(NL_VERSION_PATCH 0) SET(NL_VERSION "${NL_VERSION_MAJOR}.${NL_VERSION_MINOR}.${NL_VERSION_PATCH}") +IF(POLICY CMP0020) + CMAKE_POLICY(SET CMP0020 NEW) +ENDIF() + #----------------------------------------------------------------------------- # Redirect output files SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin) diff --git a/code/nel/include/nel/3d/driver.h b/code/nel/include/nel/3d/driver.h index a072abfbd..6147bbbb8 100644 --- a/code/nel/include/nel/3d/driver.h +++ b/code/nel/include/nel/3d/driver.h @@ -1055,6 +1055,9 @@ public: */ virtual void setLight(uint8 num, const CLight &light) = 0; + /// Get light data for the specified light + virtual CLight getLight(uint8 num) = 0; + /** * Enable / disable light. * @@ -1066,6 +1069,8 @@ public: */ virtual void enableLight(uint8 num, bool enable = true) = 0; + virtual bool isLightEnabled(uint8 num) = 0; + /** * Set ambient. * diff --git a/code/nel/include/nel/3d/driver_user.h b/code/nel/include/nel/3d/driver_user.h index 847c95bd1..d78321a05 100644 --- a/code/nel/include/nel/3d/driver_user.h +++ b/code/nel/include/nel/3d/driver_user.h @@ -205,7 +205,10 @@ public: /// \name Light support. // @{ virtual void setLight (uint8 num, const ULight& light); + virtual ULight* getLight (uint8 num); + virtual uint8 getMaxDriverLights() const; virtual void enableLight (uint8 num, bool enable=true); + virtual bool isLightEnabled (uint8 num); virtual void setAmbientColor (CRGBA color); // @} diff --git a/code/nel/include/nel/3d/u_driver.h b/code/nel/include/nel/3d/u_driver.h index 93d223a48..2330b850d 100644 --- a/code/nel/include/nel/3d/u_driver.h +++ b/code/nel/include/nel/3d/u_driver.h @@ -273,7 +273,10 @@ public: /// \name Light support. // @{ virtual void setLight (uint8 num, const ULight& light) = 0; + virtual ULight* getLight (uint8 num) = 0; + virtual uint8 getMaxDriverLights() const = 0; virtual void enableLight (uint8 num, bool enable=true) = 0; + virtual bool isLightEnabled (uint8 num) = 0; virtual void setAmbientColor (CRGBA color) = 0; // @} diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d.h b/code/nel/src/3d/driver/direct3d/driver_direct3d.h index 1055e105c..8cfc46d9d 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d.h +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d.h @@ -1041,7 +1041,9 @@ public: // Lights virtual uint getMaxLight () const; virtual void setLight (uint8 num, const CLight& light); + virtual CLight getLight (uint8 num); virtual void enableLight (uint8 num, bool enable=true); + virtual bool isLightEnabled (uint8 num); virtual void setLightMapDynamicLight (bool enable, const CLight& light); // todo hulud d3d light virtual void setPerPixelLightingLight(CRGBA /* diffuse */, CRGBA /* specular */, float /* shininess */) {} diff --git a/code/nel/src/3d/driver/direct3d/driver_direct3d_light.cpp b/code/nel/src/3d/driver/direct3d/driver_direct3d_light.cpp index 4ad5b46c0..64f9ddf0a 100644 --- a/code/nel/src/3d/driver/direct3d/driver_direct3d_light.cpp +++ b/code/nel/src/3d/driver/direct3d/driver_direct3d_light.cpp @@ -59,6 +59,15 @@ void CDriverD3D::setLight (uint8 index, const CLight &light) } +CLight CDriverD3D::getLight (uint8 index) +{ + // Not yet implemented + nlinfo( "This feature isn't yet implemented in this driver!" ); + nlassert( false ); + return CLight(); +} + + // *************************************************************************** void CDriverD3D::enableLight (uint8 index, bool enable) { @@ -76,6 +85,14 @@ void CDriverD3D::enableLight (uint8 index, bool enable) _LightMapDynamicLightDirty= true; } +bool CDriverD3D::isLightEnabled (uint8 num) +{ + if(numsetLight (num, plight->_Light); } + + +// *************************************************************************** +ULight* CDriverUser::getLight (uint8 num) +{ + ULight *l = ULight::createLight(); + CLightUser *lu = dynamic_cast< CLightUser* >( l ); + nlassert( lu != NULL ); + lu->_Light =_Driver->getLight( num ); + return l; +} + +uint8 CDriverUser::getMaxDriverLights() const +{ + return static_cast< uint8 >( _Driver->getMaxLight() ); +} + // *************************************************************************** void CDriverUser::enableLight (uint8 num, bool enable) { @@ -1431,6 +1448,13 @@ void CDriverUser::enableLight (uint8 num, bool enable) _Driver->enableLight (num, enable); } + +// *************************************************************************** +bool CDriverUser::isLightEnabled (uint8 num) +{ + return _Driver->isLightEnabled (num); +} + // *************************************************************************** void CDriverUser::setAmbientColor (CRGBA color) { diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.cpp index fc8fa0248..d7879d847 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.cpp @@ -15,8 +15,256 @@ // along with this program. If not, see . #include "lights_widget.h" +#include +#include "nel3d_interface.h" namespace MaterialEditor { + enum LWLightTypes + { + DIRECTIONAL, + POINT, + SPOT + }; + + enum LWColorButton + { + AMBIENT, + DIFFUSE, + SPECULAR + }; + + void LightsWidget::setButtonColor( unsigned char butt, int r, int g, int b ) + { + QString sh; + QPushButton *button; + + if( butt > SPECULAR ) + return; + + switch( butt ) + { + case AMBIENT: + button = ambientButton; + break; + + case DIFFUSE: + button = diffuseButton; + break; + + case SPECULAR: + button = specularButton; + break; + } + + sh = QString( "background-color: rgb(%1, %2, %3);" ).arg( r ).arg( g ).arg( b ); + button->setStyleSheet( sh ); + + buttonColors[ butt ][ 0 ] = r; + buttonColors[ butt ][ 1 ] = g; + buttonColors[ butt ][ 2 ] = b; + } + + + + LightsWidget::LightsWidget( QWidget *parent ) : + QWidget( parent ) + { + setupUi( this ); + setupConnections(); + + typeCB->addItem( "Directional light" ); + typeCB->addItem( "Point light" ); + typeCB->addItem( "Spot light" ); + } + + LightsWidget::~LightsWidget() + { + } + + void LightsWidget::loadValues() + { + disableChangeConnections(); + + unsigned char c = iface->getMaxLights(); + + lightList->clear(); + + for( unsigned char i = 0; i < c; i++ ) + { + QString s = "light"; + s += QString::number( i ); + lightList->addItem( s ); + } + + lightList->setCurrentRow( 0 ); + loadLight( 0 ); + + // loadLight enables it anyways + //setupChangeConnections(); + } + + void LightsWidget::setupConnections() + { + } + + void LightsWidget::setupChangeConnections() + { + connect( enableCB, SIGNAL( toggled( bool ) ), this, SLOT( onChanges() ) ); + connect( ambientButton, SIGNAL( clicked( bool ) ), this, SLOT( onAmbButtonClicked() ) ); + connect( diffuseButton, SIGNAL( clicked( bool ) ), this, SLOT( onDiffButtonClicked() ) ); + connect( specularButton, SIGNAL( clicked( bool ) ), this, SLOT( onSpecButtonClicked() ) ); + connect( lightList, SIGNAL( currentRowChanged( int ) ), this, SLOT( onLightChanged( int ) ) ); + + connect( typeCB, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onChanges() ) ); + connect( xSB, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + connect( ySB, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + connect( zSB, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + connect( constAttnButton, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + connect( linearAttnButton, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + connect( quadAttnButton, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + } + + void LightsWidget::disableChangeConnections() + { + disconnect( enableCB, SIGNAL( toggled( bool ) ), this, SLOT( onChanges() ) ); + disconnect( ambientButton, SIGNAL( clicked( bool ) ), this, SLOT( onAmbButtonClicked() ) ); + disconnect( diffuseButton, SIGNAL( clicked( bool ) ), this, SLOT( onDiffButtonClicked() ) ); + disconnect( specularButton, SIGNAL( clicked( bool ) ), this, SLOT( onSpecButtonClicked() ) ); + disconnect( lightList, SIGNAL( currentRowChanged( int ) ), this, SLOT( onLightChanged( int ) ) ); + + disconnect( typeCB, SIGNAL( currentIndexChanged( int ) ), this, SLOT( onChanges() ) ); + disconnect( xSB, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + disconnect( ySB, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + disconnect( zSB, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + disconnect( constAttnButton, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + disconnect( linearAttnButton, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + disconnect( quadAttnButton, SIGNAL( valueChanged( double ) ), this, SLOT( onChanges() ) ); + } + + void LightsWidget::onAmbButtonClicked() + { + QColor c = QColorDialog::getColor(); + setButtonColor( AMBIENT, c.red(), c.green(), c.blue() ); + applyChanges(); + } + + void LightsWidget::onDiffButtonClicked() + { + QColor c = QColorDialog::getColor(); + setButtonColor( DIFFUSE, c.red(), c.green(), c.blue() ); + applyChanges(); + } + + void LightsWidget::onSpecButtonClicked() + { + QColor c = QColorDialog::getColor(); + setButtonColor( SPECULAR, c.red(), c.green(), c.blue() ); + applyChanges(); + } + + void LightsWidget::onLightChanged( int light ) + { + loadLight( light ); + } + + void LightsWidget::onChanges() + { + applyChanges(); + } + + void LightsWidget::loadLight( unsigned char light ) + { + disableChangeConnections(); + + SLightInfo info; + iface->getLightInfo( light, info ); + + if( info.enabled ) + enableCB->setChecked( true ); + else + enableCB->setChecked( false ); + + switch( info.type ) + { + case SLightInfo::Directional: + typeCB->setCurrentIndex( DIRECTIONAL ); + break; + case SLightInfo::Point: + typeCB->setCurrentIndex( POINT ); + break; + case SLightInfo::Spot: + typeCB->setCurrentIndex( SPOT ); + break; + } + + xSB->setValue( info.posOrDir[ 0 ] ); + ySB->setValue( info.posOrDir[ 1 ] ); + zSB->setValue( info.posOrDir[ 2 ] ); + + constAttnButton->setValue( info.constAttn ); + linearAttnButton->setValue( info.linAttn ); + quadAttnButton->setValue( info.quadAttn ); + + setButtonColor( AMBIENT, info.ambColor[ 0 ] * 255.0f, + info.ambColor[ 1 ] * 255.0f, + info.ambColor[ 2 ] * 255.0f ); + + setButtonColor( DIFFUSE, info.diffColor[ 0 ] * 255.0f, + info.diffColor[ 1 ] * 255.0f, + info.diffColor[ 2 ] * 255.0f ); + + setButtonColor( SPECULAR, info.specColor[ 0 ] * 255.0f, + info.specColor[ 1 ] * 255.0f, + info.specColor[ 2 ] * 255.0f ); + + setupChangeConnections(); + } + + void LightsWidget::saveLight( unsigned char light ) + { + SLightInfo info; + + info.enabled = enableCB->isChecked(); + switch( typeCB->currentIndex() ) + { + case DIRECTIONAL: + info.type = SLightInfo::Directional; + break; + case POINT: + info.type = SLightInfo::Point; + break; + case SPOT: + info.type = SLightInfo::Spot; + break; + } + + info.posOrDir[ 0 ] = static_cast< float >( xSB->value() ); + info.posOrDir[ 1 ] = static_cast< float >( ySB->value() ); + info.posOrDir[ 2 ] = static_cast< float >( zSB->value() ); + + info.constAttn = static_cast< float >( constAttnButton->value() ); + info.linAttn = static_cast< float >( linearAttnButton->value() ); + info.quadAttn = static_cast< float >( quadAttnButton->value() ); + + info.ambColor[ 0 ] = buttonColors[ AMBIENT ][ 0 ] / 255.0f; + info.ambColor[ 1 ] = buttonColors[ AMBIENT ][ 1 ] / 255.0f; + info.ambColor[ 2 ] = buttonColors[ AMBIENT ][ 2 ] / 255.0f; + info.diffColor[ 0 ] = buttonColors[ DIFFUSE ][ 0 ] / 255.0f; + info.diffColor[ 1 ] = buttonColors[ DIFFUSE ][ 1 ] / 255.0f; + info.diffColor[ 2 ] = buttonColors[ DIFFUSE ][ 2 ] / 255.0f; + info.specColor[ 0 ] = buttonColors[ SPECULAR ][ 0 ] / 255.0f; + info.specColor[ 1 ] = buttonColors[ SPECULAR ][ 1 ] / 255.0f; + info.specColor[ 2 ] = buttonColors[ SPECULAR ][ 2 ] / 255.0f; + + iface->setLightInfo( light, info ); + } + + void LightsWidget::applyChanges() + { + int row = lightList->currentRow(); + saveLight( static_cast< unsigned char >( row ) ); + } + } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.h index 6e1068326..691ea9b7e 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.h @@ -18,9 +18,52 @@ #ifndef LIGHTS_WIDGET_H #define LIGHTS_WIDGET_H +#include "ui_lights_widget.h" namespace MaterialEditor { + class CNel3DInterface; + + class LightsWidget : public QWidget, public Ui::LightsWidget + { + Q_OBJECT + + private: + void setButtonColor( unsigned char butt, int r, int g, int b ); + + public: + LightsWidget( QWidget *parent = NULL ); + ~LightsWidget(); + void setNL3DIface( CNel3DInterface *iface ){ this->iface = iface; } + void loadValues(); + + private Q_SLOTS: + void onAmbButtonClicked(); + void onDiffButtonClicked(); + void onSpecButtonClicked(); + void onLightChanged( int light ); + void onChanges(); + + private: + void setupConnections(); + void setupChangeConnections(); + void disableChangeConnections(); + void loadLight( unsigned char light ); + void saveLight( unsigned char light ); + void applyChanges(); + + CNel3DInterface *iface; + + enum LightType + { + Directional, + Point, + Spot + }; + + int buttonColors[ 3 ][ 3 ]; + }; + } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.ui b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.ui index 594d66668..ef996e9b5 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.ui +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/lights_widget.ui @@ -1,18 +1,228 @@ LightsWidget - + 0 0 - 400 - 300 + 495 + 434 Light settings + + + + + Enable + + + + + + + Type + + + + + 10 + 20 + 99 + 20 + + + + + + + + + + 0 + 0 + + + + Direction or Position + + + + + + X + + + + + + + -9999.000000000000000 + + + 9999.000000000000000 + + + + + + + Y + + + + + + + -9999.000000000000000 + + + 9999.000000000000000 + + + + + + + Z + + + + + + + -9999.000000000000000 + + + 9999.000000000000000 + + + + + + + + + + Attenuation + + + + + + Constant + + + + + + + + + + Linear + + + + + + + + + + Quadratic + + + + + + + + + + + + + Color + + + + + + Ambient + + + + + + + + 0 + 0 + + + + + + + + + + + Diffuse + + + + + + + + 0 + 0 + + + + + + + + + + + Specular + + + + + + + + 0 + 0 + + + + + + + + + + + + + + + 0 + 0 + + + + + diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp index 7b29f99fd..bcdd8847f 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.cpp @@ -22,6 +22,7 @@ #include "nel3d_interface.h" #include "viewport_widget.h" #include "fog_widget.h" +#include "lights_widget.h" #include "../core/icore.h" #include "../core/core_constants.h" @@ -56,6 +57,9 @@ namespace MaterialEditor passesWidget->setNel3dIface( nl3dIface ); fogWidget = new FogWidget(); fogWidget->setNl3DIface( nl3dIface ); + lightsWidget = new LightsWidget(); + lightsWidget->setNL3DIface( nl3dIface ); + //passesWidget->onMaterialLoaded(); //materialSplitter->onMaterialLoaded(); @@ -72,6 +76,8 @@ namespace MaterialEditor { delete fogWidget; fogWidget = NULL; + delete lightsWidget; + lightsWidget = NULL; delete shaderWidget; shaderWidget = NULL; delete passesWidget; @@ -280,6 +286,8 @@ namespace MaterialEditor void MaterialEditorWindow::onLightsClicked() { + lightsWidget->loadValues(); + lightsWidget->show(); } void MaterialEditorWindow::createMenus() @@ -337,7 +345,7 @@ namespace MaterialEditor mm->addAction( a ); a = new QAction( tr( "Lights" ), NULL ); - connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onLightsSceneClicked() ) ); + connect( a, SIGNAL( triggered( bool ) ), this, SLOT( onLightsClicked() ) ); mm->addAction( a ); } diff --git a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h index e634289fe..2abf2a4dc 100644 --- a/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h +++ b/code/nel/tools/3d/object_viewer_qt/src/plugins/material_editor/material_editor_window.h @@ -28,6 +28,7 @@ namespace MaterialEditor class MaterialSplitter; class ViewPortWidget; class FogWidget; + class LightsWidget; class MaterialEditorWindow: public QMainWindow { @@ -68,6 +69,7 @@ private: MaterialSplitter *materialSplitter; ViewPortWidget *viewPort; FogWidget *fogWidget; + LightsWidget *lightsWidget; Ui::MaterialEditorWindow m_ui; 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 be170a8a0..5112069f5 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 @@ -454,8 +454,8 @@ namespace MaterialEditor ld->setConstantAttenuation( 1.0f ); ld->setLinearAttenuation( 0.0f ); ld->setQuadraticAttenuation( 0.0f ); - driver->setLight( 1, *ld ); - driver->enableLight( 1, true ); + driver->setLight( 0, *ld ); + driver->enableLight( 0, true ); delete ld; ld = NULL; @@ -602,6 +602,116 @@ namespace MaterialEditor setBGColor( c.R, c.G, c.B, c.A ); } + unsigned char CNel3DInterface::getMaxLights() const + { + return driver->getMaxDriverLights(); + } + + void CNel3DInterface::getLightInfo( unsigned char light, SLightInfo &info ) + { + info.enabled = driver->isLightEnabled( light ); + + NL3D::ULight *u = driver->getLight( light ); + info.ambColor[ 0 ] = u->getAmbiant().R / 255.0f; + info.ambColor[ 1 ] = u->getAmbiant().G / 255.0f; + info.ambColor[ 2 ] = u->getAmbiant().B / 255.0f; + info.ambColor[ 3 ] = u->getAmbiant().A / 255.0f; + + info.diffColor[ 0 ] = u->getDiffuse().R / 255.0f; + info.diffColor[ 1 ] = u->getDiffuse().G / 255.0f; + info.diffColor[ 2 ] = u->getDiffuse().B / 255.0f; + info.diffColor[ 3 ] = u->getDiffuse().A / 255.0f; + + info.specColor[ 0 ] = u->getSpecular().R / 255.0f; + info.specColor[ 1 ] = u->getSpecular().G / 255.0f; + info.specColor[ 2 ] = u->getSpecular().B / 255.0f; + info.specColor[ 3 ] = u->getSpecular().A / 255.0f; + + info.constAttn = u->getConstantAttenuation(); + info.linAttn = u->getLinearAttenuation(); + info.quadAttn = u->getQuadraticAttenuation(); + + switch( u->getMode() ) + { + case NL3D::ULight::DirectionalLight: + info.type = SLightInfo::Directional; + break; + + case NL3D::ULight::PointLight: + info.type = SLightInfo::Point; + break; + + case NL3D::ULight::SpotLight: + info.type = SLightInfo::Spot; + break; + } + + if( info.type == SLightInfo::Directional ) + { + info.posOrDir[ 0 ] = u->getDirection().x; + info.posOrDir[ 1 ] = u->getDirection().y; + info.posOrDir[ 2 ] = u->getDirection().z; + } + else + { + info.posOrDir[ 0 ] = u->getPosition().x; + info.posOrDir[ 1 ] = u->getPosition().y; + info.posOrDir[ 2 ] = u->getPosition().z; + } + + delete u; + } + + void CNel3DInterface::setLightInfo( unsigned char light, const SLightInfo &info ) + { + NL3D::ULight *u = NL3D::ULight::createLight(); + + NLMISC::CRGBA c; + c.R = info.ambColor[ 0 ] * 255.0f; + c.G = info.ambColor[ 1 ] * 255.0f; + c.B = info.ambColor[ 2 ] * 255.0f; + c.A = 255; + u->setAmbiant( c ); + + c.R = info.diffColor[ 0 ] * 255.0f; + c.G = info.diffColor[ 1 ] * 255.0f; + c.B = info.diffColor[ 2 ] * 255.0f; + u->setDiffuse( c ); + + c.R = info.specColor[ 0 ] * 255.0f; + c.G = info.specColor[ 1 ] * 255.0f; + c.B = info.specColor[ 2 ] * 255.0f; + u->setSpecular( c ); + + switch( info.type ) + { + case SLightInfo::Directional: + u->setMode( NL3D::ULight::DirectionalLight ); + break; + case SLightInfo::Point: + u->setMode( NL3D::ULight::PointLight ); + break; + case SLightInfo::Spot: + u->setMode( NL3D::ULight::SpotLight ); + break; + } + + if( info.type == SLightInfo::Directional ) + u->setDirection( NLMISC::CVector( info.posOrDir[ 0 ], info.posOrDir[ 1 ], info.posOrDir[ 2 ] ) ); + else + u->setPosition( NLMISC::CVector( info.posOrDir[ 0 ], info.posOrDir[ 1 ], info.posOrDir[ 2 ] ) ); + + u->setConstantAttenuation( info.constAttn ); + u->setLinearAttenuation( info.linAttn ); + u->setQuadraticAttenuation( info.quadAttn ); + + driver->setLight( light, *u ); + driver->enableLight( light, info.enabled ); + + delete u; + u = NULL; + } + void CNel3DInterface::setupCamera() { NLMISC::CAABBox bbox; 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 51a8f76ba..f76d29227 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 @@ -179,6 +179,39 @@ namespace MaterialEditor }; + struct SLightInfo + { + enum LightType + { + Directional, + Point, + Spot + }; + + bool enabled; + unsigned char type; + float posOrDir[ 3 ]; + float ambColor[ 3 ]; + float diffColor[ 3 ]; + float specColor[ 3 ]; + float constAttn; + float linAttn; + float quadAttn; + + SLightInfo() + { + enabled = true; + type = Directional; + posOrDir[ 0 ] = posOrDir[ 1 ] = posOrDir[ 2 ] = 0.0f; + ambColor[ 0 ] = ambColor[ 1 ] = ambColor[ 2 ] = 255; + diffColor[ 0 ] = diffColor[ 1 ] = diffColor[ 2 ] = 255; + specColor[ 0 ] = specColor[ 1 ] = specColor[ 2 ] = 255; + constAttn = 1.0f; + linAttn = quadAttn = 0.0f; + } + + }; + /// Proxy class for Nel3D, so the material editor and Nel3D can interface class CNel3DInterface { @@ -268,6 +301,10 @@ namespace MaterialEditor void getFogSettings( SFogSettings &s ); void setFogSettings( const SFogSettings &s ); + unsigned char getMaxLights() const; + void getLightInfo( unsigned char light, SLightInfo &info ); + void setLightInfo( unsigned char light, const SLightInfo &info ); + void setBGColor( unsigned char R, unsigned char G, unsigned char B, unsigned char A ){ bgColor[ 0 ] = R; bgColor[ 1 ] = G;