public static bool GenerateStadium(ref ChiselBrushContainer brushContainer, ref ChiselStadiumDefinition definition)
        {
            definition.Validate();
            Vector3[] vertices = null;
            if (!GenerateStadiumVertices(definition, ref vertices))
            {
                return(false);
            }

            brushContainer.EnsureSize(1);

            var surfaceIndices = new int[vertices.Length + 2];

            return(BrushMeshFactory.CreateExtrudedSubMesh(ref brushContainer.brushMeshes[0], definition.sides, surfaceIndices, 0, 1, vertices, definition.surfaceDefinition));
        }
        public static bool GenerateStadium(ref BrushMesh brushMesh, ref ChiselStadiumDefinition definition)
        {
            definition.Validate();
            Vector3[] vertices = null;
            if (!GenerateStadiumVertices(definition, ref vertices))
            {
                brushMesh.Clear();
                return(false);
            }

            var surfaceIndices = new int[vertices.Length + 2];

            if (!BrushMeshFactory.CreateExtrudedSubMesh(ref brushMesh, definition.sides, surfaceIndices, 0, 1, vertices, definition.surfaceDefinition))
            {
                brushMesh.Clear();
                return(false);
            }

            return(true);
        }
示例#3
0
        static void DrawOutline(IChiselHandleRenderer renderer, ChiselStadiumDefinition definition, Vector3[] vertices, LineMode lineMode)
        {
            var sides       = definition.sides;
            var topSides    = Mathf.Max(definition.topSides, 1) + 1;
            var bottomSides = Mathf.Max(definition.bottomSides, 1) + 1;

            var haveRoundedTop    = definition.haveRoundedTop;
            var haveRoundedBottom = definition.haveRoundedBottom;
            var haveCenter        = definition.haveCenter;
            //renderer.DrawLineLoop(vertices,     0, sides, lineMode: lineMode, thickness: kCapLineThickness);
            //renderer.DrawLineLoop(vertices, sides, sides, lineMode: lineMode, thickness: kCapLineThickness);

            var firstTopSide = definition.firstTopSide;
            var lastTopSide  = definition.lastTopSide;

            for (int k = firstTopSide; k <= lastTopSide; k++)
            {
                var sideLine  = !haveRoundedTop || (k == firstTopSide) || (k == lastTopSide);
                var thickness = (sideLine ? kSideLineThickness : kVertLineThickness);
                var dashSize  = (sideLine ? 0                  : kLineDash);
                renderer.DrawLine(vertices[k], vertices[sides + k], lineMode: lineMode, thickness: thickness, dashSize: dashSize);
            }

            var firstBottomSide = definition.firstBottomSide;
            var lastBottomSide  = definition.lastBottomSide;

            for (int k = firstBottomSide; k <= lastBottomSide; k++)
            {
                var sideLine  = haveCenter && (!haveRoundedBottom || (k == firstBottomSide) || (k == lastBottomSide));
                var thickness = (sideLine ? kSideLineThickness : kVertLineThickness);
                var dashSize  = (sideLine ? 0                  : kLineDash);
                renderer.DrawLine(vertices[k], vertices[sides + k], lineMode: lineMode, thickness: thickness, dashSize: dashSize);
            }

            //renderer.DrawLine(vertices[firstBottomSide], vertices[lastBottomSide], lineMode: lineMode, thickness: kVertLineThickness);
            //renderer.DrawLine(vertices[firstTopSide   ], vertices[lastTopSide   ], lineMode: lineMode, thickness: kVertLineThickness);

            //renderer.DrawLine(vertices[sides + firstBottomSide], vertices[sides + lastBottomSide], lineMode: lineMode, thickness: kVertLineThickness);
            //renderer.DrawLine(vertices[sides + firstTopSide   ], vertices[sides + lastTopSide   ], lineMode: lineMode, thickness: kVertLineThickness);
        }
        public static bool GenerateStadiumVertices(ChiselStadiumDefinition definition, ref Vector3[] vertices)
        {
            definition.Validate();

            var topSides    = definition.topSides;
            var bottomSides = definition.bottomSides;
            var sides       = definition.sides;

            var length       = definition.length;
            var topLength    = definition.topLength;
            var bottomLength = definition.bottomLength;
            var diameter     = definition.diameter;
            var radius       = diameter * 0.5f;

            if (vertices == null ||
                vertices.Length != sides * 2)
            {
                vertices = new Vector3[sides * 2];
            }

            var firstTopSide    = definition.firstTopSide;
            var lastTopSide     = definition.lastTopSide;
            var firstBottomSide = definition.firstBottomSide;
            var lastBottomSide  = definition.lastBottomSide;

            var haveCenter = definition.haveCenter;

            int vertexIndex = 0;

            if (!definition.haveRoundedTop)
            {
                vertices[vertexIndex] = new Vector3(-radius, 0, length * -0.5f); vertexIndex++;
                vertices[vertexIndex] = new Vector3(radius, 0, length * -0.5f); vertexIndex++;
            }
            else
            {
                var degreeOffset     = -180.0f * Mathf.Deg2Rad;
                var degreePerSegment = (180.0f / topSides) * Mathf.Deg2Rad;
                var center           = new Vector3(0, 0, (length * -0.5f) + topLength);
                for (int s = 0; s <= topSides; s++)
                {
                    var hRad = (s * degreePerSegment) + degreeOffset;

                    var x = center.x + (math.cos(hRad) * radius);
                    var y = center.y;
                    var z = center.z + (math.sin(hRad) * topLength);

                    vertices[vertexIndex] = new Vector3(x, y, z);
                    vertexIndex++;
                }
            }

            if (!haveCenter)
            {
                vertexIndex--;
            }

            //vertexIndex = definition.firstBottomSide;
            if (!definition.haveRoundedBottom)
            {
                vertices[vertexIndex] = new Vector3(radius, 0, length * 0.5f); vertexIndex++;
                vertices[vertexIndex] = new Vector3(-radius, 0, length * 0.5f); vertexIndex++;
            }
            else
            {
                var degreeOffset     = 0.0f * Mathf.Deg2Rad;
                var degreePerSegment = (180.0f / bottomSides) * Mathf.Deg2Rad;
                var center           = new Vector3(0, 0, (length * 0.5f) - bottomLength);
                for (int s = 0; s <= bottomSides; s++)
                {
                    var hRad = (s * degreePerSegment) + degreeOffset;

                    var x = center.x + (math.cos(hRad) * radius);
                    var y = center.y;
                    var z = center.z + (math.sin(hRad) * bottomLength);

                    vertices[vertexIndex] = new Vector3(x, y, z);
                    vertexIndex++;
                }
            }

            var extrusion = new Vector3(0, 1, 0) * definition.height;

            for (int s = 0; s < sides; s++)
            {
                vertices[s + sides] = vertices[s] + extrusion;
            }
            return(true);
        }