static void DrawOutline(ChiselSphereDefinition definition, Vector3[] vertices, LineMode lineMode)
        {
            var sides = definition.horizontalSegments;

            var extraVertices = 2;
            var bottomVertex  = 1;
            var topVertex     = 0;

            var rings = (vertices.Length - extraVertices) / sides;

            var prevColor = UnityEditor.Handles.color;
            var color     = prevColor;

            color.a *= 0.6f;

            UnityEditor.Handles.color = color;
            for (int i = 0, j = extraVertices; i < rings; i++, j += sides)
            {
                ChiselOutlineRenderer.DrawLineLoop(vertices, j, sides, lineMode: lineMode, thickness: kHorzLineThickness, dashSize: kLineDash);
            }

            for (int k = 0; k < sides; k++)
            {
                ChiselOutlineRenderer.DrawLine(vertices[topVertex], vertices[extraVertices + k], lineMode: lineMode, thickness: kVertLineThickness);
                for (int i = 0, j = extraVertices; i < rings - 1; i++, j += sides)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[j + k], vertices[j + k + sides], lineMode: lineMode, thickness: kVertLineThickness);
                }
                ChiselOutlineRenderer.DrawLine(vertices[bottomVertex], vertices[extraVertices + k + ((rings - 1) * sides)], lineMode: lineMode, thickness: kVertLineThickness);
            }
            UnityEditor.Handles.color = prevColor;
        }
Esempio n. 2
0
        static void DrawOutline(ChiselCapsuleDefinition definition, Vector3[] vertices, LineMode lineMode)
        {
            var sides = definition.sides;

            // TODO: share this logic with GenerateCapsuleVertices

            var topHemisphere    = definition.haveRoundedTop;
            var bottomHemisphere = definition.haveRoundedBottom;
            var topSegments      = topHemisphere    ? definition.topSegments    : 0;
            var bottomSegments   = bottomHemisphere ? definition.bottomSegments : 0;

            var extraVertices = definition.extraVertexCount;
            var bottomVertex  = definition.bottomVertex;
            var topVertex     = definition.topVertex;

            var rings      = definition.ringCount;
            var bottomRing = (bottomHemisphere) ? (rings - bottomSegments) : rings - 1;
            var topRing    = (topHemisphere) ? (topSegments - 1) : 0;

            var prevColor = UnityEditor.Handles.color;
            var color     = prevColor;

            color.a *= 0.6f;

            for (int i = 0, j = extraVertices; i < rings; i++, j += sides)
            {
                if ((!definition.haveRoundedTop && i == topRing) ||
                    (!definition.haveRoundedBottom && i == bottomRing))
                {
                    continue;
                }
                bool isCapRing = (i == topRing || i == bottomRing);
                if (isCapRing)
                {
                    continue;
                }
                UnityEditor.Handles.color = (isCapRing ? prevColor : color);
                ChiselOutlineRenderer.DrawLineLoop(vertices, j, sides, lineMode: lineMode, thickness: (isCapRing ? kCapLineThickness : kHorzLineThickness), dashSize: (isCapRing ? 0 : kLineDash));
            }

            UnityEditor.Handles.color = color;
            for (int k = 0; k < sides; k++)
            {
                if (topHemisphere)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[topVertex], vertices[extraVertices + k], lineMode: lineMode, thickness: kVertLineThickness);
                }
                for (int i = 0, j = extraVertices; i < rings - 1; i++, j += sides)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[j + k], vertices[j + k + sides], lineMode: lineMode, thickness: kVertLineThickness);
                }
                if (bottomHemisphere)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[bottomVertex], vertices[extraVertices + k + ((rings - 1) * sides)], lineMode: lineMode, thickness: kVertLineThickness);
                }
            }
            UnityEditor.Handles.color = prevColor;
        }
