Exemplo n.º 1
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                var path = new VertexStorage();
                path.MoveTo(0, 0);
                path.LineTo(Math.Sqrt(2), 0);
                path.LineTo(0, Height);

                var mesh = VertexSourceToMesh.Revolve(path, 4);
                mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2, Depth / 2, 1));
                Mesh = mesh;

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
Exemplo n.º 2
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref valuesChanged);
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
                RingSides     = agg_basics.Clamp(RingSides, 3, 360, ref valuesChanged);

                StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged);
                EndingAngle   = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged);

                var ringSides      = RingSides;
                var startingAngle  = StartingAngle;
                var endingAngle    = EndingAngle;
                var ringPhaseAngle = RingPhaseAngle;
                if (!Advanced)
                {
                    ringSides      = Math.Max(3, (int)(Sides / 2));
                    startingAngle  = 0;
                    endingAngle    = 360;
                    ringPhaseAngle = 0;
                }

                var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);

                using (new CenterAndHeightMaintainer(this))
                {
                    var poleRadius     = (OuterDiameter / 2 - innerDiameter / 2) / 2;
                    var toroidRadius   = innerDiameter / 2 + poleRadius;
                    var path           = new VertexStorage();
                    var angleDelta     = MathHelper.Tau / ringSides;
                    var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
                    var ringAngle      = ringStartAngle;
                    var circleCenter   = new Vector2(toroidRadius, 0);
                    path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
                    for (int i = 0; i < ringSides - 1; i++)
                    {
                        ringAngle += angleDelta;
                        path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
                    }

                    path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 3
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref changed);
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref changed);
                RingSides     = agg_basics.Clamp(RingSides, 3, 360, ref changed);

                var ringSides      = RingSides;
                var startingAngle  = StartingAngle;
                var endingAngle    = EndingAngle;
                var ringPhaseAngle = RingPhaseAngle;
                if (!Advanced)
                {
                    ringSides      = Math.Max(3, (int)(Sides / 2));
                    startingAngle  = 0;
                    endingAngle    = 360;
                    ringPhaseAngle = 0;
                }

                var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);

                var aabb = this.GetAxisAlignedBoundingBox();

                var poleRadius     = (OuterDiameter / 2 - innerDiameter / 2) / 2;
                var toroidRadius   = innerDiameter / 2 + poleRadius;
                var path           = new VertexStorage();
                var angleDelta     = MathHelper.Tau / ringSides;
                var ringStartAngle = MathHelper.DegreesToRadians(ringPhaseAngle);
                var ringAngle      = ringStartAngle;
                var circleCenter   = new Vector2(toroidRadius, 0);
                path.MoveTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));
                for (int i = 0; i < ringSides - 1; i++)
                {
                    ringAngle += angleDelta;
                    path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringAngle), poleRadius * Math.Sin(ringAngle)));
                }

                path.LineTo(circleCenter + new Vector2(poleRadius * Math.Cos(ringStartAngle), poleRadius * Math.Sin(ringStartAngle)));

                var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            if (changed)
            {
                base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties));
            }
        }
Exemplo n.º 4
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                Sides = agg_basics.Clamp(Sides, 3, 360, ref changed);
                var aabb = this.GetAxisAlignedBoundingBox();

                var path = new VertexStorage();
                path.MoveTo(0, 0);
                path.LineTo(Diameter / 2, 0);
                path.LineTo(0, Height);

                Mesh = VertexSourceToMesh.Revolve(path, Sides);
                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            if (changed)
            {
                base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties));
            }
        }
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                var radius     = Diameter / 2;
                var angleDelta = MathHelper.Tau / 4 / LatitudeSides;
                var angle      = 0.0;
                var path       = new VertexStorage();
                path.MoveTo(0, 0);
                path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                for (int i = 0; i < LatitudeSides; i++)
                {
                    angle += angleDelta;
                    path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                }

                Mesh = VertexSourceToMesh.Revolve(path, LongitudeSides);
                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
