public static List <Brep> OrthogonalEgress(List <Curve> coreCurves, List <Curve> egressAxis) { List <Brep> egressExemptionRegions = new List <Brep>(); for (int i = 0; i < egressAxis.Count; i++) { Point3d coreCurveMidpoint = Utils.GetCurveMidPoint(coreCurves[i]); egressAxis[i].ClosestPoint(coreCurveMidpoint, out double circulationParameter); Point3d circulationPoint = egressAxis[i].PointAt(circulationParameter); Vector3d connectionVector = new Vector3d(circulationPoint - coreCurveMidpoint); bool proportionIsVertical = Confirm.VectorProportionIsVertical(connectionVector); Vector3d egressVector = (proportionIsVertical == true) ? new Vector3d(0, connectionVector.Y, 0) : new Vector3d(connectionVector.X, 0, 0); Curve egressRegionProfile = Curves.RebuildPerpendicularTo(coreCurves[i], egressVector); //MessageBox.Show(connectionVector.ToString() + " => " + egressVector.ToString()); Brep egressRegion = Brep.CreateFromSurface(Extrusion.CreateExtrusion(egressRegionProfile, egressVector)); egressExemptionRegions.Add(egressRegion); } return(egressExemptionRegions); }
internal static Brep ToBrep(DB.Face face) { var surface = Raw.RawDecoder.ToRhinoSurface(face, out var _, 1.0); if (surface is null) { return(null); } var brep = Brep.CreateFromSurface(surface); if (brep is null) { return(null); } if (!face.MatchesSurfaceOrientation()) { brep.Flip(); } var loops = ToCurveMany(face.GetEdgesAsCurveLoops()).ToArray(); try { return(TrimFaces(brep, loops)); } finally { brep.Dispose(); } }
public static Brep GetTrimmedBrep(pps.Surface surface, SurfaceConverter surfConv, CurveConverter curveConv) { var rhSurf = surfConv.FromPipe <Surface, pps.Surface>(surface); var brep = Brep.CreateFromSurface(rhSurf); //if (!brep.IsValid) { brep.Repair(Rhino.RhinoMath.ZeroTolerance); } if (typeof(pps.NurbsSurface).IsAssignableFrom(surface.GetType()) && ((pps.NurbsSurface)surface).TrimCurves.Count > 0) { List <ppc.Curve> trims = ((pps.NurbsSurface)surface).TrimCurves; List <ppc.Curve> loops = brep.Faces.First().Loops.Select((l) => curveConv.ToPipe <Curve, ppc.Curve>(l.To3dCurve())).ToList(); if (!PipeDataUtil.EqualIgnoreOrder(loops, trims)) { var rhTrims = trims.Select((c) => curveConv.FromPipe <Curve, ppc.Curve>(c)).ToList(); var faceToSplit = brep.Faces.First(); var brep2 = faceToSplit.Split(rhTrims, Rhino.RhinoMath.ZeroTolerance); //if (brep2 != null && !brep2.IsValid) { brep2.Repair(Rhino.RhinoMath.ZeroTolerance); } if (brep2 != null && brep2.IsValid) { brep = GetEnclosedFacesAsBrep(brep2, rhTrims) ?? brep2; } } } return(brep); }
public static Brep ToRhino(this DB.Face face, bool untrimmed = false) { var surface = face.ToRhinoSurface(); if (surface is null) { return(null); } var brep = Brep.CreateFromSurface(surface); if (brep is null) { return(null); } #if REVIT_2018 if (!face.OrientationMatchesSurfaceOrientation) { brep.Flip(); } #endif if (untrimmed) { return(brep); } var loops = face.GetEdgesAsCurveLoops().ToRhino().ToArray(); try { return(brep.TrimFaces(loops)); } finally { brep.Dispose(); } }
private void createPlaneBrep() { Plane plane = new Plane(); if (type == XYZPlanes.YZ) { plane = new Plane(origin, new Rhino.Geometry.Vector3d(1, 0, 0)); } else if (type == XYZPlanes.XZ) { plane = new Plane(origin, new Rhino.Geometry.Vector3d(0, 1, 0)); } else if (type == XYZPlanes.XY) { plane = new Plane(origin, new Rhino.Geometry.Vector3d(0, 0, 1)); } PlaneSurface plane_surface = new PlaneSurface(plane, new Interval(-size, size), new Interval(-size, size)); Brep planeBrep = Brep.CreateFromSurface(plane_surface); if (planeBrep != null) { Guid guid = UtilOld.addRhinoObjectSceneNode(ref mScene, ref planeBrep, ref mesh_m, "plane" + type.ToString(), out planeSN, true); planeObjRef = new Rhino.DocObjects.ObjRef(guid); } }
private bool ProcesssCurveItem(HbInputItem hbInputItem, double verticalHeight) { try { List <Point3d> points; Curve curve; Extrusion extrusion = null; //Brep brep = null; HbToRhino(hbInputItem.HbCurve, out points, out curve); // Add to outputs this.dataTreePoints.AddRange(points, new GH_Path(indexPoints)); indexPoints++; this.dataTreeCurves.AddRange(new List <Curve> { curve }, new GH_Path(indexCurves)); indexCurves++; if (verticalHeight > 0) { extrusion = Extrusion.Create(curve, verticalHeight, false); this.dataTreeBreps.AddRange(new List <Brep> { Brep.CreateFromSurface(extrusion) }, new GH_Path(indexBreps)); indexBreps++; } // Create Geometry if (createGeometryPoints) { if (points != null) { foreach (Point3d point3d in points) { Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(point3d); } } } if (createGeometryCurves) { if (curve != null) { Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(curve); } } if (createGeometrySurfaces) { if (extrusion != null) { Rhino.RhinoDoc.ActiveDoc.Objects.AddExtrusion(extrusion); } } return(true); } catch { return(false); } }
/// <summary> /// Merges two surfaces into one surface at untrimmed edges. /// </summary> /// <param name="surface0">The first surface to merge.</param> /// <param name="surface1">The second surface to merge.</param> /// <returns>The merged surfaces as a Brep if successful, null if not successful.</returns> public static Brep MergeSurfaces(Surface surface0, Surface surface1) { if (null == surface0 || null == surface1) { return(null); } var brep0 = Brep.CreateFromSurface(surface0); var brep1 = Brep.CreateFromSurface(surface1); if (null == brep0 || null == brep1) { return(null); } return(MergeSurfaces(brep0, brep1, Point2d.Unset, Point2d.Unset, 1.0, true, RhinoMath.UnsetValue)); }
protected override void onClickOculusTrigger(ref VREvent_t vrEvent) { primaryDeviceIndex = vrEvent.trackedDeviceIndex; if (currentState != State.READY || targetPRhObjID == Guid.Empty) { return; } pointOnObjRef = new ObjRef(targetPRhObjID); //chage to only raycasting to the obj where we draw, if not snap to the origin if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0)) { rayCastingObjs.Clear(); rayCastingObjs.Add(pointOnObjRef); } //testing Vector3 projectPVR = UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(projectP)); mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, projectPVR)); //not use at the current version, point is VR coordinate pointsList.Add(projectP); //render edit points in VR Geometry.Geometry geo = new Geometry.DrawPointMarker(new Vector3(0, 0, 0)); Material.Material m = new Material.SingleColorMaterial(0, 1, 0, 1); SceneNode editPointSN; UtilOld.MarkPointVR(ref mScene, projectPVR, ref geo, ref m, out editPointSN); pointMarkers.Add(editPointSN); //TODO-hide two other design plane if (pointMarkers.Count == 1) { if (pointOnObjRef != null && drawnType == DrawnType.Plane) { if (!(projectP.X == 0 && projectP.Y == 0 && projectP.Z == 0)) { UtilOld.hideOtherPlanes(ref mScene, pointOnObjRef.Object().Attributes.Name); } computeContourCurve(); } //TODO- how to find the curvePlane on the surface like teapot body, using the normal of first point? //do we need to use different ways for patch surface and other generated surface else if (pointOnObjRef != null && drawnType == DrawnType.Surface) { computeContourCurve(); } } if (maxNumPoint == pointMarkers.Count) { //Assume we always can find a curvePlane sicnce we use a huge tolerance NurbsCurve modelcurve = null; Brep modelBrep; string modelName = ""; if (shapeType == ShapeType.Circle) { float radius = (float)Math.Sqrt(Math.Pow(pointsList[1].X - pointsList[0].X, 2) + Math.Pow(pointsList[1].Y - pointsList[0].Y, 2) + Math.Pow(pointsList[1].Z - pointsList[0].Z, 2)); Circle circle = new Rhino.Geometry.Circle(curvePlane, pointsList[0], radius); modelcurve = circle.ToNurbsCurve(); modelName = "Circle"; } else if (shapeType == ShapeType.Rect) { Vector3 rectDiagonalV = new Vector3((float)(pointsList[0].X - pointsList[1].X), (float)(pointsList[0].Y - pointsList[1].Y), (float)(pointsList[0].Z - pointsList[1].Z)); float lenDiagonal = rectDiagonalV.Length; Vector3 rectLeftTop = new Vector3((float)pointsList[0].X, (float)pointsList[0].Y, (float)pointsList[0].Z) + lenDiagonal * rectDiagonalV.Normalized(); Point3d topLeftP = new Point3d(rectLeftTop.X, rectLeftTop.Y, rectLeftTop.Z); Rectangle3d rect = new Rectangle3d(curvePlane, topLeftP, pointsList[1]); //using top-left cornel and bottom right //Rectangle3d rect = new Rectangle3d(curvePlane, pointsList[0], pointsList[1]); modelcurve = rect.ToNurbsCurve(); modelName = "Rect"; } /* * Brep[] shapes = Brep.CreatePlanarBreps(modelcurve); * modelBrep = shapes[0]; * Guid guid = Util.addRhinoObjectSceneNode(ref mScene, ref modelBrep, ref profile_m, modelName, out renderObjSN); */ //generate new curveOnObj for mvoingPlane cases sicne and move the XYZPlanes to origial positons if (drawnType == DrawnType.Plane) { Rhino.Geometry.Vector3d newNormal = new Rhino.Geometry.Vector3d();; Point3d newOrigin = new Point3d(); String planeName = pointOnObjRef.Object().Attributes.Name; Point3d planeOrigin = pointOnObjRef.Object().Geometry.GetBoundingBox(true).Center; if (planeName.Contains("planeXY")) { newNormal = new Rhino.Geometry.Vector3d(0, 0, 1); newOrigin = new Point3d(0, 0, planeOrigin.Z); } else if (planeName.Contains("planeYZ")) { newNormal = new Rhino.Geometry.Vector3d(1, 0, 0); newOrigin = new Point3d(planeOrigin.X, 0, 0); } else if (planeName.Contains("planeXZ")) { newNormal = new Rhino.Geometry.Vector3d(0, 1, 0); newOrigin = new Point3d(0, planeOrigin.Y, 0); } Plane newPlane = new Plane(newOrigin, newNormal); int size = 240; PlaneSurface plane_surface = new PlaneSurface(newPlane, new Interval(-size, size), new Interval(-size, size)); Brep newPlaneBrep = Brep.CreateFromSurface(plane_surface); Guid newPlaneID = UtilOld.addRhinoObject(ref mScene, ref newPlaneBrep, "MoveP"); //might be better to use Replace(), just need to be careful about the referece count pointOnObjRef = null; pointOnObjRef = new ObjRef(newPlaneID); modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), newPlaneID.ToString()); modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), newPlane.Origin.ToString()); modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), newPlane.Normal.ToString()); } else if (drawnType == DrawnType.Surface) { modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), pointOnObjRef.ObjectId.ToString()); modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString()); modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString()); } mScene.iCurveList.Add(modelcurve); //call next interaction in the chain afterCurveCount = mScene.iCurveList.Count; mScene.pushInteractionFromChain(); currentState = State.READY; } }
protected override void SolveInstance(IGH_DataAccess DA) { Brep brep = null; DA.GetData("Brep", ref brep); if (!DA.GetData("Workplane", ref Workplane)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Workplane missing. Default used (WorldXY)."); } if (!DA.GetData("MachineTool", ref Tool)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "MachineTool missing. Default used."); } bool male = false; DA.GetData("Male", ref male); bool flip = false; DA.GetData("Flip", ref flip); double angle = 60; double hangle = angle / 360 * Math.PI; double depth = 3; Curve[] intersections; Point3d[] intersection_points; Rhino.Geometry.Intersect.Intersection.BrepPlane(brep, Workplane, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, out intersections, out intersection_points); if (intersections.Length < 1) { return; } BoundingBox bb = intersections[0].GetBoundingBox(Workplane); double r = double.MaxValue; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { r = Math.Min(bb.Corner((i == 1), (j == 1), (k == 1)).DistanceTo(Point3d.Origin), r); } } } List <Point3d> pts = new List <Point3d>(); double step = Math.Tan(hangle) * depth; int num_grooves = (int)(r / step) + 5; if (male) { depth *= -1; } for (int i = 0; i <= num_grooves; ++i) { pts.Add(new Point3d(step * i, 0.0, depth * ((Math.Abs(i) % 2) * 2 - 1))); } Polyline poly = new Polyline(pts); Rhino.Geometry.RevSurface rev = RevSurface.Create(poly, new Line(Point3d.Origin, Vector3d.ZAxis)); rev.Transform(Transform.PlaneToPlane(Plane.WorldXY, Workplane)); Brep grooves = rev.ToBrep(); if (flip) { List <Brep> srfs = new List <Brep>(); for (int i = 0; i < grooves.Surfaces.Count; ++i) { srfs.Add(Brep.CreateFromSurface(grooves.Surfaces[i].Reverse(0))); } grooves = Brep.MergeBreps(srfs, 0.1); } Brep[] trims = brep.Trim(grooves, 0.1); if (trims.Length < 1) { throw new Exception("Trim failed!"); } Brep final = trims[0]; for (int i = 1; i < trims.Length; ++i) { final.Join(trims[i], 0.1, true); } trims = grooves.Trim(brep, 0.1); for (int i = 0; i < trims.Length; ++i) { final.Join(trims[i], 0.1, true); } DA.SetData("Finger Joint", final); }
private static Brep SubtractBrep(Surface surface, List <Brep> excludeGeometry) { var brepSurface = Brep.CreateFromSurface(surface); return(_SubtractBrep(brepSurface, excludeGeometry)); }
private static Brep MoveSurface(Surface surface, double offset, string offsetDirection) { var _surface = Brep.CreateFromSurface(surface); return(_MoveSurface(_surface, offset, offsetDirection)); }
private bool ProcessPlaneSurfaceByPoints(Point3d center, List <Point3d> points, Interval intervalX, Interval intervalY) { try { // Calculate List <LineCurve> lineCurves = new List <LineCurve>(); switch (points.Count) { case 0: return(false); case 1: break; default: Point3d pointFirst = new Point3d(0, 0, 0); // Dummy value for compiler Point3d pointPrevious = new Point3d(0, 0, 0); // Dummy value for compiler bool first = true; foreach (Point3d point in points) { if (first) { pointFirst = point; first = false; } else { lineCurves.Add(new LineCurve(new Line(pointPrevious, point))); } pointPrevious = point; } lineCurves.Add(new LineCurve(new Line(pointPrevious, pointFirst))); break; } PlaneSurface rhPlaneSurface = new PlaneSurface(new Plane(center, new Vector3d(0, 0, 1)), intervalX, intervalY); // Add to outputs this.dataTreePoints.AddRange(points, new GH_Path(indexPoints)); indexPoints++; if (lineCurves.Count > 0) { this.dataTreeCurves.AddRange(lineCurves, new GH_Path(indexCurves)); indexCurves++; } this.dataTreeBreps.AddRange(new List <Brep> { Brep.CreateFromSurface(rhPlaneSurface) }, new GH_Path(indexBreps)); indexBreps++; // Create geometry if (createGeometryPoints) { foreach (Point3d point in points) { Rhino.RhinoDoc.ActiveDoc.Objects.AddPoint(point); } } if (createGeometryCurves) { foreach (LineCurve lineCurve in lineCurves) { Rhino.RhinoDoc.ActiveDoc.Objects.AddCurve(lineCurve); } } if (createGeometrySurfaces) { Rhino.RhinoDoc.ActiveDoc.Objects.AddSurface(rhPlaneSurface); } return(true); } catch { return(false); } }
protected override void SolveInstance(IGH_DataAccess DA) { if (!DA.GetData("Workplane", ref Workplane)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "Workplane missing. Default used (WorldXY)."); } if (!DA.GetData("MachineTool", ref Tool)) { AddRuntimeMessage(GH_RuntimeMessageLevel.Warning, "MachineTool missing. Default used."); } Brep brep = null; DA.GetData("Brep", ref brep); bool male = false; DA.GetData("Male", ref male); bool flip = false; DA.GetData("Flip", ref flip); double angle = 0; DA.GetData("Angle", ref angle); double depth = 0; DA.GetData("Depth", ref depth); double hdepth = depth / 2; double hangle = angle / 360 * Math.PI; Curve[] intersections; Point3d[] intersection_points; Rhino.Geometry.Intersect.Intersection.BrepPlane(brep, Workplane, Rhino.RhinoDoc.ActiveDoc.ModelAbsoluteTolerance, out intersections, out intersection_points); if (intersections.Length < 1) { return; } Curve[] outline_list = Curve.JoinCurves(intersections); if (outline_list.Length < 1) { return; } Curve outline = outline_list[0]; List <Point3d> toolpath_start_points = new List <Point3d>(); BoundingBox bb = intersections[0].GetBoundingBox(Workplane); double max_x = 0; double max_y = 0; for (int i = 0; i < 2; ++i) { for (int j = 0; j < 2; ++j) { for (int k = 0; k < 2; ++k) { max_x = Math.Max(Math.Abs(bb.Corner((i == 1), (j == 1), (k == 1)).X), max_x); max_y = Math.Max(Math.Abs(bb.Corner((i == 1), (j == 1), (k == 1)).Y), max_y); } } } List <Point3d> pts = new List <Point3d>(); double step = Math.Tan(hangle) * depth; Curve[] offsets = outline.Offset(Workplane, step * 2, 0.1, CurveOffsetCornerStyle.Sharp); outline = offsets[0]; int num_grooves = (int)(max_x / step) + 5; if (male) { depth *= -1; } for (int i = -num_grooves; i <= num_grooves; ++i) { pts.Add(new Point3d(step * i, -max_y * 2, hdepth * ((Math.Abs(i) % 2) * 2 - 1))); } #region Toolpath int flipper = flip ? 1 : 0; for (int i = flipper; i < pts.Count; i += 2) { toolpath_start_points.Add(new Point3d(pts[i].X, pts[i].Y, 0.0)); } flipper = flip ? 1 : -1; List <GH_PPolyline> paths = new List <GH_PPolyline>(); List <Point3d> path_points = new List <Point3d>(); List <Tuple <Point3d, Point3d> > path_pairs = new List <Tuple <Point3d, Point3d> >(); for (int i = 0; i < toolpath_start_points.Count; ++i) { Point3d p1 = toolpath_start_points[i]; Point3d p2 = toolpath_start_points[i] + Vector3d.YAxis * max_y * 4; Polyline temp = new Polyline(new Point3d[] { p1, p2 }); temp.Transform(Transform.PlaneToPlane(Plane.WorldXY, Workplane)); Rhino.Geometry.Intersect.CurveIntersections ci = Rhino.Geometry.Intersect.Intersection.CurveCurve(outline, temp.ToNurbsCurve(), 0.1, 0.01); if (ci.Count == 2) { path_pairs.Add(new Tuple <Point3d, Point3d>(ci[0].PointA + Workplane.ZAxis * hdepth * flipper, ci[1].PointB + Workplane.ZAxis * hdepth * flipper)); } } path_points.Add(path_pairs[0].Item1); path_points.Add(path_pairs[0].Item2); double d1, d2; int index = 1; for (int i = 1; i < path_pairs.Count; ++i) { d1 = path_pairs[i].Item1.DistanceTo(path_points[index]); d2 = path_pairs[i].Item2.DistanceTo(path_points[index]); if (d1 > d2) { path_points.Add(path_pairs[i].Item2); path_points.Add(path_pairs[i].Item1); } else { path_points.Add(path_pairs[i].Item1); path_points.Add(path_pairs[i].Item2); } index += 2; } paths.Add(new GH_PPolyline(new PPolyline(path_points, Workplane))); #endregion Polyline poly = new Polyline(pts); Brep grooves = Extrusion.CreateExtrusion(poly.ToNurbsCurve(), Vector3d.YAxis * max_y * 4).ToBrep(); grooves.Transform(Transform.PlaneToPlane(Plane.WorldXY, Workplane)); if (!flip) { List <Brep> srfs = new List <Brep>(); for (int i = 0; i < grooves.Surfaces.Count; ++i) { srfs.Add(Brep.CreateFromSurface(grooves.Surfaces[i].Reverse(0))); } grooves = Brep.MergeBreps(srfs, 0.1); } Brep[] trims = brep.Trim(grooves, 0.1); if (trims.Length < 1) { throw new Exception("Trim failed!"); } Brep final = trims[0]; for (int i = 1; i < trims.Length; ++i) { final.Join(trims[i], 0.1, true); } trims = grooves.Trim(brep, 0.1); for (int i = 0; i < trims.Length; ++i) { final.Join(trims[i], 0.1, true); } DA.SetData("Finger Joint", final); DA.SetDataList("Paths", paths); }
public override void init() { resetVariables(); //support undo function if (mScene != null && (afterCurveCount - beforeCurveCount) > 0) { if (mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString()) != "") { Guid curveOnObjId = new Guid(mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.CurveOnObj.ToString())); ObjRef curveOnObjRef = new ObjRef(curveOnObjId); if (curveOnObjRef.Object().Attributes.Name.Contains("railPlane") || curveOnObjRef.Object().Attributes.Name.Contains("MoveP")) { UtilOld.removeRhinoObject(ref mScene, curveOnObjRef.ObjectId); } } mScene.iCurveList.RemoveAt(mScene.iCurveList.Count - 1); UtilOld.removeSceneNode(ref mScene, ref strokeSN); strokeSN = null; //need to clear stroke tprint SceneNode as well here if (renderObjSN != null) { UtilOld.removeSceneNode(ref mScene, ref renderObjSN); renderObjSN = null; } //Util.removeRhinoObject(ref mScene, curveOnObjRef.ObjectId); curveOnObjRef = null; if (railPlaneSN != null) { UtilOld.removeRhinoObjectSceneNode(ref mScene, ref railPlaneSN); railPlaneSN = null; } } if (drawnType != DrawnType.In3D && drawnType != DrawnType.None) { UtilOld.showLaser(ref mScene, true); //create and add referece planes to scene if (drawnType == DrawnType.Reference) { Vector3 railPlaneNormal = UtilOld.RhinoToOpenTKVector(UtilOld.getVectorfromString(mScene.iCurveList[mScene.iCurveList.Count - 1].GetUserString(CurveData.PlaneNormal.ToString()))); OpenTK.Vector3 worldUpAxis = new Vector3(0, 0, 1); //trick to avoid cross product of 2 parallel vetors if (railPlaneNormal.X == 0 && railPlaneNormal.Y == 0 && railPlaneNormal.Z == 1) { railPlaneNormal = new Vector3(0, 0.005f, 1); } Plane railPlane = new Plane(mScene.iCurveList[mScene.iCurveList.Count - 1].GetBoundingBox(true).Center, UtilOld.openTkToRhinoVector(Vector3.Cross(railPlaneNormal, worldUpAxis))); float planeSize = 240; PlaneSurface plane_surface2 = new PlaneSurface(railPlane, new Interval(-planeSize, planeSize), new Interval(-planeSize, planeSize)); Brep railPlane2 = Brep.CreateFromSurface(plane_surface2); Guid railPlaneGuid = UtilOld.addRhinoObjectSceneNode(ref mScene, ref railPlane2, ref railPlane_m, "railPlane", out railPlaneSN); } else if (drawnType == DrawnType.Plane) { UtilOld.setPlaneAlpha(ref mScene, 0.4f); } //init rayCastingObjs Rhino.DocObjects.ObjectEnumeratorSettings settings = new Rhino.DocObjects.ObjectEnumeratorSettings(); settings.ObjectTypeFilter = Rhino.DocObjects.ObjectType.Brep; foreach (Rhino.DocObjects.RhinoObject rhObj in mScene.rhinoDoc.Objects.GetObjectList(settings)) { bool b1 = (drawnType == DrawnType.Plane) && rhObj.Attributes.Name.Contains("plane"); bool b2 = (drawnType == DrawnType.Surface) && (rhObj.Attributes.Name.Contains("brepMesh") || rhObj.Attributes.Name.Contains("aprint") || rhObj.Attributes.Name.Contains("patchSurface")); bool b3 = (drawnType == DrawnType.Reference) && rhObj.Attributes.Name.Contains("railPlane"); if (b1 || b2 || b3) { rayCastingObjs.Add(new ObjRef(rhObj.Id)); } } Geometry.Geometry geo = new Geometry.DrawPointMarker(new OpenTK.Vector3(0, 0, 0)); Material.Material m = new Material.SingleColorMaterial(1, 1, 1, 0);//TODO: teseting alpha working or not drawPoint = new SceneNode("drawPoint", ref geo, ref m); UtilOld.addSceneNode(ref mScene, ref drawPoint); } else { UtilOld.showLaser(ref mScene, false); } //generate snap points when we need to draw from the center of the shapes, drawnType could be DrawnType.Reference or DrawnType.In3D if (dynamicRender == "Extrude" || dynamicRender == "Sweep" || drawnType == DrawnType.Reference) { shouldSnap = true; ShapeType shapeType = (ShapeType)mScene.selectionDic[SelectionKey.Profile1Shape]; Circle circle; Rectangle3d rect; if (shapeType == ShapeType.Circle) { if (mScene.iCurveList[mScene.iCurveList.Count - 1].TryGetCircle(out circle)) { snapPointsList.Add(circle.Center); } } else if (shapeType == ShapeType.Rect) { Rhino.Geometry.Polyline polyline; if (mScene.iCurveList[mScene.iCurveList.Count - 1].TryGetPolyline(out polyline)) { rect = Rectangle3d.CreateFromPolyline(polyline); snapPointsList.Add(rect.Center); } } //visualize the snap points Geometry.Geometry geo = new Geometry.DrawPointMarker(new Vector3(0, 0, 0)); Material.Material m = new Material.SingleColorMaterial(0, 1, 0, 1); UtilOld.MarkPointVR(ref mScene, UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(snapPointsList[0])), ref geo, ref m, out snapPointSN); } d = new generateModel_Delegate(generateModel); }
public static Result ExtendSurface(RhinoDoc doc) { var go = new Rhino.Input.Custom.GetObject(); go.SetCommandPrompt("Select edge of surface to extend"); go.GeometryFilter = ObjectType.EdgeFilter; go.GeometryAttributeFilter = GeometryAttributeFilter.EdgeCurve; go.Get(); if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } var obj_ref = go.Object(0); var surface = obj_ref.Surface(); if (surface == null) { RhinoApp.WriteLine("Unable to extend polysurfaces."); return(Result.Failure); } var brep = obj_ref.Brep(); var face = obj_ref.Face(); if (brep == null || face == null) { return(Result.Failure); } if (face.FaceIndex < 0) { return(Result.Failure); } if (!brep.IsSurface) { RhinoApp.WriteLine("Unable to extend trimmed surfaces."); return(Result.Nothing); } var curve = obj_ref.Curve(); var trim = obj_ref.Trim(); if (trim == null) { return(Result.Failure); } if (trim.TrimType == BrepTrimType.Seam) { RhinoApp.WriteLine("Unable to extend surface at seam."); return(Result.Nothing); } var extended_surface = surface.Extend(trim.IsoStatus, 5.0, true); if (extended_surface != null) { var mybrep = Brep.CreateFromSurface(extended_surface); doc.Objects.Replace(obj_ref.ObjectId, mybrep); doc.Views.Redraw(); } return(Result.Success); }
protected override void onReleaseOculusTrigger(ref VREvent_t vrEvent) { if (currentState == State.DRAW) { //simplfy the curve first before doing next interaction if (((Geometry.GeometryStroke)(stroke_g)).mPoints.Count >= 2) { simplifyCurve(ref ((Geometry.GeometryStroke)(stroke_g)).mPoints); //add to Scene curve object ,targetRhobj and check the next interaction //since dynamicRender == "none" then it didn't enter generateModel function if (dynamicRender == "none") { if (drawnType != DrawnType.In3D && curveOnObjRef != null) { //simplifyCurve(ref ((Geometry.GeometryStroke)(stroke_g)).mPoints); simplifiedCurve.SetUserString(CurveData.CurveOnObj.ToString(), curveOnObjRef.ObjectId.ToString()); } localListCurve.Add(simplifiedCurve); } //generate new curveOnObj for mvoingPlane cases and move all moveplanes back to original position later if (drawnType == DrawnType.Plane) { Rhino.Geometry.Vector3d newNormal = new Rhino.Geometry.Vector3d();; Point3d newOrigin = new Point3d(); if (curveOnObjRef.Object().Attributes.Name.Contains("planeXY")) { newNormal = new Rhino.Geometry.Vector3d(0, 0, 1); newOrigin = new Point3d(0, 0, curveOnObjRef.Object().Geometry.GetBoundingBox(true).Center.Z); } else if (curveOnObjRef.Object().Attributes.Name.Contains("planeYZ")) { newNormal = new Rhino.Geometry.Vector3d(1, 0, 0); newOrigin = new Point3d(curveOnObjRef.Object().Geometry.GetBoundingBox(true).Center.X, 0, 0); } else if (curveOnObjRef.Object().Attributes.Name.Contains("planeXZ")) { newNormal = new Rhino.Geometry.Vector3d(0, 1, 0); newOrigin = new Point3d(0, curveOnObjRef.Object().Geometry.GetBoundingBox(true).Center.Y, 0); } Plane newPlane = new Plane(newOrigin, newNormal); int size = 240; PlaneSurface plane_surface = new PlaneSurface(newPlane, new Interval(-size, size), new Interval(-size, size)); Brep newPlaneBrep = Brep.CreateFromSurface(plane_surface); Guid newPlaneID = UtilOld.addRhinoObject(ref mScene, ref newPlaneBrep, "MoveP"); curveOnObjRef = null; curveOnObjRef = new ObjRef(newPlaneID); //update curveOnObj to new plane if (localListCurve.Count > 0) { localListCurve[localListCurve.Count - 1].SetUserString(CurveData.CurveOnObj.ToString(), curveOnObjRef.ObjectId.ToString()); } else { localListCurve.Add(simplifiedCurve); localListCurve[localListCurve.Count - 1].SetUserString(CurveData.CurveOnObj.ToString(), curveOnObjRef.ObjectId.ToString()); } } //call next interaction in the chain //testing if mScene.iCurveList update /* * mScene.iCurveList.Clear(); * for (int i =0; i < localListCurve.Count; i++) * { * mScene.iCurveList.Add(localListCurve[i]); * }*/ currentState = State.END; afterCurveCount = localListCurve.Count; if (dynamicRender != "none" && backgroundStart == false) { backgroundStart = true; R = d.BeginInvoke(new AsyncCallback(modelCompleted), null); } else if (dynamicRender == "none") { mScene.pushInteractionFromChain(); } //mScene.pushInteractionFromChain(); //curveOnObjRef = null; } } }
protected override void onClickOculusAX(ref VREvent_t vrEvent) { //TODO-support projection curve Point3d planeCenter = new Point3d(); if (!isProjection) { Brep[] shapes = Brep.CreatePlanarBreps(modelcurve); modelBrep = shapes[0]; //Util.addRhinoObjectSceneNode(ref mScene, ref modelBrep, ref mesh_m, shapeType.ToString(), out renderObjSN); UtilOld.addSceneNode(ref mScene, ref modelBrep, ref mesh_m, shapeType.ToString(), out renderObjSN); if (shapeType == ShapeType.Circle) { Circle circle; if (modelcurve.TryGetCircle(out circle)) { planeCenter = circle.Center; } mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(circle.Center))); mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(circle.PointAt(0)))); } else if (shapeType == ShapeType.Rect) { Rhino.Geometry.Polyline polyline; if (modelcurve.TryGetPolyline(out polyline)) { Rectangle3d rect = Rectangle3d.CreateFromPolyline(polyline); planeCenter = rect.Center; mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(rect.Center))); mScene.iPointList.Add(UtilOld.platformToVRPoint(ref mScene, UtilOld.RhinoToOpenTKPoint(rect.Corner(3)))); } } } //update modelPlane and use tolerance to support unplanar surface Plane curvePlane = new Plane(); Double tolerance = 0; while (tolerance < 400) { if (modelcurve.TryGetPlane(out curvePlane, tolerance)) { modelPlane = curvePlane; break; } tolerance++; } int size = 240; PlaneSurface plane_surface = new PlaneSurface(curvePlane, new Interval(-size, size), new Interval(-size, size)); Brep newPlaneBrep = Brep.CreateFromSurface(plane_surface); Guid newPlaneID = UtilOld.addRhinoObject(ref mScene, ref newPlaneBrep, "3DP"); //might be better to use Replace(), just need to be careful about the referece count pointOnObjRef = null; pointOnObjRef = new ObjRef(newPlaneID); //add icurveList since we don't use EditPoint2 for circle and rect modelcurve.SetUserString(CurveData.CurveOnObj.ToString(), newPlaneID.ToString()); modelcurve.SetUserString(CurveData.PlaneOrigin.ToString(), curvePlane.Origin.ToString()); modelcurve.SetUserString(CurveData.PlaneNormal.ToString(), curvePlane.Normal.ToString()); mScene.iCurveList.Add(modelcurve); //call next interaction in the chain afterCurveCount = mScene.iCurveList.Count; mScene.pushInteractionFromChain(); }
/// <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) { // 1. Declare placeholder variables and assign initial invalid data. // This way, if the input parameters fail to supply valid data, we know when to abort. HM.hMember member = null; // 2. Retrieve input data. if (!DA.GetData(0, ref member)) { return; } // 3. Abort on invalid inputs. //if (!member.IsValid) { return; } var webAxisLine = member.WebAxis; var webNormal = member.WebNormal; var OP1 = webAxisLine.StartPoint; var OP2 = webAxisLine.EndPoint; var webAxis = HM.Triple.ByTwoPoints(OP1, OP2); var normal = webNormal; var lateral = webAxis.Cross(normal); lateral = lateral.Normalized(); lateral = lateral.Scale(1.75); normal = normal.Normalized(); normal = normal.Scale(1.5); var lateralR = new HM.Triple(lateral.X * -1, lateral.Y * -1, lateral.Z * -1); var webAxisR = new HM.Triple(webAxis.X * -1, webAxis.Y * -1, webAxis.Z * -1); var normalR = new HM.Triple(normal.X * -1, normal.Y * -1, normal.Z * -1); var p0 = HMGHUtil.TripleToPoint(OP1.Add(normal.Add(lateral))); var p1 = HMGHUtil.TripleToPoint(OP2.Add(normal.Add(lateral))); var p2 = HMGHUtil.TripleToPoint(OP1.Add(lateral)); var p3 = HMGHUtil.TripleToPoint(OP2.Add(lateral)); var p6 = HMGHUtil.TripleToPoint(OP1.Add(normal.Add(lateralR))); var p7 = HMGHUtil.TripleToPoint(OP2.Add(normal.Add(lateralR))); var p4 = HMGHUtil.TripleToPoint(OP1.Add(lateralR)); var p5 = HMGHUtil.TripleToPoint(OP2.Add(lateralR)); lateral = lateral.Normalized().Scale(1.25); lateralR = lateralR.Normalized().Scale(1.25); var p8 = HMGHUtil.TripleToPoint(OP1.Add(lateralR).Add(normal)); var p9 = HMGHUtil.TripleToPoint(OP2.Add(lateralR).Add(normal)); var p10 = HMGHUtil.TripleToPoint(OP1.Add(lateral).Add(normal)); var p11 = HMGHUtil.TripleToPoint(OP2.Add(lateral).Add(normal)); var flange1 = NurbsSurface.CreateFromCorners(p0, p1, p3, p2); var flange2 = NurbsSurface.CreateFromCorners(p4, p5, p7, p6); var web = NurbsSurface.CreateFromCorners(p2, p3, p5, p4); var lip1 = NurbsSurface.CreateFromCorners(p0, p1, p11, p10); var lip2 = NurbsSurface.CreateFromCorners(p6, p7, p9, p8); var memGeo = new List <Brep>() { Brep.CreateFromSurface(flange1), Brep.CreateFromSurface(flange2), Brep.CreateFromSurface(web), Brep.CreateFromSurface(lip1), Brep.CreateFromSurface(lip2) }; var brep = Brep.JoinBreps(memGeo, 0.001)[0]; DA.SetData(0, brep); }