Compoile fixes
This commit is contained in:
6
.vscode/settings.json
vendored
6
.vscode/settings.json
vendored
@@ -71,7 +71,11 @@
|
|||||||
"future": "cpp",
|
"future": "cpp",
|
||||||
"cassert": "cpp",
|
"cassert": "cpp",
|
||||||
"bitset": "cpp",
|
"bitset": "cpp",
|
||||||
"unordered_set": "cpp"
|
"unordered_set": "cpp",
|
||||||
|
"strstream": "cpp",
|
||||||
|
"typeindex": "cpp",
|
||||||
|
"shared_mutex": "cpp",
|
||||||
|
"any": "cpp"
|
||||||
},
|
},
|
||||||
"cmake.ignoreCMakeListsMissing": true
|
"cmake.ignoreCMakeListsMissing": true
|
||||||
}
|
}
|
||||||
2
Makefile
2
Makefile
@@ -15,7 +15,7 @@ godot-main: patch
|
|||||||
scons platform=server target=release_debug tools=yes custom_modules=../modules -j16
|
scons platform=server target=release_debug tools=yes custom_modules=../modules -j16
|
||||||
godot-editor-main: patch
|
godot-editor-main: patch
|
||||||
cd src/godot; \
|
cd src/godot; \
|
||||||
scons platform=x11 arch=$(ARCH) verbose=yes target=release_debug tools=yes custom_modules=../modules -j16;
|
scons platform=x11 arch=$(ARCH) verbose=yes target=release_debug tools=yes custom_modules=../modules -j24;
|
||||||
patch: ./src/godot/scene/animation/skeleton_ik.cpp
|
patch: ./src/godot/scene/animation/skeleton_ik.cpp
|
||||||
cd ./src/godot && git reset --hard HEAD && for p in ../patches/*.patch; do git apply $$p; done
|
cd ./src/godot && git reset --hard HEAD && for p in ../patches/*.patch; do git apply $$p; done
|
||||||
sed -e 's/ERR_FAIL_COND_V(-1 == p_task->root_bone, false);//g' -i ./src/godot/scene/animation/skeleton_ik.cpp
|
sed -e 's/ERR_FAIL_COND_V(-1 == p_task->root_bone, false);//g' -i ./src/godot/scene/animation/skeleton_ik.cpp
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -62,6 +62,47 @@ sidewalk_end_mesh = "res://astream/road/road-lanes_road-sidewalk-end.mesh"
|
|||||||
sidewalk_sideroad_mesh = "res://astream/road/road-lanes_road-sidewalk-sideroad.mesh"
|
sidewalk_sideroad_mesh = "res://astream/road/road-lanes_road-sidewalk-sideroad.mesh"
|
||||||
lot_mesh = "res://astream/road/road-lanes_road-lot.mesh"
|
lot_mesh = "res://astream/road/road-lanes_road-lot.mesh"
|
||||||
lot_depth = 200.0
|
lot_depth = 200.0
|
||||||
|
allow_building_prefixes = [
|
||||||
|
"zebra",
|
||||||
|
"bus-stop",
|
||||||
|
"power-",
|
||||||
|
"terrain-"
|
||||||
|
]
|
||||||
|
lot_buildings_residental = [
|
||||||
|
["residental-house13"],
|
||||||
|
["residental-house11"],
|
||||||
|
["residental-house10", "residental-garage1"],
|
||||||
|
["residental-house10"],
|
||||||
|
["residental-house9", "residental-garage1"],
|
||||||
|
["residental-house9"],
|
||||||
|
["residental-house8", "residental-garage1"],
|
||||||
|
["residental-house8"],
|
||||||
|
["residental-house7", "residental-garage1"],
|
||||||
|
["residental-house7"],
|
||||||
|
["residental-house6", "residental-garage1"],
|
||||||
|
["residental-house6"],
|
||||||
|
["residental-house5", "residental-garage1"],
|
||||||
|
["residental-house5"],
|
||||||
|
["residental-house4", "residental-garage1"],
|
||||||
|
["residental-house4"],
|
||||||
|
["residental-house3", "residental-garage1"],
|
||||||
|
["residental-house3"],
|
||||||
|
["residental-house2", "residental-garage1"],
|
||||||
|
["residental-house2"],
|
||||||
|
["residental-house1", "residental-garage1"],
|
||||||
|
["residental-house1"],
|
||||||
|
["residental-hut1", "residental-garage1"],
|
||||||
|
["residental-hut1"]
|
||||||
|
]
|
||||||
|
lot_buildings_commercial = [
|
||||||
|
["business-store1"],
|
||||||
|
["business-cafe1"],
|
||||||
|
["business-bar1"],
|
||||||
|
]
|
||||||
|
lot_buildings_industrial = [
|
||||||
|
["residental-garage1"],
|
||||||
|
["residental-garage1"]
|
||||||
|
]
|
||||||
[lines]
|
[lines]
|
||||||
road_lines_path = "res://astream/road_lines.json"
|
road_lines_path = "res://astream/road_lines.json"
|
||||||
gen_prefixes = ["empty", "foundation30", "foundation60", "sideroad-start",
|
gen_prefixes = ["empty", "foundation30", "foundation60", "sideroad-start",
|
||||||
|
|||||||
Submodule src/flecs updated: a51883026c...254e7ee72f
Submodule src/godot updated: 9ce78ca5c2...766b02c9cd
Submodule src/meshoptimizer updated: fc45e051a8...7634a68dd5
@@ -7,8 +7,8 @@ Import("env_modules")
|
|||||||
|
|
||||||
env_stream = env_modules.Clone()
|
env_stream = env_modules.Clone()
|
||||||
env_stream.module_obj = []
|
env_stream.module_obj = []
|
||||||
env_stream.Prepend(CPPPATH=["../../meshoptimizer/src"])
|
env_stream.Append(CPPPATH=["../../meshoptimizer/src"])
|
||||||
env_stream.Prepend(CPPPATH=["event"])
|
env_stream.Append(CPPPATH=["./event"])
|
||||||
env_stream.add_source_files(env_stream.module_obj, "*.cpp")
|
env_stream.add_source_files(env_stream.module_obj, "*.cpp")
|
||||||
env.modules_sources += env_stream.module_obj
|
env.modules_sources += env_stream.module_obj
|
||||||
|
|
||||||
@@ -21,3 +21,4 @@ SConscript("flecs/SCsub")
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -15,4 +15,5 @@ env.add_source_files(env.stream_building_sources, "*.cpp")
|
|||||||
lib = env.add_library("buildings", env.stream_building_sources)
|
lib = env.add_library("buildings", env.stream_building_sources)
|
||||||
env.Prepend(LIBS=[lib])
|
env.Prepend(LIBS=[lib])
|
||||||
env.Prepend(CPPPATH=[".."])
|
env.Prepend(CPPPATH=[".."])
|
||||||
|
env.Prepend(CPPPATH=["../event"])
|
||||||
env.Prepend(CPPPATH=["../../../meshoptimizer/src"])
|
env.Prepend(CPPPATH=["../../../meshoptimizer/src"])
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <core/object.h>
|
#include <core/object.h>
|
||||||
#include <scene/3d/immediate_geometry.h>
|
#include <scene/3d/immediate_geometry.h>
|
||||||
#include "wedge.h"
|
#include "wedge.h"
|
||||||
|
#include "base_data.h"
|
||||||
#include "contours.h"
|
#include "contours.h"
|
||||||
|
|
||||||
Contours *Contours::singleton = nullptr;
|
Contours *Contours::singleton = nullptr;
|
||||||
@@ -17,6 +18,7 @@ Contours *Contours::get_singleton()
|
|||||||
Contours::Contours()
|
Contours::Contours()
|
||||||
: dbg(nullptr)
|
: dbg(nullptr)
|
||||||
{
|
{
|
||||||
|
BaseData::get_singleton()->get().component<Lot>();
|
||||||
}
|
}
|
||||||
|
|
||||||
Contours::~Contours()
|
Contours::~Contours()
|
||||||
@@ -84,41 +86,107 @@ void Contours::build()
|
|||||||
}
|
}
|
||||||
contours.push_back(mc);
|
contours.push_back(mc);
|
||||||
}
|
}
|
||||||
polygons.clear();
|
flecs::entity base_e = BaseData::get_singleton()->get().lookup("lots");
|
||||||
for (i = 0; i < (int)contours.size(); i++)
|
if (base_e.is_valid())
|
||||||
polygons.push_back({ contours[i].points, contours[i].aabb });
|
base_e.destruct();
|
||||||
List<struct polygon> polygon_queue;
|
base_e = BaseData::get_singleton()->get().entity("lots");
|
||||||
List<struct polygon> polygon_output;
|
List<struct Lot::polygon> polygon_queue;
|
||||||
for (i = 0; i < (int)polygons.size(); i++)
|
List<struct Lot::polygon> polygon_output;
|
||||||
polygon_queue.push_back(polygons[i]);
|
Vector<struct Lot::polygon> check;
|
||||||
polygons.clear();
|
check.resize(contours.size());
|
||||||
List<struct polygon>::Element *e = polygon_queue.front();
|
/* checking contours do not intersect */
|
||||||
while (e) {
|
for (i = 0; i < (int)contours.size(); i++) {
|
||||||
struct polygon item = e->get();
|
check.write[i] = { contours[i].points, contours[i].aabb };
|
||||||
print_line("queue: " + itos(polygon_queue.size()));
|
}
|
||||||
polygon_queue.pop_front();
|
Set<int> ignore;
|
||||||
float area = item.area();
|
int k, l;
|
||||||
if (area > 120.0f * 120.0f && item.aabb.size.x > 10.0f &&
|
for (i = 0; i < (int)contours.size(); i++) {
|
||||||
item.aabb.size.z > 10.0f) {
|
for (j = 0; j < (int)check.size(); j++) {
|
||||||
std::pair<struct polygon, struct polygon> polys =
|
if (i != j) {
|
||||||
item.split();
|
for (k = 0; k < (int)contours[i].points.size();
|
||||||
if (polys.first.area() < 10.0f ||
|
k++) {
|
||||||
polys.second.area() < 10.0f) {
|
for (l = 0;
|
||||||
polygon_output.push_back(item);
|
l < (int)contours[j].points.size();
|
||||||
} else {
|
l++) {
|
||||||
polygon_queue.push_back(polys.first);
|
assert(!contours[i].points[k].is_equal_approx(
|
||||||
polygon_queue.push_back(polys.second);
|
contours[j].points[l]));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
polygon_output.push_back(item);
|
|
||||||
e = polygon_queue.front();
|
|
||||||
}
|
}
|
||||||
polygons.reserve(polygon_output.size());
|
for (i = 0; i < (int)contours.size(); i++) {
|
||||||
e = polygon_output.front();
|
check.write[i] = { contours[i].points, contours[i].aabb };
|
||||||
while (e) {
|
check.write[i].update_aabb();
|
||||||
polygons.push_back(e->get());
|
|
||||||
e = e->next();
|
|
||||||
}
|
}
|
||||||
|
for (i = 0; i < check.size(); i++) {
|
||||||
|
for (j = 0; j < (int)check.size(); j++) {
|
||||||
|
if (i == j)
|
||||||
|
continue;
|
||||||
|
check[i].intersects(&check[j]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (i = 0; i < (int)check.size(); i++) {
|
||||||
|
polygon_queue.push_back(check[i]);
|
||||||
|
#if 0
|
||||||
|
polygon_output.push_back(check[i]);
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
for (i = 0; i < (int)contours.size(); i++)
|
||||||
|
polygon_queue.push_back(
|
||||||
|
{ contours[i].points, contours[i].aabb });
|
||||||
|
#endif
|
||||||
|
{
|
||||||
|
List<struct Lot::polygon>::Element *e = polygon_queue.front();
|
||||||
|
while (e) {
|
||||||
|
struct Lot::polygon item = e->get();
|
||||||
|
print_line("queue: " + itos(polygon_queue.size()));
|
||||||
|
polygon_queue.pop_front();
|
||||||
|
float area = item.area();
|
||||||
|
if (area > 120.0f * 120.0f &&
|
||||||
|
item.aabb.size.x > 10.0f &&
|
||||||
|
item.aabb.size.z > 10.0f) {
|
||||||
|
std::pair<struct Lot::polygon,
|
||||||
|
struct Lot::polygon>
|
||||||
|
polys = item.split();
|
||||||
|
if (polys.first.area() < 10.0f ||
|
||||||
|
polys.second.area() < 10.0f) {
|
||||||
|
polygon_output.push_back(item);
|
||||||
|
} else {
|
||||||
|
polygon_queue.push_back(polys.first);
|
||||||
|
polygon_queue.push_back(polys.second);
|
||||||
|
}
|
||||||
|
} else
|
||||||
|
polygon_output.push_back(item);
|
||||||
|
e = polygon_queue.front();
|
||||||
|
}
|
||||||
|
e = polygon_output.front();
|
||||||
|
while (e) {
|
||||||
|
flecs::entity lot_e = BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.entity()
|
||||||
|
.child_of(base_e);
|
||||||
|
lot_e.set<Lot>({ e->get() });
|
||||||
|
e = e->next();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
BaseData::get_singleton()->get().query_builder<Lot>().build().each(
|
||||||
|
[&](flecs::entity e, Lot &lot) { lot.polygon.update_aabb(); });
|
||||||
|
BaseData::get_singleton()->get().query_builder<Lot>().build().each(
|
||||||
|
[&](flecs::entity e, Lot &lot) {
|
||||||
|
BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.query_builder<Lot>()
|
||||||
|
.build()
|
||||||
|
.each([&](flecs::entity we, Lot &wlot) {
|
||||||
|
if (e != we) {
|
||||||
|
assert(!lot.polygon.intersects(
|
||||||
|
&wlot.polygon));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
Lot::pack();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Contours::debug()
|
void Contours::debug()
|
||||||
@@ -155,124 +223,102 @@ void Contours::debug()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dbg->end();
|
dbg->end();
|
||||||
|
flecs::entity base_e = BaseData::get_singleton()->get().lookup("lots");
|
||||||
|
assert(base_e.is_valid());
|
||||||
|
flecs::query<Lot> query = BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.query_builder<Lot>()
|
||||||
|
.with(flecs::ChildOf, base_e)
|
||||||
|
.build();
|
||||||
dbg->begin(Mesh::PRIMITIVE_LINES);
|
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||||
dbg->set_color(Color(1, 1, 0.4f, 1));
|
dbg->set_color(Color(1, 1, 0.4f, 1));
|
||||||
for (i = 0; i < (int)polygons.size(); i++) {
|
query.each([&](flecs::entity e, const Lot &lot) {
|
||||||
for (j = 0; j < (int)polygons[i].points.size(); j++) {
|
for (j = 0; j < (int)lot.polygon.points.size(); j++) {
|
||||||
dbg->add_vertex(polygons[i].points[j] +
|
dbg->add_vertex(lot.polygon.points[j] +
|
||||||
Vector3(0, 2, 0));
|
Vector3(0, 2, 0));
|
||||||
dbg->add_vertex(
|
dbg->add_vertex(
|
||||||
polygons[i].points[(j + 1) %
|
lot.polygon.points[(j + 1) %
|
||||||
polygons[i].points.size()] +
|
lot.polygon.points.size()] +
|
||||||
Vector3(0, 2, 0));
|
Vector3(0, 2, 0));
|
||||||
|
List<Pair<AABB, String> > lot_data;
|
||||||
|
Lot::get_lot_data(e, &lot_data);
|
||||||
|
List<Pair<AABB, String> >::Element *me =
|
||||||
|
lot_data.front();
|
||||||
|
while (me) {
|
||||||
|
const Pair<AABB, String> &data = me->get();
|
||||||
|
dbg->add_vertex(data.first.get_center());
|
||||||
|
dbg->add_vertex(data.first.get_center() +
|
||||||
|
Vector3(0, 50, 0));
|
||||||
|
me = me->next();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
});
|
||||||
|
dbg->end();
|
||||||
|
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||||
|
dbg->set_color(Color(1, 1, 0.3, 1));
|
||||||
|
query.each([&](flecs::entity e, const Lot &lot) {
|
||||||
|
for (i = 0; i < lot.polygon.intersections.size(); i++) {
|
||||||
|
for (j = 0; j < lot.polygon.intersections[i].size();
|
||||||
|
j++) {
|
||||||
|
int i0 = j;
|
||||||
|
int i1 = (j + 1) %
|
||||||
|
lot.polygon.intersections.size();
|
||||||
|
Vector2 p0 = lot.polygon.intersections[i][i0];
|
||||||
|
Vector2 p1 = lot.polygon.intersections[i][i1];
|
||||||
|
dbg->add_vertex(Vector3(p0.x, 50, p0.y));
|
||||||
|
dbg->add_vertex(Vector3(p1.x, 50, p1.y));
|
||||||
|
}
|
||||||
|
assert(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
dbg->end();
|
||||||
|
dbg->begin(Mesh::PRIMITIVE_LINES);
|
||||||
|
dbg->set_color(Color(0.8f, 0.5f, 0.9f, 1));
|
||||||
|
query.each([&](flecs::entity e, const Lot &lot) {
|
||||||
|
Vector<Pair<Rect2, String> > buildings;
|
||||||
|
Lot::get_lot_buildings(e, &buildings);
|
||||||
|
Vector<Vector<Vector2> > polys = Lot::get_lot_polygons(e);
|
||||||
|
for (i = 0; i < (int)buildings.size(); i++) {
|
||||||
|
const Rect2 r = buildings[i].first;
|
||||||
|
Vector2 mp0 = r.position;
|
||||||
|
Vector2 mp1 = r.position + Vector2(r.size.x, 0);
|
||||||
|
Vector2 mp2 = r.position + r.size;
|
||||||
|
Vector2 mp3 = r.position + Vector2(0, r.size.y);
|
||||||
|
Vector2 rect[] = { mp0, mp1, mp2, mp3 };
|
||||||
|
Vector2 c = r.get_center();
|
||||||
|
dbg->set_color(Color(0.3f, 0.1f, 0.9f, 1));
|
||||||
|
for (j = 0; j < 4; j++) {
|
||||||
|
int i0 = j;
|
||||||
|
int i1 = (j + 1) % 4;
|
||||||
|
Vector3 p0 = Vector3(rect[i0].x, 0, rect[i0].y);
|
||||||
|
Vector3 p1 = Vector3(rect[i1].x, 0, rect[i1].y);
|
||||||
|
dbg->add_vertex(p0);
|
||||||
|
dbg->add_vertex(p1);
|
||||||
|
dbg->add_vertex(p0 + Vector3(0, -10, 0));
|
||||||
|
dbg->add_vertex(p0 + Vector3(0, +10, 0));
|
||||||
|
}
|
||||||
|
#if 0
|
||||||
|
dbg->set_color(Color(0.1f, 0.1f, 1.0f, 1));
|
||||||
|
dbg->add_vertex(Vector3(c.x, 0, c.y));
|
||||||
|
dbg->add_vertex(lot.polygon.points[0]);
|
||||||
|
#endif
|
||||||
|
dbg->set_color(Color(0.3f, 0.1f, 0.9f, 1));
|
||||||
|
assert(polys[i].size() > 0);
|
||||||
|
for (j = 0; j < (int)polys[i].size(); j++) {
|
||||||
|
int i0 = j;
|
||||||
|
int i1 = (j + 1) % (int)polys[i].size();
|
||||||
|
Vector3 p0 = Vector3(polys[i][i0].x, 100,
|
||||||
|
polys[i][i0].y);
|
||||||
|
Vector3 p1 = Vector3(polys[i][i1].x, 100,
|
||||||
|
polys[i][i1].y);
|
||||||
|
dbg->add_vertex(p0);
|
||||||
|
dbg->add_vertex(p1);
|
||||||
|
}
|
||||||
|
dbg->set_color(Color(1.0f, 0.1f, 0.1f, 1));
|
||||||
|
dbg->add_vertex(Vector3(c.x, 0, c.y));
|
||||||
|
dbg->add_vertex(
|
||||||
|
Vector3(polys[i][0].x, 100, polys[i][0].y));
|
||||||
|
}
|
||||||
|
});
|
||||||
dbg->end();
|
dbg->end();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::pair<struct Contours::polygon, struct Contours::polygon>
|
|
||||||
Contours::polygon::split() const
|
|
||||||
{
|
|
||||||
int i, j;
|
|
||||||
float split_polygons_area = 0.0f;
|
|
||||||
float split_polygons_area_min = 0.0f;
|
|
||||||
std::pair<struct Contours::polygon, struct Contours::polygon>
|
|
||||||
split_polygons;
|
|
||||||
std::vector<int> edges;
|
|
||||||
for (i = 0; i < (int)points.size(); i++) {
|
|
||||||
Vector3 p0 = points[i];
|
|
||||||
Vector3 p1 = points[(i + 1) % points.size()];
|
|
||||||
if (p0.distance_squared_to(p1) > 100 * 100)
|
|
||||||
edges.push_back(i);
|
|
||||||
}
|
|
||||||
if (edges.size() == 0) {
|
|
||||||
for (i = 0; i < (int)points.size(); i++) {
|
|
||||||
Vector3 p0 = points[i];
|
|
||||||
Vector3 p1 = points[(i + 1) % points.size()];
|
|
||||||
edges.push_back(i);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (i = 0; i < (int)edges.size(); i++) {
|
|
||||||
Vector3 p0 = points[edges[i]];
|
|
||||||
Vector3 p1 = points[(edges[i] + 1) % points.size()];
|
|
||||||
Transform xf =
|
|
||||||
Transform(Basis(), p0).looking_at(p1, Vector3(0, 1, 0));
|
|
||||||
AABB base;
|
|
||||||
base.position = xf.xform_inv(p0);
|
|
||||||
base.expand_to(xf.xform_inv(p1));
|
|
||||||
for (j = 0; j < (int)points.size(); j++)
|
|
||||||
base.expand_to(xf.xform_inv(points[j]));
|
|
||||||
Vector3 mpos0, mpos1;
|
|
||||||
if (base.size.x > base.size.z) {
|
|
||||||
mpos0 = base.position +
|
|
||||||
Vector3(base.size.x, 0, 0) * 0.5f;
|
|
||||||
mpos1 = mpos0 + Vector3(0, 0, base.size.z);
|
|
||||||
mpos0 = xf.xform(mpos0);
|
|
||||||
mpos1 = xf.xform(mpos1);
|
|
||||||
} else {
|
|
||||||
mpos0 = base.position +
|
|
||||||
Vector3(0, 0, base.size.z) * 0.5f;
|
|
||||||
mpos1 = mpos0 + Vector3(base.size.x, 0, 0);
|
|
||||||
mpos0 = xf.xform(mpos0);
|
|
||||||
mpos1 = xf.xform(mpos1);
|
|
||||||
}
|
|
||||||
mpos0.y = 0;
|
|
||||||
mpos1.y == 0;
|
|
||||||
/* mpos0 is at start of cut */
|
|
||||||
|
|
||||||
Vector3 n =
|
|
||||||
(mpos1 - mpos0).cross(Vector3(0, 1, 0)).normalized();
|
|
||||||
Plane pl1(mpos0 - n * 1.5f, n);
|
|
||||||
Plane pl2(mpos0 + n * 1.5f, -n);
|
|
||||||
Vector<Vector3> pdata;
|
|
||||||
pdata.resize(points.size());
|
|
||||||
memcpy(pdata.ptrw(), points.data(),
|
|
||||||
points.size() * sizeof(Vector3));
|
|
||||||
struct polygon poly1, poly2;
|
|
||||||
Vector<Vector3> rpdata = Geometry::clip_polygon(pdata, pl1);
|
|
||||||
poly1.points.resize(rpdata.size());
|
|
||||||
memcpy(poly1.points.data(), rpdata.ptr(),
|
|
||||||
rpdata.size() * sizeof(Vector3));
|
|
||||||
poly1.update_aabb();
|
|
||||||
rpdata = Geometry::clip_polygon(pdata, pl2);
|
|
||||||
poly2.points.resize(rpdata.size());
|
|
||||||
memcpy(poly2.points.data(), rpdata.ptr(),
|
|
||||||
rpdata.size() * sizeof(Vector3));
|
|
||||||
poly2.update_aabb();
|
|
||||||
float area1 = poly1.area();
|
|
||||||
float area2 = poly2.area();
|
|
||||||
if (area1 <= 4.0f || area2 <= 4.0f)
|
|
||||||
continue;
|
|
||||||
float area_min = MIN(area1, area2);
|
|
||||||
float area = area1 + area2;
|
|
||||||
if (split_polygons_area_min < area_min &&
|
|
||||||
split_polygons_area < area) {
|
|
||||||
split_polygons = { poly1, poly2 };
|
|
||||||
split_polygons_area_min = area_min;
|
|
||||||
split_polygons_area = area;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return split_polygons;
|
|
||||||
}
|
|
||||||
|
|
||||||
int Contours::polygon::longest_edge() const
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Contours::polygon::update_aabb()
|
|
||||||
{
|
|
||||||
aabb = AABB();
|
|
||||||
int i;
|
|
||||||
for (i = 0; i < (int)points.size(); i++) {
|
|
||||||
if (aabb.is_equal_approx(AABB()))
|
|
||||||
aabb.position = points[i];
|
|
||||||
else
|
|
||||||
aabb.expand_to(points[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
float Contours::polygon::area() const
|
|
||||||
{
|
|
||||||
return Geometry::find_polygon_area(points.data(), points.size());
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
#ifndef CONTOURS_H_
|
#ifndef CONTOURS_H_
|
||||||
#define CONTOURS_H_
|
#define CONTOURS_H_
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "road_lot.h"
|
||||||
|
|
||||||
class ImmediateGeometry;
|
class ImmediateGeometry;
|
||||||
struct Contours {
|
struct Contours {
|
||||||
@@ -14,20 +15,11 @@ struct Contours {
|
|||||||
std::vector<Vector3> points;
|
std::vector<Vector3> points;
|
||||||
AABB aabb;
|
AABB aabb;
|
||||||
};
|
};
|
||||||
struct polygon {
|
|
||||||
std::vector<Vector3> points;
|
|
||||||
AABB aabb;
|
|
||||||
std::pair<struct polygon, struct polygon> split() const;
|
|
||||||
float area() const;
|
|
||||||
int longest_edge() const;
|
|
||||||
void update_aabb();
|
|
||||||
};
|
|
||||||
void build();
|
void build();
|
||||||
ImmediateGeometry *dbg;
|
ImmediateGeometry *dbg;
|
||||||
Ref<SpatialMaterial> imm_mat;
|
Ref<SpatialMaterial> imm_mat;
|
||||||
std::vector<std::vector<struct wedge *> > wedge_contours;
|
std::vector<std::vector<struct wedge *> > wedge_contours;
|
||||||
std::vector<struct main_contour> contours;
|
std::vector<struct main_contour> contours;
|
||||||
std::vector<struct polygon> polygons;
|
|
||||||
static Contours *singleton;
|
static Contours *singleton;
|
||||||
static Contours *get_singleton();
|
static Contours *get_singleton();
|
||||||
Contours();
|
Contours();
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
#ifndef ROAD_LINES_DATA_H
|
#ifndef ROAD_LINES_DATA_H
|
||||||
#define ROAD_LINES_DATA_H
|
#define ROAD_LINES_DATA_H
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
#include <unordered_map>
|
||||||
#include <core/io/json.h>
|
#include <core/io/json.h>
|
||||||
|
#include <scene/resources/curve.h>
|
||||||
#include "callable.h"
|
#include "callable.h"
|
||||||
class ImmediateGeometry;
|
class ImmediateGeometry;
|
||||||
class RoadLinesData {
|
class RoadLinesData {
|
||||||
|
|||||||
@@ -23,6 +23,7 @@
|
|||||||
#include "buildings_data.h"
|
#include "buildings_data.h"
|
||||||
#include "contours.h"
|
#include "contours.h"
|
||||||
#include "wedge.h"
|
#include "wedge.h"
|
||||||
|
#include "road_lot.h"
|
||||||
#include "road_processing.h"
|
#include "road_processing.h"
|
||||||
|
|
||||||
class DebugGeo : public ImmediateGeometry {
|
class DebugGeo : public ImmediateGeometry {
|
||||||
@@ -140,8 +141,9 @@ struct RoadLinesProcessing {
|
|||||||
else
|
else
|
||||||
BuildingsData::get_singleton()->add_scene_item(b.id,
|
BuildingsData::get_singleton()->add_scene_item(b.id,
|
||||||
b.key);
|
b.key);
|
||||||
print_line("created building: " + b.key);
|
print_line("created building: " + b.key + " " + b.id);
|
||||||
print_line("at: " + (b.xform.origin.operator String()));
|
print_line("at: " + (b.xform.origin.operator String()));
|
||||||
|
print_line("created ok");
|
||||||
}
|
}
|
||||||
int create_sideroads(const String &line_key, int edge_no,
|
int create_sideroads(const String &line_key, int edge_no,
|
||||||
const RoadLinesData::road_edge &edge,
|
const RoadLinesData::road_edge &edge,
|
||||||
@@ -205,6 +207,7 @@ out2:;
|
|||||||
}
|
}
|
||||||
return structures_generated;
|
return structures_generated;
|
||||||
}
|
}
|
||||||
|
#if 0
|
||||||
int
|
int
|
||||||
create_line_building(const String &line_key, int edge_id,
|
create_line_building(const String &line_key, int edge_id,
|
||||||
const Transform &xform,
|
const Transform &xform,
|
||||||
@@ -245,6 +248,7 @@ out2:;
|
|||||||
}
|
}
|
||||||
return structures_generated;
|
return structures_generated;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
int create_lots(const String &line_key, int edge_no,
|
int create_lots(const String &line_key, int edge_no,
|
||||||
const RoadLinesData::road_edge &edge, const Vector3 &p0,
|
const RoadLinesData::road_edge &edge, const Vector3 &p0,
|
||||||
const Vector3 &p1, const Vector3 &dir)
|
const Vector3 &p1, const Vector3 &dir)
|
||||||
@@ -841,6 +845,155 @@ out_skip_end:;
|
|||||||
}
|
}
|
||||||
e = e->next();
|
e = e->next();
|
||||||
}
|
}
|
||||||
|
#define GENERATE_STRUCTURES
|
||||||
|
#ifdef GENERATE_STRUCTURES
|
||||||
|
BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.query_builder<Lot>()
|
||||||
|
.build()
|
||||||
|
.each([&](flecs::entity e, Lot &lot) {
|
||||||
|
BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.query_builder<Lot>()
|
||||||
|
.build()
|
||||||
|
.each([&](flecs::entity we, Lot &wlot) {
|
||||||
|
if (e != we) {
|
||||||
|
lot.polygon
|
||||||
|
.update_aabb();
|
||||||
|
wlot.polygon
|
||||||
|
.update_aabb();
|
||||||
|
if (lot.polygon.aabb
|
||||||
|
.size
|
||||||
|
.length() >
|
||||||
|
100000.0f *
|
||||||
|
1000000.0f)
|
||||||
|
e.destruct();
|
||||||
|
else if (wlot.polygon
|
||||||
|
.aabb
|
||||||
|
.size
|
||||||
|
.length() >
|
||||||
|
100000.0f *
|
||||||
|
1000000.0f)
|
||||||
|
we.destruct();
|
||||||
|
else if (lot.polygon.intersects(
|
||||||
|
&wlot.polygon)) {
|
||||||
|
print_line(
|
||||||
|
"polygon intersection:");
|
||||||
|
lot.polygon
|
||||||
|
.dump();
|
||||||
|
wlot.polygon
|
||||||
|
.dump();
|
||||||
|
if (lot.polygon
|
||||||
|
.area() >
|
||||||
|
wlot.polygon
|
||||||
|
.area())
|
||||||
|
we.destruct();
|
||||||
|
else
|
||||||
|
e.destruct();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.query_builder<Lot>()
|
||||||
|
.build()
|
||||||
|
.each([&](flecs::entity e, const Lot &lot) {
|
||||||
|
List<Pair<AABB, String> > lot_data;
|
||||||
|
Lot::get_lot_data(e, &lot_data);
|
||||||
|
List<Pair<AABB, String> >::Element *lot_e =
|
||||||
|
lot_data.front();
|
||||||
|
int ccount = 0;
|
||||||
|
while (lot_e) {
|
||||||
|
Pair<AABB, String> data = lot_e->get();
|
||||||
|
Vector3 center = data.first.position;
|
||||||
|
center += Vector3(data.first.size.x, 0,
|
||||||
|
data.first.size.z) *
|
||||||
|
0.5f;
|
||||||
|
Transform xform(Basis(), center);
|
||||||
|
Vector3 m = xform.origin;
|
||||||
|
m.y = 0;
|
||||||
|
print_line("Position: " +
|
||||||
|
m.operator String());
|
||||||
|
if (m.length() < 1.0f) {
|
||||||
|
int j;
|
||||||
|
print_line("id: " +
|
||||||
|
data.second);
|
||||||
|
print_line("aabb: " +
|
||||||
|
data.first.
|
||||||
|
operator String());
|
||||||
|
for (j = 0;
|
||||||
|
j <
|
||||||
|
lot.polygon.points.size();
|
||||||
|
j++)
|
||||||
|
print_line(
|
||||||
|
"polygon: " +
|
||||||
|
itos(j) + " " +
|
||||||
|
lot.polygon
|
||||||
|
.points[j]
|
||||||
|
.
|
||||||
|
operator String());
|
||||||
|
}
|
||||||
|
lot_e = lot_e->next();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
BaseData::get_singleton()
|
||||||
|
->get()
|
||||||
|
.query_builder<Lot>()
|
||||||
|
.build()
|
||||||
|
.each([&](flecs::entity e, const Lot &lot) {
|
||||||
|
List<Pair<AABB, String> > lot_data;
|
||||||
|
List<Transform> lot_xform;
|
||||||
|
Lot::get_lot_data(e, &lot_data);
|
||||||
|
Lot::get_lot_rotations(e, &lot_xform);
|
||||||
|
List<Pair<AABB, String> >::Element *lot_e =
|
||||||
|
lot_data.front();
|
||||||
|
List<Transform>::Element *lotx_e =
|
||||||
|
lot_xform.front();
|
||||||
|
int ccount = 0;
|
||||||
|
while (lot_e) {
|
||||||
|
Pair<AABB, String> data = lot_e->get();
|
||||||
|
String key = "road__lot__" +
|
||||||
|
String(e.path()) + "_" +
|
||||||
|
itos(ccount);
|
||||||
|
key = key.replace("#", "_");
|
||||||
|
BuildingsData::building b;
|
||||||
|
b.key = key;
|
||||||
|
b.id = data.second;
|
||||||
|
b.generated = true;
|
||||||
|
b.line_name = "";
|
||||||
|
// TODO: add lot to BuildingsData:: building struct;
|
||||||
|
// TODO use rotation with building packing
|
||||||
|
Vector3 center = data.first.position;
|
||||||
|
center += Vector3(data.first.size.x, 0,
|
||||||
|
data.first.size.z) *
|
||||||
|
0.5f;
|
||||||
|
Transform rot = lotx_e->get();
|
||||||
|
Transform xform(rot.basis, center);
|
||||||
|
Vector3 m = xform.origin;
|
||||||
|
m.y = 0;
|
||||||
|
print_line("Position: " +
|
||||||
|
m.operator String());
|
||||||
|
assert(!m.is_equal_approx(Vector3()));
|
||||||
|
b.key_hash = b.key.hash64();
|
||||||
|
b.pattern_id = 0;
|
||||||
|
b.xform = xform;
|
||||||
|
// TODO: fix working time for building
|
||||||
|
b.worktime[0] = 0;
|
||||||
|
b.worktime[1] = 23;
|
||||||
|
create_building_structure(b);
|
||||||
|
print_line(
|
||||||
|
"building: " + key + ": " +
|
||||||
|
data.first.operator String());
|
||||||
|
print_line(
|
||||||
|
"center: " +
|
||||||
|
xform.origin.operator String());
|
||||||
|
lot_e = lot_e->next();
|
||||||
|
lotx_e = lotx_e->next();
|
||||||
|
ccount++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
#endif
|
||||||
print_line("structures generated: " +
|
print_line("structures generated: " +
|
||||||
itos(structures_generated));
|
itos(structures_generated));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,4 +14,4 @@ env.add_source_files(env.stream_building_sources, "*.cpp")
|
|||||||
|
|
||||||
lib = env.add_library("rtree", env.stream_building_sources)
|
lib = env.add_library("rtree", env.stream_building_sources)
|
||||||
env.Prepend(LIBS=[lib])
|
env.Prepend(LIBS=[lib])
|
||||||
env.Prepend(CPPPATH=["..", ".", "../ui"])
|
env.Prepend(CPPPATH=["../ui", ".."])
|
||||||
|
|||||||
@@ -4,7 +4,9 @@
|
|||||||
#include <core/list.h>
|
#include <core/list.h>
|
||||||
#include <core/hashfuncs.h>
|
#include <core/hashfuncs.h>
|
||||||
#include <core/hash_map.h>
|
#include <core/hash_map.h>
|
||||||
|
#include "world_editor.h"
|
||||||
#include "building_layout_graph.h"
|
#include "building_layout_graph.h"
|
||||||
|
#include "grid_misc.h"
|
||||||
#include "region_tree.h"
|
#include "region_tree.h"
|
||||||
|
|
||||||
#define SHRINK_RIGHT (1 << 0)
|
#define SHRINK_RIGHT (1 << 0)
|
||||||
|
|||||||
@@ -1094,4 +1094,4 @@ void BuildingLayoutGraphUI::_bind_methods()
|
|||||||
ClassDB::bind_method(D_METHOD("select_grid_floor_ob", "id", "button",
|
ClassDB::bind_method(D_METHOD("select_grid_floor_ob", "id", "button",
|
||||||
"draw"),
|
"draw"),
|
||||||
&BuildingLayoutGraphUI::select_grid_floor_ob);
|
&BuildingLayoutGraphUI::select_grid_floor_ob);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
#include "growth_regions.h"
|
|
||||||
@@ -1,51 +0,0 @@
|
|||||||
#ifndef GROWTH_REGIONS_H
|
|
||||||
#define GROWTH_REGIONS_H
|
|
||||||
#include <core/vector.h>
|
|
||||||
#include <core/list.h>
|
|
||||||
#include <core/pair.h>
|
|
||||||
#include <core/math/vector2.h>
|
|
||||||
#include "base_data.h"
|
|
||||||
#include "region_rect2.h"
|
|
||||||
#include "graph_module.h"
|
|
||||||
struct region {
|
|
||||||
flecs::entity_t parent;
|
|
||||||
flecs::entity_t seed_et;
|
|
||||||
flecs::entity_t region_et;
|
|
||||||
RegionRect2i rect;
|
|
||||||
int remains_area;
|
|
||||||
bool can_grow_square;
|
|
||||||
bool can_move;
|
|
||||||
bool can_grow;
|
|
||||||
bool complete;
|
|
||||||
bool can_grow_region() const
|
|
||||||
{
|
|
||||||
bool ret = can_grow;
|
|
||||||
if (remains_area <= 0)
|
|
||||||
ret = false;
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
bool update_region_size(RegionRect2i &mrect)
|
|
||||||
{
|
|
||||||
bool ret = false;
|
|
||||||
int old_area = rect.get_area();
|
|
||||||
int new_area = mrect.get_area();
|
|
||||||
int area_diff = new_area - old_area;
|
|
||||||
if (area_diff > 0) {
|
|
||||||
rect = mrect;
|
|
||||||
remains_area -= area_diff;
|
|
||||||
ret = true;
|
|
||||||
}
|
|
||||||
if (remains_area <= 0) {
|
|
||||||
can_grow_square = false;
|
|
||||||
can_grow = false;
|
|
||||||
}
|
|
||||||
flecs::log::dbg("update_region_size %d -> %d", area_diff, ret);
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
struct growth_regions {
|
|
||||||
List<struct grow_job> job_list;
|
|
||||||
bool complete;
|
|
||||||
};
|
|
||||||
|
|
||||||
#endif
|
|
||||||
Reference in New Issue
Block a user