Exemplo n.º 6
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            var startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
            var endingAngle   = EndingAngle.ClampIfNotCalculated(this, startingAngle + .01, 360, ref valuesChanged);
            var sides         = Sides.Value(this);
            var axisPosition  = AxisPosition.Value(this);

            if (startingAngle > 0 || endingAngle < 360)
            {
                Sides = agg_basics.Clamp(sides, 1, 360, ref valuesChanged);
            }
            else
            {
                Sides = agg_basics.Clamp(sides, 3, 360, ref valuesChanged);
            }

            Invalidate(InvalidateType.DisplayValues);

            var rebuildLock = RebuildLock();

            // now create a long running task to process the image
            return(ApplicationController.Instance.Tasks.Execute(
                       "Revolve".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var vertexSource = this.VertexSource;
                var pathBounds = vertexSource.GetBounds();
                vertexSource = vertexSource.Translate(-pathBounds.Left - axisPosition, 0);
                Mesh mesh = VertexSourceToMesh.Revolve(vertexSource,
                                                       sides,
                                                       MathHelper.DegreesToRadians(360 - endingAngle),
                                                       MathHelper.DegreesToRadians(360 - startingAngle),
                                                       false);

                // take the axis offset out
                mesh.Transform(Matrix4X4.CreateTranslation(pathBounds.Left + axisPosition, 0, 0));

                if (mesh.Vertices.Count == 0)
                {
                    mesh = null;
                }

                Mesh = mesh;

                UiThread.RunOnIdle(() =>
                {
                    rebuildLock.Dispose();
                    Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
                });

                return Task.CompletedTask;
            }));
        }
Exemplo n.º 7
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged);
            EndingAngle   = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged);

            if (StartingAngle > 0 || EndingAngle < 360)
            {
                Sides = agg_basics.Clamp(Sides, 1, 360, ref valuesChanged);
            }
            else
            {
                Sides = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            var rebuildLock = RebuildLock();

            // now create a long running task to process the image
            return(ApplicationController.Instance.Tasks.Execute(
                       "Revolve".Localize(),
                       null,
                       (reporter, cancellationToken) =>
            {
                var vertexSource = this.VertexSource.Transform(Matrix);
                var pathBounds = vertexSource.GetBounds();
                vertexSource = vertexSource.Translate(-pathBounds.Left - AxisPosition, 0);
                Mesh mesh = VertexSourceToMesh.Revolve(vertexSource,
                                                       Sides,
                                                       MathHelper.DegreesToRadians(360 - EndingAngle),
                                                       MathHelper.DegreesToRadians(360 - StartingAngle),
                                                       false);

                // take the axis offset out
                mesh.Transform(Matrix4X4.CreateTranslation(pathBounds.Left + AxisPosition, 0, 0));
                // move back to object space
                mesh.Transform(this.Matrix.Inverted);

                if (mesh.Vertices.Count == 0)
                {
                    mesh = null;
                }

                Mesh = mesh;

                rebuildLock.Dispose();
                Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
                return Task.CompletedTask;
            }));
        }
        // TODO: EditorTools owns this, move to more general location
        private static Mesh CreateCylinder(double height = 20, double radius = 10, int rotationCount = 30)
        {
            var path = new VertexStorage();

            path.MoveTo(0, 0);
            path.LineTo(radius, 0);
            path.LineTo(radius, height);
            path.LineTo(0, height);

            return(VertexSourceToMesh.Revolve(path, rotationCount));
        }
Exemplo n.º 9
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref changed);
                LatitudeSides = agg_basics.Clamp(LatitudeSides, 3, 360, ref changed);

                var aabb = this.GetAxisAlignedBoundingBox();

                var startingAngle = StartingAngle;
                var endingAngle   = EndingAngle;
                var latitudeSides = LatitudeSides;
                if (!Advanced)
                {
                    startingAngle = 0;
                    endingAngle   = 360;
                    latitudeSides = Sides;
                }

                var path       = new VertexStorage();
                var angleDelta = MathHelper.Tau / 2 / latitudeSides;
                var angle      = -MathHelper.Tau / 4;
                var radius     = Diameter / 2;
                path.MoveTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                for (int i = 0; i < latitudeSides; i++)
                {
                    angle += angleDelta;
                    path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                }

                var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                var steps      = Math.Max(1, (int)(Sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5));
                Mesh = VertexSourceToMesh.Revolve(path,
                                                  steps,
                                                  startAngle,
                                                  endAngle);
                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));

            if (changed)
            {
                base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties));
            }
        }
