コード例 #1
0
ファイル: Round.cs プロジェクト: glocklueng/agg-sharp
		public void RoundEdge(Edge edgeToRound, double radius, double extraDimension = defaultExtraDimension)
		{
			if (roundedEdges.ContainsKey(edgeToRound))
			{
				return;
			}
			CsgObject newRound = null;
			double radiusBoxSize = radius + extraDimension;
			switch (edgeToRound)
			{
				case Edge.LeftFront:
					{
						double zSize = size.z + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
						CsgObject frontTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
						frontTopCut = new Align(frontTopCut, Face.Left | Face.Front, newRound, Face.Left | Face.Front, extraDimension, extraDimension, 0);
						newRound -= frontTopCut;
						newRound = new Align(newRound, Face.Left | Face.Front, GetEdgeOffset(Face.Left | Face.Front), -extraDimension, -extraDimension, 0);
					}
					break;

				case Edge.LeftBack:
					{
						double zSize = size.z + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
						CsgObject BackTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
						BackTopCut = new Align(BackTopCut, Face.Left | Face.Back, newRound, Face.Left | Face.Back, extraDimension, -extraDimension, 0);
						newRound -= BackTopCut;
						newRound = new Align(newRound, Face.Left | Face.Back, GetEdgeOffset(Face.Left | Face.Back), -extraDimension, extraDimension, 0);
					}
					break;

				case Edge.LeftTop:
					{
						double ySize = size.y + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
						CsgObject frontTopCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
						frontTopCut = new Align(frontTopCut, Face.Left | Face.Top, newRound, Face.Left | Face.Top, extraDimension, 0, -extraDimension);
						newRound -= frontTopCut;
						newRound = new Align(newRound, Face.Left | Face.Top, GetEdgeOffset(Face.Left | Face.Top), -extraDimension, 0, extraDimension);
					}
					break;

				case Edge.LeftBottom:
					{
						double ySize = size.y + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
						CsgObject frontTopCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
						frontTopCut = new Align(frontTopCut, Face.Left | Face.Bottom, newRound, Face.Left | Face.Bottom, extraDimension, 0, extraDimension);
						newRound -= frontTopCut;
						newRound = new Align(newRound, Face.Left | Face.Bottom, GetEdgeOffset(Face.Left | Face.Bottom), -extraDimension, 0, -extraDimension);
					}
					break;

				case Edge.RightFront:
					{
						double zSize = size.z + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
						CsgObject frontTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
						frontTopCut = new Align(frontTopCut, Face.Right | Face.Front, newRound, Face.Right | Face.Front, -extraDimension, extraDimension, 0);
						newRound -= frontTopCut;
						newRound = new Align(newRound, Face.Right | Face.Front, GetEdgeOffset(Face.Right | Face.Front), extraDimension, -extraDimension, 0);
					}
					break;

				case Edge.RightTop:
					{
						double ySize = size.y + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
						CsgObject frontTopCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
						frontTopCut = new Align(frontTopCut, Face.Right | Face.Top, newRound, Face.Right | Face.Top, -extraDimension, 0, -extraDimension);
						newRound -= frontTopCut;
						newRound = new Align(newRound, Face.Right | Face.Top, GetEdgeOffset(Face.Right | Face.Top), extraDimension, 0, extraDimension);
					}
					break;

				case Edge.RightBottom:
					{
						double ySize = size.y + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
						CsgObject frontBottomCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
						frontBottomCut = new Align(frontBottomCut, Face.Right | Face.Bottom, newRound, Face.Right | Face.Bottom, -extraDimension, 0, extraDimension);
						newRound -= frontBottomCut;
						newRound = new Align(newRound, Face.Right | Face.Bottom, GetEdgeOffset(Face.Right | Face.Bottom), extraDimension, 0, -extraDimension);
					}
					break;

				case Edge.RightBack:
					{
						double zSize = size.z + 2 * extraDimension;
						newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
						CsgObject BackTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
						BackTopCut = new Align(BackTopCut, Face.Right | Face.Back, newRound, Face.Right | Face.Back, -extraDimension, -extraDimension, 0);
						newRound -= BackTopCut;
						newRound = new Align(newRound, Face.Right | Face.Back, GetEdgeOffset(Face.Right | Face.Back), extraDimension, extraDimension, 0);
					}
					break;

				case Edge.FrontTop:
					{
						double xSize = size.x + 2 * extraDimension;
						newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
						CsgObject frontTopCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
						frontTopCut = new Align(frontTopCut, Face.Front | Face.Top, newRound, Face.Front | Face.Top, 0, extraDimension, -extraDimension);
						newRound -= frontTopCut;
						newRound = new Align(newRound, Face.Front | Face.Top, GetEdgeOffset(Face.Front | Face.Top), 0, -extraDimension, extraDimension);
					}
					break;

				case Edge.FrontBottom:
					{
						double xSize = size.x + 2 * extraDimension;
						newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
						CsgObject frontTopCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
						frontTopCut = new Align(frontTopCut, Face.Front | Face.Bottom, newRound, Face.Front | Face.Bottom, 0, extraDimension, extraDimension);
						newRound -= frontTopCut;
						newRound = new Align(newRound, Face.Front | Face.Bottom, GetEdgeOffset(Face.Front | Face.Bottom), 0, -extraDimension, -extraDimension);
					}
					break;

				case Edge.BackBottom:
					{
						double xSize = size.x + 2 * extraDimension;
						newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
						CsgObject backBottomCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
						backBottomCut = new Align(backBottomCut, Face.Back | Face.Bottom, newRound, Face.Back | Face.Bottom, 0, -extraDimension, extraDimension);
						newRound -= backBottomCut;
						newRound = new Align(newRound, Face.Back | Face.Bottom, GetEdgeOffset(Face.Back | Face.Bottom), 0, extraDimension, -extraDimension);
					}
					break;

				case Edge.BackTop:
					{
						double xSize = size.x + 2 * extraDimension;
						newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
						CsgObject backTopCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
						backTopCut = new Align(backTopCut, Face.Back | Face.Top, newRound, Face.Back | Face.Top, 0, -extraDimension, -extraDimension);
						newRound -= backTopCut;
						newRound = new Align(newRound, Face.Back | Face.Top, GetEdgeOffset(Face.Back | Face.Top), 0, extraDimension, extraDimension);
					}
					break;

				default:
					throw new NotImplementedException("Don't know how to round " + edgeToRound.ToString());
			}

			if (root is Box)
			{
				root = newRound;
			}
			else
			{
				root += newRound;
			}

			roundedEdges.Add(edgeToRound, radius);

			CheckCornersAndRoundIfNeeded(extraDimension);
		}
