Separated setup code
This commit is contained in:
@@ -624,7 +624,7 @@ static Dictionary map_site2dict(const struct map_site *ms)
|
|||||||
ret["avg_height"] = ms->avg_height;
|
ret["avg_height"] = ms->avg_height;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
static Dictionary vshape2dict(const struct RoadGrid::vshape *v)
|
static Dictionary vshape2dict(const struct vshape *v)
|
||||||
{
|
{
|
||||||
Dictionary ret;
|
Dictionary ret;
|
||||||
ret["area"] = var2str(v->area);
|
ret["area"] = var2str(v->area);
|
||||||
@@ -680,4 +680,3 @@ void RoadGrid::save_json(const String &path)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -69,6 +69,22 @@ struct half_edge {
|
|||||||
float depth;
|
float depth;
|
||||||
float length;
|
float length;
|
||||||
};
|
};
|
||||||
|
struct vshape {
|
||||||
|
AABB area;
|
||||||
|
int instance;
|
||||||
|
int e1, e2;
|
||||||
|
int site;
|
||||||
|
Vector3 p1, p2, p3;
|
||||||
|
float depth1, depth2;
|
||||||
|
|
||||||
|
/* filled later */
|
||||||
|
float total_width1,
|
||||||
|
total_width2;
|
||||||
|
PoolVector<String> parts_list1,
|
||||||
|
parts_list2;
|
||||||
|
Ref<Curve3D> curve3;
|
||||||
|
Ref<Curve3D> curve3a;
|
||||||
|
};
|
||||||
class RoadDiagram {
|
class RoadDiagram {
|
||||||
protected:
|
protected:
|
||||||
List<struct cluster> clusters;
|
List<struct cluster> clusters;
|
||||||
@@ -128,19 +144,8 @@ protected:
|
|||||||
Ref<RandomNumberGenerator> rnd;
|
Ref<RandomNumberGenerator> rnd;
|
||||||
int keep_seed;
|
int keep_seed;
|
||||||
List<struct cluster> clusters;
|
List<struct cluster> clusters;
|
||||||
protected:
|
|
||||||
Rect2 bounds;
|
Rect2 bounds;
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
public:
|
|
||||||
struct vshape {
|
|
||||||
AABB area;
|
|
||||||
int instance;
|
|
||||||
int e1, e2;
|
|
||||||
int site;
|
|
||||||
Vector3 p1, p2, p3;
|
|
||||||
float depth1, depth2;
|
|
||||||
};
|
|
||||||
protected:
|
|
||||||
Vector<Vector2> diagram_vertices;
|
Vector<Vector2> diagram_vertices;
|
||||||
Vector<struct map_site> map_sites;
|
Vector<struct map_site> map_sites;
|
||||||
Vector<struct half_edge *> map_hedges;
|
Vector<struct half_edge *> map_hedges;
|
||||||
|
|||||||
@@ -131,12 +131,6 @@ void Roads::all_offsets()
|
|||||||
for (k = mesh_data.next(NULL); k; k = mesh_data.next(k))
|
for (k = mesh_data.next(NULL); k; k = mesh_data.next(k))
|
||||||
offsets[*k] = calculate_offsets(mesh_data[*k]);
|
offsets[*k] = calculate_offsets(mesh_data[*k]);
|
||||||
}
|
}
|
||||||
enum {
|
|
||||||
FLAGS_SIDEWALK = (1 << 0),
|
|
||||||
FLAGS_INTERSECTION = (1 << 1),
|
|
||||||
FLAGS_WALL = (1 << 2),
|
|
||||||
};
|
|
||||||
|
|
||||||
PoolVector<String> Roads::build_item_list(float width, int flags, float sidewalk_width) const
|
PoolVector<String> Roads::build_item_list(float width, int flags, float sidewalk_width) const
|
||||||
{
|
{
|
||||||
PoolVector<String> ret;
|
PoolVector<String> ret;
|
||||||
@@ -180,7 +174,7 @@ inline float Roads::get_total_width(float width, int flags, float sidewalk_width
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
float total_width = 0.0f;
|
float total_width = 0.0f;
|
||||||
PoolVector<String> parts_list = rg->build_item_list(width, flags, sidewalk_width);
|
PoolVector<String> parts_list = build_item_list(width, flags, sidewalk_width);
|
||||||
for (i = 0; i < parts_list.size(); i++)
|
for (i = 0; i < parts_list.size(); i++)
|
||||||
total_width += offsets[parts_list[i]].x;
|
total_width += offsets[parts_list[i]].x;
|
||||||
return total_width;
|
return total_width;
|
||||||
@@ -190,22 +184,24 @@ inline Ref<Curve3D> Roads::get_curve(const PoolVector<Vector3> &points, float wi
|
|||||||
{
|
{
|
||||||
float total_width = get_total_width(width, flags, sidewalk_width);
|
float total_width = get_total_width(width, flags, sidewalk_width);
|
||||||
Ref<Curve3D> curve = build_curve(points[0], points[1], points[2], total_width);
|
Ref<Curve3D> curve = build_curve(points[0], points[1], points[2], total_width);
|
||||||
|
assert(!curve.is_null());
|
||||||
return curve;
|
return curve;
|
||||||
}
|
}
|
||||||
|
|
||||||
Array Roads::curve_mesh(const PoolVector<Vector3> &points, Ref<Curve3D> curve3, float width1, float width2, int flags, float sidewalk_width)
|
Array Roads::curve_mesh(const PoolVector<Vector3> &points,
|
||||||
|
Ref<Curve3D> curve3,
|
||||||
|
float total_width1,
|
||||||
|
float total_width2,
|
||||||
|
const PoolVector<String> &parts_list1,
|
||||||
|
const PoolVector<String> &parts_list2,
|
||||||
|
int flags,
|
||||||
|
float sidewalk_width)
|
||||||
{
|
{
|
||||||
float tx = 0.0f, total_width1 = 0.0f, total_width2 = 0.0f, t = 0.0f, l;
|
float tx = 0.0f, t = 0.0f, l;
|
||||||
int i;
|
int i;
|
||||||
Array ret;
|
Array ret;
|
||||||
all_offsets();
|
assert(!curve3.is_null());
|
||||||
total_width1 = get_total_width(width1, flags, sidewalk_width);
|
|
||||||
total_width2 = get_total_width(width2, flags, sidewalk_width);
|
|
||||||
PoolVector<String> parts_list1 = build_item_list(width1, flags, sidewalk_width);
|
|
||||||
PoolVector<String> parts_list2 = build_item_list(width2, flags, sidewalk_width);
|
|
||||||
assert(total_width1 >= 3.0f && total_width2 >= 3.0f);
|
assert(total_width1 >= 3.0f && total_width2 >= 3.0f);
|
||||||
// Ref<Curve3D> curve3 = build_curve(points[0], points[1], points[2], total_width2);
|
|
||||||
// Ref<Curve3D> curve3 = get_curve(points, width2, flags, sidewalk_width);
|
|
||||||
l = curve3->get_baked_length();
|
l = curve3->get_baked_length();
|
||||||
assert(l > 0.0f);
|
assert(l > 0.0f);
|
||||||
PoolVector<Vector3> new_verts, new_normals;
|
PoolVector<Vector3> new_verts, new_normals;
|
||||||
@@ -368,9 +364,15 @@ int Roads::make_vmesh(Node *root, Ref<Material> mat, Ref<ArrayMesh> mesh, MeshIn
|
|||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
PoolVector<Vector3> points = make_points(data->points);
|
PoolVector<Vector3> points = make_points(data->points);
|
||||||
rg->all_offsets();
|
// Ref<Curve3D> curve3 = get_curve(points, data->width2, data->flags, data->sidewalk_width);
|
||||||
Ref<Curve3D> curve3 = get_curve(points, data->width2, data->flags, data->sidewalk_width);
|
assert(!data->vshape->curve3.is_null());
|
||||||
Array rdata = curve_mesh(points, curve3, data->width1, data->width2, data->flags, data->sidewalk_width);
|
Array rdata = curve_mesh(points, data->vshape->curve3,
|
||||||
|
data->vshape->total_width1,
|
||||||
|
data->vshape->total_width2,
|
||||||
|
data->vshape->parts_list1,
|
||||||
|
data->vshape->parts_list2,
|
||||||
|
data->flags,
|
||||||
|
data->sidewalk_width);
|
||||||
Ref<ArrayMesh> mdata = mesh;
|
Ref<ArrayMesh> mdata = mesh;
|
||||||
assert(mdata.is_valid());
|
assert(mdata.is_valid());
|
||||||
mdata->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, rdata);
|
mdata->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, rdata);
|
||||||
@@ -424,7 +426,7 @@ void Roads::process_vshapes()
|
|||||||
camarea.grow_by(550.0f);
|
camarea.grow_by(550.0f);
|
||||||
int i;
|
int i;
|
||||||
List<int> active_vshapes;
|
List<int> active_vshapes;
|
||||||
const PoolVector<struct RoadGrid::vshape> &vshapes = rg->get_vshapes();
|
const PoolVector<struct vshape> &vshapes = rg->get_vshapes();
|
||||||
for (i = 0; i < vshapes.size(); i++) {
|
for (i = 0; i < vshapes.size(); i++) {
|
||||||
if (active_vshapes.size() > 32)
|
if (active_vshapes.size() > 32)
|
||||||
break;
|
break;
|
||||||
@@ -446,11 +448,10 @@ void Roads::process_vshapes()
|
|||||||
List<int>::Element *e;
|
List<int>::Element *e;
|
||||||
for (e = active_vshapes.front(); e; e = e->next()) {
|
for (e = active_vshapes.front(); e; e = e->next()) {
|
||||||
i = e->get();
|
i = e->get();
|
||||||
struct RoadGrid::vshape &v = rg->get_vshapes().write()[i];
|
struct vshape &v = rg->get_vshapes().write()[i];
|
||||||
assert(v.p1.distance_squared_to(v.p2) > 2.0f);
|
assert(v.p1.distance_squared_to(v.p2) > 2.0f);
|
||||||
assert(v.p2.distance_squared_to(v.p3) > 2.0f);
|
assert(v.p2.distance_squared_to(v.p3) > 2.0f);
|
||||||
assert(v.p1.distance_squared_to(v.p3) > 2.0f);
|
assert(v.p1.distance_squared_to(v.p3) > 2.0f);
|
||||||
float sidewalk_width = 6.0f;
|
|
||||||
if (vshapes[i].instance < 0) {
|
if (vshapes[i].instance < 0) {
|
||||||
if (thread.thread.is_started())
|
if (thread.thread.is_started())
|
||||||
thread.thread.wait_to_finish();
|
thread.thread.wait_to_finish();
|
||||||
@@ -467,7 +468,23 @@ void Roads::process_vshapes()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void Roads::create_data(struct RoadGrid::vshape *v, struct RoadMeshData *data, int flags, float sidewalk_width)
|
void Roads::create_vshape_data(struct vshape *v, int flags, float sidewalk_width)
|
||||||
|
{
|
||||||
|
PoolVector<Vector3> ipoints;
|
||||||
|
ipoints.resize(3);
|
||||||
|
ipoints.write()[0] = v->p1;
|
||||||
|
ipoints.write()[1] = v->p2;
|
||||||
|
ipoints.write()[2] = v->p3;
|
||||||
|
v->total_width1 = get_total_width(v->depth1, flags, sidewalk_width);
|
||||||
|
v->total_width2 = get_total_width(v->depth2, flags, sidewalk_width);
|
||||||
|
v->parts_list1 = build_item_list(v->depth1, flags, sidewalk_width);
|
||||||
|
v->parts_list2 = build_item_list(v->depth2, flags, sidewalk_width);
|
||||||
|
PoolVector<Vector3> points = make_points(ipoints);
|
||||||
|
v->curve3 = get_curve(points, v->depth2, flags, sidewalk_width);
|
||||||
|
v->curve3a = get_curve(points, v->depth1, flags, sidewalk_width);
|
||||||
|
assert(!v->curve3.is_null());
|
||||||
|
}
|
||||||
|
void Roads::create_data(struct vshape *v, struct RoadMeshData *data, int flags, float sidewalk_width)
|
||||||
{
|
{
|
||||||
data->points.resize(3);
|
data->points.resize(3);
|
||||||
data->points.write()[0] = v->p1;
|
data->points.write()[0] = v->p1;
|
||||||
@@ -480,6 +497,16 @@ void Roads::create_data(struct RoadGrid::vshape *v, struct RoadMeshData *data, i
|
|||||||
data->vshape = v;
|
data->vshape = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Roads::build_vshape_data()
|
||||||
|
{
|
||||||
|
int i;
|
||||||
|
RoadGrid *rg = RoadsData::get_singleton()->get_road_grid();
|
||||||
|
PoolVector<struct vshape> &vshapes = rg->get_vshapes();
|
||||||
|
for (i = 0; i < vshapes.size(); i++)
|
||||||
|
create_vshape_data(&(vshapes.write()[i]), FLAGS_SIDEWALK|FLAGS_INTERSECTION,
|
||||||
|
sidewalk_width);
|
||||||
|
}
|
||||||
|
|
||||||
void Roads::_notification(int p_what)
|
void Roads::_notification(int p_what)
|
||||||
{
|
{
|
||||||
switch(p_what) {
|
switch(p_what) {
|
||||||
@@ -492,6 +519,9 @@ void Roads::_notification(int p_what)
|
|||||||
counter = 0;
|
counter = 0;
|
||||||
set_process(true);
|
set_process(true);
|
||||||
add_child(body);
|
add_child(body);
|
||||||
|
sidewalk_width = 6.0f;
|
||||||
|
all_offsets();
|
||||||
|
build_vshape_data();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@
|
|||||||
#include <scene/resources/concave_polygon_shape.h>
|
#include <scene/resources/concave_polygon_shape.h>
|
||||||
|
|
||||||
class StaticBody;
|
class StaticBody;
|
||||||
struct RoadGrid::vshape;
|
struct vshape;
|
||||||
|
|
||||||
struct RoadMeshData {
|
struct RoadMeshData {
|
||||||
PoolVector<Vector3> points;
|
PoolVector<Vector3> points;
|
||||||
@@ -14,7 +14,7 @@ struct RoadMeshData {
|
|||||||
float width2;
|
float width2;
|
||||||
int flags;
|
int flags;
|
||||||
float sidewalk_width;
|
float sidewalk_width;
|
||||||
struct RoadGrid::vshape *vshape;
|
struct vshape *vshape;
|
||||||
};
|
};
|
||||||
|
|
||||||
class Roads: public MeshInstance {
|
class Roads: public MeshInstance {
|
||||||
@@ -32,6 +32,7 @@ protected:
|
|||||||
void _get_property_list(List<PropertyInfo> *p_list) const;
|
void _get_property_list(List<PropertyInfo> *p_list) const;
|
||||||
static void _bind_methods();
|
static void _bind_methods();
|
||||||
void update_all();
|
void update_all();
|
||||||
|
float sidewalk_width;
|
||||||
struct thread_data {
|
struct thread_data {
|
||||||
Thread thread;
|
Thread thread;
|
||||||
Ref<Material> mat;
|
Ref<Material> mat;
|
||||||
@@ -78,15 +79,20 @@ public:
|
|||||||
PoolVector<String> build_item_list(float width, int flags, float sidewalk_width) const;
|
PoolVector<String> build_item_list(float width, int flags, float sidewalk_width) const;
|
||||||
Ref<Curve3D> build_curve(Vector3 p1, Vector3 p2, Vector3 p3, float total_width) const;
|
Ref<Curve3D> build_curve(Vector3 p1, Vector3 p2, Vector3 p3, float total_width) const;
|
||||||
// Array curve_mesh(PoolVector<Vector3> points, float width1, float width2, int flags, float sidewalk_width);
|
// Array curve_mesh(PoolVector<Vector3> points, float width1, float width2, int flags, float sidewalk_width);
|
||||||
Array curve_mesh(const PoolVector<Vector3> &points, Ref<Curve3D> curve3, float width1, float width2, int flags, float sidewalk_width);
|
Array curve_mesh(const PoolVector<Vector3> &points, Ref<Curve3D> curve3, float total_width1, float total_width2,
|
||||||
|
const PoolVector<String> &parts_list1,
|
||||||
|
const PoolVector<String> &parts_list2,
|
||||||
|
int flags, float sidewalk_width);
|
||||||
int make_vmesh(Node *root, Ref<Material> mat, Ref<ArrayMesh> mesh, MeshInstance *xmi, RoadMeshData *data);
|
int make_vmesh(Node *root, Ref<Material> mat, Ref<ArrayMesh> mesh, MeshInstance *xmi, RoadMeshData *data);
|
||||||
void process_vshapes();
|
void process_vshapes();
|
||||||
void create_data(struct RoadGrid::vshape *v,
|
void create_vshape_data(struct vshape *v, int flags, float sidewalk_width);
|
||||||
|
void create_data(struct vshape *v,
|
||||||
struct RoadMeshData *data,
|
struct RoadMeshData *data,
|
||||||
int flags, float sidewalk_width);
|
int flags, float sidewalk_width);
|
||||||
void add_scene_element(Node *root, Node *xnode, const Vector3 &p2, Ref<ConcavePolygonShape> shape);
|
void add_scene_element(Node *root, Node *xnode, const Vector3 &p2, Ref<ConcavePolygonShape> shape);
|
||||||
inline float get_total_width(float width, int flags, float sidewalk_width);
|
inline float get_total_width(float width, int flags, float sidewalk_width);
|
||||||
inline Ref<Curve3D> get_curve(const PoolVector<Vector3> &points, float width, int flags, float sidewalk_width);
|
inline Ref<Curve3D> get_curve(const PoolVector<Vector3> &points, float width, int flags, float sidewalk_width);
|
||||||
|
void build_vshape_data();
|
||||||
};
|
};
|
||||||
|
|
||||||
class RoadsData: public Object {
|
class RoadsData: public Object {
|
||||||
|
|||||||
Reference in New Issue
Block a user