Skip to content

Commit

Permalink
Added C# SampleCsQuadRemesh example to SampleCsCommands project
Browse files Browse the repository at this point in the history
  • Loading branch information
travisserio committed May 19, 2020
1 parent 06588ee commit 72bb746
Show file tree
Hide file tree
Showing 2 changed files with 108 additions and 1 deletion.
107 changes: 107 additions & 0 deletions rhinocommon/cs/SampleCsCommands/SampleCSQuadRemesh.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
using Rhino;
using Rhino.Commands;
using Rhino.DocObjects;
using Rhino.Geometry;
using Rhino.Input;
using Rhino.Input.Custom;

namespace SampleCsCommands
{
public class SampleCsQuadRemesh : Command
{
static SampleCsQuadRemesh _instance;
public SampleCsQuadRemesh()
{
_instance = this;
}

///<summary>The only instance of the SampleCSQuadRemesh command.</summary>
public static SampleCsQuadRemesh Instance
{
get { return _instance; }
}

public override string EnglishName
{
get { return "SampleCsQuadRemesh"; }
}

protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
//Select some object
var go = new GetObject();
go.SetCommandPrompt("Select object to remesh");
go.GeometryFilter = ObjectType.Brep | ObjectType.Mesh;
go.Get();

if (go.Result() != GetResult.Object)
return Result.Cancel;

//Grab the results of the object picker.
var rhino_object = go.Object(0).Object();


//Set our desired quad remesh parameters
var quad_remesh_parameters = new QuadRemeshParameters()
{
TargetQuadCount = 2000,
AdaptiveQuadCount = true,
AdaptiveSize = .5,
DetectHardEdges = true,
SymmetryAxis = QuadRemeshSymmetryAxis.X | QuadRemeshSymmetryAxis.Y | QuadRemeshSymmetryAxis.Z, //Set symmetry on all 3 axis
GuideCurveInfluence = 0, //Guide Curve Influence 0 Approx ; 1 = Edge Ring ; 2 = Edge Loop (ignored if no curve array input)
};

//Remesh a selected BRep
if (rhino_object.ObjectType == ObjectType.Brep)
{
if (!(rhino_object.Geometry is Brep brep))
return Result.Cancel;

//Remesh the brep
//Optionally this method also accepts an IEnumerable<Curve> overload.
//Pass it your curve object array/list if you want guide curves)
//If guide curves, lastly change your quad_remesh_parameters.GuideCurveInfluence if using curves
var remeshed = Mesh.QuadRemeshBrep(brep, quad_remesh_parameters);

if (remeshed == null)
return Result.Cancel;

//Add the result to the doc
doc.Objects.AddMesh(remeshed);
doc.Views.Redraw();
RhinoApp.WriteLine("1 Brep successfully remeshed");
}
//Remesh a selected Mesh
else if(rhino_object.ObjectType == ObjectType.Mesh)
{
if (!(rhino_object is MeshObject mesh_object))
return Result.Cancel;

//Make sure this is a valid selected mesh object (it should be)
if (!mesh_object.MeshGeometry.IsValid)
return Result.Cancel;

//Do the remeshing of the Mesh Objects Mesh Geometry
var remeshed = mesh_object.MeshGeometry.QuadRemesh(quad_remesh_parameters);

if (remeshed == null)
return Result.Cancel;

//Add the result to the doc
doc.Objects.AddMesh(remeshed);
doc.Views.Redraw();
RhinoApp.WriteLine("1 Mesh successfully remeshed");
}








return Result.Success;
}
}
}
2 changes: 1 addition & 1 deletion rhinocommon/cs/SampleCsCommands/SampleCsCommands.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="Xfinium.Pdf.Win">
<HintPath>C:\Program Files\Rhino 7 WIP\Plug-ins\Xfinium.Pdf.Win.dll</HintPath>
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
Expand Down Expand Up @@ -181,6 +180,7 @@
<Compile Include="SampleCsPrintViewList.cs" />
<Compile Include="SampleCsProjectCurvesToBrep.cs" />
<Compile Include="SampleCsProjectPointToMesh.cs" />
<Compile Include="SampleCsQuadRemesh.cs" />
<Compile Include="SampleCsRenderBackground.cs" />
<Compile Include="SampleCsRestoreLayerState.cs" />
<Compile Include="SampleCsRestoreNamedView.cs" />
Expand Down

0 comments on commit 72bb746

Please sign in to comment.