protected IObject3D CreateReach(double reach, double innerDiameter) { var finWidth = 4.0; var finLength = innerDiameter; var pattern = new VertexStorage(); pattern.MoveTo(0, 0); pattern.LineTo(finLength / 2, 0); pattern.LineTo(finLength / 2, reach - finLength / 8); pattern.LineTo(finLength / 2 - finLength / 8, reach); pattern.LineTo(-finLength / 2 + finLength / 8, reach); pattern.LineTo(-finLength / 2, reach - finLength / 8); pattern.LineTo(-finLength / 2, 0); var fin1 = new Object3D() { Mesh = VertexSourceToMesh.Extrude(pattern, finWidth) }; fin1 = new TranslateObject3D(fin1, 0, 0, -finWidth / 2); //fin1.ChamferEdge(Face.Top | Face.Back, finLength / 8); //fin1.ChamferEdge(Face.Top | Face.Front, finLength / 8); fin1 = new RotateObject3D(fin1, -MathHelper.Tau / 4); var fin2 = new SetCenterObject3D(new RotateObject3D(fin1, 0, 0, MathHelper.Tau / 4), fin1.GetCenter()); return(new Object3D().SetChildren(new List <IObject3D>() { fin1, fin2 })); }
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); }
public async Task SubtractTests() { // Subtract has correct number of results { var root = new Object3D(); var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var offsetCubeB = new TranslateObject3D(cubeB, 10); var subtract = new SubtractObject3D(); subtract.Children.Add(cubeA); subtract.Children.Add(offsetCubeB); subtract.SelectedChildren.Add(offsetCubeB.ID); root.Children.Add(subtract); subtract.Subtract(); subtract.Flatten(null); Assert.AreEqual(1, root.Children.Count()); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 0, 10, 10).Equals(rootAabb, .001)); } // make sure the MatterCAD subtract function is working { var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var offsetCubeB = new TranslateObject3D(cubeB, 10); var subtract = cubeA.Minus(offsetCubeB); Assert.AreEqual(0, subtract.Children.Count()); Assert.IsTrue(subtract.Mesh != null); var aabb = subtract.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 0, 10, 10).Equals(aabb, .001)); } }
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 CombineTests() { StartupMC(); // Combine has correct results { var root = new Object3D(); var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var offsetCubeB = new TranslateObject3D(cubeB, 10); Assert.IsTrue(offsetCubeB.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox( 0, -10, -10, 20, 10, 10), .001)); var union = new CombineObject3D_2(); union.Children.Add(cubeA); union.Children.Add(offsetCubeB); root.Children.Add(union); Assert.IsTrue(union.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10), .001)); Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10), .001)); union.Combine(); Assert.IsTrue(union.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10), .001)); union.Flatten(null); Assert.AreEqual(1, root.Children.Count()); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(rootAabb, .001)); } // Combine has correct results when inner content is changed { var root = new Object3D(); var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var union = new CombineObject3D_2(); union.Children.Add(cubeA); union.Children.Add(cubeB); root.Children.Add(union); union.Combine(); Assert.AreEqual(5, root.Descendants().Count()); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 10, 10, 10).Equals(rootAabb, .001)); var offsetCubeB = new TranslateObject3D(cubeB, 10); union.Combine(); Assert.AreEqual(7, root.Descendants().Count()); rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(rootAabb, .001)); } // now make sure undo has the right results for flatten { var root = new Object3D(); var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var offsetCubeB = new TranslateObject3D(cubeB, 10); var combine = new CombineObject3D_2(); combine.Children.Add(cubeA); combine.Children.Add(offsetCubeB); root.Children.Add(combine); Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 cubeB, 4 offset cubeB, 5 offset sourceItem"); combine.Combine(); Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB"); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(rootAabb, .001)); var undoBuffer = new UndoBuffer(); combine.Flatten(undoBuffer); Assert.AreEqual(1, root.Descendants().Count()); Assert.AreEqual(1, root.Children.Count()); rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(rootAabb, .001)); undoBuffer.Undo(); Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB"); } // now make sure undo has the right results for remove { var root = new Object3D(); var cubeA = await CubeObject3D.Create(20, 20, 20); cubeA.Name = "cubeA"; var cubeB = await CubeObject3D.Create(20, 20, 20); cubeB.Name = "cubeB"; var combine = new CombineObject3D_2(); combine.Children.Add(cubeA); combine.Children.Add(cubeB); root.Children.Add(combine); Assert.AreEqual(3, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 cubeB"); combine.Combine(); Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 wrapped cubeB"); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 10, 10, 10).Equals(rootAabb, .001)); var undoBuffer = new UndoBuffer(); combine.Remove(undoBuffer); Assert.AreEqual(2, root.Descendants().Count(), "Should have the 1 cubeA, 2 cubeB"); rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 10, 10, 10).Equals(rootAabb, .001)); undoBuffer.Undo(); Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 wrapped cubeB"); } // now make sure undo has the right results for remove { var root = new Object3D(); var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var offsetCubeB = new TranslateObject3D(cubeB, 10); var combine = new CombineObject3D_2(); combine.Children.Add(cubeA); combine.Children.Add(offsetCubeB); root.Children.Add(combine); Assert.AreEqual(5, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 cubeB, 4 offset cubeB, 5 offset sourceItem"); combine.Combine(); Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB"); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(rootAabb, .001)); var undoBuffer = new UndoBuffer(); combine.Remove(undoBuffer); Assert.AreEqual(4, root.Descendants().Count(), "Should have the 1 cubeA, 2 cubeB, 3 offset cubeB, 4 offset sourceItem"); rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(rootAabb, .001)); undoBuffer.Undo(); Assert.AreEqual(7, root.Descendants().Count(), "Should have the 1 combine, 2 cubeA, 3 wrapped cubeA, 4 cubeB, 5 offset cubeB, 6 offset sourceItem, wrapped cubeB"); } // make sure the MatterCAD add function is working { var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var offsetCubeB = new TranslateObject3D(cubeB, 10); var plus = cubeA.Plus(offsetCubeB, true); Assert.AreEqual(0, plus.Children.Count()); Assert.IsTrue(plus.Mesh != null); var aabb = plus.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(aabb, .001)); } // test single object combine { var root = new Object3D(); var cubeA = await CubeObject3D.Create(20, 20, 20); var cubeB = await CubeObject3D.Create(20, 20, 20); var offsetCubeB = new TranslateObject3D(cubeB, 10); var group = new Object3D(); group.Children.Add(cubeA); group.Children.Add(offsetCubeB); var union = new CombineObject3D_2(); union.Children.Add(group); root.Children.Add(union); union.Combine(); Assert.AreEqual(8, root.Descendants().Count(), "group, union, wa, a, wtb, tb, b"); union.Flatten(null); Assert.AreEqual(1, root.Descendants().Count(), "Should have the union result"); Assert.AreEqual(1, root.Children.Count()); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(new AxisAlignedBoundingBox( -10, -10, -10, 20, 10, 10).Equals(rootAabb, .001)); } }
public async Task AabbCalculatedCorrectlyForPinchedFitObjects() { StartupMC(); // build without pinch { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); root.Children.Add(cube); Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); root.Children.Remove(cube); var fit = await FitToBoundsObject3D_3.Create(cube); fit.Width = 50; fit.Depth = 20; fit.Height = 20; fit.Invalidate(InvalidateType.Properties); root.Children.Add(fit); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001)); } // build with pinch { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_3.Create(cube); fit.Width = 50; fit.Depth = 20; fit.Height = 20; var pinch = new PinchObject3D_3(); pinch.Children.Add(fit); await pinch.Rebuild(); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); } // build with translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); root.Children.Add(translate); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); var pinch = new PinchObject3D_3(); pinch.Children.Add(translate); root.Children.Add(pinch); await pinch.Rebuild(); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_3.Create(cube); fit.Width = 50; fit.Depth = 20; fit.Height = 20; var translate = new TranslateObject3D(fit, 11, 0, 0); var pinch = new PinchObject3D_3(); pinch.Children.Add(translate); await pinch.Rebuild(); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } }
public async Task AabbCalculatedCorrectlyForPinchedFitObjects() { 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.InitPluginFinder(); AppContext.Platform.ProcessCommandline(); // build without pinch { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); root.Children.Add(cube); Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); root.Children.Remove(cube); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; root.Children.Add(fit); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001)); } // build with pinch { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; var pinch = new PinchObject3D_2(); pinch.Children.Add(fit); await pinch.Rebuild(); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); } // build with translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); root.Children.Add(translate); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); var pinch = new PinchObject3D_2(); pinch.Children.Add(translate); root.Children.Add(pinch); await pinch.Rebuild(); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = await CubeObject3D.Create(20, 20, 20); var fit = await FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; var translate = new TranslateObject3D(fit, 11, 0, 0); var pinch = new PinchObject3D_2(); pinch.Children.Add(translate); await pinch.Rebuild(); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } }
public void AabbCalculatedCorrectlyForPinchedFitObjects() { // build without pinch { var root = new Object3D(); var cube = new CubeObject3D(20, 20, 20); root.Children.Add(cube); Assert.IsTrue(root.GetAxisAlignedBoundingBox().Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); root.Children.Remove(cube); var fit = FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; root.Children.Add(fit); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-25, -10, -10), new Vector3(25, 10, 10)), .001)); } // build with pinch { var root = new Object3D(); var cube = new CubeObject3D(20, 20, 20); root.Children.Add(cube); var fit = FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; var pinch = new PinchObject3D(); pinch.Children.Add(fit); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(-10, -10, -10), new Vector3(10, 10, 10)), .001)); } // build with translate { var root = new Object3D(); var cube = new CubeObject3D(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); root.Children.Add(translate); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = new CubeObject3D(20, 20, 20); var translate = new TranslateObject3D(cube, 11, 0, 0); var pinch = new PinchObject3D(); pinch.Children.Add(translate); root.Children.Add(pinch); pinch.Invalidate(new InvalidateArgs(pinch, InvalidateType.Properties)); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } // build with pinch and translate { var root = new Object3D(); var cube = new CubeObject3D(20, 20, 20); var fit = FitToBoundsObject3D_2.Create(cube); fit.SizeX = 50; fit.SizeY = 20; fit.SizeZ = 20; var translate = new TranslateObject3D(fit, 11, 0, 0); var pinch = new PinchObject3D(); pinch.Children.Add(translate); pinch.Invalidate(new InvalidateArgs(pinch, InvalidateType.Properties)); root.Children.Add(pinch); var rootAabb = root.GetAxisAlignedBoundingBox(); Assert.IsTrue(rootAabb.Equals(new AxisAlignedBoundingBox(new Vector3(1, -10, -10), new Vector3(21, 10, 10)), .001)); } }