WIP on texture previews

This commit is contained in:
Michaël Lemaire 2013-08-24 00:51:27 +02:00
parent 2c79175304
commit 7cd74b2c8a
12 changed files with 203 additions and 7 deletions

View file

@ -43,7 +43,7 @@ bool FreeFormHelper::eventFilter(QObject* object, QEvent* event)
{
preview_size = QSize(320, 320);
}
else if (form_size.width() < 1000 || form_size.height() < 700)
else if (form_size.width() < 1100 || form_size.height() < 750)
{
preview_size = QSize(200, 200);
}

View file

@ -70,7 +70,9 @@ HEADERS += \
common/DrawingWidget.h \
lighting/SmallPreviewColor.h \
lighting/SmallPreviewHues.h \
textures/PreviewLayerCoverage.h
textures/PreviewLayerCoverage.h \
textures/PreviewLayerLook.h \
textures/PreviewCumul.h
SOURCES += \
terrain/widgetheightmap.cpp \
@ -126,7 +128,9 @@ SOURCES += \
common/DrawingWidget.cpp \
lighting/SmallPreviewColor.cpp \
lighting/SmallPreviewHues.cpp \
textures/PreviewLayerCoverage.cpp
textures/PreviewLayerCoverage.cpp \
textures/PreviewLayerLook.cpp \
textures/PreviewCumul.cpp
FORMS += \
terrain/dialogterrainpainting.ui \

View file

@ -0,0 +1,44 @@
#include "PreviewCumul.h"
#include "editing/basepreview.h"
#include "rendering/textures/tex_preview.h"
void PreviewCumul::setTextures(TexturesDefinition* textures)
{
this->textures = textures;
}
void PreviewCumul::setLayer(int layer)
{
this->layer = layer;
}
void PreviewCumul::bindEvent(BasePreview* preview)
{
preview->addOsd(QString("geolocation"));
//preview->configHdrToneMapping(true);
preview->configScaling(20.0, 1000.0, 20.0, 200.0);
preview->configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
}
void PreviewCumul::updateEvent()
{
if (textures)
{
TexturesPreviewCumul_bind(renderer, textures);
}
}
Color PreviewCumul::getColor2D(double x, double y, double scaling)
{
if (textures)
{
return TexturesPreviewCumul_getColor(renderer, x, y, scaling, layer);
}
else
{
return COLOR_BLACK;
}
}

View file

@ -0,0 +1,24 @@
#ifndef EDITING_TEXTURES_PREVIEWCUMUL_H
#define EDITING_TEXTURES_PREVIEWCUMUL_H
#include "editing/common/previewrenderer.h"
class BasePreview;
class PreviewCumul : public PreviewRenderer
{
public:
void setTextures(TexturesDefinition* textures);
void setLayer(int layer);
protected:
virtual void bindEvent(BasePreview* preview);
virtual void updateEvent();
virtual Color getColor2D(double x, double y, double scaling);
private:
TexturesDefinition* textures = 0;
int layer;
};
#endif

View file

@ -35,4 +35,8 @@ Color PreviewLayerCoverage::getColor2D(double x, double y, double scaling)
{
return TexturesPreviewLayerCoverage_getColor(renderer, x, y, scaling, layer);
}
else
{
return COLOR_BLACK;
}
}

View file

@ -0,0 +1,42 @@
#include "PreviewLayerLook.h"
#include "editing/basepreview.h"
#include "rendering/textures/tex_preview.h"
void PreviewLayerLook::setTextures(TexturesDefinition* textures)
{
this->textures = textures;
}
void PreviewLayerLook::setLayer(int layer)
{
this->layer = layer;
}
void PreviewLayerLook::bindEvent(BasePreview* preview)
{
//preview->configHdrToneMapping(true);
preview->configScaling(0.01, 1.0, 0.01, 0.1);
}
void PreviewLayerLook::updateEvent()
{
if (textures)
{
TexturesPreviewLayerLook_bind(renderer, textures);
}
}
Color PreviewLayerLook::getColor2D(double x, double y, double scaling)
{
if (textures)
{
return TexturesPreviewLayerLook_getColor(renderer, x, y, scaling, layer);
}
else
{
return COLOR_BLACK;
}
}

View file

@ -0,0 +1,24 @@
#ifndef EDITING_TEXTURES_PREVIEWLAYERLOOK_H
#define EDITING_TEXTURES_PREVIEWLAYERLOOK_H
#include "editing/common/previewrenderer.h"
class BasePreview;
class PreviewLayerLook : public PreviewRenderer
{
public:
void setTextures(TexturesDefinition* textures);
void setLayer(int layer);
protected:
virtual void bindEvent(BasePreview* preview);
virtual void updateEvent();
virtual Color getColor2D(double x, double y, double scaling);
private:
TexturesDefinition* textures = 0;
int layer;
};
#endif

