Skip to content
This repository has been archived by the owner on Feb 10, 2021. It is now read-only.

Commit

Permalink
Added resolution multiplier option to roads and intersections
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcusElg committed Jun 27, 2019
1 parent 9bf2954 commit 5bfa769
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 5 deletions.
3 changes: 2 additions & 1 deletion Resources/Scripts/Intersections/Intersection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class Intersection : MonoBehaviour
public SerializedObject settings;
public GameObject objectToMove;
public bool stretchTexture = false;
public float resolutionMultiplier = 1;

public bool generateBridge = true;
public BridgeSettings bridgeSettings = new BridgeSettings();
Expand Down Expand Up @@ -253,7 +254,7 @@ private void GenerateNormalMesh()
return;
}

float segments = totalLengths[i] * settings.FindProperty("resolution").floatValue * 5;
float segments = totalLengths[i] * settings.FindProperty("resolution").floatValue * resolutionMultiplier * 5;
segments = Mathf.Max(3, segments);
float distancePerSegment = 1f / segments;

Expand Down
2 changes: 2 additions & 0 deletions Resources/Scripts/Intersections/IntersectionEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public override void OnInspectorGUI()
intersection.overlayMaterial = (Material)EditorGUILayout.ObjectField("Overlay Material", intersection.overlayMaterial, typeof(Material), false);
intersection.connectionBaseMaterial = (Material)EditorGUILayout.ObjectField("Connection Base Material", intersection.connectionBaseMaterial, typeof(Material), false);
intersection.connectionOverlayMaterial = (Material)EditorGUILayout.ObjectField("Connection Overlay Material", intersection.connectionOverlayMaterial, typeof(Material), false);
intersection.resolutionMultiplier = Mathf.Clamp(EditorGUILayout.FloatField("Resoltion Multiplier", intersection.resolutionMultiplier), 0.01f, 10f);

