hi,
i would like to draw triangles using exactly this class :
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();
//trace("add triangle,normals", normal.x, normal.y, normal.z);
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]);
}
}
but i encounter a very confusing problem :
if i define the vertices of the triangle like this, all is rendered fine:
new Vector3D( -2, 0.1, 2),//p1
new Vector3D( 2, 0.1, 2),//p2
new Vector3D( 0, 0.1, 0)//p3
but changing the vertices in this order, the triangle is not rendered:
new Vector3D( 2, 0.1, 2),//p1
new Vector3D( 0, 0.1, 0),//p2
new Vector3D( -2, 0.1, 2)//p3
both is in clockwise order, i have no idea why the second triangle is not rendered.
this image shows the orientaion of both triangles:
triangle Problem