Esempio n. 1
0
		public Union(CsgObject a, CsgObject b, string name = "")
			: base(name)
		{
			if (a is Union)
			{
				foreach (CsgObject objectsFromUnion in ((Union)a).allObjects)
				{
					allObjects.Add(objectsFromUnion);
				}
			}
			else
			{
				allObjects.Add(a);
			}
			if (b is Union)
			{
				foreach (CsgObject objectsFromUnion in ((Union)b).allObjects)
				{
					allObjects.Add(objectsFromUnion);
				}
			}
			else
			{
				allObjects.Add(b);
			}
		}
Esempio n. 2
0
		public Align(CsgObject objectToAlign, Face boundingFacesToAlign, Vector3 positionToAlignTo, string name = "")
			: base(objectToAlign, positionToAlignTo, name)
		{
			AxisAlignedBoundingBox bounds = objectToAlign.GetAxisAlignedBoundingBox();

			if (IsSet(boundingFacesToAlign, Face.Left, Face.Right))
			{
				positionToAlignTo.x = positionToAlignTo.x - bounds.minXYZ.x;
			}
			if (IsSet(boundingFacesToAlign, Face.Right, Face.Left))
			{
				positionToAlignTo.x = positionToAlignTo.x - bounds.minXYZ.x - (bounds.maxXYZ.x - bounds.minXYZ.x);
			}
			if (IsSet(boundingFacesToAlign, Face.Front, Face.Back))
			{
				positionToAlignTo.y = positionToAlignTo.y - bounds.minXYZ.y;
			}
			if (IsSet(boundingFacesToAlign, Face.Back, Face.Front))
			{
				positionToAlignTo.y = positionToAlignTo.y - bounds.minXYZ.y - (bounds.maxXYZ.y - bounds.minXYZ.y);
			}
			if (IsSet(boundingFacesToAlign, Face.Bottom, Face.Top))
			{
				positionToAlignTo.z = positionToAlignTo.z - bounds.minXYZ.z;
			}
			if (IsSet(boundingFacesToAlign, Face.Top, Face.Bottom))
			{
				positionToAlignTo.z = positionToAlignTo.z - bounds.minXYZ.z - (bounds.maxXYZ.z - bounds.minXYZ.z);
			}

			base.Translation = positionToAlignTo;
		}
Esempio n. 3
0
		public static void Save(CsgObject objectToProcess, string fileName, string prepend = "")
		{
			FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write);

			Save(objectToProcess, file, prepend);
			file.Close();
		}
Esempio n. 4
0
		public static void Save(CsgObject objectToProcess, Stream stream, string prepend = "")
		{
			StreamWriter sw = new StreamWriter(stream);
			string fileString = GetScadString(objectToProcess, prepend);

			sw.Write(fileString);
			sw.Close();
		}
Esempio n. 5
0
		public Align(CsgObject objectToAlign, Face boundingFacesToAlign, CsgObject objectToAlignTo, Face boundingFacesToAlignTo, double offsetX = 0, double offsetY = 0, double offsetZ = 0, string name = "")
			: this(objectToAlign, boundingFacesToAlign, GetPositionToAlignTo(objectToAlignTo, boundingFacesToAlignTo, new Vector3(offsetX, offsetY, offsetZ)), name)
		{
			if (objectToAlign == objectToAlignTo)
			{
				throw new Exception("You cannot align an object ot itself.");
			}
		}
		static public void Save(CsgObject objectToProcess, string nameWeAreLookingFor, string fileName, bool outputAsScad)
		{
			FileStream file = new FileStream(fileName, FileMode.Create, FileAccess.Write);
			StreamWriter sw = new StreamWriter(file);

			OutputNamedCenters visitor = new OutputNamedCenters(nameWeAreLookingFor, outputAsScad);
			string fileString = visitor.LookForNamedPartRecursive((dynamic)objectToProcess, Matrix4X4.Identity);

			sw.Write(fileString);
			sw.Close();
			file.Close();
		}
Esempio n. 7
0
		public Difference(CsgObject primary, CsgObject subtract, string name = "")
			: base(name)
		{
			if (primary is Difference)
			{
				this.primary = ((Difference)primary).primary;
				foreach (CsgObject subtractObject in ((Difference)primary).allSubtracts)
				{
					allSubtracts.Add(subtractObject);
				}
			}
			else
			{
				this.primary = primary;
			}
			allSubtracts.Add(subtract);
		}
