flash.display3D

# VertexBuffer3D - AS3

Package | flash.display3D
Class | public class VertexBuffer3D
Inheritance | VertexBuffer3D Object

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 11, AIR 3

The VertexBuffer3D class represents a set of vertex data uploaded to a rendering context.

Use a VertexBuffer3D object to define the data associated with each point in a set of vertexes. You can upload the vertex data either from a Vector array or a ByteArray. (Once uploaded, the data in the original array is no longer referenced; changing or discarding the source array does not change the vertex data.)

The data associated with each vertex is in an application-defined format and is used as the input for the vertex shader program. Identify which values belong to which vertex program input using the Context3D `setVertexBufferAt()` function. A vertex program can use up to eight inputs (also known as vertex attribute registers). Each input can require between one and four 32-bit values. For example, the [x,y,z] position coordinates of a vertex can be passed to a vertex program as a vector containing three 32 bit values. The Context3DVertexBufferFormat class defines constants for the supported formats for shader inputs. You can supply up to sixty-four 32-bit values (256 bytes) of data for each point (but a single vertex shader cannot use all of the data in this case).

The `setVertexBufferAt()` function also identifies which vertex buffer to use for rendering any subsequent `drawTriangles()` calls. To render data from a different vertex buffer, call `setVertexBufferAt()` again with the appropriate arguments. (You can store data for the same point in multiple vertex buffers, say position data in one buffer and texture coordinates in another, but typically rendering is more efficient if all the data for a point comes from a single buffer.)

The Index3DBuffer object passed to the Context3D `drawTriangles()` method organizes the vertex data into triangles. Each value in the index buffer is the index to a vertex in the vertex buffer. A set of three indexes, in sequence, defines a triangle.

You cannot create a VertexBuffer3D object directly. Use the Context3D `createVertexBuffer()` method instead.

To free the render context resources associated with a vertex buffer, call the object's `dispose()` method.

View the examples

Related API Elements

Context3D.createVertexBuffer()
Context3D.setVertexBufferAt()
Context3DVertexBufferFormat

Public Properties
Hide Inherited Public Properties
Show Inherited Public Properties

| Property | Defined By
--- | --- | ---
|  | constructor : Object A reference to the class object or constructor function for a given object instance. | Object

Public Methods
Hide Inherited Public Methods
Show Inherited Public Methods

| Method | Defined By
--- | --- | ---
|  | dispose():void Frees all resources associated with this object. | VertexBuffer3D
|  | hasOwnProperty(name:String):Boolean Indicates whether an object has a specified property defined. | Object
|  | isPrototypeOf(theClass:Object):Boolean Indicates whether an instance of the Object class is in the prototype chain of the object specified as the parameter. | Object
|  | propertyIsEnumerable(name:String):Boolean Indicates whether the specified property exists and is enumerable. | Object
|  | setPropertyIsEnumerable(name:String, isEnum:Boolean = true):void Sets the availability of a dynamic property for loop operations. | Object
|  | toLocaleString():String Returns the string representation of this object, formatted according to locale-specific conventions. | Object
|  | toString():String Returns the string representation of the specified object. | Object
|  | uploadFromByteArray(data:ByteArray, byteArrayOffset:int, startVertex:int, numVertices:int):void Uploads the data for a set of points to the rendering context from a byte array. | VertexBuffer3D
|  | uploadFromVector(data:Vector.<Number>, startVertex:int, numVertices:int):void Uploads the data for a set of points to the rendering context from a vector array. | VertexBuffer3D
|  | valueOf():Object Returns the primitive value of the specified object. | Object

Method Detail

### dispose

()
method

`public function dispose():void`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 11, AIR 3

Frees all resources associated with this object. After disposing a vertex buffer, calling upload() and rendering using this object will fail.

### uploadFromByteArray

()
method

`public function uploadFromByteArray(data:ByteArray, byteArrayOffset:int, startVertex:int, numVertices:int):void`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 11, AIR 3

