Skip to content

Chart3DMeshContext

ClassChartGuruChartGuru.3D
public sealed class Chart3DMeshContext

Context handed to 3D marks when the Chart3DMeshBuilder asks them to contribute geometry. Wraps the cached axes, scales, theme and write targets so marks never touch the Chart3DMeshContext.Chart directly. The theme's ChartTheme.Appearance3D block, also available as Chart3DMeshContext.Appearance, supplies materials, color maps and surface resolution. A custom IChart3DMark adds its geometry with Chart3DMeshContext.AddTriangles(ReadOnlySpan<Vector3>, ReadOnlySpan<Vector3>, ReadOnlySpan<Color>, ReadOnlySpan<int>) and Chart3DMeshContext.AddInstance(Mesh, Material, Matrix4x4, Color); colors it resolves are the mark's neutral colors, and the host applies hover and selection highlight on top without rebuilding.

public Chart Chart

Returns

ChartGuru.Chart

public ChartTheme Theme

Returns

ChartGuru.ChartTheme

public Scale XScale

Returns

ChartGuru.Scale

public Scale YScale

Returns

ChartGuru.Scale

public Scale ZScale

Returns

ChartGuru.Scale

public Bounds PlotBounds

Returns

UnityEngine.Bounds

public Vector3 Project(float x, float y, float z)

Map a raw (x,y,z) value triple to plot-space 3D position.

Parameters

NameType
xSystem.Single
ySystem.Single
zSystem.Single

Returns

UnityEngine.Vector3

public Vector3 Project(Vector3 v)

Maps the data values in v to a plot-space position, as Chart3DMeshContext.Project(float, float, float) does.

Parameters

NameType
vUnityEngine.Vector3

Returns

UnityEngine.Vector3

public Vector3 Project(DataPoint3D p)

Maps the X, Y and Z of p to a plot-space position through the chart’s scales; its range ends are ignored.

Parameters

NameType
pChartGuru.DataPoint3D

Returns

UnityEngine.Vector3

public Vector3 Project(IChart3DMark mark)

Maps the data point of mark to a plot-space position without the mark’s offset, which marks add themselves; a null mark maps the data origin.

Parameters

NameType
markChartGuru.IChart3DMark

Returns

UnityEngine.Vector3

public DataPoint3D ResolveDataPoint(IChart3DMark mark)

Returns the data point a mark builds from, its IChart3DDataMark.DataPoint3D, or a point at the data origin for a null mark.

Parameters

NameType
markChartGuru.IChart3DMark

Returns

ChartGuru.DataPoint3D

public Color ResolveMarkColor(IChartMark mark, int fallbackIndex = -1, int dataPointIndex = -1)

The neutral color of mark: its explicit color, gradient midpoint, style scale or series color with its opacity, without hover and selection effects, which the host applies on top. The data point index is accepted for compatibility with 2D color resolution and does not change the neutral color.

Parameters

NameType
markChartGuru.IChartMark
fallbackIndexSystem.Int32
dataPointIndexSystem.Int32

Returns

UnityEngine.Color

AddTriangles(ReadOnlySpan, ReadOnlySpan, ReadOnlySpan, ReadOnlySpan)

Section titled “AddTriangles(ReadOnlySpan, ReadOnlySpan, ReadOnlySpan, ReadOnlySpan)”
public void AddTriangles(ReadOnlySpan<Vector3> positions, ReadOnlySpan<Vector3> normals, ReadOnlySpan<Color> colors, ReadOnlySpan<int> triangles)

Adds triangles to the mark being built, in plot space: positions come from Chart3DMeshContext.Project(Vector3), normals and colors have one entry per position, and every three triangles index into the positions. Colors are neutral, such as Chart3DMeshContext.ResolveMarkColor(IChartMark, int, int) returns; blended colors draw in the transparent pass. Picking and highlight map the triangles to the mark. Arrays convert to the spans implicitly.

Parameters

NameType
positionsSystem.ReadOnlySpan{UnityEngine.Vector3}
normalsSystem.ReadOnlySpan{UnityEngine.Vector3}
colorsSystem.ReadOnlySpan{UnityEngine.Color}
trianglesSystem.ReadOnlySpan{System.Int32}

Examples

A custom mark that draws a small triangle at its point, in its own color:

public override void BuildMesh(Chart3DMeshContext ctx)
{
    Vector3 p = ctx.Project(DataPoint3D);
    Color color = ctx.ResolveMarkColor(this);
    ctx.AddTriangles(
        new[] { p, p + Vector3.right * 0.1f, p + Vector3.up * 0.1f },
        new[] { Vector3.back, Vector3.back, Vector3.back },
        new[] { color, color, color },
        new[] { 0, 2, 1 });
}
### AddInstance(Mesh, Material, Matrix4x4, Color)
public void AddInstance(Mesh mesh, Material material, Matrix4x4 transform, Color color)

Adds an instance of mesh drawn with material to the mark being built. transform places the mesh in plot space and color is the neutral instance color, which the material’s instanced color property receives. Instances of the same mesh and material draw in one batch.

Parameters

NameType
meshUnityEngine.Mesh
materialUnityEngine.Material
transformUnityEngine.Matrix4x4
colorUnityEngine.Color

public Chart3DMeshContext()

public ChartTheme3D Appearance { get; }

The 3D look of Chart3DMeshContext.Theme, or of the default theme when none is set.

Returns

ChartGuru.ChartTheme3D