triangle vertices problem

Software: Away3D 4.x

Grummel88, Newbie
Posted: 12 November 2011 12:50 PM   Total Posts: 2

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:MaterialBasev0:Vector3Dv1:Vector3Dv2:Vector3D,
                                                    
uv0:Vector3D nulluv1:Vector3D nulluv2: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>([012]);

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

        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.xnormal.ynormal.znormal.xnormal.ynormal.znormal.xnormal.ynormal.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(   -20.12),//p1
new Vector3D(   20.12),//p2
new Vector3D(  00.10)//p3 

but changing the vertices in this order, the triangle is not rendered:

new Vector3D(   20.12),//p1
new Vector3D(   00.10),//p2
new Vector3D(  -20.12)//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

 

   

Avatar
Fabrice Closier, Administrator
Posted: 12 November 2011 09:01 PM   Total Posts: 1265   [ # 1 ]

probably because the resulting normal is pointing the other way. Here you do shift the values of the vertices but have you updated their respective indices as well?

Also, if you want to see the triangles at all time (assuming camera is looking at them of course), no matter what their orientations are, set bothSides true to you material.

   

Avatar
80prozent, Sr. Member
Posted: 12 November 2011 09:50 PM   Total Posts: 430   [ # 2 ]

hi

i tested this too.

doing trace for the normal gives the same for both cases (0,1,0)

i enabled bothSides on the material, but still the triangle wont show up.

 Signature 

sorry…i hope my actionscript is better than my english…

   

Grummel88, Newbie
Posted: 13 November 2011 10:16 AM   Total Posts: 2   [ # 3 ]

hi,

of course the vector data posted are just input data for the constructor of the triangle class. So for both triangles, points are passed in a clockwise manner. Both normal vectors are equal, pointing up (0,1,0). Should face the camera. But the second triangle will not draw.

i found a workaround, first sort all points along the x axis. After that determine winding order and exchange points if required.

regards

   
   
‹‹ 3D Picture

X

Away3D Forum

Member Login

Username

Password

Remember_me



X