diff --git a/main.py b/main.py index 2fb0396..a7aa278 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import networks.lines.Line as Line +import networks.lanes.Lane as Lane from gdpc import Editor, Block, geometry import networks.geometry.curve as curve import networks.geometry.CurveSurface as CurveSurface @@ -91,9 +92,14 @@ block_list = ["blue_concrete", "red_concrete", "green_concrete", # # editor.placeBlock(coordinate, Block("yellow_concrete")) -coordinates = [(0, 0, 0), (0, 10, 0), (0, 20, 0)] +coordinates = [(0, 0, 0), (0, 0, 10), (0, 0, 20)] -with open('networks/lines/line.json') as f: - lines_type = json.load(f) - l = Line.Line(coordinates, lines_type.get('solid_white')) - print(l.get_surface()) +# with open('networks/lines/lines.json') as f: +# lines_type = json.load(f) +# l = Line.Line(coordinates, lines_type.get('solid_white')) +# print(l.get_surface()) + +# with open('networks/lanes/lanes.json') as f: +# lanes_type = json.load(f) +# l = Lane.Lane(coordinates, lanes_type.get('classic_lane'), 5) +# print(l.get_surface()) diff --git a/networks/lanes/Lane.py b/networks/lanes/Lane.py index dd1e5eb..3e3824e 100644 --- a/networks/lanes/Lane.py +++ b/networks/lanes/Lane.py @@ -5,18 +5,17 @@ import random class Lane: - def __init__(self, coordinates, width, lane_type): + def __init__(self, coordinates, lane_materials, width): self.coordinates = coordinates self.width = width - self.lane_type = lane_type self.lane_materials = lane_materials self.surface = [] - def create_surface(self, coordinates): - resolution, distance = curve.resolution_distance(coordinates, 6) + def get_surface(self): + resolution, distance = curve.resolution_distance(self.coordinates, 6) - curve_points = curve.curve(coordinates, resolution) - curve_surface = CurveSurface.CurveSurface(coordinates) + curve_points = curve.curve(self.coordinates, resolution) + curve_surface = CurveSurface.CurveSurface(self.coordinates) curve_surface.compute_curvature() # Set the road to be flat @@ -25,12 +24,14 @@ class Lane: normals.append((0, 1, 0)) # Compute each line - for distance in range(width): + for distance in range(self.width): offset = curve.offset(curve_surface.curve, distance, normals) for i in range(len(offset)-1): line = segment.discrete_segment(offset[i], offset[i+1]) for coordinate in line: self.surface.append((coordinate, random.choices( - list(lane_materials.keys()), - weights=lane_materials.values(), + list(self.lane_materials.keys()), + weights=self.lane_materials.values(), k=1,))) + + return self.surface diff --git a/networks/lanes/materials.json b/networks/lanes/lanes.json similarity index 100% rename from networks/lanes/materials.json rename to networks/lanes/lanes.json diff --git a/networks/lines/Line.py b/networks/lines/Line.py index 86e6dbd..0222eef 100644 --- a/networks/lines/Line.py +++ b/networks/lines/Line.py @@ -4,9 +4,9 @@ import random class Line: - def __init__(self, coordinates, line_type): + def __init__(self, coordinates, line_materials): self.coordinates = coordinates - self.line_type = line_type + self.line_materials = line_materials self.surface = [] def get_surface(self): @@ -18,7 +18,7 @@ class Line: pattern_length = 0 pattern_materials = [] - for key, value in self.line_type.items(): + for key, value in self.line_materials.items(): pattern_length += int(key) for _ in range(int(key)): pattern_materials.append(value) diff --git a/networks/lines/line.json b/networks/lines/lines.json similarity index 100% rename from networks/lines/line.json rename to networks/lines/lines.json