I have frequently heard the voice that the developers want to draw some custom graphics in Naivsworks e.g. the custom red line. Now it came true. The new plugin type provides methods to render user-graphics. It can render in 3D model space or 2D screen space. The new class Graphics is used to create the 2D/3D primitives.
Firstly, create a class deriving from RenderPlugin. It is a kind of implicit plugin which has no interface. So the attribute DisplayName is useless.
[Plugin("RenderPluginTest",
"ADSK")]
public class RenderPluginTest : RenderPlugin
{
}
Next, override the methods you want to use.
This method renders the graphics in the overlay buffer.By default it’s set up for you to call graphics methods that take 3D model space coordinates. You can call graphics methods that take 2D model space coordinates from inside a BeginWindowContext-EndWindowContext block.
This method renders the graphics in the overlay buffer. By default it’s set up for you to call graphics methods that take 2D window space coordinates. You can also call graphics methods that take 3D model space coordinates from inside a BeginModelContext-EndModelContext block
Similar to OverlayRenderModel, but renders in the main buffer.
Similar to OverlayRenderWindow but renders in the main buffer.
Where possible, it is recommended that you should be using Overlay*** to do ‘overly graphics’ rather than using ‘Render***’.
The code below draws a triangle and two lines.
public override void OverlayRenderWindow(View view,
Graphics graphics)
{
// the color for the graphics
Color colorRed = Color.FromByteRGB(255, 0, 0);
// color and alpha value
graphics.Color(colorRed, 0.7);
//set line width
graphics.LineWidth(5);
Point2D p1 = new Point2D(20, 20);
Point2D p2 = new Point2D(view.Width - 20, 20);
Point2D p3 = new Point2D(view.Width /2.0, view.Height - 20);
// draw triangle, fill in it
graphics.Triangle(p1,p2,p3,true);
// the color for the graphics
Color colorGreen = Color.FromByteRGB(0, 255, 0);
// color and alpha value
graphics.Color(colorGreen, 0.7);
Point2D p4 = new Point2D(20, 20);
Point2D p5 = new Point2D(view.Width / 2.0, (view.Height - 20) / 2.0);
Point2D p6 = new Point2D(view.Width - 20, 20);
//draw two lines
graphics.Line(p4, p5);
graphics.Line(p5, p6);
}
The code below draws a cylinder.
public override void OverlayRenderModel(View view, Graphics graphics)
{
// the color for the graphics
Color colorBlue = Color.FromByteRGB(0, 0, 255);
// color and alpha value
graphics.Color(colorBlue, 1);
Point3D p1 = new Point3D(0, 0,0);
Point3D p2 = new Point3D(0, 0,10);
// draw Cylinder
graphics.Cylinder(p1,p2,10);
// the color for the graphics
Color colorGrey = Color.FromByteRGB(128, 128, 128);
// color and alpha value
graphics.Color(colorGrey, 1);
Point3D p3 = new Point3D(20, 20,0);
// draw sphere
graphics.Sphere(p3, 10);
}