rebuilding roads done, closes #20

This commit is contained in:
2024-09-14 17:00:08 +03:00
parent c95976016e
commit 01c69a4ae9
7 changed files with 51 additions and 18 deletions

View File

@@ -323,6 +323,12 @@ protected:
case 31:
editor->place_generated_objects();
break;
case 32:
editor->rebuild_roads();
break;
case 33:
editor->remove_road_meshes();
break;
case 51:
editor->set_point_to_cursor();
break;
@@ -885,6 +891,16 @@ void RoadLinesEditor::place_generated_objects()
{
place_zebras();
}
void RoadLinesEditor::rebuild_roads()
{
Array args;
editor->editor_command("rebuild_roads", args);
}
void RoadLinesEditor::remove_road_meshes()
{
Array args;
editor->editor_command("remove_road_meshes", args);
}
void RoadLinesEditor::place_zebras()
{
editor->remove_buildings_by_prefix("zebra");

View File

@@ -44,6 +44,8 @@ public:
String get_current_line_metadata() const;
void remove_generated_stuff();
void place_generated_objects();
void rebuild_roads();
void remove_road_meshes();
protected:
void activate();

View File

@@ -56,6 +56,7 @@ struct RoadLinesProcessing {
int i;
List<String> keys;
RoadLinesData *rld = RoadLinesData::get_singleton();
edges.clear();
rld->get_road_lines_key_list(&keys);
List<String>::Element *e = keys.front();
while (e) {
@@ -184,7 +185,7 @@ struct RoadLinesProcessing {
singleton = nullptr;
}
}
void road_setup(Node *base)
void road_setup()
{
RoadLinesData *rld = RoadLinesData::get_singleton();
std::vector<Vector3> road_lines_nodes;
@@ -195,6 +196,7 @@ struct RoadLinesProcessing {
rld->process_lines(road_lines_nodes_hash, road_lines_nodes);
create_nodes(road_lines_nodes);
create_edges();
wedges.clear();
build_wedges(wedges);
print_line("ROAD SETUP DONE");
}
@@ -581,13 +583,18 @@ public:
new_mesh->surface_set_name(0, "main");
return new_mesh;
}
void clear_road_meshes()
{
int i;
for (i = 0; i < (int)nodes_mi.size(); i++)
nodes_mi[i]->queue_delete();
nodes_mi.clear();
}
void create_road_meshes(Node *base)
{
int i;
RoadLinesProcessing *r = RoadLinesProcessing::get_singleton();
for (i = 0; i < (int)nodes_mi.size(); i++)
nodes_mi[i]->queue_delete();
nodes_mi.clear();
clear_road_meshes();
for (i = 0; i < (int)r->nodes.size(); i++) {
Ref<ArrayMesh> mesh =
build_road(r->wedges[i], "common/center",
@@ -625,10 +632,15 @@ RoadMeshProcessing *RoadMeshProcessing::singleton;
void RoadProcessing::road_setup(Node *target)
{
RoadLinesProcessing::get_singleton()->road_setup(target);
RoadLinesProcessing::get_singleton()->road_setup();
RoadMeshProcessing::get_singleton()->create_road_meshes(target);
}
void RoadProcessing::remove_road_meshes(Node *target)
{
RoadMeshProcessing::get_singleton()->clear_road_meshes();
}
void RoadProcessing::load_data()
{
/* Not needed but still */

View File

@@ -4,6 +4,7 @@ class Node;
class RoadProcessing {
public:
static void road_setup(Node *target);
static void remove_road_meshes(Node *target);
static void load_data();
static void cleanup();
};

View File

@@ -554,14 +554,12 @@ void StreamWorld::run_command(const String &command, const Array &args)
} else if (command == "remove_generated_stuff") {
remove_generated_stuff();
update_items();
} else if (command == "place") {
if (args.size() == 0) {
print_error("bad command: not enough args: " + command);
return;
}
String what = args[0];
if (what == "zebra")
place_zebras();
} else if (command == "rebuild_roads") {
RoadProcessing::road_setup(this);
print_line("road_rebuild done");
} else if (command == "remove_road_meshes") {
RoadProcessing::remove_road_meshes(this);
print_line("remove_road_meshes done");
} else
print_error("No command " + command);
}
@@ -703,9 +701,6 @@ void StreamWorld::undo()
update_view();
update_items();
}
void StreamWorld::place_zebras()
{
}
void StreamWorld::cleanup()
{
RoadProcessing::cleanup();

View File

@@ -240,7 +240,14 @@ void WorldEditor::editor_command(const String &command, const Array &args)
} else if (command == "select_building") {
select_building(args[0], args[1], args[2]);
} else if (command == "remove_generated_stuff") {
stream_world->run_command(command, args);
if (stream_world)
stream_world->run_command(command, args);
} else if (command == "rebuild_roads") {
if (stream_world)
stream_world->run_command(command, args);
} else if (command == "remove_road_meshes") {
if (stream_world)
stream_world->run_command(command, args);
} else if (road_lines_editor) {
road_lines_editor->editor_command(command, args);
}