Exemplo n.º 10
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
                LatitudeSides = agg_basics.Clamp(LatitudeSides, 3, 360, ref valuesChanged);

                using (new CenterAndHeightMaintainer(this))
                {
                    var startingAngle = StartingAngle;
                    var endingAngle   = EndingAngle;
                    var latitudeSides = LatitudeSides;
                    if (!Advanced)
                    {
                        startingAngle = 0;
                        endingAngle   = 360;
                        latitudeSides = Sides;
                    }

                    var path       = new VertexStorage();
                    var angleDelta = MathHelper.Tau / 2 / latitudeSides;
                    var angle      = -MathHelper.Tau / 4;
                    var radius     = Diameter / 2;
                    path.MoveTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                    for (int i = 0; i < latitudeSides; i++)
                    {
                        angle += angleDelta;
                        path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                    }

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    var steps      = Math.Max(1, (int)(Sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5));
                    Mesh = VertexSourceToMesh.Revolve(path,
                                                      steps,
                                                      startAngle,
                                                      endAngle);
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 11
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            double height        = Height.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
            var    diameter      = Diameter.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
            var    diameterTop   = DiameterTop.ClampIfNotCalculated(this, .01, 1000000, ref valuesChanged);
            var    sides         = Sides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
            var    startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
            var    endingAngle   = EndingAngle.ClampIfNotCalculated(this, StartingAngle.Value(this) + .01, 360, ref valuesChanged);

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    if (!Advanced)
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -height / 2);
                        path.LineTo(diameter / 2, -height / 2);
                        path.LineTo(diameter / 2, height / 2);
                        path.LineTo(0, height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, sides);
                    }
                    else
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -height / 2);
                        path.LineTo(diameter / 2, -height / 2);
                        path.LineTo(diameterTop / 2, height / 2);
                        path.LineTo(0, height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, sides, MathHelper.DegreesToRadians(startingAngle), MathHelper.DegreesToRadians(endingAngle));
                    }
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 12
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref changed);
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref changed);

                var aabb = this.GetAxisAlignedBoundingBox();

                var startingAngle = StartingAngle;
                var endingAngle   = EndingAngle;
                if (!Advanced)
                {
                    startingAngle = 0;
                    endingAngle   = 360;
                }

                var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);

                var path = new VertexStorage();
                path.MoveTo(OuterDiameter / 2, -Height / 2);
                path.LineTo(OuterDiameter / 2, Height / 2);
                path.LineTo(innerDiameter / 2, Height / 2);
                path.LineTo(innerDiameter / 2, -Height / 2);
                path.LineTo(OuterDiameter / 2, -Height / 2);

                var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            if (changed)
            {
                base.OnInvalidate(new InvalidateArgs(this, InvalidateType.Properties));
            }
        }
