protected override Result RunCommand(RhinoDoc doc, RunMode mode) { OptionDouble amountOption = new OptionDouble(amount, 0.001, 300); OptionInteger triesOption = new OptionInteger(tries, 1, 1000); GetObject go = new GetObject(); go.SetCommandPrompt("Select meshes to Randomize"); go.AddOptionDouble("Amount", ref amountOption); go.AddOptionInteger("Tries", ref triesOption); go.GeometryFilter = Rhino.DocObjects.ObjectType.Mesh; for (;;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { tries = triesOption.CurrentValue; amount = amountOption.CurrentValue; continue; } if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } break; } if (go.ObjectCount < 1) { return(Result.Failure); } foreach (var obj in go.Objects()) { var rhinoMesh = obj.Mesh(); if (rhinoMesh == null || !rhinoMesh.IsValid) { continue; } var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh()); g3.DMesh3 outputMeshRandom; GopherUtil.RandomizeMesh(mesh, out outputMeshRandom, amount, tries); var rhinoOutputMeshRandom = GopherUtil.ConvertToRhinoMesh(outputMeshRandom); doc.Objects.Replace(obj, rhinoOutputMeshRandom); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType geometry_filter = ObjectType.Surface | ObjectType.PolysrfFilter | ObjectType.Mesh; var integer1 = 300; var integer2 = 300; var option_integer1 = new OptionInteger(integer1, 200, 900); var option_integer2 = new OptionInteger(integer2, 200, 900); var go = new GetObject(); go.SetCommandPrompt("Select surfaces, polysurfaces, or meshes"); go.GeometryFilter = geometry_filter; go.AddOptionInteger("Option1", ref option_integer1); go.AddOptionInteger("Option2", ref option_integer2); go.GroupSelect = true; go.SubObjectSelect = false; var have_preselected_objects = false; while (true) { var res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); go.AlreadySelectedObjectSelect = true; go.EnableClearObjectsOnEntry(false); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); continue; } if (res != GetResult.Object) { return(Result.Cancel); } if (go.ObjectsWerePreselected) { have_preselected_objects = true; go.EnablePreSelect(false, true); go.AlreadySelectedObjectSelect = true; go.EnableClearObjectsOnEntry(false); go.DeselectAllBeforePostSelect = false; go.EnableUnselectObjectsOnExit(false); continue; } break; } if (have_preselected_objects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (var i = 0; i < go.ObjectCount; i++) { var rhino_object = go.Object(i).Object(); rhino_object?.Select(false); } doc.Views.Redraw(); } var object_count = go.ObjectCount; integer1 = option_integer1.CurrentValue; integer2 = option_integer2.CurrentValue; RhinoApp.WriteLine("Select object count: {0}", object_count); RhinoApp.WriteLine("Value of integer1: {0}", integer1); RhinoApp.WriteLine("Value of integer2: {0}", integer2); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { bool bHavePreselectedObjects = false; const ObjectType geometryFilter = ObjectType.MeshFace; OptionDouble minEdgeLengthOption = new OptionDouble(minEdgeLength, 0.001, 200); OptionDouble maxEdgeLengthOption = new OptionDouble(maxEdgeLength, 0.001, 200); OptionDouble constriantAngleOption = new OptionDouble(constriantAngle, 0.001, 360); OptionInteger smoothStepsOptions = new OptionInteger(smoothSteps, 0, 100); OptionDouble smoothSpeedOption = new OptionDouble(smoothSpeed, 0.01, 1.0); OptionDouble projectAmountOption = new OptionDouble(projectedAmount, 0.01, 1.0); OptionDouble projectedDistanceOption = new OptionDouble(projectedDistance, 0.01, 100000.0); GetObject go = new GetObject(); go.SetCommandPrompt("Select mesh faces to project onto another mesh"); go.GeometryFilter = geometryFilter; go.AddOptionDouble("ConstraintAngle", ref constriantAngleOption); go.AddOptionDouble("MinEdge", ref minEdgeLengthOption); go.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption); go.AddOptionInteger("SmoothSteps", ref smoothStepsOptions); go.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption); go.GroupSelect = true; go.SubObjectSelect = true; for (; ;) { GetResult faceres = go.GetMultiple(1, 0); if (faceres == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } minEdgeLength = minEdgeLengthOption.CurrentValue; maxEdgeLength = maxEdgeLengthOption.CurrentValue; constriantAngle = constriantAngleOption.CurrentValue; smoothSteps = smoothStepsOptions.CurrentValue; smoothSpeed = smoothSpeedOption.CurrentValue; //System.Collections.Generic.List<System.Guid> meshes = new System.Collections.Generic.List<System.Guid>(); System.Guid rhinoMesh = System.Guid.Empty; System.Collections.Generic.List <int> removeFaces = new System.Collections.Generic.List <int>(); g3.DMesh3 projectFaces = new g3.DMesh3(true, false, false, false); Rhino.Geometry.Mesh rhinoInputMesh = new Rhino.Geometry.Mesh(); for (int i = 0; i < go.ObjectCount; i++) { ObjRef obj = go.Object(i); if (rhinoMesh == System.Guid.Empty) { rhinoMesh = obj.ObjectId; rhinoInputMesh = obj.Mesh(); for (int j = 0; j < rhinoInputMesh.Vertices.Count; j++) { var vertex = new g3.NewVertexInfo(); vertex.n = new g3.Vector3f(rhinoInputMesh.Normals[j].X, rhinoInputMesh.Normals[j].Y, rhinoInputMesh.Normals[j].Z); vertex.v = new g3.Vector3d(rhinoInputMesh.Vertices[j].X, rhinoInputMesh.Vertices[j].Y, rhinoInputMesh.Vertices[j].Z); projectFaces.AppendVertex(vertex); } } var m = rhinoInputMesh; if (rhinoMesh != obj.ObjectId) { continue; } removeFaces.Add(obj.GeometryComponentIndex.Index); var mf = rhinoInputMesh.Faces[obj.GeometryComponentIndex.Index]; if (mf.IsQuad) { double dist1 = m.Vertices[mf.A].DistanceTo(m.Vertices[mf.C]); double dist2 = m.Vertices[mf.B].DistanceTo(m.Vertices[mf.D]); if (dist1 > dist2) { projectFaces.AppendTriangle(mf.A, mf.B, mf.D); projectFaces.AppendTriangle(mf.B, mf.C, mf.D); } else { projectFaces.AppendTriangle(mf.A, mf.B, mf.C); projectFaces.AppendTriangle(mf.A, mf.C, mf.D); } } else { projectFaces.AppendTriangle(mf.A, mf.B, mf.C); } } if (rhinoInputMesh == null) { return(Result.Failure); } removeFaces.Sort(); removeFaces.Reverse(); foreach (var removeFace in removeFaces) { rhinoInputMesh.Faces.RemoveAt(removeFace); } rhinoInputMesh.Compact(); GetObject goProjected = new GetObject(); goProjected.EnablePreSelect(false, true); goProjected.SetCommandPrompt("Select mesh to project to"); goProjected.GeometryFilter = ObjectType.Mesh; goProjected.AddOptionDouble("ConstraintAngle", ref constriantAngleOption); goProjected.AddOptionDouble("MinEdge", ref minEdgeLengthOption); goProjected.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption); goProjected.AddOptionInteger("SmoothSteps", ref smoothStepsOptions); goProjected.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption); goProjected.AddOptionDouble("ProjectAmount", ref projectAmountOption); goProjected.AddOptionDouble("ProjectDistance", ref projectedDistanceOption); goProjected.GroupSelect = true; goProjected.SubObjectSelect = false; goProjected.EnableClearObjectsOnEntry(false); goProjected.EnableUnselectObjectsOnExit(false); for (; ;) { GetResult resProject = goProjected.Get(); if (resProject == GetResult.Option) { continue; } else if (goProjected.CommandResult() != Result.Success) { return(goProjected.CommandResult()); } break; } minEdgeLength = minEdgeLengthOption.CurrentValue; maxEdgeLength = maxEdgeLengthOption.CurrentValue; constriantAngle = constriantAngleOption.CurrentValue; smoothSteps = smoothStepsOptions.CurrentValue; smoothSpeed = smoothSpeedOption.CurrentValue; projectedAmount = projectAmountOption.CurrentValue; projectedDistance = projectedDistanceOption.CurrentValue; if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } bool result = false; if (goProjected.ObjectCount < 1) { return(Result.Failure); } var rhinoMeshProject = goProjected.Object(0).Mesh(); if (rhinoMeshProject == null || !rhinoMeshProject.IsValid) { return(Result.Failure); } var meshProjected = GopherUtil.ConvertToD3Mesh(rhinoMeshProject); var res = GopherUtil.RemeshMesh(projectFaces, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance); var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(res); if (newRhinoMesh != null && newRhinoMesh.IsValid) { newRhinoMesh.Append(rhinoInputMesh); result |= doc.Objects.Replace(rhinoMesh, newRhinoMesh); } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { //look at this for a summary of all the GET commands. // https://developer.rhino3d.com/api/RhinoCommon/html/T_Rhino_Input_Custom_GetBaseClass.htm. /*System.Object * Rhino.Input.Custom.GetBaseClass * Rhino.Input.Custom.GetInteger * Rhino.Input.Custom.GetNumber * Rhino.Input.Custom.GetObject * Rhino.Input.Custom.GetOption * Rhino.Input.Custom.GetPoint * Rhino.Input.Custom.GetString * * */ var gc = new GetObject(); gc.SetCommandPrompt("Select objects"); gc.GeometryFilter = ObjectType.AnyObject; OptionInteger intOption = new OptionInteger(1, 1, 99); OptionDouble dblOption = new OptionDouble(2.2, 0, 99); OptionToggle boolOption = new OptionToggle(true, "off", "on"); gc.AddOptionInteger("Integer", ref intOption); gc.AddOptionDouble("Double", ref dblOption); gc.AddOptionToggle("Boolean", ref boolOption); int listIndex = 0; string[] listValues = new string[] { "Bran", "Bob", "Arya", "Sansa", "Rickon" }; int optList = gc.AddOptionList("List", listValues, listIndex); while (true) { GetResult res = gc.GetMultiple(1, 0); //we can check if the user selected something if (gc.CommandResult() != Result.Success) { return(gc.CommandResult()); } if (res == Rhino.Input.GetResult.Object) { RhinoApp.WriteLine("Command line option values are"); RhinoApp.WriteLine("Integer = {0}", intOption.CurrentValue); RhinoApp.WriteLine("Double = {0}", dblOption.CurrentValue); RhinoApp.WriteLine("Boolean = {0}", boolOption.CurrentValue); RhinoApp.WriteLine("List = {0}", listValues[listIndex]); } else if (res == Rhino.Input.GetResult.Option) { if (gc.OptionIndex() == optList) { listIndex = gc.Option().CurrentListOptionIndex; //this updates the list option to whatever index the user has picked } continue; } break; } return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType geometryFilter = ObjectType.Mesh; OptionDouble minEdgeLengthOption = new OptionDouble(minEdgeLength, 0.001, 200); OptionDouble maxEdgeLengthOption = new OptionDouble(maxEdgeLength, 0.001, 200); OptionDouble constriantAngleOption = new OptionDouble(constriantAngle, 0.001, 360); OptionInteger smoothStepsOptions = new OptionInteger(smoothSteps, 0, 10000); OptionDouble smoothSpeedOption = new OptionDouble(smoothSpeed, 0.01, 1.0); GetObject go = new GetObject(); go.SetCommandPrompt("Select meshes to remesh"); go.GeometryFilter = geometryFilter; go.AddOptionDouble("ConstraintAngle", ref constriantAngleOption); go.AddOptionDouble("MinEdge", ref minEdgeLengthOption); go.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption); go.AddOptionInteger("SmoothSteps", ref smoothStepsOptions); go.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (;;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } minEdgeLength = minEdgeLengthOption.CurrentValue; maxEdgeLength = maxEdgeLengthOption.CurrentValue; constriantAngle = constriantAngleOption.CurrentValue; smoothSteps = smoothStepsOptions.CurrentValue; smoothSpeed = smoothSpeedOption.CurrentValue; if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } bool result = false; foreach (var obj in go.Objects()) { var rhinoMesh = obj.Mesh(); if (rhinoMesh == null || !rhinoMesh.IsValid) { continue; } var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh()); var res = GopherUtil.RemeshMesh(mesh, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps); var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(mesh); if (newRhinoMesh != null && newRhinoMesh.IsValid) { doc.Objects.Replace(obj, newRhinoMesh); } if (newRhinoMesh != null && newRhinoMesh.IsValid) { result |= doc.Objects.Replace(obj, newRhinoMesh); } } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType geometryFilter = ObjectType.Mesh; OptionDouble minEdgeLengthOption = new OptionDouble(minEdgeLength, 0.001, 200); OptionDouble maxEdgeLengthOption = new OptionDouble(maxEdgeLength, 0.001, 200); OptionDouble constriantAngleOption = new OptionDouble(constriantAngle, 0.001, 360); OptionInteger smoothStepsOptions = new OptionInteger(smoothSteps, 0, 1000); OptionDouble smoothSpeedOption = new OptionDouble(smoothSpeed, 0.01, 1.0); OptionDouble projectAmountOption = new OptionDouble(projectedAmount, 0.01, 1.0); OptionDouble projectedDistanceOption = new OptionDouble(projectedDistance, 0.01, 100000.0); GetObject go = new GetObject(); go.SetCommandPrompt("Select mesh to remesh"); go.GeometryFilter = geometryFilter; go.AddOptionDouble("ConstraintAngle", ref constriantAngleOption); go.AddOptionDouble("MinEdge", ref minEdgeLengthOption); go.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption); go.AddOptionInteger("SmoothSteps", ref smoothStepsOptions); go.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption); go.AddOptionDouble("ProjectAmount", ref projectAmountOption); go.AddOptionDouble("ProjectDistance", ref projectedDistanceOption); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (;;) { GetResult res = go.Get(); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } GetObject goProjected = new GetObject(); goProjected.EnablePreSelect(false, true); goProjected.SetCommandPrompt("Select mesh to project to"); goProjected.GeometryFilter = geometryFilter; goProjected.AddOptionDouble("ConstraintAngle", ref constriantAngleOption); goProjected.AddOptionDouble("MinEdge", ref minEdgeLengthOption); goProjected.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption); goProjected.AddOptionInteger("SmoothSteps", ref smoothStepsOptions); goProjected.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption); goProjected.AddOptionDouble("ProjectAmount", ref projectAmountOption); goProjected.AddOptionDouble("ProjectDistance", ref projectedDistanceOption); goProjected.GroupSelect = true; goProjected.SubObjectSelect = false; goProjected.EnableClearObjectsOnEntry(false); goProjected.EnableUnselectObjectsOnExit(false); for (;;) { GetResult res = goProjected.Get(); if (res == GetResult.Option) { continue; } else if (goProjected.CommandResult() != Result.Success) { return(goProjected.CommandResult()); } break; } minEdgeLength = minEdgeLengthOption.CurrentValue; maxEdgeLength = maxEdgeLengthOption.CurrentValue; constriantAngle = constriantAngleOption.CurrentValue; smoothSteps = smoothStepsOptions.CurrentValue; smoothSpeed = smoothSpeedOption.CurrentValue; projectedAmount = projectAmountOption.CurrentValue; projectedDistance = projectedDistanceOption.CurrentValue; if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) { rhinoObject.Select(false); } } doc.Views.Redraw(); } bool result = false; if (goProjected.ObjectCount < 1) { return(Result.Failure); } foreach (var obj in go.Objects()) { var rhinoMesh = obj.Mesh(); if (rhinoMesh == null || !rhinoMesh.IsValid) { continue; } var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh()); var rhinoMeshProject = goProjected.Object(0).Mesh(); if (rhinoMeshProject == null || !rhinoMeshProject.IsValid) { continue; } var meshProjected = GopherUtil.ConvertToD3Mesh(rhinoMeshProject); var mesh2 = new DMesh3(mesh); var mesh3 = new DMesh3(mesh); var res3 = GopherUtil.RemeshMesh(mesh3, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance); var watch = System.Diagnostics.Stopwatch.StartNew(); // the code that you want to measure comes here var res = GopherUtil.RemeshMesh(mesh, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance); watch.Stop(); var watch2 = System.Diagnostics.Stopwatch.StartNew(); var res2 = GopherUtil.RemeshMeshNew(mesh2, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, meshProjected, (float)projectedAmount, (float)projectedDistance); watch2.Stop(); Rhino.RhinoApp.WriteLine("Time 1: {0} Time 2: {1}", watch.ElapsedMilliseconds, watch2.ElapsedMilliseconds); var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(res); var newRhinoMesh2 = GopherUtil.ConvertToRhinoMesh(mesh2); newRhinoMesh2.Translate(new Rhino.Geometry.Vector3d(newRhinoMesh2.GetBoundingBox(true).Diagonal.X, 0, 0)); doc.Objects.Add(newRhinoMesh2); if (newRhinoMesh != null && newRhinoMesh.IsValid) { doc.Objects.Replace(obj, newRhinoMesh); } if (newRhinoMesh != null && newRhinoMesh.IsValid) { result |= doc.Objects.Replace(obj, newRhinoMesh); } } doc.Views.Redraw(); return(Result.Success); }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType geometryFilter = ObjectType.Mesh; OptionDouble minEdgeLengthOption = new OptionDouble(minEdgeLength, 0.001, 200); OptionInteger maxTriangleCountOption = new OptionInteger(maxTriangleCount, 0, 100000000); GetObject go = new GetObject(); go.SetCommandPrompt("Select meshes to reduce"); go.GeometryFilter = geometryFilter; go.AddOptionDouble("MinEdge", ref minEdgeLengthOption); go.AddOptionInteger("MaxTriangle", ref maxTriangleCountOption); go.GroupSelect = true; go.SubObjectSelect = false; go.EnableClearObjectsOnEntry(false); go.EnableUnselectObjectsOnExit(false); go.DeselectAllBeforePostSelect = false; bool bHavePreselectedObjects = false; for (;;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (go.CommandResult() != Result.Success) return go.CommandResult(); if (go.ObjectsWerePreselected) { bHavePreselectedObjects = true; go.EnablePreSelect(false, true); continue; } break; } maxTriangleCount = maxTriangleCountOption.CurrentValue; minEdgeLength = minEdgeLengthOption.CurrentValue; if (bHavePreselectedObjects) { // Normally, pre-selected objects will remain selected, when a // command finishes, and post-selected objects will be unselected. // This this way of picking, it is possible to have a combination // of pre-selected and post-selected. So, to make sure everything // "looks the same", lets unselect everything before finishing // the command. for (int i = 0; i < go.ObjectCount; i++) { RhinoObject rhinoObject = go.Object(i).Object(); if (null != rhinoObject) rhinoObject.Select(false); } doc.Views.Redraw(); } bool result = false; foreach (var obj in go.Objects()) { var rhinoMesh = obj.Mesh(); if (rhinoMesh == null || !rhinoMesh.IsValid) continue; var mesh = GopherUtil.ConvertToD3Mesh(obj.Mesh()); GopherUtil.ReduceMesh(mesh, (float)minEdgeLength, maxTriangleCount); double mine, maxe, avge; MeshQueries.EdgeLengthStats(mesh, out mine, out maxe, out avge); RhinoApp.WriteLine("Edge length stats: {0} {1} {2}", mine, maxe, avge); var newRhinoMesh = GopherUtil.ConvertToRhinoMesh(mesh); if (newRhinoMesh != null && newRhinoMesh.IsValid) { doc.Objects.Replace(obj, newRhinoMesh); } if (newRhinoMesh != null && newRhinoMesh.IsValid) { result |= doc.Objects.Replace(obj, newRhinoMesh); } } doc.Views.Redraw(); return Result.Success; }
protected override Result RunCommand(RhinoDoc doc, RunMode mode) { const ObjectType geometryFilter = ObjectType.MeshEdge; OptionDouble minEdgeLengthOption = new OptionDouble(minEdgeLength, 0.001, 200); OptionDouble maxEdgeLengthOption = new OptionDouble(maxEdgeLength, 0.001, 200); OptionDouble constriantAngleOption = new OptionDouble(constriantAngle, 0.001, 360); OptionInteger smoothStepsOptions = new OptionInteger(smoothSteps, 0, 1000); OptionDouble smoothSpeedOption = new OptionDouble(smoothSpeed, 0.01, 1.0); GetObject go = new GetObject(); go.SetCommandPrompt("Select mesh edges to constrain during remesh"); go.GeometryFilter = geometryFilter; go.AddOptionDouble("ConstraintAngle", ref constriantAngleOption); go.AddOptionDouble("MinEdge", ref minEdgeLengthOption); go.AddOptionDouble("MaxEdge", ref maxEdgeLengthOption); go.AddOptionInteger("SmoothSteps", ref smoothStepsOptions); go.AddOptionDouble("SmoothSpeed", ref smoothSpeedOption); go.GroupSelect = true; go.SubObjectSelect = true; for (;;) { GetResult res = go.GetMultiple(1, 0); if (res == GetResult.Option) { go.EnablePreSelect(false, true); continue; } else if (go.CommandResult() != Result.Success) { return(go.CommandResult()); } break; } minEdgeLength = minEdgeLengthOption.CurrentValue; maxEdgeLength = maxEdgeLengthOption.CurrentValue; constriantAngle = constriantAngleOption.CurrentValue; smoothSteps = smoothStepsOptions.CurrentValue; smoothSpeed = smoothSpeedOption.CurrentValue; System.Collections.Generic.List <g3.Line3d> constrain = new System.Collections.Generic.List <g3.Line3d>(); System.Collections.Generic.List <System.Guid> meshes = new System.Collections.Generic.List <System.Guid>(); foreach (var obj in go.Objects()) { if (!meshes.Contains(obj.ObjectId)) { meshes.Add(obj.ObjectId); } ObjRef objref = new ObjRef(obj.ObjectId); var mesh = objref.Mesh(); var line = mesh.TopologyEdges.EdgeLine(obj.GeometryComponentIndex.Index); var dir = line.Direction; constrain.Add(new g3.Line3d(new Vector3d(line.FromX, line.FromY, line.FromZ), new Vector3d(dir.X, dir.Y, dir.Z))); } foreach (var guid in meshes) { var objref = new ObjRef(guid); var mesh = GopherUtil.ConvertToD3Mesh(objref.Mesh()); var res = GopherUtil.RemeshMesh(mesh, (float)minEdgeLength, (float)maxEdgeLength, (float)constriantAngle, (float)smoothSpeed, smoothSteps, constrain); var newMesh = GopherUtil.ConvertToRhinoMesh(res); doc.Objects.Replace(objref, newMesh); } doc.Views.Redraw(); return(Result.Success); }