В мене э функція для читання і створення мешу води, проте деякі фігури "flipped", я…
- User
В мене э функція для читання і створення мешу води, проте деякі фігури "flipped", я знайшов ці фігури в файлі, допоможи розбратись. Ось функція: bool World::LoadWater(const std::string& filepath) { std::vectorstd::string waterData = readWaterDatFile(filepath);
if (waterData.empty()) { std::cerr << "Failed to read water data or file is empty." << std::endl; return false; } std::cout << "Read " << waterData.size() << " lines from " << filepath << std::endl; std::vector<glm::vec3> vertices; std::vector<unsigned int> indices; for (const auto& line : waterData) { if (line == "processed" || line.empty() || line[0] == '#') { continue; // Skip processed, empty, or comment lines } std::istringstream iss(line); std::vector<float> values; float value; while (iss >> value) { values.push_back(value); } if (values.size() != 29) { // 28 floats + 1 int std::cerr << "Invalid data line: " << line << std::endl; continue; } // Extract the four corners of the water quad std::array<glm::vec3, 4> corners; for (int i = 0; i < 4; ++i) { corners[i] = glm::vec3(values[i * 7], values[i * 7 + 1], values[i * 7 + 2]); } // Add vertices and merge if close enough std::array<unsigned int, 4> cornerIndices; for (int i = 0; i < 4; ++i) { cornerIndices[i] = vertices.size(); vertices.push_back(corners[i]); } // Add two triangles to form a quad indices.push_back(cornerIndices[0]); indices.push_back(cornerIndices[1]); indices.push_back(cornerIndices[2]); indices.push_back(cornerIndices[2]); indices.push_back(cornerIndices[1]); indices.push_back(cornerIndices[3]); } // Add merged vertices to the mesh for (const auto& vertex : vertices) { m_WaterWorldMesh.addVertex(vertex.x, vertex.y, vertex.z); } // Add triangles to the mesh for (size_t i = 0; i < indices.size(); i += 3) { m_WaterWorldMesh.addTriangle(indices[i], indices[i + 1], indices[i + 2]); } if (vertices.empty()) { std::cerr << "No valid water data found in the file." << std::endl; return false; } return true;} Ось приклад правильних фігур (в файлі): 2000.0 1000.0 12.5 0.00000 0.00000 0.00000 0.00000 2000.0 1200.0 12.5 0.00000 0.00000 0.00000 0.00000 1900.0 1000.0 12.5 0.00000 0.00000 0.00000 0.00000 1900.0 1200.0 12.5 0.00000 0.00000 0.00000 0.00000 1 680.0 656.0 9.59998 0.00000 0.00000 0.00000 0.00000 680.0 732.0 9.59998 0.00000 0.00000 0.00000 0.00000 580.0 656.0 9.59998 0.00000 0.00000 0.00000 0.00000 580.0 732.0 9.59998 0.00000 0.00000 0.00000 0.00000 1 68.0 344.0 11.0 0.00000 0.00000 0.00000 0.00000 68.0 408.0 11.0 0.00000 0.00000 0.00000 0.00000 0.0 344.0 11.0 0.00000 0.00000 0.00000 0.00000 0.0 408.0 11.0 0.00000 0.00000 0.00000 0.00000 1 -1036.0 2248.0 0.0 0.00000 0.00000 0.00000 0.00000 -1036.0 2500.0 0.0 0.00000 0.00000 0.00000 0.00000 -1336.0 2248.0 -6.10352e-05 0.00000 0.00000 0.00000 0.00000 -1336.0 2500.0 -6.10352e-05 0.00000 0.00000 0.00000 0.00000 1 -872.0 2248.0 0.0 0.00000 0.00000 0.00000 0.00000 -872.0 2500.0 0.0 0.00000 0.00000 0.00000 0.00000 -1036.0 2248.0 0.0 0.00000 0.00000 0.00000 0.00000 -1036.0 2500.0 0.0 0.00000 0.00000 0.00000 0.00000 1 -624.0 2248.0 0.0 0.00000 0.00000 0.00000 0.00000 -624.0 2500.0 0.0 0.00000 0.00000 0.00000 0.00000 -872.0 2248.0 0.0 0.00000 0.00000 0.00000 0.00000 -872.0 2500.0 0.0 0.00000 0.00000 0.00000 0.00000 1 -624.0 2500.0 0.0 0.00000 0.00000 0.00000 0.00000 -624.0 2624.0 0.0 0.00000 0.00000 0.00000 0.00000 -872.0 2500.0 0.0 0.00000 0.00000 0.00000 0.00000 -872.0 2624.0 0.0 0.00000 0.00000 0.00000 0.00000 1 -916.0 192.0 22.5 0.00000 0.00000 0.00000 0.00000 -916.0 216.0 22.5 0.00000 0.00000 0.00000 0.00000 -944.0 192.0 22.5 0.00000 0.00000 0.00000 0.00000 -944.0 216.0 22.5 0.00000 0.00000 0.00000 0.00000 1 -936.0 336.0 24.5 0.00000 0.00000 0.00000 0.00000 -936.0 352.0 24.5 0.00000 0.00000 0.00000 0.00000 -956.0 336.0 24.5 0.00000 0.00000 0.00000 0.00000 -956.0 352.0 24.5 0.00000 0.00000 0.00000 0.00000 1 -1048.0 336.0 24.0 0.00000 0.00000 0.00000 0.00000 -1048.0 348.0 24.0 0.00000 0.00000 0.00000 0.00000 -1052.0 336.0 24.0 0.00000 0.00000 0.00000 0.00000 -1052.0 348.0 24.0 0.00000 0.00000 0.00000 0.00000 1 -1044.0 188.0 24.7 0.00000 0.00000 0.00000 0.00000 -1044.0 204.0 24.7 0.00000 0.00000 0.00000 0.00000 -1060.0 188.0 24.7 0.00000 0.00000 0.00000 0.00000 -1060.0 204.0 24.7 0.00000 0.00000 0.00000 0.00000 1. І ось всі неправильні фігури (трикутники деякі чомусь неправильно flipped): -2836.0 1788.0 -0.000305176 0.00000 0.00000 0.00000 0.00000 -2836.0 2060.0 -0.000366211 0.00000 0.00000 0.00000 0.00000 -3136.0 2060.0 -0.000549316 0.00000 0.00000 0.00000 0.00000 -3136.0 1788.0 -0.000488281 0.00000 0.00000 0.00000 0.00000 1 -2536.0 1788.0 -0.00012207 0.00000 0.00000 0.00000 0.00000 -2536.0 2060.0 -0.000183105 0.00000 0.00000 0.00000 0.00000 -2836.0 2060.0 -0.000610352 0.00000 0.00000 0.00000 0.00000 -2836.0 1788.0 -0.000549316 0.00000 0.00000 0.00000 0.00000 1 -2236.0 1788.0 0.000244141 0.00000 0.00000 0.00000 0.00000 -2236.0 2060.0 0.000183105 0.00000 0.00000 0.00000 0.00000 -2536.0 2060.0 -0.000244141 0.00000 0.00000 0.00000 0.00000 -2536.0 1788.0 -0.000183105 0.00000 0.00000 0.00000 0.00000 1 -1936.0 1788.0 0.000610352 0.00000 0.00000 0.00000 0.00000 -1936.0 2060.0 0.000549316 0.00000 0.00000 0.00000 0.00000 -2236.0 2060.0 0.00012207 0.00000 0.00000 0.00000 0.00000 -2236.0 1788.0 0.000183105 0.00000 0.00000 0.00000 0.00000 1 -1636.0 1868.0 0.000244141 0.00000 0.00000 0.00000 0.00000 -1636.0 2136.0 0.000183105 0.00000 0.00000 0.00000 0.00000 -1936.0 2136.0 -0.000244141 0.00000 0.00000 0.00000 0.00000 -1936.0 1868.0 -0.000183105 0.00000 0.00000 0.00000 0.00000 1 -1336.0 1948.0 0.000549316 0.00000 0.00000 0.00000 0.00000 -1336.0 2216.0 0.000488281 0.00000 0.00000 0.00000 0.00000 -1636.0 2216.0 6.10352e-05 0.00000 0.00000 0.00000 0.00000 -1636.0 1948.0 0.00012207 0.00000 0.00000 0.00000 0.00000 1 -1036.0 1976.0 0.000488281 0.00000 0.00000 0.00000 0.00000 -1036.0 2248.0 0.000427246 0.00000 0.00000 0.00000 0.00000 -1336.0 2248.0 0.0 0.00000 0.00000 0.00000 0.00000 -1336.0 1976.0 6.10352e-05 0.00000 0.00000 0.00000 0.00000 1 -2100.0 -2700.0 0.0 0.00000 0.00000 0.00000 0.00000 -2100.0 -2400.0 0.0 0.00000 0.00000 0.00000 0.00000 -2400.0 -2400.0 0.0 0.00000 0.00000 0.00000 0.00000 -2400.0 -2700.0 0.0 0.00000 0.00000 0.00000 0.00000 1 -2400.0 -2400.0 6.10352e-05 0.00000 0.00000 0.00000 0.00000 -2400.0 -2100.0 6.10352e-05 0.00000 0.00000 0.00000 0.00000 -2700.0 -2100.0 6.10352e-05 0.00000 0.00000 0.00000 0.00000 -2700.0 -2400.0 6.10352e-05 0.00000 0.00000 0.00000 0.00000 1
- Assistant