static void CalculateTangentForFace(VertexInfo[] vertices, RangeI indexRange, Vector3F[] tangents, Vector3F[] bitangents, GetTextureCoord getTextureCoord = null) { // triangle or polygon... we always use only the first three indices. A polygon // is supposed to be planar anyways.... if (indexRange.Size < 3) { for (int i = indexRange.Minimum; i < indexRange.Maximum; i++) { tangents[i] = new Vector3F(float.NaN, float.NaN, float.NaN); bitangents[i] = new Vector3F(float.NaN, float.NaN, float.NaN); } FbxImportLog.LogWarning("To calculate the tangents a polygon must have > 2 vertices"); return; } ref StandardVertex pt0 = ref vertices[indexRange.Minimum].Vertex;
/// <summary> /// Requirements : normals and UV coordinates must be present. /// </summary> /// <param name="vertices"></param> /// <param name="tangents"></param> /// <param name="bitangents"></param> /// <param name="getTextureCoord">if null then texCoord0 is used, if not null this delegete than takes the necessary texCoord</param> public static void CalculateTangents(VertexInfo[] vertices, out Vector3F[] tangents, out Vector3F[] bitangents, GetTextureCoord getTextureCoord = null) { tangents = new Vector3F[vertices.Length]; bitangents = new Vector3F[vertices.Length]; if (vertices.Length == 0) { return; } foreach (var polygonIndexRange in CalcMiscProcess.EnumeratePolygons(vertices)) { CalculateTangentForFace(vertices, polygonIndexRange, tangents, bitangents, getTextureCoord); } //SmoothTangents( vertices, tangents, bitangents, FbxMath.ComputePositionEpsilon( vertices ), maxSmoothingAngleInRadians ); }