SciChart Android 3D Charts API > 3D Chart Types > The SurfaceMesh 3D Chart Type > Applying Palettes to Surface Meshes
Applying Palettes to Surface Meshes

The SurfaceMeshRenderableSeries3D accepts color palettes via the MeshColorPalette property.  Several options are available for paletting the mesh, including:

We will talk about each of these options below.

SolidColorBrushPalette

The SolidColorBrushPalette is simple enough.

SolidColorBrushPalette
Copy Code
surfaceMeshRenderableSeries3D.setMeshColorPalette(new SolidColorBrushPalette(ColorUtil.DarkGreen));

GradientColorPalette

The GradientColorPalette can be used to map a Gradient Brush set of colors to heights in the Surface Mesh. The mapping is similar to that performed by the Heatmap Series in 2D Charts.

Given the following code:

GradientBrushPalette
Copy Code
final int[] colors = new int[]{0xFF1D2C6B, Blue, Cyan, GreenYellow, Yellow, Red, DarkRed};
final float[] stops = {0, .1f, .3f, .5f, .7f, .9f, 1};

surfaceMeshRenderableSeries3D.setMeshColorPalette(new GradientColorPalette(colors, stops));

Colors are mapped onto Y-values as follows:

  • Y values corresponding to Minimum are drawn with the gradient stop color at offset 0.
  • Y values corresponding to Maximum are drawn with the gradient stop color at offset 1.
  • All other values are linearly interpolated (including Y-values outside of Minimum and Maximum).

GradientColorPalette.IsStepped

When the property IsStepped is set to true, the color map is not interpolated, and graidnet stops are interpretted as hard steppings.

Stepped GradientColorPalette
Copy Code
final int[] colors = new int[]{0xFF1D2C6B, Blue, Cyan, GreenYellow, Yellow, Red, DarkRed};
final float[] stops = {0, .1f, .3f, .5f, .7f, .9f, 1};

surfaceMeshRenderableSeries3D.setMeshColorPalette(new GradientColorPalette(colors, stops, true));

The Surface Mesh now looks like this:

BrushColorPalette

A texture can be applied to the SurfaceMesh and mapped over it in the X-Z plane by using a combination of BrushColorPalette, MeshPaletteMode.Textured and MeshColorPaletteSize.

BrushColorPalette
Copy Code
final Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.smiley);
final TextureBrushStyle brushStyle = new TextureBrushStyle(bitmap);
surfaceMeshRenderableSeries.setMeshPaletteMode(MeshPaletteMode.Textured);
surfaceMeshRenderableSeries.setMeshColorPalette(new BrushColorPalette(brushStyle));
surfaceMeshRenderableSeries.setMeshColorPaletteSize(new Size(bitmap.getWidth(), bitmap.getHeight()));

Creating a Custom Palette

You can create a custom Color Palette by inheriting MeshColorPalette and overriding getTexture. For example, see below.

Custom Palette
Copy Code
class CustomPalette extends MeshColorPalette {
    @Override
    public Texture2D getTexture(int width, int height) {
        final Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888);
        try {
            // TODO fill Bitmap
            return Texture2D.fromBitmap(bitmap);
        } finally {
            bitmap.recycle();
        }
    }
}

The palette is applied to a SurfaceMeshRenderableSeries3D as before.

Effect of SurfaceMeshRenderableSeries3D.MeshPaletteMode

The MeshPaletteMode property changes how the palette is applied to the Mesh.