Creating a face from vertices?

Software: Away3D 4.x

hlstriker, Newbie
Posted: 17 September 2011 08:27 PM   Total Posts: 1

I’m trying to create a face using vertices but have no clue how with Away3D 4. I found the tutorial below but apparently it’s all different now.

http://polygeek.com/3965_away3d_101-vector-shapes

Can someone please explain how I can do this in Away3D 4?

   

Avatar
Alejandro Santander, Administrator
Posted: 18 September 2011 02:00 AM   Total Posts: 414   [ # 1 ]

You can do something like this:

public class Triangle extends PrimitiveBase
{
    
private var _v0:Vector3D;
    private var 
_v1:Vector3D;
    private var 
_v2:Vector3D;
    private var 
_uv0:Vector3D;
    private var 
_uv1:Vector3D;
    private var 
_uv2:Vector3D;

    
// Define vertices in a clockwise manner.
    
public function Triangle(material:MaterialBase, v0:Vector3D, v1:Vector3D, v2:Vector3D,
                                                    
uv0:Vector3D = null, uv1:Vector3D = null, uv2:Vector3D = null)
    
{
        super
(material);

        
_v0 = v0;
        
_v1 = v1;
        
_v2 = v2;
        
_uv0 = uv0;
        
_uv1 = uv1;
        
_uv2 = uv2;
    
}

    override 
protected function buildGeometry(target:SubGeometry):void
    {
        
var rawVertices:Vector.<Number> = Vector.<Number>([_v0.x, _v0.y, _v0.z, _v1.x, _v1.y, _v1.z, _v2.x, _v2.y, _v2.z]);
        var 
rawIndices:Vector.<uint> = Vector.<uint>([0, 1, 2]);

        var 
d0:Vector3D = _v1.subtract(_v0);
        var 
d1:Vector3D = _v2.subtract(_v0);
        var 
rawTangents:Vector.<Number> = Vector.<Number>([0, 0, 0]);

        var 
normal:Vector3D = d0.crossProduct(d1);
        
normal.normalize();
        var 
rawNormals:Vector.<Number> = Vector.<Number>([normal.x, normal.y, normal.z, normal.x, normal.y, normal.z, normal.x, normal.y, normal.z]);

        
target.updateVertexData(rawVertices);
        
target.updateIndexData(rawIndices);
        
target.updateVertexNormalData(rawNormals);
        
target.updateVertexTangentData(rawTangents);
    
}

    override 
protected function buildUVs(target:SubGeometry):void
    {
        
if(_uv0 && _uv1 && _uv2)
            var 
rawUvData:Vector.<Number> = Vector.<Number>([_uv0.x, _uv0.y, _uv1.x, _uv1.y, _uv2.x, _uv2.y]);
    
}
}
} 
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X