Esempio n. 8
0
		public SetCenter(CsgObject objectToCenter, Vector3 offset, bool onX = true, bool onY = true, bool onZ = true, string name = "")
			: base(objectToCenter, offset, name)
		{
			AxisAlignedBoundingBox bounds = objectToCenter.GetAxisAlignedBoundingBox();
			Vector3 center = (bounds.maxXYZ + bounds.minXYZ) / 2;

			Vector3 origin = Vector3.Zero; // zero out anything we don't want
			if (onX)
			{
				origin.x = offset.x - center.x;
			}
			if (onY)
			{
				origin.y = offset.y - center.y;
			}
			if (onZ)
			{
				origin.z = offset.z - center.z;
			}

			base.Translation = origin;
		}
Esempio n. 9
0
 public TransformBase(CsgObject objectToTransform, string name = "")
     : this(objectToTransform, Matrix4X4.Identity, name)
 {
 }
Esempio n. 10
0
        public static void Render(CsgObject objectToProcess)
        {
            RenderCsgToGl visitor = new RenderCsgToGl();

            visitor.RenderToGlRecursive((dynamic)objectToProcess);
        }
Esempio n. 11
0
 public Align(CsgObject objectToAlign, Face boundingFacesToAlign, Vector3 positionToAlignTo, double offsetX, double offsetY, double offsetZ, string name = "")
     : this(objectToAlign, boundingFacesToAlign, positionToAlignTo + new Vector3(offsetX, offsetY, offsetZ), name)
 {
 }
Esempio n. 12
0
 public Rotate(CsgObject objectToRotate, double x = 0, double y = 0, double z = 0, string name = "")
     : this(objectToRotate, new Vector3(x, y, z), name)
 {
 }
Esempio n. 13
0
 public string GetScadOutputRecursive(CsgObject objectToProcess, int level = 0)
 {
     throw new Exception("You must write the specialized function for this type.");
 }
Esempio n. 14
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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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, Sides, 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);
        }
Esempio n. 15
0
 public SetCenter(CsgObject objectToCenter, double x = 0, double y = 0, double z = 0, bool onX = true, bool onY = true, bool onZ = true, string name = "")
     : this(objectToCenter, new Vector3(x, y, z), onX, onY, onZ, name)
 {
 }
