From 516debdcb2592a659d7486e212ebfd93fe38cc8b Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Wed, 13 Nov 2019 12:50:13 -0800 Subject: [PATCH] Fix code style / remove cruft --- libraries/animation/src/AnimSkeleton.cpp | 8 +- libraries/animation/src/AnimSkeleton.h | 2 +- libraries/baking/src/MaterialBaker.cpp | 2 +- .../src/RenderableModelEntityItem.cpp | 16 +--- libraries/fbx/src/FBXSerializer.cpp | 4 +- libraries/fbx/src/OBJSerializer.cpp | 10 +-- libraries/render-utils/src/Model.cpp | 15 ++-- .../render-utils/src/SoftAttachmentModel.cpp | 3 +- tests-manual/fbx/CMakeLists.txt | 11 --- tests-manual/fbx/src/main.cpp | 77 ------------------- 10 files changed, 23 insertions(+), 125 deletions(-) delete mode 100644 tests-manual/fbx/CMakeLists.txt delete mode 100644 tests-manual/fbx/src/main.cpp diff --git a/libraries/animation/src/AnimSkeleton.cpp b/libraries/animation/src/AnimSkeleton.cpp index b60fc42f89..e5f05ab45f 100644 --- a/libraries/animation/src/AnimSkeleton.cpp +++ b/libraries/animation/src/AnimSkeleton.cpp @@ -24,13 +24,13 @@ AnimSkeleton::AnimSkeleton(const HFMModel& hfmModel) { // we make a copy of the inverseBindMatrices in order to prevent mutating the model bind pose // when we are dealing with a joint offset in the model - for (int i = 0; i < (int)hfmModel.skinDeformers.size(); i++) { - const auto& defor = hfmModel.skinDeformers[i]; + for (uint32_t i = 0; i < (uint32_t)hfmModel.skinDeformers.size(); i++) { + const auto& deformer = hfmModel.skinDeformers[i]; std::vector dummyClustersList; - for (uint32_t j = 0; j < (uint32_t)defor.clusters.size(); j++) { + for (uint32_t j = 0; j < (uint32_t)deformer.clusters.size(); j++) { // cast into a non-const reference, so we can mutate the FBXCluster - HFMCluster& cluster = const_cast(defor.clusters.at(j)); + HFMCluster& cluster = const_cast(deformer.clusters.at(j)); HFMCluster localCluster; localCluster.jointIndex = cluster.jointIndex; diff --git a/libraries/animation/src/AnimSkeleton.h b/libraries/animation/src/AnimSkeleton.h index 1477efb223..a6470ac609 100644 --- a/libraries/animation/src/AnimSkeleton.h +++ b/libraries/animation/src/AnimSkeleton.h @@ -68,7 +68,7 @@ public: void dump(const AnimPoseVec& poses) const; std::vector lookUpJointIndices(const std::vector& jointNames) const; - const HFMCluster getClusterBindMatricesOriginalValues(const int skinDeformerIndex, const int clusterIndex) const { return _clusterBindMatrixOriginalValues[skinDeformerIndex][clusterIndex]; } + const HFMCluster getClusterBindMatricesOriginalValues(int skinDeformerIndex, int clusterIndex) const { return _clusterBindMatrixOriginalValues[skinDeformerIndex][clusterIndex]; } protected: void buildSkeletonFromJoints(const std::vector& joints, const QMap jointOffsets); diff --git a/libraries/baking/src/MaterialBaker.cpp b/libraries/baking/src/MaterialBaker.cpp index d177ddf358..fbb17f0d01 100644 --- a/libraries/baking/src/MaterialBaker.cpp +++ b/libraries/baking/src/MaterialBaker.cpp @@ -260,7 +260,7 @@ void MaterialBaker::addTexture(const QString& materialName, image::TextureUsage: void MaterialBaker::setMaterials(const std::vector& materials, const QString& baseURL) { _materialResource = NetworkMaterialResourcePointer(new NetworkMaterialResource(), [](NetworkMaterialResource* ptr) { ptr->deleteLater(); }); - for (auto& material : materials) { + for (const auto& material : materials) { _materialResource->parsedMaterials.names.push_back(material.name.toStdString()); _materialResource->parsedMaterials.networkMaterials[material.name.toStdString()] = std::make_shared(material, baseURL); diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 4de092c7fd..1bde9a0fa6 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -403,19 +403,11 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer uint32_t indexStart = (uint32_t)part.x; uint32_t indexEnd = indexStart + numIndices; - for (uint32_t j = indexStart; j < indexEnd; j += TRIANGLE_STRIDE) { + for (uint32_t j = indexStart; j < indexEnd; ++j) { // NOTE: It seems odd to skip vertices when initializing a btConvexHullShape, but let's keep the behavior similar to the old behavior for now - glm::vec3 p0 = triangleListMesh.vertices[triangleListMesh.indices[j]]; - glm::vec3 p1 = triangleListMesh.vertices[triangleListMesh.indices[j + 1]]; - glm::vec3 p2 = triangleListMesh.vertices[triangleListMesh.indices[j + 2]]; - if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p0) == pointsInPart.cend()) { - pointsInPart.push_back(p0); - } - if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p1) == pointsInPart.cend()) { - pointsInPart.push_back(p1); - } - if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), p2) == pointsInPart.cend()) { - pointsInPart.push_back(p2); + glm::vec3 point = triangleListMesh.vertices[triangleListMesh.indices[j]]; + if (std::find(pointsInPart.cbegin(), pointsInPart.cend(), point) == pointsInPart.cend()) { + pointsInPart.push_back(point); } } diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index f09182c0e6..46971b01e5 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1462,7 +1462,7 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const const auto& partMaterialTextures = extracted.partMaterialTextures; uint32_t meshIndex = (uint32_t)hfmModel.meshes.size(); - meshIDsToMeshIndices.insert(it.key(), meshIndex); + meshIDsToMeshIndices.insert(meshID, meshIndex); hfmModel.meshes.push_back(extracted.mesh); hfm::Mesh& mesh = hfmModel.meshes.back(); @@ -1635,8 +1635,8 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const } // Store the model's dynamic transform, and put its ID in the shapes + uint32_t skinDeformerID = (uint32_t)hfmModel.skinDeformers.size(); hfmModel.skinDeformers.push_back(skinDeformer); - uint32_t skinDeformerID = (uint32_t)(hfmModel.skinDeformers.size() - 1); for (hfm::Shape& shape : partShapes) { shape.skinDeformer = skinDeformerID; } diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/fbx/src/OBJSerializer.cpp index 31f92555f1..a998c3442d 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -701,9 +701,9 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V QMap materialMeshIdMap; std::vector hfmMeshParts; - for (uint32_t i = 0, meshPartCount = 0; i < (uint32_t)mesh.parts.size(); i++, meshPartCount++) { - HFMMeshPart& meshPart = mesh.parts[i]; - FaceGroup faceGroup = faceGroups[meshPartCount]; + for (uint32_t meshPartIndex = 0; meshPartIndex < (uint32_t)mesh.parts.size(); ++meshPartIndex) { + HFMMeshPart& meshPart = mesh.parts[meshPartIndex]; + FaceGroup faceGroup = faceGroups[meshPartIndex]; bool specifiesUV = false; foreach(OBJFace face, faceGroup) { // Go through all of the OBJ faces and determine the number of different materials necessary (each different material will be a unique mesh). @@ -758,8 +758,8 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V mesh.parts.clear(); mesh.parts = hfmMeshParts; - for (uint32_t i = 0, meshPartCount = 0; i < unmodifiedMeshPartCount; i++, meshPartCount++) { - FaceGroup faceGroup = faceGroups[meshPartCount]; + for (uint32_t meshPartIndex = 0; meshPartIndex < unmodifiedMeshPartCount; meshPartIndex++) { + FaceGroup faceGroup = faceGroups[meshPartIndex]; // Now that each mesh has been created with its own unique material mappings, fill them with data (vertex data is duplicated, face data is not). foreach(OBJFace face, faceGroup) { diff --git a/libraries/render-utils/src/Model.cpp b/libraries/render-utils/src/Model.cpp index b932e4df60..0e5b032b07 100644 --- a/libraries/render-utils/src/Model.cpp +++ b/libraries/render-utils/src/Model.cpp @@ -189,7 +189,7 @@ bool Model::shouldInvalidatePayloadShapeKey(int meshIndex) { const auto& networkMeshes = getNetworkModel()->getMeshes(); // if our index is ever out of range for either meshes or networkMeshes, then skip it, and set our _meshGroupsKnown // to false to rebuild out mesh groups. - if (meshIndex < 0 || meshIndex >= (int)networkMeshes.size() || meshIndex >= (int)hfmModel.meshes.size() /* || meshIndex >= (int)_meshStates.size()*/) { + if (meshIndex < 0 || meshIndex >= (int)networkMeshes.size() || meshIndex >= (int)hfmModel.meshes.size()) { _needsFixupInScene = true; // trigger remove/add cycle invalidCalculatedMeshBoxes(); // if we have to reload, we need to assume our mesh boxes are all invalid return true; @@ -252,9 +252,6 @@ void Model::updateRenderItems() { } Transform renderTransform = modelTransform; - // if (meshState.clusterMatrices.size() <= 1) { - // renderTransform = modelTransform.worldTransform(shapeState._rootFromJointTransform); - // } data.updateTransform(renderTransform); data.updateTransformAndBound(modelTransform.worldTransform(shapeState._rootFromJointTransform)); @@ -299,12 +296,10 @@ void Model::reset() { } void Model::updateShapeStatesFromRig() { - { // Shapes state: - for (auto& shape : _shapeStates) { - uint32_t jointId = shape._jointIndex; - if (jointId < (uint32_t) _rig.getJointStateCount()) { - shape._rootFromJointTransform = _rig.getJointTransform(jointId); - } + for (auto& shape : _shapeStates) { + uint32_t jointId = shape._jointIndex; + if (jointId < (uint32_t) _rig.getJointStateCount()) { + shape._rootFromJointTransform = _rig.getJointTransform(jointId); } } } diff --git a/libraries/render-utils/src/SoftAttachmentModel.cpp b/libraries/render-utils/src/SoftAttachmentModel.cpp index 1b8d1e7b69..7a58498e50 100644 --- a/libraries/render-utils/src/SoftAttachmentModel.cpp +++ b/libraries/render-utils/src/SoftAttachmentModel.cpp @@ -61,8 +61,7 @@ void SoftAttachmentModel::updateClusterMatrices() { Transform clusterTransform; Transform::mult(clusterTransform, jointTransform, cbmov.inverseBindTransform); state.clusterDualQuaternions[clusterIndex] = Model::TransformDualQuaternion(clusterTransform); - } - else { + } else { auto jointMatrix = rig->getJointTransform(cbmov.jointIndex); glm_mat4u_mul(jointMatrix, cbmov.inverseBindMatrix, state.clusterMatrices[clusterIndex]); } diff --git a/tests-manual/fbx/CMakeLists.txt b/tests-manual/fbx/CMakeLists.txt deleted file mode 100644 index 7221f081fe..0000000000 --- a/tests-manual/fbx/CMakeLists.txt +++ /dev/null @@ -1,11 +0,0 @@ -set(TARGET_NAME fbx-test) -# This is not a testcase -- just set it up as a regular hifi project -setup_hifi_project(Quick Gui) -setup_memory_debugger() -set_target_properties(${TARGET_NAME} PROPERTIES FOLDER "Tests/manual-tests/") - -file(GLOB_RECURSE GLB_TEST_FILES "c:/Users/bdavi/git/glTF-Sample-Models/2.0/*.glb") -list(JOIN GLB_TEST_FILES "|" GLB_TEST_FILES) -target_compile_definitions(${TARGET_NAME} PRIVATE -DGLB_TEST_FILES="${GLB_TEST_FILES}") -link_hifi_libraries(shared graphics networking image gpu hfm fbx) -package_libraries_for_deployment() diff --git a/tests-manual/fbx/src/main.cpp b/tests-manual/fbx/src/main.cpp deleted file mode 100644 index 66c3a4f30e..0000000000 --- a/tests-manual/fbx/src/main.cpp +++ /dev/null @@ -1,77 +0,0 @@ -// -// Created by Bradley Austin Davis on 2018/01/11 -// Copyright 2014 High Fidelity, Inc. -// -// Distributed under the Apache License, Version 2.0. -// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html -// - -#include -#include - -#include - -#include -#include -#include -#include - -#include - -// Currently only used by testing code -inline std::list splitString(const std::string& source, const char delimiter = ' ') { - std::list result; - size_t start = 0, next; - - while (std::string::npos != (next = source.find(delimiter, start))) { - std::string sub = source.substr(start, next - start); - if (!sub.empty()) { - result.push_back(sub); - } - start = next + 1; - } - if (source.size() > start) { - result.push_back(source.substr(start)); - } - return result; -} - -std::list getGlbTestFiles() { - return splitString(GLB_TEST_FILES, '|'); -} - -QtMessageHandler originalHandler; - -void messageHandler(QtMsgType type, const QMessageLogContext& context, const QString& message) { -#if defined(Q_OS_WIN) - OutputDebugStringA(message.toStdString().c_str()); - OutputDebugStringA("\n"); -#endif - originalHandler(type, context, message); -} - -QByteArray readFileBytes(const std::string& filename) { - QFile file(filename.c_str()); - file.open(QFile::ReadOnly); - QByteArray result = file.readAll(); - file.close(); - return result; -} - -void processFile(const std::string& filename) { - qDebug() << filename.c_str(); - GLTFSerializer().read(readFileBytes(filename), {}, QUrl::fromLocalFile(filename.c_str())); -} - -int main(int argc, char** argv) { - QCoreApplication app{ argc, argv }; - originalHandler = qInstallMessageHandler(messageHandler); - - DependencyManager::set(false); - - //processFile("c:/Users/bdavi/git/glTF-Sample-Models/2.0/Box/glTF-Binary/Box.glb"); - - for (const auto& testFile : getGlbTestFiles()) { - processFile(testFile); - } -}