2012-01-26 23:08:09 +00:00
|
|
|
#include "formtextures.h"
|
|
|
|
|
|
|
|
#include "../lib_paysages/textures.h"
|
|
|
|
#include "../lib_paysages/scenery.h"
|
2012-04-05 16:16:32 +00:00
|
|
|
#include "tools.h"
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
static TexturesDefinition _definition;
|
2012-04-03 19:33:40 +00:00
|
|
|
static TextureLayerDefinition _layer;
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
/**************** Previews ****************/
|
2012-04-03 19:33:40 +00:00
|
|
|
class PreviewTexturesCoverage:public BasePreview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewTexturesCoverage(QWidget* parent):BasePreview(parent)
|
|
|
|
{
|
|
|
|
_renderer = rendererCreate();
|
|
|
|
_renderer.render_quality = 3;
|
|
|
|
|
|
|
|
_preview_layer = texturesLayerCreateDefinition();
|
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
|
|
|
return QColor(0, 0, 0);
|
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
texturesLayerCopyDefinition(&_layer, &_preview_layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
Renderer _renderer;
|
|
|
|
TextureLayerDefinition _preview_layer;
|
|
|
|
};
|
|
|
|
|
|
|
|
class PreviewTexturesColor:public BasePreview
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
PreviewTexturesColor(QWidget* parent):BasePreview(parent)
|
|
|
|
{
|
2012-04-05 16:16:32 +00:00
|
|
|
LightDefinition light;
|
|
|
|
|
|
|
|
_preview_layer = texturesLayerCreateDefinition();
|
|
|
|
|
|
|
|
_lighting = lightingCreateDefinition();
|
|
|
|
light.color = COLOR_WHITE;
|
|
|
|
light.amplitude = 0.0;
|
|
|
|
light.direction.x = 0.0;
|
|
|
|
light.direction.y = -0.4794;
|
|
|
|
light.direction.z = 0.8776;
|
|
|
|
light.filtered = 0;
|
|
|
|
light.masked = 0;
|
|
|
|
light.reflection = 1.0;
|
|
|
|
lightingAddLight(&_lighting, light);
|
|
|
|
lightingValidateDefinition(&_lighting);
|
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
_renderer = rendererCreate();
|
|
|
|
_renderer.render_quality = 3;
|
2012-04-05 16:16:32 +00:00
|
|
|
_renderer.applyLightingToSurface = _applyLightingToSurface;
|
|
|
|
_renderer.customData[0] = &_lighting;
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
protected:
|
|
|
|
QColor getColor(double x, double y)
|
|
|
|
{
|
2012-04-05 16:16:32 +00:00
|
|
|
Vector3 location;
|
|
|
|
location.x = x * 0.01;
|
|
|
|
location.y = 0.0;
|
|
|
|
location.z = y * 0.01;
|
|
|
|
return colorToQColor(texturesGetLayerColor(&_preview_layer, &_renderer, location, this->scaling * 0.01));
|
2012-04-03 19:33:40 +00:00
|
|
|
}
|
|
|
|
void updateData()
|
|
|
|
{
|
|
|
|
texturesLayerCopyDefinition(&_layer, &_preview_layer);
|
|
|
|
}
|
|
|
|
private:
|
2012-04-05 16:16:32 +00:00
|
|
|
static Color _applyLightingToSurface(Renderer* renderer, Vector3 location, Vector3 normal, SurfaceMaterial material)
|
|
|
|
{
|
|
|
|
return lightingApplyToSurface((LightingDefinition*)renderer->customData[0], renderer, location, normal, material);
|
|
|
|
}
|
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
Renderer _renderer;
|
|
|
|
TextureLayerDefinition _preview_layer;
|
2012-04-05 16:16:32 +00:00
|
|
|
LightingDefinition _lighting;
|
2012-04-03 19:33:40 +00:00
|
|
|
};
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
/**************** Form ****************/
|
|
|
|
FormTextures::FormTextures(QWidget *parent):
|
2012-04-03 19:33:40 +00:00
|
|
|
BaseForm(parent, false, true)
|
2012-01-26 23:08:09 +00:00
|
|
|
{
|
|
|
|
_definition = texturesCreateDefinition();
|
2012-04-03 19:33:40 +00:00
|
|
|
_layer = texturesLayerCreateDefinition();
|
2012-01-26 23:08:09 +00:00
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
previewCoverage = new PreviewTexturesCoverage(this);
|
|
|
|
previewColor = new PreviewTexturesColor(this);
|
|
|
|
addPreview(previewCoverage, QString("Coverage preview"));
|
|
|
|
addPreview(previewColor, QString("Colored preview"));
|
2012-01-26 23:08:09 +00:00
|
|
|
|
2012-04-03 19:33:40 +00:00
|
|
|
addInputNoise(tr("Surface noise"), _layer.bump_noise);
|
|
|
|
addInputDouble(tr("Surface noise height"), &_layer.bump_height, 0.0, 0.5, 0.001, 0.05);
|
|
|
|
addInputDouble(tr("Surface noise scaling"), &_layer.bump_scaling, 0.1, 3.0, 0.01, 0.1);
|
|
|
|
addInputColor(tr("Base color"), &_layer.material.base);
|
|
|
|
addInputDouble(tr("Light reflection"), &_layer.material.reflection, 0.0, 1.0, 0.01, 0.1);
|
|
|
|
addInputDouble(tr("Light reflection shininess"), &_layer.material.shininess, 0.0, 20.0, 0.1, 1.0);
|
2012-01-26 23:08:09 +00:00
|
|
|
|
|
|
|
revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::revertConfig()
|
|
|
|
{
|
|
|
|
sceneryGetTextures(&_definition);
|
2012-04-03 19:33:40 +00:00
|
|
|
setLayerCount(texturesGetLayerCount(&_definition));
|
2012-01-26 23:08:09 +00:00
|
|
|
BaseForm::revertConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::applyConfig()
|
|
|
|
{
|
|
|
|
scenerySetTextures(&_definition);
|
|
|
|
BaseForm::applyConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::configChangeEvent()
|
|
|
|
{
|
2012-04-03 19:33:40 +00:00
|
|
|
texturesLayerCopyDefinition(&_layer, texturesGetLayer(&_definition, currentLayer()));
|
2012-01-26 23:08:09 +00:00
|
|
|
texturesValidateDefinition(&_definition);
|
|
|
|
BaseForm::configChangeEvent();
|
|
|
|
}
|
2012-04-03 19:33:40 +00:00
|
|
|
|
|
|
|
void FormTextures::layerAddedEvent()
|
|
|
|
{
|
|
|
|
if (texturesAddLayer(&_definition) >= 0)
|
|
|
|
{
|
|
|
|
BaseForm::layerAddedEvent();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::layerDeletedEvent(int layer)
|
|
|
|
{
|
|
|
|
texturesDeleteLayer(&_definition, layer);
|
|
|
|
|
|
|
|
BaseForm::layerDeletedEvent(layer);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FormTextures::layerSelectedEvent(int layer)
|
|
|
|
{
|
|
|
|
texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer);
|
|
|
|
|
|
|
|
BaseForm::layerSelectedEvent(layer);
|
|
|
|
}
|