Separated setup code
This commit is contained in:
@@ -131,12 +131,6 @@ void Roads::all_offsets()
|
||||
for (k = mesh_data.next(NULL); k; k = mesh_data.next(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> ret;
|
||||
@@ -180,7 +174,7 @@ inline float Roads::get_total_width(float width, int flags, float sidewalk_width
|
||||
{
|
||||
int i;
|
||||
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++)
|
||||
total_width += offsets[parts_list[i]].x;
|
||||
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);
|
||||
Ref<Curve3D> curve = build_curve(points[0], points[1], points[2], total_width);
|
||||
assert(!curve.is_null());
|
||||
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;
|
||||
Array ret;
|
||||
all_offsets();
|
||||
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(!curve3.is_null());
|
||||
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();
|
||||
assert(l > 0.0f);
|
||||
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;
|
||||
PoolVector<Vector3> points = make_points(data->points);
|
||||
rg->all_offsets();
|
||||
Ref<Curve3D> curve3 = get_curve(points, data->width2, data->flags, data->sidewalk_width);
|
||||
Array rdata = curve_mesh(points, curve3, data->width1, 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, 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;
|
||||
assert(mdata.is_valid());
|
||||
mdata->add_surface_from_arrays(Mesh::PRIMITIVE_TRIANGLES, rdata);
|
||||
@@ -424,7 +426,7 @@ void Roads::process_vshapes()
|
||||
camarea.grow_by(550.0f);
|
||||
int i;
|
||||
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++) {
|
||||
if (active_vshapes.size() > 32)
|
||||
break;
|
||||
@@ -446,11 +448,10 @@ void Roads::process_vshapes()
|
||||
List<int>::Element *e;
|
||||
for (e = active_vshapes.front(); e; e = e->next()) {
|
||||
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.p2.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 (thread.thread.is_started())
|
||||
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.write()[0] = v->p1;
|
||||
@@ -480,6 +497,16 @@ void Roads::create_data(struct RoadGrid::vshape *v, struct RoadMeshData *data, i
|
||||
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)
|
||||
{
|
||||
switch(p_what) {
|
||||
@@ -492,6 +519,9 @@ void Roads::_notification(int p_what)
|
||||
counter = 0;
|
||||
set_process(true);
|
||||
add_child(body);
|
||||
sidewalk_width = 6.0f;
|
||||
all_offsets();
|
||||
build_vshape_data();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user