Implemented light controls.

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

@ -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)

@ -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.
*

@ -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);
// @}

@ -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;
// @}

@ -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 */) {}

@ -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(num<MaxLight)
return _UserLightEnable[num];
return false;
}
static const float sqrtFLT_MAX = (float) sqrtf(FLT_MAX);
// ***************************************************************************

@ -577,8 +577,12 @@ public:
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 setPerPixelLightingLight(CRGBA diffuse, CRGBA specular, float shininess);
virtual void setLightMapDynamicLight (bool enable, const CLight& light);

@ -54,6 +54,14 @@ void CDriverGL::setLight (uint8 num, const CLight& light)
}
CLight CDriverGL::getLight (uint8 num)
{
nlinfo( "This feature isn't yet implemented in this driver!" );
nlassert( false );
return CLight();
}
// ***************************************************************************
void CDriverGL::setLightInternal(uint8 num, const CLight& light)
{
@ -180,6 +188,14 @@ void CDriverGL::enableLight (uint8 num, bool enable)
_LightMapDynamicLightDirty= true;
}
bool CDriverGL::isLightEnabled (uint8 num)
{
if(num<_MaxDriverLight)
return _UserLightEnable[num];
return false;
}
// ***************************************************************************
void CDriverGL::enableLightInternal(uint8 num, bool enable)

@ -591,8 +591,12 @@ public:
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 setPerPixelLightingLight(CRGBA diffuse, CRGBA specular, float shininess);
virtual void setLightMapDynamicLight (bool enable, const CLight& light);

@ -50,6 +50,12 @@ void CDriverGL3::setLight (uint8 num, const CLight& light)
}
CLight CDriverGL3::getLight (uint8 num)
{
return _UserLight[ num ];
}
// ***************************************************************************
void CDriverGL3::setLightInternal(uint8 num, const CLight& light)
{
@ -114,6 +120,14 @@ void CDriverGL3::enableLight (uint8 num, bool enable)
_LightMapDynamicLightDirty= true;
}
bool CDriverGL3::isLightEnabled (uint8 num)
{
if(num<_MaxDriverLight)
return _UserLightEnable[num];
return false;
}
// ***************************************************************************
void CDriverGL3::enableLightInternal(uint8 num, bool enable)

@ -1424,6 +1424,23 @@ void CDriverUser::setLight (uint8 num, const ULight& light)
CLightUser *plight= (CLightUser*)&light;
_Driver->setLight (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)
{

@ -15,8 +15,256 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
#include "lights_widget.h"
#include <QColorDialog>
#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 ) );
}
}

@ -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 ];
};
}

@ -1,18 +1,228 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>LightsWidget</class>
<widget class="QDialog" name="LightsWidget">
<widget class="QWidget" name="LightsWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>400</width>
<height>300</height>
<width>495</width>
<height>434</height>
</rect>
</property>
<property name="windowTitle">
<string>Light settings</string>
</property>
<layout class="QGridLayout" name="gridLayout_4">
<item row="0" column="2">
<widget class="QCheckBox" name="enableCB">
<property name="text">
<string>Enable</string>
</property>
</widget>
</item>
<item row="1" column="2">
<widget class="QGroupBox" name="groupBox_4">
<property name="title">
<string>Type</string>
</property>
<widget class="QComboBox" name="typeCB">
<property name="geometry">
<rect>
<x>10</x>
<y>20</y>
<width>99</width>
<height>20</height>
</rect>
</property>
</widget>
</widget>
</item>
<item row="2" column="2">
<widget class="QGroupBox" name="groupBox">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="title">
<string>Direction or Position</string>
</property>
<layout class="QGridLayout" name="gridLayout">
<item row="0" column="0">
<widget class="QLabel" name="label_2">
<property name="text">
<string>X</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="xSB">
<property name="minimum">
<double>-9999.000000000000000</double>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_3">
<property name="text">
<string>Y</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="ySB">
<property name="minimum">
<double>-9999.000000000000000</double>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_4">
<property name="text">
<string>Z</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="zSB">
<property name="minimum">
<double>-9999.000000000000000</double>
</property>
<property name="maximum">
<double>9999.000000000000000</double>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="3" column="2">
<widget class="QGroupBox" name="groupBox_3">
<property name="title">
<string>Attenuation</string>
</property>
<layout class="QGridLayout" name="gridLayout_3">
<item row="0" column="0">
<widget class="QLabel" name="label_8">
<property name="text">
<string>Constant</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QDoubleSpinBox" name="constAttnButton"/>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_9">
<property name="text">
<string>Linear</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QDoubleSpinBox" name="linearAttnButton"/>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_10">
<property name="text">
<string>Quadratic</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QDoubleSpinBox" name="quadAttnButton"/>
</item>
</layout>
</widget>
</item>
<item row="4" column="2" rowspan="2">
<widget class="QGroupBox" name="groupBox_2">
<property name="title">
<string>Color</string>
</property>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QLabel" name="label_5">
<property name="text">
<string>Ambient</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QPushButton" name="ambientButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Diffuse</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QPushButton" name="diffuseButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
<item row="2" column="0">
<widget class="QLabel" name="label_7">
<property name="text">
<string>Specular</string>
</property>
</widget>
</item>
<item row="2" column="1">
<widget class="QPushButton" name="specularButton">
<property name="sizePolicy">
<sizepolicy hsizetype="Fixed" vsizetype="Fixed">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
<property name="text">
<string/>
</property>
</widget>
</item>
</layout>
</widget>
</item>
<item row="0" column="0" rowspan="6">
<widget class="QListWidget" name="lightList">
<property name="sizePolicy">
<sizepolicy hsizetype="Preferred" vsizetype="Preferred">
<horstretch>0</horstretch>
<verstretch>0</verstretch>
</sizepolicy>
</property>
</widget>
</item>
</layout>
</widget>
<resources/>
<connections/>

@ -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 );
}

@ -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;

@ -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;

@ -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;

Loading…
Cancel
Save