Пример #1
0
 private static IObject3D PlaceOnBase(IObject3D logoBase, IObject3D imageObject)
 {
     if (imageObject != null)
     {
         // put it at the right height
         imageObject = new AlignObject3D(imageObject, FaceAlign.Bottom, logoBase, FaceAlign.Top);
         // move it to the base center
         imageObject = new TranslateObject3D(imageObject, -new Vector3(logoBase.GetCenter().X, logoBase.GetCenter().Y, 0));
     }
     return(imageObject);
 }
Пример #2
0
        public async Task AabbCalculatedCorrectlyForAlignedFitObject()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";

            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var root = new Object3D();
            var cube = await CubeObject3D.Create(20, 20, 20);

            var fit = await FitToBoundsObject3D_2.Create(cube);

            fit.SizeX = 10;
            fit.SizeY = 10;
            fit.SizeZ = 6;

            Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-5, -5, -10), new Vector3(5, 5, -4)), .01));

            var bigCube = await CubeObject3D.Create(20, 20, 20);

            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .01));

            var align = new AlignObject3D();

            align.Children.Add(bigCube);
            align.Children.Add(fit);

            await align.Rebuild();

            align.XAlign   = Align.Center;
            align.YAlign   = Align.Center;
            align.ZAlign   = Align.Max;
            align.Advanced = true;
            align.ZOffset  = 1;

            await align.Rebuild();

            var alignAabb = align.GetAxisAlignedBoundingBox();

            Assert.IsTrue(alignAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));

            alignAabb = align.GetAxisAlignedBoundingBox();
            root.Children.Add(align);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));
        }
Пример #3
0
        public async override Task Rebuild()
        {
            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    // validate the some of the values and store in user data if changed
                    InnerDiameter = ValidateValue(InnerDiameter, "PipeWorksInnerDiameter", 15);
                    OuterDiameter = ValidateValue(OuterDiameter, "PipeWorksOuterDiameter", 20);
                    BottomReach   = ValidateValue(BottomReach, "PipeWorksBottomReach", 30);
                    FrontReach    = ValidateValue(FrontReach, "PipeWorksFrontReach", 25);
                    TopReach      = ValidateValue(TopReach, "PipeWorksTopReach", 30);

                    IObject3D topBottomConnect = await CylinderObject3D.Create(OuterDiameter, OuterDiameter, Sides, Alignment.Y);

                    IObject3D frontConnect = await CylinderObject3D.Create(OuterDiameter, OuterDiameter, Sides, Alignment.X);

                    frontConnect = new AlignObject3D(frontConnect, FaceAlign.Right, topBottomConnect, FaceAlign.Right);

                    IObject3D bottomReach = new RotateObject3D(CreateReach(BottomReach, InnerDiameter), -MathHelper.Tau / 4);
                    bottomReach = new AlignObject3D(bottomReach, FaceAlign.Back, topBottomConnect, FaceAlign.Front, 0, .02);

                    IObject3D topReach = new RotateObject3D(CreateReach(TopReach, InnerDiameter), MathHelper.Tau / 4);
                    topReach = new AlignObject3D(topReach, FaceAlign.Front, topBottomConnect, FaceAlign.Back, 0, -.02);

                    IObject3D frontReach = new RotateObject3D(CreateReach(FrontReach, InnerDiameter), 0, -MathHelper.Tau / 4);
                    frontReach = new AlignObject3D(frontReach, FaceAlign.Left, topBottomConnect, FaceAlign.Right, -.02);

                    // output multiple meshes for pipe connector
                    this.Children.Modify(list =>
                    {
                        list.Clear();
                        list.Add(topBottomConnect);
                        list.Add(frontConnect);
                        list.Add(bottomReach);
                        list.Add(topReach);
                        list.Add(frontReach);
                    });

                    this.Color = Color.Transparent;
                    this.Mesh  = null;
                }
            }

            Invalidate(InvalidateType.Children);
        }
        public async Task AabbCalculatedCorrectlyForAlignedFitObject()
        {
            StartupMC();

            var root = new Object3D();
            var cube = await CubeObject3D.Create(20, 20, 20);

            var fit = await FitToBoundsObject3D_3.Create(cube);

            fit.Width  = 10;
            fit.Depth  = 10;
            fit.Height = 6;
            fit.Invalidate(InvalidateType.Properties);

            Assert.IsTrue(fit.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-5, -5, -10), new Vector3(5, 5, -4)), .01));

            var bigCube = await CubeObject3D.Create(20, 20, 20);

            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .01));

            var align = new AlignObject3D();

            align.Children.Add(bigCube);
            align.Children.Add(fit);

            await align.Rebuild();

            align.XAlign   = Align.Center;
            align.YAlign   = Align.Center;
            align.ZAlign   = Align.Max;
            align.Advanced = true;
            align.ZOffset  = 1;

            await align.Rebuild();

            var alignAabb = align.GetAxisAlignedBoundingBox();

            Assert.IsTrue(alignAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));

            alignAabb = align.GetAxisAlignedBoundingBox();
            root.Children.Add(align);
            var rootAabb = root.GetAxisAlignedBoundingBox();

            Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 11)), .01));
        }