Esempio n. 16
0
 public Rotate(CsgObject objectToRotate, Vector3 radians, string name = "")
     : base(objectToRotate, name)
 {
     rotateCache = radians;
     transform = Matrix4X4.CreateRotation(radians);
 }
        public static CsgObject SimplePartFunction()
        {
            double    pcbHoldLip  = 2;
            double    standYDepth = 8;
            double    pcbYDepth   = 2;
            CsgObject pcbTotal;

            CsgObject pcbBottom = new Box(23, pcbYDepth, 40);

            pcbTotal = pcbBottom;

            CsgObject pcbMid = new Box(30, pcbYDepth, 34.5);

            pcbMid    = new Align(pcbMid, Face.Top, pcbBottom, Face.Top);
            pcbMid    = new SetCenter(pcbMid, pcbBottom.GetCenter(), true, false, false);
            pcbTotal += pcbMid;

            CsgObject pcbTop = new Box(64.5, pcbYDepth, 21.5);

            pcbTop    = new Align(pcbTop, Face.Top, pcbBottom, Face.Top);
            pcbTop    = new SetCenter(pcbTop, pcbBottom.GetCenter(), true, false, false);
            pcbTotal += pcbTop;

            Box standBaseBox = new Box(pcbTop.XSize + 2 * (standYDepth - pcbHoldLip), 37, standYDepth);
            //standBaseBox.BevelFace(Face.Top, 3);
            //standBaseBox.BevelEdge(Face.Left | Face.Front, 3);
            //standBaseBox.BevelEdge(Face.Left | Face.Back, 3);
            //standBaseBox.BevelEdge(Face.Right | Face.Front, 3);
            //standBaseBox.BevelEdge(Face.Right | Face.Back, 3);
            CsgObject standBase  = standBaseBox;
            CsgObject standTotal = standBase;

            Box standSideSupportLeftBox = new Box(standYDepth, standYDepth, pcbBottom.ZSize + standBase.ZSize - 10);
            //standSideSupportLeftBox.BevelEdge(Face.Left | Face.Front, 3);
            //standSideSupportLeftBox.BevelEdge(Face.Left | Face.Back, 3);
            //standSideSupportLeftBox.BevelEdge(Face.Left | Face.Top, 3);
            //standSideSupportLeftBox.BevelEdge(Face.Right | Face.Front, 1);
            //standSideSupportLeftBox.BevelEdge(Face.Right | Face.Back, 1);
            CsgObject standSideSupportLeft = standSideSupportLeftBox;

            standSideSupportLeft = new SetCenter(standSideSupportLeft, standBase.GetCenter(), false, true, false);
            standSideSupportLeft = new Align(standSideSupportLeft, Face.Bottom | Face.Left, standBase, Face.Bottom | Face.Left);
            standTotal          += standSideSupportLeft;

            Box insideBevelLeftBox = new Box(standYDepth, standYDepth, standYDepth);

            insideBevelLeftBox.CutAlongDiagonal(Face.Left | Face.Bottom);
            CsgObject insideBevelLeft = insideBevelLeftBox;

            insideBevelLeft = new Align(insideBevelLeft, Face.Left | Face.Front, standSideSupportLeft, Face.Right | Face.Front, -1, 0, -.1);
            insideBevelLeft = new Align(insideBevelLeft, Face.Bottom, standBase, Face.Top);
            standTotal     += insideBevelLeft;

            Box standSideSupportRightBox = new Box(standYDepth, standYDepth, pcbBottom.ZSize + standBase.ZSize - 10);
            //standSideSupportRightBox.BevelEdge(Face.Right | Face.Front, 3);
            //standSideSupportRightBox.BevelEdge(Face.Right | Face.Back, 3);
            //standSideSupportRightBox.BevelEdge(Face.Right | Face.Top, 3);
            //standSideSupportRightBox.BevelEdge(Face.Left | Face.Front, 1);
            //standSideSupportRightBox.BevelEdge(Face.Left | Face.Back, 1);
            CsgObject standSideSupportRight = standSideSupportRightBox;

            standSideSupportRight = new SetCenter(standSideSupportRight, standBase.GetCenter(), false, true, false);
            standSideSupportRight = new Align(standSideSupportRight, Face.Bottom | Face.Right, standBase, Face.Bottom | Face.Right);
            standTotal           += standSideSupportRight;

            Box insideBevelRightBox = new Box(standYDepth, standYDepth, standYDepth);

            insideBevelRightBox.CutAlongDiagonal(Face.Right | Face.Bottom);
            CsgObject insideBevelRight = insideBevelRightBox;

            insideBevelRight = new Align(insideBevelRight, Face.Right | Face.Front, standSideSupportRight, Face.Left | Face.Front, 1, 0, -.1);
            insideBevelRight = new Align(insideBevelRight, Face.Bottom, standBase, Face.Top);
            standTotal      += insideBevelRight;

            CsgObject ringCutOut = new Cylinder(11, 6, Alignment.y);

            ringCutOut  = new SetCenter(ringCutOut, standBase.GetCenter());
            ringCutOut  = new Align(ringCutOut, Face.Bottom | Face.Back, standBase, Face.Top | Face.Front, 0, 5.9, -4);
            standTotal -= ringCutOut;

            pcbTotal    = new SetCenter(pcbTotal, standBase.GetCenter(), true, true, false);
            pcbTotal    = new Align(pcbTotal, Face.Bottom, standBase, Face.Top, offsetZ: -pcbHoldLip);
            standTotal -= pcbTotal;

            return(standTotal);
        }
Esempio n. 18
0
		public static Vector3 GetPositionToAlignTo(CsgObject objectToAlignTo, Face boundingFacesToAlignTo, Vector3 extraOffset)
		{
			Vector3 positionToAlignTo = new Vector3();
			if (IsSet(boundingFacesToAlignTo, Face.Left, Face.Right))
			{
				positionToAlignTo.x = objectToAlignTo.GetAxisAlignedBoundingBox().minXYZ.x;
			}
			if (IsSet(boundingFacesToAlignTo, Face.Right, Face.Left))
			{
				positionToAlignTo.x = objectToAlignTo.GetAxisAlignedBoundingBox().maxXYZ.x;
			}
			if (IsSet(boundingFacesToAlignTo, Face.Front, Face.Back))
			{
				positionToAlignTo.y = objectToAlignTo.GetAxisAlignedBoundingBox().minXYZ.y;
			}
			if (IsSet(boundingFacesToAlignTo, Face.Back, Face.Front))
			{
				positionToAlignTo.y = objectToAlignTo.GetAxisAlignedBoundingBox().maxXYZ.y;
			}
			if (IsSet(boundingFacesToAlignTo, Face.Bottom, Face.Top))
			{
				positionToAlignTo.z = objectToAlignTo.GetAxisAlignedBoundingBox().minXYZ.z;
			}
			if (IsSet(boundingFacesToAlignTo, Face.Top, Face.Bottom))
			{
				positionToAlignTo.z = objectToAlignTo.GetAxisAlignedBoundingBox().maxXYZ.z;
			}
			return positionToAlignTo + extraOffset;
		}
