Skip to content

Commit d5227b2

Browse files
committed
initial release
1 parent e05d6f9 commit d5227b2

File tree

85 files changed

+2062
-114
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+2062
-114
lines changed

Editor.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Editor/TrackGeneratorEditor.cs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
using Track;
2+
using UnityEditor;
3+
using UnityEngine;
4+
5+
namespace Editor
6+
{
7+
[CustomEditor(typeof(TrackGenerator), true)]
8+
public class TrackGeneratorEditor : UnityEditor.Editor
9+
{
10+
private TrackGenerator _trackGenerator;
11+
12+
public override void OnInspectorGUI()
13+
{
14+
base.OnInspectorGUI();
15+
16+
_trackGenerator = (TrackGenerator) target;
17+
18+
if (GUILayout.Button(new GUIContent("Generate", "Generate track")))
19+
{
20+
_trackGenerator.Generate();
21+
}
22+
23+
if (GUILayout.Button(new GUIContent("Generate Mesh", "Generate the track mesh")))
24+
{
25+
_trackGenerator.GenerateMesh();
26+
}
27+
}
28+
}
29+
}

Editor/TrackGeneratorEditor.cs.meta

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "rob1997.track-generator.editor",
3+
"rootNamespace": "",
4+
"references": [
5+
"GUID:6b8a2c0415858014b94e09eef3e3fc15"
6+
],
7+
"includePlatforms": [
8+
"Editor"
9+
],
10+
"excludePlatforms": [],
11+
"allowUnsafeCode": false,
12+
"overrideReferences": true,
13+
"precompiledReferences": [],
14+
"autoReferenced": true,
15+
"defineConstraints": [],
16+
"versionDefines": [],
17+
"noEngineReferences": false
18+
}

Editor/rob1997.track-generator.editor.asmdef.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

