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