Example #1
0
		public RotateExtrude(double[] points, double axisOffset = 0, Alignment alignment = Alignment.z, string name = "")
		{
			if ((points.Length % 2) != 0)
			{
				throw new Exception("You must pass in an even number of points so they can be converted to Vector2s.");
			}
			List<Vector2> vectorPoints = new List<Vector2>();
			for (int i = 0; i < points.Length; i += 2)
			{
				vectorPoints.Add(new Vector2(points[i], points[i + 1]));
			}
			root = new RotateExtrudePrimitive(vectorPoints.ToArray(), axisOffset, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.z:
					// don't need to do anything
					break;

				default:
					throw new NotImplementedException();
			}
		}
Example #2
0
		public NGonExtrusion(double radius1, double numSides, double height, Alignment alignment = Alignment.z, string name = "")
			: base(name)
		{
			this.height = height;
			root = new NGonExtrusionPrimitive(radius1, numSides, height, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;
			}
		}
Example #3
0
		public Cylinder(double radius1, double radius2, double height, Alignment alignment = Alignment.z, string name = "")
			: base(name)
		{
			this.height = height;
			root = new CylinderPrimitive(radius1, radius2, height, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;
			}
		}
Example #4
0
		public Torus(double innerRadius, double outerRadius, Alignment alignment = Alignment.z, string name = "")
			: base(name)
		{
			double size = outerRadius - innerRadius;
			List<Vector2> points = new List<Vector2>();

			int numCurvePoints = 32;
			for (int curvePoint = 0; curvePoint <= numCurvePoints; curvePoint++)
			{
				double x = size - Math.Cos((MathHelper.Tau * curvePoint / numCurvePoints)) * size;
				double y = size - Math.Sin((MathHelper.Tau * curvePoint / numCurvePoints)) * size;
				points.Add(new Vector2(x, y));
			}

			root = new RotateExtrude(points.ToArray(), innerRadius, alignment, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.negX:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(-90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.z:
					break;

				case Alignment.negZ:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(180));
					break;

				default:
					throw new NotImplementedException();
			}
		}
Example #5
0
		public RotateExtrude(Vector2[] points, double axisOffset, Alignment alignment = Alignment.z, string name = "")
			: base(name)
		{
			root = new RotateExtrudePrimitive(points, axisOffset, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.negX:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(-90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.z:
					break;

				case Alignment.negZ:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(180));
					break;

				default:
					throw new NotImplementedException();
			}
		}
Example #6
0
		/// <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.");
			}
		}
Example #7
0
		/// <summary>
		/// The constructor takes an array of doubles as the input to the polygon to extrude.
		/// </summary>
		/// <param name="points">Pairs of double values that will be used as the coordinates of the polygon points.</param>
		/// <param name="height"></param>
		/// <param name="alignment"></param>
		/// <param name="twistRadians"></param>
		/// <param name="name"></param>
		public LinearExtrude(double[] points, double height, Alignment alignment = Alignment.z, double twistRadians = 0, string name = "")
		{
			if ((points.Length % 2) != 0)
			{
				throw new Exception("You must pass in an even number of points so they can be converted to Vector2s.");
			}
			List<Vector2> vectorPoints = new List<Vector2>();
			for (int i = 0; i < points.Length; i += 2)
			{
				vectorPoints.Add(new Vector2(points[i], points[i + 1]));
			}
			root = new LinearExtrudePrimitive(vectorPoints.ToArray(), height, twistRadians, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;
			}
		}
Example #8
0
		/// <summary>
		/// The constructor takes an array of Vector2s as the input to the polygon to extrude.
		/// </summary>
		/// <param name="points"></param>
		/// <param name="height"></param>
		/// <param name="alignment"></param>
		/// <param name="twistRadians"></param>
		/// <param name="name"></param>
		public LinearExtrude(Vector2[] points, double height, Alignment alignment = Alignment.z, double twistRadians = 0, string name = "")
			: base(name)
		{
			root = new LinearExtrudePrimitive(points, height, twistRadians, name);
			switch (alignment)
			{
				case Alignment.x:
					root = new Rotate(root, y: MathHelper.DegreesToRadians(90));
					break;

				case Alignment.y:
					root = new Rotate(root, x: MathHelper.DegreesToRadians(90));
					break;
			}
		}