LICENSE.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 94 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,71 +1,117 @@
1-
# Voronoi
1+
# Track Generator
2+
[![GitHub release](https://img.shields.io/github/v/release/rob1997/TrackGenerator?include_prereleases)](https://github.com/rob1997/TrackGenerator/releases)
23
[![Made with Unity](https://img.shields.io/badge/Made%20with-Unity-57b9d3.svg?style=flat&logo=unity)](https://unity3d.com)
3-
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
4+
[![GitHub license](https://img.shields.io/github/license/rob1997/TrackGenerator)](https://opensource.org/licenses/MIT)
45

5-
A Vornoi Diagram Generator on Unity using C# Job System (DOTS).
6+
A package that Procedurally Generates Closed Tracks from Voronoi Diagrams using C# Jobs System, Splines and Procedural Mesh Generation.
67

78
Unity Version: `2022.3.44f1`
89

9-
![drawing.gif](docs/diagram.png) ![drawing.gif](docs/drawing.gif)
10+
![spline_4](./~docs/spline_4.png)
1011

1112
## Performance
1213

13-
| Diagram Size | Performance in ms |
14-
|--------------|-------------------|
15-
| 5x5 | 0.4 - 0.5 |
16-
| 25x25 | 98 - 100 |
17-
| 50x50 | 1725 - 1800 |
18-
19-
## How to use
20-
#### 1. Install Dependencies
21-
Install dependency package `Burst` and `Collections` Packages from the Package Manager.
22-
#### 2. Import `Voronoi.unitypackage` in your project
23-
Download and import `Voronoi.unitypackage` into your project found [here](https://github.com/rob1997/Voronoi/releases/).
24-
#### 3. Usage
25-
- Create a serialized `VoronoiPlane` object in your MonoBehaviour script and Generate it.
14+
| Track Size/Cells | Performance in ms |
15+
|------------------|-------------------|
16+
| 10 | 2.5 - 3 |
17+
| 25 | 8 - 8.7 |
18+
| 50 | 21 - 23 |
19+
20+
Complexity = 1
21+
Smoothness = 500
22+
23+
## Installation
24+
You can install the package via UPM (Unity Package Manager)
25+
- Open the Unity Package Manager from `Window > Package Manager` and [Import Package from Git URL](https://docs.unity3d.com/Manual/upm-ui-giturl.html).
26+
- Input the following URL: https://github.com/rob1997/TrackGenerator.git
27+
28+
## Configuration
29+
30+
Below are properties of Track Generator that you can configure to generate different types of tracks.
31+
32+
| **Name** | **Type** | **Description** |
33+
|------------|------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|
34+
| Resolution | `int` | Number of triangles that'll be used for mesh generation, the higher the value the smoother the generated mesh. |
35+
| Width | `float` | Width of the generated mesh. |
36+
| Tiling | `Range[0f, 1f] float` | The tiling of the generated mesh relative to the distance of the generated Spline. A value of 1 will tile the texture once per unit of distance. |
37+
| Scale | `float` | Scale of the generated track. |
38+
| Complexity | `Rangle[0f, 1f] float` | The lower the complexity the fewer sides/segments the track will have. |
39+
40+
There are two types of Track Generators available in the package:
41+
42+
### 1. Random Track Generator
43+
44+
Generates a random track based on size (area).
45+
46+
| **Name** | **Type** | **Description** |
47+
|----------|------------------------|-----------------------------------------------------------------------------------------------------|
48+
| Size | `int` | Number of voronoi cells used to generate a random track. The higher the value the bigger the track. |
49+
50+
### 2. Rect Track Generator
51+
52+
Generates a rectangular track based on size (width, height).
53+
54+
| **Name** | **Type** | **Description** |
55+
|----------|--------------|----------------------------------------------------------------------------------------------|
56+
| Size | `Vector2Int` | Determines the dimensions of the track, corresponding to width (Size.x) and height (Size.Y). |
57+
58+
## Setup
59+
60+
- Attach the `RandomTrackGenerator` or `RectTrackGenerator` `MonoBehaviour` to a `GameObject` in the Scene. This will automatically add `SplineContainer`, `MeshRenderer` and `MeshFilter` components to the `GameObject`.
61+
62+
63+
- Assign a Material of your choice to the `MeshRenderer` component. You can find a default road material in the Materials folder in the package.
64+
65+
## Usage
66+
67+
First declare a serialized implementation of `TrackGenerator`
68+
69+
```csharp
70+
[field: SerializeField] public RandomTrackGenerator TrackGenerator { get; private set; }
71+
```
72+
73+
or
74+
2675
```csharp
27-
[field: SerializeField] public VoronoiPlane VoronoiPlane { get; private set; }
76+
[field: SerializeField] public RectTrackGenerator TrackGenerator { get; private set; }
77+
```
78+
79+
then generate track
2880

81+
```csharp
2982
private void Update()
3083
{
31-
// Generate Voronoi Diagram on Space Key Press
84+
// Generate a Random Track on Space Key Press
3285
if (Input.GetKeyDown(KeyCode.Space))
3386
{
34-
VoronoiPlane.Generate(transform);
87+
TrackGenerator.Generate();
3588
}
3689
}
3790
```
38-
- The `VoronoiPlane.Generate()` method takes a `Transform` object as an argument that determines the position and rotation of the diagram, you can also alternatively use `VoronoiDiagram.Generate(Vector3 origin, Vector3 forward, Vector3 up)` where `origin` will be used to position the diagram while `forward` and `up` are used to rotate the diagram.
39-
- You can also use the `VoronoiPlane` object to get the generated Voronoi Diagram Cells.
40-
```csharp
41-
// Get the Voronoi Diagram data
42-
Cell[] cells = VoronoiPlane.Cells;
43-
```
44-
- Each cell contains the center point of each cell as `Cell.Center` and an array of segments and vertices for each cell arranged in a **clockwise** order as `Cell.Segments` and `Cell.Vertices`.
45-
```csharp
46-
Cell[] cells = VoronoiPlane.Cells;
47-
48-
for (int i = 0; i < cells.Length; i++)
49-
{
50-
Cell cell = cells[i];
51-
52-
// Center point of a Voronoi cell
53-
Vector3 center = cell.Center;
54-
55-
// Segments of a single Voronoi cell arranged in a clockwise manner
56-
Segment[] segments = cell.Segments;
57-
58-
// Vertices of a single Voronoi cell arranged in a clockwise manner
59-
float3[] vertices = cell.Vertices;
60-
}
61-
```
62-
- Each segment contains the start and end points of the segment as `Segment.Start` and `Segment.End` ordered clockwise.
63-
- You can also visualize the Voronoi Diagram by either adding a `Drawer` instance in your scene and enabling `VoronoiPlane.drawGizmos` in the inspector or by calling `VoronoiPlane.Draw()` in `OnDrawGizmos`.
91+
The `TrackGenerator.Generate()` method generates a random track based on the `transform` of the `GameObject`.
92+
93+
You can also alternatively use the Generate Button in the Inspector.
94+
95+
![spline_0](./~docs/spline_0.png)
96+
97+
You can use the Spline Editor tool to edit any generated Track Spline in the Scene View. Once you're done editing the Spline you can press the `Generate Mesh` button to generate a new mesh based on the edited Spline.
98+
99+
![spline_1](./~docs/spline_1.png)
100+
101+
![spline_2](./~docs/spline_2.png)
102+
103+
![spline_3](./~docs/spline_3.png)
104+
105+
You can get the generated Vertices and Spline via `TrackGenerator.Spline` and `TrackGenerator.Vertices`.
106+
107+
## Contributing
108+
109+
If you'd like to contribute to the project, you can fork the repository and create a pull request. You can also create an issue if you find any bugs or have any feature requests.
64110

65111
---
66112

67-
**⚠️Caution⚠️**
113+
##### **⚠️Caution⚠️**
68114

69-
As you go higher up in diagram size significantly (> 2500 cells | 50x50) you'll start to get a specific exception `Next segment not unique` more and more frequently which happens due to floating point precision. In cases where you need a significantly large diagram perhaps consider more than one adjacent diagrams or consider refactoring the source code to use `double` and `double3` instead of `float` and `float3`.
115+
As you go higher up in track size significantly you'll start to get a specific exception `Next segment not unique` more and more frequently which happens due to floating point precision. In cases where you need a significantly large track perhaps consider increasing scale instead. More on this [here](Runtime/Scripts/Voronoi/README.md#caution).
70116

71117
---

README.md.meta

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Materials.meta

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)