Packagealternativa.engine3d.resources
Classpublic class Geometry
InheritanceGeometry Inheritance Resource Inheritance Object

Resource, that stores data about geometry of object. All data are stored for each vertex. So, you can set any set of parameters. And this set will be defined for each vertex of geometry. It will be useful to divide parameters by some vertexBuffers in order to update these data at memory of GPU, independently of each other (vertexBuffer can be updated at once only). For this, you can store groups of parameters in different streams. Based on them vertexBuffers will be formed on uploading to GPU. When new stream is formed, are specified the parameters, that will be stored in it.

View the examples



Public Properties
 PropertyDefined By
  indices : Vector.<uint>
Indexes of vertices for specifying of triangles of surface.
Geometry
  isUploaded : Boolean
[override] [read-only] Check for existence of resource in video memory.
Geometry
  numTriangles : int
[read-only] Number of triangles, that are contained in geometry.
Geometry
  numVertexStreams : int
[read-only] Number of vertex-streams.
Geometry
  numVertices : int
Number of vertices of geometry.
Geometry
Public Methods
 MethodDefined By
  
Geometry(numVertices:int = 0)
Creates a new instance.
Geometry
  
addVertexStream(attributes:Array):int
Adds a stream for set of parameters, that can be updated independently of the other sets of parameters.
Geometry
  
Calculation of vertex normals.
Geometry
  
calculateTangents(uvChannel:int):void
Calculation of tangents and bi-normals.
Geometry
  
dispose():void
[override] Removes this resource from Context3D to which it was uploaded.
Geometry
  
findVertexStreamByAttribute(attribute:uint):int
Returns index of stream, that contains needed attribute.
Geometry
  
getAttributeOffset(attribute:uint):int
Offset of attribute at stream, with which this attribute is stored.
Geometry
  
getAttributeValues(attribute:uint):Vector.<Number>
Geometry
  
getVertexStreamAttributes(index:int):Array
returns mapping of stream by index.
Geometry
  
hasAttribute(attribute:uint):Boolean
Check the existence of attribute in all streams.
Geometry
  
setAttributeValues(attribute:uint, values:Vector.<Number>):void
Sets value for attribute.
Geometry
  
updateIndexBufferInContextFromByteArray(data:ByteArray, byteArrayOffset:int, startOffset:int, count:int):void
Updates values of index-buffer in video memory.
Geometry
  
updateIndexBufferInContextFromVector(data:Vector.<uint>, startOffset:int, count:int):void
Updates values of index-buffer in video memory.
Geometry
  
updateVertexBufferInContextFromByteArray(index:int, data:ByteArray, byteArrayOffset:int, startVertex:int, numVertices:int):void
Updates values of vertex-buffer in video memory.
Geometry
  
updateVertexBufferInContextFromVector(index:int, data:Vector.<Number>, startVertex:int, numVertices:int):void
Updates values of vertex-buffer in video memory.
Geometry
  
upload(context3D:Context3D):void
[override] Uploads resource into given Context3D.
Geometry
Property Detail
indicesproperty
indices:Vector.<uint>

Indexes of vertices for specifying of triangles of surface. Example of specifying of surface, that consists of two triangles: Vector.<uint>([vertex_id_1,vertex_id_2,vertex_id_3,vertex_id_4,vertex_id_5,vertex_id_6]);.


Implementation
    public function get indices():Vector.<uint>
    public function set indices(value:Vector.<uint>):void
isUploadedproperty 
isUploaded:Boolean  [read-only] [override]

Check for existence of resource in video memory.


Implementation
    public function get isUploaded():Boolean
numTrianglesproperty 
numTriangles:int  [read-only]

Number of triangles, that are contained in geometry.


Implementation
    public function get numTriangles():int
numVertexStreamsproperty 
numVertexStreams:int  [read-only]

Number of vertex-streams.


Implementation
    public function get numVertexStreams():int
numVerticesproperty 
numVertices:int

Number of vertices of geometry.


Implementation
    public function get numVertices():int
    public function set numVertices(value:int):void
Constructor Detail
Geometry()Constructor
public function Geometry(numVertices:int = 0)

Creates a new instance.

Parameters
numVertices:int (default = 0) — Number of vertices.
Method Detail
addVertexStream()method
public function addVertexStream(attributes:Array):int

Adds a stream for set of parameters, that can be updated independently of the other sets of parameters.

Parameters

attributes:Array — List of parameters. Types of parameters are get from VertexAttributes.

Returns
int — Index of stream, that has been created.
calculateNormals()method 
public function calculateNormals():void

Calculation of vertex normals.

calculateTangents()method 
public function calculateTangents(uvChannel:int):void

