Skip to content

Commit

Permalink
noggit: ui: texture_swapper: add hardness and pressure parameters for…
Browse files Browse the repository at this point in the history
… the brush mode
  • Loading branch information
Adspartan committed Nov 22, 2024
1 parent d798acc commit 905d2a7
Show file tree
Hide file tree
Showing 9 changed files with 36 additions and 20 deletions.
4 changes: 2 additions & 2 deletions src/noggit/MapChunk.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1473,10 +1473,10 @@ bool MapChunk::paintTexture(math::vector_3d const& pos, Brush* brush, float stre
return texture_set->paintTexture(xbase, zbase, pos.x, pos.z, brush, strength, pressure, std::move (texture));
}

bool MapChunk::replaceTexture(math::vector_3d const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture)
bool MapChunk::replaceTexture(math::vector_3d const& pos, Brush const& brush, float change, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture)
{
texture_set_changed();
return texture_set->replace_texture(xbase, zbase, pos.x, pos.z, radius, old_texture, std::move (new_texture));
return texture_set->replace_texture(xbase, zbase, pos.x, pos.z, brush, change, old_texture, std::move (new_texture));
}

bool MapChunk::canPaintTexture(std::string const& texture)
Expand Down
2 changes: 1 addition & 1 deletion src/noggit/MapChunk.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class MapChunk

//! \todo implement Action stack for these
bool paintTexture(math::vector_3d const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture);
bool replaceTexture(math::vector_3d const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture);
bool replaceTexture(math::vector_3d const& pos, Brush const& brush, float change, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture);
bool canPaintTexture(std::string const& texture);
int addTexture(scoped_blp_texture_reference texture);
void switchTexture(scoped_blp_texture_reference const& oldTexture, scoped_blp_texture_reference newTexture);
Expand Down
6 changes: 3 additions & 3 deletions src/noggit/World.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2052,13 +2052,13 @@ bool World::sprayTexture(math::vector_3d const& pos, Brush *brush, float strengt
return succ;
}

