| 836 | } |
| 837 | |
| 838 | void PatchTesselation::generate(std::size_t patchWidth, std::size_t patchHeight, |
| 839 | const PatchControlArray& controlPoints, bool subdivionsFixed, const Subdivisions& subdivs, |
| 840 | IRenderEntity* renderEntity) |
| 841 | { |
| 842 | width = patchWidth; |
| 843 | height = patchHeight; |
| 844 | |
| 845 | _maxWidth = width; |
| 846 | _maxHeight = height; |
| 847 | |
| 848 | // We start off with the control vertex grid, copy it into our tesselation structure |
| 849 | vertices.resize(controlPoints.size()); |
| 850 | |
| 851 | for (std::size_t w = 0; w < width; w++) |
| 852 | { |
| 853 | for (std::size_t h = 0; h < height; h++) |
| 854 | { |
| 855 | vertices[h*width + w].vertex = controlPoints[h*width + w].vertex; |
| 856 | vertices[h*width + w].texcoord = controlPoints[h*width + w].texcoord; |
| 857 | } |
| 858 | } |
| 859 | |
| 860 | // generate normals for the control mesh |
| 861 | generateNormals(); |
| 862 | |
| 863 | if (subdivionsFixed) |
| 864 | { |
| 865 | subdivideMeshFixed(subdivs.x(), subdivs.y()); |
| 866 | } |
| 867 | else |
| 868 | { |
| 869 | subdivideMesh(); |
| 870 | } |
| 871 | |
| 872 | // Final update: assign colours and normalise normals |
| 873 | auto colour = renderEntity ? renderEntity->getEntityColour() : Vector4(1, 1, 1, 1); |
| 874 | |
| 875 | for (MeshVertex& vertex : vertices) |
| 876 | { |
| 877 | // normalize all the lerped normals |
| 878 | if (vertex.normal.getLengthSquared() > 0) |
| 879 | { |
| 880 | vertex.normal.normalise(); |
| 881 | } |
| 882 | |
| 883 | // Assign vertex colours using the colour of the entity |
| 884 | vertex.colour = colour; |
| 885 | } |
| 886 | |
| 887 | // Build the strip indices for rendering the quads |
| 888 | generateIndices(); |
| 889 | |
| 890 | // With indices in place we can derive the tangent/bitangent vectors |
| 891 | deriveTangents(); |
| 892 | } |
no test coverage detected