“guess they’re not always 0”
That should be 1,0,0
Also buildUvs should be something like
var rawUvData:Vector.<Number>
if(_uv0 && _uv1 && _uv2)
rawUvData = Vector.<Number>([_uv0.x, _uv0.y, _uv1.x, _uv1.y, _uv2.x, _uv2.y]);
else
rawUvData = Vector.<Number>([0, 0, 0, 1, 1, 1]);
target.updateUVData(rawUvData);
Sorry, I blame Li )
http://code.google.com/p/litools/source/browse/trunk/com/li/away3d/primitives/Triangle.as
How do you caluclate them?
If your not using bump mapping, you dont need them (I think, not sure if anything else needs them).
The easy way, would be to not bother and use
target.autoDeriveVertexTangents = true;
instead of
target.updateVertexTangentData(vertexTangents);
or
myMesh.subGeometries[0].autoDeriveVertexTangents = true;
after you create the mesh.
Same with normals
target.autoDeriveVertexNormals = true;
If you were doing a plane with rounded corners then the tangents would still be 1,0,0
Trying to think of a better way to say this but..
tangents basically point in the same direction as the u of the UV space blaa blaa blaa and averaged with any shared vertices.
try that google thang Or work out what happens in subGeometry.as updateVertexTangents()
As for indices.
Little example with a plane.
If you trace out the vertices for the plane.
var plane:Plane = new Plane(new ColorMaterial(0xff0000));
scene.addChild(plane);
trace(plane.geometry.subGeometries[0].vertexData);
//-50,0,-50, 50,0,-50, -50,0,50 ,50,0,50
You only seem to get 4 vertices, you would expect there would be 6 ( 2 triangles), something like
-50, 0, -50, -50, 0, 50, 50, 0, 50, -50, 0, -50, 50, 0, 50, 50, 0, -50
Thats because the adjacent edge of the two triangles are sharing the same vertice positions.
Tracing out the indices
trace(plane.geometry.subGeometries[0].indexData);
//0,2,3,0,3,1
yay we got six of something
Notice 0 and 3 appear twice, they are the shared ones.
Indices give you the index position of the vertices,Uvs,normals and tangents.
eg
var index:Vector.<uint> = plane.geometry.subGeometries[0].indexData;
var vertex:Vector.<Number> = plane.geometry.subGeometries[0].vertexData;
var tangent:Vector.<Number> = plane.geometry.subGeometries[0].vertexTangentData
var normal:Vector.<Number> = plane.geometry.subGeometries[0].vertexNormalData;
var uv:Vector.<Number> = plane.geometry.subGeometries[0].UVData;
var ind:uint = 0
for ( var i:uint = 0; i < index.length; i++)
{
ind = index[i]*3;
trace(vertex[ind] , vertex[ind+1], vertex[ind + 2]);
//trace(normal[ind] , normal[ind+1], normal[ind + 2]);
//trace(tangent[ind], tangent[ind + 1], tangent[ind + 2]);
/*UVs only 2 components
* ind = index[i] * 2;
* trace(uv[ind] , uv[ind + 1]);
*/
}
A mesh can be made with shared vertices,normals etc or with unique ones or a mixture of both.
The cube uses both, shared vertices tangents and normals for each side unique for each edge of the cube.
Basically unique will give a harder edge under lights as the normals for each vertex can be slightly different.
//add a light to your mesh then try this
//raise the Y component of the first vertice by 50 (this is a shared one)
plane.geometry.subGeometries[0].vertexData[1] += 50;
plane.geometry.subGeometries[0].updateVertexData(plane.geometry.subGeometries[0].vertexData)
render and you see the edge isnt very hard under the lights thats the shared normals
now add
//makes all vertices normals tangents unique
Explode.apply(plane, false);
You will see a harder edge under the light.
Another thing that may help
look at
MeshDebugTest in the examples to see normals/tangents etc and play about.
Blaa blaa blaa lots of other stuff
erm google