In case you would like to display your mesh in wireframe with its colormap as well like in the following picture:
you should create a new custom Mesh-derived class, that overrides method DrawWireframe().
This sample has been created starting from FunctionPlot sample, you will find the new Mesh-derived class called MyMesh, at the bottom of this code.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
// viewportLayout1.Unlock(""); // For more details see 'Product Activation' topic in the documentation.
}
protected override void OnLoad(EventArgs e)
{
design1.ActiveViewport.DisplayMode = displayType.Wireframe;
design1.ActiveViewport.Grid.AutoSize = true;
design1.ActiveViewport.Grid.Step = 1;
const int rows = 50;
const int cols = 50;
const double scale = 4;
List<Point3D> vertices = new List<Point3D>(rows * cols);
Mesh surface = new Mesh();
surface.NormalAveragingMode = Mesh.normalAveragingType.Averaged;
for (int j = 0; j < rows; j++)
for (int i = 0; i < cols; i++)
{
double x = i / 5.0;
double y = j / 5.0;
double f = 0;
double den = Math.Sqrt(x * x + y * y);
if (den != 0)
f = scale * Math.Sin(Math.Sqrt(x * x + y * y)) / den;
// generates a random color
int red = (int)(255 - y * 20);
int green = (int)(255 - x * 20);
int blue = (int)(-f * 50);
// clamps color values lat 0-255
devDept.Geometry.Utility.LimitRange(0, ref red, 255);
devDept.Geometry.Utility.LimitRange(0, ref green, 255);
devDept.Geometry.Utility.LimitRange(0, ref blue, 255);
vertices.Add(new PointRGB(x, y, f, (byte)red, (byte)green, (byte)blue));
}
List<SmoothTriangle> triangles = new List<SmoothTriangle>((rows - 1) * (cols - 1) * 2);
for (int j = 0; j < (rows - 1); j++)
for (int i = 0; i < (cols - 1); i++)
{
triangles.Add(new SmoothTriangle(i + j * cols,
i + j * cols + 1,
i + (j + 1) * cols + 1));
triangles.Add(new SmoothTriangle(i + j * cols,
i + (j + 1) * cols + 1,
i + (j + 1) * cols));
}
surface.Vertices = vertices.ToArray();
surface.Triangles = triangles.ToArray();
MyMesh mesh = new MyMesh(surface);
// you need to turn off your mesh edges
mesh.EdgeStyleType = Mesh.edgeStyleType.None;
design1.Entities.Add(mesh);
// fits the model in the viewportLayout1
design1.ZoomFit();
}
class MyMesh : Mesh
{
public MyMesh(Mesh another)
: base(another)
{
}
public override void DrawWireframe(DrawParams drawParams)
{
drawParams.RenderContext.PushShader();
drawParams.RenderContext.PushRasterizerState();
Color prev = drawParams.RenderContext.CurrentWireColor;
drawParams.RenderContext.SetShader(shaderType.MultiColorNoLightsWithNormals);
drawParams.RenderContext.SetState(rasterizerStateType.CCW_PolygonLine_NoCullFace);
Draw(drawParams);
drawParams.RenderContext.PushShader();
drawParams.RenderContext.PushRasterizerState();
drawParams.RenderContext.SetColorWireframe(prev);
}
public override void DrawIsocurves(DrawParams data)
{
//base.DrawIsocurves();
}
}
Comments
Please sign in to leave a comment.