Uploads the data for a set of points to the rendering context from a byte array.

Parameters

| `data:ByteArray` — a byte array containing the vertex data. Each data value is four bytes long. The number of values in a vertex is specified at buffer creation using the `data32PerVertex` parameter to the Context3D `createVertexBuffer3D()` method. The length of the data in bytes must be `byteArrayOffset` plus four times the number of values per vertex times the number of vertices. The ByteArray object must use the little endian format.
| `byteArrayOffset:int` — number of bytes to skip from the beginning of data
| `startVertex:int` — The index of the first vertex to be loaded. A value for startVertex not equal to zero may be used to load a sub-region of the vertex data.
| `numVertices:int` — The number of vertices to be loaded from `data`.

Throws

| `TypeError` — Null Pointer Error: when `data` is null.
| `RangeError` — Bad Input Size: if `byteArrayOffset` is less than 0, or if `byteArrayOffset` is greater than or equal to the length of `data`, or if no. of elements in `data` - `byteArrayOffset` is less than `numVertices`*`data32pervertex`*4 given in `Context3D::createVertexBuffer()`.
| `Error` — 3768: The `Stage3D` API may not be used during background execution.

### uploadFromVector

()
method

`public function uploadFromVector(data:Vector.<Number>, startVertex:int, numVertices:int):void`

Language Version: | ActionScript 3.0

Runtime Versions: | Flash Player 11, AIR 3

Uploads the data for a set of points to the rendering context from a vector array.

Parameters

| `data:Vector.<Number>` — a vector of 32-bit values. A single vertex is comprised of a number of values stored sequentially in the vector. The number of values in a vertex is specified at buffer creation using the `data32PerVertex` parameter to the Context3D `createVertexBuffer3D()` method. The length of the vector must be the number of values per vertex times the number of vertexes.
| `startVertex:int` — The index of the first vertex to be loaded. A value for `startVertex` not equal to zero may be used to load a sub-region of the vertex data.
| `numVertices:int` — The number of vertices represented by `data`.

Throws

| `TypeError` — Null Pointer Error: when `data` is null.
| `RangeError` — Bad Input Size: when number of elements in `data` is less than `numVertices` * `data32PerVertex` given in `Context3D::createVertexBuffer()`, or when `startVertex` + `numVertices` is greater than `numVertices` given in `Context3D::createVertexBuffer()`.

Examples How to use this example
Context3D_createVertex.as
The following example illustrates how to create and load a vertex data buffer. The buffer in the example contains two types of data for each vertex: the position, as x, y, z coordinates; and the color, as rgb components. After the vertex buffer is created, the example calls the `setVertexBufferAt()` method to specify that the first three data points are passed to the vertex program as 3 Floating point values in va0 and that the second three data points are passed as va1. A vertex program can have up to 8 inputs, also known as vertex attribute registers, defined in this way.
Copy

    const dataPerVertex:int = 6;
    var vertexData:Vector.<Number> = Vector.<Number>(
        [
          // x, y, z    r, g, b format
             0, 0, 0,   1, 1, 1,
            -1, 1, 0,   0, 0,.5,
             1, 1, 0,   0, 0, 1,
             1,-1, 0,  .5, 0, 0,
            -1,-1, 0,   1, 0, 0
        ]
    );
    var vertexes:VertexBuffer3D = renderContext.createVertexBuffer( vertexData.length/dataPerVertex, dataPerVertex );
    vertexes.uploadFromVector( vertexData, 0, vertexData.length/dataPerVertex );

    //Identify vertex data inputs for vertex program
    renderContext.setVertexBufferAt( 0, vertexes, 0, Context3DVertexBufferFormat.FLOAT_3 ); //Defines shader input va0 as the position data
    renderContext.setVertexBufferAt( 1, vertexes, 3, Context3DVertexBufferFormat.FLOAT_3 ); //Defines shader input va1 as the color data

© 2015 Adobe Systems Incorporated. All rights reserved.
Mon Apr 10 2017, 12:28 PM -07:00