Update - fixed lots generation, now can save lots polygons
This commit is contained in:
@@ -27,7 +27,15 @@ public:
|
||||
};
|
||||
|
||||
public:
|
||||
struct test_edge;
|
||||
struct road_edge;
|
||||
struct road_line;
|
||||
struct road_edge_side {
|
||||
const RoadLinesData::road_edge &edge;
|
||||
Vector3 normal;
|
||||
Vector3 pmid[2];
|
||||
Vector3 pside[2];
|
||||
Vector3 test_p[2];
|
||||
int transit_stop_count;
|
||||
String transit_stop_type;
|
||||
float transit_stop_offset;
|
||||
@@ -45,6 +53,12 @@ public:
|
||||
float lot_y_offset;
|
||||
float lot_y_rotation;
|
||||
String lot_type;
|
||||
|
||||
float lot_depth;
|
||||
/* calculated */
|
||||
float lot_depth_eff;
|
||||
|
||||
public:
|
||||
struct buildings {
|
||||
String id;
|
||||
Vector3 offsets;
|
||||
@@ -97,6 +111,7 @@ public:
|
||||
ret["sideroad_y_rotation"] = sideroad_y_rotation;
|
||||
ret["sideroad_type"] = sideroad_type;
|
||||
ret["lot"] = lot;
|
||||
ret["lot_depth"] = lot_depth;
|
||||
ret["lot_offset"] = lot_offset;
|
||||
ret["lot_dir_offset"] = lot_dir_offset;
|
||||
ret["lot_y_offset"] = lot_y_offset;
|
||||
@@ -112,8 +127,9 @@ public:
|
||||
ret["lot_buildings"] = lot_buildings;
|
||||
return ret;
|
||||
}
|
||||
road_edge_side()
|
||||
: transit_stop_count(0)
|
||||
road_edge_side(const RoadLinesData::road_edge &edge)
|
||||
: edge(edge)
|
||||
, transit_stop_count(0)
|
||||
, transit_stop_type("")
|
||||
, transit_stop_offset(0.0f)
|
||||
, transit_stop_dir_offset(0.0f)
|
||||
@@ -130,6 +146,7 @@ public:
|
||||
, lot_y_offset(0.0f)
|
||||
, lot_y_rotation(0.0f)
|
||||
, lot_type(String(""))
|
||||
, lot_depth(100.0f)
|
||||
, buildings{}
|
||||
{
|
||||
}
|
||||
@@ -151,6 +168,7 @@ public:
|
||||
side.sideroad_y_rotation = dict["sideroad_y_rotation"];
|
||||
side.sideroad_type = dict["sideroad_type"];
|
||||
side.lot = dict["lot"];
|
||||
side.lot_depth = dict.get("lot_depth", 100.0f);
|
||||
side.lot_offset = dict["lot_offset"];
|
||||
side.lot_dir_offset = dict["lot_dir_offset"];
|
||||
side.lot_y_offset = dict["lot_y_offset"];
|
||||
@@ -169,6 +187,118 @@ public:
|
||||
parts[i]);
|
||||
}
|
||||
}
|
||||
bool test(const struct RoadLinesData::test_edge &other);
|
||||
void
|
||||
update_test_points(const struct RoadLinesData::road_edge &edge);
|
||||
struct RoadLinesData::road_edge_side &
|
||||
operator=(const struct RoadLinesData::road_edge_side &other)
|
||||
{
|
||||
if (this == &other)
|
||||
return *this;
|
||||
from_dict(*this, other.to_dict());
|
||||
pmid[0] = other.pmid[0];
|
||||
pmid[1] = other.pmid[1];
|
||||
pside[0] = other.pside[0];
|
||||
pside[1] = other.pside[1];
|
||||
normal = other.normal;
|
||||
test_p[0] = other.test_p[0];
|
||||
test_p[1] = other.test_p[1];
|
||||
lot_depth_eff = other.lot_depth_eff;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
struct test_edge {
|
||||
String line_key;
|
||||
int edge_index;
|
||||
int p0_index, p1_index;
|
||||
Vector3 p0, p1;
|
||||
struct road_edge_side left, right;
|
||||
test_edge(const String &key, int index)
|
||||
: line_key(key)
|
||||
, edge_index(index)
|
||||
, left(RoadLinesData::get_singleton()
|
||||
->lines(key)
|
||||
.edges[index])
|
||||
, right(RoadLinesData::get_singleton()
|
||||
->lines(key)
|
||||
.edges[index])
|
||||
{
|
||||
update_from_line();
|
||||
}
|
||||
bool operator==(const struct test_edge &other)
|
||||
{
|
||||
return line_key == other.line_key &&
|
||||
edge_index == other.edge_index;
|
||||
}
|
||||
void validate()
|
||||
{
|
||||
RoadLinesData *rld = RoadLinesData::get_singleton();
|
||||
RoadLinesData::road_edge edge =
|
||||
rld->get_line_edge(line_key, edge_index);
|
||||
if (edge.left.lot != left.lot) {
|
||||
print_line("key: " + line_key +
|
||||
" index: " + itos(edge_index));
|
||||
print_line("rl.edges[edge_index].left.lot = " +
|
||||
itos(edge.left.lot));
|
||||
print_line("left.lot = " + itos(left.lot));
|
||||
}
|
||||
if (edge.right.lot != right.lot) {
|
||||
print_line("key: " + line_key +
|
||||
" index: " + itos(edge_index));
|
||||
print_line("rl.edges[edge_index].right.lot = " +
|
||||
itos(edge.right.lot));
|
||||
print_line("right.lot = " + itos(right.lot));
|
||||
}
|
||||
assert(edge.left.lot == left.lot);
|
||||
assert(edge.left.lot_depth == left.lot_depth);
|
||||
assert(edge.right.lot == right.lot);
|
||||
assert(edge.right.lot_depth == right.lot_depth);
|
||||
}
|
||||
void update_from_line()
|
||||
{
|
||||
RoadLinesData *rld = RoadLinesData::get_singleton();
|
||||
RoadLinesData::road_edge edge =
|
||||
rld->get_line_edge(line_key, edge_index);
|
||||
print_line("line: " + line_key +
|
||||
" index: " + itos(edge_index) +
|
||||
" left.lot: " + itos(edge.left.lot) +
|
||||
" right.lot: " + itos(edge.right.lot));
|
||||
print_line(edge.left.pmid[0].operator String());
|
||||
print_line(edge.right.pmid[0].operator String());
|
||||
assert(edge.left.pmid[0].is_equal_approx(
|
||||
edge.right.pmid[0]));
|
||||
assert(edge.left.pmid[1].is_equal_approx(
|
||||
edge.right.pmid[1]));
|
||||
|
||||
left = edge.left;
|
||||
right = edge.right;
|
||||
left.normal = edge.left.normal;
|
||||
left.lot = edge.left.lot;
|
||||
left.lot_depth = edge.left.lot_depth;
|
||||
right.normal = edge.right.normal;
|
||||
right.lot = edge.right.lot;
|
||||
right.lot_depth = edge.right.lot_depth;
|
||||
validate();
|
||||
}
|
||||
void update_line()
|
||||
{
|
||||
print_line("update_line");
|
||||
RoadLinesData *rld = RoadLinesData::get_singleton();
|
||||
RoadLinesData::road_edge_side tmp_left =
|
||||
rld->get_line_edge_left(line_key, edge_index);
|
||||
RoadLinesData::road_edge_side tmp_right =
|
||||
rld->get_line_edge_right(line_key, edge_index);
|
||||
tmp_left.lot = left.lot;
|
||||
tmp_left.lot_depth = left.lot_depth;
|
||||
tmp_right.lot = right.lot;
|
||||
tmp_right.lot_depth = right.lot_depth;
|
||||
rld->set_line_edge_left(line_key, edge_index, tmp_left);
|
||||
rld->set_line_edge_right(line_key, edge_index,
|
||||
tmp_right);
|
||||
validate();
|
||||
rld->update_line_edges();
|
||||
validate();
|
||||
}
|
||||
};
|
||||
struct road_edge {
|
||||
struct road_edge_side left, right;
|
||||
@@ -188,10 +318,18 @@ public:
|
||||
road_edge_side::from_dict(edge.left, dleft);
|
||||
road_edge_side::from_dict(edge.right, dright);
|
||||
}
|
||||
road_edge()
|
||||
: left(*this)
|
||||
, right(*this)
|
||||
{
|
||||
}
|
||||
};
|
||||
struct road_line {
|
||||
std::vector<Transform> points;
|
||||
|
||||
std::vector<struct road_edge> edges;
|
||||
|
||||
public:
|
||||
std::vector<struct line_segment> segments;
|
||||
int lanes;
|
||||
int pattern;
|
||||
@@ -202,6 +340,50 @@ public:
|
||||
struct road_line_index {
|
||||
std::vector<int> indices;
|
||||
};
|
||||
void update_line_edges()
|
||||
{
|
||||
int edge_index;
|
||||
List<String> keys;
|
||||
get_road_lines_key_list(&keys);
|
||||
List<String>::Element *e = keys.front();
|
||||
while (e) {
|
||||
String key = e->get();
|
||||
// struct road_line rl = get_line(key);
|
||||
for (edge_index = 0;
|
||||
edge_index < get_line_edge_count(key);
|
||||
edge_index++) {
|
||||
const Vector3 &p0 =
|
||||
get_line_point(key, edge_index);
|
||||
const Vector3 &p1 =
|
||||
get_line_point(key, edge_index + 1);
|
||||
Vector3 dir = (p1 - p0).normalized();
|
||||
Vector3 d = dir;
|
||||
Vector3 left_n = Vector3(0, 1, 0).cross(d);
|
||||
Vector3 right_n = -left_n;
|
||||
RoadLinesData::road_edge tmp_edge =
|
||||
get_line_edge(key, edge_index);
|
||||
tmp_edge.left.normal = left_n;
|
||||
tmp_edge.right.normal = right_n;
|
||||
tmp_edge.left.pmid[0] = p0;
|
||||
tmp_edge.left.pmid[1] = p1;
|
||||
tmp_edge.right.pmid[0] = p0;
|
||||
tmp_edge.right.pmid[1] = p1;
|
||||
tmp_edge.left.test_p[0] = p0 + (p1 - p0) * 0.5f;
|
||||
tmp_edge.left.test_p[1] =
|
||||
tmp_edge.left.test_p[0] +
|
||||
tmp_edge.left.normal *
|
||||
tmp_edge.left.lot_depth;
|
||||
tmp_edge.right.test_p[0] =
|
||||
p0 + (p1 - p0) * 0.5f;
|
||||
tmp_edge.right.test_p[1] =
|
||||
tmp_edge.right.test_p[0] +
|
||||
tmp_edge.right.normal *
|
||||
tmp_edge.right.lot_depth;
|
||||
set_line_edge(key, edge_index, tmp_edge);
|
||||
}
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
|
||||
public:
|
||||
static ImmediateGeometry *get_debug_node();
|
||||
@@ -214,6 +396,25 @@ public:
|
||||
const struct road_line &lines(const String &key) const;
|
||||
const struct road_line_index &indices(const String &key) const;
|
||||
void set_line(const String &key, const struct road_line &line);
|
||||
void update_line(const String &key);
|
||||
const struct road_line *get_line_ptr(const String &key) const;
|
||||
struct road_edge get_line_edge(const String &key, int edge) const;
|
||||
struct road_edge_side get_line_edge_left(const String &key,
|
||||
int edge) const;
|
||||
struct road_edge_side get_line_edge_right(const String &key,
|
||||
int edge) const;
|
||||
struct road_edge_side get_line_edge_side(const String &key, int edge,
|
||||
int side) const;
|
||||
void set_line_edge_left(const String &key, int edge,
|
||||
struct road_edge_side &side);
|
||||
void set_line_edge_right(const String &key, int edge,
|
||||
struct road_edge_side &side);
|
||||
void set_line_edge(const String &key, int edge_id,
|
||||
const struct road_edge &edge);
|
||||
int get_line_edge_count(const String &key) const;
|
||||
const Vector3 &get_line_point(const String &key, int index) const;
|
||||
const Transform &get_line_point_transform(const String &key,
|
||||
int index) const;
|
||||
bool has_line(const String &key);
|
||||
void insert_line_point(const String &key, int index,
|
||||
const Transform &xform);
|
||||
|
||||
Reference in New Issue
Block a user