Worked on brush parameter editing
This commit is contained in:
13
godot/astream/brush.ini
Normal file
13
godot/astream/brush.ini
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
[brushes/0]
|
||||||
|
|
||||||
|
curve=[ Vector2( 0, 2 ), 0.0, 0.0, 0, 0, Vector2( 1, -0.0338984 ), 0.0, 0.0, 0, 0 ]
|
||||||
|
radius=2.0
|
||||||
|
strength=1.0
|
||||||
|
flags=0
|
||||||
|
|
||||||
|
[brushes/1]
|
||||||
|
|
||||||
|
curve=[ ]
|
||||||
|
radius=1.0
|
||||||
|
strength=1.0
|
||||||
|
flags=0
|
||||||
@@ -71,13 +71,13 @@ focus_mode = 2
|
|||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
margin_top = 52.0
|
margin_top = 52.0
|
||||||
margin_right = 248.0
|
margin_right = 248.0
|
||||||
margin_bottom = 128.0
|
margin_bottom = 190.0
|
||||||
|
|
||||||
[node name="v_terrain" type="VBoxContainer" parent="VBoxContainer"]
|
[node name="v_terrain" type="VBoxContainer" parent="VBoxContainer"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
margin_top = 132.0
|
margin_top = 194.0
|
||||||
margin_right = 248.0
|
margin_right = 248.0
|
||||||
margin_bottom = 132.0
|
margin_bottom = 194.0
|
||||||
|
|
||||||
[node name="v_buildings" type="VBoxContainer" parent="VBoxContainer"]
|
[node name="v_buildings" type="VBoxContainer" parent="VBoxContainer"]
|
||||||
unique_name_in_owner = true
|
unique_name_in_owner = true
|
||||||
@@ -550,6 +550,5 @@ mesh = SubResource( 14 )
|
|||||||
material/0 = SubResource( 11 )
|
material/0 = SubResource( 11 )
|
||||||
|
|
||||||
[node name="mi2" type="MeshInstance" parent="terrain_cursor"]
|
[node name="mi2" type="MeshInstance" parent="terrain_cursor"]
|
||||||
transform = Transform( 1, 0, 0, 0, 1, 0, 0, 0, 1, 0, 30, 0 )
|
|
||||||
mesh = SubResource( 15 )
|
mesh = SubResource( 15 )
|
||||||
material/0 = SubResource( 11 )
|
material/0 = SubResource( 11 )
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 337 KiB After Width: | Height: | Size: 337 KiB |
@@ -86,9 +86,14 @@
|
|||||||
obj_name, sig_name, hdecl, hargs, hbind) \
|
obj_name, sig_name, hdecl, hargs, hbind) \
|
||||||
typedef _GODOT_HANDLER_CONCAT2(class_name, __LINE__) class_name;
|
typedef _GODOT_HANDLER_CONCAT2(class_name, __LINE__) class_name;
|
||||||
|
|
||||||
GODOT_HANDLER_METHOD(BrushSelectHandler, OptionButton, item_selected,
|
//GODOT_HANDLER_METHOD(BrushSelectHandler, OptionButton, item_selected,
|
||||||
brush_select, (int id), (id), D_METHOD("handler", "id"))
|
// brush_select, (int id), (id), D_METHOD("handler", "id"))
|
||||||
GODOT_HANDLER_EVENT_METHOD(OptionButtonHandler, OptionButton, item_selected,
|
GODOT_HANDLER_EVENT_METHOD(OptionButtonHandler, OptionButton, item_selected,
|
||||||
(int id), (id), D_METHOD("handler", "id"))
|
(int id), (id), D_METHOD("handler", "id"))
|
||||||
|
GODOT_HANDLER_EVENT_METHOD(ButtonPressHandler, Button, pressed, (), (),
|
||||||
|
D_METHOD("handler"))
|
||||||
|
GODOT_HANDLER_EVENT_METHOD(LineEditString, LineEdit, text_changed,
|
||||||
|
(const String &text), (text),
|
||||||
|
D_METHOD("handler", "text"))
|
||||||
|
|
||||||
#endif // SIGNAL_HANDLER_H_
|
#endif // SIGNAL_HANDLER_H_
|
||||||
@@ -3,11 +3,18 @@
|
|||||||
#include <core/math/vector3.h>
|
#include <core/math/vector3.h>
|
||||||
#include <scene/3d/camera.h>
|
#include <scene/3d/camera.h>
|
||||||
#include <scene/gui/option_button.h>
|
#include <scene/gui/option_button.h>
|
||||||
|
#include <scene/gui/label.h>
|
||||||
|
#include <scene/gui/line_edit.h>
|
||||||
|
#include <scene/gui/box_container.h>
|
||||||
|
#include <scene/gui/check_box.h>
|
||||||
|
#include <scene/3d/mesh_instance.h>
|
||||||
|
#include <scene/resources/primitive_meshes.h>
|
||||||
#include <core/os/keyboard.h>
|
#include <core/os/keyboard.h>
|
||||||
#include <core/os/input.h>
|
#include <core/os/input.h>
|
||||||
|
|
||||||
#include "editor_event.h"
|
#include "editor_event.h"
|
||||||
#include "world_editor.h"
|
#include "world_editor.h"
|
||||||
|
#include "signal_handler.h"
|
||||||
#include "terrain_editor.h"
|
#include "terrain_editor.h"
|
||||||
|
|
||||||
void TerrainEditor::exit()
|
void TerrainEditor::exit()
|
||||||
@@ -82,6 +89,8 @@ void TerrainEditor::activate()
|
|||||||
ib++;
|
ib++;
|
||||||
}
|
}
|
||||||
assert(brushes.size() > 0);
|
assert(brushes.size() > 0);
|
||||||
|
EditorEvent::get_singleton()->event.emit("terrain_load_data",
|
||||||
|
varray(brushes));
|
||||||
EditorEvent::get_singleton()->event.emit("terrain_update_brushes",
|
EditorEvent::get_singleton()->event.emit("terrain_update_brushes",
|
||||||
varray(brushes));
|
varray(brushes));
|
||||||
active = true;
|
active = true;
|
||||||
@@ -162,6 +171,9 @@ end:;
|
|||||||
brush_curves[id].instance();
|
brush_curves[id].instance();
|
||||||
brush_curves[id]->set_min_value(-2);
|
brush_curves[id]->set_min_value(-2);
|
||||||
brush_curves[id]->set_max_value(2);
|
brush_curves[id]->set_max_value(2);
|
||||||
|
brush_radius[id] = 1.0f;
|
||||||
|
brush_strength[id] = 1.0f;
|
||||||
|
brush_flags[id] = 0;
|
||||||
}
|
}
|
||||||
if (!ob->get_parent()->has_meta("brush_editor")) {
|
if (!ob->get_parent()->has_meta("brush_editor")) {
|
||||||
BrushCurveEditor *curve_edit = memnew(BrushCurveEditor);
|
BrushCurveEditor *curve_edit = memnew(BrushCurveEditor);
|
||||||
@@ -176,6 +188,131 @@ end:;
|
|||||||
"brush_editor"));
|
"brush_editor"));
|
||||||
curve_edit->set_curve(brush_curves[id]);
|
curve_edit->set_curve(brush_curves[id]);
|
||||||
}
|
}
|
||||||
|
if (!ob->get_parent()->has_meta("brush_radius_label")) {
|
||||||
|
Label *radius_label = memnew(Label);
|
||||||
|
radius_label->set_text("Radius");
|
||||||
|
ob->get_parent()->call_deferred("add_child",
|
||||||
|
radius_label);
|
||||||
|
ob->get_parent()->set_meta("brush_radius_label",
|
||||||
|
radius_label);
|
||||||
|
} else {
|
||||||
|
Label *radius_label = Object::cast_to<Label>(
|
||||||
|
ob->get_parent()->get_meta(
|
||||||
|
"brush_radius_label"));
|
||||||
|
radius_label->set_text("Radius");
|
||||||
|
}
|
||||||
|
if (!ob->get_parent()->has_meta("brush_radius")) {
|
||||||
|
LineEdit *line_edit = memnew(LineEdit);
|
||||||
|
ob->get_parent()->call_deferred("add_child", line_edit);
|
||||||
|
ob->get_parent()->set_meta("brush_radius", line_edit);
|
||||||
|
line_edit->set_text(String::num(brush_radius[id]));
|
||||||
|
memnew(LineEditString(line_edit,
|
||||||
|
"terrain_brush_radius_change"));
|
||||||
|
} else {
|
||||||
|
LineEdit *line_edit = Object::cast_to<LineEdit>(
|
||||||
|
ob->get_parent()->get_meta("brush_radius"));
|
||||||
|
line_edit->set_text(String::num(brush_radius[id]));
|
||||||
|
}
|
||||||
|
if (!ob->get_parent()->has_meta("brush_strength_label")) {
|
||||||
|
Label *strength_label = memnew(Label);
|
||||||
|
strength_label->set_text("Strength");
|
||||||
|
ob->get_parent()->call_deferred("add_child",
|
||||||
|
strength_label);
|
||||||
|
ob->get_parent()->set_meta("brush_strength_label",
|
||||||
|
strength_label);
|
||||||
|
} else {
|
||||||
|
Label *strength_label = Object::cast_to<Label>(
|
||||||
|
ob->get_parent()->get_meta(
|
||||||
|
"brush_strength_label"));
|
||||||
|
strength_label->set_text("Strength");
|
||||||
|
}
|
||||||
|
if (!ob->get_parent()->has_meta("brush_strength")) {
|
||||||
|
LineEdit *strength_edit = memnew(LineEdit);
|
||||||
|
strength_edit->set_text(
|
||||||
|
String::num(brush_strength[id]));
|
||||||
|
ob->get_parent()->call_deferred("add_child",
|
||||||
|
strength_edit);
|
||||||
|
ob->get_parent()->set_meta("brush_strength",
|
||||||
|
strength_edit);
|
||||||
|
} else {
|
||||||
|
LineEdit *strength_edit = Object::cast_to<LineEdit>(
|
||||||
|
ob->get_parent()->get_meta("brush_strength"));
|
||||||
|
strength_edit->set_text(
|
||||||
|
String::num(brush_strength[id]));
|
||||||
|
}
|
||||||
|
struct flag_info {
|
||||||
|
String caption;
|
||||||
|
};
|
||||||
|
struct flag_info flag_data[] = {
|
||||||
|
{ "Absolute" },
|
||||||
|
{ "Random" },
|
||||||
|
};
|
||||||
|
if (!ob->get_parent()->has_meta("brush_flags")) {
|
||||||
|
VBoxContainer *flags_ui = memnew(VBoxContainer);
|
||||||
|
int flags = brush_flags[id];
|
||||||
|
int f_idx;
|
||||||
|
for (f_idx = 0;
|
||||||
|
f_idx <
|
||||||
|
(int)sizeof(flag_data) / (int)sizeof(flag_data[0]);
|
||||||
|
f_idx++) {
|
||||||
|
CheckBox *cb = memnew(CheckBox);
|
||||||
|
cb->set_text(flag_data[f_idx].caption);
|
||||||
|
cb->set_pressed_no_signal(flags & (1 << f_idx));
|
||||||
|
flags_ui->add_child(cb);
|
||||||
|
}
|
||||||
|
ob->get_parent()->call_deferred("add_child", flags_ui);
|
||||||
|
ob->get_parent()->set_meta("brush_flags", flags_ui);
|
||||||
|
} else {
|
||||||
|
VBoxContainer *flags_ui = Object::cast_to<VBoxContainer>(
|
||||||
|
ob->get_parent()->get_meta("brush_flags"));
|
||||||
|
int flags = brush_flags[id];
|
||||||
|
int f_idx;
|
||||||
|
for (f_idx = 0;
|
||||||
|
f_idx <
|
||||||
|
(int)sizeof(flag_data) / (int)sizeof(flag_data[0]);
|
||||||
|
f_idx++) {
|
||||||
|
CheckBox *cb = Object::cast_to<CheckBox>(
|
||||||
|
flags_ui->get_child(f_idx));
|
||||||
|
cb->set_text(flag_data[f_idx].caption);
|
||||||
|
cb->set_pressed_no_signal(flags & (1 << f_idx));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (current_brush >= 0) {
|
||||||
|
MeshInstance *cursor_mesh =
|
||||||
|
get_as_node<MeshInstance>(cursor_name + "/mi2");
|
||||||
|
assert(cursor_mesh);
|
||||||
|
Ref<TorusMesh> torus_mesh = cursor_mesh->get_mesh();
|
||||||
|
if (torus_mesh.is_valid()) {
|
||||||
|
torus_mesh->set_inner_radius(
|
||||||
|
brush_radius[current_brush]);
|
||||||
|
torus_mesh->set_outer_radius(
|
||||||
|
brush_radius[current_brush] + 3.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (event == "terrain_save_data") {
|
||||||
|
/* save brush settings */
|
||||||
|
save_data();
|
||||||
|
} else if (event == "terrain_load_data") {
|
||||||
|
load_data();
|
||||||
|
} else if (event == "terrain_brush_radius_change") {
|
||||||
|
String data = args[1];
|
||||||
|
data = data.strip_edges();
|
||||||
|
if ((data.is_valid_float() || data.is_valid_integer()) &&
|
||||||
|
current_brush >= 0) {
|
||||||
|
brush_radius[current_brush] =
|
||||||
|
MAX(data.to_float(), 1.0f);
|
||||||
|
print_line(data);
|
||||||
|
MeshInstance *cursor_mesh =
|
||||||
|
get_as_node<MeshInstance>(cursor_name + "/mi2");
|
||||||
|
assert(cursor_mesh);
|
||||||
|
Ref<TorusMesh> torus_mesh = cursor_mesh->get_mesh();
|
||||||
|
if (torus_mesh.is_valid()) {
|
||||||
|
torus_mesh->set_inner_radius(
|
||||||
|
brush_radius[current_brush]);
|
||||||
|
torus_mesh->set_outer_radius(
|
||||||
|
brush_radius[current_brush] + 3.0f);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -208,6 +345,49 @@ int TerrainEditor::get_camera_mode() const
|
|||||||
{
|
{
|
||||||
return editor->get_camera_mode();
|
return editor->get_camera_mode();
|
||||||
}
|
}
|
||||||
|
void TerrainEditor::save_data()
|
||||||
|
{
|
||||||
|
List<int> curves_list;
|
||||||
|
brush_curves.get_key_list(&curves_list);
|
||||||
|
List<int>::Element *e = curves_list.front();
|
||||||
|
while (e) {
|
||||||
|
int idx = e->get();
|
||||||
|
config.set_value("brushes/" + itos(idx), "curve",
|
||||||
|
brush_curves[idx]->get_data());
|
||||||
|
config.set_value("brushes/" + itos(idx), "radius",
|
||||||
|
brush_radius[idx]);
|
||||||
|
config.set_value("brushes/" + itos(idx), "strength",
|
||||||
|
brush_strength[idx]);
|
||||||
|
config.set_value("brushes/" + itos(idx), "flags",
|
||||||
|
brush_flags[idx]);
|
||||||
|
e = e->next();
|
||||||
|
}
|
||||||
|
config.save("res://astream/brush.ini");
|
||||||
|
}
|
||||||
|
void TerrainEditor::load_data()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
Error err = config.load("res://astream/brush.ini");
|
||||||
|
if (err != OK)
|
||||||
|
return;
|
||||||
|
for (i = 0; i < 10000; i++) {
|
||||||
|
if (config.has_section("brushes/" + itos(i))) {
|
||||||
|
brush_curves[i] = Ref<Curve>();
|
||||||
|
brush_curves[i].instance();
|
||||||
|
Array curve_data = config.get_value(
|
||||||
|
"brushes/" + itos(i), "curve", Array());
|
||||||
|
brush_curves[i]->set_data(curve_data);
|
||||||
|
brush_curves[i]->set_min_value(-2);
|
||||||
|
brush_curves[i]->set_max_value(2);
|
||||||
|
brush_radius[i] = config.get_value("brushes/" + itos(i),
|
||||||
|
"radius", 1.0f);
|
||||||
|
brush_strength[i] = config.get_value(
|
||||||
|
"brushes/" + itos(i), "strength", 1.0f);
|
||||||
|
brush_flags[i] = config.get_value("brushes/" + itos(i),
|
||||||
|
"flags", 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Node *TerrainEditor::scene()
|
Node *TerrainEditor::scene()
|
||||||
{
|
{
|
||||||
return editor->get_tree()->get_current_scene();
|
return editor->get_tree()->get_current_scene();
|
||||||
|
|||||||
@@ -98,6 +98,9 @@ class TerrainEditor {
|
|||||||
int current_brush;
|
int current_brush;
|
||||||
float pressure;
|
float pressure;
|
||||||
HashMap<int, Ref<Curve> > brush_curves;
|
HashMap<int, Ref<Curve> > brush_curves;
|
||||||
|
HashMap<int, float> brush_radius, brush_strength;
|
||||||
|
HashMap<int, int> brush_flags;
|
||||||
|
ConfigFile config;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void exit();
|
void exit();
|
||||||
@@ -114,6 +117,8 @@ protected:
|
|||||||
void set_ui_cursor_position(const Vector3 &cursor_position);
|
void set_ui_cursor_position(const Vector3 &cursor_position);
|
||||||
template <class T> T *get_as_node(const String &path);
|
template <class T> T *get_as_node(const String &path);
|
||||||
int get_camera_mode() const;
|
int get_camera_mode() const;
|
||||||
|
void save_data();
|
||||||
|
void load_data();
|
||||||
Node *scene();
|
Node *scene();
|
||||||
};
|
};
|
||||||
#endif // TERRAIN_EDITOR_H_
|
#endif // TERRAIN_EDITOR_H_
|
||||||
@@ -201,19 +201,26 @@ void MainTabs::_notification(int which)
|
|||||||
"Brush",
|
"Brush",
|
||||||
/* 1 */
|
/* 1 */
|
||||||
"Brush", 0, "terrain_select_brush",
|
"Brush", 0, "terrain_select_brush",
|
||||||
|
/* 2 */
|
||||||
|
"Save brush data", "save_brush_data",
|
||||||
};
|
};
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
HashMap<String, Object *> save_data;
|
HashMap<String, Object *> save_data;
|
||||||
ui_field::ui_field_builder(this, tab,
|
ui_field::ui_field_builder(this, tab,
|
||||||
"l_p{v{lo#!$}}",
|
"l_p{v{lo#!$b#!$}}",
|
||||||
args_data.data(),
|
args_data.data(),
|
||||||
args_data.size(),
|
args_data.size(),
|
||||||
&save_data);
|
&save_data);
|
||||||
assert(save_data.has("terrain_select_brush"));
|
assert(save_data.has("terrain_select_brush"));
|
||||||
|
assert(save_data.has("save_brush_data"));
|
||||||
OptionButton *ob = Object::cast_to<OptionButton>(
|
OptionButton *ob = Object::cast_to<OptionButton>(
|
||||||
save_data["terrain_select_brush"]);
|
save_data["terrain_select_brush"]);
|
||||||
memnew(OptionButtonHandler(
|
memnew(OptionButtonHandler(
|
||||||
ob, "terrain_brush_select"));
|
ob, "terrain_brush_select"));
|
||||||
|
Button *b = Object::cast_to<Button>(
|
||||||
|
save_data["save_brush_data"]);
|
||||||
|
memnew(ButtonPressHandler(b,
|
||||||
|
"terrain_save_data"));
|
||||||
} break;
|
} break;
|
||||||
case 1: {
|
case 1: {
|
||||||
// VBoxContainer *v = memnew(VBoxContainer);
|
// VBoxContainer *v = memnew(VBoxContainer);
|
||||||
|
|||||||
Reference in New Issue
Block a user