Esempio n. 1
0
        public override void OnEdit(IChiselHandles handles)
        {
            var normal = Vector3.up;

            float3[] vertices = null;
            if (BrushMeshFactory.GenerateTorusVertices(this, ref vertices))
            {
                var baseColor = handles.color;
                handles.color = handles.GetStateColor(baseColor, false, false);
                DrawOutline(handles, this, vertices, lineMode: LineMode.ZTest);
                handles.color = handles.GetStateColor(baseColor, false, true);
                DrawOutline(handles, this, vertices, lineMode: LineMode.NoZTest);
                handles.color = baseColor;
            }

            var outerRadius = settings.outerDiameter * 0.5f;
            var innerRadius = settings.InnerDiameter * 0.5f;
            var topPoint    = normal * (settings.tubeHeight * 0.5f);
            var bottomPoint = normal * (-settings.tubeHeight * 0.5f);

            handles.DoRadiusHandle(ref outerRadius, normal, float3.zero);
            handles.DoRadiusHandle(ref innerRadius, normal, float3.zero);
            handles.DoDirectionHandle(ref bottomPoint, -normal);
            handles.DoDirectionHandle(ref topPoint, normal);
            if (handles.modified)
            {
                settings.outerDiameter = outerRadius * 2.0f;
                settings.InnerDiameter = innerRadius * 2.0f;
                settings.tubeHeight    = (topPoint.y - bottomPoint.y);
                // TODO: handle sizing down
            }
        }
        static                         Vector3[] vertices = null; // TODO: store this per instance? or just allocate every frame?

        public void OnEdit(IChiselHandles handles)
        {
            var baseColor = handles.color;
            var normal    = Vector3.up;

            if (BrushMeshFactory.GenerateHemisphereVertices(ref this, ref vertices))
            {
                handles.color = handles.GetStateColor(baseColor, false, false);
                DrawOutline(handles, this, vertices, lineMode: LineMode.ZTest);

                handles.color = handles.GetStateColor(baseColor, false, true);
                DrawOutline(handles, this, vertices, lineMode: LineMode.NoZTest);
                handles.color = baseColor;
            }


            var topPoint = normal * this.diameterXYZ.y;
            var radius2D = new Vector2(this.diameterXYZ.x, this.diameterXYZ.z) * 0.5f;

            if (this.diameterXYZ.y < 0)
            {
                normal = -normal;
            }
            bool previousModified;

            previousModified = handles.modified;
            {
                handles.color = baseColor;
                // TODO: make it possible to (optionally) size differently in x & z
                handles.DoRadiusHandle(ref radius2D.x, normal, Vector3.zero);

                {
                    var isTopBackfaced = false;          // TODO: how to do this?

                    handles.backfaced = isTopBackfaced;
                    handles.DoDirectionHandle(ref topPoint, normal);
                    handles.backfaced = false;
                }
            }
            if (previousModified != handles.modified)
            {
                var diameter = this.diameterXYZ;
                diameter.y       = topPoint.y;
                diameter.x       = radius2D.x * 2.0f;
                diameter.z       = radius2D.x * 2.0f;
                this.diameterXYZ = diameter;
            }
        }
        public override void OnEdit(IChiselHandles handles)
        {
            var normal       = Vector3.up;
            var topDirection = Vector3.forward;
            var lowDirection = Vector3.forward;

            var originalOuterDiameter = settings.outerDiameter;
            var originalInnerDiameter = settings.innerDiameter;
            var originalStartAngle    = settings.startAngle;
            var originalStepHeight    = settings.stepHeight;
            var originalRotation      = settings.rotation;
            var originalHeight        = settings.height;
            var originalOrigin        = settings.origin;
            var cylinderTop           = new BrushMeshFactory.ChiselCircleDefinition {
                diameterX = 1, diameterZ = 1, height = originalOrigin.y + originalHeight
            };
            var cylinderLow = new BrushMeshFactory.ChiselCircleDefinition {
                diameterX = 1, diameterZ = 1, height = originalOrigin.y
            };
            var originalTopPoint = normal * cylinderTop.height;
            var originalLowPoint = normal * cylinderLow.height;
            var originalMidPoint = (originalTopPoint + originalLowPoint) * 0.5f;

            var outerDiameter = originalOuterDiameter;
            var innerDiameter = originalInnerDiameter;
            var topPoint      = originalTopPoint;
            var lowPoint      = originalLowPoint;
            var midPoint      = originalMidPoint;
            var startAngle    = originalStartAngle;
            var rotation      = originalRotation;

            {
                var currRotation = startAngle + rotation;
                handles.DoRotatableLineHandle(ref startAngle, lowPoint, outerDiameter * 0.5f, normal, lowDirection, Vector3.Cross(normal, lowDirection));
                handles.DoRotatableLineHandle(ref currRotation, topPoint, outerDiameter * 0.5f, normal, topDirection, Vector3.Cross(normal, topDirection));
                if (handles.modified)
                {
                    rotation = currRotation - startAngle;
                }


                // TODO: properly show things as backfaced
                // TODO: temporarily show inner or outer diameter as disabled when resizing one or the other
                // TODO: FIXME: why aren't there any arrows?
                handles.DoDirectionHandle(ref topPoint, normal, snappingStep: originalStepHeight);
                topPoint.y = math.max(lowPoint.y + originalStepHeight, topPoint.y);
                handles.DoDirectionHandle(ref lowPoint, -normal, snappingStep: originalStepHeight);
                lowPoint.y = math.min(topPoint.y - originalStepHeight, lowPoint.y);

                float minOuterDiameter = innerDiameter + ChiselSpiralStairs.kMinStairsDepth;
                {
                    var outerRadius = outerDiameter * 0.5f;
                    handles.DoRadiusHandle(ref outerRadius, Vector3.up, topPoint, renderDisc: false);
                    handles.DoRadiusHandle(ref outerRadius, Vector3.up, lowPoint, renderDisc: false);
                    outerDiameter = math.max(minOuterDiameter, outerRadius * 2.0f);
                }

                float maxInnerDiameter = outerDiameter - ChiselSpiralStairs.kMinStairsDepth;
                {
                    var innerRadius = innerDiameter * 0.5f;
                    handles.DoRadiusHandle(ref innerRadius, Vector3.up, midPoint, renderDisc: false);
                    innerDiameter = math.min(maxInnerDiameter, innerRadius * 2.0f);
                }



                // TODO: somehow put this into a separate renderer
                cylinderTop.diameterZ = cylinderTop.diameterX = cylinderLow.diameterZ = cylinderLow.diameterX = originalInnerDiameter;
                BrushMeshFactory.GetConicalFrustumVertices(cylinderLow, cylinderTop, 0, settings.innerSegments, ref s_InnerVertices);

                cylinderTop.diameterZ = cylinderTop.diameterX = cylinderLow.diameterZ = cylinderLow.diameterX = originalOuterDiameter;
                BrushMeshFactory.GetConicalFrustumVertices(cylinderLow, cylinderTop, 0, settings.outerSegments, ref s_OuterVertices);

                var originalColor = handles.color;
                var color         = handles.color;
                var outlineColor  = Color.black;
                outlineColor.a = color.a;

                handles.color = outlineColor;
                {
                    var sides = settings.outerSegments;
                    for (int i = 0, j = sides - 1; i < sides; j = i, i++)
                    {
                        var t0 = s_OuterVertices[i];
                        var t1 = s_OuterVertices[j];
                        var b0 = s_OuterVertices[i + sides];
                        var b1 = s_OuterVertices[j + sides];

                        handles.DrawLine(t0, b0, thickness: 1.0f);
                        handles.DrawLine(t0, t1, thickness: 1.0f);
                        handles.DrawLine(b0, b1, thickness: 1.0f);
                    }
                }
                {
                    var sides = settings.innerSegments;
                    for (int i = 0, j = sides - 1; i < sides; j = i, i++)
                    {
                        var t0 = s_InnerVertices[i];
                        var t1 = s_InnerVertices[j];
                        var b0 = s_InnerVertices[i + sides];
                        var b1 = s_InnerVertices[j + sides];

                        handles.DrawLine(t0, b0, thickness: 1.0f);
                        handles.DrawLine(t0, t1, thickness: 1.0f);
                        handles.DrawLine(b0, b1, thickness: 1.0f);
                    }
                }

                handles.color = originalColor;
                {
                    var sides = settings.outerSegments;
                    for (int i = 0, j = sides - 1; i < sides; j = i, i++)
                    {
                        var t0 = s_OuterVertices[i];
                        var t1 = s_OuterVertices[j];
                        var b0 = s_OuterVertices[i + sides];
                        var b1 = s_OuterVertices[j + sides];

                        handles.DrawLine(t0, b0, thickness: 1.0f);
                        handles.DrawLine(t0, t1, thickness: 1.0f);
                        handles.DrawLine(b0, b1, thickness: 1.0f);
                    }
                }
                {
                    var sides = settings.innerSegments;
                    for (int i = 0, j = sides - 1; i < sides; j = i, i++)
                    {
                        var t0 = s_InnerVertices[i];
                        var t1 = s_InnerVertices[j];
                        var b0 = s_InnerVertices[i + sides];
                        var b1 = s_InnerVertices[j + sides];


                        handles.DrawLine(t0, b0, thickness: 1.0f);
                        handles.DrawLine(t0, t1, thickness: 1.0f);
                        handles.DrawLine(b0, b1, thickness: 1.0f);

                        var m0 = (t0 + b0) * 0.5f;
                        var m1 = (t1 + b1) * 0.5f;
                        handles.DrawLine(m0, m1, thickness: 2.0f);
                    }
                }
            }
            if (handles.modified)
            {
                settings.outerDiameter = outerDiameter;
                settings.innerDiameter = innerDiameter;
                settings.startAngle    = startAngle;
                settings.rotation      = rotation;

                if (topPoint != originalTopPoint)
                {
                    settings.height = topPoint.y - lowPoint.y;
                }

                if (lowPoint != originalLowPoint)
                {
                    settings.height = topPoint.y - lowPoint.y;
                    var newOrigin = originalOrigin;
                    newOrigin.y    += lowPoint.y - originalLowPoint.y;
                    settings.origin = newOrigin;
                }
            }
        }
