/** * A run of consecutive lines, drawn as one instanced draw call per pass. */ export type LineRun = { /** * - The entity of the run. */ entity: Entity; /** * - The occluded and the depth tested pass. */ meshInstances: MeshInstance[]; /** * - The instance data. */ vertexBuffer: VertexBuffer; /** * - The storage of the instance data. */ data: Float32Array; /** * - The number of lines the instance data holds. */ capacity: number; /** * - The number of lines added this frame. */ count: number; }; /** * Lines drawn as instanced cylinders, added each frame between {@link begin} and {@link end}. * Consecutive lines form a run with its own entity, drawn as an occluded pass then a depth tested * pass, so in a manually sorted layer it keeps its place among other shapes. {@link split} starts * a new run. * * @ignore */ export class MeshLineBatch { /** * @param {AppBase} app - The application. * @param {Layer} layer - The layer of the lines. * @param {Entity} parent - The parent of the lines, which the line points are relative to. * @param {number} drawOrder - The draw order of the first run in a manually sorted layer. */ constructor(app: AppBase, layer: Layer, parent: Entity, drawOrder: number); /** * The runs, taken in order each frame. * * @type {Pool} * @private */ private _runs; /** * The run lines are added to, or null to start a new run. * * @type {LineRun|null} * @private */ private _run; /** * The draw order of the next run in a manually sorted layer. * * @type {number} */ drawOrder: number; /** * The layer of the lines. * * @type {Layer} * @private */ private _layer; /** * Whether the lines were destroyed. * * @private */ private _destroyed; _parent: Entity; _material: ShaderMaterial; _occludedMaterial: ShaderMaterial; _mesh: Mesh; /** * Sets the layer of the lines. * * @type {Layer} */ set layer(value: Layer); /** * Gets the layer of the lines. * * @type {Layer} */ get layer(): Layer; /** * @param {boolean} occluded - Whether the material draws the occluded pass. * @returns {ShaderMaterial} The material. * @private */ private _createMaterial; /** * Doubles the instance data of a run, keeping the lines added so far. * * @param {LineRun} run - The run. * @private */ private _grow; /** * Starts adding the lines of a frame. */ begin(): void; /** * Ends the current run, so the next line draws after the shapes placed in between. */ split(): void; /** * Adds a line from one point to another. * * @param {Vec3} from - The start point, relative to the parent. * @param {Vec3} to - The end point, relative to the parent. * @param {number} thickness - The thickness of the line. * @param {Color} color - The color of the line. * @param {Color} occludedColor - The color where the scene hides the line. */ add(from: Vec3, to: Vec3, thickness: number, color: Color, occludedColor: Color): void; /** * Uploads the runs of the frame and hides unused runs. */ end(): void; /** * Destroys the lines. Safe to call again. */ destroy(): void; } import { Entity } from '../../../framework/entity.js'; import { MeshInstance } from '../../../scene/mesh-instance.js'; import { VertexBuffer } from '../../../platform/graphics/vertex-buffer.js'; import { ShaderMaterial } from '../../../scene/materials/shader-material.js'; import { Mesh } from '../../../scene/mesh.js'; import type { Layer } from '../../../scene/layer.js'; import { Vec3 } from '../../../core/math/vec3.js'; import type { Color } from '../../../core/math/color.js'; import type { AppBase } from '../../../framework/app-base.js';