// // // public static Mesh BuildHemisphere(Axis axis, AxisSide axisSide, float radius, int sides) { if (radius > 0.02f) { // Works great up to radius = 0.02, under this limit normal issues appear MeshBuilder builder = new MeshBuilder(); PointList points = CreatePolygon(axis, radius, sides); int n = sides / 4; PointList[] pointsM = new PointList[n + 1]; pointsM [0] = points; Vector3 v = Vector(axis); float indexToRadAngle = Mathf.PI * 0.5f / n; if (axisSide == AxisSide.Positive) { // First Hemisphere for (int i = 1; i <= n; i++) { float angle = i * indexToRadAngle; pointsM [i] = points.Scale(Mathf.Cos(angle)).Translate(radius * Mathf.Sin(angle) * v); builder.Cap(pointsM [i - 1].Bridge(pointsM [i], PointList.BridgeMode.CloseReuse)); } } else { // Second Hemisphere for (int i = 1; i <= n; i++) { float angle = -i * indexToRadAngle; pointsM [i] = points.Scale(Mathf.Cos(angle)).Translate(radius * Mathf.Sin(angle) * v); builder.Cap(pointsM [i].Bridge(pointsM [i - 1], PointList.BridgeMode.CloseReuse)); } } return(builder.Build()); } else { Mesh mesh = BuildHemisphere(axis, axisSide, 1.0f, sides); MeshAdapter.ScaleVertices(ref mesh, new Vector3(radius, radius, radius)); return(mesh); } }
private static PointList CreateXZRectangle(float xSize, float zSize, AxisSide axisSide, float axisCoord) { PointList result = new PointList(); float x = xSize * 0.5f; float z = zSize * 0.5f; if (axisSide == AxisSide.Negative) { result.Add(-x, axisCoord, z); result.Add(-x, axisCoord, -z); result.Add(x, axisCoord, -z); result.Add(x, axisCoord, z); } else { result.Add(-x, axisCoord, z); result.Add(x, axisCoord, z); result.Add(x, axisCoord, -z); result.Add(-x, axisCoord, -z); } return(result); }
private static PointList CreateXZRoundRectangle(float xSize, float zSize, float radius, int cornerSides, AxisSide axisSide, float axisCoord) { PointList result = new PointList(); float x = xSize * 0.5f - radius; float z = zSize * 0.5f - radius; float PI_2 = Mathf.PI * 0.5f; float indexToAngle = PI_2 / cornerSides; if (axisSide == AxisSide.Negative) { // Corner 1 for (int i = 0; i < cornerSides + 1; i++) { float angle = PI_2 + i * indexToAngle; result.Add(-x + radius * Mathf.Cos(angle), axisCoord, z + radius * Mathf.Sin(angle)); } // Corner 2 for (int i = 0; i < cornerSides + 1; i++) { float angle = Mathf.PI + i * indexToAngle; result.Add(-x + radius * Mathf.Cos(angle), axisCoord, -z + radius * Mathf.Sin(angle)); } // Corner 3 for (int i = 0; i < cornerSides + 1; i++) { float angle = -PI_2 + i * indexToAngle; result.Add(x + radius * Mathf.Cos(angle), axisCoord, -z + radius * Mathf.Sin(angle)); } // Corner 4 for (int i = 0; i < cornerSides + 1; i++) { float angle = i * indexToAngle; result.Add(x + radius * Mathf.Cos(angle), axisCoord, z + radius * Mathf.Sin(angle)); } } else { // Corner 1 for (int i = 0; i < cornerSides + 1; i++) { float angle = Mathf.PI - i * indexToAngle; result.Add(-x + radius * Mathf.Cos(angle), axisCoord, z + radius * Mathf.Sin(angle)); } // Corner 4 for (int i = 0; i < cornerSides + 1; i++) { float angle = PI_2 - i * indexToAngle; result.Add(x + radius * Mathf.Cos(angle), axisCoord, z + radius * Mathf.Sin(angle)); } // Corner 3 for (int i = 0; i < cornerSides + 1; i++) { float angle = -i * indexToAngle; result.Add(x + radius * Mathf.Cos(angle), axisCoord, -z + radius * Mathf.Sin(angle)); } // Corner 2 for (int i = 0; i < cornerSides + 1; i++) { float angle = -PI_2 - i * indexToAngle; result.Add(-x + radius * Mathf.Cos(angle), axisCoord, -z + radius * Mathf.Sin(angle)); } } return(result); }