virtual public void CutMesh() { Frame3f frameL = SceneTransforms.SceneToObject(target, cut_plane); Action <DMesh3> editF = (mesh) => { MeshPlaneCut cut = new MeshPlaneCut(mesh, frameL.Origin, frameL.Y); cut.Cut(); PlaneProjectionTarget planeTarget = new PlaneProjectionTarget() { Origin = frameL.Origin, Normal = frameL.Y }; if (GenerateFillSurface) { double min, max, avg; MeshQueries.EdgeLengthStats(mesh, out min, out max, out avg); cut.FillHoles(); MeshFaceSelection selection = new MeshFaceSelection(mesh); foreach (var tris in cut.LoopFillTriangles) { selection.Select(tris); } RegionRemesher.QuickRemesh(mesh, selection.ToArray(), 2 * avg, 1.0f, 25, planeTarget); MeshNormals normals = new MeshNormals(mesh); normals.Compute(); normals.CopyTo(mesh); } }; target.EditAndUpdateMesh(editF, GeometryEditTypes.ArbitraryEdit); }
protected override void on_curve_validated() { if (previewGO != null) { RemoveGO((fGameObject)previewGO); previewGO.Destroy(); } if (EnableRegionOverlay) { if (TargetModelSO == null) { throw new InvalidOperationException("EnclosedPatchSO.on_curve_validated: curve is not connected to a Target"); } if (TransformMode != OutputCurveTransform.ToTargetSO) { throw new InvalidOperationException("EnclosedPatchSO.on_curve_validated: curve is not transformed to TargetSO"); } DCurve3 target_curve = RequestCurveCopyFromMainThread(); MeshFacesFromLoop loop = new MeshFacesFromLoop(TargetModel.SourceMesh, target_curve, TargetModel.SourceSpatial); MeshFaceSelection face_selection = loop.ToSelection(); DSubmesh3 submesh = new DSubmesh3(TargetModel.SourceMesh, face_selection, face_selection.Count); MeshNormals normals = new MeshNormals(submesh.SubMesh); normals.Compute(); foreach (int vid in submesh.SubMesh.VertexIndices()) { Vector3d n = normals.Normals[vid]; Vector3d v = submesh.SubMesh.GetVertex(vid); v += 0.1 * n; v = SceneTransforms.TransformTo(v, TargetModelSO, this); submesh.SubMesh.SetVertex(vid, v); } previewGO = GameObjectFactory.CreateMeshGO("patch", new fMesh(submesh.SubMesh), false, true); previewGO.SetMaterial(previewMaterial, true); previewGO.SetLayer(FPlatform.WidgetOverlayLayer); previewGO.SetIgnoreMaterialChanges(); AppendNewGO(previewGO, root, false); } }
protected override void SolveInstance(IGH_DataAccess DA) { DMesh3_goo goo = null; DA.GetData(0, ref goo); DMesh3 mesh = new DMesh3(goo.Value); List <Rhino.Geometry.Vector3d> vecs = new List <Rhino.Geometry.Vector3d>(); if (!mesh.HasVertexNormals) { var normals = new MeshNormals(mesh); normals.Compute(); } foreach (var ind in mesh.VertexIndices()) { vecs.Add(mesh.GetVertexNormal(ind).ToRhinoVec()); } DA.SetDataList(0, vecs); }
public virtual bool Apply() { DMesh3 testAgainstMesh = Mesh; if (InsideMode == CalculationMode.RayParity) { MeshBoundaryLoops loops = new MeshBoundaryLoops(testAgainstMesh); if (loops.Count > 0) { testAgainstMesh = new DMesh3(Mesh); foreach (var loop in loops) { if (Cancelled()) { return(false); } SimpleHoleFiller filler = new SimpleHoleFiller(testAgainstMesh, loop); filler.Fill(); } } } DMeshAABBTree3 spatial = (Spatial != null && testAgainstMesh == Mesh) ? Spatial : new DMeshAABBTree3(testAgainstMesh, true); if (InsideMode == CalculationMode.AnalyticWindingNumber) { spatial.WindingNumber(Vector3d.Zero); } else if (InsideMode == CalculationMode.FastWindingNumber) { spatial.FastWindingNumber(Vector3d.Zero); } if (Cancelled()) { return(false); } // ray directions List <Vector3d> ray_dirs = null; int NR = 0; if (InsideMode == CalculationMode.SimpleOcclusionTest) { ray_dirs = new List <Vector3d>(); ray_dirs.Add(Vector3d.AxisX); ray_dirs.Add(-Vector3d.AxisX); ray_dirs.Add(Vector3d.AxisY); ray_dirs.Add(-Vector3d.AxisY); ray_dirs.Add(Vector3d.AxisZ); ray_dirs.Add(-Vector3d.AxisZ); NR = ray_dirs.Count; } Func <Vector3d, bool> isOccludedF = (pt) => { if (InsideMode == CalculationMode.RayParity) { return(spatial.IsInside(pt)); } else if (InsideMode == CalculationMode.AnalyticWindingNumber) { return(spatial.WindingNumber(pt) > WindingIsoValue); } else if (InsideMode == CalculationMode.FastWindingNumber) { return(spatial.FastWindingNumber(pt) > WindingIsoValue); } else { for (int k = 0; k < NR; ++k) { int hit_tid = spatial.FindNearestHitTriangle(new Ray3d(pt, ray_dirs[k])); if (hit_tid == DMesh3.InvalidID) { return(false); } } return(true); } }; bool cancel = false; BitArray vertices = null; if (PerVertex) { vertices = new BitArray(Mesh.MaxVertexID); MeshNormals normals = null; if (Mesh.HasVertexNormals == false) { normals = new MeshNormals(Mesh); normals.Compute(); } gParallel.ForEach(Mesh.VertexIndices(), (vid) => { if (cancel) { return; } if (vid % 10 == 0) { cancel = Cancelled(); } Vector3d c = Mesh.GetVertex(vid); Vector3d n = (normals == null) ? Mesh.GetVertexNormal(vid) : normals[vid]; c += n * NormalOffset; vertices[vid] = isOccludedF(c); }); } if (Cancelled()) { return(false); } RemovedT = new List <int>(); SpinLock removeLock = new SpinLock(); gParallel.ForEach(Mesh.TriangleIndices(), (tid) => { if (cancel) { return; } if (tid % 10 == 0) { cancel = Cancelled(); } bool inside = false; if (PerVertex) { Index3i tri = Mesh.GetTriangle(tid); inside = vertices[tri.a] || vertices[tri.b] || vertices[tri.c]; } else { Vector3d c = Mesh.GetTriCentroid(tid); Vector3d n = Mesh.GetTriNormal(tid); c += n * NormalOffset; inside = isOccludedF(c); } if (inside) { bool taken = false; removeLock.Enter(ref taken); RemovedT.Add(tid); removeLock.Exit(); } }); if (Cancelled()) { return(false); } if (RemovedT.Count > 0) { MeshEditor editor = new MeshEditor(Mesh); bool bOK = editor.RemoveTriangles(RemovedT, true); RemoveFailed = (bOK == false); } return(true); }