Now generating roads on terrain. Still some trouble left.
This commit is contained in:
@@ -197,8 +197,12 @@ void Roads::update_all()
|
||||
mat = mesh->surface_get_material(0);
|
||||
}
|
||||
}
|
||||
if (curve.is_valid() && noise.is_valid())
|
||||
if (curve.is_valid() && noise.is_valid()) {
|
||||
curve->bake();
|
||||
RoadsData::get_singleton()->set_noise(noise);
|
||||
RoadsData::get_singleton()->set_curve(curve);
|
||||
rg->build(curve, noise);
|
||||
}
|
||||
printf("vertices: %d\n", rg->diagram_vertices.size());
|
||||
printf("heights: %d\n", rg->diagram_vertex_heights.size());
|
||||
printf("edges: %d\n", rg->map_hedges.size());
|
||||
@@ -588,13 +592,35 @@ void RoadsData::destroy_singleton()
|
||||
memdelete(g_roads_data);
|
||||
g_roads_data = NULL;
|
||||
}
|
||||
RoadGrid *RoadsData::get_road_grid()
|
||||
RoadGrid *RoadsData::get_road_grid() const
|
||||
{
|
||||
return rg;
|
||||
}
|
||||
void RoadsData::_bind_methods()
|
||||
{
|
||||
ClassDB::bind_method(D_METHOD("get_road_grid"), &RoadsData::get_road_grid);
|
||||
ClassDB::bind_method(D_METHOD("get_sdf", "x", "y", "z"), &RoadsData::get_sdf);
|
||||
}
|
||||
void RoadsData::set_noise(Ref<OpenSimplexNoise> noise)
|
||||
{
|
||||
this->noise = noise;
|
||||
}
|
||||
void RoadsData::set_curve(Ref<Curve> curve)
|
||||
{
|
||||
this->curve = curve;
|
||||
}
|
||||
float RoadsData::get_sdf(int x, int y, int z)
|
||||
{
|
||||
if (!curve.is_valid() || !noise.is_valid())
|
||||
return (float)y;
|
||||
float n = curve->interpolate_baked(0.5f + noise->get_noise_2d(x, z) * 0.5f);
|
||||
Vector2 ifl = rg->get_influence(x, z);
|
||||
if (ifl.x > 0.0f) {
|
||||
if (n <= ifl.y + 2.0f)
|
||||
return (float)y - ifl.y;
|
||||
else
|
||||
return (float)y - ifl.y;
|
||||
}
|
||||
return y - n;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user