Select Git revision
ConeGenerator.cs
ConeGenerator.cs 1.64 KiB
using System;
using System.Linq;
using UnityEngine;
public class ConeGenerator : ShapeGenerator
{
#region InspectorVariables
[Header("Cone values")]
[Range(0, 100)] public float bottomRadius = 1f;
[Range(0, 100)] public float topRadius = 0f;
public Vector3 topPosition = new Vector3(0, 1f, 0);
[Header("Technical")]
[Range(3, 1000)]
public int sideCount = 500;
#endregion InspectorVariables
#region Implementation
protected override (Vector3[] vertices, int[] triangles) GenerateTopology()
{
Vector3[] top_circle = new[] { topPosition };
Vector3[] bottom_circle = new[] { Vector3.zero };
int[] top_boundary = new int[] { 0 };
int[] bottom_boundary = new int[] { 0 };
if (topRadius > 0f)
{
Vector3[] edge = GetCirclePoints(topRadius, sideCount, topPosition);
top_circle = top_circle
.AppendRange(edge)
.Append(edge[0])
.ToArray();
top_boundary = Enumerable.Range(1, edge.Length).ToArray();
}
if (bottomRadius > 0f)
{
Vector3[] edge = GetCirclePoints(bottomRadius, sideCount);
bottom_circle = bottom_circle
.AppendRange(edge)
.Append(edge[0])
.ToArray();
bottom_boundary = Enumerable.Range(1, edge.Length).ToArray();
}
return CreatePrism(
CreatePlane(top_circle),
CreatePlane(bottom_circle, true),
top_boundary,
bottom_boundary
);
}
#endregion Implementation
}