diff --git a/dust3d/mesh/section_remesher.cc b/dust3d/mesh/section_remesher.cc index f29eb319..c0228612 100644 --- a/dust3d/mesh/section_remesher.cc +++ b/dust3d/mesh/section_remesher.cc @@ -81,7 +81,7 @@ void SectionRemesher::remesh() maxUs[i] = offsetU; offsetU += (m_vertices[i] - m_vertices[j]).length(); } - maxUs[m_ringSize] = offsetU; + maxUs[m_ringSize] += offsetU; offsetU = std::max(offsetU, std::numeric_limits::epsilon()); for (auto& it : maxUs) it /= offsetU; @@ -90,8 +90,8 @@ void SectionRemesher::remesh() m_generatedFaces.emplace_back(std::vector { i, j, m_ringSize }); m_generatedFaceUvs.emplace_back(std::vector { Vector2(maxUs[i], m_ringV), - Vector2(maxUs[j], m_ringV), - Vector2((maxUs[i] + maxUs[j]) * 0.5, m_centerV) }); + Vector2(maxUs[i + 1], m_ringV), + Vector2((maxUs[i] + maxUs[i + 1]) * 0.5, m_centerV) }); } return; } diff --git a/dust3d/mesh/tube_mesh_builder.cc b/dust3d/mesh/tube_mesh_builder.cc index 5efb05e2..d47b4e50 100644 --- a/dust3d/mesh/tube_mesh_builder.cc +++ b/dust3d/mesh/tube_mesh_builder.cc @@ -299,14 +299,12 @@ void TubeMeshBuilder::build() } } if (!m_isCircle) { - addCap(cutFaceIndices.back(), vOffsetBecauseOfFrontCap + vTubeRatio, 1.0); - auto front = cutFaceIndices.front(); - std::reverse(front.begin(), front.end()); - addCap(front, vOffsetBecauseOfFrontCap, 0.0); + addCap(cutFaceIndices.back(), vOffsetBecauseOfFrontCap + vTubeRatio, 1.0, false); + addCap(cutFaceIndices.front(), vOffsetBecauseOfFrontCap, 0.0, true); } } -void TubeMeshBuilder::addCap(const std::vector& section, double ringV, double centerV) +void TubeMeshBuilder::addCap(const std::vector& section, double ringV, double centerV, bool reverseU) { std::vector vertexIndices = section; std::vector ringVertices(vertexIndices.size()); @@ -325,9 +323,13 @@ void TubeMeshBuilder::addCap(const std::vector& section, double ringV, d for (size_t i = 0; i < it.size(); ++i) newFace[i] = vertexIndices[it[i]]; m_generatedFaces.emplace_back(newFace); + if (reverseU) + std::reverse(m_generatedFaces.back().begin(), m_generatedFaces.back().end()); } for (const auto& it : sectionRemesher.generatedFaceUvs()) { m_generatedFaceUvs.emplace_back(it); + if (reverseU) + std::reverse(m_generatedFaceUvs.back().begin(), m_generatedFaceUvs.back().end()); } } diff --git a/dust3d/mesh/tube_mesh_builder.h b/dust3d/mesh/tube_mesh_builder.h index 23cecbce..800ab673 100644 --- a/dust3d/mesh/tube_mesh_builder.h +++ b/dust3d/mesh/tube_mesh_builder.h @@ -69,7 +69,7 @@ private: const Vector3& forwardDirection); void applyRoundEnd(); void applyInterpolation(); - void addCap(const std::vector& section, double ringV, double centerV); + void addCap(const std::vector& section, double ringV, double centerV, bool reverseU); }; };