Esempio n. 19
0
		public Align(CsgObject objectToAlign, Face boundingFacesToAlign, Vector3 positionToAlignTo, double offsetX, double offsetY, double offsetZ, string name = "")
			: this(objectToAlign, boundingFacesToAlign, positionToAlignTo + new Vector3(offsetX, offsetY, offsetZ), name)
		{
		}
 public IPrimitive GetIPrimitiveRecursive(CsgObject objectToProcess)
 {
     throw new Exception("You must write the specialized function for this type.");
 }
Esempio n. 21
0
 public void RenderToGlRecursive(CsgObject objectToProcess)
 {
     throw new Exception("You must write the specialized function for this type.");
 }
Esempio n. 22
0
 static public CsgObject ProcessObject(CsgObject objectToCopyAndFlatten)
 {
     CopyAndFlatten instance = new CopyAndFlatten();
     return instance.DoCopyAndFlatten((dynamic)objectToCopyAndFlatten);
 }
Esempio n. 23
0
		public void Add(CsgObject objectToAdd)
		{
			allObjects.Add(objectToAdd);
		}
Esempio n. 24
0
		public static CsgObject CreateFillet(CsgObject objectA, Face faceA, CsgObject objectB, Face faceB, double radius, double extraDimension = defaultExtraDimension)
		{
			int centralAxis = 0; // we start defaulted to x
			switch ((Edge)(faceA | faceB))
			{
				case Edge.LeftTop:
				case Edge.LeftBottom:
				case Edge.RightTop:
				case Edge.RightBottom:
					centralAxis = 1; // y axis
					break;

				case Edge.LeftFront:
				case Edge.LeftBack:
				case Edge.RightFront:
				case Edge.RightBack:
					centralAxis = 2; // z axis
					break;
			}

			AxisAlignedBoundingBox boundsA = objectA.GetAxisAlignedBoundingBox();
			AxisAlignedBoundingBox boundsB = objectB.GetAxisAlignedBoundingBox();

			double maxMin = Math.Max(boundsA.minXYZ[centralAxis], boundsB.minXYZ[centralAxis]);
			double minMax = Math.Min(boundsA.maxXYZ[centralAxis], boundsB.maxXYZ[centralAxis]);
			if (maxMin >= minMax)
			{
				throw new ArgumentException("Your two objects must overlap to have a fillet be created.");
			}

			Vector3 size = new Vector3(radius, radius, radius);
			size[centralAxis] = minMax - maxMin;
			Round newFilletRound = new Round(size);

			Face faceToGetBevelFor = CsgObject.GetOposite(faceA) | CsgObject.GetOposite(faceB);
			newFilletRound.RoundEdge((Edge)faceToGetBevelFor, radius, extraDimension);

			CsgObject newFillet = new SetCenter(newFilletRound, objectA.GetCenter());
			newFillet = new Align(newFillet, CsgObject.GetOposite(faceA), objectA, faceA);
			newFillet = new Align(newFillet, CsgObject.GetOposite(faceB), objectB, faceB);

			return newFillet;
		}
Esempio n. 25
0
		public SetCenter(CsgObject objectToCenter, double x = 0, double y = 0, double z = 0, bool onX = true, bool onY = true, bool onZ = true, string name = "")
			: this(objectToCenter, new Vector3(x, y, z), onX, onY, onZ, name)
		{
		}
Esempio n. 26
0
		public Scale(CsgObject objectToScale, double x, double y, double z, string name = "")
			: this(objectToScale, new Vector3(x, y, z), name)
		{
		}
Esempio n. 27
0
 public Intersection(CsgObject a, CsgObject b, string name = "")
     : base(name)
 {
     this.a = a;
     this.b = b;
 }
