Redo Lane
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import networks.geometry.curve_tools as curve_tools
|
||||
import networks.geometry.Strip as Strip
|
||||
import networks.roads.lanes.Lane as Lane
|
||||
import networks.roads.lines.Line as Line
|
||||
import json
|
||||
import random
|
||||
|
||||
from gdpc import Editor, Block, geometry
|
||||
|
||||
@@ -25,15 +29,39 @@ class Road:
|
||||
for i in range(len(self.curve_surface.curvature)):
|
||||
self.curvature.append((0, 1, 0))
|
||||
|
||||
with open('networks/roads/lanes/lanes.json') as lanes_materials:
|
||||
lane_type = json.load(lanes_materials).get('classic_lane')
|
||||
|
||||
# for coordinate, block in surface:
|
||||
# editor.placeBlock(coordinate, Block(block))
|
||||
|
||||
with open('networks/roads/lines/lines.json') as lines_materials:
|
||||
line_type = json.load(lines_materials).get('broken_white')
|
||||
|
||||
print(line_type, lane_type)
|
||||
|
||||
# for coordinate, block in surface:
|
||||
# editor.placeBlock(coordinate, Block(block))
|
||||
|
||||
# Perpendicular
|
||||
self.curve_surface.compute_surface_perpendicular(10, self.curvature)
|
||||
for i in range(len(self.curve_surface.surface)):
|
||||
for j in range(len(self.curve_surface.surface[i])):
|
||||
# block = random.choice(block_list)
|
||||
for k in range(len(self.curve_surface.surface[i][j])):
|
||||
editor.placeBlock(
|
||||
self.curve_surface.surface[i][j][k], Block("blackstone"))
|
||||
|
||||
for l in range(len(self.curve_surface.surface[i][j][k])):
|
||||
editor.placeBlock(
|
||||
self.curve_surface.surface[i][j][k][l], Block(random.choices(
|
||||
list(lane_type.keys()),
|
||||
weights=lane_type.values(),
|
||||
k=1,)[0]))
|
||||
if k == 0:
|
||||
block = random.choices(
|
||||
list(pattern_materials[pattern_iteration].keys()),
|
||||
weights=pattern_materials[pattern_iteration].values(
|
||||
),
|
||||
k=1)[0]
|
||||
if block != 'None':
|
||||
self.surface.append((coordinate, block))
|
||||
# offset = curve.offset(curve_surface.curve, -9, curvature)
|
||||
# for i in range(len(offset)-1):
|
||||
# line = segment.discrete_segment(offset[i], offset[i+1])
|
||||
|
||||
@@ -24,15 +24,25 @@ class Lane:
|
||||
for i in range(len(curve_surface.curvature)):
|
||||
normals.append((0, 1, 0))
|
||||
|
||||
# Compute each line
|
||||
for distance in range(self.width):
|
||||
offset = curve_tools.offset(curve_surface.curve, distance, normals)
|
||||
for i in range(len(offset)-1):
|
||||
line = segment_tools.discrete_segment(offset[i], offset[i+1])
|
||||
for coordinate in line:
|
||||
self.surface.append((coordinate, random.choices(
|
||||
list(self.lane_materials.keys()),
|
||||
weights=self.lane_materials.values(),
|
||||
k=1,)))
|
||||
# # Compute each line
|
||||
# for distance in range(self.width):
|
||||
# offset = curve_tools.offset(curve_surface.curve, distance, normals)
|
||||
# for i in range(len(offset)-1):
|
||||
# line = segment_tools.discrete_segment(offset[i], offset[i+1])
|
||||
# for coordinate in line:
|
||||
# self.surface.append((coordinate, random.choices(
|
||||
# list(self.lane_materials.keys()),
|
||||
# weights=self.lane_materials.values(),
|
||||
# k=1,)[0]))
|
||||
|
||||
curve_surface.compute_surface_perpendicular(self.width, normals)
|
||||
for i in range(len(curve_surface.surface)):
|
||||
for j in range(len(curve_surface.surface[i])):
|
||||
for k in range(len(curve_surface.surface[i][j])):
|
||||
for l in range(len(curve_surface.surface[i][j][k])):
|
||||
self.surface.append((curve_surface.surface[i][j][k][l], random.choices(
|
||||
list(self.lane_materials.keys()),
|
||||
weights=self.lane_materials.values(),
|
||||
k=1,)[0]))
|
||||
|
||||
return self.surface
|
||||
|
||||
@@ -5,40 +5,31 @@ import random
|
||||
|
||||
class Line:
|
||||
def __init__(self, coordinates, line_materials):
|
||||
self.coordinates = coordinates
|
||||
self.line_materials = line_materials
|
||||
self.surface = []
|
||||
|
||||
def get_surface(self):
|
||||
resolution, distance = curve_tools.resolution_distance(
|
||||
self.coordinates, 6)
|
||||
|
||||
curve_points = curve_tools.curve(self.coordinates, resolution)
|
||||
|
||||
# Compute the line
|
||||
self.coordinates = coordinates # Full lines coordinates, not just endpoints
|
||||
self.line_materials = line_materials # From lines.json
|
||||
self.coordinates_with_blocks = [] # Output
|
||||
|
||||
def get_blocks(self):
|
||||
pattern_length = 0
|
||||
pattern_materials = []
|
||||
|
||||
# Create the pattern materials list with correct materials depending on the selected pattern.
|
||||
for pattern in self.line_materials:
|
||||
pattern_length += pattern[1]
|
||||
for _ in range(pattern[1]):
|
||||
pattern_materials.append(pattern[0])
|
||||
|
||||
pattern_iteration = 0
|
||||
for i in range(len(curve_points)-1):
|
||||
line = segment_tools.discrete_segment(
|
||||
curve_points[i], curve_points[i+1])
|
||||
for coordinate in line:
|
||||
block = random.choices(
|
||||
list(pattern_materials[pattern_iteration].keys()),
|
||||
weights=pattern_materials[pattern_iteration].values(),
|
||||
k=1)[0]
|
||||
if block != 'None':
|
||||
self.surface.append((coordinate, block))
|
||||
for coordinate in self.coordinates:
|
||||
block = random.choices(
|
||||
list(pattern_materials[pattern_iteration].keys()),
|
||||
weights=pattern_materials[pattern_iteration].values(),
|
||||
k=1)[0]
|
||||
if block != 'None':
|
||||
self.coordinates_with_blocks.append((coordinate, block))
|
||||
|
||||
pattern_iteration += 1
|
||||
if pattern_iteration >= pattern_length:
|
||||
pattern_iteration = 0
|
||||
|
||||
return self.surface
|
||||
return self.coordinates_with_blocks
|
||||
|
||||
Reference in New Issue
Block a user