paysages : Textures are now on the new layers system.
git-svn-id: https://subversion.assembla.com/svn/thunderk/paysages@419 b1fd45b6-86a6-48da-8261-f70d1f35bdcc
This commit is contained in:
parent
623fbaa2e3
commit
a98185c5e1
11 changed files with 212 additions and 329 deletions
3
TODO
3
TODO
|
@ -13,7 +13,8 @@ Technology Preview 2 :
|
||||||
- Improve terrain canvas editor.
|
- Improve terrain canvas editor.
|
||||||
=> Add GeoArea editor.
|
=> Add GeoArea editor.
|
||||||
=> Resample map on changing resolution.
|
=> Resample map on changing resolution.
|
||||||
=> Map loading should not choose arbitrary resolution.
|
=> GeoAreas should not overlap.
|
||||||
|
=> Map loading should not choose arbitrary resolution, choose the closer one and resample.
|
||||||
- Improve textures (current model is greatly incorrect).
|
- Improve textures (current model is greatly incorrect).
|
||||||
=> Separate models (basic texture and covering texture).
|
=> Separate models (basic texture and covering texture).
|
||||||
=> Covering texture height should inpact terrain height.
|
=> Covering texture height should inpact terrain height.
|
||||||
|
|
|
@ -4,38 +4,65 @@
|
||||||
|
|
||||||
BaseFormLayer::BaseFormLayer(QWidget* parent, Layers* layers) : BaseForm(parent, false, true)
|
BaseFormLayer::BaseFormLayer(QWidget* parent, Layers* layers) : BaseForm(parent, false, true)
|
||||||
{
|
{
|
||||||
_layers_original = layers;
|
_layers_original = NULL;
|
||||||
_layers_modified = layersCreateCopy(_layers_original);
|
_layers_modified = NULL;
|
||||||
|
if (layers)
|
||||||
|
{
|
||||||
|
setLayers(layers);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
BaseFormLayer::~BaseFormLayer()
|
BaseFormLayer::~BaseFormLayer()
|
||||||
{
|
{
|
||||||
layersDelete(_layers_modified);
|
if (_layers_modified)
|
||||||
|
{
|
||||||
|
layersDelete(_layers_modified);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFormLayer::revertConfig()
|
void BaseFormLayer::revertConfig()
|
||||||
{
|
{
|
||||||
layersCopy(_layers_original, _layers_modified);
|
if (_layers_original && _layers_modified)
|
||||||
layerSelectedEvent(currentLayer());
|
{
|
||||||
|
layersCopy(_layers_original, _layers_modified);
|
||||||
|
layerSelectedEvent(currentLayer());
|
||||||
|
}
|
||||||
|
|
||||||
BaseForm::revertConfig();
|
BaseForm::revertConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFormLayer::applyConfig()
|
void BaseFormLayer::applyConfig()
|
||||||
{
|
{
|
||||||
layersCopy(_layers_modified, _layers_original);
|
if (_layers_original && _layers_modified)
|
||||||
|
{
|
||||||
|
layersCopy(_layers_modified, _layers_original);
|
||||||
|
}
|
||||||
|
|
||||||
BaseForm::applyConfig();
|
BaseForm::applyConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseFormLayer::setLayers(Layers* layers)
|
||||||
|
{
|
||||||
|
_layers_original = layers;
|
||||||
|
if (_layers_modified)
|
||||||
|
{
|
||||||
|
layersDelete(_layers_modified);
|
||||||
|
}
|
||||||
|
_layers_modified = layersCreateCopy(_layers_original);
|
||||||
|
revertConfig();
|
||||||
|
}
|
||||||
|
|
||||||
void BaseFormLayer::afterLayerAdded(void*)
|
void BaseFormLayer::afterLayerAdded(void*)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFormLayer::configChangeEvent()
|
void BaseFormLayer::configChangeEvent()
|
||||||
{
|
{
|
||||||
layerApply(layersGetLayer(_layers_modified, currentLayer()));
|
if (_layers_modified)
|
||||||
layersValidate(_layers_modified);
|
{
|
||||||
|
layerApply(layersGetLayer(_layers_modified, currentLayer()));
|
||||||
|
layersValidate(_layers_modified);
|
||||||
|
}
|
||||||
|
|
||||||
BaseForm::configChangeEvent();
|
BaseForm::configChangeEvent();
|
||||||
}
|
}
|
||||||
|
@ -44,9 +71,12 @@ QStringList BaseFormLayer::getLayers()
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
|
|
||||||
for (int i = 0; i < layersCount(_layers_modified); i++)
|
if (_layers_modified)
|
||||||
{
|
{
|
||||||
result << QString::fromUtf8(layersGetName(_layers_modified, i));
|
for (int i = 0; i < layersCount(_layers_modified); i++)
|
||||||
|
{
|
||||||
|
result << QString::fromUtf8(layersGetName(_layers_modified, i));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -54,45 +84,60 @@ QStringList BaseFormLayer::getLayers()
|
||||||
|
|
||||||
void BaseFormLayer::layerAddedEvent()
|
void BaseFormLayer::layerAddedEvent()
|
||||||
{
|
{
|
||||||
QString layer_name = QInputDialog::getText(this, tr("Create layer"), tr("Layer name :"), QLineEdit::Normal, tr("Unnamed layer"));
|
if (_layers_modified)
|
||||||
if (not layer_name.isEmpty())
|
|
||||||
{
|
{
|
||||||
int layer = layersAddLayer(_layers_modified, NULL);
|
QString layer_name = QInputDialog::getText(this, tr("Create layer"), tr("Layer name :"), QLineEdit::Normal, tr("Unnamed layer"));
|
||||||
if (layer >= 0)
|
if (not layer_name.isEmpty())
|
||||||
{
|
{
|
||||||
layersSetName(_layers_modified, layer, layer_name.toUtf8().data());
|
int layer = layersAddLayer(_layers_modified, NULL);
|
||||||
|
if (layer >= 0)
|
||||||
|
{
|
||||||
|
layersSetName(_layers_modified, layer, layer_name.toUtf8().data());
|
||||||
|
|
||||||
BaseForm::layerAddedEvent();
|
BaseForm::layerAddedEvent();
|
||||||
|
|
||||||
afterLayerAdded(layersGetLayer(_layers_modified, layer));
|
afterLayerAdded(layersGetLayer(_layers_modified, layer));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFormLayer::layerDeletedEvent(int layer)
|
void BaseFormLayer::layerDeletedEvent(int layer)
|
||||||
{
|
{
|
||||||
layersDeleteLayer(_layers_modified, layer);
|
if (_layers_modified)
|
||||||
|
{
|
||||||
|
layersDeleteLayer(_layers_modified, layer);
|
||||||
|
}
|
||||||
|
|
||||||
BaseForm::layerDeletedEvent(layer);
|
BaseForm::layerDeletedEvent(layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFormLayer::layerMovedEvent(int layer, int new_position)
|
void BaseFormLayer::layerMovedEvent(int layer, int new_position)
|
||||||
{
|
{
|
||||||
layersMove(_layers_modified, layer, new_position);
|
if (_layers_modified)
|
||||||
|
{
|
||||||
|
layersMove(_layers_modified, layer, new_position);
|
||||||
|
}
|
||||||
|
|
||||||
BaseForm::layerMovedEvent(layer, new_position);
|
BaseForm::layerMovedEvent(layer, new_position);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFormLayer::layerRenamedEvent(int layer, QString new_name)
|
void BaseFormLayer::layerRenamedEvent(int layer, QString new_name)
|
||||||
{
|
{
|
||||||
layersSetName(_layers_modified, layer, new_name.toUtf8().data());
|
if (_layers_modified)
|
||||||
|
{
|
||||||
|
layersSetName(_layers_modified, layer, new_name.toUtf8().data());
|
||||||
|
}
|
||||||
|
|
||||||
BaseForm::layerRenamedEvent(layer, new_name);
|
BaseForm::layerRenamedEvent(layer, new_name);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseFormLayer::layerSelectedEvent(int layer)
|
void BaseFormLayer::layerSelectedEvent(int layer)
|
||||||
{
|
{
|
||||||
layerGetCopy(layersGetLayer(_layers_modified, layer));
|
if (_layers_modified)
|
||||||
|
{
|
||||||
|
layerGetCopy(layersGetLayer(_layers_modified, layer));
|
||||||
|
}
|
||||||
|
|
||||||
BaseForm::layerSelectedEvent(layer);
|
BaseForm::layerSelectedEvent(layer);
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,7 @@ class BaseFormLayer:public BaseForm
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
BaseFormLayer(QWidget* parent, Layers* layers);
|
BaseFormLayer(QWidget* parent, Layers* layers=NULL);
|
||||||
~BaseFormLayer();
|
~BaseFormLayer();
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
|
@ -19,6 +19,7 @@ public slots:
|
||||||
virtual void applyConfig();
|
virtual void applyConfig();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
void setLayers(Layers* layers);
|
||||||
virtual void layerGetCopy(void* layer_definition) = 0;
|
virtual void layerGetCopy(void* layer_definition) = 0;
|
||||||
virtual void layerApply(void* layer_definition) = 0;
|
virtual void layerApply(void* layer_definition) = 0;
|
||||||
virtual void afterLayerAdded(void* layer_definition);
|
virtual void afterLayerAdded(void* layer_definition);
|
||||||
|
|
|
@ -85,8 +85,7 @@ public:
|
||||||
|
|
||||||
_terrain = terrainCreateDefinition();
|
_terrain = terrainCreateDefinition();
|
||||||
_textures = texturesCreateDefinition();
|
_textures = texturesCreateDefinition();
|
||||||
texturesAddLayer(&_textures);
|
texture = (TextureLayerDefinition*)layersGetLayer(_textures.layers, layersAddLayer(_textures.layers, NULL));
|
||||||
texture = texturesGetLayer(&_textures, 0);
|
|
||||||
texture->material.base = COLOR_WHITE;
|
texture->material.base = COLOR_WHITE;
|
||||||
texture->material.reflection = 0.3;
|
texture->material.reflection = 0.3;
|
||||||
texture->material.shininess = 2.0;
|
texture->material.shininess = 2.0;
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
#include "../lib_paysages/scenery.h"
|
#include "../lib_paysages/scenery.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
static TexturesDefinition _definition;
|
|
||||||
static TextureLayerDefinition _layer;
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
Curve* height_curve;
|
Curve* height_curve;
|
||||||
|
@ -18,7 +15,7 @@ static TextureSupp _supp;
|
||||||
class PreviewTexturesCoverage:public BasePreview
|
class PreviewTexturesCoverage:public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PreviewTexturesCoverage(QWidget* parent):BasePreview(parent)
|
PreviewTexturesCoverage(QWidget* parent, TextureLayerDefinition* layer):BasePreview(parent)
|
||||||
{
|
{
|
||||||
_terrain = terrainCreateDefinition();
|
_terrain = terrainCreateDefinition();
|
||||||
|
|
||||||
|
@ -27,6 +24,7 @@ public:
|
||||||
_renderer.getTerrainHeight = _getTerrainHeight;
|
_renderer.getTerrainHeight = _getTerrainHeight;
|
||||||
_renderer.customData[0] = &_terrain;
|
_renderer.customData[0] = &_terrain;
|
||||||
|
|
||||||
|
_original_layer = layer;
|
||||||
_preview_layer = texturesLayerCreateDefinition();
|
_preview_layer = texturesLayerCreateDefinition();
|
||||||
|
|
||||||
addOsd(QString("geolocation"));
|
addOsd(QString("geolocation"));
|
||||||
|
@ -34,6 +32,10 @@ public:
|
||||||
configScaling(0.5, 200.0, 1.0, 50.0);
|
configScaling(0.5, 200.0, 1.0, 50.0);
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||||
}
|
}
|
||||||
|
~PreviewTexturesCoverage()
|
||||||
|
{
|
||||||
|
texturesLayerDeleteDefinition(_preview_layer);
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
QColor getColor(double x, double y)
|
QColor getColor(double x, double y)
|
||||||
{
|
{
|
||||||
|
@ -42,13 +44,13 @@ protected:
|
||||||
location.x = x;
|
location.x = x;
|
||||||
location.y = terrainGetHeight(&_terrain, x, y);
|
location.y = terrainGetHeight(&_terrain, x, y);
|
||||||
location.z = y;
|
location.z = y;
|
||||||
coverage = texturesGetLayerCoverage(&_preview_layer, &_renderer, location, this->scaling);
|
coverage = texturesGetLayerCoverage(_preview_layer, &_renderer, location, this->scaling);
|
||||||
return QColor::fromRgbF(coverage, coverage, coverage, 1.0);
|
return QColor::fromRgbF(coverage, coverage, coverage, 1.0);
|
||||||
}
|
}
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
sceneryGetTerrain(&_terrain);
|
sceneryGetTerrain(&_terrain);
|
||||||
texturesLayerCopyDefinition(&_layer, &_preview_layer);
|
texturesLayerCopyDefinition(_original_layer, _preview_layer);
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -58,17 +60,19 @@ private:
|
||||||
}
|
}
|
||||||
|
|
||||||
Renderer _renderer;
|
Renderer _renderer;
|
||||||
TextureLayerDefinition _preview_layer;
|
TextureLayerDefinition* _original_layer;
|
||||||
|
TextureLayerDefinition* _preview_layer;
|
||||||
TerrainDefinition _terrain;
|
TerrainDefinition _terrain;
|
||||||
};
|
};
|
||||||
|
|
||||||
class PreviewTexturesColor:public BasePreview
|
class PreviewTexturesColor:public BasePreview
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
PreviewTexturesColor(QWidget* parent):BasePreview(parent)
|
PreviewTexturesColor(QWidget* parent, TextureLayerDefinition* layer):BasePreview(parent)
|
||||||
{
|
{
|
||||||
LightDefinition light;
|
LightDefinition light;
|
||||||
|
|
||||||
|
_original_layer = layer;
|
||||||
_preview_layer = texturesLayerCreateDefinition();
|
_preview_layer = texturesLayerCreateDefinition();
|
||||||
|
|
||||||
_lighting = lightingCreateDefinition();
|
_lighting = lightingCreateDefinition();
|
||||||
|
@ -95,6 +99,10 @@ public:
|
||||||
configScaling(0.01, 1.0, 0.01, 0.1);
|
configScaling(0.01, 1.0, 0.01, 0.1);
|
||||||
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
configScrolling(-1000.0, 1000.0, 0.0, -1000.0, 1000.0, 0.0);
|
||||||
}
|
}
|
||||||
|
~PreviewTexturesColor()
|
||||||
|
{
|
||||||
|
texturesLayerDeleteDefinition(_preview_layer);
|
||||||
|
}
|
||||||
protected:
|
protected:
|
||||||
QColor getColor(double x, double y)
|
QColor getColor(double x, double y)
|
||||||
{
|
{
|
||||||
|
@ -102,17 +110,18 @@ protected:
|
||||||
location.x = x;
|
location.x = x;
|
||||||
location.y = 0.0;
|
location.y = 0.0;
|
||||||
location.z = y;
|
location.z = y;
|
||||||
return colorToQColor(texturesGetLayerColor(&_preview_layer, &_renderer, location, this->scaling));
|
return colorToQColor(texturesGetLayerColor(_preview_layer, &_renderer, location, this->scaling));
|
||||||
}
|
}
|
||||||
void updateData()
|
void updateData()
|
||||||
{
|
{
|
||||||
texturesLayerCopyDefinition(&_layer, &_preview_layer);
|
texturesLayerCopyDefinition(_original_layer, _preview_layer);
|
||||||
zoneCopy(_zone, _preview_layer.zone);
|
zoneCopy(_zone, _preview_layer->zone);
|
||||||
}
|
}
|
||||||
private:
|
private:
|
||||||
Zone* _zone;
|
Zone* _zone;
|
||||||
Renderer _renderer;
|
Renderer _renderer;
|
||||||
TextureLayerDefinition _preview_layer;
|
TextureLayerDefinition* _original_layer;
|
||||||
|
TextureLayerDefinition* _preview_layer;
|
||||||
LightingDefinition _lighting;
|
LightingDefinition _lighting;
|
||||||
|
|
||||||
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
static void _getLightStatus(Renderer* renderer, LightStatus* status, Vector3 location)
|
||||||
|
@ -123,35 +132,35 @@ private:
|
||||||
|
|
||||||
/**************** Form ****************/
|
/**************** Form ****************/
|
||||||
FormTextures::FormTextures(QWidget *parent):
|
FormTextures::FormTextures(QWidget *parent):
|
||||||
BaseForm(parent, false, true)
|
BaseFormLayer(parent)
|
||||||
{
|
{
|
||||||
_definition = texturesCreateDefinition();
|
_definition = texturesCreateDefinition();
|
||||||
_layer = texturesLayerCreateDefinition();
|
_layer = texturesLayerCreateDefinition();
|
||||||
_supp.height_curve = curveCreate();
|
_supp.height_curve = curveCreate();
|
||||||
_supp.slope_curve = curveCreate();
|
_supp.slope_curve = curveCreate();
|
||||||
|
|
||||||
previewCoverage = new PreviewTexturesCoverage(this);
|
previewCoverage = new PreviewTexturesCoverage(this, _layer);
|
||||||
previewColor = new PreviewTexturesColor(this);
|
previewColor = new PreviewTexturesColor(this, _layer);
|
||||||
addPreview(previewCoverage, tr("Coverage preview"));
|
addPreview(previewCoverage, tr("Coverage preview"));
|
||||||
addPreview(previewColor, tr("Lighted sample"));
|
addPreview(previewColor, tr("Lighted sample"));
|
||||||
|
|
||||||
addInputNoise(tr("Surface noise"), _layer.bump_noise);
|
addInputNoise(tr("Surface noise"), _layer->bump_noise);
|
||||||
addInputDouble(tr("Surface noise height"), &_layer.bump_height, 0.0, 0.1, 0.001, 0.01);
|
addInputDouble(tr("Surface noise height"), &_layer->bump_height, 0.0, 0.1, 0.001, 0.01);
|
||||||
addInputDouble(tr("Surface noise scaling"), &_layer.bump_scaling, 0.001, 0.1, 0.001, 0.01);
|
addInputDouble(tr("Surface noise scaling"), &_layer->bump_scaling, 0.001, 0.1, 0.001, 0.01);
|
||||||
addInputMaterial(tr("Material"), &_layer.material);
|
addInputMaterial(tr("Material"), &_layer->material);
|
||||||
addInputCurve(tr("Coverage by altitude"), _supp.height_curve, -20.0, 20.0, 0.0, 1.0, tr("Terrain altitude"), tr("Texture coverage"));
|
addInputCurve(tr("Coverage by altitude"), _supp.height_curve, -20.0, 20.0, 0.0, 1.0, tr("Terrain altitude"), tr("Texture coverage"));
|
||||||
addInputCurve(tr("Coverage by slope"), _supp.slope_curve, 0.0, 5.0, 0.0, 1.0, tr("Terrain slope"), tr("Texture coverage"));
|
addInputCurve(tr("Coverage by slope"), _supp.slope_curve, 0.0, 5.0, 0.0, 1.0, tr("Terrain slope"), tr("Texture coverage"));
|
||||||
addInputDouble(tr("Amplitude for slope coverage"), &_layer.slope_range, 0.001, 0.1, 0.001, 0.01);
|
addInputDouble(tr("Amplitude for slope coverage"), &_layer->slope_range, 0.001, 0.1, 0.001, 0.01);
|
||||||
addInputDouble(tr("Layer thickness"), &_layer.thickness, 0.0, 0.1, 0.001, 0.01);
|
addInputDouble(tr("Layer thickness"), &_layer->thickness, 0.0, 0.1, 0.001, 0.01);
|
||||||
addInputDouble(tr("Transparency thickness"), &_layer.thickness_transparency, 0.0, 0.1, 0.001, 0.01);
|
addInputDouble(tr("Transparency thickness"), &_layer->thickness_transparency, 0.0, 0.1, 0.001, 0.01);
|
||||||
|
|
||||||
revertConfig();
|
setLayers(_definition.layers);
|
||||||
}
|
}
|
||||||
|
|
||||||
FormTextures::~FormTextures()
|
FormTextures::~FormTextures()
|
||||||
{
|
{
|
||||||
texturesDeleteDefinition(&_definition);
|
texturesDeleteDefinition(&_definition);
|
||||||
texturesLayerDeleteDefinition(&_layer);
|
texturesLayerDeleteDefinition(_layer);
|
||||||
curveDelete(_supp.height_curve);
|
curveDelete(_supp.height_curve);
|
||||||
curveDelete(_supp.slope_curve);
|
curveDelete(_supp.slope_curve);
|
||||||
}
|
}
|
||||||
|
@ -159,81 +168,21 @@ FormTextures::~FormTextures()
|
||||||
void FormTextures::revertConfig()
|
void FormTextures::revertConfig()
|
||||||
{
|
{
|
||||||
sceneryGetTextures(&_definition);
|
sceneryGetTextures(&_definition);
|
||||||
BaseForm::revertConfig();
|
BaseFormLayer::revertConfig();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormTextures::applyConfig()
|
void FormTextures::applyConfig()
|
||||||
{
|
{
|
||||||
configChangeEvent();
|
BaseFormLayer::applyConfig();
|
||||||
scenerySetTextures(&_definition);
|
scenerySetTextures(&_definition);
|
||||||
BaseForm::applyConfig();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void FormTextures::configChangeEvent()
|
void FormTextures::layerGetCopy(void* layer_definition)
|
||||||
{
|
{
|
||||||
texturesLayerCopyDefinition(&_layer, texturesGetLayer(&_definition, currentLayer()));
|
texturesLayerCopyDefinition((TextureLayerDefinition*)layer_definition, _layer);
|
||||||
|
|
||||||
zoneSetHeightCurve(_layer.zone, _supp.height_curve);
|
|
||||||
zoneSetSlopeCurve(_layer.zone, _supp.slope_curve);
|
|
||||||
|
|
||||||
texturesValidateDefinition(&_definition);
|
|
||||||
BaseForm::configChangeEvent();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList FormTextures::getLayers()
|
void FormTextures::layerApply(void* layer_definition)
|
||||||
{
|
{
|
||||||
QStringList result;
|
texturesLayerCopyDefinition(_layer, (TextureLayerDefinition*)layer_definition);
|
||||||
TextureLayerDefinition* layer;
|
|
||||||
int i, n;
|
|
||||||
|
|
||||||
n = texturesGetLayerCount(&_definition);
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
layer = texturesGetLayer(&_definition, i);
|
|
||||||
result << QString::fromUtf8(layer->name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormTextures::layerAddedEvent()
|
|
||||||
{
|
|
||||||
if (texturesAddLayer(&_definition) >= 0)
|
|
||||||
{
|
|
||||||
BaseForm::layerAddedEvent();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormTextures::layerDeletedEvent(int layer)
|
|
||||||
{
|
|
||||||
texturesDeleteLayer(&_definition, layer);
|
|
||||||
|
|
||||||
BaseForm::layerDeletedEvent(layer);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormTextures::layerMovedEvent(int layer, int new_position)
|
|
||||||
{
|
|
||||||
texturesMoveLayer(&_definition, layer, new_position);
|
|
||||||
|
|
||||||
BaseForm::layerMovedEvent(layer, new_position);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormTextures::layerRenamedEvent(int layer, QString new_name)
|
|
||||||
{
|
|
||||||
TextureLayerDefinition* layer_def;
|
|
||||||
|
|
||||||
layer_def = texturesGetLayer(&_definition, layer);
|
|
||||||
texturesLayerSetName(layer_def, new_name.toUtf8().data());
|
|
||||||
|
|
||||||
BaseForm::layerRenamedEvent(layer, new_name);
|
|
||||||
}
|
|
||||||
|
|
||||||
void FormTextures::layerSelectedEvent(int layer)
|
|
||||||
{
|
|
||||||
texturesLayerCopyDefinition(texturesGetLayer(&_definition, layer), &_layer);
|
|
||||||
|
|
||||||
zoneGetHeightCurve(_layer.zone, _supp.height_curve);
|
|
||||||
zoneGetSlopeCurve(_layer.zone, _supp.slope_curve);
|
|
||||||
|
|
||||||
BaseForm::layerSelectedEvent(layer);
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,9 +3,10 @@
|
||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
#include "basepreview.h"
|
#include "basepreview.h"
|
||||||
#include "baseform.h"
|
#include "baseformlayer.h"
|
||||||
|
#include "../lib_paysages/textures.h"
|
||||||
|
|
||||||
class FormTextures : public BaseForm
|
class FormTextures : public BaseFormLayer
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
|
@ -13,22 +14,17 @@ public:
|
||||||
explicit FormTextures(QWidget *parent = 0);
|
explicit FormTextures(QWidget *parent = 0);
|
||||||
~FormTextures();
|
~FormTextures();
|
||||||
|
|
||||||
protected:
|
|
||||||
virtual QStringList getLayers();
|
|
||||||
virtual void layerAddedEvent();
|
|
||||||
virtual void layerDeletedEvent(int layer);
|
|
||||||
virtual void layerMovedEvent(int layer, int new_position);
|
|
||||||
virtual void layerRenamedEvent(int layer, QString new_name);
|
|
||||||
virtual void layerSelectedEvent(int layer);
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
virtual void revertConfig();
|
virtual void revertConfig();
|
||||||
virtual void applyConfig();
|
virtual void applyConfig();
|
||||||
|
|
||||||
protected slots:
|
protected:
|
||||||
virtual void configChangeEvent();
|
virtual void layerGetCopy(void* layer_definition);
|
||||||
|
virtual void layerApply(void* layer_definition);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
TexturesDefinition _definition;
|
||||||
|
TextureLayerDefinition* _layer;
|
||||||
BasePreview* previewCoverage;
|
BasePreview* previewCoverage;
|
||||||
BasePreview* previewColor;
|
BasePreview* previewColor;
|
||||||
};
|
};
|
||||||
|
|
|
@ -80,37 +80,37 @@ QMainWindow(parent)
|
||||||
|
|
||||||
form = new FormTerrain(tabs);
|
form = new FormTerrain(tabs);
|
||||||
tabs->addTab(form, tr("Terrain"));
|
tabs->addTab(form, tr("Terrain"));
|
||||||
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormTextures(tabs);
|
form = new FormTextures(tabs);
|
||||||
tabs->addTab(form, tr("Textures"));
|
tabs->addTab(form, tr("Textures"));
|
||||||
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormWater(tabs);
|
form = new FormWater(tabs);
|
||||||
tabs->addTab(form, tr("Water"));
|
tabs->addTab(form, tr("Water"));
|
||||||
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormSky(tabs);
|
form = new FormSky(tabs);
|
||||||
tabs->addTab(form, tr("Sky"));
|
tabs->addTab(form, tr("Sky"));
|
||||||
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormAtmosphere(tabs);
|
form = new FormAtmosphere(tabs);
|
||||||
tabs->addTab(form, tr("Atmosphere"));
|
tabs->addTab(form, tr("Atmosphere"));
|
||||||
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
form = new FormClouds(tabs);
|
form = new FormClouds(tabs);
|
||||||
tabs->addTab(form, tr("Clouds"));
|
tabs->addTab(form, tr("Clouds"));
|
||||||
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);
|
_forms.append(form);
|
||||||
|
|
||||||
/*form = new FormLighting(tabs);
|
/*form = new FormLighting(tabs);
|
||||||
tabs->addTab(form, tr("Lighting"));
|
tabs->addTab(form, tr("Lighting"));
|
||||||
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()));
|
QObject::connect(form, SIGNAL(configApplied()), this, SLOT(refreshAll()), Qt::QueuedConnection);
|
||||||
_forms.append(form);*/
|
_forms.append(form);*/
|
||||||
|
|
||||||
_form_render = new FormRender(tabs);
|
_form_render = new FormRender(tabs);
|
||||||
|
|
|
@ -64,6 +64,7 @@ void autoGenRealisticLandscape(int seed)
|
||||||
SkyDefinition sky;
|
SkyDefinition sky;
|
||||||
TexturesDefinition textures;
|
TexturesDefinition textures;
|
||||||
TextureLayerDefinition* texture;
|
TextureLayerDefinition* texture;
|
||||||
|
int layer;
|
||||||
|
|
||||||
if (!seed)
|
if (!seed)
|
||||||
{
|
{
|
||||||
|
@ -146,8 +147,9 @@ void autoGenRealisticLandscape(int seed)
|
||||||
|
|
||||||
/* Textures */
|
/* Textures */
|
||||||
textures = texturesCreateDefinition();
|
textures = texturesCreateDefinition();
|
||||||
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
|
layer = layersAddLayer(textures.layers, NULL);
|
||||||
texturesLayerSetName(texture, "Ground");
|
layersSetName(textures.layers, layer, "Ground");
|
||||||
|
texture = layersGetLayer(textures.layers, layer);
|
||||||
noiseGenerateBaseNoise(texture->bump_noise, 102400);
|
noiseGenerateBaseNoise(texture->bump_noise, 102400);
|
||||||
noiseClearLevels(texture->bump_noise);
|
noiseClearLevels(texture->bump_noise);
|
||||||
noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, 1.0);
|
noiseAddLevelsSimple(texture->bump_noise, 8, 1.0, 1.0);
|
||||||
|
@ -161,8 +163,9 @@ void autoGenRealisticLandscape(int seed)
|
||||||
texture->thickness = 0.001;
|
texture->thickness = 0.001;
|
||||||
texture->slope_range = 0.001;
|
texture->slope_range = 0.001;
|
||||||
texture->thickness_transparency = 0.0;
|
texture->thickness_transparency = 0.0;
|
||||||
texture = texturesGetLayer(&textures, texturesAddLayer(&textures));
|
layer = layersAddLayer(textures.layers, NULL);
|
||||||
texturesLayerSetName(texture, "Grass");
|
layersSetName(textures.layers, layer, "Grass");
|
||||||
|
texture = layersGetLayer(textures.layers, layer);
|
||||||
zoneAddHeightRangeQuick(texture->zone, 1.0, -6.0, -5.0, 3.0, 15.0);
|
zoneAddHeightRangeQuick(texture->zone, 1.0, -6.0, -5.0, 3.0, 15.0);
|
||||||
zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.05, 0.4);
|
zoneAddSlopeRangeQuick(texture->zone, 1.0, 0.0, 0.0, 0.05, 0.4);
|
||||||
noiseGenerateBaseNoise(texture->bump_noise, 102400);
|
noiseGenerateBaseNoise(texture->bump_noise, 102400);
|
||||||
|
|
|
@ -26,7 +26,6 @@ void sceneryInit()
|
||||||
noiseInit();
|
noiseInit();
|
||||||
cloudsInit();
|
cloudsInit();
|
||||||
lightingInit();
|
lightingInit();
|
||||||
texturesInit();
|
|
||||||
|
|
||||||
_atmosphere = atmosphereCreateDefinition();
|
_atmosphere = atmosphereCreateDefinition();
|
||||||
_camera = cameraCreateDefinition();
|
_camera = cameraCreateDefinition();
|
||||||
|
@ -56,7 +55,6 @@ void sceneryQuit()
|
||||||
|
|
||||||
cloudsQuit();
|
cloudsQuit();
|
||||||
lightingQuit();
|
lightingQuit();
|
||||||
texturesQuit();
|
|
||||||
noiseQuit();
|
noiseQuit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "terrain.h"
|
#include "terrain.h"
|
||||||
#include "tools.h"
|
#include "tools.h"
|
||||||
|
|
||||||
static TextureLayerDefinition _NULL_LAYER;
|
#define TEXTURES_MAX_LAYERS 50
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
|
@ -22,126 +22,96 @@ typedef struct
|
||||||
TextureLayerDefinition* definition;
|
TextureLayerDefinition* definition;
|
||||||
} TextureResult;
|
} TextureResult;
|
||||||
|
|
||||||
void texturesInit()
|
static void texturesLayerSave(PackStream* stream, TextureLayerDefinition* layer)
|
||||||
{
|
{
|
||||||
_NULL_LAYER = texturesLayerCreateDefinition();
|
zoneSave(stream, layer->zone);
|
||||||
|
noiseSaveGenerator(stream, layer->bump_noise);
|
||||||
|
packWriteDouble(stream, &layer->bump_height);
|
||||||
|
packWriteDouble(stream, &layer->bump_scaling);
|
||||||
|
materialSave(stream, &layer->material);
|
||||||
|
packWriteDouble(stream, &layer->thickness);
|
||||||
|
packWriteDouble(stream, &layer->slope_range);
|
||||||
|
packWriteDouble(stream, &layer->thickness_transparency);
|
||||||
}
|
}
|
||||||
|
|
||||||
void texturesQuit()
|
static void texturesLayerLoad(PackStream* stream, TextureLayerDefinition* layer)
|
||||||
{
|
{
|
||||||
texturesLayerDeleteDefinition(&_NULL_LAYER);
|
zoneLoad(stream, layer->zone);
|
||||||
}
|
noiseLoadGenerator(stream, layer->bump_noise);
|
||||||
|
packReadDouble(stream, &layer->bump_height);
|
||||||
void texturesSave(PackStream* stream, TexturesDefinition* definition)
|
packReadDouble(stream, &layer->bump_scaling);
|
||||||
{
|
materialLoad(stream, &layer->material);
|
||||||
TextureLayerDefinition* layer;
|
packReadDouble(stream, &layer->thickness);
|
||||||
int i;
|
packReadDouble(stream, &layer->slope_range);
|
||||||
|
packReadDouble(stream, &layer->thickness_transparency);
|
||||||
packWriteInt(stream, &definition->nblayers);
|
|
||||||
for (i = 0; i < definition->nblayers; i++)
|
|
||||||
{
|
|
||||||
layer = definition->layers + i;
|
|
||||||
|
|
||||||
packWriteString(stream, layer->name, TEXTURES_MAX_NAME_LENGTH);
|
|
||||||
zoneSave(stream, layer->zone);
|
|
||||||
noiseSaveGenerator(stream, layer->bump_noise);
|
|
||||||
packWriteDouble(stream, &layer->bump_height);
|
|
||||||
packWriteDouble(stream, &layer->bump_scaling);
|
|
||||||
materialSave(stream, &layer->material);
|
|
||||||
packWriteDouble(stream, &layer->thickness);
|
|
||||||
packWriteDouble(stream, &layer->slope_range);
|
|
||||||
packWriteDouble(stream, &layer->thickness_transparency);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void texturesLoad(PackStream* stream, TexturesDefinition* definition)
|
|
||||||
{
|
|
||||||
TextureLayerDefinition* layer;
|
|
||||||
int i, n;
|
|
||||||
|
|
||||||
while (definition->nblayers > 0)
|
|
||||||
{
|
|
||||||
texturesDeleteLayer(definition, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
packReadInt(stream, &n);
|
|
||||||
for (i = 0; i < n; i++)
|
|
||||||
{
|
|
||||||
layer = definition->layers + texturesAddLayer(definition);
|
|
||||||
|
|
||||||
packReadString(stream, layer->name, TEXTURES_MAX_NAME_LENGTH);
|
|
||||||
zoneLoad(stream, layer->zone);
|
|
||||||
noiseLoadGenerator(stream, layer->bump_noise);
|
|
||||||
packReadDouble(stream, &layer->bump_height);
|
|
||||||
packReadDouble(stream, &layer->bump_scaling);
|
|
||||||
materialLoad(stream, &layer->material);
|
|
||||||
packReadDouble(stream, &layer->thickness);
|
|
||||||
packReadDouble(stream, &layer->slope_range);
|
|
||||||
packReadDouble(stream, &layer->thickness_transparency);
|
|
||||||
}
|
|
||||||
|
|
||||||
texturesValidateDefinition(definition);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TexturesDefinition texturesCreateDefinition()
|
TexturesDefinition texturesCreateDefinition()
|
||||||
{
|
{
|
||||||
TexturesDefinition result;
|
TexturesDefinition result;
|
||||||
|
|
||||||
result.nblayers = 0;
|
result.layers = layersCreate(texturesGetLayerType(), TEXTURES_MAX_LAYERS);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void texturesDeleteDefinition(TexturesDefinition* definition)
|
void texturesDeleteDefinition(TexturesDefinition* definition)
|
||||||
{
|
{
|
||||||
while (definition->nblayers > 0)
|
layersDelete(definition->layers);
|
||||||
{
|
|
||||||
texturesDeleteLayer(definition, 0);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void texturesCopyDefinition(TexturesDefinition* source, TexturesDefinition* destination)
|
void texturesCopyDefinition(TexturesDefinition* source, TexturesDefinition* destination)
|
||||||
{
|
{
|
||||||
TextureLayerDefinition* layer;
|
layersCopy(source->layers, destination->layers);
|
||||||
int i;
|
|
||||||
|
|
||||||
while (destination->nblayers > 0)
|
|
||||||
{
|
|
||||||
texturesDeleteLayer(destination, 0);
|
|
||||||
}
|
|
||||||
for (i = 0; i < source->nblayers; i++)
|
|
||||||
{
|
|
||||||
layer = texturesGetLayer(destination, texturesAddLayer(destination));
|
|
||||||
texturesLayerCopyDefinition(source->layers + i, layer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void texturesValidateDefinition(TexturesDefinition* definition)
|
void texturesValidateDefinition(TexturesDefinition* definition)
|
||||||
{
|
{
|
||||||
int i;
|
layersValidate(definition->layers);
|
||||||
for (i = 0; i < definition->nblayers; i++)
|
|
||||||
{
|
|
||||||
texturesLayerValidateDefinition(definition->layers + i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TextureLayerDefinition texturesLayerCreateDefinition()
|
void texturesSave(PackStream* stream, TexturesDefinition* definition)
|
||||||
{
|
{
|
||||||
TextureLayerDefinition result;
|
layersSave(stream, definition->layers);
|
||||||
|
}
|
||||||
|
|
||||||
texturesLayerSetName(&result, "Unnamed");
|
void texturesLoad(PackStream* stream, TexturesDefinition* definition)
|
||||||
result.zone = zoneCreate();
|
{
|
||||||
result.bump_noise = noiseCreateGenerator();
|
layersLoad(stream, definition->layers);
|
||||||
noiseGenerateBaseNoise(result.bump_noise, 102400);
|
}
|
||||||
noiseAddLevelsSimple(result.bump_noise, 8, 1.0, 1.0);
|
|
||||||
result.bump_height = 0.1;
|
LayerType texturesGetLayerType()
|
||||||
result.bump_scaling = 0.1;
|
{
|
||||||
result.material.base = COLOR_WHITE;
|
LayerType result;
|
||||||
result.material.reflection = 0.0;
|
|
||||||
result.material.shininess = 0.0;
|
result.callback_create = (LayerCallbackCreate)texturesLayerCreateDefinition;
|
||||||
result.thickness = 0.0;
|
result.callback_delete = (LayerCallbackDelete)texturesLayerDeleteDefinition;
|
||||||
result.slope_range = 0.001;
|
result.callback_copy = (LayerCallbackCopy)texturesLayerCopyDefinition;
|
||||||
result.thickness_transparency = 0.0;
|
result.callback_validate = (LayerCallbackValidate)texturesLayerValidateDefinition;
|
||||||
|
result.callback_save = (LayerCallbackSave)texturesLayerSave;
|
||||||
|
result.callback_load = (LayerCallbackLoad)texturesLayerLoad;
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureLayerDefinition* texturesLayerCreateDefinition()
|
||||||
|
{
|
||||||
|
TextureLayerDefinition* result;
|
||||||
|
|
||||||
|
result = malloc(sizeof(TextureLayerDefinition));
|
||||||
|
|
||||||
|
result->zone = zoneCreate();
|
||||||
|
result->bump_noise = noiseCreateGenerator();
|
||||||
|
noiseGenerateBaseNoise(result->bump_noise, 102400);
|
||||||
|
noiseAddLevelsSimple(result->bump_noise, 8, 1.0, 1.0);
|
||||||
|
result->bump_height = 0.1;
|
||||||
|
result->bump_scaling = 0.1;
|
||||||
|
result->material.base = COLOR_WHITE;
|
||||||
|
result->material.reflection = 0.0;
|
||||||
|
result->material.shininess = 0.0;
|
||||||
|
result->thickness = 0.0;
|
||||||
|
result->slope_range = 0.001;
|
||||||
|
result->thickness_transparency = 0.0;
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -150,11 +120,11 @@ void texturesLayerDeleteDefinition(TextureLayerDefinition* definition)
|
||||||
{
|
{
|
||||||
zoneDelete(definition->zone);
|
zoneDelete(definition->zone);
|
||||||
noiseDeleteGenerator(definition->bump_noise);
|
noiseDeleteGenerator(definition->bump_noise);
|
||||||
|
free(definition);
|
||||||
}
|
}
|
||||||
|
|
||||||
void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination)
|
void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination)
|
||||||
{
|
{
|
||||||
strncpy(destination->name, source->name, TEXTURES_MAX_NAME_LENGTH);
|
|
||||||
destination->material = source->material;
|
destination->material = source->material;
|
||||||
destination->bump_height = source->bump_height;
|
destination->bump_height = source->bump_height;
|
||||||
destination->bump_scaling = source->bump_scaling;
|
destination->bump_scaling = source->bump_scaling;
|
||||||
|
@ -167,7 +137,6 @@ void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDef
|
||||||
|
|
||||||
void texturesLayerValidateDefinition(TextureLayerDefinition* definition)
|
void texturesLayerValidateDefinition(TextureLayerDefinition* definition)
|
||||||
{
|
{
|
||||||
definition->name[TEXTURES_MAX_NAME_LENGTH] = '\0';
|
|
||||||
if (definition->bump_scaling < 0.000001)
|
if (definition->bump_scaling < 0.000001)
|
||||||
{
|
{
|
||||||
definition->bump_scaling = 0.000001;
|
definition->bump_scaling = 0.000001;
|
||||||
|
@ -178,73 +147,6 @@ void texturesLayerValidateDefinition(TextureLayerDefinition* definition)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void texturesLayerSetName(TextureLayerDefinition* definition, const char* name)
|
|
||||||
{
|
|
||||||
strncpy(definition->name, name, TEXTURES_MAX_NAME_LENGTH);
|
|
||||||
}
|
|
||||||
|
|
||||||
int texturesGetLayerCount(TexturesDefinition* definition)
|
|
||||||
{
|
|
||||||
return definition->nblayers;
|
|
||||||
}
|
|
||||||
|
|
||||||
TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer)
|
|
||||||
{
|
|
||||||
if (layer >= 0 && layer < definition->nblayers)
|
|
||||||
{
|
|
||||||
return definition->layers + layer;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return &_NULL_LAYER;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
int texturesAddLayer(TexturesDefinition* definition)
|
|
||||||
{
|
|
||||||
if (definition->nblayers < TEXTURES_MAX_LAYERS)
|
|
||||||
{
|
|
||||||
definition->layers[definition->nblayers] = texturesLayerCreateDefinition();
|
|
||||||
|
|
||||||
return definition->nblayers++;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void texturesDeleteLayer(TexturesDefinition* definition, int layer)
|
|
||||||
{
|
|
||||||
if (layer >= 0 && layer < definition->nblayers)
|
|
||||||
{
|
|
||||||
texturesLayerDeleteDefinition(definition->layers + layer);
|
|
||||||
if (definition->nblayers > 1 && layer < definition->nblayers - 1)
|
|
||||||
{
|
|
||||||
memmove(definition->layers + layer, definition->layers + layer + 1, sizeof(TextureLayerDefinition) * (definition->nblayers - layer - 1));
|
|
||||||
}
|
|
||||||
definition->nblayers--;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void texturesMoveLayer(TexturesDefinition* definition, int layer, int new_position)
|
|
||||||
{
|
|
||||||
if (layer >= 0 && layer < definition->nblayers && new_position != layer && new_position >= 0 && new_position < definition->nblayers)
|
|
||||||
{
|
|
||||||
TextureLayerDefinition temp;
|
|
||||||
temp = definition->layers[layer];
|
|
||||||
if (new_position > layer)
|
|
||||||
{
|
|
||||||
memmove(definition->layers + layer, definition->layers + layer + 1, sizeof(TextureLayerDefinition) * (new_position - layer));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
memmove(definition->layers + new_position + 1, definition->layers + new_position, sizeof(TextureLayerDefinition) * (layer - new_position));
|
|
||||||
}
|
|
||||||
definition->layers[new_position] = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
static inline Vector3 _getNormal4(Vector3 center, Vector3 north, Vector3 east, Vector3 south, Vector3 west)
|
static inline Vector3 _getNormal4(Vector3 center, Vector3 north, Vector3 east, Vector3 south, Vector3 west)
|
||||||
{
|
{
|
||||||
Vector3 dnorth, deast, dsouth, dwest, normal;
|
Vector3 dnorth, deast, dsouth, dwest, normal;
|
||||||
|
@ -385,24 +287,25 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
|
||||||
TextureResult results[TEXTURES_MAX_LAYERS + 1];
|
TextureResult results[TEXTURES_MAX_LAYERS + 1];
|
||||||
Color result, color;
|
Color result, color;
|
||||||
double thickness, last_height;
|
double thickness, last_height;
|
||||||
int i, start;
|
int i, start, nblayers;
|
||||||
|
|
||||||
detail *= 0.1;
|
detail *= 0.1;
|
||||||
|
|
||||||
results[0] = _getTerrainResult(renderer, x, z, detail);
|
results[0] = _getTerrainResult(renderer, x, z, detail);
|
||||||
|
|
||||||
for (i = 0; i < definition->nblayers; i++)
|
nblayers = layersCount(definition->layers);
|
||||||
|
for (i = 0; i < nblayers; i++)
|
||||||
{
|
{
|
||||||
results[i + 1] = _getLayerResult(definition->layers + i, renderer, x, z, detail);
|
results[i + 1] = _getLayerResult(layersGetLayer(definition->layers, i), renderer, x, z, detail);
|
||||||
}
|
}
|
||||||
|
|
||||||
qsort(results, definition->nblayers + 1, sizeof(TextureResult), _cmpResults);
|
qsort(results, nblayers + 1, sizeof(TextureResult), _cmpResults);
|
||||||
|
|
||||||
/* Pre compute alpha channel */
|
/* Pre compute alpha channel */
|
||||||
start = 0;
|
start = 0;
|
||||||
last_height = results[0].thickness;
|
last_height = results[0].thickness;
|
||||||
results[0].thickness = 1.0;
|
results[0].thickness = 1.0;
|
||||||
for (i = 1; i <= definition->nblayers; i++)
|
for (i = 1; i <= nblayers; i++)
|
||||||
{
|
{
|
||||||
thickness = results[i].thickness - last_height;
|
thickness = results[i].thickness - last_height;
|
||||||
last_height = results[i].thickness;
|
last_height = results[i].thickness;
|
||||||
|
@ -440,7 +343,7 @@ Color texturesGetColor(TexturesDefinition* definition, Renderer* renderer, doubl
|
||||||
{
|
{
|
||||||
result = COLOR_GREEN;
|
result = COLOR_GREEN;
|
||||||
}
|
}
|
||||||
for (i = start + 1; i <= definition->nblayers; i++)
|
for (i = start + 1; i <= nblayers; i++)
|
||||||
{
|
{
|
||||||
if (results[i].thickness)
|
if (results[i].thickness)
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
#define _PAYSAGES_TEXTURES_H_
|
#define _PAYSAGES_TEXTURES_H_
|
||||||
|
|
||||||
#include "shared/types.h"
|
#include "shared/types.h"
|
||||||
|
#include "layers.h"
|
||||||
#include "noise.h"
|
#include "noise.h"
|
||||||
#include "lighting.h"
|
#include "lighting.h"
|
||||||
#include "pack.h"
|
#include "pack.h"
|
||||||
|
@ -11,12 +12,8 @@
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define TEXTURES_MAX_LAYERS 50
|
|
||||||
#define TEXTURES_MAX_NAME_LENGTH 50
|
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
char name[TEXTURES_MAX_NAME_LENGTH + 1];
|
|
||||||
Zone* zone;
|
Zone* zone;
|
||||||
NoiseGenerator* bump_noise;
|
NoiseGenerator* bump_noise;
|
||||||
double bump_scaling;
|
double bump_scaling;
|
||||||
|
@ -29,31 +26,22 @@ typedef struct
|
||||||
|
|
||||||
typedef struct
|
typedef struct
|
||||||
{
|
{
|
||||||
int nblayers;
|
Layers* layers;
|
||||||
TextureLayerDefinition layers[TEXTURES_MAX_LAYERS];
|
|
||||||
} TexturesDefinition;
|
} TexturesDefinition;
|
||||||
|
|
||||||
void texturesInit();
|
|
||||||
void texturesQuit();
|
|
||||||
void texturesSave(PackStream* stream, TexturesDefinition* definition);
|
|
||||||
void texturesLoad(PackStream* stream, TexturesDefinition* definition);
|
|
||||||
|
|
||||||
TexturesDefinition texturesCreateDefinition();
|
TexturesDefinition texturesCreateDefinition();
|
||||||
void texturesDeleteDefinition(TexturesDefinition* definition);
|
void texturesDeleteDefinition(TexturesDefinition* definition);
|
||||||
void texturesCopyDefinition(TexturesDefinition* source, TexturesDefinition* destination);
|
void texturesCopyDefinition(TexturesDefinition* source, TexturesDefinition* destination);
|
||||||
void texturesValidateDefinition(TexturesDefinition* definition);
|
void texturesValidateDefinition(TexturesDefinition* definition);
|
||||||
|
|
||||||
TextureLayerDefinition texturesLayerCreateDefinition();
|
void texturesSave(PackStream* stream, TexturesDefinition* definition);
|
||||||
|
void texturesLoad(PackStream* stream, TexturesDefinition* definition);
|
||||||
|
|
||||||
|
LayerType texturesGetLayerType();
|
||||||
|
TextureLayerDefinition* texturesLayerCreateDefinition();
|
||||||
void texturesLayerDeleteDefinition(TextureLayerDefinition* definition);
|
void texturesLayerDeleteDefinition(TextureLayerDefinition* definition);
|
||||||
void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination);
|
void texturesLayerCopyDefinition(TextureLayerDefinition* source, TextureLayerDefinition* destination);
|
||||||
void texturesLayerValidateDefinition(TextureLayerDefinition* definition);
|
void texturesLayerValidateDefinition(TextureLayerDefinition* definition);
|
||||||
void texturesLayerSetName(TextureLayerDefinition* definition, const char* name);
|
|
||||||
|
|
||||||
int texturesGetLayerCount(TexturesDefinition* definition);
|
|
||||||
TextureLayerDefinition* texturesGetLayer(TexturesDefinition* definition, int layer);
|
|
||||||
int texturesAddLayer(TexturesDefinition* definition);
|
|
||||||
void texturesDeleteLayer(TexturesDefinition* definition, int layer);
|
|
||||||
void texturesMoveLayer(TexturesDefinition* definition, int layer, int new_position);
|
|
||||||
|
|
||||||
double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
|
double texturesGetLayerCoverage(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
|
||||||
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
|
Color texturesGetLayerColor(TextureLayerDefinition* definition, Renderer* renderer, Vector3 location, double detail);
|
||||||
|
|
Loading…
Reference in a new issue