コード例 #2
0
        public void RoundEdge(Edge edgeToRound, double radius, double extraDimension = defaultExtraDimension)
        {
            if (roundedEdges.ContainsKey(edgeToRound))
            {
                return;
            }
            CsgObject newRound      = null;
            double    radiusBoxSize = radius + extraDimension;

            switch (edgeToRound)
            {
            case Edge.LeftFront:
            {
                double zSize = size.z + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
                CsgObject frontTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
                frontTopCut = new Align(frontTopCut, Face.Left | Face.Front, newRound, Face.Left | Face.Front, extraDimension, extraDimension, 0);
                newRound   -= frontTopCut;
                newRound    = new Align(newRound, Face.Left | Face.Front, GetEdgeOffset(Face.Left | Face.Front), -extraDimension, -extraDimension, 0);
            }
            break;

            case Edge.LeftBack:
            {
                double zSize = size.z + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
                CsgObject BackTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
                BackTopCut = new Align(BackTopCut, Face.Left | Face.Back, newRound, Face.Left | Face.Back, extraDimension, -extraDimension, 0);
                newRound  -= BackTopCut;
                newRound   = new Align(newRound, Face.Left | Face.Back, GetEdgeOffset(Face.Left | Face.Back), -extraDimension, extraDimension, 0);
            }
            break;

            case Edge.LeftTop:
            {
                double ySize = size.y + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
                CsgObject frontTopCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
                frontTopCut = new Align(frontTopCut, Face.Left | Face.Top, newRound, Face.Left | Face.Top, extraDimension, 0, -extraDimension);
                newRound   -= frontTopCut;
                newRound    = new Align(newRound, Face.Left | Face.Top, GetEdgeOffset(Face.Left | Face.Top), -extraDimension, 0, extraDimension);
            }
            break;

            case Edge.LeftBottom:
            {
                double ySize = size.y + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
                CsgObject frontTopCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
                frontTopCut = new Align(frontTopCut, Face.Left | Face.Bottom, newRound, Face.Left | Face.Bottom, extraDimension, 0, extraDimension);
                newRound   -= frontTopCut;
                newRound    = new Align(newRound, Face.Left | Face.Bottom, GetEdgeOffset(Face.Left | Face.Bottom), -extraDimension, 0, -extraDimension);
            }
            break;

            case Edge.RightFront:
            {
                double zSize = size.z + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
                CsgObject frontTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
                frontTopCut = new Align(frontTopCut, Face.Right | Face.Front, newRound, Face.Right | Face.Front, -extraDimension, extraDimension, 0);
                newRound   -= frontTopCut;
                newRound    = new Align(newRound, Face.Right | Face.Front, GetEdgeOffset(Face.Right | Face.Front), extraDimension, -extraDimension, 0);
            }
            break;

            case Edge.RightTop:
            {
                double ySize = size.y + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
                CsgObject frontTopCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
                frontTopCut = new Align(frontTopCut, Face.Right | Face.Top, newRound, Face.Right | Face.Top, -extraDimension, 0, -extraDimension);
                newRound   -= frontTopCut;
                newRound    = new Align(newRound, Face.Right | Face.Top, GetEdgeOffset(Face.Right | Face.Top), extraDimension, 0, extraDimension);
            }
            break;

            case Edge.RightBottom:
            {
                double ySize = size.y + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, ySize, radiusBoxSize);
                CsgObject frontBottomCut = new Cylinder(radius, ySize + extraDimension * 2, Alignment.y);
                frontBottomCut = new Align(frontBottomCut, Face.Right | Face.Bottom, newRound, Face.Right | Face.Bottom, -extraDimension, 0, extraDimension);
                newRound      -= frontBottomCut;
                newRound       = new Align(newRound, Face.Right | Face.Bottom, GetEdgeOffset(Face.Right | Face.Bottom), extraDimension, 0, -extraDimension);
            }
            break;

            case Edge.RightBack:
            {
                double zSize = size.z + 2 * extraDimension;
                newRound = new Box(radiusBoxSize, radiusBoxSize, zSize);
                CsgObject BackTopCut = new Cylinder(radius, zSize + extraDimension * 2, Alignment.z);
                BackTopCut = new Align(BackTopCut, Face.Right | Face.Back, newRound, Face.Right | Face.Back, -extraDimension, -extraDimension, 0);
                newRound  -= BackTopCut;
                newRound   = new Align(newRound, Face.Right | Face.Back, GetEdgeOffset(Face.Right | Face.Back), extraDimension, extraDimension, 0);
            }
            break;

            case Edge.FrontTop:
            {
                double xSize = size.x + 2 * extraDimension;
                newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
                CsgObject frontTopCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
                frontTopCut = new Align(frontTopCut, Face.Front | Face.Top, newRound, Face.Front | Face.Top, 0, extraDimension, -extraDimension);
                newRound   -= frontTopCut;
                newRound    = new Align(newRound, Face.Front | Face.Top, GetEdgeOffset(Face.Front | Face.Top), 0, -extraDimension, extraDimension);
            }
            break;

            case Edge.FrontBottom:
            {
                double xSize = size.x + 2 * extraDimension;
                newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
                CsgObject frontTopCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
                frontTopCut = new Align(frontTopCut, Face.Front | Face.Bottom, newRound, Face.Front | Face.Bottom, 0, extraDimension, extraDimension);
                newRound   -= frontTopCut;
                newRound    = new Align(newRound, Face.Front | Face.Bottom, GetEdgeOffset(Face.Front | Face.Bottom), 0, -extraDimension, -extraDimension);
            }
            break;

            case Edge.BackBottom:
            {
                double xSize = size.x + 2 * extraDimension;
                newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
                CsgObject backBottomCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
                backBottomCut = new Align(backBottomCut, Face.Back | Face.Bottom, newRound, Face.Back | Face.Bottom, 0, -extraDimension, extraDimension);
                newRound     -= backBottomCut;
                newRound      = new Align(newRound, Face.Back | Face.Bottom, GetEdgeOffset(Face.Back | Face.Bottom), 0, extraDimension, -extraDimension);
            }
            break;

            case Edge.BackTop:
            {
                double xSize = size.x + 2 * extraDimension;
                newRound = new Box(xSize, radiusBoxSize, radiusBoxSize);
                CsgObject backTopCut = new Cylinder(radius, xSize + extraDimension * 2, Alignment.x);
                backTopCut = new Align(backTopCut, Face.Back | Face.Top, newRound, Face.Back | Face.Top, 0, -extraDimension, -extraDimension);
                newRound  -= backTopCut;
                newRound   = new Align(newRound, Face.Back | Face.Top, GetEdgeOffset(Face.Back | Face.Top), 0, extraDimension, extraDimension);
            }
            break;

            default:
                throw new NotImplementedException("Don't know how to round " + edgeToRound.ToString());
            }

            if (root is Box)
            {
                root = newRound;
            }
            else
            {
                root += newRound;
            }

            roundedEdges.Add(edgeToRound, radius);

            CheckCornersAndRoundIfNeeded(extraDimension);
        }