Esempio n. 3
0
        static void DrawOutline(ChiselTorusDefinition definition, Vector3[] vertices, LineMode lineMode)
        {
            //var baseColor		= UnityEditor.Handles.yAxisColor;
            //var isDisabled		= UnitySceneExtensions.Handles.disabled;
            var normal = Vector3.up;

            var horzSegments = definition.horizontalSegments;
            var vertSegments = definition.verticalSegments;

            if (definition.totalAngle != 360)
            {
                horzSegments++;
            }

            var prevColor = UnityEditor.Handles.color;

            prevColor.a *= 0.8f;
            var color = prevColor;

            color.a *= 0.6f;

            UnityEditor.Handles.color = color;
            for (int i = 0, j = 0; i < horzSegments; i++, j += vertSegments)
            {
                ChiselOutlineRenderer.DrawLineLoop(vertices, j, vertSegments, lineMode: lineMode, thickness: kVertLineThickness);
            }

            for (int k = 0; k < vertSegments; k++)
            {
                for (int i = 0, j = 0; i < horzSegments - 1; i++, j += vertSegments)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[j + k], vertices[j + k + vertSegments], lineMode: lineMode, thickness: kHorzLineThickness);
                }
            }
            if (definition.totalAngle == 360)
            {
                for (int k = 0; k < vertSegments; k++)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[k], vertices[k + ((horzSegments - 1) * vertSegments)], lineMode: lineMode, thickness: kHorzLineThickness);
                }
            }
            UnityEditor.Handles.color = prevColor;
        }
