From 4e80fc3791455d25bd9b7bad14feb7aa63dacdae Mon Sep 17 00:00:00 2001 From: Xeon0X Date: Sat, 20 Apr 2024 15:48:32 +0200 Subject: [PATCH] Add dev instructions --- README.md | 15 +++++++++-- main.py | 19 ++++++++----- networks/curve.py | 61 ++++++++++++++++++++++++++++++++++++++++++ networks/roads/road.py | 7 +++++ 4 files changed, 93 insertions(+), 9 deletions(-) create mode 100644 networks/curve.py create mode 100644 networks/roads/road.py diff --git a/README.md b/README.md index 05d6dbe..881b09a 100644 --- a/README.md +++ b/README.md @@ -4,8 +4,19 @@ A procedural city generator for Minecraft as part of the GDMC 2024 competition. # Run Install required packages using `pip`: -```python +```bash pip install -r requirements.txt ``` -Run `main.py`. \ No newline at end of file +Run `main.py`. + +# Dev + +First, setup your virtual environment using Python's built-in venv. + +Install `pipreqs`: +```bash +pip install pipreqs +``` + +Run `pipreqs --ignore .venv` to generate an updated list of dependencies for the project in requirements file. \ No newline at end of file diff --git a/main.py b/main.py index 061ccec..139193e 100644 --- a/main.py +++ b/main.py @@ -1,12 +1,17 @@ from gdpc import Editor, Block, geometry +import networks.curve as curve -editor = Editor(buffering=True) -# Get a block -block = editor.getBlock((0,48,0)) -# Place a block -editor.placeBlock((394, 132, 741), Block("stone")) +# editor = Editor(buffering=True) -# Build a cube -geometry.placeCuboid(editor, (458, 92, 488), (468, 99, 471), Block("oak_planks")) \ No newline at end of file +# # Get a block +# block = editor.getBlock((0,48,0)) + +# # Place a block +# editor.placeBlock((394, 132, 741), Block("stone")) + +# # Build a cube +# geometry.placeCuboid(editor, (458, 92, 488), (468, 99, 471), Block("oak_planks")) + +curve = curve.Curve([(0, 0, 0)]) \ No newline at end of file diff --git a/networks/curve.py b/networks/curve.py new file mode 100644 index 0000000..c384a98 --- /dev/null +++ b/networks/curve.py @@ -0,0 +1,61 @@ +class Curve: + def __init__(self, points): + self.points = points # list of tuples (x1, y1, z1) in order + + def curve(points, resolution=40, debug=False): + """ + Returns a 3d curve. + + https://stackoverflow.com/questions/18962175/spline-interpolation-coefficients-of-a-line-curve-in-3d-space + + Args: + points (np.array): Points where the curve should pass in order. + resolution (int, optional): Number of points to compute. Defaults to 40. + debug (bool, optional): Visual. Defaults to False. + + Returns: + tuple: Tuple of list of each coordinate. + """ + # Remove duplicates. + points = tuple(map(tuple, points)) + points = sorted(set(points), key=points.index) + + x_sample = [] + y_sample = [] + z_sample = [] + + for i in range(len(points)): + x_sample.append(points[i][0]) + z_sample.append(points[i][1]) + y_sample.append(points[i][2]) + + x_sample = np.array(x_sample) + y_sample = np.array(y_sample) + z_sample = np.array(z_sample) + + tck, u = interpolate.splprep([x_sample, y_sample, z_sample], s=2, k=2) + x_knots, y_knots, z_knots = interpolate.splev(tck[0], tck) + u_fine = np.linspace(0, 1, number_true_pts) + x_fine, y_fine, z_fine = interpolate.splev(u_fine, tck) + + if debug: + fig2 = plt.figure(2) + ax3d = fig2.add_subplot(111, projection="3d") + ax3d.plot(x_sample, y_sample, z_sample, "r*") + ax3d.plot(x_knots, y_knots, z_knots, "go") + ax3d.plot(x_fine, y_fine, z_fine, "r") + fig2.show() + plt.show() + + x = x_fine.tolist() + z = y_fine.tolist() + y = z_fine.tolist() + + for i in x: + i = round(i) + for i in y: + i = round(i) + for i in z: + i = round(i) + + return x, y, z \ No newline at end of file diff --git a/networks/roads/road.py b/networks/roads/road.py new file mode 100644 index 0000000..f05719a --- /dev/null +++ b/networks/roads/road.py @@ -0,0 +1,7 @@ +class Road: + def __init__(self, coordinates, road_type): + self.coordinates = coordinates # List of tuples (x1, y1, z1) in order + self.road_type = road_type # 'road', 'highway' + + def place_roads(self): + pass \ No newline at end of file