Skip to content

Commit

Permalink
#5576: Add another ArbitraryMeshVertex constructor accepting the vert…
Browse files Browse the repository at this point in the history
…ex colour
  • Loading branch information
codereader committed Apr 5, 2021
1 parent 70c4af2 commit 2dcf027
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 18 deletions.
26 changes: 18 additions & 8 deletions libs/render/ArbitraryMeshVertex.h
Expand Up @@ -29,14 +29,24 @@ class ArbitraryMeshVertex
colour(1.0, 1.0, 1.0)
{}

/// Initialising constructor.
ArbitraryMeshVertex(const Vertex3f& v, const Normal3f& n, const TexCoord2f& t)
: texcoord(t),
normal(n),
vertex(v),
tangent(0, 0, 0),
bitangent(0, 0, 0),
colour(1.0, 1.0, 1.0)
/// Initialising constructor, leaves colour at 1,1,1 and tangent vectors at 0,0,0
ArbitraryMeshVertex(const Vertex3f& v, const Normal3f& n, const TexCoord2f& t) :
texcoord(t),
normal(n),
vertex(v),
tangent(0, 0, 0),
bitangent(0, 0, 0),
colour(1.0, 1.0, 1.0)
{}

/// Initialising constructor, leaves tangent vectors at 0,0,0
ArbitraryMeshVertex(const Vertex3f& v, const Normal3f& n, const TexCoord2f& t, const Vector3& c) :
texcoord(t),
normal(n),
vertex(v),
tangent(0, 0, 0),
bitangent(0, 0, 0),
colour(c)
{}

/// Cast to simple Vertex3f, throwing away other components
Expand Down
15 changes: 5 additions & 10 deletions radiantcore/model/import/AseModel.cpp
Expand Up @@ -70,6 +70,7 @@ AseModel::Material::Material() :
void AseModel::finishSurface(Mesh& mesh, std::size_t materialIndex, const Matrix4& nodeMatrix)
{
assert(mesh.vertices.size() == mesh.normals.size());
static Vector3 White(1, 1, 1);

if (materialIndex >= _materials.size())
{
Expand Down Expand Up @@ -112,23 +113,17 @@ void AseModel::finishSurface(Mesh& mesh, std::size_t materialIndex, const Matrix
v = 0;
}

const auto& colour = !mesh.colours.empty() ? mesh.colours[face.colourIndices[j]] : White;

auto& meshVertex = surface.vertices.emplace_back(ArbitraryMeshVertex
{
vertex,
nodeMatrix.transformDirection(normal).getNormalised(),
TexCoord2f(u * materialCos + v * materialSin, u * -materialSin + v * materialCos)
TexCoord2f(u * materialCos + v * materialSin, u * -materialSin + v * materialCos),
colour
});

surface.indices.emplace_back(nextIndex++);

if (!mesh.colours.empty())
{
meshVertex.colour = mesh.colours[face.colourIndices[j]];
}
else
{
meshVertex.colour.set(1, 1, 1);
}
}
}
}
Expand Down

0 comments on commit 2dcf027

Please sign in to comment.