Пример #5
0
        public override Task Rebuild()
        {
            IObject3D cancerRibbonStl = Object3D.Load("Cancer_Ribbon.stl", CancellationToken.None);

            cancerRibbonStl = new RotateObject3D(cancerRibbonStl, MathHelper.DegreesToRadians(90));

            var letterPrinter = new TypeFacePrinter(NameToWrite.ToUpper(), new StyledTypeFace(ApplicationController.GetTypeFace(Font), 12));

            IObject3D nameMesh = new Object3D()
            {
                Mesh = VertexSourceToMesh.Extrude(letterPrinter, 5)
            };

            AxisAlignedBoundingBox textBounds = nameMesh.GetAxisAlignedBoundingBox();
            var textArea = new Vector2(25, 6);

            double scale = Math.Min(textArea.X / textBounds.XSize, textArea.Y / textBounds.YSize);

            nameMesh = new ScaleObject3D_3(nameMesh, scale, scale, 2 / textBounds.ZSize);
            nameMesh = new AlignObject3D(nameMesh, FaceAlign.Bottom | FaceAlign.Front, cancerRibbonStl, FaceAlign.Top | FaceAlign.Front, 0, 0, -1);
            nameMesh = new SetCenterObject3D(nameMesh, cancerRibbonStl.GetCenter(), true, false, false);

            nameMesh = new RotateObject3D(nameMesh, 0, 0, MathHelper.DegreesToRadians(50));
            nameMesh = new TranslateObject3D(nameMesh, -37, -14, -1);

            // output two meshes for card holder and text
            this.Children.Modify(list =>
            {
                list.Clear();
                list.Add(cancerRibbonStl);
                list.Add(nameMesh);
            });

            this.Mesh = null;
            this.Invalidate(InvalidateType.Children);
            return(Task.CompletedTask);
        }
        public async Task AlignObjectHasCorrectPositionsOnXAxis()
        {
            StartupMC();

            var scene = new InteractiveScene();

            var cube = await CubeObject3D.Create(20, 20, 20);

            cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            scene.Children.Add(cube);

            var bigCube = await CubeObject3D.Create(40, 40, 40);

            bigCube.Matrix = Matrix4X4.CreateTranslation(20, 20, 20);
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
            scene.Children.Add(bigCube);

            // select them
            scene.SelectedItem = cube;
            scene.AddToSelection(bigCube);

            // create an align of them
            var align = new AlignObject3D();

            align.AddSelectionAsChildren(scene, scene.SelectedItem);

            var unalignedBounds = align.GetAxisAlignedBoundingBox();

            // assert the align in built correctly
            Assert.AreEqual(1, scene.Children.Count);
            Assert.AreEqual(2, align.Children.Count);
            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(60, 70, 40)), 1.0));

            align.SelectedChild = new SelectedChildren()
            {
                cube.ID.ToString()
            };

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn align on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // turn it off
            align.XAlign = Align.None;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn it back on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // remove the align and assert stuff moved back to where it started
            align.Remove(null);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
        }