Esempio n. 4
0
        static void DrawOutline(ChiselHemisphereDefinition definition, Vector3[] vertices, LineMode lineMode)
        {
            //var baseColor		= UnityEditor.Handles.yAxisColor;
            //var isDisabled		= UnitySceneExtensions.Handles.disabled;
            //var normal			= Vector3.up;
            var sides = definition.horizontalSegments;

            var topSegments   = Mathf.Max(definition.verticalSegments, 0);
            var bottomCap     = false;
            var topCap        = (topSegments != 0);
            var extraVertices = ((topCap) ? 1 : 0) + ((bottomCap) ? 1 : 0);
            var bottomVertex  = 0;
            //var topVertex		= (bottomCap) ? 1 : 0;

            var rings      = (vertices.Length - extraVertices) / sides;
            var bottomRing = 0;

            var prevColor = UnityEditor.Handles.color;
            var color     = prevColor;

            color.a *= 0.6f;

            for (int i = 0, j = extraVertices; i < rings; i++, j += sides)
            {
                UnityEditor.Handles.color = ((i == bottomRing) ? prevColor : color);
                ChiselOutlineRenderer.DrawLineLoop(vertices, j, sides, lineMode: lineMode, thickness: ((i == bottomRing) ? kCapLineThickness : kHorzLineThickness), dashSize: ((i == bottomRing) ? 0 : kLineDash));
            }

            UnityEditor.Handles.color = color;
            for (int k = 0; k < sides; k++)
            {
                for (int i = 0, j = extraVertices; i < rings - 1; i++, j += sides)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[j + k], vertices[j + k + sides], lineMode: lineMode, thickness: kVertLineThickness);
                }
                if (topCap)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[bottomVertex], vertices[extraVertices + k + ((rings - 1) * sides)], lineMode: lineMode, thickness: kVertLineThickness);
                }
            }
            UnityEditor.Handles.color = prevColor;
        }
        static Vector3[] vertices = null; // TODO: store this per instance? or just allocate every frame?

        protected override void OnScene(ChiselCapsule generator)
        {
            var baseColor    = UnityEditor.Handles.yAxisColor;
            var isDisabled   = UnitySceneExtensions.SceneHandles.disabled;
            var focusControl = UnitySceneExtensions.SceneHandleUtility.focusControl;
            var normal       = Vector3.up;

            if (!BrushMeshFactory.GenerateCapsuleVertices(ref generator.definition, ref vertices))
            {
                return;
            }

            UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, false, false, isDisabled);
            DrawOutline(generator.definition, vertices, lineMode: LineMode.ZTest);

            UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, false, true, isDisabled);
            DrawOutline(generator.definition, vertices, lineMode: LineMode.NoZTest);


            var topLoopID    = GUIUtility.GetControlID(s_TopLoopHash, FocusType.Keyboard);
            var bottomLoopID = GUIUtility.GetControlID(s_BottomLoopHash, FocusType.Keyboard);


            var topPoint    = normal * (generator.definition.offsetY + generator.Height);
            var bottomPoint = normal * (generator.definition.offsetY);
            var middlePoint = normal * (generator.definition.offsetY + (generator.Height * 0.5f));
            var radius2D    = new Vector2(generator.definition.diameterX, generator.definition.diameterZ) * 0.5f;

            var topHeight    = generator.definition.topHeight;
            var bottomHeight = generator.definition.bottomHeight;

            var maxTopHeight    = generator.definition.height - bottomHeight;
            var maxBottomHeight = generator.definition.height - topHeight;

            if (generator.Height < 0)
            {
                normal = -normal;
            }

            EditorGUI.BeginChangeCheck();
            {
                UnityEditor.Handles.color = baseColor;
                // TODO: make it possible to (optionally) size differently in x & z
                radius2D.x = UnitySceneExtensions.SceneHandles.RadiusHandle(normal, middlePoint, radius2D.x);

                var topId = GUIUtility.GetControlID(s_TopHash, FocusType.Passive);
                {
                    var isTopBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(topPoint, normal);
                    var topHasFocus    = (focusControl == topId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, topHasFocus, isTopBackfaced, isDisabled);
                    topPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(topId, topPoint, normal);

                    var topLoopHasFocus = (topHasFocus && !generator.HaveRoundedTop) || (focusControl == topLoopID);

                    var thickness = topLoopHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, topLoopHasFocus, true, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(vertices, generator.definition.topVertexOffset, generator.definition.sides, lineMode: LineMode.NoZTest, thickness: thickness);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, topLoopHasFocus, false, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(vertices, generator.definition.topVertexOffset, generator.definition.sides, lineMode: LineMode.ZTest, thickness: thickness);

                    {
                        var prevGUIChanged = GUI.changed;
                        for (int j = generator.definition.sides - 1, i = 0; i < generator.definition.sides; j = i, i++)
                        {
                            GUI.changed = false;
                            var from       = vertices[j + generator.definition.topVertexOffset];
                            var to         = vertices[i + generator.definition.topVertexOffset];
                            var edgeOffset = UnitySceneExtensions.SceneHandles.Edge1DHandleOffset(topLoopID, UnitySceneExtensions.Axis.Y, from, to, capFunction: null);
                            if (GUI.changed)
                            {
                                topHeight      = Mathf.Clamp(topHeight - edgeOffset, 0, maxTopHeight);
                                prevGUIChanged = true;
                            }
                        }
                        GUI.changed = prevGUIChanged;
                    }
                }

                var bottomId = GUIUtility.GetControlID(s_BottomHash, FocusType.Passive);
                {
                    var isBottomBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(bottomPoint, -normal);
                    var bottomHasFocus    = (focusControl == bottomId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, bottomHasFocus, isBottomBackfaced, isDisabled);
                    bottomPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(bottomId, bottomPoint, -normal);

                    var bottomLoopHasFocus = (bottomHasFocus && !generator.HaveRoundedBottom) || (focusControl == bottomLoopID);

                    var thickness = bottomLoopHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, bottomLoopHasFocus, true, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(vertices, generator.definition.bottomVertexOffset, generator.definition.sides, lineMode: LineMode.NoZTest, thickness: thickness);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, bottomLoopHasFocus, false, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(vertices, generator.definition.bottomVertexOffset, generator.definition.sides, lineMode: LineMode.ZTest, thickness: thickness);

                    {
                        var prevGUIChanged = GUI.changed;
                        for (int j = generator.definition.sides - 1, i = 0; i < generator.definition.sides; j = i, i++)
                        {
                            GUI.changed = false;
                            var from       = vertices[j + generator.definition.bottomVertexOffset];
                            var to         = vertices[i + generator.definition.bottomVertexOffset];
                            var edgeOffset = UnitySceneExtensions.SceneHandles.Edge1DHandleOffset(bottomLoopID, UnitySceneExtensions.Axis.Y, from, to, capFunction: null);
                            if (GUI.changed)
                            {
                                bottomHeight   = Mathf.Clamp(bottomHeight + edgeOffset, 0, maxBottomHeight);
                                prevGUIChanged = true;
                            }
                        }
                        GUI.changed = prevGUIChanged;
                    }
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Modified " + generator.NodeTypeName);
                generator.definition.diameterX    = radius2D.x * 2.0f;
                generator.definition.height       = topPoint.y - bottomPoint.y;
                generator.definition.diameterZ    = radius2D.x * 2.0f;
                generator.definition.offsetY      = bottomPoint.y;
                generator.definition.topHeight    = topHeight;
                generator.definition.bottomHeight = bottomHeight;
                generator.OnValidate();
                // TODO: handle sizing down (needs to modify transformation?)
            }
        }
