From 83cc90ace07f4b48132371b7806b8e35bca342e0 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 5 Nov 2018 16:40:10 -0800 Subject: [PATCH 01/11] Re-name GLTFReader to GLTFSerializer and do the same for other model readers --- interface/src/ModelPropertiesDialog.h | 2 +- interface/src/raypick/CollisionPick.cpp | 6 +- libraries/animation/src/AnimSkeleton.h | 2 +- libraries/animation/src/AnimationCache.h | 2 +- libraries/animation/src/AnimationObject.h | 2 +- libraries/baking/src/FBXBaker.cpp | 12 +-- libraries/baking/src/ModelBaker.cpp | 2 +- libraries/baking/src/OBJBaker.cpp | 10 +- .../src/RenderableModelEntityItem.cpp | 8 +- libraries/fbx/src/FBX.h | 2 +- .../src/{FBXReader.cpp => FBXSerializer.cpp} | 44 ++++----- .../fbx/src/{FBXReader.h => FBXSerializer.h} | 10 +- ...aterial.cpp => FBXSerializer_Material.cpp} | 8 +- ...Reader_Mesh.cpp => FBXSerializer_Mesh.cpp} | 16 +-- ...Reader_Node.cpp => FBXSerializer_Node.cpp} | 24 ++--- .../{GLTFReader.cpp => GLTFSerializer.cpp} | 98 +++++++++---------- .../src/{GLTFReader.h => GLTFSerializer.h} | 14 +-- .../src/{OBJReader.cpp => OBJSerializer.cpp} | 68 ++++++------- .../fbx/src/{OBJReader.h => OBJSerializer.h} | 4 +- .../src/model-networking/ModelCache.cpp | 12 +-- .../src/model-networking/ModelCache.h | 2 +- tests-manual/gpu/src/TestFbx.cpp | 2 +- tools/skeleton-dump/src/SkeletonDumpApp.cpp | 2 +- tools/vhacd-util/src/VHACDUtil.cpp | 4 +- tools/vhacd-util/src/VHACDUtil.h | 4 +- tools/vhacd-util/src/VHACDUtilApp.h | 2 +- 26 files changed, 181 insertions(+), 181 deletions(-) rename libraries/fbx/src/{FBXReader.cpp => FBXSerializer.cpp} (98%) rename libraries/fbx/src/{FBXReader.h => FBXSerializer.h} (97%) rename libraries/fbx/src/{FBXReader_Material.cpp => FBXSerializer_Material.cpp} (98%) rename libraries/fbx/src/{FBXReader_Mesh.cpp => FBXSerializer_Mesh.cpp} (98%) rename libraries/fbx/src/{FBXReader_Node.cpp => FBXSerializer_Node.cpp} (94%) rename libraries/fbx/src/{GLTFReader.cpp => GLTFSerializer.cpp} (94%) rename libraries/fbx/src/{GLTFReader.h => GLTFSerializer.h} (99%) rename libraries/fbx/src/{OBJReader.cpp => OBJSerializer.cpp} (92%) rename libraries/fbx/src/{OBJReader.h => OBJSerializer.h} (97%) diff --git a/interface/src/ModelPropertiesDialog.h b/interface/src/ModelPropertiesDialog.h index 0bf8075197..7068d5cb76 100644 --- a/interface/src/ModelPropertiesDialog.h +++ b/interface/src/ModelPropertiesDialog.h @@ -14,7 +14,7 @@ #include -#include +#include #include #include "ui/ModelsBrowser.h" diff --git a/interface/src/raypick/CollisionPick.cpp b/interface/src/raypick/CollisionPick.cpp index 2b75946e28..ff453d99a5 100644 --- a/interface/src/raypick/CollisionPick.cpp +++ b/interface/src/raypick/CollisionPick.cpp @@ -149,7 +149,7 @@ void CollisionPick::computeShapeInfo(const CollisionRegion& pick, ShapeInfo& sha uint32_t numIndices = (uint32_t)meshPart.triangleIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += TRIANGLE_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.triangleIndices[j]]; @@ -170,7 +170,7 @@ void CollisionPick::computeShapeInfo(const CollisionRegion& pick, ShapeInfo& sha numIndices = (uint32_t)meshPart.quadIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % QUAD_STRIDE == 0); - numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += QUAD_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.quadIndices[j]]; @@ -305,7 +305,7 @@ void CollisionPick::computeShapeInfo(const CollisionRegion& pick, ShapeInfo& sha auto numIndices = meshPart.triangleIndices.count(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices% TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer auto indexItr = meshPart.triangleIndices.cbegin(); while (indexItr != meshPart.triangleIndices.cend()) { diff --git a/libraries/animation/src/AnimSkeleton.h b/libraries/animation/src/AnimSkeleton.h index 3a384388d0..d72533cbdb 100644 --- a/libraries/animation/src/AnimSkeleton.h +++ b/libraries/animation/src/AnimSkeleton.h @@ -15,7 +15,7 @@ #include #include -#include +#include #include "AnimPose.h" class AnimSkeleton { diff --git a/libraries/animation/src/AnimationCache.h b/libraries/animation/src/AnimationCache.h index 4423e8f18d..d4574d9d3b 100644 --- a/libraries/animation/src/AnimationCache.h +++ b/libraries/animation/src/AnimationCache.h @@ -17,7 +17,7 @@ #include #include -#include +#include #include class Animation; diff --git a/libraries/animation/src/AnimationObject.h b/libraries/animation/src/AnimationObject.h index 83880ed2ab..fc3a351832 100644 --- a/libraries/animation/src/AnimationObject.h +++ b/libraries/animation/src/AnimationObject.h @@ -15,7 +15,7 @@ #include #include -#include +#include class QScriptEngine; diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index cef6c9b900..6349b06c49 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -27,7 +27,7 @@ #include -#include +#include #include #include "ModelBakingLoggingCategory.h" @@ -187,10 +187,10 @@ void FBXBaker::importScene() { return; } - FBXReader reader; + FBXSerializer serializer; qCDebug(model_baking) << "Parsing" << _modelURL; - _rootNode = reader._rootNode = reader.parseFBX(&fbxFile); + _rootNode = serializer._rootNode = serializer.parseFBX(&fbxFile); #ifdef HIFI_DUMP_FBX { @@ -206,8 +206,8 @@ void FBXBaker::importScene() { } #endif - _hfmModel = reader.extractHFMModel({}, _modelURL.toString()); - _textureContentMap = reader._textureContent; + _hfmModel = serializer.extractHFMModel({}, _modelURL.toString()); + _textureContentMap = serializer._textureContent; } void FBXBaker::rewriteAndBakeSceneModels() { @@ -232,7 +232,7 @@ void FBXBaker::rewriteAndBakeSceneModels() { if (objectChild.name == "Geometry") { // TODO Pull this out of _hfmModel instead so we don't have to reprocess it - auto extractedMesh = FBXReader::extractMesh(objectChild, meshIndex, false); + auto extractedMesh = FBXSerializer::extractMesh(objectChild, meshIndex, false); // Callback to get MaterialID GetMaterialIDCallback materialIDcallback = [&extractedMesh](int partIndex) { diff --git a/libraries/baking/src/ModelBaker.cpp b/libraries/baking/src/ModelBaker.cpp index ca352cebae..646f1bc010 100644 --- a/libraries/baking/src/ModelBaker.cpp +++ b/libraries/baking/src/ModelBaker.cpp @@ -13,7 +13,7 @@ #include -#include +#include #include #ifdef _WIN32 diff --git a/libraries/baking/src/OBJBaker.cpp b/libraries/baking/src/OBJBaker.cpp index d9f56b393e..389e708c12 100644 --- a/libraries/baking/src/OBJBaker.cpp +++ b/libraries/baking/src/OBJBaker.cpp @@ -14,7 +14,7 @@ #include #include -#include "OBJReader.h" +#include "OBJSerializer.h" #include "FBXWriter.h" const double UNIT_SCALE_FACTOR = 100.0; @@ -143,9 +143,9 @@ void OBJBaker::bakeOBJ() { QByteArray objData = objFile.readAll(); - bool combineParts = true; // set true so that OBJReader reads material info from material library - OBJReader reader; - auto geometry = reader.readOBJ(objData, QVariantHash(), combineParts, _modelURL); + bool combineParts = true; // set true so that OBJSerializer reads material info from material library + OBJSerializer serializer; + auto geometry = serializer.readOBJ(objData, QVariantHash(), combineParts, _modelURL); // Write OBJ Data as FBX tree nodes createFBXNodeTree(_rootNode, *geometry); @@ -219,7 +219,7 @@ void OBJBaker::createFBXNodeTree(FBXNode& rootNode, HFMModel& hfmModel) { FBXNode materialNode; materialNode.name = MATERIAL_NODE_NAME; if (hfmModel.materials.size() == 1) { - // case when no material information is provided, OBJReader considers it as a single default material + // case when no material information is provided, OBJSerializer considers it as a single default material for (auto& materialID : hfmModel.materials.keys()) { setMaterialNodeProperties(materialNode, materialID, hfmModel); } diff --git a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp index 9a68f81b66..2b1d70f4d0 100644 --- a/libraries/entities-renderer/src/RenderableModelEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableModelEntityItem.cpp @@ -421,7 +421,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { uint32_t numIndices = (uint32_t)meshPart.triangleIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += TRIANGLE_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.triangleIndices[j]]; @@ -442,7 +442,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { numIndices = (uint32_t)meshPart.quadIndices.size(); // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % QUAD_STRIDE == 0); - numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % QUAD_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer for (uint32_t j = 0; j < numIndices; j += QUAD_STRIDE) { glm::vec3 p0 = mesh.vertices[meshPart.quadIndices[j]]; @@ -595,7 +595,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { if (partItr->_topology == graphics::Mesh::TRIANGLES) { // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices % TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer auto indexItr = indices.cbegin() + partItr->_startIndex; auto indexEnd = indexItr + numIndices; @@ -652,7 +652,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& shapeInfo) { if (partItr->_topology == graphics::Mesh::TRIANGLES) { // TODO: assert rather than workaround after we start sanitizing HFMMesh higher up //assert(numIndices% TRIANGLE_STRIDE == 0); - numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXReader + numIndices -= numIndices % TRIANGLE_STRIDE; // WORKAROUND lack of sanity checking in FBXSerializer auto indexItr = indices.cbegin() + partItr->_startIndex; auto indexEnd = indexItr + numIndices; diff --git a/libraries/fbx/src/FBX.h b/libraries/fbx/src/FBX.h index 90de82e310..157ca5b282 100644 --- a/libraries/fbx/src/FBX.h +++ b/libraries/fbx/src/FBX.h @@ -33,7 +33,7 @@ using NormalType = glm::vec3; #define FBX_NORMAL_ELEMENT gpu::Element::VEC3F_XYZ #endif -// See comment in FBXReader::parseFBX(). +// See comment in FBXSerializer::parseFBX(). static const int FBX_HEADER_BYTES_BEFORE_VERSION = 23; static const QByteArray FBX_BINARY_PROLOG("Kaydara FBX Binary "); static const QByteArray FBX_BINARY_PROLOG2("\0\x1a\0", 3); diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXSerializer.cpp similarity index 98% rename from libraries/fbx/src/FBXReader.cpp rename to libraries/fbx/src/FBXSerializer.cpp index cea3d079bc..fb7d95cf37 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1,5 +1,5 @@ // -// FBXReader.cpp +// FBXSerializer.cpp // interface/src/renderer // // Created by Andrzej Kapolka on 9/18/13. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -36,7 +36,7 @@ #include // TOOL: Uncomment the following line to enable the filtering of all the unkwnon fields of a node so we can break point easily while loading a model with problems... -//#define DEBUG_FBXREADER +//#define DEBUG_FBXSERIALIZER using namespace std; @@ -254,13 +254,13 @@ HFMBlendshape extractBlendshape(const FBXNode& object) { HFMBlendshape blendshape; foreach (const FBXNode& data, object.children) { if (data.name == "Indexes") { - blendshape.indices = FBXReader::getIntVector(data); + blendshape.indices = FBXSerializer::getIntVector(data); } else if (data.name == "Vertices") { - blendshape.vertices = FBXReader::createVec3Vector(FBXReader::getDoubleVector(data)); + blendshape.vertices = FBXSerializer::createVec3Vector(FBXSerializer::getDoubleVector(data)); } else if (data.name == "Normals") { - blendshape.normals = FBXReader::createVec3Vector(FBXReader::getDoubleVector(data)); + blendshape.normals = FBXSerializer::createVec3Vector(FBXSerializer::getDoubleVector(data)); } } return blendshape; @@ -384,7 +384,7 @@ HFMLight extractLight(const FBXNode& object) { if (propname == "Intensity") { light.intensity = 0.01f * property.properties.at(valIndex).value(); } else if (propname == "Color") { - light.color = FBXReader::getVec3(property.properties, valIndex); + light.color = FBXSerializer::getVec3(property.properties, valIndex); } } } @@ -392,7 +392,7 @@ HFMLight extractLight(const FBXNode& object) { || subobject.name == "TypeFlags") { } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) QString type = object.properties.at(0).toString(); type = object.properties.at(1).toString(); @@ -417,7 +417,7 @@ QByteArray fileOnUrl(const QByteArray& filepath, const QString& url) { return filepath.mid(filepath.lastIndexOf('/') + 1); } -HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& url) { +HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QString& url) { const FBXNode& node = _rootNode; QMap meshes; QHash modelIDsToNames; @@ -488,7 +488,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } QMultiHash blendshapeChannelIndices; -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) int unknown = 0; #endif HFMModel* hfmModelPtr = new HFMModel; @@ -736,7 +736,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& extractBlendshape(subobject) }; blendshapes.append(blendshape); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else if (subobject.name == "TypeFlags") { QString attributetype = subobject.properties.at(0).toString(); if (!attributetype.empty()) { @@ -862,7 +862,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& tex.scaling.z = 1.0f; } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString propName = v; unknown++; @@ -871,7 +871,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { if (subobject.name == "Type") { } else if (subobject.name == "Version") { @@ -1044,7 +1044,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString propname = subobject.name.data(); int unknown = 0; @@ -1061,7 +1061,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } else if (object.name == "NodeAttribute") { -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) std::vector properties; foreach(const QVariant& v, object.properties) { properties.push_back(v.toString()); @@ -1124,7 +1124,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& animationCurves.insert(getID(object.properties), curve); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString objectname = object.name.data(); if ( objectname == "Pose" @@ -1215,7 +1215,7 @@ HFMModel* FBXReader::extractHFMModel(const QVariantHash& mapping, const QString& } } } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { QString objectname = child.name.data(); if ( objectname == "Pose" @@ -1803,12 +1803,12 @@ HFMModel* readFBX(const QByteArray& data, const QVariantHash& mapping, const QSt } HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { - FBXReader reader; - reader._rootNode = FBXReader::parseFBX(device); - reader._loadLightmaps = loadLightmaps; - reader._lightmapLevel = lightmapLevel; + FBXSerializer serializer; + serializer._rootNode = FBXSerializer::parseFBX(device); + serializer._loadLightmaps = loadLightmaps; + serializer._lightmapLevel = lightmapLevel; qCDebug(modelformat) << "Reading FBX: " << url; - return reader.extractHFMModel(mapping, url); + return serializer.extractHFMModel(mapping, url); } diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXSerializer.h similarity index 97% rename from libraries/fbx/src/FBXReader.h rename to libraries/fbx/src/FBXSerializer.h index c74b4dc8ac..9809b257e8 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -1,5 +1,5 @@ // -// FBXReader.h +// FBXSerializer.h // interface/src/renderer // // Created by Andrzej Kapolka on 9/18/13. @@ -9,8 +9,8 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#ifndef hifi_FBXReader_h -#define hifi_FBXReader_h +#ifndef hifi_FBXSerializer_h +#define hifi_FBXSerializer_h #include #include @@ -102,7 +102,7 @@ public: class ExtractedMesh; -class FBXReader { +class FBXSerializer { public: HFMModel* _hfmModel; @@ -166,4 +166,4 @@ public: static QVector getDoubleVector(const FBXNode& node); }; -#endif // hifi_FBXReader_h +#endif // hifi_FBXSerializer_h diff --git a/libraries/fbx/src/FBXReader_Material.cpp b/libraries/fbx/src/FBXSerializer_Material.cpp similarity index 98% rename from libraries/fbx/src/FBXReader_Material.cpp rename to libraries/fbx/src/FBXSerializer_Material.cpp index 2ec8cfde75..7713b36e57 100644 --- a/libraries/fbx/src/FBXReader_Material.cpp +++ b/libraries/fbx/src/FBXSerializer_Material.cpp @@ -1,5 +1,5 @@ // -// FBXReader_Material.cpp +// FBXSerializer_Material.cpp // interface/src/fbx // // Created by Sam Gateau on 8/27/2015. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -27,7 +27,7 @@ #include -HFMTexture FBXReader::getTexture(const QString& textureID) { +HFMTexture FBXSerializer::getTexture(const QString& textureID) { HFMTexture texture; const QByteArray& filepath = _textureFilepaths.value(textureID); texture.content = _textureContent.value(filepath); @@ -69,7 +69,7 @@ HFMTexture FBXReader::getTexture(const QString& textureID) { return texture; } -void FBXReader::consolidateHFMMaterials(const QVariantHash& mapping) { +void FBXSerializer::consolidateHFMMaterials(const QVariantHash& mapping) { QString materialMapString = mapping.value("materialMap").toString(); QJsonDocument materialMapDocument = QJsonDocument::fromJson(materialMapString.toUtf8()); diff --git a/libraries/fbx/src/FBXReader_Mesh.cpp b/libraries/fbx/src/FBXSerializer_Mesh.cpp similarity index 98% rename from libraries/fbx/src/FBXReader_Mesh.cpp rename to libraries/fbx/src/FBXSerializer_Mesh.cpp index 527e3aef75..38533dbc42 100644 --- a/libraries/fbx/src/FBXReader_Mesh.cpp +++ b/libraries/fbx/src/FBXSerializer_Mesh.cpp @@ -1,5 +1,5 @@ // -// FBXReader_Mesh.cpp +// FBXSerializer_Mesh.cpp // interface/src/fbx // // Created by Sam Gateau on 8/27/2015. @@ -33,7 +33,7 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" #include @@ -191,7 +191,7 @@ void appendIndex(MeshData& data, QVector& indices, int index, bool deduplic } } -ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIndex, bool deduplicate) { +ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& meshIndex, bool deduplicate) { MeshData data; data.extracted.mesh.meshIndex = meshIndex++; @@ -254,7 +254,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn data.colorsByVertex = true; } -#if defined(FBXREADER_KILL_BLACK_COLOR_ATTRIBUTE) +#if defined(FBXSERIALIZER_KILL_BLACK_COLOR_ATTRIBUTE) // Potential feature where we decide to kill the color attribute is to dark? // Tested with the model: // https://hifi-public.s3.amazonaws.com/ryan/gardenLight2.fbx @@ -281,7 +281,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn } else if (subdata.name == "Name") { attrib.name = subdata.properties.at(0).toString(); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { int unknown = 0; QString subname = subdata.name.data(); @@ -307,7 +307,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn } else if (subdata.name == "Name") { attrib.name = subdata.properties.at(0).toString(); } -#if defined(DEBUG_FBXREADER) +#if defined(DEBUG_FBXSERIALIZER) else { int unknown = 0; QString subname = subdata.name.data(); @@ -557,7 +557,7 @@ ExtractedMesh FBXReader::extractMesh(const FBXNode& object, unsigned int& meshIn return data.extracted; } -glm::vec3 FBXReader::normalizeDirForPacking(const glm::vec3& dir) { +glm::vec3 FBXSerializer::normalizeDirForPacking(const glm::vec3& dir) { auto maxCoord = glm::max(fabsf(dir.x), glm::max(fabsf(dir.y), fabsf(dir.z))); if (maxCoord > 1e-6f) { return dir / maxCoord; @@ -565,7 +565,7 @@ glm::vec3 FBXReader::normalizeDirForPacking(const glm::vec3& dir) { return dir; } -void FBXReader::buildModelMesh(HFMMesh& extractedMesh, const QString& url) { +void FBXSerializer::buildModelMesh(HFMMesh& extractedMesh, const QString& url) { unsigned int totalSourceIndices = 0; foreach(const HFMMeshPart& part, extractedMesh.parts) { totalSourceIndices += (part.quadTrianglesIndices.size() + part.triangleIndices.size()); diff --git a/libraries/fbx/src/FBXReader_Node.cpp b/libraries/fbx/src/FBXSerializer_Node.cpp similarity index 94% rename from libraries/fbx/src/FBXReader_Node.cpp rename to libraries/fbx/src/FBXSerializer_Node.cpp index cd717998dd..c982dfc7cb 100644 --- a/libraries/fbx/src/FBXReader_Node.cpp +++ b/libraries/fbx/src/FBXSerializer_Node.cpp @@ -1,5 +1,5 @@ // -// FBXReader_Node.cpp +// FBXSerializer_Node.cpp // interface/src/fbx // // Created by Sam Gateau on 8/27/2015. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -345,7 +345,7 @@ FBXNode parseTextFBXNode(Tokenizer& tokenizer) { return node; } -FBXNode FBXReader::parseFBX(QIODevice* device) { +FBXNode FBXSerializer::parseFBX(QIODevice* device) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xff0000ff, device); // verify the prolog if (device->peek(FBX_BINARY_PROLOG.size()) != FBX_BINARY_PROLOG) { @@ -398,12 +398,12 @@ FBXNode FBXReader::parseFBX(QIODevice* device) { } -glm::vec3 FBXReader::getVec3(const QVariantList& properties, int index) { +glm::vec3 FBXSerializer::getVec3(const QVariantList& properties, int index) { return glm::vec3(properties.at(index).value(), properties.at(index + 1).value(), properties.at(index + 2).value()); } -QVector FBXReader::createVec4Vector(const QVector& doubleVector) { +QVector FBXSerializer::createVec4Vector(const QVector& doubleVector) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 4) * 4); it != end; ) { float x = *it++; @@ -416,7 +416,7 @@ QVector FBXReader::createVec4Vector(const QVector& doubleVect } -QVector FBXReader::createVec4VectorRGBA(const QVector& doubleVector, glm::vec4& average) { +QVector FBXSerializer::createVec4VectorRGBA(const QVector& doubleVector, glm::vec4& average) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 4) * 4); it != end; ) { float x = *it++; @@ -433,7 +433,7 @@ QVector FBXReader::createVec4VectorRGBA(const QVector& double return values; } -QVector FBXReader::createVec3Vector(const QVector& doubleVector) { +QVector FBXSerializer::createVec3Vector(const QVector& doubleVector) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 3) * 3); it != end; ) { float x = *it++; @@ -444,7 +444,7 @@ QVector FBXReader::createVec3Vector(const QVector& doubleVect return values; } -QVector FBXReader::createVec2Vector(const QVector& doubleVector) { +QVector FBXSerializer::createVec2Vector(const QVector& doubleVector) { QVector values; for (const double* it = doubleVector.constData(), *end = it + ((doubleVector.size() / 2) * 2); it != end; ) { float s = *it++; @@ -454,14 +454,14 @@ QVector FBXReader::createVec2Vector(const QVector& doubleVect return values; } -glm::mat4 FBXReader::createMat4(const QVector& doubleVector) { +glm::mat4 FBXSerializer::createMat4(const QVector& doubleVector) { return glm::mat4(doubleVector.at(0), doubleVector.at(1), doubleVector.at(2), doubleVector.at(3), doubleVector.at(4), doubleVector.at(5), doubleVector.at(6), doubleVector.at(7), doubleVector.at(8), doubleVector.at(9), doubleVector.at(10), doubleVector.at(11), doubleVector.at(12), doubleVector.at(13), doubleVector.at(14), doubleVector.at(15)); } -QVector FBXReader::getIntVector(const FBXNode& node) { +QVector FBXSerializer::getIntVector(const FBXNode& node) { foreach (const FBXNode& child, node.children) { if (child.name == "a") { return getIntVector(child); @@ -480,7 +480,7 @@ QVector FBXReader::getIntVector(const FBXNode& node) { return vector; } -QVector FBXReader::getFloatVector(const FBXNode& node) { +QVector FBXSerializer::getFloatVector(const FBXNode& node) { foreach (const FBXNode& child, node.children) { if (child.name == "a") { return getFloatVector(child); @@ -499,7 +499,7 @@ QVector FBXReader::getFloatVector(const FBXNode& node) { return vector; } -QVector FBXReader::getDoubleVector(const FBXNode& node) { +QVector FBXSerializer::getDoubleVector(const FBXNode& node) { foreach (const FBXNode& child, node.children) { if (child.name == "a") { return getDoubleVector(child); diff --git a/libraries/fbx/src/GLTFReader.cpp b/libraries/fbx/src/GLTFSerializer.cpp similarity index 94% rename from libraries/fbx/src/GLTFReader.cpp rename to libraries/fbx/src/GLTFSerializer.cpp index 9cd43ddf08..5e60cfffe7 100644 --- a/libraries/fbx/src/GLTFReader.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -1,5 +1,5 @@ // -// GLTFReader.cpp +// GLTFSerializer.cpp // libraries/fbx/src // // Created by Luis Cuenca on 8/30/17. @@ -9,7 +9,7 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "GLTFReader.h" +#include "GLTFSerializer.h" #include #include @@ -33,14 +33,14 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" -GLTFReader::GLTFReader() { +GLTFSerializer::GLTFSerializer() { } -bool GLTFReader::getStringVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getStringVal(const QJsonObject& object, const QString& fieldname, QString& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isString()); if (_defined) { @@ -50,7 +50,7 @@ bool GLTFReader::getStringVal(const QJsonObject& object, const QString& fieldnam return _defined; } -bool GLTFReader::getBoolVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getBoolVal(const QJsonObject& object, const QString& fieldname, bool& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isBool()); if (_defined) { @@ -60,7 +60,7 @@ bool GLTFReader::getBoolVal(const QJsonObject& object, const QString& fieldname, return _defined; } -bool GLTFReader::getIntVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getIntVal(const QJsonObject& object, const QString& fieldname, int& value, QMap& defined) { bool _defined = (object.contains(fieldname) && !object[fieldname].isNull()); if (_defined) { @@ -70,7 +70,7 @@ bool GLTFReader::getIntVal(const QJsonObject& object, const QString& fieldname, return _defined; } -bool GLTFReader::getDoubleVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getDoubleVal(const QJsonObject& object, const QString& fieldname, double& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isDouble()); if (_defined) { @@ -79,7 +79,7 @@ bool GLTFReader::getDoubleVal(const QJsonObject& object, const QString& fieldnam defined.insert(fieldname, _defined); return _defined; } -bool GLTFReader::getObjectVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getObjectVal(const QJsonObject& object, const QString& fieldname, QJsonObject& value, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isObject()); if (_defined) { @@ -89,7 +89,7 @@ bool GLTFReader::getObjectVal(const QJsonObject& object, const QString& fieldnam return _defined; } -bool GLTFReader::getIntArrayVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getIntArrayVal(const QJsonObject& object, const QString& fieldname, QVector& values, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isArray()); if (_defined) { @@ -104,7 +104,7 @@ bool GLTFReader::getIntArrayVal(const QJsonObject& object, const QString& fieldn return _defined; } -bool GLTFReader::getDoubleArrayVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getDoubleArrayVal(const QJsonObject& object, const QString& fieldname, QVector& values, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isArray()); if (_defined) { @@ -119,7 +119,7 @@ bool GLTFReader::getDoubleArrayVal(const QJsonObject& object, const QString& fie return _defined; } -bool GLTFReader::getObjectArrayVal(const QJsonObject& object, const QString& fieldname, +bool GLTFSerializer::getObjectArrayVal(const QJsonObject& object, const QString& fieldname, QJsonArray& objects, QMap& defined) { bool _defined = (object.contains(fieldname) && object[fieldname].isArray()); if (_defined) { @@ -129,7 +129,7 @@ bool GLTFReader::getObjectArrayVal(const QJsonObject& object, const QString& fie return _defined; } -int GLTFReader::getMeshPrimitiveRenderingMode(const QString& type) +int GLTFSerializer::getMeshPrimitiveRenderingMode(const QString& type) { if (type == "POINTS") { return GLTFMeshPrimitivesRenderingMode::POINTS; @@ -155,7 +155,7 @@ int GLTFReader::getMeshPrimitiveRenderingMode(const QString& type) return GLTFMeshPrimitivesRenderingMode::TRIANGLES; } -int GLTFReader::getAccessorType(const QString& type) +int GLTFSerializer::getAccessorType(const QString& type) { if (type == "SCALAR") { return GLTFAccessorType::SCALAR; @@ -181,7 +181,7 @@ int GLTFReader::getAccessorType(const QString& type) return GLTFAccessorType::SCALAR; } -int GLTFReader::getMaterialAlphaMode(const QString& type) +int GLTFSerializer::getMaterialAlphaMode(const QString& type) { if (type == "OPAQUE") { return GLTFMaterialAlphaMode::OPAQUE; @@ -195,7 +195,7 @@ int GLTFReader::getMaterialAlphaMode(const QString& type) return GLTFMaterialAlphaMode::OPAQUE; } -int GLTFReader::getCameraType(const QString& type) +int GLTFSerializer::getCameraType(const QString& type) { if (type == "orthographic") { return GLTFCameraTypes::ORTHOGRAPHIC; @@ -206,7 +206,7 @@ int GLTFReader::getCameraType(const QString& type) return GLTFCameraTypes::PERSPECTIVE; } -int GLTFReader::getImageMimeType(const QString& mime) +int GLTFSerializer::getImageMimeType(const QString& mime) { if (mime == "image/jpeg") { return GLTFImageMimetype::JPEG; @@ -217,7 +217,7 @@ int GLTFReader::getImageMimeType(const QString& mime) return GLTFImageMimetype::JPEG; } -int GLTFReader::getAnimationSamplerInterpolation(const QString& interpolation) +int GLTFSerializer::getAnimationSamplerInterpolation(const QString& interpolation) { if (interpolation == "LINEAR") { return GLTFAnimationSamplerInterpolation::LINEAR; @@ -225,7 +225,7 @@ int GLTFReader::getAnimationSamplerInterpolation(const QString& interpolation) return GLTFAnimationSamplerInterpolation::LINEAR; } -bool GLTFReader::setAsset(const QJsonObject& object) { +bool GLTFSerializer::setAsset(const QJsonObject& object) { QJsonObject jsAsset; bool isAssetDefined = getObjectVal(object, "asset", jsAsset, _file.defined); if (isAssetDefined) { @@ -239,7 +239,7 @@ bool GLTFReader::setAsset(const QJsonObject& object) { return isAssetDefined; } -bool GLTFReader::addAccessor(const QJsonObject& object) { +bool GLTFSerializer::addAccessor(const QJsonObject& object) { GLTFAccessor accessor; getIntVal(object, "bufferView", accessor.bufferView, accessor.defined); @@ -259,7 +259,7 @@ bool GLTFReader::addAccessor(const QJsonObject& object) { return true; } -bool GLTFReader::addAnimation(const QJsonObject& object) { +bool GLTFSerializer::addAnimation(const QJsonObject& object) { GLTFAnimation animation; QJsonArray channels; @@ -297,7 +297,7 @@ bool GLTFReader::addAnimation(const QJsonObject& object) { return true; } -bool GLTFReader::addBufferView(const QJsonObject& object) { +bool GLTFSerializer::addBufferView(const QJsonObject& object) { GLTFBufferView bufferview; getIntVal(object, "buffer", bufferview.buffer, bufferview.defined); @@ -310,7 +310,7 @@ bool GLTFReader::addBufferView(const QJsonObject& object) { return true; } -bool GLTFReader::addBuffer(const QJsonObject& object) { +bool GLTFSerializer::addBuffer(const QJsonObject& object) { GLTFBuffer buffer; getIntVal(object, "byteLength", buffer.byteLength, buffer.defined); @@ -324,7 +324,7 @@ bool GLTFReader::addBuffer(const QJsonObject& object) { return true; } -bool GLTFReader::addCamera(const QJsonObject& object) { +bool GLTFSerializer::addCamera(const QJsonObject& object) { GLTFCamera camera; QJsonObject jsPerspective; @@ -352,7 +352,7 @@ bool GLTFReader::addCamera(const QJsonObject& object) { return true; } -bool GLTFReader::addImage(const QJsonObject& object) { +bool GLTFSerializer::addImage(const QJsonObject& object) { GLTFImage image; QString mime; @@ -367,7 +367,7 @@ bool GLTFReader::addImage(const QJsonObject& object) { return true; } -bool GLTFReader::getIndexFromObject(const QJsonObject& object, const QString& field, +bool GLTFSerializer::getIndexFromObject(const QJsonObject& object, const QString& field, int& outidx, QMap& defined) { QJsonObject subobject; if (getObjectVal(object, field, subobject, defined)) { @@ -377,7 +377,7 @@ bool GLTFReader::getIndexFromObject(const QJsonObject& object, const QString& fi return false; } -bool GLTFReader::addMaterial(const QJsonObject& object) { +bool GLTFSerializer::addMaterial(const QJsonObject& object) { GLTFMaterial material; getStringVal(object, "name", material.name, material.defined); @@ -413,7 +413,7 @@ bool GLTFReader::addMaterial(const QJsonObject& object) { return true; } -bool GLTFReader::addMesh(const QJsonObject& object) { +bool GLTFSerializer::addMesh(const QJsonObject& object) { GLTFMesh mesh; getStringVal(object, "name", mesh.name, mesh.defined); @@ -467,7 +467,7 @@ bool GLTFReader::addMesh(const QJsonObject& object) { return true; } -bool GLTFReader::addNode(const QJsonObject& object) { +bool GLTFSerializer::addNode(const QJsonObject& object) { GLTFNode node; getStringVal(object, "name", node.name, node.defined); @@ -487,7 +487,7 @@ bool GLTFReader::addNode(const QJsonObject& object) { return true; } -bool GLTFReader::addSampler(const QJsonObject& object) { +bool GLTFSerializer::addSampler(const QJsonObject& object) { GLTFSampler sampler; getIntVal(object, "magFilter", sampler.magFilter, sampler.defined); @@ -501,7 +501,7 @@ bool GLTFReader::addSampler(const QJsonObject& object) { } -bool GLTFReader::addScene(const QJsonObject& object) { +bool GLTFSerializer::addScene(const QJsonObject& object) { GLTFScene scene; getStringVal(object, "name", scene.name, scene.defined); @@ -511,7 +511,7 @@ bool GLTFReader::addScene(const QJsonObject& object) { return true; } -bool GLTFReader::addSkin(const QJsonObject& object) { +bool GLTFSerializer::addSkin(const QJsonObject& object) { GLTFSkin skin; getIntVal(object, "inverseBindMatrices", skin.inverseBindMatrices, skin.defined); @@ -523,7 +523,7 @@ bool GLTFReader::addSkin(const QJsonObject& object) { return true; } -bool GLTFReader::addTexture(const QJsonObject& object) { +bool GLTFSerializer::addTexture(const QJsonObject& object) { GLTFTexture texture; getIntVal(object, "sampler", texture.sampler, texture.defined); getIntVal(object, "source", texture.source, texture.defined); @@ -533,7 +533,7 @@ bool GLTFReader::addTexture(const QJsonObject& object) { return true; } -bool GLTFReader::parseGLTF(const QByteArray& data) { +bool GLTFSerializer::parseGLTF(const QByteArray& data) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); QJsonDocument d = QJsonDocument::fromJson(data); @@ -664,7 +664,7 @@ bool GLTFReader::parseGLTF(const QByteArray& data) { return true; } -glm::mat4 GLTFReader::getModelTransform(const GLTFNode& node) { +glm::mat4 GLTFSerializer::getModelTransform(const GLTFNode& node) { glm::mat4 tmat = glm::mat4(1.0); if (node.defined["matrix"] && node.matrix.size() == 16) { @@ -697,7 +697,7 @@ glm::mat4 GLTFReader::getModelTransform(const GLTFNode& node) { return tmat; } -bool GLTFReader::buildGeometry(HFMModel& hfmModel, const QUrl& url) { +bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) { //Build dependencies QVector> nodeDependencies(_file.nodes.size()); @@ -899,7 +899,7 @@ bool GLTFReader::buildGeometry(HFMModel& hfmModel, const QUrl& url) { } mesh.meshIndex = hfmModel.meshes.size(); - FBXReader::buildModelMesh(mesh, url.toString()); + FBXSerializer::buildModelMesh(mesh, url.toString()); } } @@ -910,7 +910,7 @@ bool GLTFReader::buildGeometry(HFMModel& hfmModel, const QUrl& url) { return true; } -HFMModel* GLTFReader::readGLTF(QByteArray& data, const QVariantHash& mapping, +HFMModel* GLTFSerializer::readGLTF(QByteArray& data, const QVariantHash& mapping, const QUrl& url, bool loadLightmaps, float lightmapLevel) { _url = url; @@ -934,7 +934,7 @@ HFMModel* GLTFReader::readGLTF(QByteArray& data, const QVariantHash& mapping, } -bool GLTFReader::readBinary(const QString& url, QByteArray& outdata) { +bool GLTFSerializer::readBinary(const QString& url, QByteArray& outdata) { QUrl binaryUrl = _url.resolved(url); qCDebug(modelformat) << "binaryUrl: " << binaryUrl << " OriginalUrl: " << _url; @@ -944,7 +944,7 @@ bool GLTFReader::readBinary(const QString& url, QByteArray& outdata) { return success; } -bool GLTFReader::doesResourceExist(const QString& url) { +bool GLTFSerializer::doesResourceExist(const QString& url) { if (_url.isEmpty()) { return false; } @@ -952,9 +952,9 @@ bool GLTFReader::doesResourceExist(const QString& url) { return DependencyManager::get()->resourceExists(candidateUrl); } -std::tuple GLTFReader::requestData(QUrl& url) { +std::tuple GLTFSerializer::requestData(QUrl& url) { auto request = DependencyManager::get()->createResourceRequest( - nullptr, url, true, -1, "GLTFReader::requestData"); + nullptr, url, true, -1, "GLTFSerializer::requestData"); if (!request) { return std::make_tuple(false, QByteArray()); @@ -973,7 +973,7 @@ std::tuple GLTFReader::requestData(QUrl& url) { } -QNetworkReply* GLTFReader::request(QUrl& url, bool isTest) { +QNetworkReply* GLTFSerializer::request(QUrl& url, bool isTest) { if (!qApp) { return nullptr; } @@ -997,7 +997,7 @@ QNetworkReply* GLTFReader::request(QUrl& url, bool isTest) { return netReply; // trying to sync later on. } -HFMTexture GLTFReader::getHFMTexture(const GLTFTexture& texture) { +HFMTexture GLTFSerializer::getHFMTexture(const GLTFTexture& texture) { HFMTexture fbxtex = HFMTexture(); fbxtex.texcoordSet = 0; @@ -1014,7 +1014,7 @@ HFMTexture GLTFReader::getHFMTexture(const GLTFTexture& texture) { return fbxtex; } -void GLTFReader::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& material) { +void GLTFSerializer::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& material) { if (material.defined["name"]) { @@ -1077,7 +1077,7 @@ void GLTFReader::setHFMMaterial(HFMMaterial& fbxmat, const GLTFMaterial& materia } template -bool GLTFReader::readArray(const QByteArray& bin, int byteOffset, int count, +bool GLTFSerializer::readArray(const QByteArray& bin, int byteOffset, int count, QVector& outarray, int accessorType) { QDataStream blobstream(bin); @@ -1134,7 +1134,7 @@ bool GLTFReader::readArray(const QByteArray& bin, int byteOffset, int count, return true; } template -bool GLTFReader::addArrayOfType(const QByteArray& bin, int byteOffset, int count, +bool GLTFSerializer::addArrayOfType(const QByteArray& bin, int byteOffset, int count, QVector& outarray, int accessorType, int componentType) { switch (componentType) { @@ -1158,7 +1158,7 @@ bool GLTFReader::addArrayOfType(const QByteArray& bin, int byteOffset, int count return false; } -void GLTFReader::retriangulate(const QVector& inIndices, const QVector& in_vertices, +void GLTFSerializer::retriangulate(const QVector& inIndices, const QVector& in_vertices, const QVector& in_normals, QVector& outIndices, QVector& out_vertices, QVector& out_normals) { for (int i = 0; i < inIndices.size(); i = i + 3) { @@ -1181,7 +1181,7 @@ void GLTFReader::retriangulate(const QVector& inIndices, const QVector // .obj files are not locale-specific. The C/ASCII charset applies. #include @@ -27,7 +27,7 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" #include #include @@ -238,7 +238,7 @@ void OBJFace::addFrom(const OBJFace* face, int index) { // add using data from f } } -bool OBJReader::isValidTexture(const QByteArray &filename) { +bool OBJSerializer::isValidTexture(const QByteArray &filename) { if (_url.isEmpty()) { return false; } @@ -247,7 +247,7 @@ bool OBJReader::isValidTexture(const QByteArray &filename) { return DependencyManager::get()->resourceExists(candidateUrl); } -void OBJReader::parseMaterialLibrary(QIODevice* device) { +void OBJSerializer::parseMaterialLibrary(QIODevice* device) { OBJTokenizer tokenizer(device); QString matName = SMART_DEFAULT_MATERIAL_NAME; OBJMaterial& currentMaterial = materials[matName]; @@ -255,7 +255,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { switch (tokenizer.nextToken()) { case OBJTokenizer::COMMENT_TOKEN: #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader MTLLIB comment:" << tokenizer.getComment(); + qCDebug(modelformat) << "OBJSerializer MTLLIB comment:" << tokenizer.getComment(); #endif break; case OBJTokenizer::DATUM_TOKEN: @@ -264,7 +264,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { materials[matName] = currentMaterial; #ifdef WANT_DEBUG qCDebug(modelformat) << - "OBJ Reader Last material illumination model:" << currentMaterial.illuminationModel << + "OBJSerializer Last material illumination model:" << currentMaterial.illuminationModel << " shininess:" << currentMaterial.shininess << " opacity:" << currentMaterial.opacity << " diffuse color:" << currentMaterial.diffuseColor << @@ -287,7 +287,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { matName = tokenizer.getDatum(); currentMaterial = materials[matName]; #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Starting new material definition " << matName; + qCDebug(modelformat) << "OBJSerializer Starting new material definition " << matName; #endif currentMaterial.diffuseTextureFilename = ""; currentMaterial.emissiveTextureFilename = ""; @@ -299,7 +299,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { currentMaterial.shininess = tokenizer.getFloat(); } else if (token == "Ni") { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Ignoring material Ni " << tokenizer.getFloat(); + qCDebug(modelformat) << "OBJSerializer Ignoring material Ni " << tokenizer.getFloat(); #else tokenizer.getFloat(); #endif @@ -311,13 +311,13 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { currentMaterial.illuminationModel = tokenizer.getFloat(); } else if (token == "Tf") { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Ignoring material Tf " << tokenizer.getVec3(); + qCDebug(modelformat) << "OBJSerializer Ignoring material Tf " << tokenizer.getVec3(); #else tokenizer.getVec3(); #endif } else if (token == "Ka") { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader Ignoring material Ka " << tokenizer.getVec3();; + qCDebug(modelformat) << "OBJSerializer Ignoring material Ka " << tokenizer.getVec3();; #else tokenizer.getVec3(); #endif @@ -334,7 +334,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { parseTextureLine(textureLine, filename, textureOptions); if (filename.endsWith(".tga")) { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader WARNING: currently ignoring tga texture " << filename << " in " << _url; + qCDebug(modelformat) << "OBJSerializer WARNING: currently ignoring tga texture " << filename << " in " << _url; #endif break; } @@ -354,7 +354,7 @@ void OBJReader::parseMaterialLibrary(QIODevice* device) { } } -void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& filename, OBJMaterialTextureOptions& textureOptions) { +void OBJSerializer::parseTextureLine(const QByteArray& textureLine, QByteArray& filename, OBJMaterialTextureOptions& textureOptions) { // Texture options reference http://paulbourke.net/dataformats/mtl/ // and https://wikivisually.com/wiki/Material_Template_Library @@ -368,7 +368,7 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file if (option == "-blendu" || option == "-blendv") { #ifdef WANT_DEBUG const std::string& onoff = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); #endif } else if (option == "-bm") { const std::string& bm = parser[i++]; @@ -377,22 +377,22 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file #ifdef WANT_DEBUG const std::string& boost = parser[i++]; float boostFloat = std::stof(boost); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << boost.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << boost.c_str(); #endif } else if (option == "-cc") { #ifdef WANT_DEBUG const std::string& onoff = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); #endif } else if (option == "-clamp") { #ifdef WANT_DEBUG const std::string& onoff = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << onoff.c_str(); #endif } else if (option == "-imfchan") { #ifdef WANT_DEBUG const std::string& imfchan = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << imfchan.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << imfchan.c_str(); #endif } else if (option == "-mm") { if (i + 1 < parser.size()) { @@ -401,7 +401,7 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file const std::string& mmGain = parser[i++]; float mmBaseFloat = std::stof(mmBase); float mmGainFloat = std::stof(mmGain); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << mmBase.c_str() << mmGain.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << mmBase.c_str() << mmGain.c_str(); #endif } } else if (option == "-o" || option == "-s" || option == "-t") { @@ -413,23 +413,23 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file float uFloat = std::stof(u); float vFloat = std::stof(v); float wFloat = std::stof(w); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << u.c_str() << v.c_str() << w.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << u.c_str() << v.c_str() << w.c_str(); #endif } } else if (option == "-texres") { #ifdef WANT_DEBUG const std::string& texres = parser[i++]; float texresFloat = std::stof(texres); - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << texres.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << texres.c_str(); #endif } else if (option == "-type") { #ifdef WANT_DEBUG const std::string& type = parser[i++]; - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring texture option" << option.c_str() << type.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring texture option" << option.c_str() << type.c_str(); #endif } else if (option[0] == '-') { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader WARNING: Ignoring unsupported texture option" << option.c_str(); + qCDebug(modelformat) << "OBJSerializer WARNING: Ignoring unsupported texture option" << option.c_str(); #endif } } else { // assume filename at end when no more options @@ -444,7 +444,7 @@ void OBJReader::parseTextureLine(const QByteArray& textureLine, QByteArray& file std::tuple requestData(QUrl& url) { auto request = DependencyManager::get()->createResourceRequest( - nullptr, url, true, -1, "(OBJReader) requestData"); + nullptr, url, true, -1, "(OBJSerializer) requestData"); if (!request) { return std::make_tuple(false, QByteArray()); @@ -488,7 +488,7 @@ QNetworkReply* request(QUrl& url, bool isTest) { } -bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, HFMModel& hfmModel, +bool OBJSerializer::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mapping, HFMModel& hfmModel, float& scaleGuess, bool combineParts) { FaceGroup faces; HFMMesh& mesh = hfmModel.meshes[0]; @@ -557,7 +557,7 @@ bool OBJReader::parseOBJGroup(OBJTokenizer& tokenizer, const QVariantHash& mappi currentMaterialName = nextName; } #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader new current material:" << currentMaterialName; + qCDebug(modelformat) << "OBJSerializer new current material:" << currentMaterialName; #endif } } else if (token == "v") { @@ -652,7 +652,7 @@ done: } -HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mapping, bool combineParts, const QUrl& url) { +HFMModel::Pointer OBJSerializer::readOBJ(QByteArray& data, const QVariantHash& mapping, bool combineParts, const QUrl& url) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); QBuffer buffer { &data }; buffer.open(QIODevice::ReadOnly); @@ -720,7 +720,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi QString groupMaterialName = face.materialName; if (groupMaterialName.isEmpty() && specifiesUV) { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader WARNING: " << url + qCDebug(modelformat) << "OBJSerializer WARNING: " << url << " needs a texture that isn't specified. Using default mechanism."; #endif groupMaterialName = SMART_DEFAULT_MATERIAL_NAME; @@ -822,11 +822,11 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi } // Build the single mesh. - FBXReader::buildModelMesh(mesh, url.toString()); + FBXSerializer::buildModelMesh(mesh, url.toString()); // hfmDebugDump(hfmModel); } catch(const std::exception& e) { - qCDebug(modelformat) << "OBJ reader fail: " << e.what(); + qCDebug(modelformat) << "OBJSerializer fail: " << e.what(); } QString queryPart = _url.query(); @@ -845,7 +845,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi preDefinedMaterial.diffuseColor = glm::vec3(1.0f); QVector extensions = { "jpg", "jpeg", "png", "tga" }; QByteArray base = basename.toUtf8(), textName = ""; - qCDebug(modelformat) << "OBJ Reader looking for default texture of" << url; + qCDebug(modelformat) << "OBJSerializer looking for default texture of" << url; for (int i = 0; i < extensions.count(); i++) { QByteArray candidateString = base + extensions[i]; if (isValidTexture(candidateString)) { @@ -856,7 +856,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi if (!textName.isEmpty()) { #ifdef WANT_DEBUG - qCDebug(modelformat) << "OBJ Reader found a default texture: " << textName; + qCDebug(modelformat) << "OBJSerializer found a default texture: " << textName; #endif preDefinedMaterial.diffuseTextureFilename = textName; } @@ -866,7 +866,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi foreach (QString libraryName, librariesSeen.keys()) { // Throw away any path part of libraryName, and merge against original url. QUrl libraryUrl = _url.resolved(QUrl(libraryName).fileName()); - qCDebug(modelformat) << "OBJ Reader material library" << libraryName << "used in" << _url; + qCDebug(modelformat) << "OBJSerializer material library" << libraryName << "used in" << _url; bool success; QByteArray data; std::tie(success, data) = requestData(libraryUrl); @@ -875,7 +875,7 @@ HFMModel::Pointer OBJReader::readOBJ(QByteArray& data, const QVariantHash& mappi buffer.open(QIODevice::ReadOnly); parseMaterialLibrary(&buffer); } else { - qCDebug(modelformat) << "OBJ Reader WARNING:" << libraryName << "did not answer"; + qCDebug(modelformat) << "OBJSerializer WARNING:" << libraryName << "did not answer"; } } } diff --git a/libraries/fbx/src/OBJReader.h b/libraries/fbx/src/OBJSerializer.h similarity index 97% rename from libraries/fbx/src/OBJReader.h rename to libraries/fbx/src/OBJSerializer.h index 0088e8e9d7..d33d2edf07 100644 --- a/libraries/fbx/src/OBJReader.h +++ b/libraries/fbx/src/OBJSerializer.h @@ -1,6 +1,6 @@ #include -#include "FBXReader.h" +#include "FBXSerializer.h" class OBJTokenizer { public: @@ -75,7 +75,7 @@ public: OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f), illuminationModel(-1) {} }; -class OBJReader: public QObject { // QObject so we can make network requests. +class OBJSerializer: public QObject { // QObject so we can make network requests. Q_OBJECT public: typedef QVector FaceGroup; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index dd58b0e75e..5a7e383630 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -12,9 +12,9 @@ #include "ModelCache.h" #include #include -#include "FBXReader.h" -#include "OBJReader.h" -#include "GLTFReader.h" +#include "FBXSerializer.h" +#include "OBJSerializer.h" +#include "GLTFSerializer.h" #include #include @@ -201,17 +201,17 @@ void GeometryReader::run() { throw QString("empty geometry, possibly due to an unsupported FBX version"); } } else if (_url.path().toLower().endsWith(".obj")) { - hfmModel = OBJReader().readOBJ(_data, _mapping, _combineParts, _url); + hfmModel = OBJSerializer().readOBJ(_data, _mapping, _combineParts, _url); } else if (_url.path().toLower().endsWith(".obj.gz")) { QByteArray uncompressedData; if (gunzip(_data, uncompressedData)){ - hfmModel = OBJReader().readOBJ(uncompressedData, _mapping, _combineParts, _url); + hfmModel = OBJSerializer().readOBJ(uncompressedData, _mapping, _combineParts, _url); } else { throw QString("failed to decompress .obj.gz"); } } else if (_url.path().toLower().endsWith(".gltf")) { - std::shared_ptr glreader = std::make_shared(); + std::shared_ptr glreader = std::make_shared(); hfmModel.reset(glreader->readGLTF(_data, _mapping, _url)); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported GLTF version"); diff --git a/libraries/model-networking/src/model-networking/ModelCache.h b/libraries/model-networking/src/model-networking/ModelCache.h index 1bb340b83c..9d458e7512 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.h +++ b/libraries/model-networking/src/model-networking/ModelCache.h @@ -18,7 +18,7 @@ #include #include -#include "FBXReader.h" +#include "FBXSerializer.h" #include "TextureCache.h" // Alias instead of derive to avoid copying diff --git a/tests-manual/gpu/src/TestFbx.cpp b/tests-manual/gpu/src/TestFbx.cpp index 9253f8bc91..290913e406 100644 --- a/tests-manual/gpu/src/TestFbx.cpp +++ b/tests-manual/gpu/src/TestFbx.cpp @@ -12,7 +12,7 @@ #include -#include +#include struct MyVertex { vec3 position; diff --git a/tools/skeleton-dump/src/SkeletonDumpApp.cpp b/tools/skeleton-dump/src/SkeletonDumpApp.cpp index 10b13aef36..bad38f24ba 100644 --- a/tools/skeleton-dump/src/SkeletonDumpApp.cpp +++ b/tools/skeleton-dump/src/SkeletonDumpApp.cpp @@ -12,7 +12,7 @@ #include "SkeletonDumpApp.h" #include #include -#include +#include #include SkeletonDumpApp::SkeletonDumpApp(int argc, char* argv[]) : QCoreApplication(argc, argv) { diff --git a/tools/vhacd-util/src/VHACDUtil.cpp b/tools/vhacd-util/src/VHACDUtil.cpp index 8de9c39da9..b1dcdebe60 100644 --- a/tools/vhacd-util/src/VHACDUtil.cpp +++ b/tools/vhacd-util/src/VHACDUtil.cpp @@ -17,7 +17,7 @@ #include -// FBXReader jumbles the order of the meshes by reading them back out of a hashtable. This will put +// FBXSerializer jumbles the order of the meshes by reading them back out of a hashtable. This will put // them back in the order in which they appeared in the file. bool HFMModelLessThan(const HFMMesh& e1, const HFMMesh& e2) { return e1.meshIndex < e2.meshIndex; @@ -44,7 +44,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) { HFMModel::Pointer hfmModel; if (filename.toLower().endsWith(".obj")) { bool combineParts = false; - hfmModel = OBJReader().readOBJ(fbxContents, QVariantHash(), combineParts); + hfmModel = OBJSerializer().readOBJ(fbxContents, QVariantHash(), combineParts); } else if (filename.toLower().endsWith(".fbx")) { hfmModel.reset(readFBX(fbxContents, QVariantHash(), filename)); } else { diff --git a/tools/vhacd-util/src/VHACDUtil.h b/tools/vhacd-util/src/VHACDUtil.h index dd8f606756..7a6f2f1db6 100644 --- a/tools/vhacd-util/src/VHACDUtil.h +++ b/tools/vhacd-util/src/VHACDUtil.h @@ -18,8 +18,8 @@ #include #include //c++11 feature #include -#include -#include +#include +#include #include namespace vhacd { diff --git a/tools/vhacd-util/src/VHACDUtilApp.h b/tools/vhacd-util/src/VHACDUtilApp.h index 7dadad20b3..1cbb29bb88 100644 --- a/tools/vhacd-util/src/VHACDUtilApp.h +++ b/tools/vhacd-util/src/VHACDUtilApp.h @@ -15,7 +15,7 @@ #include -#include +#include const int VHACD_RETURN_CODE_FAILURE_TO_READ = 1; const int VHACD_RETURN_CODE_FAILURE_TO_WRITE = 2; From 0271f7d3344182c07b15b546dea590912b0ab34c Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Wed, 7 Nov 2018 17:07:44 -0800 Subject: [PATCH 02/11] Create the HFMSerializer interface class --- libraries/hfm/src/hfm/HFMSerializer.h | 29 +++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 libraries/hfm/src/hfm/HFMSerializer.h diff --git a/libraries/hfm/src/hfm/HFMSerializer.h b/libraries/hfm/src/hfm/HFMSerializer.h new file mode 100644 index 0000000000..bd63d8bf82 --- /dev/null +++ b/libraries/hfm/src/hfm/HFMSerializer.h @@ -0,0 +1,29 @@ +// +// FBXSerializer.h +// libraries/hfm/src/hfm +// +// Created by Sabrina Shanman on 2018/11/07. +// Copyright 2018 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 +// + +#ifndef hifi_HFMSerializer_h +#define hifi_HFMSerializer_h + +#include +#include +#include + +#include "HFM.h" + +namespace hfm { + +class Serializer { + virtual Model* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) = 0; +}; + +}; + +#endif // hifi_HFMSerializer_h From 00f2b4eeb9087aa043c77bc62e512823b61839ab Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 5 Nov 2018 17:30:44 -0800 Subject: [PATCH 03/11] Make the existing model serializers based on HFMSerializer --- interface/src/ModelPackager.cpp | 2 +- libraries/animation/src/AnimationCache.cpp | 2 +- libraries/baking/src/FBXBaker.cpp | 8 ++++---- libraries/baking/src/OBJBaker.cpp | 2 +- libraries/fbx/src/FBXSerializer.cpp | 17 +++++++++-------- libraries/fbx/src/FBXSerializer.h | 18 +++++++++--------- libraries/fbx/src/GLTFSerializer.cpp | 4 ++-- libraries/fbx/src/GLTFSerializer.h | 7 ++++--- libraries/fbx/src/OBJSerializer.cpp | 6 +++--- libraries/fbx/src/OBJSerializer.h | 7 ++++--- libraries/hfm/src/hfm/HFMSerializer.h | 2 ++ .../src/model-networking/ModelCache.cpp | 9 ++++----- tests-manual/gpu/src/TestFbx.cpp | 2 +- tools/skeleton-dump/src/SkeletonDumpApp.cpp | 2 +- tools/vhacd-util/src/VHACDUtil.cpp | 4 ++-- 15 files changed, 48 insertions(+), 44 deletions(-) diff --git a/interface/src/ModelPackager.cpp b/interface/src/ModelPackager.cpp index a7fc0b9e20..5d7d4b1396 100644 --- a/interface/src/ModelPackager.cpp +++ b/interface/src/ModelPackager.cpp @@ -109,7 +109,7 @@ bool ModelPackager::loadModel() { qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath(); QByteArray fbxContents = fbx.readAll(); - _hfmModel.reset(readFBX(fbxContents, QVariantHash(), _fbxInfo.filePath())); + _hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath())); // make sure we have some basic mappings populateBasicMapping(_mapping, _fbxInfo.filePath(), *_hfmModel); diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 06dfc0262a..5c9f083a3b 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -71,7 +71,7 @@ void AnimationReader::run() { // Parse the FBX directly from the QNetworkReply HFMModel::Pointer hfmModel; if (_url.path().toLower().endsWith(".fbx")) { - hfmModel.reset(readFBX(_data, QVariantHash(), _url.path())); + hfmModel.reset(FBXSerializer().read(_data, QVariantHash(), _url.path())); } else { QString errorStr("usupported format"); emit onError(299, errorStr); diff --git a/libraries/baking/src/FBXBaker.cpp b/libraries/baking/src/FBXBaker.cpp index 6349b06c49..afaca1dd62 100644 --- a/libraries/baking/src/FBXBaker.cpp +++ b/libraries/baking/src/FBXBaker.cpp @@ -187,10 +187,10 @@ void FBXBaker::importScene() { return; } - FBXSerializer serializer; + FBXSerializer fbxSerializer; qCDebug(model_baking) << "Parsing" << _modelURL; - _rootNode = serializer._rootNode = serializer.parseFBX(&fbxFile); + _rootNode = fbxSerializer._rootNode = fbxSerializer.parseFBX(&fbxFile); #ifdef HIFI_DUMP_FBX { @@ -206,8 +206,8 @@ void FBXBaker::importScene() { } #endif - _hfmModel = serializer.extractHFMModel({}, _modelURL.toString()); - _textureContentMap = serializer._textureContent; + _hfmModel = fbxSerializer.extractHFMModel({}, _modelURL.toString()); + _textureContentMap = fbxSerializer._textureContent; } void FBXBaker::rewriteAndBakeSceneModels() { diff --git a/libraries/baking/src/OBJBaker.cpp b/libraries/baking/src/OBJBaker.cpp index 389e708c12..83079bc052 100644 --- a/libraries/baking/src/OBJBaker.cpp +++ b/libraries/baking/src/OBJBaker.cpp @@ -145,7 +145,7 @@ void OBJBaker::bakeOBJ() { bool combineParts = true; // set true so that OBJSerializer reads material info from material library OBJSerializer serializer; - auto geometry = serializer.readOBJ(objData, QVariantHash(), combineParts, _modelURL); + auto geometry = serializer.read(objData, QVariantHash(), _modelURL, combineParts); // Write OBJ Data as FBX tree nodes createFBXNodeTree(_rootNode, *geometry); diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index fb7d95cf37..1cbb0ce386 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1796,19 +1796,20 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr return hfmModelPtr; } -HFMModel* readFBX(const QByteArray& data, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { +HFMModel* FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url, bool combineParts) { QBuffer buffer(const_cast(&data)); buffer.open(QIODevice::ReadOnly); - return readFBX(&buffer, mapping, url, loadLightmaps, lightmapLevel); + return read(&buffer, mapping, url, combineParts); } -HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { - FBXSerializer serializer; - serializer._rootNode = FBXSerializer::parseFBX(device); - serializer._loadLightmaps = loadLightmaps; - serializer._lightmapLevel = lightmapLevel; +HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url, bool combineParts) { + _rootNode = parseFBX(device); qCDebug(modelformat) << "Reading FBX: " << url; - return serializer.extractHFMModel(mapping, url); + return extractHFMModel(mapping, url.toString()); +} + +HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { + return FBXSerializer().extractHFMModel(mapping, url); } diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index 9809b257e8..1173af2693 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -27,7 +27,7 @@ #include #include "FBX.h" -#include +#include #include #include @@ -35,10 +35,6 @@ class QIODevice; class FBXNode; -/// Reads HFMModel from the supplied model and mapping data. -/// \exception QString if an error occurs in parsing -HFMModel* readFBX(const QByteArray& data, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f); - /// Reads HFMModel from the supplied model and mapping data. /// \exception QString if an error occurs in parsing HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f); @@ -102,9 +98,13 @@ public: class ExtractedMesh; -class FBXSerializer { +class FBXSerializer : public HFMSerializer { public: HFMModel* _hfmModel; + /// Reads HFMModel from the supplied model and mapping data. + /// \exception QString if an error occurs in parsing + HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) override; + HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false); FBXNode _rootNode; static FBXNode parseFBX(QIODevice* device); @@ -147,9 +147,9 @@ public: void consolidateHFMMaterials(const QVariantHash& mapping); - bool _loadLightmaps = true; - float _lightmapOffset = 0.0f; - float _lightmapLevel; + bool _loadLightmaps { true }; + float _lightmapOffset { 0.0f }; + float _lightmapLevel { 1.0f }; QMultiMap _connectionParentMap; QMultiMap _connectionChildMap; diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 5e60cfffe7..8f529868db 100644 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -910,8 +910,8 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) { return true; } -HFMModel* GLTFSerializer::readGLTF(QByteArray& data, const QVariantHash& mapping, - const QUrl& url, bool loadLightmaps, float lightmapLevel) { +HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, + const QUrl& url, bool combineParts) { _url = url; diff --git a/libraries/fbx/src/GLTFSerializer.h b/libraries/fbx/src/GLTFSerializer.h index 8ce64a83f2..754d097614 100644 --- a/libraries/fbx/src/GLTFSerializer.h +++ b/libraries/fbx/src/GLTFSerializer.h @@ -15,6 +15,7 @@ #include #include #include +#include #include "FBXSerializer.h" @@ -702,12 +703,12 @@ struct GLTFFile { } }; -class GLTFSerializer : public QObject { +class GLTFSerializer : public QObject, public HFMSerializer { Q_OBJECT public: GLTFSerializer(); - HFMModel* readGLTF(QByteArray& data, const QVariantHash& mapping, - const QUrl& url, bool loadLightmaps = true, float lightmapLevel = 1.0f); + HFMModel* read(const QByteArray& data, const QVariantHash& mapping, + const QUrl& url = QUrl(), bool combineParts = false) override; private: GLTFFile _file; QUrl _url; diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/fbx/src/OBJSerializer.cpp index a1a6893280..1684b2812c 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -652,12 +652,12 @@ done: } -HFMModel::Pointer OBJSerializer::readOBJ(QByteArray& data, const QVariantHash& mapping, bool combineParts, const QUrl& url) { +HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url, bool combineParts) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); - QBuffer buffer { &data }; + QBuffer buffer { const_cast(&data) }; buffer.open(QIODevice::ReadOnly); - auto hfmModelPtr { std::make_shared() }; + auto hfmModelPtr = new HFMModel(); HFMModel& hfmModel { *hfmModelPtr }; OBJTokenizer tokenizer { &buffer }; float scaleGuess = 1.0f; diff --git a/libraries/fbx/src/OBJSerializer.h b/libraries/fbx/src/OBJSerializer.h index d33d2edf07..ccb97c02ff 100644 --- a/libraries/fbx/src/OBJSerializer.h +++ b/libraries/fbx/src/OBJSerializer.h @@ -1,5 +1,6 @@ #include +#include #include "FBXSerializer.h" class OBJTokenizer { @@ -75,7 +76,7 @@ public: OBJMaterial() : shininess(0.0f), opacity(1.0f), diffuseColor(0.9f), specularColor(0.9f), emissiveColor(0.0f), illuminationModel(-1) {} }; -class OBJSerializer: public QObject { // QObject so we can make network requests. +class OBJSerializer: public QObject, public HFMSerializer { // QObject so we can make network requests. Q_OBJECT public: typedef QVector FaceGroup; @@ -86,8 +87,8 @@ public: QVector faceGroups; QString currentMaterialName; QHash materials; - - HFMModel::Pointer readOBJ(QByteArray& data, const QVariantHash& mapping, bool combineParts, const QUrl& url = QUrl()); + + HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) override; private: QUrl _url; diff --git a/libraries/hfm/src/hfm/HFMSerializer.h b/libraries/hfm/src/hfm/HFMSerializer.h index bd63d8bf82..3cd48b76b2 100644 --- a/libraries/hfm/src/hfm/HFMSerializer.h +++ b/libraries/hfm/src/hfm/HFMSerializer.h @@ -26,4 +26,6 @@ class Serializer { }; +using HFMSerializer = hfm::Serializer; + #endif // hifi_HFMSerializer_h diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 5a7e383630..507ee23f7c 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -196,23 +196,22 @@ void GeometryReader::run() { HFMModel::Pointer hfmModel; if (_url.path().toLower().endsWith(".fbx")) { - hfmModel.reset(readFBX(_data, _mapping, _url.path())); + hfmModel.reset(FBXSerializer().read(_data, _mapping, _url.path())); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported FBX version"); } } else if (_url.path().toLower().endsWith(".obj")) { - hfmModel = OBJSerializer().readOBJ(_data, _mapping, _combineParts, _url); + hfmModel.reset(OBJSerializer().read(_data, _mapping, _url, _combineParts)); } else if (_url.path().toLower().endsWith(".obj.gz")) { QByteArray uncompressedData; if (gunzip(_data, uncompressedData)){ - hfmModel = OBJSerializer().readOBJ(uncompressedData, _mapping, _combineParts, _url); + hfmModel.reset(OBJSerializer().read(uncompressedData, _mapping, _url, _combineParts)); } else { throw QString("failed to decompress .obj.gz"); } } else if (_url.path().toLower().endsWith(".gltf")) { - std::shared_ptr glreader = std::make_shared(); - hfmModel.reset(glreader->readGLTF(_data, _mapping, _url)); + hfmModel.reset(GLTFSerializer().read(_data, _mapping, _url)); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported GLTF version"); } diff --git a/tests-manual/gpu/src/TestFbx.cpp b/tests-manual/gpu/src/TestFbx.cpp index 290913e406..379481baa8 100644 --- a/tests-manual/gpu/src/TestFbx.cpp +++ b/tests-manual/gpu/src/TestFbx.cpp @@ -100,7 +100,7 @@ bool TestFbx::isReady() const { void TestFbx::parseFbx(const QByteArray& fbxData) { QVariantHash mapping; - HFMModel* hfmModel = readFBX(fbxData, mapping); + HFMModel* hfmModel = FBXSerializer().read(fbxData, mapping); size_t totalVertexCount = 0; size_t totalIndexCount = 0; size_t totalPartCount = 0; diff --git a/tools/skeleton-dump/src/SkeletonDumpApp.cpp b/tools/skeleton-dump/src/SkeletonDumpApp.cpp index bad38f24ba..cbee73528f 100644 --- a/tools/skeleton-dump/src/SkeletonDumpApp.cpp +++ b/tools/skeleton-dump/src/SkeletonDumpApp.cpp @@ -54,7 +54,7 @@ SkeletonDumpApp::SkeletonDumpApp(int argc, char* argv[]) : QCoreApplication(argc return; } QByteArray blob = file.readAll(); - std::unique_ptr geometry(readFBX(blob, QVariantHash())); + std::unique_ptr geometry(FBXSerializer().read(blob, QVariantHash())); std::unique_ptr skeleton(new AnimSkeleton(*geometry)); skeleton->dump(verbose); } diff --git a/tools/vhacd-util/src/VHACDUtil.cpp b/tools/vhacd-util/src/VHACDUtil.cpp index b1dcdebe60..4036dbefa7 100644 --- a/tools/vhacd-util/src/VHACDUtil.cpp +++ b/tools/vhacd-util/src/VHACDUtil.cpp @@ -44,9 +44,9 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) { HFMModel::Pointer hfmModel; if (filename.toLower().endsWith(".obj")) { bool combineParts = false; - hfmModel = OBJSerializer().readOBJ(fbxContents, QVariantHash(), combineParts); + hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename, combineParts)); } else if (filename.toLower().endsWith(".fbx")) { - hfmModel.reset(readFBX(fbxContents, QVariantHash(), filename)); + hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), filename)); } else { qWarning() << "file has unknown extension" << filename; return false; From 0cbe0bd266875ccc811b1f4a6687f2a9450fdfb7 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 8 Nov 2018 13:36:57 -0800 Subject: [PATCH 04/11] Add missing copyright comment and header guard to OBJSerializer.h --- libraries/fbx/src/OBJSerializer.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/libraries/fbx/src/OBJSerializer.h b/libraries/fbx/src/OBJSerializer.h index ccb97c02ff..824110c345 100644 --- a/libraries/fbx/src/OBJSerializer.h +++ b/libraries/fbx/src/OBJSerializer.h @@ -1,3 +1,16 @@ +// +// OBJSerializer.h +// libraries/fbx/src/ +// +// Created by Seth Alves on 3/6/15. +// Copyright 2015 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 +// + +#ifndef hifi_OBJSerializer_h +#define hifi_OBJSerializer_h #include #include @@ -106,3 +119,5 @@ private: // What are these utilities doing here? One is used by fbx loading code in VHACD Utils, and the other a general debugging utility. void setMeshPartDefaults(HFMMeshPart& meshPart, QString materialID); void hfmDebugDump(const HFMModel& hfmModel); + +#endif // hifi_OBJSerializer_h From baa8cdb054a2ff871df59bcb871ad408a9982d58 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 8 Nov 2018 16:20:38 -0800 Subject: [PATCH 05/11] Remove combineParts from the Serializer interface --- libraries/baking/src/OBJBaker.cpp | 2 +- libraries/fbx/src/FBXSerializer.cpp | 6 +++--- libraries/fbx/src/FBXSerializer.h | 4 ++-- libraries/fbx/src/GLTFSerializer.cpp | 7 +++---- libraries/fbx/src/GLTFSerializer.h | 3 +-- libraries/fbx/src/OBJSerializer.cpp | 11 ++++++----- libraries/fbx/src/OBJSerializer.h | 2 +- libraries/hfm/src/hfm/HFMSerializer.h | 2 +- .../src/model-networking/ModelCache.cpp | 11 +++++++---- tools/vhacd-util/src/VHACDUtil.cpp | 3 +-- 10 files changed, 26 insertions(+), 25 deletions(-) diff --git a/libraries/baking/src/OBJBaker.cpp b/libraries/baking/src/OBJBaker.cpp index 83079bc052..ae29a82c28 100644 --- a/libraries/baking/src/OBJBaker.cpp +++ b/libraries/baking/src/OBJBaker.cpp @@ -145,7 +145,7 @@ void OBJBaker::bakeOBJ() { bool combineParts = true; // set true so that OBJSerializer reads material info from material library OBJSerializer serializer; - auto geometry = serializer.read(objData, QVariantHash(), _modelURL, combineParts); + auto geometry = serializer.read(objData, QVariantHash(), _modelURL); // Write OBJ Data as FBX tree nodes createFBXNodeTree(_rootNode, *geometry); diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index 1cbb0ce386..ebd105706b 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1796,13 +1796,13 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr return hfmModelPtr; } -HFMModel* FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url, bool combineParts) { +HFMModel* FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { QBuffer buffer(const_cast(&data)); buffer.open(QIODevice::ReadOnly); - return read(&buffer, mapping, url, combineParts); + return read(&buffer, mapping, url); } -HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url, bool combineParts) { +HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url) { _rootNode = parseFBX(device); qCDebug(modelformat) << "Reading FBX: " << url; diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index 1173af2693..a4832e61e9 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -103,8 +103,8 @@ public: HFMModel* _hfmModel; /// Reads HFMModel from the supplied model and mapping data. /// \exception QString if an error occurs in parsing - HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) override; - HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false); + HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; + HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl()); FBXNode _rootNode; static FBXNode parseFBX(QIODevice* device); diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 8f529868db..17b1189eae 100644 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -910,13 +910,12 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) { return true; } -HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, - const QUrl& url, bool combineParts) { +HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { _url = url; // Normalize url for local files - QUrl normalizeUrl = DependencyManager::get()->normalizeURL(url); + QUrl normalizeUrl = DependencyManager::get()->normalizeURL(_url); if (normalizeUrl.scheme().isEmpty() || (normalizeUrl.scheme() == "file")) { QString localFileName = PathUtils::expandToLocalDataAbsolutePath(normalizeUrl).toLocalFile(); _url = QUrl(QFileInfo(localFileName).absoluteFilePath()); @@ -927,7 +926,7 @@ HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mappi HFMModel* hfmModelPtr = new HFMModel(); HFMModel& hfmModel = *hfmModelPtr; - buildGeometry(hfmModel, url); + buildGeometry(hfmModel, _url); //hfmDebugDump(data); return hfmModelPtr; diff --git a/libraries/fbx/src/GLTFSerializer.h b/libraries/fbx/src/GLTFSerializer.h index 754d097614..86e31d23dd 100644 --- a/libraries/fbx/src/GLTFSerializer.h +++ b/libraries/fbx/src/GLTFSerializer.h @@ -707,8 +707,7 @@ class GLTFSerializer : public QObject, public HFMSerializer { Q_OBJECT public: GLTFSerializer(); - HFMModel* read(const QByteArray& data, const QVariantHash& mapping, - const QUrl& url = QUrl(), bool combineParts = false) override; + HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; private: GLTFFile _file; QUrl _url; diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/fbx/src/OBJSerializer.cpp index 1684b2812c..fb9b882940 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -652,7 +652,7 @@ done: } -HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url, bool combineParts) { +HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); QBuffer buffer { const_cast(&data) }; buffer.open(QIODevice::ReadOnly); @@ -665,6 +665,7 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin bool needsMaterialLibrary = false; _url = url; + bool combineParts = mapping.value("combineParts").toBool(); hfmModel.meshExtents.reset(); hfmModel.meshes.append(HFMMesh()); @@ -822,7 +823,7 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin } // Build the single mesh. - FBXSerializer::buildModelMesh(mesh, url.toString()); + FBXSerializer::buildModelMesh(mesh, _url.toString()); // hfmDebugDump(hfmModel); } catch(const std::exception& e) { @@ -838,14 +839,14 @@ HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mappin } // Some .obj files use the convention that a group with uv coordinates that doesn't define a material, should use // a texture with the same basename as the .obj file. - if (preDefinedMaterial.userSpecifiesUV && !url.isEmpty()) { - QString filename = url.fileName(); + if (preDefinedMaterial.userSpecifiesUV && !_url.isEmpty()) { + QString filename = _url.fileName(); int extIndex = filename.lastIndexOf('.'); // by construction, this does not fail QString basename = filename.remove(extIndex + 1, sizeof("obj")); preDefinedMaterial.diffuseColor = glm::vec3(1.0f); QVector extensions = { "jpg", "jpeg", "png", "tga" }; QByteArray base = basename.toUtf8(), textName = ""; - qCDebug(modelformat) << "OBJSerializer looking for default texture of" << url; + qCDebug(modelformat) << "OBJSerializer looking for default texture of" << _url; for (int i = 0; i < extensions.count(); i++) { QByteArray candidateString = base + extensions[i]; if (isValidTexture(candidateString)) { diff --git a/libraries/fbx/src/OBJSerializer.h b/libraries/fbx/src/OBJSerializer.h index 824110c345..82bd2705df 100644 --- a/libraries/fbx/src/OBJSerializer.h +++ b/libraries/fbx/src/OBJSerializer.h @@ -101,7 +101,7 @@ public: QString currentMaterialName; QHash materials; - HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) override; + HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; private: QUrl _url; diff --git a/libraries/hfm/src/hfm/HFMSerializer.h b/libraries/hfm/src/hfm/HFMSerializer.h index 3cd48b76b2..6bac9980d2 100644 --- a/libraries/hfm/src/hfm/HFMSerializer.h +++ b/libraries/hfm/src/hfm/HFMSerializer.h @@ -21,7 +21,7 @@ namespace hfm { class Serializer { - virtual Model* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl(), bool combineParts = false) = 0; + virtual Model* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) = 0; }; }; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 507ee23f7c..0ea3ff80ad 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -195,23 +195,26 @@ void GeometryReader::run() { HFMModel::Pointer hfmModel; + QVariantHash serializerMapping = _mapping; + serializerMapping["combineParts"] = _combineParts; + if (_url.path().toLower().endsWith(".fbx")) { - hfmModel.reset(FBXSerializer().read(_data, _mapping, _url.path())); + hfmModel.reset(FBXSerializer().read(_data, serializerMapping, _url)); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported FBX version"); } } else if (_url.path().toLower().endsWith(".obj")) { - hfmModel.reset(OBJSerializer().read(_data, _mapping, _url, _combineParts)); + hfmModel.reset(OBJSerializer().read(_data, serializerMapping, _url)); } else if (_url.path().toLower().endsWith(".obj.gz")) { QByteArray uncompressedData; if (gunzip(_data, uncompressedData)){ - hfmModel.reset(OBJSerializer().read(uncompressedData, _mapping, _url, _combineParts)); + hfmModel.reset(OBJSerializer().read(uncompressedData, serializerMapping, _url)); } else { throw QString("failed to decompress .obj.gz"); } } else if (_url.path().toLower().endsWith(".gltf")) { - hfmModel.reset(GLTFSerializer().read(_data, _mapping, _url)); + hfmModel.reset(GLTFSerializer().read(_data, serializerMapping, _url)); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported GLTF version"); } diff --git a/tools/vhacd-util/src/VHACDUtil.cpp b/tools/vhacd-util/src/VHACDUtil.cpp index 4036dbefa7..c72b2dff75 100644 --- a/tools/vhacd-util/src/VHACDUtil.cpp +++ b/tools/vhacd-util/src/VHACDUtil.cpp @@ -43,8 +43,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) { QByteArray fbxContents = fbx.readAll(); HFMModel::Pointer hfmModel; if (filename.toLower().endsWith(".obj")) { - bool combineParts = false; - hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename, combineParts)); + hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename)); } else if (filename.toLower().endsWith(".fbx")) { hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), filename)); } else { From 5a9af5b2c3982fb542949f587743e1e54fc3563f Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Thu, 8 Nov 2018 17:25:14 -0800 Subject: [PATCH 06/11] Correct the folder location in the FBXSerializer header/source top comment --- libraries/fbx/src/FBXSerializer.cpp | 2 +- libraries/fbx/src/FBXSerializer.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index ebd105706b..b0410d4e52 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1,6 +1,6 @@ // // FBXSerializer.cpp -// interface/src/renderer +// libraries/fbx/src // // Created by Andrzej Kapolka on 9/18/13. // Copyright 2013 High Fidelity, Inc. diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index a4832e61e9..b079baf1bd 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -1,6 +1,6 @@ // // FBXSerializer.h -// interface/src/renderer +// libraries/fbx/src // // Created by Andrzej Kapolka on 9/18/13. // Copyright 2013 High Fidelity, Inc. From f971294d6db0f7f12bf3e67ae0a6af397e7733e9 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 9 Nov 2018 09:21:02 -0800 Subject: [PATCH 07/11] Make HFMSerializer return a smart pointer to an HFMModel --- interface/src/ModelPackager.cpp | 2 +- interface/src/ModelPackager.h | 2 +- libraries/animation/src/AnimationCache.cpp | 2 +- libraries/fbx/src/FBXSerializer.cpp | 4 ++-- libraries/fbx/src/FBXSerializer.h | 2 +- libraries/fbx/src/GLTFSerializer.cpp | 4 ++-- libraries/fbx/src/GLTFSerializer.h | 2 +- libraries/fbx/src/OBJSerializer.cpp | 4 ++-- libraries/fbx/src/OBJSerializer.h | 2 +- libraries/hfm/src/hfm/HFMSerializer.h | 2 +- .../model-networking/src/model-networking/ModelCache.cpp | 8 ++++---- tests-manual/gpu/src/TestFbx.cpp | 3 +-- tools/skeleton-dump/src/SkeletonDumpApp.cpp | 2 +- tools/vhacd-util/src/VHACDUtil.cpp | 4 ++-- 14 files changed, 21 insertions(+), 22 deletions(-) diff --git a/interface/src/ModelPackager.cpp b/interface/src/ModelPackager.cpp index 5d7d4b1396..5b3b53a40c 100644 --- a/interface/src/ModelPackager.cpp +++ b/interface/src/ModelPackager.cpp @@ -109,7 +109,7 @@ bool ModelPackager::loadModel() { qCDebug(interfaceapp) << "Reading FBX file : " << _fbxInfo.filePath(); QByteArray fbxContents = fbx.readAll(); - _hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath())); + _hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), _fbxInfo.filePath()); // make sure we have some basic mappings populateBasicMapping(_mapping, _fbxInfo.filePath(), *_hfmModel); diff --git a/interface/src/ModelPackager.h b/interface/src/ModelPackager.h index 849f6ac3da..a2c23bfa74 100644 --- a/interface/src/ModelPackager.h +++ b/interface/src/ModelPackager.h @@ -46,7 +46,7 @@ private: QString _scriptDir; QVariantHash _mapping; - std::unique_ptr _hfmModel; + std::shared_ptr _hfmModel; QStringList _textures; QStringList _scripts; }; diff --git a/libraries/animation/src/AnimationCache.cpp b/libraries/animation/src/AnimationCache.cpp index 5c9f083a3b..c9911d938f 100644 --- a/libraries/animation/src/AnimationCache.cpp +++ b/libraries/animation/src/AnimationCache.cpp @@ -71,7 +71,7 @@ void AnimationReader::run() { // Parse the FBX directly from the QNetworkReply HFMModel::Pointer hfmModel; if (_url.path().toLower().endsWith(".fbx")) { - hfmModel.reset(FBXSerializer().read(_data, QVariantHash(), _url.path())); + hfmModel = FBXSerializer().read(_data, QVariantHash(), _url.path()); } else { QString errorStr("usupported format"); emit onError(299, errorStr); diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index b0410d4e52..c5c0b94f9b 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1796,10 +1796,10 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr return hfmModelPtr; } -HFMModel* FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { +HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { QBuffer buffer(const_cast(&data)); buffer.open(QIODevice::ReadOnly); - return read(&buffer, mapping, url); + return HFMModel::Pointer(read(&buffer, mapping, url)); } HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url) { diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index b079baf1bd..89f815ec1e 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -103,7 +103,7 @@ public: HFMModel* _hfmModel; /// Reads HFMModel from the supplied model and mapping data. /// \exception QString if an error occurs in parsing - HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; + HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl()); FBXNode _rootNode; diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/fbx/src/GLTFSerializer.cpp index 17b1189eae..b4082f222a 100644 --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/fbx/src/GLTFSerializer.cpp @@ -910,7 +910,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const QUrl& url) { return true; } -HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { +HFMModel::Pointer GLTFSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { _url = url; @@ -923,7 +923,7 @@ HFMModel* GLTFSerializer::read(const QByteArray& data, const QVariantHash& mappi parseGLTF(data); //_file.dump(); - HFMModel* hfmModelPtr = new HFMModel(); + auto hfmModelPtr = std::make_shared(); HFMModel& hfmModel = *hfmModelPtr; buildGeometry(hfmModel, _url); diff --git a/libraries/fbx/src/GLTFSerializer.h b/libraries/fbx/src/GLTFSerializer.h index 86e31d23dd..f5fc360326 100644 --- a/libraries/fbx/src/GLTFSerializer.h +++ b/libraries/fbx/src/GLTFSerializer.h @@ -707,7 +707,7 @@ class GLTFSerializer : public QObject, public HFMSerializer { Q_OBJECT public: GLTFSerializer(); - HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; + HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; private: GLTFFile _file; QUrl _url; diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/fbx/src/OBJSerializer.cpp index fb9b882940..e8b517da6b 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/fbx/src/OBJSerializer.cpp @@ -652,12 +652,12 @@ done: } -HFMModel* OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { +HFMModel::Pointer OBJSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { PROFILE_RANGE_EX(resource_parse, __FUNCTION__, 0xffff0000, nullptr); QBuffer buffer { const_cast(&data) }; buffer.open(QIODevice::ReadOnly); - auto hfmModelPtr = new HFMModel(); + auto hfmModelPtr = std::make_shared(); HFMModel& hfmModel { *hfmModelPtr }; OBJTokenizer tokenizer { &buffer }; float scaleGuess = 1.0f; diff --git a/libraries/fbx/src/OBJSerializer.h b/libraries/fbx/src/OBJSerializer.h index 82bd2705df..a6fe3817ca 100644 --- a/libraries/fbx/src/OBJSerializer.h +++ b/libraries/fbx/src/OBJSerializer.h @@ -101,7 +101,7 @@ public: QString currentMaterialName; QHash materials; - HFMModel* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; + HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; private: QUrl _url; diff --git a/libraries/hfm/src/hfm/HFMSerializer.h b/libraries/hfm/src/hfm/HFMSerializer.h index 6bac9980d2..424b340a6c 100644 --- a/libraries/hfm/src/hfm/HFMSerializer.h +++ b/libraries/hfm/src/hfm/HFMSerializer.h @@ -21,7 +21,7 @@ namespace hfm { class Serializer { - virtual Model* read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) = 0; + virtual Model::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) = 0; }; }; diff --git a/libraries/model-networking/src/model-networking/ModelCache.cpp b/libraries/model-networking/src/model-networking/ModelCache.cpp index 0ea3ff80ad..abca3488f6 100644 --- a/libraries/model-networking/src/model-networking/ModelCache.cpp +++ b/libraries/model-networking/src/model-networking/ModelCache.cpp @@ -199,22 +199,22 @@ void GeometryReader::run() { serializerMapping["combineParts"] = _combineParts; if (_url.path().toLower().endsWith(".fbx")) { - hfmModel.reset(FBXSerializer().read(_data, serializerMapping, _url)); + hfmModel = FBXSerializer().read(_data, serializerMapping, _url); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported FBX version"); } } else if (_url.path().toLower().endsWith(".obj")) { - hfmModel.reset(OBJSerializer().read(_data, serializerMapping, _url)); + hfmModel = OBJSerializer().read(_data, serializerMapping, _url); } else if (_url.path().toLower().endsWith(".obj.gz")) { QByteArray uncompressedData; if (gunzip(_data, uncompressedData)){ - hfmModel.reset(OBJSerializer().read(uncompressedData, serializerMapping, _url)); + hfmModel = OBJSerializer().read(uncompressedData, serializerMapping, _url); } else { throw QString("failed to decompress .obj.gz"); } } else if (_url.path().toLower().endsWith(".gltf")) { - hfmModel.reset(GLTFSerializer().read(_data, serializerMapping, _url)); + hfmModel = GLTFSerializer().read(_data, serializerMapping, _url); if (hfmModel->meshes.size() == 0 && hfmModel->joints.size() == 0) { throw QString("empty geometry, possibly due to an unsupported GLTF version"); } diff --git a/tests-manual/gpu/src/TestFbx.cpp b/tests-manual/gpu/src/TestFbx.cpp index 379481baa8..d3eab9e8e3 100644 --- a/tests-manual/gpu/src/TestFbx.cpp +++ b/tests-manual/gpu/src/TestFbx.cpp @@ -100,7 +100,7 @@ bool TestFbx::isReady() const { void TestFbx::parseFbx(const QByteArray& fbxData) { QVariantHash mapping; - HFMModel* hfmModel = FBXSerializer().read(fbxData, mapping); + HFMModel::Pointer hfmModel = FBXSerializer().read(fbxData, mapping); size_t totalVertexCount = 0; size_t totalIndexCount = 0; size_t totalPartCount = 0; @@ -163,7 +163,6 @@ void TestFbx::parseFbx(const QByteArray& fbxData) { _vertexBuffer->append(vertices); _indexBuffer->append(indices); _indirectBuffer->append(parts); - delete hfmModel; } void TestFbx::renderTest(size_t testId, RenderArgs* args) { diff --git a/tools/skeleton-dump/src/SkeletonDumpApp.cpp b/tools/skeleton-dump/src/SkeletonDumpApp.cpp index cbee73528f..42a1c78090 100644 --- a/tools/skeleton-dump/src/SkeletonDumpApp.cpp +++ b/tools/skeleton-dump/src/SkeletonDumpApp.cpp @@ -54,7 +54,7 @@ SkeletonDumpApp::SkeletonDumpApp(int argc, char* argv[]) : QCoreApplication(argc return; } QByteArray blob = file.readAll(); - std::unique_ptr geometry(FBXSerializer().read(blob, QVariantHash())); + HFMModel::Pointer geometry = FBXSerializer().read(blob, QVariantHash()); std::unique_ptr skeleton(new AnimSkeleton(*geometry)); skeleton->dump(verbose); } diff --git a/tools/vhacd-util/src/VHACDUtil.cpp b/tools/vhacd-util/src/VHACDUtil.cpp index c72b2dff75..89794bf40a 100644 --- a/tools/vhacd-util/src/VHACDUtil.cpp +++ b/tools/vhacd-util/src/VHACDUtil.cpp @@ -43,9 +43,9 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, HFMModel& result) { QByteArray fbxContents = fbx.readAll(); HFMModel::Pointer hfmModel; if (filename.toLower().endsWith(".obj")) { - hfmModel.reset(OBJSerializer().read(fbxContents, QVariantHash(), filename)); + hfmModel = OBJSerializer().read(fbxContents, QVariantHash(), filename); } else if (filename.toLower().endsWith(".fbx")) { - hfmModel.reset(FBXSerializer().read(fbxContents, QVariantHash(), filename)); + hfmModel = FBXSerializer().read(fbxContents, QVariantHash(), filename); } else { qWarning() << "file has unknown extension" << filename; return false; From 8e0fb0f9c440c378b1456d8b60bc850c2eb90114 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 9 Nov 2018 10:52:45 -0800 Subject: [PATCH 08/11] Remove unused alternate read functions in FBXSerializer --- libraries/fbx/src/FBXSerializer.cpp | 11 ++--------- libraries/fbx/src/FBXSerializer.h | 5 ----- 2 files changed, 2 insertions(+), 14 deletions(-) diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/fbx/src/FBXSerializer.cpp index c5c0b94f9b..9f5867feda 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/fbx/src/FBXSerializer.cpp @@ -1799,17 +1799,10 @@ HFMModel* FBXSerializer::extractHFMModel(const QVariantHash& mapping, const QStr HFMModel::Pointer FBXSerializer::read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url) { QBuffer buffer(const_cast(&data)); buffer.open(QIODevice::ReadOnly); - return HFMModel::Pointer(read(&buffer, mapping, url)); -} -HFMModel* FBXSerializer::read(QIODevice* device, const QVariantHash& mapping, const QUrl& url) { - _rootNode = parseFBX(device); + _rootNode = parseFBX(&buffer); qCDebug(modelformat) << "Reading FBX: " << url; - return extractHFMModel(mapping, url.toString()); -} - -HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url, bool loadLightmaps, float lightmapLevel) { - return FBXSerializer().extractHFMModel(mapping, url); + return HFMModel::Pointer(extractHFMModel(mapping, url.toString())); } diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/fbx/src/FBXSerializer.h index 89f815ec1e..c69f75cc5c 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/fbx/src/FBXSerializer.h @@ -35,10 +35,6 @@ class QIODevice; class FBXNode; -/// Reads HFMModel from the supplied model and mapping data. -/// \exception QString if an error occurs in parsing -HFMModel* readFBX(QIODevice* device, const QVariantHash& mapping, const QString& url = "", bool loadLightmaps = true, float lightmapLevel = 1.0f); - class TextureParam { public: glm::vec2 UVTranslation; @@ -104,7 +100,6 @@ public: /// Reads HFMModel from the supplied model and mapping data. /// \exception QString if an error occurs in parsing HFMModel::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) override; - HFMModel* read(QIODevice* device, const QVariantHash& mapping, const QUrl& url = QUrl()); FBXNode _rootNode; static FBXNode parseFBX(QIODevice* device); From 5b6e2aae5a85d9d4ff445ba38e088616199d6606 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Fri, 9 Nov 2018 11:07:45 -0800 Subject: [PATCH 09/11] Remove/move some unused serializer imports --- interface/src/ModelPackager.cpp | 1 + interface/src/ModelPropertiesDialog.h | 2 +- libraries/baking/src/ModelBaker.cpp | 1 - tools/vhacd-util/src/VHACDUtil.cpp | 2 ++ tools/vhacd-util/src/VHACDUtil.h | 4 ++-- 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/interface/src/ModelPackager.cpp b/interface/src/ModelPackager.cpp index 5b3b53a40c..7e63085d1d 100644 --- a/interface/src/ModelPackager.cpp +++ b/interface/src/ModelPackager.cpp @@ -17,6 +17,7 @@ #include #include +#include #include #include "ModelSelector.h" diff --git a/interface/src/ModelPropertiesDialog.h b/interface/src/ModelPropertiesDialog.h index 7068d5cb76..7c0f9d86c1 100644 --- a/interface/src/ModelPropertiesDialog.h +++ b/interface/src/ModelPropertiesDialog.h @@ -14,7 +14,7 @@ #include -#include +#include #include #include "ui/ModelsBrowser.h" diff --git a/libraries/baking/src/ModelBaker.cpp b/libraries/baking/src/ModelBaker.cpp index 646f1bc010..34f302b501 100644 --- a/libraries/baking/src/ModelBaker.cpp +++ b/libraries/baking/src/ModelBaker.cpp @@ -13,7 +13,6 @@ #include -#include #include #ifdef _WIN32 diff --git a/tools/vhacd-util/src/VHACDUtil.cpp b/tools/vhacd-util/src/VHACDUtil.cpp index 89794bf40a..9401da4314 100644 --- a/tools/vhacd-util/src/VHACDUtil.cpp +++ b/tools/vhacd-util/src/VHACDUtil.cpp @@ -15,6 +15,8 @@ #include #include +#include +#include // FBXSerializer jumbles the order of the meshes by reading them back out of a hashtable. This will put diff --git a/tools/vhacd-util/src/VHACDUtil.h b/tools/vhacd-util/src/VHACDUtil.h index 7a6f2f1db6..0fb70e8af7 100644 --- a/tools/vhacd-util/src/VHACDUtil.h +++ b/tools/vhacd-util/src/VHACDUtil.h @@ -18,10 +18,10 @@ #include #include //c++11 feature #include -#include -#include #include +#include + namespace vhacd { class VHACDUtil { public: From 93c7578f54519cf168b4a7f53d8b3851b098f644 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Mon, 12 Nov 2018 14:33:16 -0800 Subject: [PATCH 10/11] Convert hfm::Serializer to use hifi-namespaced types --- libraries/hfm/src/hfm/HFMSerializer.h | 6 ++---- libraries/shared/src/shared/HifiTypes.h | 25 +++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 4 deletions(-) create mode 100644 libraries/shared/src/shared/HifiTypes.h diff --git a/libraries/hfm/src/hfm/HFMSerializer.h b/libraries/hfm/src/hfm/HFMSerializer.h index 424b340a6c..db18f21e06 100644 --- a/libraries/hfm/src/hfm/HFMSerializer.h +++ b/libraries/hfm/src/hfm/HFMSerializer.h @@ -12,16 +12,14 @@ #ifndef hifi_HFMSerializer_h #define hifi_HFMSerializer_h -#include -#include -#include +#include #include "HFM.h" namespace hfm { class Serializer { - virtual Model::Pointer read(const QByteArray& data, const QVariantHash& mapping, const QUrl& url = QUrl()) = 0; + virtual Model::Pointer read(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url = hifi::URL()) = 0; }; }; diff --git a/libraries/shared/src/shared/HifiTypes.h b/libraries/shared/src/shared/HifiTypes.h new file mode 100644 index 0000000000..500170c88b --- /dev/null +++ b/libraries/shared/src/shared/HifiTypes.h @@ -0,0 +1,25 @@ +// +// HifiTypes.h +// libraries/shared/src/shared +// +// Created by Sabrina Shanman on 2018/11/12. +// Copyright 2018 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 +// + +#ifndef hifi_HifiTypes_h +#define hifi_HifiTypes_h + +#include +#include +#include + +namespace hifi { + using ByteArray = QByteArray; + using VariantHash = QVariantHash; + using URL = QUrl; +}; + +#endif // hifi_HifiTypes_h From 2d309028133adaf845a168fe43c69d7a66928300 Mon Sep 17 00:00:00 2001 From: sabrina-shanman Date: Wed, 14 Nov 2018 09:11:56 -0800 Subject: [PATCH 11/11] Fix OBJBaker not setting combineParts --- libraries/baking/src/OBJBaker.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libraries/baking/src/OBJBaker.cpp b/libraries/baking/src/OBJBaker.cpp index ae29a82c28..5a1239f88f 100644 --- a/libraries/baking/src/OBJBaker.cpp +++ b/libraries/baking/src/OBJBaker.cpp @@ -143,9 +143,10 @@ void OBJBaker::bakeOBJ() { QByteArray objData = objFile.readAll(); - bool combineParts = true; // set true so that OBJSerializer reads material info from material library OBJSerializer serializer; - auto geometry = serializer.read(objData, QVariantHash(), _modelURL); + QVariantHash mapping; + mapping["combineParts"] = true; // set true so that OBJSerializer reads material info from material library + auto geometry = serializer.read(objData, mapping, _modelURL); // Write OBJ Data as FBX tree nodes createFBXNodeTree(_rootNode, *geometry);