Пример #7
0
        public override async Task Rebuild()
        {
            this.DebugDepth("Rebuild");

            using (RebuildLock())
            {
                var currentAssetPath = ImageObject == null?AggContext.StaticData.ToAssetPath(Path.Combine("Images", "mh-logo.png")) : ImageObject.AssetPath;

                this.Children.Modify((list) =>
                {
                    list.Clear();
                });

                var imageObject = new ImageObject3D()
                {
                    AssetPath = currentAssetPath,
                };

                await imageObject.Rebuild();

                this.Children.Add(imageObject);

                IObject3D logoBase = new CylinderObject3D(outerDiameter, 3, 60);
                IObject3D logoRing = new AlignObject3D(new RingObject3D(outerDiameter, innerDiameter, 2, 60), FaceAlign.Bottom, logoBase, FaceAlign.Top);

                IObject3D coinBlank = logoBase.Plus(logoRing);
                if (CreateHook)
                {
                    var cube = await CubeObject3D.Create(4, 2, 4);

                    IObject3D connect = logoBase.Plus(new AlignObject3D(cube, FaceAlign.Front | FaceAlign.Bottom, logoBase, FaceAlign.Back | FaceAlign.Bottom, 0, -.5));
                    IObject3D hook    = logoBase.Plus(new AlignObject3D(new RingObject3D(10, 7, 5, 30), FaceAlign.Front | FaceAlign.Bottom, connect, FaceAlign.Back | FaceAlign.Bottom, 0, -.5));

                    coinBlank = coinBlank.Plus(connect);
                    coinBlank = coinBlank.Plus(hook);
                }

                var imageToPath = new ImageToPathObject3D();

                imageToPath.Children.Add(imageObject);

                await imageToPath.Rebuild();

                var inputShape = imageToPath.VertexSource;

                if (Inflate != 0)
                {
                    var bounds = inputShape.GetBounds();
                    var scale  = Math.Max(bounds.Width, bounds.Height) / (17 * 4);
                    inputShape = inputShape.Offset(Inflate * scale);
                }

                if (AlternateCentering)
                {
                    inputShape = new VertexSourceApplyTransform(inputShape, GetCenteringTransformVisualCenter(inputShape, innerDiameter / 2));
                }
                else
                {
                    inputShape = new VertexSourceApplyTransform(inputShape, GetCenteringTransformExpandedToRadius(inputShape, innerDiameter / 2));
                }

                if (ScalePercent != 100 &&
                    ScalePercent != 0)
                {
                    inputShape = new VertexSourceApplyTransform(inputShape, Affine.NewScaling(ScalePercent / 100.0));
                }

                if (NegativeSpace)
                {
                    var disk = new Ellipse(0, 0, innerDiameter / 2 + .2, innerDiameter / 2 + .2)
                    {
                        ResolutionScale = 1000
                    };
                    inputShape = disk.Minus(inputShape);
                }

                imageToPath.VertexSource = inputShape;

                var pathExtrusion = new LinearExtrudeObject3D();
                pathExtrusion.Children.Add(imageToPath);
                await pathExtrusion.Rebuild();

                IObject3D extrusionObject = imageObject;

                var loadingScale = 32 / extrusionObject.XSize();
                extrusionObject = new ScaleObject3D(extrusionObject, loadingScale, loadingScale, 1 / extrusionObject.ZSize());
                extrusionObject = PlaceOnBase(logoBase, extrusionObject);

                this.Children.Add(coinBlank);
                this.Children.Add(extrusionObject);
            }

            Invalidate(InvalidateType.Mesh);
        }
