public IRayTraceable GetIRayTraceableRecursive(MatterHackers.Csg.Operations.Difference objectToProcess) { List <IRayTraceable> subtractItems = new List <IRayTraceable>(); foreach (CsgObject copiedObject in objectToProcess.AllSubtracts) { subtractItems.Add(GetIRayTraceableRecursive((dynamic)copiedObject)); } return(new MatterHackers.RayTracer.Traceable.Difference(GetIRayTraceableRecursive((dynamic)objectToProcess.Primary), BoundingVolumeHierarchy.CreateNewHierachy(subtractItems))); }
public CsgObject DoCopyAndFlatten(Difference objectToProcess) { Difference differenceCopy = new Difference(DoCopyAndFlatten((dynamic)objectToProcess.primary), objectToProcess.primary.Name); foreach (CsgObject copiedObject in objectToProcess.allSubtracts) { differenceCopy -= DoCopyAndFlatten((dynamic)copiedObject); } return differenceCopy; }
public string GetScadOutputRecursive(Difference objectToProcess, int level = 0) { StringBuilder totalString = new StringBuilder(); totalString.Append("difference()" + AddNameAsComment(objectToProcess) + "\n{\n"); totalString.Append(GetScadOutputRecursive((dynamic)objectToProcess.Primary, level + 1) + "\n"); foreach (CsgObject objectToOutput in objectToProcess.AllSubtracts) { totalString.Append(GetScadOutputRecursive((dynamic)objectToOutput, level + 1) + "\n"); } totalString.Append("}"); return ApplyIndent(totalString.ToString(), level); }
/// <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."); } }
public PolygonMesh.Mesh CsgToMeshRecursive(Difference objectToProcess) { PolygonMesh.Mesh primary = CsgToMeshRecursive((dynamic)objectToProcess.Primary); foreach (CsgObject objectToOutput in objectToProcess.AllSubtracts) { PolygonMesh.Mesh remove = CsgToMeshRecursive((dynamic)objectToOutput); primary = PolygonMesh.Csg.CsgOperations.Subtract(primary, remove); } return primary; }
public void RenderToGlRecursive(Difference objectToProcess) { RenderToGlRecursive((dynamic)objectToProcess.Primary); foreach (CsgObject objectToOutput in objectToProcess.AllSubtracts) { RenderToGlRecursive((dynamic)objectToOutput); } }
public string LookForNamedPartRecursive(Difference objectToProcess, Matrix4X4 accumulatedMatrix) { StringBuilder totalString = new StringBuilder(); totalString.Append(LookForNamedPartRecursive((dynamic)objectToProcess.primary, accumulatedMatrix)); foreach (CsgObject objectToOutput in objectToProcess.allSubtracts) { totalString.Append(LookForNamedPartRecursive((dynamic)objectToOutput, accumulatedMatrix)); } return totalString.ToString(); }