The IndexData class manages a raw list of vertex indices, allowing direct upload to Stage3D index buffers. You only have to work with this class if you're writing your own rendering code (e.g. if you create custom display objects).

To render objects with Stage3D, you have to organize vertices and indices in so-called vertex- and index-buffers. Vertex buffers store the coordinates of the vertices that make up an object; index buffers reference those vertices to determine which vertices spawn up triangles. Those buffers reside in graphics memory and can be accessed very efficiently by the GPU.

Before you can move data into the buffers, you have to set it up in conventional memory — that is, in a Vector or a ByteArray. Since it's quite cumbersome to manually create and manipulate those data structures, the IndexData and VertexData classes provide a simple way to do just that. The data is stored in a ByteArray (one index or vertex after the other) that can easily be uploaded to a buffer.

Basic Quad Layout

In many cases, the indices we are working with will reference just quads, i.e. triangles composing rectangles. That means that many IndexData instances will contain similar or identical data — a great opportunity for optimization!

If an IndexData instance follows a specific layout, it will be recognized automatically and many operations can be executed much faster. In Starling, that layout is called "basic quad layout". In order to recognize this specific sequence, the indices of each quad have to use the following order:

    n, n+1, n+2, n+1, n+3, n+2

The subsequent quad has to use `n+4` as starting value, the next one `n+8`, etc. Here is an example with 3 quads / 6 triangles:

    0, 1, 2, 1, 3, 2,   4, 5, 6, 5, 7, 6,   8, 9, 10, 9, 11, 10

If you are describing quad-like meshes, make sure to always use this layout.

@see VertexData

### Hierarchy

- IndexData

## Index

### Constructors

- constructor

### Properties

- indexSizeInBytes
- numIndices
- numQuads
- numTriangles
- rawData
- useQuadLayout

### Methods

- addQuad
- addTriangle
- clear
- clone
- copyTo
- createIndexBuffer
- getIndex
- get_indexSizeInBytes
- get_numIndices
- get_numQuads
- get_numTriangles
- get_rawData
- get_useQuadLayout
- offsetIndices
- setIndex
- set_numIndices
- set_numQuads
- set_numTriangles
- set_useQuadLayout
- toString
- toVector
- trim
- uploadToIndexBuffer

## Constructors

### constructor

- new IndexData(initialCapacity?: number): IndexData

- - Defined in lib/starling/rendering/IndexData.d.ts:52

  Creates an empty IndexData instance with the given capacity (in indices).

  @param initialCapacity

  The initial capacity affects just the way the internal ByteArray is allocated, not the `numIndices` value, which will always be zero when the constructor returns. The reason for this behavior is the peculiar way in which ByteArrays organize their memory:

  The first time you set the length of a ByteArray, it will adhere to that: a ByteArray with length 20 will take up 20 bytes (plus some overhead). When you change it to a smaller length, it will stick to the original value, e.g. with a length of 10 it will still take up 20 bytes. However, now comes the weird part: change it to anything above the original length, and it will allocate 4096 bytes!

  Thus, be sure to always make a generous educated guess, depending on the planned usage of your IndexData instances.

  #### Parameters

  - ##### Optional initialCapacity: number

  #### Returns IndexData

## Properties

### indexSizeInBytes

indexSizeInBytes: number

- Defined in lib/starling/rendering/IndexData.d.ts:166

The number of bytes required for each index value.

### numIndices

numIndices: number

- Defined in lib/starling/rendering/IndexData.d.ts:149

The total number of indices.

If this instance contains only standardized, basic quad indices, resizing will automatically fill up with appropriate quad indices. Otherwise, it will fill up with zeroes.

If you set the number of indices to zero, quad layout will be restored.

### numQuads

numQuads: number

- Defined in lib/starling/rendering/IndexData.d.ts:161

The number of quads that can be spawned up with the contained indices. (In other words: the number of triangles divided by two.)

### numTriangles

numTriangles: number

- Defined in lib/starling/rendering/IndexData.d.ts:155

The number of triangles that can be spawned up with the contained indices. (In other words: the number of indices divided by three.)

### rawData

rawData: ByteArray

- Defined in lib/starling/rendering/IndexData.d.ts:190

The raw index data; not a copy! Beware: the referenced ByteArray may change any time. Never store a reference to it, and never modify its contents manually.

### useQuadLayout

useQuadLayout: boolean

- Defined in lib/starling/rendering/IndexData.d.ts:184

Indicates if all indices are following the basic quad layout.

This property is automatically updated if an index is set to a value that violates basic quad layout. Once the layout was violated, the instance will always stay that way, even if you fix that violating value later. Only calling `clear` or manually enabling the property will restore quad layout.

If you enable this property on an instance, all indices will immediately be replaced with indices following standard quad layout.

Please look at the class documentation for more information about that kind of layout, and why it is important.

@default true

## Methods

### addQuad

- addQuad(a: number, b: number, c: number, d: number): void

- - Defined in lib/starling/rendering/IndexData.d.ts:115

  Appends two triangles spawning up the quad with the given indices. The indices of the vertices are arranged like this:

       a - b
       | / |
       c - d

  To make sure the indices will follow the basic quad layout, make sure each parameter increments the one before it (e.g. `0, 1, 2, 3`).

  #### Parameters

  - ##### a: number

  - ##### b: number

  - ##### c: number

  - ##### d: number

  #### Returns void

### addTriangle

- addTriangle(a: number, b: number, c: number): void