Exemplo n.º 13
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            Sides         = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
            Height        = agg_basics.Clamp(Height, .01, 1000000, ref valuesChanged);
            Diameter      = agg_basics.Clamp(Diameter, .01, 1000000, ref valuesChanged);
            StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged);
            EndingAngle   = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged);

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    if (!Advanced)
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -Height / 2);
                        path.LineTo(Diameter / 2, -Height / 2);
                        path.LineTo(Diameter / 2, Height / 2);
                        path.LineTo(0, Height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, Sides);
                    }
                    else
                    {
                        var path = new VertexStorage();
                        path.MoveTo(0, -Height / 2);
                        path.LineTo(Diameter / 2, -Height / 2);
                        path.LineTo(DiameterTop / 2, Height / 2);
                        path.LineTo(0, Height / 2);

                        Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(StartingAngle), MathHelper.DegreesToRadians(EndingAngle));
                    }
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 14
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var latitudeSides  = LatitudeSides.ClampIfNotCalculated(this, 3, 180, ref valuesChanged);
                var longitudeSides = LongitudeSides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
                var diameter       = Diameter.Value(this);

                using (new CenterAndHeightMaintainer(this))
                {
                    if (longitudeSides != lastLongitudeSides ||
                        latitudeSides != lastLatitudeSides ||
                        diameter != lastDiameter)
                    {
                        var radius     = diameter / 2;
                        var angleDelta = MathHelper.Tau / 4 / latitudeSides;
                        var angle      = 0.0;
                        var path       = new VertexStorage();
                        path.MoveTo(0, 0);
                        path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                        for (int i = 0; i < latitudeSides; i++)
                        {
                            angle += angleDelta;
                            path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                        }

                        Mesh = VertexSourceToMesh.Revolve(path, longitudeSides);
                    }

                    lastDiameter       = diameter;
                    lastLongitudeSides = longitudeSides;
                    lastLatitudeSides  = latitudeSides;
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 15
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                InnerDiameter = agg_basics.Clamp(InnerDiameter, 0, OuterDiameter - .1, ref valuesChanged);
                Sides         = agg_basics.Clamp(Sides, 3, 360, ref valuesChanged);
                StartingAngle = agg_basics.Clamp(StartingAngle, 0, 360 - .01, ref valuesChanged);
                EndingAngle   = agg_basics.Clamp(EndingAngle, StartingAngle + .01, 360, ref valuesChanged);

                using (new CenterAndHeightMaintainer(this))
                {
                    var startingAngle = StartingAngle;
                    var endingAngle   = EndingAngle;
                    if (!Advanced)
                    {
                        startingAngle = 0;
                        endingAngle   = 360;
                    }

                    var innerDiameter = Math.Min(OuterDiameter - .1, InnerDiameter);

                    var path = new VertexStorage();
                    path.MoveTo(OuterDiameter / 2, -Height / 2);
                    path.LineTo(OuterDiameter / 2, Height / 2);
                    path.LineTo(innerDiameter / 2, Height / 2);
                    path.LineTo(innerDiameter / 2, -Height / 2);
                    path.LineTo(OuterDiameter / 2, -Height / 2);

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    Mesh = VertexSourceToMesh.Revolve(path, Sides, startAngle, endAngle);
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 16
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(Math.Sqrt(2), 0);
                    path.LineTo(0, Height);

                    var mesh = VertexSourceToMesh.Revolve(path, 4);
                    mesh.Transform(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(45)) * Matrix4X4.CreateScale(Width / 2, Depth / 2, 1));
                    Mesh = mesh;
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 17
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                Sides = agg_basics.Clamp(Sides, 3, 360, ref changed);
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(Diameter / 2, 0);
                    path.LineTo(0, Height);

                    Mesh = VertexSourceToMesh.Revolve(path, Sides);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
            return(Task.CompletedTask);
        }
Exemplo n.º 18
0
        public static Mesh CreateSphere(double diameter = 1, int sides = 30, int latitudeSides = 30, double startingAngleDeg = 0, double endingAngleDeg = 360)
        {
            var path       = new VertexStorage();
            var angleDelta = MathHelper.Tau / 2 / latitudeSides;
            var angle      = -MathHelper.Tau / 4;
            var radius     = diameter / 2;

            path.MoveTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
            for (int i = 0; i < latitudeSides; i++)
            {
                angle += angleDelta;
                path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
            }

            var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngleDeg));
            var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngleDeg));
            var steps      = Math.Max(1, (int)(sides * MathHelper.Tau / Math.Abs(MathHelper.GetDeltaAngle(startAngle, endAngle)) + .5));

            return(VertexSourceToMesh.Revolve(path,
                                              steps,
                                              startAngle,
                                              endAngle));
        }
Exemplo n.º 19
0
        private void Rebuild(UndoBuffer undoBuffer)
        {
            this.DebugDepth("Rebuild");
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                if (!Advanced)
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, -Height / 2);
                    path.LineTo(Diameter / 2, -Height / 2);
                    path.LineTo(Diameter / 2, Height / 2);
                    path.LineTo(0, Height / 2);

                    Mesh = VertexSourceToMesh.Revolve(path, Sides);
                }
                else
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, -Height / 2);
                    path.LineTo(Diameter / 2, -Height / 2);
                    path.LineTo(DiameterTop / 2, Height / 2);
                    path.LineTo(0, Height / 2);

                    Mesh = VertexSourceToMesh.Revolve(path, Sides, MathHelper.DegreesToRadians(StartingAngle), MathHelper.DegreesToRadians(EndingAngle));
                }

                if (aabb.ZSize > 0)
                {
                    // If the part was already created and at a height, maintain the height.
                    PlatingHelper.PlaceMeshAtHeight(this, aabb.minXYZ.Z);
                }
            }

            Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
        }
