# normals calculations

a guest
Oct 11th, 2016
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
3.     MeshParams_vec_sp meshParams_vec_sp = MakeShareable(new std::vector<MeshParams>(materialCount));
5.     int chunkCounter = 0;
6.     PolyVox::Mesh<PolyVox::Vertex<MDP88>, unsigned int> DecodedMesh;
10.     }
11.     else {
13.     }
14.
15.     for (int Material = 0; Material < materialCount; Material++)
16.     {
17.         MeshParams* mp = &meshParams_vec_sp->data()[Material];
18.         mp->material_index = Material;
20.         mp->colliderEnabled = true;
21.         // Loop over all of the triangle vertex indices
22.         for (uint32 i = 0; i < DecodedMesh.getNoOfIndices() - 2; i += 3)
23.         {
24.             // We need to add the vertices of each triangle in reverse or the mesh will be upside down
25.             auto Index = DecodedMesh.getIndex(i + 2);
26.             auto Vertex2 = DecodedMesh.getVertex(Index);
27.             auto TriangleMaterial = Vertex2.data.getMaterial();
28.
29.             // Before we continue, we need to be sure that the triangle is the right material; we don't want to use verticies from other materials
30.             if (TriangleMaterial == (Material + 1))
31.             {
32.                 // If it is of the same material, then we need to add the correct indices now
34.
35.                 Index = DecodedMesh.getIndex(i + 1);
36.                 auto Vertex1 = DecodedMesh.getVertex(Index);
38.
39.                 Index = DecodedMesh.getIndex(i);
40.                 auto Vertex0 = DecodedMesh.getVertex(Index);
42.
43.                 // Calculate the tangents of our triangle
44.                 const FVector Edge01 = FPolyVoxVector(Vertex1.position - Vertex0.position);
45.                 const FVector Edge02 = FPolyVoxVector(Vertex2.position - Vertex0.position);
46.
47.                 const FVector TangentX = Edge01.GetSafeNormal();
48.                 FVector TangentZ = (Edge01 ^ Edge02).GetSafeNormal();
49.
50.                 for (int32 i = 0; i < 3; i++)
51.                 {