Multicolored Mesh with transparency

Requires Eyeshot >= 10.0.857 

Here's a example on how to override the Mesh class in order to draw a semi-transparent mesh with Multicolor nature type.

 

public class MyMesh : Mesh
{
public MyMesh(Mesh mesh) : base(mesh) { }

protected override void DrawEntity(RenderContextBase context, object myParams)
{
byte alpha = Color.A;

switch (MeshNature)
{
case natureType.MulticolorPlain:
context.DrawMulticolorPlainTriangles(Triangles, Vertices, Normals, alpha);
break;
case natureType.MulticolorSmooth:
context.DrawMulticolorPlainTriangles(Triangles, Vertices, Normals, alpha);
break;
default:
base.DrawEntity(context, myParams);
break;
}
}
}

Then use it like below.

// Create a multicolored mesh
MyMesh mesh = new MyMesh(new Mesh(Mesh.natureType.MulticolorPlain));
mesh.Vertices = new PointRGB[]
{
new PointRGB(0, 0, 0, 255, 0, 87),
new PointRGB(10, 0, 0, 134, 148, 43),
new PointRGB(10, 10, 0, 255, 233, 167),
new PointRGB(0, 10, 0, 133, 222, 255),
new PointRGB(5, 5, 10, 100, 223, 12)
};

mesh.Triangles = new IndexTriangle[]
{
new IndexTriangle(0, 1, 2),
new IndexTriangle(0, 2, 3),
new IndexTriangle(0, 1, 4),
new IndexTriangle(1, 2, 4),
new IndexTriangle(2, 3, 4),
new IndexTriangle(3, 0, 4)
};

// Set the ColorMethod
mesh.ColorMethod = colorMethodType.byEntity;
// Set the color with alpha < 255
mesh.Color = Color.FromArgb(150, Color.Black);

viewportLayout1.Entities.Add(mesh);

// Add another mesh for transparency comparison
// var box1 = Mesh.CreateBox(5, 5, 5);
// box1.Translate(2, 15, 0);
// viewportLayout1.Entities.Add(box1, 0, Color.Red);

viewportLayout1.SetView(viewType.Front, true, false);
viewportLayout1.Invalidate();

 

Have more questions? Submit a request

0 Comments

Please sign in to leave a comment.