Exemplo n.º 20
0
        override public Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                LatitudeSides  = agg_basics.Clamp(LatitudeSides, 3, 180, ref valuesChanged);
                LongitudeSides = agg_basics.Clamp(LongitudeSides, 3, 360, ref valuesChanged);

                using (new CenterAndHeightMantainer(this))
                {
                    var radius     = Diameter / 2;
                    var angleDelta = MathHelper.Tau / 4 / LatitudeSides;
                    var angle      = 0.0;
                    var path       = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                    for (int i = 0; i < LatitudeSides; i++)
                    {
                        angle += angleDelta;
                        path.LineTo(new Vector2(radius * Math.Cos(angle), radius * Math.Sin(angle)));
                    }

                    Mesh = VertexSourceToMesh.Revolve(path, LongitudeSides);
                }
            }

            if (valuesChanged)
            {
                Invalidate(InvalidateType.DisplayValues);
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }
Exemplo n.º 21
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool changed = false;

            using (RebuildLock())
            {
                var sides    = Sides.ClampIfNotCalculated(this, 3, 360, ref changed);
                var diameter = Diameter.ClampIfNotCalculated(this, .01, 1000000, ref changed);
                var height   = Height.ClampIfNotCalculated(this, .01, 1000000, ref changed);
                using (new CenterAndHeightMaintainer(this))
                {
                    var path = new VertexStorage();
                    path.MoveTo(0, 0);
                    path.LineTo(diameter / 2, 0);
                    path.LineTo(0, height);

                    Mesh = VertexSourceToMesh.Revolve(path, sides);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
            return(Task.CompletedTask);
        }
Exemplo n.º 22
0
        public override Task Rebuild()
        {
            this.DebugDepth("Rebuild");
            bool valuesChanged = false;

            using (RebuildLock())
            {
                var outerDiameter = OuterDiameter.Value(this);
                var innerDiameter = InnerDiameter.ClampIfNotCalculated(this, 0, outerDiameter - .1, ref valuesChanged);
                var sides         = Sides.ClampIfNotCalculated(this, 3, 360, ref valuesChanged);
                var startingAngle = StartingAngle.ClampIfNotCalculated(this, 0, 360 - .01, ref valuesChanged);
                var endingAngle   = EndingAngle.ClampIfNotCalculated(this, startingAngle + .01, 360, ref valuesChanged);
                var height        = Height.Value(this);
                var roundSegments = RoundSegments.ClampIfNotCalculated(this, 2, 90, ref valuesChanged);

                using (new CenterAndHeightMaintainer(this, MaintainFlags.Origin | MaintainFlags.Bottom))
                {
                    if (!Advanced)
                    {
                        startingAngle = 0;
                        endingAngle   = 360;
                    }

                    innerDiameter = Math.Min(outerDiameter - .1, innerDiameter);

                    var path  = new VertexStorage();
                    var width = (outerDiameter - innerDiameter) / 2;
                    var r     = innerDiameter / 2;
                    path.MoveTo(r, 0);
                    path.LineTo(r + width, 0);
                    var range = 360 / 4.0;

                    if (!Advanced)
                    {
                        path.LineTo(r + width, height);
                        path.LineTo(r, height);
                    }
                    else
                    {
                        switch (Round)
                        {
                        case RoundTypes.None:
                            path.LineTo(r + width, height);
                            path.LineTo(r, height);
                            break;

                        case RoundTypes.Down:
                            if (Direction == RoundDirection.Inner)
                            {
                                path.LineTo(r + width, height);
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + Math.Cos(rad) * width, height - Math.Sin(rad) * height);
                                }
                            }
                            else
                            {
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + width - Math.Sin(rad) * width, height - Math.Cos(rad) * height);
                                }
                                path.LineTo(r, height);
                            }
                            break;

                        case RoundTypes.Up:
                            if (Direction == RoundDirection.Inner)
                            {
                                path.LineTo(r + width, height);
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + width - Math.Sin(rad) * width, Math.Cos(rad) * height);
                                }
                            }
                            else
                            {
                                for (int i = 1; i < roundSegments - 1; i++)
                                {
                                    var angle = range / (roundSegments - 1) * i;
                                    var rad   = MathHelper.DegreesToRadians(angle);
                                    path.LineTo(r + Math.Cos(rad) * width, Math.Sin(rad) * height);
                                }
                                path.LineTo(r, height);
                            }
                            break;
                        }
                    }

                    var startAngle = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(startingAngle));
                    var endAngle   = MathHelper.Range0ToTau(MathHelper.DegreesToRadians(endingAngle));
                    Mesh = VertexSourceToMesh.Revolve(path, sides, startAngle, endAngle);
                }
            }

            Invalidate(InvalidateType.DisplayValues);

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Mesh));
            return(Task.CompletedTask);
        }