bool World::replaceTexture(math::vector_3d const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture)
bool World::replaceTexture(math::vector_3d const& pos, Brush const& brush, float change, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture)
{
return for_all_chunks_in_range
( pos, radius
( pos, brush.get_radius()
, [&](MapChunk* chunk)
{
return chunk->replaceTexture(pos, radius, old_texture, new_texture);
return chunk->replaceTexture(pos, brush, change, old_texture, new_texture);
}
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/noggit/World.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,7 @@ class World
void blurTerrain(math::vector_3d const& pos, float remain, float radius, int BrushType, flatten_mode const& mode);
bool paintTexture(math::vector_3d const& pos, Brush *brush, float strength, float pressure, scoped_blp_texture_reference texture);
bool sprayTexture(math::vector_3d const& pos, Brush *brush, float strength, float pressure, float spraySize, float sprayPressure, scoped_blp_texture_reference texture);
bool replaceTexture(math::vector_3d const& pos, float radius, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture);
bool replaceTexture(math::vector_3d const& pos, Brush const& brush, float change, scoped_blp_texture_reference const& old_texture, scoped_blp_texture_reference new_texture);

void clear_on_chunks ( math::vector_3d const& pos, float radius, bool height, bool textures, bool duplicate_textures
, bool textures_below_threshold, float alpha_threshold, bool texture_flags, bool liquids
Expand Down
10 changes: 7 additions & 3 deletions src/noggit/texture_set.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -660,12 +660,15 @@ bool TextureSet::replace_texture( float xbase
, float zbase
, float x
, float z
, float radius
, Brush const& brush
, float change
, scoped_blp_texture_reference const& texture_to_replace
, scoped_blp_texture_reference replacement_texture
)
{
float dist = misc::getShortestDist(x, z, xbase, zbase, CHUNKSIZE);
float radius = brush.get_radius();
float inner_radius = brush.get_inner_radius();

if (dist > radius)
{
Expand Down Expand Up @@ -724,8 +727,9 @@ bool TextureSet::replace_texture( float xbase
{
int offset = j * 64 + i;

amap[new_tex_level][offset] += amap[old_tex_level][offset];
amap[old_tex_level][offset] = 0.f;
float v = amap[old_tex_level][offset] * brush.value_at_dist(dist) * change;
amap[new_tex_level][offset] += v;
amap[old_tex_level][offset] -= v;

changed = true;
}
Expand Down
3 changes: 2 additions & 1 deletion src/noggit/texture_set.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,8 @@ class TextureSet
, float zbase
, float x
, float z
, float radius
, Brush const& brush
, float change
, scoped_blp_texture_reference const& texture_to_replace
, scoped_blp_texture_reference replacement_texture
);
Expand Down
4 changes: 4 additions & 0 deletions src/noggit/ui/texture_swapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ namespace noggit
: QWidget (parent)
, _texture_to_swap()
, _radius(15.f)
, _hardness(0.5f)
, _pressure(0.75f)
{
setWindowTitle ("Swap");
setWindowFlags (Qt::Tool | Qt::WindowStaysOnTopHint);
Expand All @@ -51,6 +53,8 @@ namespace noggit
_brush_mode_group->setLayout(brush_layout);

brush_layout->addRow(new slider_spinbox("Radius", &_radius, 0.f, 100.f, 2, brush_content));
brush_layout->addRow(new slider_spinbox("Hardness", &_hardness, 0.f, 1.f, 2, brush_content));
brush_layout->addRow(new slider_spinbox("Pressure", &_pressure, 0.f, 1.f, 2, brush_content));

connect(select, &QPushButton::clicked, [&]() {
_texture_to_swap = selected_texture::get();
Expand Down
16 changes: 10 additions & 6 deletions src/noggit/ui/texture_swapper.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#pragma once

#include <math/vector_3d.hpp>
#include <noggit/Brush.h>
#include <noggit/float_property.hpp>
#include <noggit/TextureManager.h>
#include <noggit/ui/CurrentTexture.h>
Expand Down Expand Up @@ -33,18 +34,21 @@ namespace noggit
return _texture_to_swap;
}

float radius() const
{
return _radius.get();
}
float radius() const { return _radius.get(); }
float hardness() const { return _hardness.get(); }
float pressure() const { return _pressure.get(); }

void change_radius(float change) { _radius.change(change); }
void change_hardness(float change) { _hardness.change(change); }
void change_pressure(float change) { _pressure.change(change); }

bool brush_mode() const
{
return _brush_mode_group->isChecked();
}

Brush brush() const { return Brush(radius(), hardness()); }

void toggle_brush_mode()
{
_brush_mode_group->setChecked(!_brush_mode_group->isChecked());
Expand All @@ -57,13 +61,13 @@ namespace noggit
private:
boost::optional<scoped_blp_texture_reference> _texture_to_swap;
float_property _radius;
float_property _hardness;
float_property _pressure;

private:
current_texture* _texture_to_swap_display;

QGroupBox* _brush_mode_group;
QSlider* _radius_slider;
QDoubleSpinBox* _radius_spin;
};
}
}
9 changes: 6 additions & 3 deletions src/noggit/ui/texturing_tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,6 +375,7 @@ namespace noggit
switch (_texturing_mode)
{
case texturing_mode::paint: return _hardness.get();
case texturing_mode::swap: return _texture_switcher->brush_mode() ? _texture_switcher->hardness() : 0.f;
default: return 0.f;
}
}
Expand All @@ -386,16 +387,16 @@ namespace noggit

void texturing_tool::paint (World* world, math::vector_3d const& pos, float dt, scoped_blp_texture_reference texture)
{
float strength = 1.0f - pow(1.0f - _pressure.get(), dt * 10.0f);

if (_texturing_mode == texturing_mode::swap)
{
float strength = 1.0f - pow(1.0f - _texture_switcher->pressure(), dt * 10.0f);

auto to_swap (_texture_switcher->texture_to_swap());
if (to_swap)
{
if (_texture_switcher->brush_mode())
{
world->replaceTexture(pos, _texture_switcher->radius(), to_swap.get(), texture);
world->replaceTexture(pos, _texture_switcher->brush(), strength, to_swap.get(), texture);
}
else
{
Expand All @@ -405,6 +406,8 @@ namespace noggit
}
else if (_texturing_mode == texturing_mode::paint)
{
float strength = 1.0f - pow(1.0f - _pressure.get(), dt * 10.0f);

if (_spray_mode_group->isChecked())
{
world->sprayTexture(pos, &_spray_brush, alpha_target(), strength, _radius.get(), _spray_pressure.get(), texture);
Expand Down

0 comments on commit 905d2a7

Please sign in to comment.