Esempio n. 6
0
            public void ShowInstance()
            {
                var tempTop    = generator.Top;
                var tempBottom = generator.Bottom;
                var sides      = generator.Sides;


                var topId    = GUIUtility.GetControlID(s_TopHash, FocusType.Passive);
                var bottomId = GUIUtility.GetControlID(s_BottomHash, FocusType.Passive);

                var focusControl = UnitySceneExtensions.SceneHandleUtility.focusControl;
                var color        = UnityEditor.Handles.yAxisColor;
                var isDisabled   = UnitySceneExtensions.SceneHandles.disabled;

                if (!generator.IsEllipsoid)
                {
                    tempTop.diameterZ = tempTop.diameterX; tempBottom.diameterZ = tempBottom.diameterX;
                }

                EditorGUI.BeginChangeCheck();
                {
                    switch (generator.Type)
                    {
                    case CylinderShapeType.Cylinder:
                    {
                        if (generator.IsEllipsoid)
                        {
                            UnitySceneExtensions.SceneHandles.Radius2DHandle(topPoint, normal, ref bottomXVector, ref bottomZVector, renderDisc: false);
                            UnitySceneExtensions.SceneHandles.Radius2DHandle(bottomPoint, -normal, ref bottomXVector, ref bottomZVector, renderDisc: false);
                        }
                        else
                        {
                            bottomXVector = UnitySceneExtensions.SceneHandles.Radius2DHandle(topPoint, normal, bottomXVector, renderDisc: false);
                            bottomXVector = UnitySceneExtensions.SceneHandles.Radius2DHandle(bottomPoint, -normal, bottomXVector, renderDisc: false);

                            bottomZVector = bottomXVector;
                        }
                        topXVector        = bottomXVector;
                        topZVector        = bottomZVector;
                        tempTop.diameterX = tempBottom.diameterX;
                        tempTop.diameterZ = tempBottom.diameterZ;
                        break;
                    }

                    case CylinderShapeType.ConicalFrustum:
                    {
                        if (generator.IsEllipsoid)
                        {
                            UnitySceneExtensions.SceneHandles.Radius2DHandle(topPoint, normal, ref topXVector, ref topZVector, renderDisc: false);
                            UnitySceneExtensions.SceneHandles.Radius2DHandle(bottomPoint, -normal, ref bottomXVector, ref bottomZVector, renderDisc: false);
                        }
                        else
                        {
                            UnitySceneExtensions.SceneHandles.Radius2DHandle(topPoint, normal, ref topXVector, ref topXVector, renderDisc: false);
                            UnitySceneExtensions.SceneHandles.Radius2DHandle(bottomPoint, -normal, ref bottomXVector, ref bottomXVector, renderDisc: false);

                            bottomXVector = UnitySceneExtensions.SceneHandles.Radius2DHandle(bottomPoint, -normal, bottomXVector, renderDisc: false);
                            bottomZVector = bottomXVector;
                        }
                        break;
                    }

                    case CylinderShapeType.Cone:
                    {
                        if (generator.IsEllipsoid)
                        {
                            UnitySceneExtensions.SceneHandles.Radius2DHandle(bottomPoint, -normal, ref bottomXVector, ref bottomZVector, renderDisc: false);
                        }
                        else
                        {
                            bottomXVector = UnitySceneExtensions.SceneHandles.Radius2DHandle(bottomPoint, -normal, bottomXVector, renderDisc: false);
                            bottomZVector = bottomXVector;
                        }
                        topXVector        = bottomXVector;
                        topZVector        = bottomZVector;
                        tempTop.diameterX = 0;
                        tempTop.diameterZ = 0;
                        break;
                    }
                    }


                    // TODO: add cylinder horizon "side-lines"
                }
                if (EditorGUI.EndChangeCheck())
                {
                    topZVector.y = 0;
                    topXVector.y = 0;

                    bottomZVector.y = 0;
                    bottomXVector.y = 0;

                    Undo.RecordObject(generator, "Modified " + generator.NodeTypeName);
                    if (!generator.IsEllipsoid)
                    {
                        if (prevBottomXVector != bottomXVector)
                        {
                            bottomZVector = Vector3.Cross(normal, bottomXVector.normalized) * bottomXVector.magnitude;
                        }
                        if (prevTopXVector != topXVector)
                        {
                            topZVector = Vector3.Cross(normal, topXVector.normalized) * topXVector.magnitude;
                        }
                    }

                    if (prevTopXVector != topXVector)
                    {
                        generator.Rotation = Utilities.GeometryMath.SignedAngle(Vector3.right, topXVector.normalized, Vector3.up);
                    }
                    else if (prevBottomXVector != bottomXVector)
                    {
                        generator.Rotation = Utilities.GeometryMath.SignedAngle(Vector3.right, bottomXVector.normalized, Vector3.up);
                    }

                    if (generator.IsEllipsoid)
                    {
                        generator.BottomDiameterX = bottomXVector.magnitude * 2.0f;
                        generator.BottomDiameterZ = bottomZVector.magnitude * 2.0f;

                        generator.TopDiameterX = topXVector.magnitude * 2.0f;
                        generator.TopDiameterZ = topZVector.magnitude * 2.0f;
                    }
                    else
                    {
                        if (prevBottomZVector != bottomZVector)
                        {
                            generator.BottomDiameterX = bottomZVector.magnitude * 2.0f;
                            generator.BottomDiameterZ = bottomZVector.magnitude * 2.0f;
                        }
                        else
                        {
                            generator.BottomDiameterX = bottomXVector.magnitude * 2.0f;
                            generator.BottomDiameterZ = bottomXVector.magnitude * 2.0f;
                        }

                        if (prevTopZVector != topZVector)
                        {
                            generator.TopDiameterX = topZVector.magnitude * 2.0f;
                            generator.TopDiameterZ = topZVector.magnitude * 2.0f;
                        }
                        else
                        {
                            generator.TopDiameterX = topXVector.magnitude * 2.0f;
                            generator.TopDiameterZ = topXVector.magnitude * 2.0f;
                        }
                    }
                }

                const float kLineDash                 = 2.0f;
                const float kLineThickness            = 1.0f;
                const float kCircleThickness          = 1.5f;
                const float kCapLineThickness         = 2.0f;
                const float kCapLineThicknessSelected = 2.5f;

                const int kMaxOutlineSides = 32;
                const int kMinimumSides    = 8;

                var baseColor = UnityEditor.Handles.yAxisColor;

                BrushMeshFactory.GetConicalFrustumVertices(tempBottom, tempTop, generator.Rotation, sides, ref vertices);

                if (generator.TopHeight < generator.BottomHeight)
                {
                    normal = -normal;
                }

                var isTopBackfaced = IsSufaceBackFaced(topPoint, normal);
                var topHasFocus    = (focusControl == topId);
                var topThickness   = topHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                var isBottomBackfaced = IsSufaceBackFaced(bottomPoint, -normal);
                var bottomHasFocus    = (focusControl == bottomId);
                var bottomThickness   = bottomHasFocus ? kCapLineThicknessSelected : kCapLineThickness;


                UnityEditor.Handles.color = GetColorForState(baseColor, bottomHasFocus, isBottomBackfaced, isDisabled);
                ChiselOutlineRenderer.DrawLineLoop(vertices, 0, sides, thickness: bottomThickness);

                UnityEditor.Handles.color = GetColorForState(baseColor, topHasFocus, isTopBackfaced, isDisabled);
                ChiselOutlineRenderer.DrawLineLoop(vertices, sides, sides, thickness: topThickness);

                UnityEditor.Handles.color = GetColorForState(baseColor, false, false, isDisabled);
                for (int i = 0; i < sides; i++)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[i], vertices[i + sides], lineMode: LineMode.ZTest, thickness: kLineThickness);
                }

                UnityEditor.Handles.color = GetColorForState(baseColor, false, true, isDisabled);
                for (int i = 0; i < sides; i++)
                {
                    ChiselOutlineRenderer.DrawLine(vertices[i], vertices[i + sides], lineMode: LineMode.NoZTest, thickness: kLineThickness);
                }

                /*
                 * var point0    = camera.WorldToScreenPoint(topPoint);
                 * var direction = camera.ScreenToWorldPoint(point0 - Vector3.right);
                 * var point1	  = camera.WorldToScreenPoint(point0 - (direction * tempTop.diameterX));
                 * var size	  = Mathf.Max(point1.x - point0.x, point1.y - point0.y);
                 */
                // TODO: figure out how to reduce the sides of the circle depending on radius & distance
                int outlineSides = kMaxOutlineSides;

                if (sides <= kMinimumSides)
                {
                    BrushMeshFactory.GetConicalFrustumVertices(tempBottom, tempTop, generator.Rotation, outlineSides, ref dottedVertices);

                    UnityEditor.Handles.color = GetColorForState(baseColor, topHasFocus, false, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(dottedVertices, outlineSides, outlineSides, lineMode: LineMode.ZTest, thickness: kCircleThickness, dashSize: kLineDash);

                    UnityEditor.Handles.color = GetColorForState(baseColor, topHasFocus, true, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(dottedVertices, outlineSides, outlineSides, lineMode: LineMode.NoZTest, thickness: kCircleThickness, dashSize: kLineDash);

                    UnityEditor.Handles.color = GetColorForState(baseColor, bottomHasFocus, false, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(dottedVertices, 0, outlineSides, lineMode: LineMode.ZTest, thickness: kCircleThickness, dashSize: kLineDash);

                    UnityEditor.Handles.color = GetColorForState(baseColor, bottomHasFocus, true, isDisabled);
                    ChiselOutlineRenderer.DrawLineLoop(dottedVertices, 0, outlineSides, lineMode: LineMode.NoZTest, thickness: kCircleThickness, dashSize: kLineDash);
                }

                EditorGUI.BeginChangeCheck();
                {
                    UnityEditor.Handles.color = GetColorForState(baseColor, bottomHasFocus, isBottomBackfaced, isDisabled);
                    bottomPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(bottomId, bottomPoint, -normal);

                    UnityEditor.Handles.color = GetColorForState(baseColor, topHasFocus, isTopBackfaced, isDisabled);
                    topPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(topId, topPoint, normal);
                }
                if (EditorGUI.EndChangeCheck())
                {
                    Undo.RecordObject(generator, "Modified " + generator.NodeTypeName);
                    generator.TopHeight    = Vector3.Dot(Vector3.up, topPoint);
                    generator.BottomHeight = Vector3.Dot(Vector3.up, bottomPoint);
                }
            }
        protected override void OnScene(ChiselStadium generator)
        {
            var baseColor     = UnityEditor.Handles.yAxisColor;
            var isDisabled    = UnitySceneExtensions.SceneHandles.disabled;
            var focusControl  = UnitySceneExtensions.SceneHandleUtility.focusControl;
            var upVector      = Vector3.up;
            var rightVector   = Vector3.right;
            var forwardVector = Vector3.forward;

            Vector3[] vertices = null;
            if (!BrushMeshFactory.GenerateStadiumVertices(generator.definition, ref vertices))
            {
                return;
            }


            UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, false, false, isDisabled);
            DrawOutline(generator.definition, vertices, lineMode: LineMode.ZTest);

            UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, false, true, isDisabled);
            DrawOutline(generator.definition, vertices, lineMode: LineMode.NoZTest);

            var height   = generator.definition.height;
            var length   = generator.definition.length;
            var diameter = generator.definition.diameter;
            var sides    = generator.definition.sides;

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

            var haveRoundedTop    = generator.definition.haveRoundedTop;
            var haveRoundedBottom = generator.definition.haveRoundedBottom;
            var haveCenter        = generator.definition.haveCenter;
            var topLength         = generator.definition.topLength;
            var bottomLength      = generator.definition.bottomLength;


            var midY       = height * 0.5f;
            var halfLength = length * 0.5f;
            var midZ       = ((halfLength - (haveRoundedTop ? topLength : 0)) - (halfLength - (haveRoundedBottom ? bottomLength : 0))) * -0.5f;
            //	haveCenter ? ((vertices[firstTopSide].z + vertices[firstBottomSide].z) * 0.5f) : 0;

            var topPoint    = new Vector3(0, height, midZ);
            var bottomPoint = new Vector3(0, 0, midZ);
            var frontPoint  = new Vector3(0, midY, halfLength);
            var backPoint   = new Vector3(0, midY, -halfLength);
            var leftPoint   = new Vector3(diameter * 0.5f, midY, midZ);
            var rightPoint  = new Vector3(diameter * -0.5f, midY, midZ);

            EditorGUI.BeginChangeCheck();
            {
                var topId = GUIUtility.GetControlID(s_TopHash, FocusType.Passive);
                {
                    var isTopBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(topPoint, upVector);
                    var topHasFocus    = (focusControl == topId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, topHasFocus, isTopBackfaced, isDisabled);
                    topPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(topId, topPoint, upVector);
                    //if (generator.definition.haveRoundedTop)
                    {
                        var thickness = topHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                        UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, topHasFocus, true, isDisabled);
                        ChiselOutlineRenderer.DrawLineLoop(vertices, sides, sides, lineMode: LineMode.NoZTest, thickness: thickness);
                        if (haveRoundedTop)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[sides + firstTopSide], vertices[sides + lastTopSide], lineMode: LineMode.NoZTest, thickness: kVertLineThickness);
                        }
                        if (haveRoundedBottom && haveCenter)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[sides + firstBottomSide], vertices[sides + lastBottomSide], lineMode: LineMode.NoZTest, thickness: kVertLineThickness);
                        }

                        UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, topHasFocus, false, isDisabled);
                        ChiselOutlineRenderer.DrawLineLoop(vertices, sides, sides, lineMode: LineMode.ZTest, thickness: thickness);
                        if (haveRoundedTop)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[sides + firstTopSide], vertices[sides + lastTopSide], lineMode: LineMode.ZTest, thickness: kVertLineThickness);
                        }
                        if (haveRoundedBottom && haveCenter)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[sides + firstBottomSide], vertices[sides + lastBottomSide], lineMode: LineMode.ZTest, thickness: kVertLineThickness);
                        }
                    }
                }

                var bottomId = GUIUtility.GetControlID(s_BottomHash, FocusType.Passive);
                {
                    var isBottomBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(bottomPoint, -upVector);
                    var bottomHasFocus    = (focusControl == bottomId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, bottomHasFocus, isBottomBackfaced, isDisabled);
                    bottomPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(bottomId, bottomPoint, -upVector);
                    //if (haveRoundedBottom)
                    {
                        var thickness = bottomHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                        UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, bottomHasFocus, true, isDisabled);
                        ChiselOutlineRenderer.DrawLineLoop(vertices, 0, sides, lineMode: LineMode.NoZTest, thickness: thickness);
                        if (haveRoundedTop)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[firstTopSide], vertices[lastTopSide], lineMode: LineMode.NoZTest, thickness: kVertLineThickness);
                        }
                        if (haveRoundedBottom && haveCenter)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[firstBottomSide], vertices[lastBottomSide], lineMode: LineMode.NoZTest, thickness: kVertLineThickness);
                        }

                        UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, bottomHasFocus, false, isDisabled);
                        ChiselOutlineRenderer.DrawLineLoop(vertices, 0, sides, lineMode: LineMode.ZTest, thickness: thickness);
                        if (haveRoundedTop)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[firstTopSide], vertices[lastTopSide], lineMode: LineMode.ZTest, thickness: kVertLineThickness);
                        }
                        if (haveRoundedBottom && haveCenter)
                        {
                            ChiselOutlineRenderer.DrawLine(vertices[firstBottomSide], vertices[lastBottomSide], lineMode: LineMode.ZTest, thickness: kVertLineThickness);
                        }
                    }
                }

                var frontId = GUIUtility.GetControlID(s_TopHash, FocusType.Passive);
                {
                    var isTopBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(frontPoint, forwardVector);
                    var frontHasFocus  = (focusControl == frontId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, frontHasFocus, isTopBackfaced, isDisabled);
                    frontPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(frontId, frontPoint, forwardVector);
                }

                var backId = GUIUtility.GetControlID(s_BottomHash, FocusType.Passive);
                {
                    var isBottomBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(backPoint, -forwardVector);
                    var backHasFocus      = (focusControl == backId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, backHasFocus, isBottomBackfaced, isDisabled);
                    backPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(backId, backPoint, -forwardVector);
                }

                var leftId = GUIUtility.GetControlID(s_TopHash, FocusType.Passive);
                {
                    var isTopBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(leftPoint, rightVector);
                    var leftHasFocus   = (focusControl == leftId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, leftHasFocus, isTopBackfaced, isDisabled);
                    leftPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(leftId, leftPoint, rightVector);
                }

                var rightId = GUIUtility.GetControlID(s_BottomHash, FocusType.Passive);
                {
                    var isBottomBackfaced = ChiselCylinderEditor.IsSufaceBackFaced(rightPoint, -rightVector);
                    var rightHasFocus     = (focusControl == rightId);

                    UnityEditor.Handles.color = ChiselCylinderEditor.GetColorForState(baseColor, rightHasFocus, isBottomBackfaced, isDisabled);
                    rightPoint = UnitySceneExtensions.SceneHandles.DirectionHandle(rightId, rightPoint, -rightVector);
                }
            }
            if (EditorGUI.EndChangeCheck())
            {
                Undo.RecordObject(target, "Modified " + generator.NodeTypeName);
                generator.definition.height   = topPoint.y - bottomPoint.y;
                generator.definition.length   = Mathf.Max(0, frontPoint.z - backPoint.z);
                generator.definition.diameter = leftPoint.x - rightPoint.x;
                generator.OnValidate();
                // TODO: handle sizing in some directions (needs to modify transformation?)
            }
        }