public static GH_Brep ProjectBrepToTopo(Mesh topoMesh, Brep brep) { GH_Brep ghBrep = new GH_Brep(); List <Mesh> topoMeshList = new List <Mesh>(); topoMeshList.Add(topoMesh); BoundingBox bb = brep.GetBoundingBox(false); ///Get list of verteces from mesh to project List <Point3d> originalVerts = new List <Point3d>(); foreach (var v in brep.Vertices) { originalVerts.Add(v.Location); } ///create a list of verteces who share the lowest Z value of the bounding box List <Point3d> lowestVerts = originalVerts.Where(lowPoint => lowPoint.Z == bb.Min.Z).ToList(); ///transalte mesh to project up with move vector and save to output array Vector3d moveV = GetMinProjectedPointToMesh(lowestVerts, topoMesh); Vector3d maxV = new Vector3d(0, 0, Double.MaxValue); if (moveV == maxV) { return(null); } brep.Translate(moveV); if (brep.IsValid) { GH_Convert.ToGHBrep(brep, GH_Conversion.Primary, ref ghBrep); return(ghBrep); } else { return(null); } }
/*******************************************/ public static bool CastToGoo(object value, ref GH_Brep target) { return(GH_Convert.ToGHBrep(value, GH_Conversion.Both, ref target)); }
/// <summary> /// This is the method that actually does the work. /// </summary> /// <param name="DA">The DA object is used to retrieve from inputs and store in outputs.</param> protected override void SolveInstance(IGH_DataAccess DA) { InputChecker inputChecker = new InputChecker(this); #region GetIputFromCanvas GH_Structure <GH_Brep> inGhBreps = new GH_Structure <GH_Brep>(); bool areBrepsOk = DA.GetDataTree(0, out inGhBreps); inputChecker.StopIfConversionIsFailed(areBrepsOk); inGhBreps.Graft(GH_GraftMode.GraftAll); inGhBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps); GH_Structure <GH_Number> inGhDistances = new GH_Structure <GH_Number>(); bool areDistancesOk = DA.GetDataTree(1, out inGhDistances); inputChecker.StopIfConversionIsFailed(areDistancesOk); GH_Structure <GH_Number> ghDistances = new GH_Structure <GH_Number>(); ghDistances = ValuesAllocator.NumbersDSFromBreps(inGhBreps, inGhDistances, ghDistances); GH_Structure <GH_Boolean> inGhBothSides = new GH_Structure <GH_Boolean>(); bool areBoolBothSidesOk = DA.GetDataTree(2, out inGhBothSides); inputChecker.StopIfConversionIsFailed(areBoolBothSidesOk); GH_Structure <GH_Boolean> ghBothSides = new GH_Structure <GH_Boolean>(); ghBothSides = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhBothSides, ghBothSides); GH_Structure <GH_Boolean> inGhFlipNormals = new GH_Structure <GH_Boolean>(); bool areBoolFlipNormalsOk = DA.GetDataTree(3, out inGhFlipNormals); inputChecker.StopIfConversionIsFailed(areBoolFlipNormalsOk); GH_Structure <GH_Boolean> ghFlipNormals = new GH_Structure <GH_Boolean>(); ghFlipNormals = ValuesAllocator.BoolDSFromBreps(inGhBreps, inGhFlipNormals, ghFlipNormals); bool useParallel = false; DA.GetData <bool>(4, ref useParallel); double docTollerance = DocumentTolerance(); #endregion GH_Structure <GH_Brep> ghSolidBreps = new GH_Structure <GH_Brep>(); if (useParallel) { this.Message = Constants.Constants.PARALLEL_MESSAGE; this.AddRuntimeMessage(GH_RuntimeMessageLevel.Remark, Constants.Constants.PARALLEL_WARNING); int processorCount = Environment.ProcessorCount - 1; //WORK IN PARALLEL ConcurrentDictionary <GH_Path, Brep> solidBrepsPA = new ConcurrentDictionary <GH_Path, Brep>(); Parallel.ForEach(inGhBreps.Paths, new ParallelOptions { MaxDegreeOfParallelism = processorCount }, path => { Brep brepToSolidify = inGhBreps.get_DataItem(path, 0).Value; bool flipTheNormal = ghFlipNormals.get_DataItem(path, 0).Value; bool bothSide = ghBothSides.get_DataItem(path, 0).Value; double distance = ghDistances.get_DataItem(path, 0).Value; if (flipTheNormal) { distance *= -1; } foreach (var brepFace in brepToSolidify.Faces) { solidBrepsPA[path] = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true); } }); foreach (KeyValuePair <GH_Path, Brep> keyValueBrep in solidBrepsPA) { GH_Brep ghBrep = null; if (GH_Convert.ToGHBrep(keyValueBrep.Value, GH_Conversion.Both, ref ghBrep)) { ghSolidBreps.Append(ghBrep, keyValueBrep.Key); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Conversion Failed"); return; } } }//End Parallel Computation else { this.Message = Constants.Constants.SERIAL_MESSAGE; foreach (GH_Path path in inGhBreps.Paths) { Brep brepToSolidify = inGhBreps.get_DataItem(path, 0).Value; bool flipTheNormal = ghFlipNormals.get_DataItem(path, 0).Value; bool bothSide = ghBothSides.get_DataItem(path, 0).Value; double distance = ghDistances.get_DataItem(path, 0).Value; if (flipTheNormal) { distance *= -1; } foreach (var brepFace in brepToSolidify.Faces) { Brep solidBrep = Brep.CreateFromOffsetFace(brepFace, distance, docTollerance, bothSide, true); GH_Brep ghBrep = null; if (GH_Convert.ToGHBrep(solidBrep, GH_Conversion.Both, ref ghBrep)) { ghSolidBreps.Append(ghBrep, path); } else { this.AddRuntimeMessage(GH_RuntimeMessageLevel.Error, "Conversion Failed"); return; } } } }//End Serial Computation #region SendDataToCanvas ghSolidBreps.Simplify(GH_SimplificationMode.CollapseAllOverlaps); DA.SetDataTree(0, ghSolidBreps); #endregion }//end SolveInstance