Commit iteration I (kinda broken) of the stamp tool.
This commit is contained in:
@@ -6,7 +6,7 @@ uniform sampler2D tex0;
|
||||
uniform sampler2D tex1;
|
||||
uniform sampler2D tex2;
|
||||
uniform sampler2D tex3;
|
||||
//uniform sampler2D stampBrush;
|
||||
uniform sampler2D stampBrush;
|
||||
uniform vec2 tex_anim_0;
|
||||
uniform vec2 tex_anim_1;
|
||||
uniform vec2 tex_anim_2;
|
||||
@@ -39,6 +39,7 @@ uniform float fog_end;
|
||||
|
||||
uniform bool draw_cursor_circle;
|
||||
uniform vec3 cursor_position;
|
||||
uniform float cursorRotation;
|
||||
uniform float outer_cursor_radius;
|
||||
uniform float inner_cursor_ratio;
|
||||
uniform vec4 cursor_color;
|
||||
@@ -58,6 +59,7 @@ const float TILESIZE = 533.33333;
|
||||
const float CHUNKSIZE = TILESIZE / 16.0;
|
||||
const float HOLESIZE = CHUNKSIZE * 0.25;
|
||||
const float UNITSIZE = HOLESIZE * 0.5;
|
||||
const float PI = 3.14159265358979323846;
|
||||
|
||||
vec4 texture_blend()
|
||||
{
|
||||
@@ -195,7 +197,7 @@ void main()
|
||||
}
|
||||
}
|
||||
|
||||
if (draw_cursor_circle)
|
||||
if (!draw_cursor_circle)
|
||||
{
|
||||
float diff = length(vary_position.xz - cursor_position.xz);
|
||||
diff = min(abs(diff - outer_cursor_radius), abs(diff - outer_cursor_radius * inner_cursor_ratio));
|
||||
@@ -203,4 +205,37 @@ void main()
|
||||
|
||||
out_color.rgb = mix(cursor_color.rgb, out_color.rgb, alpha);
|
||||
}
|
||||
|
||||
if(draw_cursor_circle)
|
||||
{
|
||||
float angle = cursorRotation * 2.0 * PI;
|
||||
vec2 topleft = cursor_position.xz;
|
||||
topleft.x -= outer_cursor_radius;
|
||||
topleft.y -= outer_cursor_radius;
|
||||
vec2 relTopleft = topleft - cursor_position.xz;
|
||||
vec2 rotatedTopleft;
|
||||
rotatedTopleft.x = relTopleft.x * sin(angle) - relTopleft.y * cos(angle);
|
||||
rotatedTopleft.y = relTopleft.y * sin(angle) + relTopleft.x * cos(angle);
|
||||
vec2 posRel2 = (vary_position.xz - rotatedTopleft) / (outer_cursor_radius * 2.0f);
|
||||
// vec2 texcoord = (vary_position.xz - topleft) / (outer_cursor_radius * 2.0f) - 0.5;
|
||||
// vec2 rotatedTexcoord;
|
||||
// rotatedTexcoord.x = texcoord.x * sin(angle) + texcoord.y * cos(angle) + 0.5;
|
||||
// rotatedTexcoord.y = texcoord.y * sin(angle) + texcoord.x * cos(angle) + 0.5;
|
||||
out_color.rgb = mix(out_color.rgb, texture(stampBrush, posRel2).rgb
|
||||
, 1.0 * (int(length(vary_position.xz - cursor_position.xz) / outer_cursor_radius < 1.0))
|
||||
* (1.0 - length(vary_position.xz - cursor_position.xz) / outer_cursor_radius));
|
||||
|
||||
vec2 posRel = vary_position.xz - cursor_position.xz;
|
||||
float pos_x = posRel.x * sin(angle) - posRel.y * cos(angle);
|
||||
float pos_z = posRel.y * sin(angle) + posRel.x * cos(angle);
|
||||
float diff_x = abs(pos_x);
|
||||
float diff_z = abs(pos_z);
|
||||
float inner_radius = outer_cursor_radius * inner_cursor_ratio;
|
||||
float d = length(fw);
|
||||
|
||||
float alpha = 1.0 * (1 - int((diff_x < outer_cursor_radius && diff_z < outer_cursor_radius
|
||||
&& (outer_cursor_radius - diff_x <= d || outer_cursor_radius - diff_z <= d)) || (diff_x < inner_radius
|
||||
&& diff_z < inner_radius && (inner_radius - diff_x <= d || inner_radius - diff_z <= d))));
|
||||
out_color.rgb = mix(cursor_color.rgb, out_color.rgb, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1360,7 +1360,7 @@ MapView::MapView( math::degrees camera_yaw0
|
||||
, _minimap_dock (new QDockWidget ("Minimap", this))
|
||||
, _texture_palette_dock(new QDockWidget(this))
|
||||
, _dockStamp{"Stamp Tool", this}
|
||||
, _modeStampTool{&_showStampPalette, this}
|
||||
, _modeStampTool{&_showStampPalette, &_cursorRotation, this}
|
||||
, _modeStampPaletteMain{this}
|
||||
{
|
||||
_main_window->setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
|
||||
@@ -1493,6 +1493,24 @@ auto MapView::populateImageModel(QStandardItemModel* model) const -> void
|
||||
}
|
||||
}
|
||||
|
||||
auto MapView::setBrushTexture(QPixmap const* pixmap) -> void
|
||||
{
|
||||
auto img{pixmap->toImage()};
|
||||
_data.clear();
|
||||
_data.resize(img.height() * img.width());
|
||||
_dims.first = img.width();
|
||||
_dims.second = img.height();
|
||||
|
||||
for(int i{}; i < img.height(); ++i)
|
||||
for(int j{}; j < img.width(); ++j)
|
||||
_data[i * img.width() + j] = img.pixel(j, i);
|
||||
}
|
||||
|
||||
auto MapView::getBrushTexture(void) -> opengl::texture*
|
||||
{
|
||||
return &_texBrush;
|
||||
}
|
||||
|
||||
void MapView::move_camera_with_auto_height (math::vector_3d const& pos)
|
||||
{
|
||||
makeCurrent();
|
||||
@@ -1722,6 +1740,17 @@ void MapView::paintGL()
|
||||
|
||||
gl.clear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
if(!_data.empty())
|
||||
{
|
||||
opengl::texture::set_active_texture(6);
|
||||
_texBrush.bind();
|
||||
gl.texImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, _dims.first, _dims.second, 0, GL_RGBA, GL_UNSIGNED_BYTE, _data.data());
|
||||
gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||
gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||
gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
gl.texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
}
|
||||
|
||||
draw_map();
|
||||
|
||||
if (saving_minimap)
|
||||
@@ -2616,6 +2645,7 @@ void MapView::draw_map()
|
||||
_world->draw ( model_view().transposed()
|
||||
, projection().transposed()
|
||||
, _cursor_pos
|
||||
, _cursorRotation
|
||||
, terrainMode == editing_mode::mccv ? shader_color : cursor_color
|
||||
, cursor_type.get()
|
||||
, radius
|
||||
@@ -2651,6 +2681,7 @@ void MapView::draw_map()
|
||||
, terrainTool->_edit_type
|
||||
, _display_all_water_layers.get() ? -1 : _displayed_water_layer.get()
|
||||
, _display_mode
|
||||
, &_texBrush
|
||||
);
|
||||
|
||||
// reset after each world::draw call
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
#include <noggit/unsigned_int_property.hpp>
|
||||
#include <noggit/Red/StampMode/Ui/Tool.hpp>
|
||||
#include <noggit/Red/StampMode/Ui/PaletteMain.hpp>
|
||||
#include <opengl/texture.hpp>
|
||||
|
||||
#include <boost/optional.hpp>
|
||||
|
||||
@@ -78,6 +79,7 @@ private:
|
||||
float _2d_zoom = 1.f;
|
||||
float moving, strafing, updown, mousedir, turn, lookat;
|
||||
math::vector_3d _cursor_pos;
|
||||
float _cursorRotation;
|
||||
bool look, freelook;
|
||||
bool ui_hidden = false;
|
||||
|
||||
@@ -100,6 +102,8 @@ private:
|
||||
public:
|
||||
noggit::bool_toggle_property _draw_hidden_models = {false};
|
||||
private:
|
||||
std::vector<unsigned> _data;
|
||||
std::pair<unsigned, unsigned> _dims;
|
||||
int _selected_area_id = -1;
|
||||
std::map<int, misc::random_color> _area_id_colors;
|
||||
|
||||
@@ -205,6 +209,8 @@ public:
|
||||
void saveMinimap(MinimapRenderSettings* settings);
|
||||
void initMinimapSave() { saving_minimap = true; };
|
||||
auto populateImageModel(QStandardItemModel* model) const -> void;
|
||||
auto setBrushTexture(QPixmap const* pixmap) -> void;
|
||||
auto getBrushTexture(void) -> opengl::texture*;
|
||||
noggit::camera* getCamera() { return &_camera; };
|
||||
|
||||
void set_editing_mode (editing_mode);
|
||||
@@ -327,4 +333,5 @@ private:
|
||||
noggit::Red::StampMode::Ui::Tool _modeStampTool;
|
||||
noggit::Red::StampMode::Ui::PaletteMain _modeStampPaletteMain;
|
||||
std::unordered_map<std::string, QPixmap> _images;
|
||||
opengl::texture _texBrush;
|
||||
};
|
||||
|
||||
@@ -27,6 +27,7 @@ PaletteMain::PaletteMain(MapView* parent)
|
||||
_view.setWrapping(true);
|
||||
_view.setModel(&_model);
|
||||
connect(&_view, &QAbstractItemView::clicked, [this](QModelIndex const& index) -> void { emit itemSelected(index.data(Qt::UserRole).value<QPixmap const*>()); });
|
||||
connect(this, &PaletteMain::itemSelected, [parent](QPixmap const* pixmap) -> void { parent->setBrushTexture(pixmap); });
|
||||
_layout.addWidget(&_view);
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ auto Tool::setPixmap(QPixmap const* pixmap) -> void
|
||||
_label.setPixmap(pixmap->scaled(128, 128));
|
||||
}
|
||||
|
||||
Tool::Tool(bool_toggle_property* showPalette, QWidget* parent)
|
||||
: QWidget{parent}, _radiusOuter{25.f}, _radiusInner{10.f}, _layout{this}, _label{this}
|
||||
Tool::Tool(bool_toggle_property* showPalette, float* cursorRotation, QWidget* parent)
|
||||
: QWidget{parent}, _cursorRotation{cursorRotation}, _radiusOuter{25.f}, _radiusInner{10.f}, _layout{this}, _label{this}
|
||||
, _btnPalette{"Open Palette", this}, _sliderRadiusOuter{Qt::Orientation::Horizontal, this}
|
||||
, _spinboxRadiusOuter{this}, _sliderRadiusInner{Qt::Orientation::Horizontal, this}
|
||||
, _spinboxRadiusInner{this}, _dialRotation{this}, _curPixmap{nullptr}
|
||||
@@ -92,7 +92,15 @@ Tool::Tool(bool_toggle_property* showPalette, QWidget* parent)
|
||||
QSignalBlocker blocker{&_sliderRadiusInner};
|
||||
_sliderRadiusInner.setValue(val);
|
||||
});
|
||||
connect(&_dialRotation, &QDial::valueChanged, [this](int val) -> void{ _rotation = val; });
|
||||
auto label{new QLabel{this}};
|
||||
_layout.addRow(label);
|
||||
connect(&_dialRotation, &QDial::valueChanged, [this, label](int val) -> void
|
||||
{
|
||||
_rotation = val;
|
||||
*_cursorRotation = _rotation / 360.0f;
|
||||
label->setText(QString::number(*_cursorRotation));
|
||||
});
|
||||
_dialRotation.setValue(0);
|
||||
}
|
||||
|
||||
auto Tool::getOuterRadius(void) const -> float
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace noggit
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit
|
||||
Tool(bool_toggle_property* showPalette, QWidget* parent = nullptr);
|
||||
Tool(bool_toggle_property* showPalette, float* cursorRotation, QWidget* parent = nullptr);
|
||||
auto stamp(World* world, math::vector_3d const& pos, float dt, bool doAdd) const -> void;
|
||||
auto getOuterRadius(void) const -> float;
|
||||
auto getInnerRadius(void) const -> float;
|
||||
@@ -36,6 +36,7 @@ namespace noggit
|
||||
public slots:
|
||||
void setPixmap(QPixmap const* pixmap);
|
||||
private:
|
||||
float* _cursorRotation;
|
||||
float _radiusOuter;
|
||||
float _radiusInner;
|
||||
float _rotation;
|
||||
|
||||
@@ -642,6 +642,7 @@ void World::initDisplay()
|
||||
void World::draw ( math::matrix_4x4 const& model_view
|
||||
, math::matrix_4x4 const& projection
|
||||
, math::vector_3d const& cursor_pos
|
||||
, float cursorRotation
|
||||
, math::vector_4d const& cursor_color
|
||||
, int cursor_type
|
||||
, float brush_radius
|
||||
@@ -677,6 +678,7 @@ void World::draw ( math::matrix_4x4 const& model_view
|
||||
, eTerrainType ground_editing_brush
|
||||
, int water_layer
|
||||
, display_mode display
|
||||
, opengl::texture* texBrush
|
||||
)
|
||||
{
|
||||
if (!_display_initialized)
|
||||
@@ -903,6 +905,7 @@ void World::draw ( math::matrix_4x4 const& model_view
|
||||
{
|
||||
mcnk_shader.uniform ("draw_cursor_circle", 1);
|
||||
mcnk_shader.uniform ("cursor_position", cursor_pos);
|
||||
mcnk_shader.uniform("cursorRotation", cursorRotation);
|
||||
mcnk_shader.uniform ("outer_cursor_radius", brush_radius);
|
||||
mcnk_shader.uniform ("inner_cursor_ratio", inner_radius_ratio);
|
||||
mcnk_shader.uniform ("cursor_color", cursor_color);
|
||||
@@ -912,12 +915,15 @@ void World::draw ( math::matrix_4x4 const& model_view
|
||||
mcnk_shader.uniform ("draw_cursor_circle", 0);
|
||||
}
|
||||
|
||||
opengl::texture::set_active_texture(6);
|
||||
texBrush->bind();
|
||||
|
||||
mcnk_shader.uniform("alphamap", 0);
|
||||
mcnk_shader.uniform("tex0", 1);
|
||||
mcnk_shader.uniform("tex1", 2);
|
||||
mcnk_shader.uniform("tex2", 3);
|
||||
mcnk_shader.uniform("tex3", 4);
|
||||
//mcnk_shader.uniform("stampBrush", 5);
|
||||
mcnk_shader.uniform("stampBrush", 6);
|
||||
mcnk_shader.uniform("draw_shadows", 1);
|
||||
mcnk_shader.uniform("shadow_map", 5);
|
||||
|
||||
|
||||
@@ -93,6 +93,7 @@ public:
|
||||
void draw ( math::matrix_4x4 const& model_view
|
||||
, math::matrix_4x4 const& projection
|
||||
, math::vector_3d const& cursor_pos
|
||||
, float cursorRotation
|
||||
, math::vector_4d const& cursor_color
|
||||
, int cursor_type
|
||||
, float brush_radius
|
||||
@@ -129,6 +130,7 @@ public:
|
||||
, eTerrainType ground_editing_brush
|
||||
, int water_layer
|
||||
, display_mode display
|
||||
, opengl::texture* texBrush
|
||||
);
|
||||
|
||||
unsigned int getAreaID (math::vector_3d const&);
|
||||
|
||||
Reference in New Issue
Block a user