UNPKG

5.08 kBTypeScriptView Raw
1import { Attribute } from './Attribute';
2import { Buffer } from './Buffer';
3import { Runner } from '@pixi/runner';
4import type { TYPES } from '@pixi/constants';
5import type { IArrayBuffer } from './Buffer';
6/**
7 * The Geometry represents a model. It consists of two components:
8 * - GeometryStyle - The structure of the model such as the attributes layout
9 * - GeometryData - the data of the model - this consists of buffers.
10 * This can include anything from positions, uvs, normals, colors etc.
11 *
12 * Geometry can be defined without passing in a style or data if required (thats how I prefer!)
13 * @example
14 * import { Geometry } from 'pixi.js';
15 *
16 * const geometry = new Geometry();
17 *
18 * geometry.addAttribute('positions', [0, 0, 100, 0, 100, 100, 0, 100], 2);
19 * geometry.addAttribute('uvs', [0, 0, 1, 0, 1, 1, 0, 1], 2);
20 * geometry.addIndex([0, 1, 2, 1, 3, 2]);
21 * @memberof PIXI
22 */
23export declare class Geometry {
24 buffers: Array<Buffer>;
25 indexBuffer: Buffer;
26 attributes: {
27 [key: string]: Attribute;
28 };
29 id: number;
30 /** Whether the geometry is instanced. */
31 instanced: boolean;
32 /**
33 * Number of instances in this geometry, pass it to `GeometrySystem.draw()`.
34 * @default 1
35 */
36 instanceCount: number;
37 /**
38 * A map of renderer IDs to webgl VAOs
39 * @type {object}
40 */
41 glVertexArrayObjects: {
42 [key: number]: {
43 [key: string]: WebGLVertexArrayObject;
44 };
45 };
46 disposeRunner: Runner;
47 /** Count of existing (not destroyed) meshes that reference this geometry. */
48 refCount: number;
49 /**
50 * @param buffers - An array of buffers. optional.
51 * @param attributes - Of the geometry, optional structure of the attributes layout
52 */
53 constructor(buffers?: Array<Buffer>, attributes?: {
54 [key: string]: Attribute;
55 });
56 /**
57 *
58 * Adds an attribute to the geometry
59 * Note: `stride` and `start` should be `undefined` if you dont know them, not 0!
60 * @param id - the name of the attribute (matching up to a shader)
61 * @param {PIXI.Buffer|number[]} buffer - the buffer that holds the data of the attribute . You can also provide an Array and a buffer will be created from it.
62 * @param size - the size of the attribute. If you have 2 floats per vertex (eg position x and y) this would be 2
63 * @param normalized - should the data be normalized.
64 * @param [type=PIXI.TYPES.FLOAT] - what type of number is the attribute. Check {PIXI.TYPES} to see the ones available
65 * @param [stride=0] - How far apart, in bytes, the start of each value is. (used for interleaving data)
66 * @param [start=0] - How far into the array to start reading values (used for interleaving data)
67 * @param instance - Instancing flag
68 * @returns - Returns self, useful for chaining.
69 */
70 addAttribute(id: string, buffer: Buffer | Float32Array | Uint32Array | Array<number>, size?: number, normalized?: boolean, type?: TYPES, stride?: number, start?: number, instance?: boolean): this;
71 /**
72 * Returns the requested attribute.
73 * @param id - The name of the attribute required
74 * @returns - The attribute requested.
75 */
76 getAttribute(id: string): Attribute;
77 /**
78 * Returns the requested buffer.
79 * @param id - The name of the buffer required.
80 * @returns - The buffer requested.
81 */
82 getBuffer(id: string): Buffer;
83 /**
84 *
85 * Adds an index buffer to the geometry
86 * The index buffer contains integers, three for each triangle in the geometry, which reference the various attribute buffers (position, colour, UV coordinates, other UV coordinates, normal, …). There is only ONE index buffer.
87 * @param {PIXI.Buffer|number[]} [buffer] - The buffer that holds the data of the index buffer. You can also provide an Array and a buffer will be created from it.
88 * @returns - Returns self, useful for chaining.
89 */
90 addIndex(buffer?: Buffer | IArrayBuffer | number[]): Geometry;
91 /**
92 * Returns the index buffer
93 * @returns - The index buffer.
94 */
95 getIndex(): Buffer;
96 /**
97 * This function modifies the structure so that all current attributes become interleaved into a single buffer
98 * This can be useful if your model remains static as it offers a little performance boost
99 * @returns - Returns self, useful for chaining.
100 */
101 interleave(): Geometry;
102 /** Get the size of the geometries, in vertices. */
103 getSize(): number;
104 /** Disposes WebGL resources that are connected to this geometry. */
105 dispose(): void;
106 /** Destroys the geometry. */
107 destroy(): void;
108 /**
109 * Returns a clone of the geometry.
110 * @returns - A new clone of this geometry.
111 */
112 clone(): Geometry;
113 /**
114 * Merges an array of geometries into a new single one.
115 *
116 * Geometry attribute styles must match for this operation to work.
117 * @param geometries - array of geometries to merge
118 * @returns - Shiny new geometry!
119 */
120 static merge(geometries: Array<Geometry>): Geometry;
121}