Esempio n. 28
0
        //private static CsgObject AtomDiagram()
        //{

        //}

        private static CsgObject SingleComposition()
        {
            //TODO: make some bounds on how crazy or tame this goes with relative sizes...IE does the main thing
            //get more or less emphasis?
            CsgObject returnMe = null;
            Union     u        = new Union();

            CsgObject box = new Box(new Vector3(150, 150, 150));

            int whichOne                 = _rand.Next(2);
            List <CsgObject> unions      = new List <CsgObject>();
            List <CsgObject> differences = new List <CsgObject>();

            //TODO: Order prolly matters here? Maybe? So right now we're gonna build lists, do unions, then
            //do differences. Maybe later we should do it in whatever order they happen in, or at least
            //consider it...

            //foreach (Vector3 corner in )
            //{
            //int which = _rand.Next(2);
            //switch (which)
            //{
            //	case 0:
            //		solid = new Box(new Vector3(150, 150, 150));
            //		break;
            //	case 1:
            //		solid = new Sphere(150);
            //		break;
            //	default:
            //		solid = new Box(new Vector3(150, 150, 150));
            //		break;
            //}
            //}

            u.Add(box as CsgObject);

            double averageSize = (box.XSize + box.YSize + box.ZSize) / 3.0;

            List <Vector3> boxVertexes = new List <Vector3>();

            Vector3 boxCenter = box.GetCenter();
            double  halfX     = box.XSize / 2;
            double  halfY     = box.YSize / 2;
            double  halfZ     = box.ZSize / 2;

            for (int i = 0; i < 2; i++)
            {
                double x = -1 * halfX + i * box.XSize;
                for (int j = 0; j < 2; j++)
                {
                    double y = -1 * halfY + j * box.YSize;
                    for (int k = 0; k < 2; k++)
                    {
                        double  z         = -1 * halfZ + k * box.ZSize;
                        Vector3 newVertex = new Vector3(x, y, z);
                        boxVertexes.Add(newVertex);
                    }
                }
            }

            foreach (Vector3 attachPoint in boxVertexes)
            {
                CsgObject joinThis = null;
                double    doWhat   = _rand.NextDouble();
                if (doWhat < 0.33)
                {
                    joinThis = GimmeAPrimitive(GimmeABoundedDouble(averageSize * 0.25, averageSize * 0.75), attachPoint);
                    differences.Add(joinThis);
                }
                else if (doWhat < 0.85)
                {
                    joinThis = GimmeAPrimitive(GimmeABoundedDouble(averageSize * 0.25, averageSize * 0.75), attachPoint);
                    unions.Add(joinThis);
                }
                else
                {
                    joinThis = null;
                }
            }

            foreach (var thing in unions)
            {
                u.Add(thing);
                returnMe = u;
            }
            if (differences.Count > 0)
            {
                Difference d = new Difference(returnMe, differences[0]);
                for (int i = 1; i < differences.Count; i++)
                {
                    d.AddToSubtractList(differences[i]);
                }
                returnMe = d;
            }



            return(returnMe);
        }
Esempio n. 29
0
 public TransformBase(CsgObject objectToTransform, Matrix4X4 transform, string name = "")
     : base(name)
 {
     this.transform = transform;
     this.objectToTransform = objectToTransform;
 }
Esempio n. 30
0
 public Align(CsgObject objectToAlign, Face boundingFacesToAlign, double offsetX = 0, double offsetY = 0, double offsetZ = 0, string name = "")
     : this(objectToAlign, boundingFacesToAlign, new Vector3(offsetX, offsetY, offsetZ), name)
 {
 }
Esempio n. 31
0
		protected string AddNameAsComment(CsgObject objectToProcess)
		{
			if (objectToProcess.Name != "")
			{
				return " // " + objectToProcess.Name;
			}

			return "";
		}
Esempio n. 32
0
 public Rotate(CsgObject objectToRotate, Vector3 radians, string name = "")
     : base(objectToRotate, name)
 {
     rotateCache = radians;
     transform   = Matrix4X4.CreateRotation(radians);
 }
Esempio n. 33
0
 public TransformBase(CsgObject objectToTransform, Matrix4X4 transform, string name = "")
     : base(name)
 {
     this.transform         = transform;
     this.objectToTransform = objectToTransform;
 }
Esempio n. 34
0
		public Difference(CsgObject primary, string name = "")
			: base(name)
		{
			this.primary = primary;
		}
Esempio n. 35
0
		public string GetScadOutputRecursive(CsgObject objectToProcess, int level = 0)
		{
			throw new Exception("You must wirte the specialized function for this type.");
		}