Esempio n. 4
0
        static                         Vector3[] vertices = null; // TODO: store this per instance? or just allocate every frame?

        public void OnEdit(IChiselHandles handles)
        {
            var baseColor = handles.color;
            var normal    = Vector3.up;

            if (BrushMeshFactory.GenerateCapsuleVertices(ref this, ref vertices))
            {
                handles.color = handles.GetStateColor(baseColor, false, false);
                DrawOutline(handles, this, vertices, lineMode: LineMode.ZTest);

                handles.color = handles.GetStateColor(baseColor, false, true);
                DrawOutline(handles, this, vertices, lineMode: LineMode.NoZTest);

                handles.color = baseColor;
            }

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

            var topHeight    = this.topHeight;
            var bottomHeight = this.bottomHeight;

            var maxTopHeight    = this.height - bottomHeight;
            var maxBottomHeight = this.height - topHeight;

            if (this.height < 0)
            {
                normal = -normal;
            }

            var prevModified = handles.modified;

            {
                handles.color = baseColor;
                // TODO: make it possible to (optionally) size differently in x & z
                var radius2Dx = radius2D.x;
                handles.DoRadiusHandle(ref radius2Dx, normal, middlePoint);
                radius2D.x = radius2Dx;

                {
                    var isTopBackfaced  = handles.IsSufaceBackFaced(topPoint, normal);
                    var topLoopHasFocus = false;
                    handles.backfaced = isTopBackfaced;
                    for (int j = this.sides - 1, i = 0; i < this.sides; j = i, i++)
                    {
                        var from = vertices[j + this.topVertexOffset];
                        var to   = vertices[i + this.topVertexOffset];

                        if (handles.DoEdgeHandle1DOffset(out var edgeOffset, UnitySceneExtensions.Axis.Y, from, to, renderLine: false))
                        {
                            topHeight = Mathf.Clamp(topHeight - edgeOffset, 0, maxTopHeight);
                        }
                        topLoopHasFocus = topLoopHasFocus || handles.lastHandleHadFocus;
                    }


                    handles.color = baseColor;
                    handles.DoDirectionHandle(ref topPoint, normal);
                    var topHasFocus = handles.lastHandleHadFocus;
                    handles.backfaced = false;

                    topLoopHasFocus = topLoopHasFocus || (topHasFocus && !this.haveRoundedTop);

                    var thickness = topLoopHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                    handles.color = handles.GetStateColor(baseColor, topLoopHasFocus, true);
                    handles.DrawLineLoop(vertices, this.topVertexOffset, this.sides, lineMode: LineMode.NoZTest, thickness: thickness);

                    handles.color = handles.GetStateColor(baseColor, topLoopHasFocus, false);
                    handles.DrawLineLoop(vertices, this.topVertexOffset, this.sides, lineMode: LineMode.ZTest, thickness: thickness);
                }

                {
                    var isBottomBackfaced  = handles.IsSufaceBackFaced(bottomPoint, -normal);
                    var bottomLoopHasFocus = false;
                    handles.backfaced = isBottomBackfaced;
                    for (int j = this.sides - 1, i = 0; i < this.sides; j = i, i++)
                    {
                        var from = vertices[j + this.bottomVertexOffset];
                        var to   = vertices[i + this.bottomVertexOffset];

                        if (handles.DoEdgeHandle1DOffset(out var edgeOffset, UnitySceneExtensions.Axis.Y, from, to, renderLine: false))
                        {
                            bottomHeight = Mathf.Clamp(bottomHeight + edgeOffset, 0, maxBottomHeight);
                        }
                        bottomLoopHasFocus = bottomLoopHasFocus || handles.lastHandleHadFocus;
                    }

                    handles.color = baseColor;
                    handles.DoDirectionHandle(ref bottomPoint, -normal);
                    var bottomHasFocus = handles.lastHandleHadFocus;
                    handles.backfaced = false;

                    bottomLoopHasFocus = bottomLoopHasFocus || (bottomHasFocus && !this.haveRoundedBottom);

                    var thickness = bottomLoopHasFocus ? kCapLineThicknessSelected : kCapLineThickness;

                    handles.color = handles.GetStateColor(baseColor, bottomLoopHasFocus, true);
                    handles.DrawLineLoop(vertices, this.bottomVertexOffset, this.sides, lineMode: LineMode.NoZTest, thickness: thickness);

                    handles.color = handles.GetStateColor(baseColor, bottomLoopHasFocus, false);
                    handles.DrawLineLoop(vertices, this.bottomVertexOffset, this.sides, lineMode: LineMode.ZTest, thickness: thickness);
                }
            }
            if (prevModified != handles.modified)
            {
                this.diameterX    = radius2D.x * 2.0f;
                this.height       = topPoint.y - bottomPoint.y;
                this.diameterZ    = radius2D.x * 2.0f;
                this.offsetY      = bottomPoint.y;
                this.topHeight    = topHeight;
                this.bottomHeight = bottomHeight;
                // TODO: handle sizing down (needs to modify transformation?)
            }
        }
        static                         Vector3[] vertices = null; // TODO: store this per instance? or just allocate every frame?

        public void OnEdit(IChiselHandles handles)
        {
            var baseColor = handles.color;
            var normal    = Vector3.up;

            if (BrushMeshFactory.GenerateSphereVertices(this, ref vertices))
            {
                handles.color = handles.GetStateColor(baseColor, false, false);
                DrawOutline(handles, this, vertices, lineMode: LineMode.ZTest);

                handles.color = handles.GetStateColor(baseColor, false, true);
                DrawOutline(handles, this, vertices, lineMode: LineMode.NoZTest);
                handles.color = baseColor;
            }

            Vector3 center, topPoint, bottomPoint;

            if (!this.generateFromCenter)
            {
                center      = normal * (this.offsetY + (this.diameterXYZ.y * 0.5f));
                topPoint    = normal * (this.offsetY + this.diameterXYZ.y);
                bottomPoint = normal * (this.offsetY);
            }
            else
            {
                center      = normal * (this.offsetY);
                topPoint    = normal * (this.offsetY + (this.diameterXYZ.y * 0.5f));
                bottomPoint = normal * (this.offsetY + (this.diameterXYZ.y * -0.5f));
            }

            if (this.diameterXYZ.y < 0)
            {
                normal = -normal;
            }

            var radius2D = new Vector2(this.diameterXYZ.x, this.diameterXYZ.z) * 0.5f;

            {
                // TODO: make it possible to (optionally) size differently in x & z
                var radiusX = radius2D.x;
                handles.DoRadiusHandle(ref radiusX, normal, center);
                radius2D.x = radiusX;

                {
                    var isBottomBackfaced = false;       // TODO: how to do this?

                    handles.backfaced = isBottomBackfaced;
                    handles.DoDirectionHandle(ref bottomPoint, -normal);
                    handles.backfaced = false;
                }

                {
                    var isTopBackfaced = false;          // TODO: how to do this?

                    handles.backfaced = isTopBackfaced;
                    handles.DoDirectionHandle(ref topPoint, normal);
                    handles.backfaced = false;
                }
            }
            if (handles.modified)
            {
                var diameter = this.diameterXYZ;
                diameter.y       = topPoint.y - bottomPoint.y;
                diameter.x       = radius2D.x * 2.0f;
                diameter.z       = radius2D.x * 2.0f;
                this.offsetY     = bottomPoint.y;
                this.diameterXYZ = diameter;
                // TODO: handle sizing down (needs to modify transformation?)
            }
        }