コード例 #1
0
ファイル: CsgTests.cs プロジェクト: larsbrubaker/agg-sharp
        public void SubtractionMakesClosedSolid()
        {
            double XOffset = -.4;

            MatterHackers.Csg.CsgObject boxCombine = new MatterHackers.Csg.Solids.Box(10, 10, 10);
            boxCombine -= new MatterHackers.Csg.Transform.Translate(new MatterHackers.Csg.Solids.Box(10, 10, 10), XOffset, -3, 2);
            Mesh result = RenderOpenGl.CsgToMesh.Convert(boxCombine);

            Assert.IsTrue(result.IsManifold());
        }
コード例 #2
0
ファイル: Box.cs プロジェクト: glocklueng/agg-sharp
		/// <summary>
		/// Cun along the diagonal of a give edge to the opposite edge.  The edge is chosen by saying
		/// which 2 faces are to be kept solid, and or-ing them together.
		/// </summary>
		/// <param name="facesThatShareEdge">The two faces to maintain after the cut, or-ed together with '|'.</param>
		public void CutAlongDiagonal(Face facesToKeepWhole)
		{
			switch (facesToKeepWhole)
			{
				case (Face.Left | Face.Back):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1, 1.1, createCentered: false);
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, 0, MathHelper.Tau / 8));
						boxToCutOut = new Translate(boxToCutOut, x: Math.Sqrt(2) / 2, y: -Math.Sqrt(2) / 2, z: -.05);
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Left | Face.Front):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1, 1.1, createCentered: false);
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, 0, -MathHelper.Tau / 8));
						boxToCutOut = new Translate(boxToCutOut, y: 1, z: -.05);
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOutLeftFront");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Left | Face.Bottom):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1.1, 1, createCentered: false);
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, MathHelper.Tau / 8, 0));
						boxToCutOut = new Translate(boxToCutOut, y: -.05, z: 1);
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Right | Face.Front):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1, 1.1, createCentered: false, name: "boxtToCutOut");
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, 0, MathHelper.Tau / 8));
						boxToCutOut = new Translate(boxToCutOut, z: -.05);
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOutRightFront");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Right | Face.Bottom):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1.1, 1, createCentered: false, name: "boxToCutOut");
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, -MathHelper.Tau / 8, 0));
						boxToCutOut = new Translate(boxToCutOut, 0, -.05, 0);
						//boxToCutOut = new Translate(boxToCutOut, Math.Sqrt(2) / 2, 0, -Math.Sqrt(2) / 2);
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Right | Face.Top):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(Math.Sqrt(2), 1.1, 1, createCentered: false, name: "boxToCutOut");
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(0, MathHelper.Tau / 8, 0));
						boxToCutOut = new Translate(boxToCutOut, -Math.Sqrt(2) / 2, 0, 1 - Math.Sqrt(2) / 2);
						boxToCutOut = new Scale(boxToCutOut, size, name: "botToCutOut");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Front | Face.Top):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false, name: "boxToCutOut");
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(MathHelper.Tau / 8, 0, 0));
						boxToCutOut = new Translate(boxToCutOut, -.05, Math.Sqrt(2) / 2, -Math.Sqrt(2) / 2);
						boxToCutOut = new Scale(boxToCutOut, size);
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Front | Face.Bottom):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false, name: "boxToCutOut");
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(-MathHelper.Tau / 8, 0, 0));
						boxToCutOut = new Translate(boxToCutOut, -.05, 0, 1);
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxtToCutOutFrontBottom");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Bottom | Face.Back):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false);
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(MathHelper.Tau / 8, 0, 0));
						boxToCutOut = new Translate(boxToCutOut, x: -.05);
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut");
						root = new Difference(root, boxToCutOut);
					}
					break;

				case (Face.Back | Face.Top):
					{
						Vector3 size = root.Size;
						CsgObject boxToCutOut = new Box(1.1, Math.Sqrt(2), 1, createCentered: false, name: "boxToCutOut");
						boxToCutOut = new Rotate(boxToCutOut, new Vector3(-MathHelper.Tau / 8, 0, 0));
						boxToCutOut = new Translate(boxToCutOut, x: -.05, y: -Math.Sqrt(2) / 2, z: .28); // TODO: do the right math. .28 is hacky
						boxToCutOut = new Scale(boxToCutOut, size, name: "boxToCutOut");
						root = new Difference(root, boxToCutOut);
					}
					break;

				default:
					throw new NotImplementedException("Just write it for this case.");
			}
		}