-
Notifications
You must be signed in to change notification settings - Fork 334
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds C# samples for RibbonOffset and Silhouette draft curve (mold mak…
…ing tools). Fixes RH-58256 Draft Curve Fixes RH-58255 RibbonOffset
- Loading branch information
1 parent
443b70e
commit 64564b6
Showing
3 changed files
with
195 additions
and
4 deletions.
There are no files selected for viewing
99 changes: 99 additions & 0 deletions
99
rhinocommon/cs/SampleCsCommands/SampleCSRibbonOffsetCurve.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
using Rhino; | ||
using Rhino.Commands; | ||
using Rhino.DocObjects; | ||
using Rhino.Geometry; | ||
using Rhino.Input; | ||
using Rhino.Input.Custom; | ||
|
||
namespace SampleCsCommands | ||
{ | ||
public class SampleCSRibbonOffsetCurve : Command | ||
{ | ||
static SampleCSRibbonOffsetCurve _instance; | ||
public SampleCSRibbonOffsetCurve() | ||
{ | ||
_instance = this; | ||
} | ||
|
||
///<summary>The only instance of the SampleCSRibbonOffsetCurve command.</summary> | ||
public static SampleCSRibbonOffsetCurve Instance | ||
{ | ||
get { return _instance; } | ||
} | ||
|
||
public override string EnglishName | ||
{ | ||
get { return "SampleCSRibbonOffsetCurve"; } | ||
} | ||
|
||
protected override Result RunCommand(RhinoDoc doc, RunMode mode) | ||
{ | ||
//Get a closed curve to offset | ||
var go = new GetObject | ||
{ | ||
GeometryFilter = ObjectType.Curve, | ||
GeometryAttributeFilter = GeometryAttributeFilter.ClosedCurve | ||
}; | ||
go.SetCommandPrompt("Select curve to offset"); | ||
go.Get(); | ||
|
||
//The user did not select a curve | ||
if (go.Result() != GetResult.Object) | ||
return Result.Cancel; | ||
|
||
//Get the curve from the GetObject | ||
var crv = go.Object(0).Curve(); | ||
if (crv == null) | ||
return Result.Cancel; | ||
|
||
//Get the side of the curve to offset towards. | ||
var gp = new GetPoint(); | ||
gp.SetCommandPrompt("Select curve side to offset"); | ||
gp.Get(); | ||
|
||
//The user did not select a point | ||
if (gp.Result() != GetResult.Point) | ||
return Result.Cancel; | ||
//The selected Point | ||
var pt = gp.Point(); | ||
|
||
//Try to get the plane from the curve | ||
crv.TryGetPlane(out Plane ribbon_plane); | ||
if (!ribbon_plane.IsValid) | ||
ribbon_plane = doc.Views.ActiveView.ActiveViewport.ConstructionPlane(); | ||
|
||
//Set the ribbon plane vector | ||
var plane_vector = ribbon_plane.Normal; | ||
|
||
//Create the ribbon offset, its cross sections, and its ruled surfaces | ||
var ribbon_curve_output = crv.RibbonOffset(1, .1, pt, plane_vector, doc.ModelAbsoluteTolerance,out Curve[] cross_sections, out Surface[] ruled_surfaces); | ||
|
||
//Add the ribbon curve to the document | ||
if (ribbon_curve_output != null) | ||
{ | ||
doc.Objects.AddCurve(ribbon_curve_output); | ||
} | ||
|
||
//Add any cross section curves to the document | ||
if (cross_sections != null) | ||
{ | ||
foreach (var curve in cross_sections) | ||
{ | ||
doc.Objects.AddCurve(curve); | ||
} | ||
} | ||
|
||
//Add any ruled surfaces to the document | ||
if (ruled_surfaces != null) | ||
{ | ||
foreach (var surface in ruled_surfaces) | ||
{ | ||
doc.Objects.AddSurface(surface); | ||
} | ||
} | ||
|
||
doc.Views.Redraw(); | ||
return Result.Success; | ||
} | ||
} | ||
} |
90 changes: 90 additions & 0 deletions
90
rhinocommon/cs/SampleCsCommands/SampleCSSilhouetteDraftCurve.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
using System; | ||
using System.Drawing; | ||
using Rhino; | ||
using Rhino.Commands; | ||
using Rhino.DocObjects; | ||
using Rhino.Geometry; | ||
using Rhino.Input; | ||
using Rhino.Input.Custom; | ||
|
||
namespace SampleCsCommands | ||
{ | ||
public class SampleCSSilhouetteDraftCurve : Command | ||
{ | ||
static SampleCSSilhouetteDraftCurve _instance; | ||
public SampleCSSilhouetteDraftCurve() | ||
{ | ||
_instance = this; | ||
} | ||
|
||
///<summary>The only instance of the SampleCSShilhouetteDraftCurve command.</summary> | ||
public static SampleCSSilhouetteDraftCurve Instance | ||
{ | ||
get { return _instance; } | ||
} | ||
|
||
public override string EnglishName | ||
{ | ||
get { return "SampleCSSilhouetteDraftCurve"; } | ||
} | ||
|
||
protected override Result RunCommand(RhinoDoc doc, RunMode mode) | ||
{ | ||
|
||
//Select a brep or mesh to extract some curves from | ||
var go = new GetObject() {GeometryFilter = ObjectType.Brep | ObjectType.Mesh}; | ||
go.SetCommandPrompt("Select object for draft curve extraction"); | ||
go.Get(); | ||
if (go.Result() != GetResult.Object) | ||
return Result.Cancel; | ||
|
||
//The selected geometry base | ||
var geometry = go.Object(0).Geometry(); | ||
|
||
|
||
//Min & Max angle must be specified in Radians | ||
double min_angle = RhinoMath.ToRadians(-5.00); | ||
double max_angle = RhinoMath.ToRadians(5.00); | ||
|
||
//Set the vector direction of the draft computation | ||
Vector3d direction = Vector3d.ZAxis * -1; | ||
|
||
//Set the tolerances | ||
double tolerance = doc.ModelAbsoluteTolerance; | ||
double angle_tolerance = doc.ModelAngleToleranceRadians; | ||
|
||
//Compute the minimum draft angle curves | ||
var min_draft_silhouettes = Silhouette.ComputeDraftCurve(geometry, min_angle, direction, tolerance,angle_tolerance); | ||
|
||
//Compute the maximum draft angle curves | ||
var max_draft_silhouettes = Silhouette.ComputeDraftCurve(geometry, max_angle, direction, tolerance, angle_tolerance); | ||
|
||
|
||
//Add all of the minimum draft angle silhouette curves to the doc | ||
if (min_draft_silhouettes != null) | ||
{ | ||
var oa = new ObjectAttributes(){ObjectColor = Color.Red,ColorSource = ObjectColorSource.ColorFromObject}; | ||
foreach (var silhouette in min_draft_silhouettes) | ||
{ | ||
var crv = silhouette.Curve; | ||
doc.Objects.AddCurve(crv,oa); | ||
} | ||
} | ||
|
||
|
||
//Add all of the maximum draft angle silhouette curves to the doc | ||
if (max_draft_silhouettes != null) | ||
{ | ||
var oa = new ObjectAttributes(){ObjectColor = Color.Blue, ColorSource = ObjectColorSource.ColorFromObject }; | ||
foreach (var silhouette in max_draft_silhouettes) | ||
{ | ||
var crv = silhouette.Curve; | ||
doc.Objects.AddCurve(crv,oa); | ||
} | ||
} | ||
|
||
doc.Views.Redraw(); | ||
return Result.Success; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters