mirror of
https://github.com/overte-org/overte.git
synced 2025-04-18 13:56:33 +02:00
address code review comments
This commit is contained in:
parent
bfb4dd0cdb
commit
9cb4e2c5f2
3 changed files with 20 additions and 38 deletions
|
@ -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<int>& 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<QString> nodeNamesToDelete {
|
||||
|
|
|
@ -361,11 +361,11 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn
|
|||
|
||||
QHash<QPair<int, int>, 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<float, 3> positionValue;
|
||||
positionAttribute->ConvertValue<float, 3>(mappedIndex, &positionValue[0]);
|
||||
data.extracted.mesh.vertices.push_back({ positionValue[0], positionValue[1], positionValue[2] });
|
||||
positionAttribute->ConvertValue<float, 3>(mappedIndex,
|
||||
reinterpret_cast<float*>(&data.extracted.mesh.vertices[i]));
|
||||
}
|
||||
|
||||
if (normalAttribute) {
|
||||
// read normals from draco mesh to extracted mesh
|
||||
auto mappedIndex = normalAttribute->mapped_index(vertexIndex);
|
||||
|
||||
std::array<float, 3> normalValue;
|
||||
normalAttribute->ConvertValue<float, 3>(mappedIndex, &normalValue[0]);
|
||||
data.extracted.mesh.normals.push_back({ normalValue[0], normalValue[1], normalValue[2] });
|
||||
normalAttribute->ConvertValue<float, 3>(mappedIndex,
|
||||
reinterpret_cast<float*>(&data.extracted.mesh.normals[i]));
|
||||
}
|
||||
|
||||
if (texCoordAttribute) {
|
||||
// read UVs from draco mesh to extracted mesh
|
||||
auto mappedIndex = texCoordAttribute->mapped_index(vertexIndex);
|
||||
|
||||
std::array<float, 2> texCoordValue;
|
||||
texCoordAttribute->ConvertValue<float, 2>(mappedIndex, &texCoordValue[0]);
|
||||
data.extracted.mesh.texCoords.push_back({ texCoordValue[0], texCoordValue[1] });
|
||||
texCoordAttribute->ConvertValue<float, 2>(mappedIndex,
|
||||
reinterpret_cast<float*>(&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<float, 2> texCoordValue;
|
||||
extraTexCoordAttribute->ConvertValue<float, 2>(mappedIndex, &texCoordValue[0]);
|
||||
data.extracted.mesh.texCoords1.push_back({ texCoordValue[0], texCoordValue[1] });
|
||||
extraTexCoordAttribute->ConvertValue<float, 2>(mappedIndex,
|
||||
reinterpret_cast<float*>(&data.extracted.mesh.texCoords1[i]));
|
||||
}
|
||||
|
||||
if (colorAttribute) {
|
||||
// read vertex colors from draco mesh to extracted mesh
|
||||
auto mappedIndex = colorAttribute->mapped_index(vertexIndex);
|
||||
|
||||
std::array<float, 3> colorValue;
|
||||
|
||||
colorAttribute->ConvertValue<float, 3>(mappedIndex, &colorValue[0]);
|
||||
data.extracted.mesh.colors.push_back({ colorValue[0], colorValue[1], colorValue[2] });
|
||||
colorAttribute->ConvertValue<float, 3>(mappedIndex,
|
||||
reinterpret_cast<float*>(&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 };
|
||||
|
||||
|
|
|
@ -19,9 +19,8 @@ void writeVector(QDataStream& out, char ch, QVector<T> list) {
|
|||
out << (int32_t)list.length();
|
||||
out << (int32_t)0;
|
||||
out << (int32_t)0;
|
||||
for (auto& value : list) {
|
||||
out << value;
|
||||
}
|
||||
|
||||
out.writeBytes(reinterpret_cast<const char*>(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;
|
||||
|
||||
|
|
Loading…
Reference in a new issue