Calculation of tangents and bi-normals. Normals of geometry must be calculated.

Parameters

uvChannel:int

dispose()method 
override public function dispose():void

Removes this resource from Context3D to which it was uploaded.

findVertexStreamByAttribute()method 
public function findVertexStreamByAttribute(attribute:uint):int

Returns index of stream, that contains needed attribute.

Parameters

attribute:uint

Returns
int — -1 if attribute is not found.
getAttributeOffset()method 
public function getAttributeOffset(attribute:uint):int

Offset of attribute at stream, with which this attribute is stored. You can find index of stream using findVertexStreamByAttribute.

Parameters

attribute:uint — Type of attribute. List of types of attributes placed at VertexAttributes.

Returns
int — Offset.

See also

getAttributeValues()method 
public function getAttributeValues(attribute:uint):Vector.<Number>

Parameters

attribute:uint

Returns
Vector.<Number>
getVertexStreamAttributes()method 
public function getVertexStreamAttributes(index:int):Array

returns mapping of stream by index.

Parameters

index:int — index of stream.

Returns
Array — mapping.
hasAttribute()method 
public function hasAttribute(attribute:uint):Boolean

Check the existence of attribute in all streams.

Parameters

attribute:uint — Attribute, that is checked.

Returns
Boolean
intersectRay()method 
alternativa3d function intersectRay(origin:Vector3D, direction:Vector3D, indexBegin:uint, numTriangles:uint):RayIntersectionData

Parameters

origin:Vector3D
 
direction:Vector3D
 
indexBegin:uint
 
numTriangles:uint

Returns
RayIntersectionData
setAttributeValues()method 
public function setAttributeValues(attribute:uint, values:Vector.<Number>):void

Sets value for attribute. If buffer has not been initialized, then it initialized with zeros automatically.

Parameters

attribute:uint
 
values:Vector.<Number>

updateIndexBufferInContextFromByteArray()method 
public function updateIndexBufferInContextFromByteArray(data:ByteArray, byteArrayOffset:int, startOffset:int, count:int):void

Updates values of index-buffer in video memory.

Parameters

data:ByteArray — Data
 
byteArrayOffset:int — Offset
 
startOffset:int — Number of updated values.
 
count:int

updateIndexBufferInContextFromVector()method 
public function updateIndexBufferInContextFromVector(data:Vector.<uint>, startOffset:int, count:int):void

Updates values of index-buffer in video memory.

Parameters

data:Vector.<uint> — List of values.
 
startOffset:int — Offset.
 
count:int — Count of updated values.

updateVertexBufferInContextFromByteArray()method 
public function updateVertexBufferInContextFromByteArray(index:int, data:ByteArray, byteArrayOffset:int, startVertex:int, numVertices:int):void

Updates values of vertex-buffer in video memory.

Parameters

index:int — Data
 
data:ByteArray — Offset.
 
byteArrayOffset:int — Number of updated values.
 
startVertex:int
 
numVertices:int

updateVertexBufferInContextFromVector()method 
public function updateVertexBufferInContextFromVector(index:int, data:Vector.<Number>, startVertex:int, numVertices:int):void

Updates values of vertex-buffer in video memory.

Parameters

index:int — List of values.
 
data:Vector.<Number> — Offset.
 
startVertex:int — Number of updated values.
 
numVertices:int

upload()method 
override public function upload(context3D:Context3D):void

Uploads resource into given Context3D.

Parameters

context3D:Context3DContext3D to which resource will uploaded.

Examples
This code creates stream on properties: x,y,z,u,v and forms a triangle by three vertices.
     var attributes:Array = new Array();
     attributes[0] = VertexAttributes.POSITION;
     attributes[1] = VertexAttributes.POSITION;
     attributes[2] = VertexAttributes.POSITION;
     attributes[3] = VertexAttributes.TEXCOORDS[0];
     attributes[4] = VertexAttributes.TEXCOORDS[0];
     var geometry = new Geometry();
     geometry.addVertexStream(attributes);
     geometry.numVertices = 3;
     geometry.setAttributeValues(VertexAttributes.POSITION, new <Number>[x1,y1,z1,x2,y2,z2,x3,y3,z3]);
     geometry.setAttributeValues(VertexAttributes.TEXCOORDS[0], new <Number>[u1,v1,u2,v2,u3,v3]);
     geometry.indices = Vector.<uint>([0,1,2]);
     
To get access to data, you can use method getAttributeValues by parameter name, e.g.: geometry.getAttributeValues(VertexAttributes.POSITION) returns vector from coordinates: <Number>[x1,y1,z1,x2,y2,z2,x3,y3,z3].