Hi John,
I made a function that if a mesh is big, it is splitting it into peaces of 65535 vertices, and takes 65535/3 of the index coordinates, from the x3d file. works fine, I don't understand why every triangle has to have 3 vertices though, as you say, some vertices are shared by more then one triangle, no point in writing them twice, I really don't understand why the exporter of x3d from 3d max is writing the file this way, maybe it is part of the xd3 file format, and maybe it is a limitation of the exporter, don't know.
Anyway I have another problem. when you rotate the object, you have to rotate the light direction you use in the Fragment shader, otherwise the light will rotate with the object as if it is a spot of color on the object, so I did rotate it, but then if I use a very small object the light spot is not steady while you rotate the object, it dances around, I guess when the calculation is done with very small numbers, with many numbers over the floating point, that makes the output very inaccurate.
maybe this is not the reason, but I can't think of anything else.
here is the code I use to rotate and move the light source to it's correct position, maybe someone can show me a better way to do it.
first I get the rotation and position changes stored in the object, and the groups it belongs to, in a Matrix3D called "drawMatrix":
var tmp:Object3D = obj;
while (tmp.Parent)
{
drawMatrix.prepend(tmp.Parent.modelToWorld);
tmp = tmp.Parent;
}
drawMatrix.prepend(worldToClip);
now I use this matrix to rotate and move the light:
var m:Vector.<Number> = obj.modelToWorld.rawData;
//I begin by setting the light position it it's original place I have to
//change the position in accordance of the object, don't know exactly why but
//this is the only way it works.
obj.LightPos = new Vector3D();
obj.LightPos.x = -(sceneLight.Position.x - m[3]);
obj.LightPos.y = -(sceneLight.Position.y - m[7]);
obj.LightPos.z = sceneLight.Position.z - m[11];
obj.LightPos.w = sceneLight.Position.w;
//now I do the adjustment
obj.LightDir = new Matrix3D();
drawMatrix.copyToMatrix3D(obj.LightDir);
obj.LightDir.appendRotation(180, Vector3D.X_AXIS);
obj.LightDir.appendRotation(180, Vector3D.Z_AXIS);
obj.LightPos = obj.LightDir.transformVector(obj.LightPos);
obj.LightPos.normalize();
obj.LightPos.scaleBy(sceneLight.intensity);
any help would be appreciated
Thanks.