Пример #8
0
        public async Task AlignObjectHasCorrectPositionsOnXAxis()
        {
            AggContext.StaticData = new FileSystemStaticData(TestContext.CurrentContext.ResolveProjectPath(4, "StaticData"));
            MatterControlUtilities.OverrideAppDataLocation(TestContext.CurrentContext.ResolveProjectPath(4));

            // Automation runner must do as much as program.cs to spin up platform
            string platformFeaturesProvider = "MatterHackers.MatterControl.WindowsPlatformsFeatures, MatterControl.Winforms";

            AppContext.Platform = AggContext.CreateInstanceFrom <INativePlatformFeatures>(platformFeaturesProvider);
            AppContext.Platform.ProcessCommandline();

            var scene = new InteractiveScene();

            var cube = await CubeObject3D.Create(20, 20, 20);

            cube.Matrix = Matrix4X4.CreateTranslation(50, 60, 10);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            scene.Children.Add(cube);

            var bigCube = await CubeObject3D.Create(40, 40, 40);

            bigCube.Matrix = Matrix4X4.CreateTranslation(20, 20, 20);
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
            scene.Children.Add(bigCube);

            // select them
            scene.SelectedItem = cube;
            scene.AddToSelection(bigCube);

            // create an align of them
            var align = new AlignObject3D();

            align.AddSelectionAsChildren(scene, scene.SelectedItem);

            var unalignedBounds = align.GetAxisAlignedBoundingBox();

            // assert the align in built correctly
            Assert.AreEqual(1, scene.Children.Count);
            Assert.AreEqual(2, align.Children.Count);
            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(60, 70, 40)), 1.0));

            align.SelectedChild = new SelectedChildren()
            {
                cube.ID.ToString()
            };

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn align on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // turn it off
            align.XAlign = Align.None;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(unalignedBounds, 1.0));

            // turn it back on
            align.XAlign = Align.Min;
            await align.Rebuild();

            Assert.IsTrue(align.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 0, 0), new Vector3(80, 70, 40)), 1.0));

            // remove the align and assert stuff moved back to where it started
            align.Remove(null);
            Assert.IsTrue(cube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(40, 50, 0), new Vector3(60, 70, 20)), .01));
            Assert.IsTrue(bigCube.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(0, 0, 0), new Vector3(40, 40, 40)), .01));
        }
