From 9cb4e2c5f2ba61b409f5ae7efa2e32dd8daab4b5 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Thu, 14 Sep 2017 13:54:04 -0700 Subject: [PATCH] address code review comments --- libraries/baking/src/FBXBaker.cpp | 14 ++-------- libraries/fbx/src/FBXReader_Mesh.cpp | 38 ++++++++++++---------------- libraries/fbx/src/FBXWriter.cpp | 6 ++--- 3 files changed, 20 insertions(+), 38 deletions(-) diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index 5abb3feb0d..791d89e503 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -299,7 +299,7 @@ void FBXBaker::rewriteAndBakeSceneModels() { // TODO Pull this out of _geometry instead so we don't have to reprocess it auto extractedMesh = FBXReader::extractMesh(objectChild, meshIndex); - auto mesh = extractedMesh.mesh; + auto& mesh = extractedMesh.mesh; Q_ASSERT(mesh.normals.size() == 0 || mesh.normals.size() == mesh.vertices.size()); Q_ASSERT(mesh.colors.size() == 0 || mesh.colors.size() == mesh.vertices.size()); @@ -366,7 +366,7 @@ void FBXBaker::rewriteAndBakeSceneModels() { auto partIndex = 0; draco::FaceIndex face; for (auto& part : mesh.parts) { - const auto matTex = extractedMesh.partMaterialTextures[partIndex]; + const auto& matTex = extractedMesh.partMaterialTextures[partIndex]; auto addFace = [&](QVector& indices, int index, draco::FaceIndex face) { auto idx0 = indices[index]; @@ -447,16 +447,6 @@ void FBXBaker::rewriteAndBakeSceneModels() { auto value = QVariant::fromValue(QByteArray(buffer.data(), (int) buffer.size())); dracoMeshNode.properties.append(value); - - QFile file("C:/Users/huffm/encodedFBX/" + this->_fbxURL.fileName() + "-" + QString::number(meshIndex) + ".drc"); - if (file.open(QIODevice::WriteOnly)) { - file.write(buffer.data(), buffer.size()); - file.close(); - } else { - qWarning() << "Failed to write to: " << file.fileName(); - - } - objectChild.children.push_back(dracoMeshNode); static const std::vector nodeNamesToDelete { diff --git a/libraries/fbx/src/FBXReader_Mesh.cpp b/libraries/fbx/src/FBXReader_Mesh.cpp index fd9756b4c0..bb35447adb 100644 --- a/libraries/fbx/src/FBXReader_Mesh.cpp +++ b/libraries/fbx/src/FBXReader_Mesh.cpp @@ -361,11 +361,11 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn QHash, int> materialTextureParts; - data.extracted.mesh.vertices.reserve(numVertices); - data.extracted.mesh.normals.reserve(numVertices); - data.extracted.mesh.texCoords.reserve(numVertices); - data.extracted.mesh.texCoords1.reserve(numVertices); - data.extracted.mesh.colors.reserve(numVertices); + data.extracted.mesh.vertices.resize(numVertices); + data.extracted.mesh.normals.resize(numVertices); + data.extracted.mesh.texCoords.resize(numVertices); + data.extracted.mesh.texCoords1.resize(numVertices); + data.extracted.mesh.colors.resize(numVertices); // enumerate the vertices and construct the extracted mesh for (int i = 0; i < numVertices; ++i) { @@ -375,46 +375,40 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn // read position from draco mesh to extracted mesh auto mappedIndex = positionAttribute->mapped_index(vertexIndex); - std::array positionValue; - positionAttribute->ConvertValue(mappedIndex, &positionValue[0]); - data.extracted.mesh.vertices.push_back({ positionValue[0], positionValue[1], positionValue[2] }); + positionAttribute->ConvertValue(mappedIndex, + reinterpret_cast(&data.extracted.mesh.vertices[i])); } if (normalAttribute) { // read normals from draco mesh to extracted mesh auto mappedIndex = normalAttribute->mapped_index(vertexIndex); - std::array normalValue; - normalAttribute->ConvertValue(mappedIndex, &normalValue[0]); - data.extracted.mesh.normals.push_back({ normalValue[0], normalValue[1], normalValue[2] }); + normalAttribute->ConvertValue(mappedIndex, + reinterpret_cast(&data.extracted.mesh.normals[i])); } if (texCoordAttribute) { // read UVs from draco mesh to extracted mesh auto mappedIndex = texCoordAttribute->mapped_index(vertexIndex); - std::array texCoordValue; - texCoordAttribute->ConvertValue(mappedIndex, &texCoordValue[0]); - data.extracted.mesh.texCoords.push_back({ texCoordValue[0], texCoordValue[1] }); + texCoordAttribute->ConvertValue(mappedIndex, + reinterpret_cast(&data.extracted.mesh.texCoords[i])); } if (extraTexCoordAttribute) { // some meshes have a second set of UVs, read those to extracted mesh auto mappedIndex = extraTexCoordAttribute->mapped_index(vertexIndex); - std::array texCoordValue; - extraTexCoordAttribute->ConvertValue(mappedIndex, &texCoordValue[0]); - data.extracted.mesh.texCoords1.push_back({ texCoordValue[0], texCoordValue[1] }); + extraTexCoordAttribute->ConvertValue(mappedIndex, + reinterpret_cast(&data.extracted.mesh.texCoords1[i])); } if (colorAttribute) { // read vertex colors from draco mesh to extracted mesh auto mappedIndex = colorAttribute->mapped_index(vertexIndex); - std::array colorValue; - - colorAttribute->ConvertValue(mappedIndex, &colorValue[0]); - data.extracted.mesh.colors.push_back({ colorValue[0], colorValue[1], colorValue[2] }); + colorAttribute->ConvertValue(mappedIndex, + reinterpret_cast(&data.extracted.mesh.colors[i])); } data.extracted.newIndices.insert(i, i); @@ -422,7 +416,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn for (int i = 0; i < dracoMesh->num_faces(); ++i) { // grab the material ID and texture ID for this face, if we have it - auto firstCorner = dracoMesh->face(draco::FaceIndex(i))[0]; + auto& firstCorner = dracoMesh->face(draco::FaceIndex(i))[0]; uint16_t materialID { 0 }; diff --git a/libraries/fbx/src/FBXWriter.cpp b/libraries/fbx/src/FBXWriter.cpp index cc34696f92..7195d2abb4 100644 --- a/libraries/fbx/src/FBXWriter.cpp +++ b/libraries/fbx/src/FBXWriter.cpp @@ -19,9 +19,8 @@ void writeVector(QDataStream& out, char ch, QVector list) { out << (int32_t)list.length(); out << (int32_t)0; out << (int32_t)0; - for (auto& value : list) { - out << value; - } + + out.writeBytes(reinterpret_cast(list.constData()), list.length() * sizeof(T)); } @@ -98,7 +97,6 @@ void FBXWriter::encodeFBXProperty(QDataStream& out, const QVariant& prop) { case QVariant::Type::Bool: out.device()->write("C", 1); - //out.device()->write(prop.toBool() ? 1 : 0, 1); out << prop.toBool(); break;