Colormap Mesh using Texture1D 🎨

Immagine01.png

In case you need to create a colormap Mesh that shows a smooth (or sharp) color transition for two adjacent vertices, you can use a Texture1D object.

Here it is the code to create a custom mesh using Texture1D:

using System.Drawing; 
using devDept.Eyeshot; 
using devDept.Eyeshot.Entities; 
using devDept.Geometry; 
using devDept.Graphics; 

class MyPoint : Point3D 
{ 
    public MyPoint(double x, double y, double z, double t) : base(x, y, z)
    { 
       Temperature = t; 
    } 
    
    public double Temperature; 
}

public class MyMeshTex1D : Mesh
{
private TextureBase tex;
public MyMeshTex1D() : base(natureType.RichPlain) { } private void CreateTexture1D(RenderContextBase renderContext) { Color[] colors = new Color[] { Color.Salmon, Color.Red, Color.Yellow, Color.LimeGreen, Color.Blue }; tex = renderContext.CreateTexture1D(colors, textureFilteringFunctionType.Nearest, textureFilteringFunctionType.Nearest, true, false); // Replace with this for smooth mode // tex = renderContext.CreateTexture1D(colors, textureFilteringFunctionType.Linear, textureFilteringFunctionType.Linear, true, false); } public override void Dispose() { tex.Dispose(); base.Dispose(); } public override void Compile(CompileParams data) { CreateTexture1D(data.RenderContext); base.Compile(data); } private bool prevTex1D; protected override void SetShader(DrawParams data) { // Tell the shader to set a Texture1D. if (data.ShaderParams != null && !data.Selected) { prevTex1D = data.ShaderParams.Texture1D; data.ShaderParams.Texture1D = true; } base.SetShader(data); } protected override void Render(RenderParams data) { if (data.ShaderParams != null && !data.Selected) data.RenderContext.SetTexture(tex); base.Render(data); if (data.ShaderParams != null && !data.Selected) { data.RenderContext.CloseTexture(); data.ShaderParams.Texture1D = prevTex1D; } } }

Declaration of the object:

Mesh m = new MyMeshTex1D();

Point3D[] pts = new Point3D[] { new MyPoint(0, 0, 0, 0), new MyPoint(20, 0, 0, 0), new MyPoint(20, 15, 0, 1), new MyPoint(0, 15, 0, 0) };

IndexTriangle[] triangles = new IndexTriangle[] { new RichTriangle(0, 1, 2, 0, 1, 2), new RichTriangle(0, 2, 3, 0, 2, 3) };

m.Vertices = pts;
m.Triangles = triangles;

// the second coordinate is unused because we are using Texture1D
m.TextureCoords = new PointF[m.Vertices.Length];

for (int i = 0; i < m.Vertices.Length; i++)
{
   // The second coordinate is not used
   // Multiply by 0.75 to use just the first 3 colors
   m.TextureCoords[i] = new PointF((float)((MyPoint)m.Vertices[i]).Temperature, 0);
}

m.Color = Color.White;
m.ColorMethod = colorMethodType.byEntity;
viewportLayout1.Entities.Add(m);

// sets rendered only display mode
viewportLayout1.DisplayMode = displayType.Rendered;

// sets trimetric view
viewportLayout1.SetView(viewType.Trimetric);
Smooth color transition Sharp color transition
Capture.PNG Capture.PNG
Was this article helpful?
0 out of 0 found this helpful
Have more questions? Submit a request

Comments

0 comments

Please sign in to leave a comment.