Пример #9
0
        override public Task Rebuild()
        {
            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify(list =>
                    {
                        list.Clear();
                    });

                    var brailleText = TextToEncode;
                    if (UseGrade2)
                    {
                        brailleText = BrailleGrade2.ConvertString(brailleText);
                    }

                    double    pointSize  = 18.5;
                    double    pointsToMm = 0.352778;
                    IObject3D textObject = new Object3D();
                    var       offest     = 0.0;

                    TypeFacePrinter textPrinter;
                    if (RenderAsBraille)
                    {
                        textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(typeFace, pointSize));
                    }
                    else
                    {
                        textPrinter = new TypeFacePrinter(brailleText, new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
                    }

                    foreach (var letter in brailleText.ToCharArray())
                    {
                        IObject3D       letterObject;
                        TypeFacePrinter letterPrinter;
                        if (RenderAsBraille)
                        {
                            letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(typeFace, pointSize));
                            var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));

                            // add all the spheres to letterObject
                            letterObject = new Object3D();

                            var vertexCount  = 0;
                            var positionSum  = Vector2.Zero;
                            var lastPosition = Vector2.Zero;
                            // find each dot outline and get it's center and place a sphere there
                            foreach (var vertex in scalledLetterPrinter.Vertices())
                            {
                                switch (vertex.command)
                                {
                                case Agg.ShapePath.FlagsAndCommand.Stop:
                                case Agg.ShapePath.FlagsAndCommand.EndPoly:
                                case Agg.ShapePath.FlagsAndCommand.FlagClose:
                                case Agg.ShapePath.FlagsAndCommand.MoveTo:
                                    if (vertexCount > 0)
                                    {
                                        var    center = positionSum / vertexCount;
                                        double radius = 1.44 / 2;                                                // (center - lastPosition).Length;
                                        var    sphere = new HalfSphereObject3D(radius * 2, 15)
                                        {
                                            Color = Color.LightBlue
                                        };
                                        sphere.Translate(center.X, center.Y);
                                        letterObject.Children.Add(sphere);
                                    }
                                    vertexCount = 0;
                                    positionSum = Vector2.Zero;
                                    break;

                                case Agg.ShapePath.FlagsAndCommand.Curve3:
                                case Agg.ShapePath.FlagsAndCommand.Curve4:
                                case Agg.ShapePath.FlagsAndCommand.LineTo:
                                    vertexCount++;
                                    lastPosition = vertex.position;
                                    positionSum += lastPosition;
                                    break;
                                }
                            }
                        }
                        else
                        {
                            letterPrinter = new TypeFacePrinter(letter.ToString(), new StyledTypeFace(ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono), pointSize));
                            var scalledLetterPrinter = new VertexSourceApplyTransform(letterPrinter, Affine.NewScaling(pointsToMm));
                            letterObject = new Object3D()
                            {
                                Mesh  = VertexSourceToMesh.Extrude(scalledLetterPrinter, 1),
                                Color = Color.LightBlue
                            };
                        }

                        letterObject.Matrix = Matrix4X4.CreateTranslation(offest, 0, 0);
                        textObject.Children.Add(letterObject);

                        offest += letterPrinter.GetSize(letter.ToString()).X *pointsToMm;
                    }

                    // add a plate under the dots
                    var padding = .9 * pointSize * pointsToMm / 2;
                    var size    = textPrinter.LocalBounds * pointsToMm;

                    // make the base
                    var basePath = new VertexStorage();
                    basePath.MoveTo(0, 0);
                    basePath.LineTo(size.Width + padding, 0);
                    basePath.LineTo(size.Width + padding, size.Height + padding);
                    basePath.LineTo(padding, size.Height + padding);
                    basePath.LineTo(0, size.Height);

                    IObject3D basePlate = new Object3D()
                    {
                        Mesh = VertexSourceToMesh.Extrude(basePath, BaseHeight)
                    };

                    basePlate = new AlignObject3D(basePlate, FaceAlign.Top, textObject, FaceAlign.Bottom, 0, 0, .01);
                    basePlate = new AlignObject3D(basePlate, FaceAlign.Left | FaceAlign.Front,
                                                  size.Left - padding / 2,
                                                  size.Bottom - padding / 2);
                    this.Children.Add(basePlate);

                    basePlate.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);

                    // add an optional chain hook
                    if (AddHook)
                    {
                        // x 10 to make it smoother
                        double        edgeWidth      = 3;
                        double        height         = basePlate.ZSize();
                        IVertexSource leftSideObject = new RoundedRect(0, 0, height / 2, height, 0)
                        {
                            ResolutionScale = 10
                        };

                        IVertexSource cicleObject = new Ellipse(0, 0, height / 2, height / 2)
                        {
                            ResolutionScale = 10
                        };

                        cicleObject = new Align2D(cicleObject, Side2D.Left | Side2D.Bottom, leftSideObject, Side2D.Left | Side2D.Bottom, -.01);
                        IVertexSource holeObject = new Ellipse(0, 0, height / 2 - edgeWidth, height / 2 - edgeWidth)
                        {
                            ResolutionScale = 10
                        };
                        holeObject = new SetCenter2D(holeObject, cicleObject.GetBounds().Center);

                        IVertexSource hookPath = leftSideObject.Plus(cicleObject);
                        hookPath = hookPath.Minus(holeObject);

                        IObject3D chainHook = new Object3D()
                        {
                            Mesh   = VertexSourceToMesh.Extrude(hookPath, BaseHeight),
                            Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
                        };

                        chainHook = new AlignObject3D(chainHook, FaceAlign.Left | FaceAlign.Bottom | FaceAlign.Back, basePlate, FaceAlign.Right | FaceAlign.Bottom | FaceAlign.Back, -.01);

                        this.Children.Add(chainHook);
                    }

                    // add the object that is the dots
                    this.Children.Add(textObject);
                    textObject.Matrix *= Matrix4X4.CreateRotationX(MathHelper.Tau / 4);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
            return(Task.CompletedTask);
        }