Esempio n. 36
0
		public void AddToSubtractList(CsgObject objectToAddToSubtractList)
		{
			allSubtracts.Add(objectToAddToSubtractList);
		}
Esempio n. 37
0
 public string LookForNamedPartRecursive(CsgObject objectToProcess, Matrix4X4 accumulatedMatrix)
 {
     throw new Exception("You must write the specialized function for this type.");
 }
Esempio n. 38
0
 public TransformBase(CsgObject objectToTransform, string name = "")
     : this(objectToTransform, Matrix4X4.Identity, name)
 {
 }
Esempio n. 39
0
 public void Add(CsgObject objectToAdd)
 {
     allObjects.Add(objectToAdd);
 }
Esempio n. 40
0
		private string AddRenderInfoIfReqired(CsgObject objectToProcess)
		{
			string info = "";
			if (objectToProcess.Name.Length > 0 && (objectToProcess.Name[0] == '#' || objectToProcess.Name[0] == '%'))
			{
				info = objectToProcess.Name[0] + " ";
			}

			return info;
		}
Esempio n. 41
0
        public static PolygonMesh.Mesh Convert(CsgObject objectToProcess)
        {
            CsgToMesh visitor = new CsgToMesh();

            return(visitor.CsgToMeshRecursive((dynamic)objectToProcess));
        }
Esempio n. 42
0
 public PolygonMesh.Mesh CsgToMeshRecursive(CsgObject objectToProcess)
 {
     throw new Exception("You must write the specialized function for this type.");
 }
Esempio n. 43
0
 public Intersection(CsgObject a, CsgObject b, string name = "")
     : base(name)
 {
     this.a = a;
     this.b = b;
 }
Esempio n. 44
0
		public static string GetScadString(CsgObject objectToProcess, string prepend = "")
		{
			OpenSCadOutput visitor = new OpenSCadOutput();
			return prepend + visitor.GetScadOutputRecursive((dynamic)objectToProcess);
		}
Esempio n. 45
0
        public static CsgObject MountMount()
        {
            Vector3 magnetSize = new Vector3(10, 5, 2.5);

            CsgObject total;

            CsgObject baseBox    = new Box(37, 26, wallWidth * 2);
            Round     baseBevels = new Round(baseBox.Size);

            baseBevels.RoundEdge(Edge.LeftFront, 4);
            baseBevels.RoundEdge(Edge.LeftBack, 4);
            baseBox -= baseBevels;
            CsgObject fakeXCarriage = new Translate(baseBox, 0.5);

            total = fakeXCarriage;

            double    pivotRingYOffset = -pivotHeight / 2 - wallWidth / 2 - .5;
            CsgObject pivotRingFront   = new Cylinder(pivotRingRadius / 2, wallWidth, Alignment.y);
            CsgObject pivotFrontWall   = new Box(pivotRingRadius, wallWidth, mountPivotHeight);

            pivotFrontWall = new Translate(pivotFrontWall, 0, 0, -mountPivotHeight / 2);
            CsgObject pivotSupportFront = pivotRingFront + pivotFrontWall;
            CsgObject pivotHole         = new Cylinder(pivotHoleRadius / 2, pivotRingFront.YSize + .1, Alignment.y);

            pivotHole          = new SetCenter(pivotHole, pivotRingFront.GetCenter());
            pivotSupportFront -= pivotHole;
            pivotSupportFront  = new Translate(pivotSupportFront, 0, pivotRingYOffset, mountPivotHeight);
            pivotSupportFront += Round.CreateFillet(pivotSupportFront, Face.Back, fakeXCarriage, Face.Top, 3);
            pivotSupportFront += Round.CreateFillet(pivotSupportFront, Face.Front, fakeXCarriage, Face.Top, 3);
            total             += pivotSupportFront;

            CsgObject pivotSupportBack = pivotSupportFront.NewMirrorAccrossY();

            total += pivotSupportBack;

            CsgObject backMagnetHolder = new Box(wallWidth * 2, magnetSize.x + wallWidth, backMagnetHeight);

            backMagnetHolder = new Align(backMagnetHolder, Face.Bottom | Face.Right, fakeXCarriage, Face.Top | Face.Right, 0, 0, -.1);
            CsgObject backMagnetHole = new Box(magnetSize.z, magnetSize.x, magnetSize.y);

            backMagnetHole = new SetCenter(backMagnetHole, backMagnetHolder.GetCenter());
            backMagnetHole = new Align(backMagnetHole, Face.Left | Face.Top, backMagnetHolder, Face.Left | Face.Top, -.1, 0, -wallWidth / 2);

            total += Round.CreateFillet(backMagnetHolder, Face.Front, fakeXCarriage, Face.Top, 3);
            total += Round.CreateFillet(backMagnetHolder, Face.Back, fakeXCarriage, Face.Top, 3);
            total += Round.CreateFillet(backMagnetHolder, Face.Left, fakeXCarriage, Face.Top, 3);

            backMagnetHolder -= backMagnetHole;
            total            += backMagnetHolder;

            CsgObject baseMagnetHolder = new Box(wallWidth * 2, magnetSize.x + wallWidth, baseMagnetHeight);

            baseMagnetHolder = new Align(baseMagnetHolder, Face.Bottom, fakeXCarriage, Face.Top, -14, 0, -.1);
            CsgObject baseMagnetHole = new Box(magnetSize.y, magnetSize.x, magnetSize.z);

            baseMagnetHole    = new SetCenter(baseMagnetHole, baseMagnetHolder.GetCenter());
            baseMagnetHole    = new Align(baseMagnetHole, Face.Top, baseMagnetHolder, Face.Top, 0, 0, .1);
            baseMagnetHolder -= baseMagnetHole;
            total            += baseMagnetHolder;

            return(total);
        }
