paysages : Terrain canvas (WIP).

git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@385 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
Michaël Lemaire 2012-07-10 19:39:12 +00:00 committed by ThunderK
parent 75487d286f
commit 79850824c4
14 changed files with 222 additions and 18 deletions

15
TODO
View file

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

View file

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

View file

@ -7,6 +7,7 @@
#include <QStringList>
#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();

5
gui_qt/baseformlayer.cpp Normal file
View file

@ -0,0 +1,5 @@
#include "baseformlayer.h"
BaseFormLayer::BaseFormLayer(QWidget* parent) : BaseForm(parent, false, true)
{
}

17
gui_qt/baseformlayer.h Normal file
View file

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

View file

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

73
gui_qt/dialoglayers.cpp Normal file
View file

@ -0,0 +1,73 @@
#include "dialoglayers.h"
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QWidget>
#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();
}

37
gui_qt/dialoglayers.h Normal file
View file

@ -0,0 +1,37 @@
#ifndef _PAYSAGES_QT_DIALOGLAYERS_H_
#define _PAYSAGES_QT_DIALOGLAYERS_H_
/* Dialog for generic layers control */
#include <QListWidget>
#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

View file

@ -3,6 +3,7 @@
#include <math.h>
#include <QColor>
#include <QSlider>
#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();
}

View file

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

View file

@ -0,0 +1,27 @@
#ifndef _PAYSAGES_QT_FORMTERRAINCANVAS_H_
#define _PAYSAGES_QT_FORMTERRAINCANVAS_H_
#include <QWidget>
#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

View file

@ -2,15 +2,19 @@
#include <QLabel>
#include <QPushButton>
#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))
{
}
}

View file

@ -3,6 +3,7 @@
#include <QWidget>
#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

View file

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