Started work on procgen
This commit is contained in:
@@ -327,6 +327,9 @@ protected:
|
||||
case 30:
|
||||
editor->remove_generated_stuff();
|
||||
break;
|
||||
case 31:
|
||||
editor->place_generated_objects();
|
||||
break;
|
||||
case 51:
|
||||
editor->set_point_to_cursor();
|
||||
break;
|
||||
@@ -917,6 +920,92 @@ void RoadLinesEditor::load_data()
|
||||
e = e->next();
|
||||
}
|
||||
}
|
||||
void RoadLinesEditor::place_generated_objects()
|
||||
{
|
||||
place_zebras();
|
||||
}
|
||||
void RoadLinesEditor::place_zebras()
|
||||
{
|
||||
editor->remove_buildings_by_prefix("zebra");
|
||||
/*
|
||||
func place_zebras():
|
||||
var road_nodes = SceneComps.get_component("road_nodes2")
|
||||
var next_index = 0
|
||||
var positions = []
|
||||
var d = buildings.keys().duplicate()
|
||||
for k in d:
|
||||
if buildings[k].id == "zebra":
|
||||
buildings.erase(k)
|
||||
for k in buildings.keys():
|
||||
if buildings[k].index >= next_index:
|
||||
next_index = buildings[k].index + 1
|
||||
|
||||
for k in range(road_nodes.roads_data.nodes.size()):
|
||||
if !road_nodes.roads_data.edges.has(str(k)):
|
||||
continue
|
||||
var e = road_nodes.roads_data.edges[str(k)]
|
||||
if e.neighbors.size() <= 2:
|
||||
continue
|
||||
var pos = str2var(road_nodes.roads_data.nodes[k])
|
||||
for n in e.neighbors:
|
||||
var pne = str2var(road_nodes.roads_data.nodes[n])
|
||||
if pos.distance_squared_to(pne) < 50 * 50:
|
||||
continue
|
||||
# var ne = road_nodes.roads_data.edges[str(n)]
|
||||
# var pne = str2var(ne)
|
||||
# var pt = pos.linear_interpolate(pne, 0.5)
|
||||
var dir: Vector3 = (pne - pos).normalized()
|
||||
var nml = dir.rotated(Vector3.UP, PI / 2.0)
|
||||
var points = []
|
||||
var bad = false
|
||||
for x in range(2):
|
||||
points.push_back(pos + dir * 30.0 + nml * 4.0 * x)
|
||||
for x in range(2):
|
||||
points.push_back(pos + dir * 30.0 - nml * 4.0 * (x + 1))
|
||||
for xp in positions:
|
||||
for lp in points:
|
||||
if xp.distance_squared_to(lp) < 30 * 30:
|
||||
bad = true
|
||||
break
|
||||
if bad:
|
||||
points.clear()
|
||||
for pt in points:
|
||||
var xform: Transform = Transform(Basis(), pt)
|
||||
xform = xform.looking_at(pt + nml * 30, Vector3.UP)
|
||||
positions.push_back(xform.origin)
|
||||
var key = var2str(xform)
|
||||
assert(!buildings.has(key))
|
||||
buildings[key] = {
|
||||
"id": "zebra",
|
||||
"index": next_index,
|
||||
"residents": []
|
||||
}
|
||||
next_index += 1
|
||||
for b in spawned_buildings.keys():
|
||||
var sp = spawned_buildings[b]
|
||||
building_pool.unparent_building(sp[0], sp[1])
|
||||
spawned_buildings.clear()
|
||||
|
||||
# for k in road_nodes.roads_data.edges.keys():
|
||||
# if road_nodes.roads_data.edges[k].neighbors.size() <= 2:
|
||||
# continue
|
||||
# for wk in road_nodes.current_wedges.keys():
|
||||
# var wdata = road_nodes.current_wedges[wk]
|
||||
# var sz = wdata.size()
|
||||
# if sz <= 2:
|
||||
# continue
|
||||
# for w in wdata:
|
||||
# var pos = w[4].linear_interpolate(w[3], 0.5)
|
||||
# var xform: Transform = Transform(Basis(), pos)
|
||||
# xform = xform.looking_at(w[1], Vector3.UP)
|
||||
# var key = var2str(xform)
|
||||
# buildings[key] = {
|
||||
# "id": "zebra",
|
||||
# "index": next_index,
|
||||
# "residents": []
|
||||
# }
|
||||
*/
|
||||
}
|
||||
void RoadLinesEditor::save_data()
|
||||
{
|
||||
int i;
|
||||
|
||||
Reference in New Issue
Block a user