Esempio n. 46
0
 public Translate(CsgObject objectToTranslate, Vector3 translation, string name = "")
     : base(objectToTranslate, name)
 {
     translateCache = translation;
     transform = Matrix4X4.CreateTranslation(translation);
 }
Esempio n. 47
0
        private static CsgObject GimmeACompositionSpheresOnly()
        {
            CsgObject returnThis = GimmeAPrimitive();
            int       whichOne   = _rand.Next(10);

            switch (whichOne)
            {
            case 0:
                _symmetryLikelihood = 0.75;
                returnThis          = SphereWithInnerSpheres();
                break;

            case 1:
                _symmetryLikelihood = 0.5;
                returnThis          = CutUpASphereHybrid();
                break;

            case 2:
                _symmetryLikelihood = 0.5;
                returnThis          = SphereWithSmartSurfaceSpheres();
                break;

            case 3:
                _symmetryLikelihood = 0.33;
                returnThis          = MakeRandomSpheres();
                break;

            case 4:
                _symmetryLikelihood = 0.25;
                returnThis          = StringEmUpCrazy();
                break;

            case 5:
                _symmetryLikelihood = 0.4;
                returnThis          = SphereWithSurfaceSpheres();
                break;

            case 6:
                _symmetryLikelihood = 0.5;
                returnThis          = CutUpASphereRandom();
                break;

            case 7:
                _symmetryLikelihood = 0.5;
                returnThis          = CutUpASphereRegular();
                break;

            case 8:
                _symmetryLikelihood = 0.5;
                returnThis          = DoSomethingSymmetric();
                break;

            case 9:
                _symmetryLikelihood = 0.25;
                returnThis          = VaryOnlyXYorZ();
                break;

            default:
                returnThis = new Sphere(GimmeASize());
                break;
            }
            return(returnThis);
        }
Esempio n. 48
0
 public CsgObject DoCopyAndFlatten(CsgObject objectToProcess)
 {
     throw new Exception("You must write the specialized function for this type.");
 }
Esempio n. 49
0
        private static void DoASingleOne(Func <CsgObject> thisOne)
        {
            CsgObject thing = thisOne();

            MoveAndScaleAndWriteToFile(thing, "output.scad");
        }
Esempio n. 50
0
		public static CsgObject CreateBevel(CsgObject objectToApplyBevelTo, Edge edgeToRound, int radius)
		{
			Round bevel = new Round(objectToApplyBevelTo.Size);
			bevel.RoundEdge(edgeToRound, radius);
			return bevel;
		}