Пример #10
0
        public override async Task Rebuild()
        {
            using (RebuildLock())
            {
                using (new CenterAndHeightMaintainer(this))
                {
                    // validate the some of the values and store in user data if changed
                    InnerDiameter = ValidateValue(InnerDiameter, "PipeWorksInnerDiameter", 15);
                    OuterDiameter = ValidateValue(OuterDiameter, "PipeWorksOuterDiameter", 20);
                    BottomReach   = ValidateValue(BottomReach, "PipeWorksBottomReach", 30);
                    FrontReach    = ValidateValue(FrontReach, "PipeWorksFrontReach", 25);

                    IObject3D bottomReach  = new RotateObject3D(CreateReach(BottomReach, InnerDiameter), -MathHelper.Tau / 4);
                    IObject3D frontReach   = null;
                    IObject3D elbowConnect = null;
                    if (Angle < 90)
                    {
                        frontReach = bottomReach.Clone();

                        var translate = new Vector3(-OuterDiameter / 2, 0, 0);
                        bottomReach.Translate(translate);

                        frontReach = new RotateObject3D(frontReach, 0, 0, -MathHelper.DegreesToRadians(Angle));
                        translate  = Vector3Ex.Transform(-translate, Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(Angle)));
                        frontReach.Translate(translate);

                        var torus = new TorusObject3D();

                        using (torus.RebuildLock())
                        {
                            torus.Advanced      = true;
                            torus.InnerDiameter = 0;
                            OuterDiameter       = OuterDiameter * 2;
                            torus.RingSides     = Sides;
                            torus.Sides         = Sides;
                            torus.StartingAngle = Angle;
                            torus.EndingAngle   = 180;
                        }

                        torus.Invalidate(new InvalidateArgs(torus, InvalidateType.Properties));
                        elbowConnect = torus;
                    }
                    else if (Angle < 270)
                    {
                        bottomReach.Translate(0, -OuterDiameter / 2, 0);
                        IObject3D reachConnect = await CylinderObject3D.Create(OuterDiameter, OuterDiameter, Sides, Alignment.Y);

                        reachConnect = new AlignObject3D(reachConnect, FaceAlign.Front, bottomReach, FaceAlign.Back);
                        reachConnect = new SetCenterObject3D(reachConnect, bottomReach.GetCenter(), true, false, true);
                        bottomReach  = bottomReach.Plus(reachConnect);

                        frontReach = bottomReach.Clone();
                        frontReach = new RotateObject3D(frontReach, 0, 0, -MathHelper.DegreesToRadians(Angle));

                        elbowConnect = new SphereObject3D(OuterDiameter, Sides);
                    }

                    // output multiple meshes for pipe connector
                    this.Children.Modify(list =>
                    {
                        list.Clear();
                        list.Add(elbowConnect);
                        list.Add(bottomReach);
                        list.Add(frontReach);
                    });

                    this.Color = Color.Transparent;
                    this.Mesh  = null;
                }
            }

            Invalidate(InvalidateType.Children);
        }
