diff --git a/radiantcore/model/export/Lwo2Exporter.cpp b/radiantcore/model/export/Lwo2Exporter.cpp index 2f47efd7d2..3992ea28e4 100644 --- a/radiantcore/model/export/Lwo2Exporter.cpp +++ b/radiantcore/model/export/Lwo2Exporter.cpp @@ -137,18 +137,28 @@ void Lwo2Exporter::exportToStream(std::ostream& stream) Lwo2Chunk::Ptr pols = fileChunk.addChunk("POLS"); Lwo2Chunk::Ptr ptag = fileChunk.addChunk("PTAG"); Lwo2Chunk::Ptr vmap = fileChunk.addChunk("VMAP"); + Lwo2Chunk::Ptr colourVmap = fileChunk.addChunk("VMAP"); // We only ever export FACE polygons pols->stream.write("FACE", 4); ptag->stream.write("SURF", 4); // we tag the surfaces + // Texture UV Coordinates go into one VMAP // VMAP { type[ID4], dimension[U2], name[S0], ...) } vmap->stream.write("TXUV", 4); // "TXUV" - stream::writeBigEndian(vmap->stream, 2); // dimension + stream::writeBigEndian(vmap->stream, 2); // dimension (2 vector components) std::string uvmapName = "UVMap"; stream::writeString(vmap->stream, uvmapName); + // Vertex Colours go into another VMAP + // VMAP { type[ID4], dimension[U2], name[S0], ...) } + colourVmap->stream.write("RGBA", 4); // type [ID4] == "RGBA" + stream::writeBigEndian(colourVmap->stream, 4); // dimension (4 colour components) + + std::string vertColourMapName = "VertexColourMap"; + stream::writeString(colourVmap->stream, vertColourMapName); // map name [S0] + std::size_t vertexIdxStart = 0; std::size_t polyNum = 0; // poly index is used across all surfaces @@ -175,6 +185,13 @@ void Lwo2Exporter::exportToStream(std::ostream& stream) stream::writeBigEndian(vmap->stream, static_cast(vertex.texcoord.x())); stream::writeBigEndian(vmap->stream, 1.0f - static_cast(vertex.texcoord.y())); + // Write the vertex colour data + stream::writeVariableIndex(colourVmap->stream, vertNum); + stream::writeBigEndian(colourVmap->stream, static_cast(vertex.colour.x())); + stream::writeBigEndian(colourVmap->stream, static_cast(vertex.colour.y())); + stream::writeBigEndian(colourVmap->stream, static_cast(vertex.colour.z())); + stream::writeBigEndian(colourVmap->stream, 1.0f); + // Accumulate the BBOX bounds.includePoint(vertex.vertex); } @@ -215,6 +232,13 @@ void Lwo2Exporter::exportToStream(std::ostream& stream) stream::writeBigEndian(colr->stream, 1.0f); stream::writeVariableIndex(colr->stream, 0); + // Reference the name of the vertex colour map + Lwo2Chunk::Ptr vcol = surf->addSubChunk("VCOL"); + stream::writeBigEndian(vcol->stream, 1.0f); // intensity [F4] + stream::writeVariableIndex(vcol->stream, 0); // [VX] + vcol->stream.write("RGBA", 4); // vmap-type [ID4] + stream::writeString(vcol->stream, vertColourMapName); // name [S0] + // Smoothing angle Lwo2Chunk::Ptr sman = surf->addSubChunk("SMAN"); stream::writeBigEndian(sman->stream, static_cast(degrees_to_radians(95.0f))); // 95 degrees smoothing angle diff --git a/radiantcore/model/export/ModelExporterBase.h b/radiantcore/model/export/ModelExporterBase.h index f6c2b81475..1a446179fa 100644 --- a/radiantcore/model/export/ModelExporterBase.h +++ b/radiantcore/model/export/ModelExporterBase.h @@ -65,12 +65,13 @@ class ModelExporterBase : for (const auto& meshVertex : vertices) { // Copy-construct based on the incoming meshVertex, transform the vertex. - // Transform the normal using the inverse transpose - // We discard the tangent and bitangent vectors here, none of the exporters is using them. - surface.vertices.emplace_back( - localToWorld.transformPoint(meshVertex.vertex), - invTranspTransform.transformPoint(meshVertex.normal).getNormalised(), - meshVertex.texcoord); + // Transform the normal using the inverse transpose + // We discard the tangent and bitangent vectors here, none of the exporters is using them. + surface.vertices.emplace_back( + localToWorld.transformPoint(meshVertex.vertex), + invTranspTransform.transformPoint(meshVertex.normal).getNormalised(), + meshVertex.texcoord, + meshVertex.colour); } surface.indices.reserve(surface.indices.size() + indices.size());