UNPKG

gl2d

Version:

2D graphics package for WebGL

174 lines (173 loc) 7.26 kB
import { MeshSpecification } from '../specification/mesh'; import { IndexTupleBuffer } from '../struct/indextuple'; import { PointLike } from '../struct/point'; import { Rect, RectLike } from '../struct/rect'; import { Vec2Buffer } from '../struct/vec2'; import { VertexBuffer } from '../struct/vertex'; /** * Stores static vertex and index data that multiple graphics can share. */ export declare abstract class Mesh { /** * Optional string identifier for this mesh. */ id?: string; /** * The vertex data. */ vertices: VertexBuffer; /** * The indices for each triangle in this mesh (if any). */ triangleIndices?: IndexTupleBuffer; /** * The miter vectors used to draw an outline of this mesh (if any). */ miters?: Vec2Buffer; /** * The smallest rect containing each mesh vertex. */ bounds: Rect; /** * The byte offset of this mesh's vertex data in a vertex buffer (if any). */ vertexBufferOffset?: number; /** * The byte offset of this mesh's index data in an element buffer (if any). */ elementBufferOffset?: number; /** * The byte offset of this mesh's stroke vertex data in a vertex buffer (if any). */ strokeVertexBufferOffset?: number; /** * The byte offset of this mesh's stroke index data in an element buffer (if any). */ strokeElementBufferOffset?: number; /** * The number of indices used to render the stroke (if any). */ strokeElementCount?: number; /** * The byte offset of this mesh's miter data in an element buffer (if any). */ miterBufferOffset?: number; /** * Creates a mesh with the specified data. * @param vertices the mesh vertices. * @param triangleIndices the indices for each triangle in the mesh. * @param polygonIndices the indices for each polygon in the mesh. * @param id an optional id for the mesh. * @param bounds the boundaries of the mesh. */ constructor(vertices: VertexBuffer, triangleIndices?: IndexTupleBuffer, id?: string, bounds?: Rect); /** * Creates a mesh with the specified source data. * @param source obejct containing the data for the mesh. */ static fromSpecification(spec: MeshSpecification): PolygonMesh; /** * Checks if this mesh contains the specified point * @param pt the point to check. */ contains(pt: PointLike): boolean; /** * Checks if this mesh contains the point (x,y). * @param x the x coordinate of the point. * @param y the y coordinate of the point. */ abstract contains$(x: number, y: number): boolean; } export declare class PolygonMesh extends Mesh { /** * Creates a mesh with the specified data. * @param vertices the mesh vertices. * @param polygonIndices the indices for each polygon in the mesh. * @param triangleIndices the indices for each triangle in the mesh. * @param id an optional id for the mesh. * @param bounds the boundaries of the mesh. */ constructor(vertices: VertexBuffer, triangleIndices?: IndexTupleBuffer, id?: string, bounds?: Rect); static measureMiters(vertices: VertexBuffer, offset?: number, count?: number): Vec2Buffer; /** * Creates the mesh for a regular polygon with n sides. * @param n how many sides the polygon should have. * @param isFlatTopped whether the polygon is flat-topped (true) or pointy-topped (false). Defaults to false. * @param id an optional id for the mesh. */ static regular(n: number, isFlatTopped?: boolean, id?: string): PolygonMesh; /** * Generates the vertices for a regular polygon centered at (0,0). * @param n how many sides the polygon should have. * @param isFlatTopped whether the polygon is flat-topped (true) or pointy-topped (false). Defaults to false. */ static regularVertices(n: number, isFlatTopped?: boolean): VertexBuffer; /** * Generates the indices for a regular mesh with n sides. * The mesh will have 3*(n-2) indices. * @param n how many sides the mesh should have. */ static regularIndices(n: number): IndexTupleBuffer; /** * Creates the mesh for a rectangle * @param id an optional id for the mesh. */ static rectangle(rect: Rect, id?: string): PolygonMesh; /** * Extracts the vertices from the specified rect into a new vertex buffer. * @param rect the rect from which to extract the vertices. */ static rectangleVertices(rect: RectLike): VertexBuffer; /** * Creates the mesh for a star with n points and the specified inner and outer radii. * @param n how many points the star should have. * @param ratio ratio of the inner radius to the outer radius. * @param id an optional id for the mesh. */ static star(n: number, ratio: number, id?: string): PolygonMesh; /** * Generates the vertices for a star centered at (0,0). * @param points how many points the star should have. * @param ratio ratio of the inner radius to the outer radius. */ static starVertices(points: number, ratio: number): VertexBuffer; /** * Generates the indices for a star with n points. * The star will have 3*(n-2) inner indices and 3n outer indices. * @param n how many points the star should have. */ static starIndices(n: number): IndexTupleBuffer; contains$(x: number, y: number): boolean; } export declare class InstancedPolygonMesh extends Mesh { verticesPerInstance: number; /** * Creates a mesh with the specified data. * @param vertices the mesh vertices. * @param triangleIndices the indices for each triangle in the mesh. * @param polygonIndices the indices for each polygon in the mesh. * @param id an optional id for the mesh. * @param bounds the boundaries of the mesh. */ constructor(vertices: VertexBuffer, verticesPerInstance: number, triangleIndices?: IndexTupleBuffer, id?: string, bounds?: Rect); static spray(instance: PolygonMesh, instancesInInnerRing: number, rings: number, id?: string): InstancedPolygonMesh; private static countInstancesInSpray(shapesInInnerRing, rings); contains$(x: number, y: number): boolean; } export declare class MultiPolygonMesh extends Mesh { /** * The indices for each polygon in this mesh. */ polygonIndices?: number[][]; /** * Creates a mesh with the specified data. * @param vertices the mesh vertices. * @param polygonIndices the indices for each polygon in the mesh. * @param triangleIndices the indices for each triangle in the mesh. * @param id an optional id for the mesh. * @param bounds the boundaries of the mesh. */ constructor(vertices: VertexBuffer, polygonIndices: number[][], triangleIndices?: IndexTupleBuffer, id?: string, bounds?: Rect); static measureMiters(vertices: VertexBuffer, polygonIndices: number[][]): Vec2Buffer; contains$(x: number, y: number): boolean; }