Пример #11
0
        public override async Task Rebuild()
        {
            using (RebuildLock())
            {
                using (new CenterAndHeightMantainer(this))
                {
                    this.Children.Modify(list =>
                    {
                        list.Clear();
                    });

                    var brailleLetter = new BrailleObject3D()
                    {
                        TextToEncode = Letter.ToString(),
                        BaseHeight   = BaseHeight,
                    };
                    await brailleLetter.Rebuild();

                    this.Children.Add(brailleLetter);

                    var textObject = new TextObject3D()
                    {
                        PointSize   = 46,
                        Color       = Color.LightBlue,
                        NameToWrite = Letter.ToString(),
                        Height      = BaseHeight
                    };

                    await textObject.Rebuild();

                    IObject3D letterObject = new RotateObject3D_2(textObject, Vector3.UnitX, -90);
                    await letterObject.Rebuild();

                    var scaleRatio = Math.Max(letterObject.XSize() / 17, letterObject.ZSize() / 17);
                    if (scaleRatio > 1)
                    {
                        letterObject = new ScaleObject3D(letterObject, 1.0 / scaleRatio, 1, 1.0 / scaleRatio);
                    }
                    letterObject = new AlignObject3D(letterObject, FaceAlign.Bottom | FaceAlign.Front, brailleLetter, FaceAlign.Top | FaceAlign.Front, 0, 0, 3.5);
                    letterObject = new SetCenterObject3D(letterObject, brailleLetter.GetCenter(), true, false, false);
                    this.Children.Add(letterObject);

                    var basePath = new RoundedRect(0, 0, 22, 34, 3)
                    {
                        ResolutionScale = 10
                    };

                    IObject3D basePlate = new Object3D()
                    {
                        Mesh   = VertexSourceToMesh.Extrude(basePath, BaseHeight),
                        Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
                    };

                    basePlate = new AlignObject3D(basePlate, FaceAlign.Bottom | FaceAlign.Back, brailleLetter, FaceAlign.Bottom | FaceAlign.Back);
                    basePlate = new SetCenterObject3D(basePlate, brailleLetter.GetCenter(), true, false, false);
                    this.Children.Add(basePlate);

                    IObject3D underline = await CubeObject3D.Create(basePlate.XSize(), .2, 1);

                    underline = new AlignObject3D(underline, FaceAlign.Bottom, brailleLetter, FaceAlign.Top);
                    underline = new AlignObject3D(underline, FaceAlign.Back | FaceAlign.Left, basePlate, FaceAlign.Front | FaceAlign.Left, 0, .01);
                    this.Children.Add(underline);
                }
            }

            Parent?.Invalidate(new InvalidateArgs(this, InvalidateType.Children));
        }
Пример #12
0
        public void Rebuild(UndoBuffer undoBuffer)
        {
            using (RebuildLock())
            {
                var aabb = this.GetAxisAlignedBoundingBox();

                this.Children.Modify(list =>
                {
                    list.Clear();
                });

                var brailleLetter = new BrailleObject3D()
                {
                    TextToEncode = Letter.ToString(),
                    BaseHeight   = BaseHeight,
                };
                brailleLetter.Rebuild(null);
                this.Children.Add(brailleLetter);

                var textObject = new TextObject3D()
                {
                    PointSize   = 46,
                    Color       = Color.LightBlue,
                    NameToWrite = Letter.ToString(),
                    Height      = BaseHeight
                };

                textObject.Invalidate(new InvalidateArgs(textObject, InvalidateType.Properties, null));
                IObject3D letterObject = new RotateObject3D(textObject, MathHelper.Tau / 4);
                letterObject = new AlignObject3D(letterObject, FaceAlign.Bottom | FaceAlign.Front, brailleLetter, FaceAlign.Top | FaceAlign.Front, 0, 0, 3.5);
                letterObject = new SetCenterObject3D(letterObject, brailleLetter.GetCenter(), true, false, false);
                this.Children.Add(letterObject);

                var basePath = new RoundedRect(0, 0, 22, 34, 3)
                {
                    ResolutionScale = 10
                };

                IObject3D basePlate = new Object3D()
                {
                    Mesh   = VertexSourceToMesh.Extrude(basePath, BaseHeight),
                    Matrix = Matrix4X4.CreateRotationX(MathHelper.Tau / 4)
                };

                basePlate = new AlignObject3D(basePlate, FaceAlign.Bottom | FaceAlign.Back, brailleLetter, FaceAlign.Bottom | FaceAlign.Back);
                basePlate = new SetCenterObject3D(basePlate, brailleLetter.GetCenter(), true, false, false);
                this.Children.Add(basePlate);

                IObject3D underline = new CubeObject3D(basePlate.XSize(), .2, 1);
                underline = new AlignObject3D(underline, FaceAlign.Bottom, brailleLetter, FaceAlign.Top);
                underline = new AlignObject3D(underline, FaceAlign.Back | FaceAlign.Left, basePlate, FaceAlign.Front | FaceAlign.Left, 0, .01);
                this.Children.Add(underline);

                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.Content));
        }