JavaScript Immediate Mesh 3D Chart

Demonstrates how to draw custom lit 3D geometry in JavaScript with ImmediateLitMeshContext, by emitting an aurora-like banked helix as a single triangle strip from a custom scene entity.

src/drawExample.ts
import {
    EMainLightMode,
    MouseWheelZoomModifier3D,
    NumberRange,
    NumericAxis3D,
    OrbitModifier3D,
    ResetCamera3DModifier,
    SciChart3DSurface,
    Vector3,
} from "scichart";
import { appTheme } from "./appTheme";
import { AuroraRibbonSceneEntity } from "./AuroraRibbonSceneEntity";

export const drawExample = async (rootElement: string | HTMLDivElement) => {
    const { sciChart3DSurface, wasmContext } = await SciChart3DSurface.create(rootElement, {
        theme: appTheme.SciChartJsTheme,
        worldDimensions: new Vector3(400, 200, 400),
        lighting: {
            ambientLight: 0.18,
            lightMode: EMainLightMode.GlobalSpace,
            lightDirection: new Vector3(-0.25, 0.5, -0.25),
        },
        cameraOptions: {
            position: new Vector3(300, 300, 300),
            target: new Vector3(0, 50, 0),
        },
    });

    sciChart3DSurface.xAxis = new NumericAxis3D(wasmContext, { visibleRange: new NumberRange(-100, 100) });
    sciChart3DSurface.yAxis = new NumericAxis3D(wasmContext, { visibleRange: new NumberRange(-100, 100) });
    sciChart3DSurface.zAxis = new NumericAxis3D(wasmContext, { visibleRange: new NumberRange(-100, 100) });

    // An immediate mesh is not a renderable series - it is a custom scene entity added to the root entity
    sciChart3DSurface.rootEntity.children.add(new AuroraRibbonSceneEntity(wasmContext));

    sciChart3DSurface.chartModifiers.add(
        new MouseWheelZoomModifier3D(),
        new OrbitModifier3D(),
        new ResetCamera3DModifier()
    );

    return { sciChartSurface: sciChart3DSurface, wasmContext };
};

Immediate Mesh 3D Chart

ImmediateLitMeshContext draws custom lit geometry directly into a SciChart3DSurface scene. It is useful when no built-in 3D series can describe the shape you need: a swept path, a non-uniform tube, or application-specific geometry.

Unlike a renderable series, an immediate mesh is a custom BaseSceneEntity3D added to rootEntity.children. This example builds an aurora-like, banked helix as one triangle strip. Every emitted vertex carries a position, normal, texture coordinate and colour, so the scene light reveals the ribbon's shape while the colour shifts along its length.

How it works

  • The render mode controls how SciChart joins emitted vertices. This example uses TSR_RENDERMODE_TRIANGLESTRIP, so each pair of left and right vertices adds one ribbon segment. Other native render modes cover triangles, lines and points.
  • setVertex3() always takes world coordinates. The ribbon is kept in data space and each vertex is mapped through the current render-pass axis calculators, so axis ranges and worldDimensions affect the mesh. Normals are recalculated after that conversion, because axis scaling can alter their direction.
  • For a fixed scene object such as a gizmo or a world-space overlay, pass world coordinates straight to setVertex3() and skip the conversion.
  • normal3(), texCoord2(), setVertexColor() and setSelectionId() set the state applied to subsequently emitted vertices. setVertexColor() accepts a CSS colour string or an ARGB number.
  • Create and dispose the context inside Render(). dispose() submits the completed mesh and releases the native resources.

Orbit with the left mouse button, zoom with the mouse wheel and double-click to reset the camera.