trackgen: fix double sided normals

git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@9473 30fe4595-0a0c-4342-8851-515496e4dcbd

Former-commit-id: e80bca4f9f393817be4061918f20e9dba886be68
Former-commit-id: 48b0dff667dc927c6452b2630b2ecccb95442a73
This commit is contained in:
iobyte 2024-07-11 15:12:02 +00:00
parent cb897f2621
commit a809475b47
2 changed files with 8 additions and 5 deletions

View file

@ -1205,7 +1205,7 @@ void Ac3d::Object::generateNormals()
V3d vertex = { 0.0, 0.0, 0.0 };
V3d normal = { 0.0, 0.0, 0.0 };
bool operator == (const Vertex &other) const
bool equals(const Vertex &other) const
{
return (vertex.equals(other.vertex) && normal.equals(other.normal));
}
@ -1276,7 +1276,10 @@ void Ac3d::Object::generateNormals()
vertex.normal = m_normals[index][0];
for (size_t i = 1; i < m_normals[index].size(); i++)
{
if (object.crease.initialized || vertex.normal.angleDegrees(m_normals[index][i]) < object.crease.value)
double angle = vertex.normal.angleDegrees(m_normals[index][i]);
if (object.crease.initialized && angle < object.crease.value)
vertex.normal += m_normals[index][i];
else if (angle < 179.999)
vertex.normal += m_normals[index][i];
}
vertex.normal.normalize();
@ -1361,9 +1364,9 @@ void Ac3d::Object::generateNormals()
{
bool found = false;
const Vertex vertex = triangle.vertex(i, *this);
for (size_t j = 0; j < new_vertices.size(); j++)
for (size_t j = 0, end = new_vertices.size(); j < end; j++)
{
if (new_vertices[j] == vertex)
if (new_vertices[j].equals(vertex))
{
triangle.m_vertex_index[i] = int(j);
found = true;

View file

@ -97,7 +97,7 @@ struct Ac3d
}
bool equals(const V3d &other) const
{
static constexpr double SMALL_NUM = static_cast<double>(std::numeric_limits<double>::epsilon());
static constexpr double SMALL_NUM = static_cast<double>(std::numeric_limits<float>::epsilon());
return std::abs(x() - other.x()) < SMALL_NUM &&
std::abs(y() - other.y()) < SMALL_NUM &&