From 79850824c4bdda88056f814d874e7cd81dbf390f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C3=ABl=20Lemaire?= Date: Tue, 10 Jul 2012 19:39:12 +0000 Subject: [PATCH] paysages : Terrain canvas (WIP). git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@385 b1fd45b6-86a6-48da-8261-f70d1f35bdcc --- TODO | 15 +++++--- gui_qt/baseform.cpp | 4 +- gui_qt/baseform.h | 3 +- gui_qt/baseformlayer.cpp | 5 +++ gui_qt/baseformlayer.h | 17 +++++++++ gui_qt/basepreview.cpp | 5 ++- gui_qt/dialoglayers.cpp | 73 ++++++++++++++++++++++++++++++++++++ gui_qt/dialoglayers.h | 37 ++++++++++++++++++ gui_qt/formterrain.cpp | 8 +++- gui_qt/formterraincanvas.cpp | 22 +++++++++++ gui_qt/formterraincanvas.h | 27 +++++++++++++ gui_qt/inputlayers.cpp | 13 ++++++- gui_qt/inputlayers.h | 5 ++- lib_paysages/textures.c | 6 +-- 14 files changed, 222 insertions(+), 18 deletions(-) create mode 100644 gui_qt/baseformlayer.cpp create mode 100644 gui_qt/baseformlayer.h create mode 100644 gui_qt/dialoglayers.cpp create mode 100644 gui_qt/dialoglayers.h create mode 100644 gui_qt/formterraincanvas.cpp create mode 100644 gui_qt/formterraincanvas.h diff --git a/TODO b/TODO index 1c84f7d..7bed803 100644 --- a/TODO +++ b/TODO @@ -8,17 +8,21 @@ Technology Preview 2 : - Add "hardness to light" and shadow control ("minimum lighting") to material. - Add logarithmic sliders for some float values. - Improve previews. - => Add user markers on OSD -- Add a zone editor dialog for localized textures. -- Add a terrain modifier dialog with zones. -- Use the curve editor in noise editor + => Add user markers on OSD. + => Add areas marking. +- Start a terrain editor (see mockup). +- Improve textures (current model is greatly incorrect). + => Separate models (basic texture and covering texture). + => Covering texture height should inpact terrain height. + => Add texture shadowing. +- Use the curve editor in noise editor (option). - Add a noise filler (and maybe noise intervals ?). - Fix the distorted sun appearance. - Improve curve editor. => Add curve modes => Add logarithmic mode => Add zoom and scrolling -- Fix "RGB parameters out of range" (and segfault) on preview while moving render params fast in render tab. +- Fix "RGB parameters out of range" (and segfault) on some previews, caused by data changing during a chunk computation. => May need to change the updateData system. => Previews need to be paused while updating data. - Lock some previews together (eg: terrain height and colored preview). @@ -31,7 +35,6 @@ Technology Preview 3 : - Use bicubic interpolation for antialiasing. - Allow for larger renders/antialias (will need several two-pass chunks). - Add basic vegetation system ? -- Texture shadowing and self-shadowing ? - Add a progress indicator on previews. - Multi threaded first pass. - Mark modified tabs and ask for losing modifications (idem for layers). diff --git a/gui_qt/baseform.cpp b/gui_qt/baseform.cpp index 22e709d..5463568 100644 --- a/gui_qt/baseform.cpp +++ b/gui_qt/baseform.cpp @@ -412,9 +412,9 @@ BaseInput* BaseForm::addInputEnum(QString label, int* value, const QStringList& return addInput(new InputEnum(_form, label, value, values)); } -BaseInput* BaseForm::addInputLayers(QString label, Layers* value) +BaseInput* BaseForm::addInputLayers(QString label, Layers* value, FormLayerBuilder form_builder) { - return addInput(new InputLayers(_form, label, value)); + return addInput(new InputLayers(_form, label, value, form_builder)); } void BaseForm::updatePreviews() diff --git a/gui_qt/baseform.h b/gui_qt/baseform.h index ab1d558..c648f28 100644 --- a/gui_qt/baseform.h +++ b/gui_qt/baseform.h @@ -7,6 +7,7 @@ #include #include "basepreview.h" #include "baseinput.h" +#include "dialoglayers.h" #include "../lib_paysages/shared/types.h" #include "../lib_paysages/noise.h" #include "../lib_paysages/curve.h" @@ -56,7 +57,7 @@ protected: BaseInput* addInputCurve(QString label, Curve* value, double xmin, double xmax, double ymin, double ymax, QString xlabel, QString ylabel); BaseInput* addInputMaterial(QString label, SurfaceMaterial* material); BaseInput* addInputEnum(QString label, int* value, const QStringList& values); - BaseInput* addInputLayers(QString label, Layers* value); + BaseInput* addInputLayers(QString label, Layers* value, FormLayerBuilder form_builder); void updatePreviews(); void disablePreviewsUpdate(); diff --git a/gui_qt/baseformlayer.cpp b/gui_qt/baseformlayer.cpp new file mode 100644 index 0000000..629de47 --- /dev/null +++ b/gui_qt/baseformlayer.cpp @@ -0,0 +1,5 @@ +#include "baseformlayer.h" + +BaseFormLayer::BaseFormLayer(QWidget* parent) : BaseForm(parent, false, true) +{ +} diff --git a/gui_qt/baseformlayer.h b/gui_qt/baseformlayer.h new file mode 100644 index 0000000..a4aef00 --- /dev/null +++ b/gui_qt/baseformlayer.h @@ -0,0 +1,17 @@ +#ifndef _PAYSAGES_QT_BASEFORMLAYER_H_ +#define _PAYSAGES_QT_BASEFORMLAYER_H_ + +/* Base form, with automatic layer control */ + +#include "baseform.h" + +class BaseFormLayer:public BaseForm +{ + Q_OBJECT + +public: + BaseFormLayer(QWidget* parent); + +}; + +#endif diff --git a/gui_qt/basepreview.cpp b/gui_qt/basepreview.cpp index bdfd7e9..68231d3 100644 --- a/gui_qt/basepreview.cpp +++ b/gui_qt/basepreview.cpp @@ -329,7 +329,7 @@ void BasePreview::savePack(PackStream* stream) { packWriteDouble(stream, &this->xoffset); packWriteDouble(stream, &this->yoffset); - packWriteDouble(stream, &this->scaling); + packWriteDouble(stream, &this->scalingbase); // TODO Save choices and toggles } @@ -338,10 +338,11 @@ void BasePreview::loadPack(PackStream* stream) { packReadDouble(stream, &this->xoffset); packReadDouble(stream, &this->yoffset); - packReadDouble(stream, &this->scaling); + packReadDouble(stream, &this->scalingbase); // TODO Save choices and toggles + updateScaling(); emit contentChange(); } diff --git a/gui_qt/dialoglayers.cpp b/gui_qt/dialoglayers.cpp new file mode 100644 index 0000000..df7d29d --- /dev/null +++ b/gui_qt/dialoglayers.cpp @@ -0,0 +1,73 @@ +#include "dialoglayers.h" + +#include +#include +#include +#include +#include "baseformlayer.h" + +/**************** Dialog form ****************/ +DialogLayers::DialogLayers(QWidget *parent, Layers* layers, QString title, FormLayerBuilder form_builder) : DialogWithPreview(parent) +{ + QPushButton* button; + QWidget* buttons; + + _layers = layers; + + setLayout(new QVBoxLayout()); + + _form = form_builder(this); + _form->hideButtons(); + layout()->addWidget(_form); + + buttons = new QWidget(this); + buttons->setLayout(new QHBoxLayout()); + layout()->addWidget(buttons); + layout()->setAlignment(buttons, Qt::AlignBottom); + + button = new QPushButton(tr("Validate"), buttons); + buttons->layout()->addWidget(button); + QObject::connect(button, SIGNAL(clicked()), this, SLOT(accept())); + + button = new QPushButton(tr("Reset"), buttons); + buttons->layout()->addWidget(button); + QObject::connect(button, SIGNAL(clicked()), this, SLOT(revert())); + + button = new QPushButton(tr("Cancel"), buttons); + buttons->layout()->addWidget(button); + QObject::connect(button, SIGNAL(clicked()), this, SLOT(reject())); + + setWindowTitle(tr("Paysages 3D - ") + title); +} + +DialogLayers::~DialogLayers() +{ +} + +bool DialogLayers::editLayers(QWidget* parent, Layers* layers, QString title, FormLayerBuilder form_builder) +{ + int result; + + DialogLayers* dialog = new DialogLayers(parent, layers, title, form_builder); + result = dialog->exec(); + + delete dialog; + + return result != 0; +} + +void DialogLayers::closeEvent(QCloseEvent* e) +{ + reject(); +} + +void DialogLayers::accept() +{ + _form->applyConfig(); + QDialog::accept(); +} + +void DialogLayers::revert() +{ + _form->revertConfig(); +} diff --git a/gui_qt/dialoglayers.h b/gui_qt/dialoglayers.h new file mode 100644 index 0000000..b2397a2 --- /dev/null +++ b/gui_qt/dialoglayers.h @@ -0,0 +1,37 @@ +#ifndef _PAYSAGES_QT_DIALOGLAYERS_H_ +#define _PAYSAGES_QT_DIALOGLAYERS_H_ + +/* Dialog for generic layers control */ + +#include +#include "tools.h" + +#include "../lib_paysages/layers.h" + +class DialogLayers; +class BaseFormLayer; + +typedef BaseFormLayer* (*FormLayerBuilder)(DialogLayers* parent); + +class DialogLayers : public DialogWithPreview +{ + Q_OBJECT +public: + explicit DialogLayers(QWidget* parent, Layers* layers, QString title, FormLayerBuilder form_builder); + ~DialogLayers(); + + static bool editLayers(QWidget* parent, Layers* layers, QString title, FormLayerBuilder form_builder); + +public slots: + virtual void accept(); + void revert(); + +protected: + virtual void closeEvent(QCloseEvent* e); + +private: + BaseFormLayer* _form; + Layers* _layers; +}; + +#endif diff --git a/gui_qt/formterrain.cpp b/gui_qt/formterrain.cpp index 7b196e9..72e1ebc 100644 --- a/gui_qt/formterrain.cpp +++ b/gui_qt/formterrain.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "formterraincanvas.h" #include "tools.h" #include "../lib_paysages/terrain.h" @@ -140,6 +141,11 @@ private: }; /**************** Form ****************/ +static BaseFormLayer* _formBuilderCanvas(DialogLayers* parent) +{ + return new FormTerrainCanvas(parent); +} + FormTerrain::FormTerrain(QWidget *parent): BaseForm(parent) { @@ -154,7 +160,7 @@ FormTerrain::FormTerrain(QWidget *parent): addInputDouble(tr("Height"), &_definition.height_factor, 0.0, 20.0, 0.1, 1.0); addInputDouble(tr("Scaling"), &_definition.scaling, 1.0, 50.0, 0.1, 5.0); addInputDouble(tr("Shadow smoothing"), &_definition.shadow_smoothing, 0.0, 0.3, 0.003, 0.03); - addInputLayers(tr("Canvases"), _definition.canvases); + addInputLayers(tr("Canvases"), _definition.canvases, _formBuilderCanvas); revertConfig(); } diff --git a/gui_qt/formterraincanvas.cpp b/gui_qt/formterraincanvas.cpp new file mode 100644 index 0000000..c40497a --- /dev/null +++ b/gui_qt/formterraincanvas.cpp @@ -0,0 +1,22 @@ +#include "formterraincanvas.h" + +/**************** Form ****************/ +FormTerrainCanvas::FormTerrainCanvas(QWidget *parent): + BaseFormLayer(parent) +{ +} + +void FormTerrainCanvas::revertConfig() +{ + BaseFormLayer::revertConfig(); +} + +void FormTerrainCanvas::applyConfig() +{ + BaseFormLayer::applyConfig(); +} + +void FormTerrainCanvas::configChangeEvent() +{ + BaseFormLayer::configChangeEvent(); +} diff --git a/gui_qt/formterraincanvas.h b/gui_qt/formterraincanvas.h new file mode 100644 index 0000000..3f3a2c0 --- /dev/null +++ b/gui_qt/formterraincanvas.h @@ -0,0 +1,27 @@ +#ifndef _PAYSAGES_QT_FORMTERRAINCANVAS_H_ +#define _PAYSAGES_QT_FORMTERRAINCANVAS_H_ + +#include +#include "basepreview.h" +#include "baseformlayer.h" + +class FormTerrainCanvas : public BaseFormLayer +{ + Q_OBJECT + +public: + FormTerrainCanvas(QWidget* parent); + +public slots: + virtual void revertConfig(); + virtual void applyConfig(); + +protected slots: + virtual void configChangeEvent(); + +private: +// BasePreview* previewHeight; +// BasePreview* previewColor; +}; + +#endif diff --git a/gui_qt/inputlayers.cpp b/gui_qt/inputlayers.cpp index 88fa930..eae813f 100644 --- a/gui_qt/inputlayers.cpp +++ b/gui_qt/inputlayers.cpp @@ -2,15 +2,19 @@ #include #include +#include "dialoglayers.h" -InputLayers::InputLayers(QWidget* form, QString label, Layers* value): +InputLayers::InputLayers(QWidget* form, QString label, Layers* value, FormLayerBuilder form_builder): BaseInput(form, label) { _value = value; + _form_builder = form_builder; _preview = new QLabel(form); ((QLabel*)_preview)->setAlignment(Qt::AlignCenter); _control = new QPushButton(tr("Editer"), form); + + connect(_control, SIGNAL(clicked()), this, SLOT(editLayers())); } void InputLayers::updatePreview() @@ -19,3 +23,10 @@ void InputLayers::updatePreview() BaseInput::updatePreview(); } + +void InputLayers::editLayers() +{ + if (DialogLayers::editLayers(_control, _value, _label->text(), _form_builder)) + { + } +} diff --git a/gui_qt/inputlayers.h b/gui_qt/inputlayers.h index ed55546..b6ba424 100644 --- a/gui_qt/inputlayers.h +++ b/gui_qt/inputlayers.h @@ -3,6 +3,7 @@ #include #include "baseinput.h" +#include "dialoglayers.h" #include "../lib_paysages/layers.h" class InputLayers:public BaseInput @@ -10,13 +11,15 @@ class InputLayers:public BaseInput Q_OBJECT public: - InputLayers(QWidget* form, QString label, Layers* value); + InputLayers(QWidget* form, QString label, Layers* value, FormLayerBuilder form_builder); public slots: virtual void updatePreview(); + void editLayers(); private: Layers* _value; + FormLayerBuilder _form_builder; }; #endif diff --git a/lib_paysages/textures.c b/lib_paysages/textures.c index 138d8f7..191290a 100644 --- a/lib_paysages/textures.c +++ b/lib_paysages/textures.c @@ -401,6 +401,7 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl /* Pre compute alpha channel */ start = 0; last_height = results[0].thickness; + results[0].thickness = 1.0; for (i = 1; i <= definition->nblayers; i++) { thickness = results[i].thickness - last_height; @@ -419,7 +420,6 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl } else { - color = COLOR_GREEN; results[i].thickness = 1.0; } @@ -427,8 +427,6 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl { start = i; } - - colorMask(&result, &color); } /* Apply colors and alphas */ @@ -442,7 +440,7 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl { result = COLOR_GREEN; } - for (i = start; i <= definition->nblayers; i++) + for (i = start + 1; i <= definition->nblayers; i++) { if (results[i].thickness) {