Esempio n. 51
0
        private static void DoABunchSpheresOnly(int howMany)
        {
            for (int i = 0; i < howMany; i++)
            {
                //Console.Out.WriteLine(i);
                try
                {
                    CsgObject theThing    = null;
                    double    moreThanOne = _rand.NextDouble();
                    if (moreThanOne >= 0)
                    {
                        Union            u = new Union();
                        int              howManyMethods = _rand.Next(5);
                        List <CsgObject> unions         = new List <CsgObject>();
                        List <CsgObject> differences    = new List <CsgObject>();
                        for (int j = 0; j < howManyMethods; j++)
                        {
                            double addOrRemove = _rand.NextDouble();
                            if (addOrRemove <= 0.75 || j == 0)
                            {
                                var addMe = GimmeACompositionSpheresOnly();
                                unions.Add(addMe);
                            }
                            else
                            {
                                var diffMe = GimmeACompositionSpheresOnly();
                                differences.Add(diffMe);
                            }
                        }
                        foreach (var thing in unions)
                        {
                            u.Add(thing);
                        }
                        theThing = u;
                        if (differences.Count > 0)
                        {
                            Difference d = new Difference(theThing, differences[0]);
                            for (int j = 1; j < differences.Count; j++)
                            {
                                d.AddToSubtractList(differences[j]);
                            }
                            theThing = d;
                        }
                    }
                    else
                    {
                        theThing = GimmeACompositionSpheresOnly();
                    }

                    DateTime now = DateTime.Now;
                    if (theThing == null)
                    {
                        theThing = GimmeACompositionSpheresOnly();
                    }

                    var symmetry = _rand.NextDouble();
                    if (symmetry >= _symmetryLikelihood)
                    {
                        theThing = MakeThisSymmetric(theThing);
                    }

                    //Console.Out.WriteLine("Writing file {0}", i);
                    MoveAndScaleAndWriteToFile(theThing, string.Format("{0}.scad", "image-" + i));
                }
                catch (Exception e)
                {
                    //DON'T CARE!!! HAHAHA
                    Console.Out.WriteLine("EXCEPTION: {0}", e.Message);
                }
            }
        }
Esempio n. 52
0
 public Rotate(CsgObject objectToRotate, double x = 0, double y = 0, double z = 0, string name = "")
     : this(objectToRotate, new Vector3(x, y, z), name)
 {
 }
Esempio n. 53
0
        private static void DoABunchOneMethod(int howMany, Func <CsgObject> method)
        {
            for (int i = 0; i < howMany; i++)
            {
                //Console.Out.WriteLine(i);
                try
                {
                    CsgObject theThing    = null;
                    double    moreThanOne = _rand.NextDouble();
                    if (moreThanOne >= 0)
                    {
                        Union            u = new Union();
                        int              howManyMethods = _rand.Next(5);
                        List <CsgObject> unions         = new List <CsgObject>();
                        List <CsgObject> differences    = new List <CsgObject>();
                        for (int j = 0; j < howManyMethods; j++)
                        {
                            double addOrRemove = _rand.NextDouble();
                            if (addOrRemove <= 0.75 || j == 0)
                            {
                                var addMe = method();
                                unions.Add(addMe);
                            }
                            else
                            {
                                var diffMe = method();
                                differences.Add(diffMe);
                            }
                        }
                        foreach (var thing in unions)
                        {
                            u.Add(thing);
                        }
                        theThing = u;
                        if (differences.Count > 0)
                        {
                            Difference d = new Difference(theThing, differences[0]);
                            for (int j = 1; j < differences.Count; j++)
                            {
                                d.AddToSubtractList(differences[j]);
                            }
                            theThing = d;
                        }
                    }
                    else
                    {
                        theThing = method();
                    }

                    DateTime now = DateTime.Now;
                    if (theThing == null)
                    {
                        theThing = method();
                    }
                    //Console.Out.WriteLine("Writing file {0}", i);
                    //OpenSCadOutput.Save(theThing, string.Format("{0}.scad", now.ToString("yyMMddHHmmssff")));
                    MoveAndScaleAndWriteToFile(theThing, string.Format("{0}.scad", now.ToString("yyMMddHHmmssff")));
                }
                catch (Exception e)
                {
                    //DON'T CARE!!! HAHAHA
                    Console.Out.WriteLine("EXCEPTION: {0}", e.Message);
                }
            }
        }
Esempio n. 54
0
		public Scale(CsgObject objectToScale, Vector3 scale, string name = "")
			: base(objectToScale, name)
		{
			this.scaleCache = scale;
			transform = Matrix4X4.CreateScale(scale);
		}
Esempio n. 55
0
        public static string GetScadString(CsgObject objectToProcess, string prepend = "")
        {
            OpenSCadOutput visitor = new OpenSCadOutput();

            return(prepend + visitor.GetScadOutputRecursive((dynamic)objectToProcess));
        }