/// <summary> /// Generates Tangents and Bitangents for the vertices /// </summary> public void GenerateTangentsAndBitangents() { var positions = GetPositions(); var normals = GetNormals(); var uvs = GetUvs(); var signedIndices = GetSignedIndices(); TriangleListUtils.CalculateTangentsBitangents(positions, normals, uvs, signedIndices, out Vector3[] tangents, out Vector3[] bitangents);
public void ThreeVerticesNormalized() { var values3d = new List <Vector3> { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }; var values2d = new List <Vector2> { new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 1) }; TriangleListUtils.CalculateTangentsBitangents(values3d, values3d, values2d, new List <int> { 0, 1, 2 }, out Vector3[] tangents, out Vector3[] bitangents);
public void ThreeVertices() { var values3d = new List <Vector3> { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) }; TriangleListUtils.CalculateSmoothNormals(values3d, new List <int> { 0, 1, 2 }, out Vector3[] normals); // Ensure vectors are normalized. Assert.AreEqual(1.0f, normals[0].Length, delta); Assert.AreEqual(1.0f, normals[1].Length, delta); Assert.AreEqual(1.0f, normals[2].Length, delta); }
public void CalculateTangentBitangent() { // Don't generate tangents and bitangents if the vertex format doesn't support them. int vertType = vertSize & 0xF; if (!(vertType == 3 || vertType == 7)) { return; } List <int> vertexIndices = GetRenderingVertexIndices(); Vector3[] tangents; Vector3[] bitangents; TriangleListUtils.CalculateTangentsBitangents(GetPositions(), GetNormals(), GetUv0(), vertexIndices, out tangents, out bitangents); ApplyTanBitanArray(tangents, bitangents); }
/// <summary> /// Generates Tangents and Bitangents for the vertices /// </summary> public void GenerateTangentsAndBitangents() { List <int> indices = new List <int>(); foreach (var v in Polygons) { v.ToTriangles(this); if (v.PrimitiveType != IOPrimitive.TRIANGLE) { continue; } indices.AddRange(v.Indicies); } var positions = Vertices.Select(e => e.Position).ToList(); var normals = Vertices.Select(e => e.Normal).ToList(); var uvs = HasUVSet(0) ? Vertices.Select(e => e.UVs[0]).ToList(): Vertices.Select(e => Vector2.Zero).ToList(); TriangleListUtils.CalculateTangentsBitangents(positions, normals, uvs, indices, out Vector3[] tangents, out Vector3[] bitangents);
public void NoVertices() { TriangleListUtils.CalculateSmoothNormals(new List <Vector3>(), new List <int>(), out Vector3[] normals); Assert.AreEqual(0, normals.Length); }