forked from mdjcad/SampleCsCommands
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSampleCsShadedBrep.cs
104 lines (89 loc) · 2.6 KB
/
SampleCsShadedBrep.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System;
using System.Drawing;
using Rhino;
using Rhino.Commands;
using Rhino.Display;
using Rhino.Geometry;
using Rhino.Input;
namespace SampleCsCommands
{
/// <summary>
/// SampleCsShadedBrepConduit display conduit
/// </summary>
class SampleCsShadedBrepConduit : DisplayConduit
{
private Brep m_brep;
public SampleCsShadedBrepConduit()
{
m_brep = null;
}
public Brep BrepGeometry
{
get { return m_brep; }
set
{
m_brep = value;
if (null != m_brep && m_brep.IsValid)
{
if (m_brep.SolidOrientation == BrepSolidOrientation.Inward)
m_brep.Flip();
}
}
}
protected override void CalculateBoundingBox(CalculateBoundingBoxEventArgs e)
{
if (null != m_brep && m_brep.IsValid)
{
e.BoundingBox.Union(BrepGeometry.GetBoundingBox(false));
}
}
/// <summary>
/// If you’re drawing shaded objects, then you’ll probably want to draw them in either
/// the PreDrawObjects or PostDrawObjects channel. However, if transparency is involved,
/// then you’ll have to draw them in PostDrawObjects in order for all other objects to
/// “show through” your transparent ones.
/// </summary>
protected override void PostDrawObjects(DrawEventArgs e)
{
if (null != m_brep && m_brep.IsValid)
{
DisplayMaterial material = new DisplayMaterial();
material.Diffuse = Color.RoyalBlue;
e.Display.DrawBrepShaded(m_brep, material);
}
}
}
/// <summary>
/// SampleCsShadedBrep command
/// </summary>
[System.Runtime.InteropServices.Guid("380a2b33-6c84-4e26-a705-c539f47c1548")]
public class SampleCsShadedBrep : Command
{
public SampleCsShadedBrep()
{
}
public override string EnglishName
{
get { return "SampleCsShadedBrep"; }
}
protected override Result RunCommand(RhinoDoc doc, RunMode mode)
{
Plane plane = Plane.WorldXY;
double radius = 10.0;
double height = 2.0;
Circle circle = new Circle(plane, radius);
Cylinder cylinder = new Cylinder(circle, height);
Brep brep = Brep.CreateFromCylinder(cylinder, true, true);
SampleCsShadedBrepConduit conduit = new SampleCsShadedBrepConduit();
conduit.BrepGeometry = brep;
conduit.Enabled = true;
doc.Views.Redraw();
string out_str = null;
Result rc = RhinoGet.GetString("Press <Enter> to continue", true, ref out_str);
conduit.Enabled = false;
doc.Objects.AddBrep(brep);
doc.Views.Redraw();
return Result.Success;
}
}
}