if (EditorGUI.EndChangeCheck() == true)
{
Expand All @@ -76,6 +77,7 @@ public override void OnInspectorGUI()
intersection.physicMaterial = (PhysicMaterial)EditorGUILayout.ObjectField("Physics Material", intersection.physicMaterial, typeof(PhysicMaterial), false);
intersection.yOffset = Mathf.Max(0.01f, EditorGUILayout.FloatField("Y Offset", intersection.yOffset));
intersection.stretchTexture = GUILayout.Toggle(intersection.stretchTexture, "Stretch Texture");
intersection.resolutionMultiplier = Mathf.Clamp(EditorGUILayout.FloatField("Resoltion Multiplier", intersection.resolutionMultiplier), 0.01f, 10f);

if (EditorGUI.EndChangeCheck() == true)
{
Expand Down
7 changes: 4 additions & 3 deletions Resources/Scripts/Intersections/Roundabout.cs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ private static void AddConnectionExtraMeshes(Intersection intersection, ref List

private static void AddNewRoadConnectionVertices(Intersection intersection, ref List<Vector3> vertices, ref List<Vector2> uvs, ref List<Vector2> uvs2, ref List<Vector3> bridgeVertices, ref List<int> bridgeTriangles, ref List<Vector2> bridgeUvs, int i, Vector3 centerPoint, List<int> nearestLeftPoints, List<int> nearestRightPoints, ref int addedVertices, List<RoundaboutExtraMesh> leftExtraMeshes, List<RoundaboutExtraMesh> rightExtraMeshes, ref int actualSegments, ref int addedBridgeVertices)
{
int segments = (int)Mathf.Max(3, intersection.settings.FindProperty("resolution").floatValue * Vector3.Distance(intersection.connections[i].lastPoint, centerPoint + intersection.transform.position - new Vector3(0, intersection.yOffset, 0)) * 10);
int segments = (int)Mathf.Max(3, intersection.settings.FindProperty("resolution").floatValue * intersection.resolutionMultiplier * Vector3.Distance(intersection.connections[i].lastPoint, centerPoint + intersection.transform.position - new Vector3(0, intersection.yOffset, 0)) * 10);
float distancePerSegment = 1f / segments;
float degreesStartInner = Quaternion.LookRotation(vertices[nearestLeftPoints[i] + 1]).eulerAngles.y;
float degreesEndInner = Quaternion.LookRotation(vertices[nearestRightPoints[i] + 1]).eulerAngles.y;
Expand Down Expand Up @@ -592,7 +592,7 @@ private static void GenerateCapFlipped(ref List<Vector3> bridgeVertices, ref Lis

private static void CreateRoundaboutVertices(Intersection intersection, ref List<Vector3> vertices, ref List<Vector2> uvs, ref List<Vector2> uvs2)
{
int segments = (int)Mathf.Max(6, intersection.settings.FindProperty("resolution").floatValue * intersection.roundaboutRadius * 30f);
int segments = (int)Mathf.Max(6, intersection.settings.FindProperty("resolution").floatValue * intersection.resolutionMultiplier * intersection.roundaboutRadius * 30f);
float degreesPerSegment = 1f / segments;
float textureRepeations = Mathf.PI * intersection.roundaboutRadius * intersection.textureTilingY * 0.5f;

Expand Down Expand Up @@ -670,7 +670,8 @@ private static void CreateCenterExtraMeshes(Intersection intersection)
{
List<ExtraMesh> centerExtraMeshes = new List<ExtraMesh>();
List<int> indexes = new List<int>();
int segments = (int)Mathf.Max(6, intersection.settings.FindProperty("resolution").floatValue * intersection.roundaboutRadius * 30f);
int segments = (int)Mathf.Max(6, intersection.settings.FindProperty("resolution").floatValue * intersection.resolutionMultiplier * intersection.roundaboutRadius * 30f);

float degreesPerSegment = 1f / segments;
float textureRepeations = Mathf.PI * intersection.roundaboutRadius * intersection.textureTilingY * 0.5f;

Expand Down
3 changes: 2 additions & 1 deletion Resources/Scripts/Road/RoadCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ public class RoadCreator : MonoBehaviour

public SerializedObject settings;
public Preset segmentPreset;
public float resolutionMultiplier = 1;
public GameObject objectToMove = null;
public GameObject extraObjectToMove = null;
private bool mouseDown;
Expand Down Expand Up @@ -1062,7 +1063,7 @@ public Vector3[] CalculatePoints(Transform segment)
}

float distance = Misc.CalculateDistance(segment.GetChild(0).GetChild(0).position, segment.GetChild(0).GetChild(1).position, segment.GetChild(0).GetChild(2).position);
float divisions = settings.FindProperty("resolution").floatValue * 4 * distance;
float divisions = settings.FindProperty("resolution").floatValue * resolutionMultiplier * 4 * distance;
divisions = Mathf.Max(3, divisions);
List<Vector3> points = new List<Vector3>();
float distancePerDivision = 1 / divisions;
Expand Down
1 change: 1 addition & 0 deletions Resources/Scripts/Road/RoadEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public override void OnInspectorGUI()
EditorGUI.BeginChangeCheck();
roadCreator.heightOffset = Mathf.Max(0, EditorGUILayout.FloatField("Y Offset", roadCreator.heightOffset));
roadCreator.segmentPreset = (Preset)EditorGUILayout.ObjectField("Segment Preset", roadCreator.segmentPreset, typeof(Preset), false);
roadCreator.resolutionMultiplier = Mathf.Clamp(EditorGUILayout.FloatField("Resoltion Multiplier", roadCreator.resolutionMultiplier), 0.01f, 10f);
roadCreator.createIntersections = EditorGUILayout.Toggle("Create Intersections", roadCreator.createIntersections);

if (EditorGUI.EndChangeCheck() == true)
Expand Down

0 comments on commit 5bfa769

Please sign in to comment.