diff --git a/dust3d/mesh/tube_mesh_builder.cc b/dust3d/mesh/tube_mesh_builder.cc index f49ebdb4..f9ae4efa 100644 --- a/dust3d/mesh/tube_mesh_builder.cc +++ b/dust3d/mesh/tube_mesh_builder.cc @@ -62,12 +62,15 @@ void TubeMeshBuilder::buildNodePositionAndDirections() std::vector rawDirections; rawDirections.resize(m_nodePositions.size()); + m_nodeForwardDistances.resize(m_nodePositions.size()); m_nodeForwardDirections.resize(m_nodePositions.size()); if (m_nodePositions.size() >= 2) { if (m_isCircle) { for (size_t i = 0; i < m_nodePositions.size(); ++i) { size_t j = (i + 1) % m_nodePositions.size(); - rawDirections[i] = (m_nodePositions[j] - m_nodePositions[i]).normalized(); + rawDirections[i] = (m_nodePositions[j] - m_nodePositions[i]); + m_nodeForwardDistances[i] = rawDirections[i].length(); + rawDirections[i].normalize(); } for (size_t i = 0; i < m_nodePositions.size(); ++i) { size_t j = (i + 1) % m_nodePositions.size(); @@ -76,13 +79,16 @@ void TubeMeshBuilder::buildNodePositionAndDirections() } else { for (size_t j = 1; j < m_nodePositions.size(); ++j) { size_t i = j - 1; - rawDirections[i] = (m_nodePositions[j] - m_nodePositions[i]).normalized(); + rawDirections[i] = (m_nodePositions[j] - m_nodePositions[i]); + m_nodeForwardDistances[i] = rawDirections[i].length(); + rawDirections[i].normalize(); } rawDirections[m_nodeForwardDirections.size() - 1] = rawDirections[m_nodeForwardDirections.size() - 2]; m_nodeForwardDirections.front() = rawDirections.front(); for (size_t j = 1; j + 1 < m_nodePositions.size(); ++j) { size_t i = j - 1; - m_nodeForwardDirections[j] = (rawDirections[i] + rawDirections[j]).normalized(); + m_nodeForwardDirections[j] = (rawDirections[i] * m_nodeForwardDistances[j] + + rawDirections[j] * m_nodeForwardDistances[i]).normalized(); } m_nodeForwardDirections.back() = rawDirections.back(); } diff --git a/dust3d/mesh/tube_mesh_builder.h b/dust3d/mesh/tube_mesh_builder.h index c5dc61ff..fd0ec653 100644 --- a/dust3d/mesh/tube_mesh_builder.h +++ b/dust3d/mesh/tube_mesh_builder.h @@ -53,6 +53,7 @@ private: std::vector m_nodes; std::vector m_nodePositions; std::vector m_nodeForwardDirections; + std::vector m_nodeForwardDistances; std::vector m_generatedVertices; std::vector> m_generatedFaces; Vector3 m_generatedBaseNormal;