|
|
|
|
@@ -3,11 +3,18 @@
|
|
|
|
|
#include <core/math/vector3.h>
|
|
|
|
|
#include <scene/3d/camera.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/input.h>
|
|
|
|
|
|
|
|
|
|
#include "editor_event.h"
|
|
|
|
|
#include "world_editor.h"
|
|
|
|
|
#include "signal_handler.h"
|
|
|
|
|
#include "terrain_editor.h"
|
|
|
|
|
|
|
|
|
|
void TerrainEditor::exit()
|
|
|
|
|
@@ -82,6 +89,8 @@ void TerrainEditor::activate()
|
|
|
|
|
ib++;
|
|
|
|
|
}
|
|
|
|
|
assert(brushes.size() > 0);
|
|
|
|
|
EditorEvent::get_singleton()->event.emit("terrain_load_data",
|
|
|
|
|
varray(brushes));
|
|
|
|
|
EditorEvent::get_singleton()->event.emit("terrain_update_brushes",
|
|
|
|
|
varray(brushes));
|
|
|
|
|
active = true;
|
|
|
|
|
@@ -162,6 +171,9 @@ end:;
|
|
|
|
|
brush_curves[id].instance();
|
|
|
|
|
brush_curves[id]->set_min_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")) {
|
|
|
|
|
BrushCurveEditor *curve_edit = memnew(BrushCurveEditor);
|
|
|
|
|
@@ -176,6 +188,131 @@ end:;
|
|
|
|
|
"brush_editor"));
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
return editor->get_tree()->get_current_scene();
|
|
|
|
|
|