View file

@ -6,6 +6,8 @@
#include "rendering/scenery.h"
#include "previewmaterial.h"
#include "editing/textures/PreviewLayerCoverage.h"
#include "editing/textures/PreviewLayerLook.h"
#include "editing/textures/PreviewCumul.h"
MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui::MainTexturesForm)
{
@ -33,6 +35,14 @@ MainTexturesForm::MainTexturesForm(QWidget *parent) : QWidget(parent), ui(new Ui
preview_layer_coverage->setTextures(textures);
form_helper->addPreview(ui->preview_coverage, preview_layer_coverage);
preview_layer_look = new PreviewLayerLook();
preview_layer_look->setTextures(textures);
form_helper->addPreview(ui->preview_texture, preview_layer_look);
preview_cumul = new PreviewCumul();
preview_cumul->setTextures(textures);
form_helper->addPreview(ui->preview_cumul, preview_cumul);
form_helper->addPreset(tr("Rocks with grass"));
form_helper->addPreset(tr("Snow covered mountains"));
form_helper->addPreset(tr("Arid canyons"));

View file

@ -11,6 +11,8 @@ class MainTexturesForm;
class FreeFormHelper;
class FreeLayerHelper;
class PreviewLayerCoverage;
class PreviewLayerLook;
class PreviewCumul;
class MainTexturesForm : public QWidget
{
@ -37,6 +39,8 @@ private:
FreeFormHelper* form_helper;
FreeLayerHelper* layer_helper;
PreviewLayerCoverage* preview_layer_coverage;
PreviewLayerLook* preview_layer_look;
PreviewCumul* preview_cumul;
};
#endif // MAINTEXTURESFORM_H

View file

@ -36,9 +36,9 @@ static void _fakeGetLightingStatus(Renderer* renderer, LightStatus* status, Vect
UNUSED(normal);
UNUSED(opaque);
light.color.r = 0.8;
light.color.g = 0.8;
light.color.b = 0.8;
light.color.r = 1.0;
light.color.g = 1.0;
light.color.b = 1.0;
light.direction.x = -0.7;
light.direction.y = -0.7;
light.direction.z = 0.7;

View file

@ -7,7 +7,7 @@
void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition)
{
TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
sceneryGetTerrain(renderer->terrain->definition);
sceneryGetTerrain(terrain);
TerrainRendererClass.bind(renderer, terrain);
TerrainDefinitionClass.destroy(terrain);
@ -39,3 +39,35 @@ Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double
return result;
}
void TexturesPreviewLayerLook_bind(Renderer* renderer, TexturesDefinition* definition)
{
TexturesRendererClass.bind(renderer, definition);
}
Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y, double scaling, int layer)
{
UNUSED(scaling);
UNUSED(layer);
return renderer->textures->applyToTerrain(renderer, x, y).final_color;
}
void TexturesPreviewCumul_bind(Renderer* renderer, TexturesDefinition* definition)
{
TerrainDefinition* terrain = (TerrainDefinition*)TerrainDefinitionClass.create();
sceneryGetTerrain(terrain);
TerrainRendererClass.bind(renderer, terrain);
TerrainDefinitionClass.destroy(terrain);
TexturesRendererClass.bind(renderer, definition);
}
Color TexturesPreviewCumul_getColor(Renderer* renderer, double x, double y, double scaling, int layer)
{
UNUSED(scaling);
UNUSED(layer);
return renderer->textures->applyToTerrain(renderer, x, y).final_color;
}

View file

@ -12,6 +12,14 @@ extern "C" {
void TexturesPreviewLayerCoverage_bind(Renderer* renderer, TexturesDefinition* definition);
Color TexturesPreviewLayerCoverage_getColor(Renderer* renderer, double x, double y, double scaling, int layer);
/* Single layer look */
void TexturesPreviewLayerLook_bind(Renderer* renderer, TexturesDefinition* definition);
Color TexturesPreviewLayerLook_getColor(Renderer* renderer, double x, double y, double scaling, int layer);
/* Cumulative color preview */
void TexturesPreviewCumul_bind(Renderer* renderer, TexturesDefinition* definition);
Color TexturesPreviewCumul_getColor(Renderer* renderer, double x, double y, double scaling, int layer);
#ifdef __cplusplus
}
#endif