Skip to content
Snippets Groups Projects
Select Git revision
  • 4789d1f5b5fd8d4406450a18e1c037bf341f72c1
  • master default
  • JS-based-scroll-rendering
  • Paul_Marius_Level
  • Paul_Marius_2
  • Paul_Marius
  • Andi_Mark
  • be-UnityWebView
  • gitignoreFrameitServer
  • ZimmerBSc
  • Bugfix_StageLoading
  • stages
  • MAZIFAU_Experimental
  • tsc/coneworld
  • tsc/fact-interaction
  • marcel
  • MaZiFAU_TopSort
  • mergeHelper
  • zwischenSpeichern
  • tempAndrToMaster
  • SebBranch
  • 3.0
  • v2.1
  • v2.0
  • v1.0
25 results

ConeGenerator.cs

Blame
  • user avatar
    MaZiFAU authored
    4789d1f5
    History
    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
    }