- - Defined in lib/starling/rendering/IndexData.d.ts:101

  Appends three indices representing a triangle. Reference the vertices clockwise, as this defines the front side of the triangle.

  #### Parameters

  - ##### a: number

  - ##### b: number

  - ##### c: number

  #### Returns void

### clear

- clear(): void

- - Defined in lib/starling/rendering/IndexData.d.ts:75

  Explicitly frees up the memory used by the ByteArray, thus removing all indices. Quad layout will be restored (until adding data violating that layout).

  #### Returns void

### clone

- clone(): IndexData

- - Defined in lib/starling/rendering/IndexData.d.ts:78

  Creates a duplicate of the IndexData object.

  #### Returns IndexData

### copyTo

- copyTo(target: IndexData, targetIndexID?: number, offset?: number, indexID?: number, numIndices?: number): void

- - Defined in lib/starling/rendering/IndexData.d.ts:87

  Copies the index data (or a range of it, defined by 'indexID' and 'numIndices') of this instance to another IndexData object, starting at a certain target index. If the target is not big enough, it will grow to fit all the new indices.

  By passing a non-zero `offset`, you can raise all copied indices by that value in the target object.

  #### Parameters

  - ##### target: IndexData

  - ##### Optional targetIndexID: number

  - ##### Optional offset: number

  - ##### Optional indexID: number

  - ##### Optional numIndices: number

  #### Returns void

### createIndexBuffer

- createIndexBuffer(upload?: boolean, bufferUsage?: string): IndexBuffer3D

- - Defined in lib/starling/rendering/IndexData.d.ts:129

  Creates an index buffer object with the right size to fit the complete data. Optionally, the current data is uploaded right away.

  #### Parameters

  - ##### Optional upload: boolean

  - ##### Optional bufferUsage: string

  #### Returns IndexBuffer3D

### getIndex

- getIndex(indexID: number): number

- - Defined in lib/starling/rendering/IndexData.d.ts:94

  Reads the index from the specified position.

  #### Parameters

  - ##### indexID: number

  #### Returns number

### Protected get_indexSizeInBytes

- get_indexSizeInBytes(): number

- - Defined in lib/starling/rendering/IndexData.d.ts:167

  #### Returns number

### Protected get_numIndices

- get_numIndices(): number

- - Defined in lib/starling/rendering/IndexData.d.ts:150

  #### Returns number

### Protected get_numQuads

- get_numQuads(): number

- - Defined in lib/starling/rendering/IndexData.d.ts:162

  #### Returns number

### Protected get_numTriangles

- get_numTriangles(): number

- - Defined in lib/starling/rendering/IndexData.d.ts:156

  #### Returns number

### Protected get_rawData

- get_rawData(): ByteArray

- - Defined in lib/starling/rendering/IndexData.d.ts:191

  #### Returns ByteArray

### Protected get_useQuadLayout

- get_useQuadLayout(): boolean

- - Defined in lib/starling/rendering/IndexData.d.ts:185

  #### Returns boolean

### offsetIndices

- offsetIndices(offset: number, indexID?: number, numIndices?: number): void

- - Defined in lib/starling/rendering/IndexData.d.ts:97

  Adds an offset to all indices in the specified range.

  #### Parameters

  - ##### offset: number

  - ##### Optional indexID: number

  - ##### Optional numIndices: number

  #### Returns void

### setIndex

- setIndex(indexID: number, index: number): void

- - Defined in lib/starling/rendering/IndexData.d.ts:91

  Sets an index at the specified position.

  #### Parameters

  - ##### indexID: number

  - ##### index: number

  #### Returns void

### Protected set_numIndices

- set_numIndices(value: number): number

- - Defined in lib/starling/rendering/IndexData.d.ts:151

  #### Parameters

  - ##### value: number

  #### Returns number

### Protected set_numQuads

- set_numQuads(value: number): number

- - Defined in lib/starling/rendering/IndexData.d.ts:163

  #### Parameters

  - ##### value: number

  #### Returns number

### Protected set_numTriangles

- set_numTriangles(value: number): number

- - Defined in lib/starling/rendering/IndexData.d.ts:157

  #### Parameters

  - ##### value: number

  #### Returns number

### Protected set_useQuadLayout

- set_useQuadLayout(value: boolean): boolean

- - Defined in lib/starling/rendering/IndexData.d.ts:186

  #### Parameters

  - ##### value: boolean

  #### Returns boolean

### toString

- toString(): string

- - Defined in lib/starling/rendering/IndexData.d.ts:123

  Returns a string representation of the IndexData object, including a comma-separated list of all indices.

  #### Returns string

### toVector

- toVector(out?: Vector<number>): Vector<number>

- - Defined in lib/starling/rendering/IndexData.d.ts:119

  Creates a vector containing all indices. If you pass an existing vector to the method, its contents will be overwritten.

  #### Parameters

  - ##### Optional out: Vector<number>

  #### Returns Vector<number>

### trim

- trim(): void

- - Defined in lib/starling/rendering/IndexData.d.ts:138

  Optimizes the ByteArray so that it has exactly the required capacity, without wasting any memory. If your IndexData object grows larger than the initial capacity you passed to the constructor, call this method to avoid the 4k memory problem.

  #### Returns void

### uploadToIndexBuffer

- uploadToIndexBuffer(buffer: IndexBuffer3D, indexID?: number, numIndices?: number): void

- - Defined in lib/starling/rendering/IndexData.d.ts:133

  Uploads the complete data (or a section of it) to the given index buffer.

  #### Parameters

  - ##### buffer: IndexBuffer3D

  - ##### Optional indexID: number

  - ##### Optional numIndices: number

  #### Returns void

Generated using TypeDoc