Brushes work now, curve editor
This commit is contained in:
Binary file not shown.
|
Before Width: | Height: | Size: 337 KiB After Width: | Height: | Size: 337 KiB |
@@ -446,7 +446,42 @@ float VoxelGeneratorImgMapper::get_height_full(const Vector3 &v)
|
||||
|
||||
void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int id)
|
||||
{
|
||||
print_line("draw_brush " + (v.operator String()) + " " +
|
||||
String::num(r) + " " + String::num(s) + " " + itos(id));
|
||||
ERR_FAIL_COND(!_image_draw.is_valid());
|
||||
if (!curve1.is_valid())
|
||||
{
|
||||
int i;
|
||||
curve1.instance();
|
||||
curve1->set_min_value(-100);
|
||||
curve1->set_max_value(100);
|
||||
Array curve_data;
|
||||
std::vector<Variant> data = {
|
||||
Vector2(0, 100), 0.0f, 0.0f, 0, 0,
|
||||
Vector2(0.492823, 81.8182), -150.0, -150.0, 0, 0,
|
||||
Vector2(1, 21.8182), -123.243, -123.243, 0, 0,
|
||||
Vector2(1, 3.63635), 0.0, 0.0, 0, 0};
|
||||
curve_data.resize(data.size());
|
||||
for (i = 0; i < (int)data.size(); i++)
|
||||
curve_data[i] = data[i];
|
||||
curve1->set_data(curve_data);
|
||||
}
|
||||
if (!curve2.is_valid())
|
||||
{
|
||||
int i;
|
||||
curve2.instance();
|
||||
curve2->set_min_value(-100);
|
||||
curve2->set_max_value(100);
|
||||
Array curve_data;
|
||||
std::vector<Variant> data = {
|
||||
Vector2(0, -100), 0.0, 0.0, 0, 0,
|
||||
Vector2(0.813397, -30.9091), 86.8571, 86.8571, 0, 0,
|
||||
Vector2(1, -14.5455), 57.0, 0.0, 0, 0};
|
||||
curve_data.resize(data.size());
|
||||
for (i = 0; i < (int)data.size(); i++)
|
||||
curve_data[i] = data[i];
|
||||
curve2->set_data(curve_data);
|
||||
}
|
||||
ERR_FAIL_COND(!curve1.is_valid());
|
||||
ERR_FAIL_COND(!curve2.is_valid());
|
||||
int i, j;
|
||||
@@ -641,6 +676,7 @@ void VoxelGeneratorImgMapper::draw_brush(const Vector3 &v, float r, float s, int
|
||||
void VoxelGeneratorImgMapper::compose()
|
||||
{
|
||||
Ref<Image> copy;
|
||||
print_line("compose");
|
||||
ERR_FAIL_COND(!_image_bg.is_valid());
|
||||
ERR_FAIL_COND(!_image_overlay.is_valid());
|
||||
ERR_FAIL_COND(!_image_draw.is_valid());
|
||||
@@ -680,11 +716,11 @@ void VoxelGeneratorImgMapper::compose()
|
||||
void VoxelGeneratorImgMapper::save_png()
|
||||
{
|
||||
if (_image_bg.is_valid())
|
||||
_image_bg->save_png("res://textures/terrain.png");
|
||||
_image_bg->save_png("res://terrain/terrain.png");
|
||||
if (_image_draw.is_valid())
|
||||
_image_draw->save_png("res://textures/terrain_draw.png");
|
||||
_image_draw->save_png("res://terrain/terrain_draw.png");
|
||||
if (_image_overlay.is_valid())
|
||||
_image_overlay->save_png("res://textures/terrain_edit.png");
|
||||
_image_overlay->save_png("res://terrain/terrain_edit.png");
|
||||
}
|
||||
|
||||
void VoxelGeneratorImgMapper::set_curve1(const Ref<Curve> &curve)
|
||||
|
||||
@@ -360,6 +360,14 @@ void StreamWorld::run_command(const String &command,
|
||||
} else if (command == "remove_road_meshes") {
|
||||
RoadProcessing::remove_road_meshes(this);
|
||||
print_line("remove_road_meshes done");
|
||||
} else if (command == "nudge_generator") {
|
||||
auto gen = terrain->get_generator();
|
||||
terrain->set_generator(Ref<VoxelGenerator>());
|
||||
terrain->set_generator(gen);
|
||||
update_items();
|
||||
RoadProcessing::road_setup(this, 0);
|
||||
update_view();
|
||||
assert(false);
|
||||
} else
|
||||
print_error("No command " + command);
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,90 @@
|
||||
#define TERRAIN_EDITOR_H_
|
||||
class WorldEditor;
|
||||
class VoxelGeneratorImgMapper;
|
||||
|
||||
class BrushCurveEditor : public Control {
|
||||
GDCLASS(BrushCurveEditor, Control);
|
||||
|
||||
public:
|
||||
BrushCurveEditor();
|
||||
|
||||
Size2 get_minimum_size() const;
|
||||
|
||||
void set_curve(Ref<Curve> curve);
|
||||
|
||||
enum PresetID {
|
||||
PRESET_FLAT0 = 0,
|
||||
PRESET_FLAT1,
|
||||
PRESET_LINEAR,
|
||||
PRESET_EASE_IN,
|
||||
PRESET_EASE_OUT,
|
||||
PRESET_SMOOTHSTEP,
|
||||
PRESET_COUNT
|
||||
};
|
||||
|
||||
enum ContextAction {
|
||||
CONTEXT_ADD_POINT = 0,
|
||||
CONTEXT_REMOVE_POINT,
|
||||
CONTEXT_LINEAR,
|
||||
CONTEXT_LEFT_LINEAR,
|
||||
CONTEXT_RIGHT_LINEAR
|
||||
};
|
||||
|
||||
enum TangentIndex {
|
||||
TANGENT_NONE = -1,
|
||||
TANGENT_LEFT = 0,
|
||||
TANGENT_RIGHT = 1
|
||||
};
|
||||
|
||||
protected:
|
||||
void _notification(int p_what);
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
private:
|
||||
void on_gui_input(const Ref<InputEvent> &p_event);
|
||||
void on_preset_item_selected(int preset_id);
|
||||
void _curve_changed();
|
||||
void on_context_menu_item_selected(int action_id);
|
||||
|
||||
void open_context_menu(Vector2 pos);
|
||||
int get_point_at(Vector2 pos) const;
|
||||
TangentIndex get_tangent_at(Vector2 pos) const;
|
||||
void add_point(Vector2 pos);
|
||||
void remove_point(int index);
|
||||
void toggle_linear(TangentIndex tangent = TANGENT_NONE);
|
||||
void set_selected_point(int index);
|
||||
void set_hover_point_index(int index);
|
||||
void update_view_transform();
|
||||
|
||||
Vector2 get_tangent_view_pos(int i, TangentIndex tangent) const;
|
||||
Vector2 get_view_pos(Vector2 world_pos) const;
|
||||
Vector2 get_world_pos(Vector2 view_pos) const;
|
||||
|
||||
void _draw();
|
||||
|
||||
private:
|
||||
Transform2D _world_to_view;
|
||||
|
||||
Ref<Curve> _curve_ref;
|
||||
PopupMenu *_context_menu;
|
||||
PopupMenu *_presets_menu;
|
||||
|
||||
Array _undo_data;
|
||||
bool _has_undo_data;
|
||||
|
||||
Vector2 _context_click_pos;
|
||||
int _selected_point;
|
||||
int _hover_point;
|
||||
TangentIndex _selected_tangent;
|
||||
bool _dragging;
|
||||
|
||||
// Constant
|
||||
float _hover_radius;
|
||||
float _tangents_length;
|
||||
float _gizmo_handle_scale = 1.0;
|
||||
};
|
||||
|
||||
class TerrainEditor {
|
||||
WorldEditor *editor;
|
||||
bool active;
|
||||
@@ -11,6 +95,9 @@ class TerrainEditor {
|
||||
bool camera_moved;
|
||||
Vector3 camera_motion;
|
||||
Ref<VoxelGeneratorImgMapper> imgmapper;
|
||||
int current_brush;
|
||||
float pressure;
|
||||
HashMap<int, Ref<Curve> > brush_curves;
|
||||
|
||||
public:
|
||||
void exit();
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "menu_handler.h"
|
||||
#include "ui_field_builder.h"
|
||||
#include "building_layout_graph_ui.h"
|
||||
#include "signal_handler.h"
|
||||
#include "main_tabs.h"
|
||||
|
||||
template <class T>
|
||||
@@ -201,14 +202,18 @@ void MainTabs::_notification(int which)
|
||||
/* 1 */
|
||||
"Brush", 0, "terrain_select_brush",
|
||||
};
|
||||
HashMap<String, Object *> save_data;
|
||||
/* clang-format on */
|
||||
HashMap<String, Object *> save_data;
|
||||
ui_field::ui_field_builder(this, tab,
|
||||
"l_p{v{lo#!$}}",
|
||||
args_data.data(),
|
||||
args_data.size(),
|
||||
&save_data);
|
||||
assert(save_data.has("terrain_select_brush"));
|
||||
OptionButton *ob = Object::cast_to<OptionButton>(
|
||||
save_data["terrain_select_brush"]);
|
||||
memnew(OptionButtonHandler(
|
||||
ob, "terrain_brush_select"));
|
||||
} break;
|
||||
case 1: {
|
||||
// VBoxContainer *v = memnew(VBoxContainer);
|
||||
|
||||
@@ -338,6 +338,9 @@ void WorldEditor::editor_command(const String &command,
|
||||
} else if (command == "rebuild_roads") {
|
||||
if (stream_world)
|
||||
stream_world->run_command(command, args);
|
||||
} else if (command == "nudge_generator") {
|
||||
if (stream_world)
|
||||
stream_world->run_command(command, args);
|
||||
} else if (command == "remove_road_meshes") {
|
||||
if (stream_world)
|
||||
stream_world->run_command(command, args);
|
||||
|
||||
Reference in New Issue
Block a user