コード例 #3
0
ファイル: CopyAndFlatten.cs プロジェクト: jeske/agg-sharp
 public CsgObject DoCopyAndFlatten(Cylinder.CylinderPrimitive objectToProcess)
 {
     return new Cylinder.CylinderPrimitive(objectToProcess);
 }
コード例 #4
0
		public string GetScadOutputRecursive(Cylinder.CylinderPrimitive objectToProcess, int level = 0)
		{
			string info = AddRenderInfoIfReqired(objectToProcess);

			info += "cylinder(r1=" + objectToProcess.Radius1.ToString() + ", r2=" + objectToProcess.Radius2.ToString() + ", h=" + objectToProcess.Height.ToString() + ", center=true, $fn={0});".FormatWith(NumberOfCylinderSegments) + AddNameAsComment(objectToProcess);

			return ApplyIndent(info, level);
		}
コード例 #5
0
ファイル: CsgToMesh.cs プロジェクト: glocklueng/agg-sharp
		public PolygonMesh.Mesh CsgToMeshRecursive(Cylinder.CylinderPrimitive objectToProcess)
		{
			return CreateCylinder(objectToProcess);
		}
コード例 #6
0
ファイル: CsgToMesh.cs プロジェクト: glocklueng/agg-sharp
		public static PolygonMesh.Mesh CreateCylinder(Cylinder.CylinderPrimitive cylinderToMeasure)
		{
			PolygonMesh.Mesh cylinder = new PolygonMesh.Mesh();
			List<Vertex> bottomVerts = new List<Vertex>();
			List<Vertex> topVerts = new List<Vertex>();

			int count = 20;
			for (int i = 0; i < count; i++)
			{
				Vector2 bottomRadialPos = Vector2.Rotate(new Vector2(cylinderToMeasure.Radius1, 0), MathHelper.Tau * i / 20);
				Vertex bottomVertex = cylinder.CreateVertex(new Vector3(bottomRadialPos.x, bottomRadialPos.y, -cylinderToMeasure.Height / 2));
				bottomVerts.Add(bottomVertex);
				Vector2 topRadialPos = Vector2.Rotate(new Vector2(cylinderToMeasure.Radius1, 0), MathHelper.Tau * i / 20);
				Vertex topVertex = cylinder.CreateVertex(new Vector3(topRadialPos.x, topRadialPos.y, cylinderToMeasure.Height / 2));
				topVerts.Add(topVertex);
			}

			cylinder.ReverseFaceEdges(cylinder.CreateFace(bottomVerts.ToArray()));
			cylinder.CreateFace(topVerts.ToArray());

			for (int i = 0; i < count - 1; i++)
			{
				cylinder.CreateFace(new Vertex[] { topVerts[i], bottomVerts[i], bottomVerts[i + 1], topVerts[i + 1] });
			}
			cylinder.CreateFace(new Vertex[] { topVerts[count - 1], bottomVerts[count - 1], bottomVerts[0], topVerts[0] });

			return cylinder;
		}
コード例 #7
0
		public IPrimitive GetIPrimitiveRecursive(Cylinder.CylinderPrimitive objectToProcess)
		{
			return new CylinderShape(objectToProcess.Radius1, objectToProcess.Height, DefaultMaterial);
		}
コード例 #8
0
ファイル: RenderCsgToGl.cs プロジェクト: jeske/agg-sharp
 public void RenderToGlRecursive(Cylinder.CylinderPrimitive objectToProcess)
 {
     RGBA_Floats partColor = new RGBA_Floats(.8, .8, 1);
     RenderMeshToGl.Render(CreateCylinder(objectToProcess), partColor);
 }