From ecb7c47f1a5a55538831988838dda4b8effaa13b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gro=C3=9F?= Date: Thu, 15 Apr 2021 19:26:10 +0200 Subject: [PATCH 1/5] Rename fbx folder to model-serializers --- assignment-client/CMakeLists.txt | 2 +- interface/CMakeLists.txt | 2 +- libraries/animation/CMakeLists.txt | 2 +- libraries/baking/CMakeLists.txt | 4 +- libraries/graphics-scripting/CMakeLists.txt | 2 +- libraries/model-networking/CMakeLists.txt | 4 +- .../{fbx => model-serializers}/CMakeLists.txt | 2 +- .../{fbx => model-serializers}/src/FBX.h | 2 +- .../src/FBXSerializer.cpp | 6 +- .../src/FBXSerializer.h | 6 +- .../src/FBXSerializer_Material.cpp | 2 +- .../src/FBXSerializer_Mesh.cpp | 20 +-- .../src/FBXSerializer_Node.cpp | 8 +- .../src/FBXToJSON.cpp | 6 +- .../src/FBXToJSON.h | 2 +- .../src/FBXWriter.cpp | 2 +- .../src/FBXWriter.h | 2 +- .../{fbx => model-serializers}/src/FST.cpp | 0 .../{fbx => model-serializers}/src/FST.h | 0 .../src/FSTReader.cpp | 0 .../src/FSTReader.h | 0 .../src/GLTFSerializer.cpp | 157 ++++++++---------- .../src/GLTFSerializer.h | 40 ++--- .../src/OBJSerializer.cpp | 28 ++-- .../src/OBJSerializer.h | 6 +- .../src/OBJWriter.cpp | 2 +- .../src/OBJWriter.h | 2 +- libraries/render-utils/CMakeLists.txt | 2 +- libraries/script-engine/CMakeLists.txt | 2 +- plugins/openvr/CMakeLists.txt | 4 +- tools/oven/CMakeLists.txt | 2 +- tools/skeleton-dump/CMakeLists.txt | 2 +- tools/vhacd-util/CMakeLists.txt | 2 +- 33 files changed, 156 insertions(+), 167 deletions(-) rename libraries/{fbx => model-serializers}/CMakeLists.txt (79%) rename libraries/{fbx => model-serializers}/src/FBX.h (97%) rename libraries/{fbx => model-serializers}/src/FBXSerializer.cpp (99%) rename libraries/{fbx => model-serializers}/src/FBXSerializer.h (99%) rename libraries/{fbx => model-serializers}/src/FBXSerializer_Material.cpp (99%) rename libraries/{fbx => model-serializers}/src/FBXSerializer_Mesh.cpp (99%) rename libraries/{fbx => model-serializers}/src/FBXSerializer_Node.cpp (99%) rename libraries/{fbx => model-serializers}/src/FBXToJSON.cpp (98%) rename libraries/{fbx => model-serializers}/src/FBXToJSON.h (95%) rename libraries/{fbx => model-serializers}/src/FBXWriter.cpp (99%) rename libraries/{fbx => model-serializers}/src/FBXWriter.h (94%) rename libraries/{fbx => model-serializers}/src/FST.cpp (100%) rename libraries/{fbx => model-serializers}/src/FST.h (100%) rename libraries/{fbx => model-serializers}/src/FSTReader.cpp (100%) rename libraries/{fbx => model-serializers}/src/FSTReader.h (100%) rename libraries/{fbx => model-serializers}/src/GLTFSerializer.cpp (98%) mode change 100755 => 100644 rename libraries/{fbx => model-serializers}/src/GLTFSerializer.h (98%) mode change 100755 => 100644 rename libraries/{fbx => model-serializers}/src/OBJSerializer.cpp (99%) rename libraries/{fbx => model-serializers}/src/OBJSerializer.h (99%) rename libraries/{fbx => model-serializers}/src/OBJWriter.cpp (99%) rename libraries/{fbx => model-serializers}/src/OBJWriter.h (94%) diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 285c3221f8..abb94f95e3 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -12,7 +12,7 @@ setup_thread_debugger() # link in the shared libraries link_hifi_libraries( - audio avatars octree gpu graphics shaders fbx hfm entities + audio avatars octree gpu graphics shaders model-serializers hfm entities networking animation recording shared script-engine embedded-webserver controllers physics plugins midi image material-networking model-networking ktx shaders diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 6e4837527e..b8ff86959a 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -219,7 +219,7 @@ endif() # link required hifi libraries link_hifi_libraries( shared workload task octree ktx gpu gl procedural graphics graphics-scripting render - pointers recording hfm fbx networking material-networking + pointers recording hfm model-serializers networking material-networking model-networking model-baker entities avatars audio audio-client animation script-engine physics render-utils entities-renderer avatars-renderer ui qml auto-updater midi diff --git a/libraries/animation/CMakeLists.txt b/libraries/animation/CMakeLists.txt index 1ab54ed342..d962d9e222 100644 --- a/libraries/animation/CMakeLists.txt +++ b/libraries/animation/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET_NAME animation) setup_hifi_library(Network Script) -link_hifi_libraries(shared graphics fbx) +link_hifi_libraries(shared graphics model-serializers) include_hifi_library_headers(networking) include_hifi_library_headers(gpu) include_hifi_library_headers(hfm) diff --git a/libraries/baking/CMakeLists.txt b/libraries/baking/CMakeLists.txt index 4350f386ab..12fb192877 100644 --- a/libraries/baking/CMakeLists.txt +++ b/libraries/baking/CMakeLists.txt @@ -1,7 +1,7 @@ set(TARGET_NAME baking) setup_hifi_library(Concurrent) -link_hifi_libraries(shared shaders graphics networking procedural graphics-scripting ktx image fbx model-baker task) +link_hifi_libraries(shared shaders graphics networking procedural graphics-scripting ktx image model-serializers model-baker task) include_hifi_library_headers(gpu) include_hifi_library_headers(hfm) -include_hifi_library_headers(material-networking) \ No newline at end of file +include_hifi_library_headers(material-networking) diff --git a/libraries/graphics-scripting/CMakeLists.txt b/libraries/graphics-scripting/CMakeLists.txt index 9bb34adda1..3542704fc8 100644 --- a/libraries/graphics-scripting/CMakeLists.txt +++ b/libraries/graphics-scripting/CMakeLists.txt @@ -1,4 +1,4 @@ set(TARGET_NAME graphics-scripting) setup_hifi_library() -link_hifi_libraries(shared networking graphics fbx image material-networking model-networking script-engine) +link_hifi_libraries(shared networking graphics model-serializers image material-networking model-networking script-engine) include_hifi_library_headers(gpu) diff --git a/libraries/model-networking/CMakeLists.txt b/libraries/model-networking/CMakeLists.txt index b71d125586..9a7ce47b8e 100644 --- a/libraries/model-networking/CMakeLists.txt +++ b/libraries/model-networking/CMakeLists.txt @@ -1,9 +1,9 @@ set(TARGET_NAME model-networking) setup_hifi_library() -link_hifi_libraries(shared shaders networking graphics fbx procedural model-baker) +link_hifi_libraries(shared shaders networking graphics model-serializers procedural model-baker) include_hifi_library_headers(hfm) include_hifi_library_headers(task) include_hifi_library_headers(gpu) include_hifi_library_headers(image) include_hifi_library_headers(ktx) -include_hifi_library_headers(material-networking) \ No newline at end of file +include_hifi_library_headers(material-networking) diff --git a/libraries/fbx/CMakeLists.txt b/libraries/model-serializers/CMakeLists.txt similarity index 79% rename from libraries/fbx/CMakeLists.txt rename to libraries/model-serializers/CMakeLists.txt index 2006d23c60..76775896dc 100644 --- a/libraries/fbx/CMakeLists.txt +++ b/libraries/model-serializers/CMakeLists.txt @@ -1,4 +1,4 @@ -set(TARGET_NAME fbx) +set(TARGET_NAME model-serializers) setup_hifi_library() link_hifi_libraries(shared graphics networking image hfm) diff --git a/libraries/fbx/src/FBX.h b/libraries/model-serializers/src/FBX.h similarity index 97% rename from libraries/fbx/src/FBX.h rename to libraries/model-serializers/src/FBX.h index 362ae93e99..3c4234e14b 100644 --- a/libraries/fbx/src/FBX.h +++ b/libraries/model-serializers/src/FBX.h @@ -1,6 +1,6 @@ // // FBX.h -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Ryan Huffman on 9/5/17. // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/fbx/src/FBXSerializer.cpp b/libraries/model-serializers/src/FBXSerializer.cpp similarity index 99% rename from libraries/fbx/src/FBXSerializer.cpp rename to libraries/model-serializers/src/FBXSerializer.cpp index 9c700be607..a18e305a80 100644 --- a/libraries/fbx/src/FBXSerializer.cpp +++ b/libraries/model-serializers/src/FBXSerializer.cpp @@ -1,6 +1,6 @@ // // FBXSerializer.cpp -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Andrzej Kapolka on 9/18/13. // Copyright 2013 High Fidelity, Inc. @@ -404,7 +404,7 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const QVector blendshapes; QHash fbxModels; - QHash clusters; + QHash clusters; QHash animationCurves; QHash typeFlags; @@ -1236,7 +1236,7 @@ HFMModel* FBXSerializer::extractHFMModel(const hifi::VariantHash& mapping, const // models with clusters must be parented to the cluster top // Unless the model is a root node. bool isARootNode = !modelIDs.contains(_connectionParentMap.value(fbxModel.key())); - if (!isARootNode) { + if (!isARootNode) { foreach(const QString& deformerID, _connectionChildMap.values(fbxModel.key())) { foreach(const QString& clusterID, _connectionChildMap.values(deformerID)) { if (!clusters.contains(clusterID)) { diff --git a/libraries/fbx/src/FBXSerializer.h b/libraries/model-serializers/src/FBXSerializer.h similarity index 99% rename from libraries/fbx/src/FBXSerializer.h rename to libraries/model-serializers/src/FBXSerializer.h index 7d41f98444..e528885754 100644 --- a/libraries/fbx/src/FBXSerializer.h +++ b/libraries/model-serializers/src/FBXSerializer.h @@ -1,6 +1,6 @@ // // FBXSerializer.h -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Andrzej Kapolka on 9/18/13. // Copyright 2013 High Fidelity, Inc. @@ -69,7 +69,7 @@ public: useMaterial(true), isDefault(true) {} - + TextureParam(const TextureParam& src) : cropping(src.cropping), UVSet(src.UVSet), @@ -81,7 +81,7 @@ public: useMaterial(src.useMaterial), isDefault(src.isDefault) {} - + }; class MaterialParam { diff --git a/libraries/fbx/src/FBXSerializer_Material.cpp b/libraries/model-serializers/src/FBXSerializer_Material.cpp similarity index 99% rename from libraries/fbx/src/FBXSerializer_Material.cpp rename to libraries/model-serializers/src/FBXSerializer_Material.cpp index 8b170eba1b..81f9ca45e3 100644 --- a/libraries/fbx/src/FBXSerializer_Material.cpp +++ b/libraries/model-serializers/src/FBXSerializer_Material.cpp @@ -1,6 +1,6 @@ // // FBXSerializer_Material.cpp -// interface/src/fbx +// libraries/model-serializers/src // // Created by Sam Gateau on 8/27/2015. // Copyright 2015 High Fidelity, Inc. diff --git a/libraries/fbx/src/FBXSerializer_Mesh.cpp b/libraries/model-serializers/src/FBXSerializer_Mesh.cpp similarity index 99% rename from libraries/fbx/src/FBXSerializer_Mesh.cpp rename to libraries/model-serializers/src/FBXSerializer_Mesh.cpp index f74a960dc8..8d270d8320 100644 --- a/libraries/fbx/src/FBXSerializer_Mesh.cpp +++ b/libraries/model-serializers/src/FBXSerializer_Mesh.cpp @@ -1,6 +1,6 @@ // // FBXSerializer_Mesh.cpp -// interface/src/fbx +// libraries/model-serializers/src // // Created by Sam Gateau on 8/27/2015. // Copyright 2015 High Fidelity, Inc. @@ -106,7 +106,7 @@ void appendIndex(MeshData& data, QVector& indices, int index, bool deduplic } Vertex vertex; vertex.originalIndex = vertexIndex; - + glm::vec3 position; if (vertexIndex < data.vertices.size()) { position = data.vertices.at(vertexIndex); @@ -114,7 +114,7 @@ void appendIndex(MeshData& data, QVector& indices, int index, bool deduplic glm::vec3 normal; int normalIndex = data.normalsByVertex ? vertexIndex : index; - if (data.normalIndices.isEmpty()) { + if (data.normalIndices.isEmpty()) { if (normalIndex < data.normals.size()) { normal = data.normals.at(normalIndex); } @@ -130,7 +130,7 @@ void appendIndex(MeshData& data, QVector& indices, int index, bool deduplic bool hasColors = (data.colors.size() > 0); if (hasColors) { int colorIndex = data.colorsByVertex ? vertexIndex : index; - if (data.colorIndices.isEmpty()) { + if (data.colorIndices.isEmpty()) { if (colorIndex < data.colors.size()) { color = data.colors.at(colorIndex); } @@ -152,7 +152,7 @@ void appendIndex(MeshData& data, QVector& indices, int index, bool deduplic vertex.texCoord = data.texCoords.at(texCoordIndex); } } - + bool hasMoreTexcoords = (data.attributes.size() > 1); if (hasMoreTexcoords) { if (data.attributes[1].texCoordIndices.empty()) { @@ -222,7 +222,7 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me } else if (subdata.name == "MappingInformationType" && subdata.properties.at(0) == BY_VERTICE) { data.normalsByVertex = true; - + } else if (subdata.name == "ReferenceInformationType" && subdata.properties.at(0) == INDEX_TO_DIRECT) { indexToDirect = true; } @@ -242,7 +242,7 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me } else if (subdata.name == "MappingInformationType" && subdata.properties.at(0) == BY_VERTICE) { data.colorsByVertex = true; - + } else if (subdata.name == "ReferenceInformationType" && subdata.properties.at(0) == INDEX_TO_DIRECT) { indexToDirect = true; } @@ -264,7 +264,7 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me qCDebug(modelformat) << "LayerElementColor has an average value of 0.0f... let's forget it."; } #endif - + } else if (child.name == "LayerElementUV") { if (child.properties.at(0).toInt() == 0) { AttributeData attrib; @@ -278,7 +278,7 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me attrib.texCoordIndices = getIntVector(subdata); } else if (subdata.name == "Name") { attrib.name = subdata.properties.at(0).toString(); - } + } #if defined(DEBUG_FBXSERIALIZER) else { int unknown = 0; @@ -579,6 +579,6 @@ ExtractedMesh FBXSerializer::extractMesh(const FBXNode& object, unsigned int& me } } } - + return data.extracted; } diff --git a/libraries/fbx/src/FBXSerializer_Node.cpp b/libraries/model-serializers/src/FBXSerializer_Node.cpp similarity index 99% rename from libraries/fbx/src/FBXSerializer_Node.cpp rename to libraries/model-serializers/src/FBXSerializer_Node.cpp index a2772d02d7..f662f10c1a 100644 --- a/libraries/fbx/src/FBXSerializer_Node.cpp +++ b/libraries/model-serializers/src/FBXSerializer_Node.cpp @@ -1,6 +1,6 @@ // // FBXSerializer_Node.cpp -// interface/src/fbx +// libraries/model-serializers/src // // Created by Sam Gateau on 8/27/2015. // Copyright 2015 High Fidelity, Inc. @@ -183,7 +183,7 @@ FBXNode parseBinaryFBXNode(QDataStream& in, int& position, bool has64BitPosition // FBX 2016 and beyond uses 64bit positions in the node headers, pre-2016 used 32bit values // our code generally doesn't care about the size that much, so we will use 64bit values - // from here on out, but if the file is an older format we read the stream into temp 32bit + // from here on out, but if the file is an older format we read the stream into temp 32bit // values and then assign to our actual 64bit values. if (has64BitPositions) { in >> endOffset; @@ -335,8 +335,8 @@ FBXNode parseTextFBXNode(Tokenizer& tokenizer) { if ((token = tokenizer.nextToken()) == ':') { tokenizer.ungetChar(':'); tokenizer.pushBackToken(Tokenizer::DATUM_TOKEN); - return node; - + return node; + } else { tokenizer.pushBackToken(token); node.properties.append(datum); diff --git a/libraries/fbx/src/FBXToJSON.cpp b/libraries/model-serializers/src/FBXToJSON.cpp similarity index 98% rename from libraries/fbx/src/FBXToJSON.cpp rename to libraries/model-serializers/src/FBXToJSON.cpp index 195b7f5f90..f7431e1f61 100644 --- a/libraries/fbx/src/FBXToJSON.cpp +++ b/libraries/model-serializers/src/FBXToJSON.cpp @@ -1,6 +1,6 @@ // // FBXToJSON.cpp -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Simon Walton on 5/4/2018. // Copyright 2018 High Fidelity, Inc. @@ -61,7 +61,7 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) { case QMetaType::QByteArray: *this << '"' << stringEscape(prop.toByteArray().toStdString()) << '"'; break; - + default: if (prop.canConvert>()) { *this << prop.value>(); @@ -95,7 +95,7 @@ FBXToJSON& FBXToJSON::operator<<(const FBXNode& fbxNode) { string FBXToJSON::stringEscape(const string& in) { string out; out.reserve(in.length()); - + for (unsigned char inChar: in) { if (inChar == '"') { out.append(R"(\")"); diff --git a/libraries/fbx/src/FBXToJSON.h b/libraries/model-serializers/src/FBXToJSON.h similarity index 95% rename from libraries/fbx/src/FBXToJSON.h rename to libraries/model-serializers/src/FBXToJSON.h index e6b8efe51d..f36235abca 100644 --- a/libraries/fbx/src/FBXToJSON.h +++ b/libraries/model-serializers/src/FBXToJSON.h @@ -1,6 +1,6 @@ // // FBXToJSON.h -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Simon Walton on 5/4/2018. // Copyright 2018 High Fidelity, Inc. diff --git a/libraries/fbx/src/FBXWriter.cpp b/libraries/model-serializers/src/FBXWriter.cpp similarity index 99% rename from libraries/fbx/src/FBXWriter.cpp rename to libraries/model-serializers/src/FBXWriter.cpp index 4504898e32..efc94461aa 100644 --- a/libraries/fbx/src/FBXWriter.cpp +++ b/libraries/model-serializers/src/FBXWriter.cpp @@ -1,6 +1,6 @@ // // FBXWriter.cpp -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Ryan Huffman on 9/5/17. // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/fbx/src/FBXWriter.h b/libraries/model-serializers/src/FBXWriter.h similarity index 94% rename from libraries/fbx/src/FBXWriter.h rename to libraries/model-serializers/src/FBXWriter.h index f20d208cb1..f7f4e647c6 100644 --- a/libraries/fbx/src/FBXWriter.h +++ b/libraries/model-serializers/src/FBXWriter.h @@ -1,6 +1,6 @@ // // FBXWriter.h -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Ryan Huffman on 9/5/17. // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/fbx/src/FST.cpp b/libraries/model-serializers/src/FST.cpp similarity index 100% rename from libraries/fbx/src/FST.cpp rename to libraries/model-serializers/src/FST.cpp diff --git a/libraries/fbx/src/FST.h b/libraries/model-serializers/src/FST.h similarity index 100% rename from libraries/fbx/src/FST.h rename to libraries/model-serializers/src/FST.h diff --git a/libraries/fbx/src/FSTReader.cpp b/libraries/model-serializers/src/FSTReader.cpp similarity index 100% rename from libraries/fbx/src/FSTReader.cpp rename to libraries/model-serializers/src/FSTReader.cpp diff --git a/libraries/fbx/src/FSTReader.h b/libraries/model-serializers/src/FSTReader.h similarity index 100% rename from libraries/fbx/src/FSTReader.h rename to libraries/model-serializers/src/FSTReader.h diff --git a/libraries/fbx/src/GLTFSerializer.cpp b/libraries/model-serializers/src/GLTFSerializer.cpp old mode 100755 new mode 100644 similarity index 98% rename from libraries/fbx/src/GLTFSerializer.cpp rename to libraries/model-serializers/src/GLTFSerializer.cpp index 0916316ec1..3c59e51b1b --- a/libraries/fbx/src/GLTFSerializer.cpp +++ b/libraries/model-serializers/src/GLTFSerializer.cpp @@ -1,6 +1,6 @@ // // GLTFSerializer.cpp -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Luis Cuenca on 8/30/17. // Copyright 2017 High Fidelity, Inc. @@ -148,7 +148,7 @@ bool GLTFSerializer::getObjectArrayVal(const QJsonObject& object, const QString& } hifi::ByteArray GLTFSerializer::setGLBChunks(const hifi::ByteArray& data) { - int byte = 4; + int byte = 4; int jsonStart = data.indexOf("JSON", Qt::CaseSensitive); int binStart = data.indexOf("BIN", Qt::CaseSensitive); int jsonLength, binLength; @@ -271,7 +271,7 @@ bool GLTFSerializer::setAsset(const QJsonObject& object) { QJsonObject jsAsset; bool isAssetDefined = getObjectVal(object, "asset", jsAsset, _file.defined); if (isAssetDefined) { - if (!getStringVal(jsAsset, "version", _file.asset.version, + if (!getStringVal(jsAsset, "version", _file.asset.version, _file.asset.defined) || _file.asset.version != "2.0") { return false; } @@ -318,7 +318,7 @@ GLTFAccessor::GLTFAccessorSparse GLTFSerializer::createAccessorSparse(const QJso bool GLTFSerializer::addAccessor(const QJsonObject& object) { GLTFAccessor accessor; - + getIntVal(object, "bufferView", accessor.bufferView, accessor.defined); getIntVal(object, "byteOffset", accessor.byteOffset, accessor.defined); getIntVal(object, "componentType", accessor.componentType, accessor.defined); @@ -344,7 +344,7 @@ bool GLTFSerializer::addAccessor(const QJsonObject& object) { bool GLTFSerializer::addAnimation(const QJsonObject& object) { GLTFAnimation animation; - + QJsonArray channels; if (getObjectArrayVal(object, "channels", channels, animation.defined)) { foreach(const QJsonValue & v, channels) { @@ -355,7 +355,7 @@ bool GLTFSerializer::addAnimation(const QJsonObject& object) { if (getObjectVal(v.toObject(), "target", jsChannel, channel.defined)) { getIntVal(jsChannel, "node", channel.target.node, channel.target.defined); getIntVal(jsChannel, "path", channel.target.path, channel.target.defined); - } + } } } } @@ -374,7 +374,7 @@ bool GLTFSerializer::addAnimation(const QJsonObject& object) { } } } - + _file.animations.push_back(animation); return true; @@ -382,20 +382,20 @@ bool GLTFSerializer::addAnimation(const QJsonObject& object) { bool GLTFSerializer::addBufferView(const QJsonObject& object) { GLTFBufferView bufferview; - + getIntVal(object, "buffer", bufferview.buffer, bufferview.defined); getIntVal(object, "byteLength", bufferview.byteLength, bufferview.defined); getIntVal(object, "byteOffset", bufferview.byteOffset, bufferview.defined); getIntVal(object, "target", bufferview.target, bufferview.defined); - + _file.bufferviews.push_back(bufferview); - + return true; } bool GLTFSerializer::addBuffer(const QJsonObject& object) { GLTFBuffer buffer; - + getIntVal(object, "byteLength", buffer.byteLength, buffer.defined); if (_url.path().endsWith("glb")) { @@ -411,13 +411,13 @@ bool GLTFSerializer::addBuffer(const QJsonObject& object) { } } _file.buffers.push_back(buffer); - + return true; } bool GLTFSerializer::addCamera(const QJsonObject& object) { GLTFCamera camera; - + QJsonObject jsPerspective; QJsonObject jsOrthographic; QString type; @@ -437,15 +437,15 @@ bool GLTFSerializer::addCamera(const QJsonObject& object) { } else if (getStringVal(object, "type", type, camera.defined)) { camera.type = getCameraType(type); } - + _file.cameras.push_back(camera); - + return true; } bool GLTFSerializer::addImage(const QJsonObject& object) { GLTFImage image; - + QString mime; getStringVal(object, "uri", image.uri, image.defined); if (image.uri.contains("data:image/png;base64,")) { @@ -455,9 +455,9 @@ bool GLTFSerializer::addImage(const QJsonObject& object) { } if (getStringVal(object, "mimeType", mime, image.defined)) { image.mimeType = getImageMimeType(mime); - } + } getIntVal(object, "bufferView", image.bufferView, image.defined); - + _file.images.push_back(image); return true; @@ -489,20 +489,20 @@ bool GLTFSerializer::addMaterial(const QJsonObject& object) { getDoubleVal(object, "alphaCutoff", material.alphaCutoff, material.defined); QJsonObject jsMetallicRoughness; if (getObjectVal(object, "pbrMetallicRoughness", jsMetallicRoughness, material.defined)) { - getDoubleArrayVal(jsMetallicRoughness, "baseColorFactor", - material.pbrMetallicRoughness.baseColorFactor, + getDoubleArrayVal(jsMetallicRoughness, "baseColorFactor", + material.pbrMetallicRoughness.baseColorFactor, material.pbrMetallicRoughness.defined); - getIndexFromObject(jsMetallicRoughness, "baseColorTexture", - material.pbrMetallicRoughness.baseColorTexture, + getIndexFromObject(jsMetallicRoughness, "baseColorTexture", + material.pbrMetallicRoughness.baseColorTexture, material.pbrMetallicRoughness.defined); - getDoubleVal(jsMetallicRoughness, "metallicFactor", - material.pbrMetallicRoughness.metallicFactor, + getDoubleVal(jsMetallicRoughness, "metallicFactor", + material.pbrMetallicRoughness.metallicFactor, material.pbrMetallicRoughness.defined); - getDoubleVal(jsMetallicRoughness, "roughnessFactor", - material.pbrMetallicRoughness.roughnessFactor, + getDoubleVal(jsMetallicRoughness, "roughnessFactor", + material.pbrMetallicRoughness.roughnessFactor, material.pbrMetallicRoughness.defined); - getIndexFromObject(jsMetallicRoughness, "metallicRoughnessTexture", - material.pbrMetallicRoughness.metallicRoughnessTexture, + getIndexFromObject(jsMetallicRoughness, "metallicRoughnessTexture", + material.pbrMetallicRoughness.metallicRoughnessTexture, material.pbrMetallicRoughness.defined); } _file.materials.push_back(material); @@ -524,7 +524,7 @@ bool GLTFSerializer::addMesh(const QJsonObject& object) { getIntVal(jsPrimitive, "mode", primitive.mode, primitive.defined); getIntVal(jsPrimitive, "indices", primitive.indices, primitive.defined); getIntVal(jsPrimitive, "material", primitive.material, primitive.defined); - + QJsonObject jsAttributes; if (getObjectVal(jsPrimitive, "attributes", jsAttributes, primitive.defined)) { QStringList attrKeys = jsAttributes.keys(); @@ -550,7 +550,7 @@ bool GLTFSerializer::addMesh(const QJsonObject& object) { primitive.targets.push_back(target); } } - } + } mesh.primitives.push_back(primitive); } } @@ -561,8 +561,8 @@ bool GLTFSerializer::addMesh(const QJsonObject& object) { if (getObjectVal(object, "extras", jsExtras, mesh.defined)) { QJsonArray jsTargetNames; if (getObjectArrayVal(jsExtras, "targetNames", jsTargetNames, extras.defined)) { - foreach (const QJsonValue& tarName, jsTargetNames) { - extras.targetNames.push_back(tarName.toString()); + foreach (const QJsonValue& tarName, jsTargetNames) { + extras.targetNames.push_back(tarName.toString()); } } mesh.extras = extras; @@ -575,7 +575,7 @@ bool GLTFSerializer::addMesh(const QJsonObject& object) { bool GLTFSerializer::addNode(const QJsonObject& object) { GLTFNode node; - + getStringVal(object, "name", node.name, node.defined); getIntVal(object, "camera", node.camera, node.defined); getIntVal(object, "mesh", node.mesh, node.defined); @@ -630,10 +630,10 @@ bool GLTFSerializer::addSkin(const QJsonObject& object) { } bool GLTFSerializer::addTexture(const QJsonObject& object) { - GLTFTexture texture; + GLTFTexture texture; getIntVal(object, "sampler", texture.sampler, texture.defined); getIntVal(object, "source", texture.source, texture.defined); - + _file.textures.push_back(texture); return true; @@ -646,8 +646,8 @@ bool GLTFSerializer::parseGLTF(const hifi::ByteArray& data) { if (_url.path().endsWith("glb") && data.indexOf("glTF") == 0 && data.contains("JSON")) { jsonChunk = setGLBChunks(data); - } - + } + QJsonDocument d = QJsonDocument::fromJson(jsonChunk); QJsonObject jsFile = d.object(); @@ -769,7 +769,7 @@ bool GLTFSerializer::parseGLTF(const hifi::ByteArray& data) { } } } - } + } return success; } @@ -789,13 +789,13 @@ glm::mat4 GLTFSerializer::getModelTransform(const GLTFNode& node) { s = glm::scale(s, scale); tmat = s * tmat; } - + if (node.defined["rotation"] && node.rotation.size() == 4) { //quat(x,y,z,w) to quat(w,x,y,z) glm::quat rotquat = glm::quat(node.rotation[3], node.rotation[0], node.rotation[1], node.rotation[2]); tmat = glm::mat4_cast(rotquat) * tmat; } - + if (node.defined["translation"] && node.translation.size() == 3) { glm::vec3 trans = glm::vec3(node.translation[0], node.translation[1], node.translation[2]); glm::mat4 t = glm::mat4(1.0); @@ -842,7 +842,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& sortedNodes.push_back(nodecount); ++nodecount; } - + // Build transforms nodecount = 0; @@ -965,8 +965,8 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& std::vector& value = inverseBindValues[s]; int matrixCount = 16 * matrixIndex; jointInverseBindTransforms[jointIndex] = - glm::mat4(value[matrixCount], value[matrixCount + 1], value[matrixCount + 2], value[matrixCount + 3], - value[matrixCount + 4], value[matrixCount + 5], value[matrixCount + 6], value[matrixCount + 7], + glm::mat4(value[matrixCount], value[matrixCount + 1], value[matrixCount + 2], value[matrixCount + 3], + value[matrixCount + 4], value[matrixCount + 5], value[matrixCount + 6], value[matrixCount + 7], value[matrixCount + 8], value[matrixCount + 9], value[matrixCount + 10], value[matrixCount + 11], value[matrixCount + 12], value[matrixCount + 13], value[matrixCount + 14], value[matrixCount + 15]); } else { @@ -1008,7 +1008,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& setHFMMaterial(hfmMaterial, _file.materials[i]); } - + // Build meshes nodecount = 0; hfmModel.meshExtents.reset(); @@ -1061,7 +1061,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& qWarning(modelformat) << "Indices accessor index is out of bounds for model " << _url; continue; } - + GLTFAccessor& indicesAccessor = _file.accessors[indicesAccessorIdx]; // Buffers @@ -1561,7 +1561,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& // Use blendshape from mapping. foreach(const QVariant& mapping, mappings) { auto blendshapeMapping = mapping.toList(); - blendshapeIndices.insert(blendshapeMapping.at(0).toString(), + blendshapeIndices.insert(blendshapeMapping.at(0).toString(), WeightedIndex(i, blendshapeMapping.at(1).toFloat())); } } else { @@ -1627,7 +1627,7 @@ bool GLTFSerializer::buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& glm::vec3 transformedVertex = glm::vec3(globalTransforms[nodeIndex] * glm::vec4(vertex, 1.0f)); mesh.meshExtents.addPoint(transformedVertex); hfmModel.meshExtents.addPoint(transformedVertex); - } + } } // Mesh extents must be at least a minimum size, in particular for blendshapes to work on planar meshes. @@ -1664,7 +1664,7 @@ std::unique_ptr GLTFSerializer::getFactory() const { HFMModel::Pointer GLTFSerializer::read(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url) { _url = url; - + // Normalize url for local files hifi::URL normalizeUrl = DependencyManager::get()->normalizeURL(_url); if (normalizeUrl.scheme().isEmpty() || (normalizeUrl.scheme() == "file")) { @@ -1699,7 +1699,7 @@ bool GLTFSerializer::readBinary(const QString& url, hifi::ByteArray& outdata) { hifi::URL binaryUrl = _url.resolved(url); std::tie(success, outdata) = requestData(binaryUrl); } - + return success; } @@ -1732,7 +1732,7 @@ std::tuple GLTFSerializer::requestData(hifi::URL& url) { } hifi::ByteArray GLTFSerializer::requestEmbeddedData(const QString& url) { - QString binaryUrl = url.split(",")[1]; + QString binaryUrl = url.split(",")[1]; return binaryUrl.isEmpty() ? hifi::ByteArray() : QByteArray::fromBase64(binaryUrl.toUtf8()); } @@ -1764,7 +1764,7 @@ QNetworkReply* GLTFSerializer::request(hifi::URL& url, bool isTest) { HFMTexture GLTFSerializer::getHFMTexture(const GLTFTexture& texture) { HFMTexture fbxtex = HFMTexture(); fbxtex.texcoordSet = 0; - + if (texture.defined["source"]) { QString url = _file.images[texture.source].uri; @@ -1775,7 +1775,7 @@ HFMTexture GLTFSerializer::getHFMTexture(const GLTFTexture& texture) { if (_url.path().endsWith("glb") && !_glbBinary.isEmpty()) { int bufferView = _file.images[texture.source].bufferView; - + GLTFBufferView& imagesBufferview = _file.bufferviews[bufferView]; int offset = imagesBufferview.byteOffset; int length = imagesBufferview.byteLength; @@ -1785,7 +1785,7 @@ HFMTexture GLTFSerializer::getHFMTexture(const GLTFTexture& texture) { } if (url.contains("data:image/jpeg;base64,") || url.contains("data:image/png;base64,")) { - fbxtex.content = requestEmbeddedData(url); + fbxtex.content = requestEmbeddedData(url); } } return fbxtex; @@ -1815,12 +1815,12 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const GLTFMaterial& mat hfmMat.emissiveTexture = getHFMTexture(_file.textures[material.emissiveTexture]); hfmMat.useEmissiveMap = true; } - + if (material.defined["normalTexture"]) { hfmMat.normalTexture = getHFMTexture(_file.textures[material.normalTexture]); hfmMat.useNormalMap = true; } - + if (material.defined["occlusionTexture"]) { hfmMat.occlusionTexture = getHFMTexture(_file.textures[material.occlusionTexture]); hfmMat.useOcclusionMap = true; @@ -1848,7 +1848,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const GLTFMaterial& mat if (material.pbrMetallicRoughness.defined["roughnessFactor"]) { hfmMat._material->setRoughness(material.pbrMetallicRoughness.roughnessFactor); } - if (material.pbrMetallicRoughness.defined["baseColorFactor"] && + if (material.pbrMetallicRoughness.defined["baseColorFactor"] && material.pbrMetallicRoughness.baseColorFactor.size() == 4) { glm::vec3 dcolor = glm::vec3(material.pbrMetallicRoughness.baseColorFactor[0], material.pbrMetallicRoughness.baseColorFactor[1], @@ -1863,8 +1863,8 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const GLTFMaterial& mat template bool GLTFSerializer::readArray(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType, bool normalized) { - + QVector& outarray, int accessorType) { + QDataStream blobstream(bin); blobstream.setByteOrder(QDataStream::LittleEndian); blobstream.setVersion(QDataStream::Qt_5_9); @@ -1899,22 +1899,12 @@ bool GLTFSerializer::readArray(const hifi::ByteArray& bin, int byteOffset, int c blobstream.setDevice(nullptr); return false; } - - float scale = 1.0f; // Normalized output values should always be floats. - if (normalized) { - scale = (float)(std::numeric_limits::max)(); - } - for (int i = 0; i < count; ++i) { for (int j = 0; j < bufferCount; ++j) { if (!blobstream.atEnd()) { T value; blobstream >> value; - if (normalized) { - outarray.push_back(std::max((float)value / scale, -1.0f)); - } else { - outarray.push_back(value); - } + outarray.push_back(value); } else { blobstream.setDevice(nullptr); return false; @@ -1927,24 +1917,24 @@ bool GLTFSerializer::readArray(const hifi::ByteArray& bin, int byteOffset, int c } template bool GLTFSerializer::addArrayOfType(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType, int componentType, bool normalized) { - + QVector& outarray, int accessorType, int componentType) { + switch (componentType) { case GLTFAccessorComponentType::BYTE: {} case GLTFAccessorComponentType::UNSIGNED_BYTE: { - return readArray(bin, byteOffset, count, outarray, accessorType, normalized); + return readArray(bin, byteOffset, count, outarray, accessorType); } case GLTFAccessorComponentType::SHORT: { - return readArray(bin, byteOffset, count, outarray, accessorType, normalized); + return readArray(bin, byteOffset, count, outarray, accessorType); } case GLTFAccessorComponentType::UNSIGNED_INT: { - return readArray(bin, byteOffset, count, outarray, accessorType, normalized); + return readArray(bin, byteOffset, count, outarray, accessorType); } case GLTFAccessorComponentType::UNSIGNED_SHORT: { - return readArray(bin, byteOffset, count, outarray, accessorType, normalized); + return readArray(bin, byteOffset, count, outarray, accessorType); } case GLTFAccessorComponentType::FLOAT: { - return readArray(bin, byteOffset, count, outarray, accessorType, normalized); + return readArray(bin, byteOffset, count, outarray, accessorType); } } return false; @@ -1961,11 +1951,11 @@ bool GLTFSerializer::addArrayFromAccessor(GLTFAccessor& accessor, QVector& ou int accBoffset = accessor.defined["byteOffset"] ? accessor.byteOffset : 0; success = addArrayOfType(buffer.blob, bufferview.byteOffset + accBoffset, accessor.count, outarray, accessor.type, - accessor.componentType, accessor.normalized); + accessor.componentType); } else { for (int i = 0; i < accessor.count; ++i) { T value; - memset(&value, 0, sizeof(T)); // Make sure the dummy array is initialized to zero. + memset(&value, 0, sizeof(T)); // Make sure the dummy array is initalised to zero. outarray.push_back(value); } } @@ -1981,7 +1971,7 @@ bool GLTFSerializer::addArrayFromAccessor(GLTFAccessor& accessor, QVector& ou success = addArrayOfType(sparseIndicesBuffer.blob, sparseIndicesBufferview.byteOffset + accSIBoffset, accessor.sparse.count, out_sparse_indices_array, GLTFAccessorType::SCALAR, - accessor.sparse.indices.componentType, false); + accessor.sparse.indices.componentType); if (success) { QVector out_sparse_values_array; @@ -1991,12 +1981,11 @@ bool GLTFSerializer::addArrayFromAccessor(GLTFAccessor& accessor, QVector& ou int accSVBoffset = accessor.sparse.values.defined["byteOffset"] ? accessor.sparse.values.byteOffset : 0; success = addArrayOfType(sparseValuesBuffer.blob, sparseValuesBufferview.byteOffset + accSVBoffset, - accessor.sparse.count, out_sparse_values_array, accessor.type, accessor.componentType, - accessor.normalized); + accessor.sparse.count, out_sparse_values_array, accessor.type, accessor.componentType); if (success) { for (int i = 0; i < accessor.sparse.count; ++i) { - if ((i * 3) + 2 < out_sparse_values_array.size()) { + if ((i * 3) + 2 < out_sparse_values_array.size()) { if ((out_sparse_indices_array[i] * 3) + 2 < outarray.length()) { for (int j = 0; j < 3; ++j) { outarray[(out_sparse_indices_array[i] * 3) + j] = out_sparse_values_array[(i * 3) + j]; @@ -2018,8 +2007,8 @@ bool GLTFSerializer::addArrayFromAccessor(GLTFAccessor& accessor, QVector& ou return success; } -void GLTFSerializer::retriangulate(const QVector& inIndices, const QVector& in_vertices, - const QVector& in_normals, QVector& outIndices, +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) { diff --git a/libraries/fbx/src/GLTFSerializer.h b/libraries/model-serializers/src/GLTFSerializer.h old mode 100755 new mode 100644 similarity index 98% rename from libraries/fbx/src/GLTFSerializer.h rename to libraries/model-serializers/src/GLTFSerializer.h index 040ccb413b..676d91b32b --- a/libraries/fbx/src/GLTFSerializer.h +++ b/libraries/model-serializers/src/GLTFSerializer.h @@ -1,6 +1,6 @@ // // GLTFSerializer.h -// libraries/fbx/src +// libraries/model-serializers/src // // Created by Luis Cuenca on 8/30/17. // Copyright 2017 High Fidelity, Inc. @@ -343,7 +343,7 @@ struct GLTFCamera { QString name; GLTFCameraPerspective perspective; //required (or) GLTFCameraOrthographic orthographic; //required (or) - int type; + int type; QMap defined; void dump() { if (defined["name"]) { @@ -519,7 +519,7 @@ struct GLTFAccessor { QMap defined; void dump() { - + } }; int bufferView; @@ -527,7 +527,7 @@ struct GLTFAccessor { int componentType; //required int count; //required int type; //required - bool normalized { false }; + bool normalized{ false }; QVector max; QVector min; GLTFAccessorSparse sparse; @@ -778,26 +778,26 @@ private: bool buildGeometry(HFMModel& hfmModel, const hifi::VariantHash& mapping, const hifi::URL& url); bool parseGLTF(const hifi::ByteArray& data); - - bool getStringVal(const QJsonObject& object, const QString& fieldname, + + bool getStringVal(const QJsonObject& object, const QString& fieldname, QString& value, QMap& defined); - bool getBoolVal(const QJsonObject& object, const QString& fieldname, + bool getBoolVal(const QJsonObject& object, const QString& fieldname, bool& value, QMap& defined); - bool getIntVal(const QJsonObject& object, const QString& fieldname, + bool getIntVal(const QJsonObject& object, const QString& fieldname, int& value, QMap& defined); - bool getDoubleVal(const QJsonObject& object, const QString& fieldname, + bool getDoubleVal(const QJsonObject& object, const QString& fieldname, double& value, QMap& defined); - bool getObjectVal(const QJsonObject& object, const QString& fieldname, + bool getObjectVal(const QJsonObject& object, const QString& fieldname, QJsonObject& value, QMap& defined); - bool getIntArrayVal(const QJsonObject& object, const QString& fieldname, + bool getIntArrayVal(const QJsonObject& object, const QString& fieldname, QVector& values, QMap& defined); - bool getDoubleArrayVal(const QJsonObject& object, const QString& fieldname, + bool getDoubleArrayVal(const QJsonObject& object, const QString& fieldname, QVector& values, QMap& defined); - bool getObjectArrayVal(const QJsonObject& object, const QString& fieldname, + bool getObjectArrayVal(const QJsonObject& object, const QString& fieldname, QJsonArray& objects, QMap& defined); hifi::ByteArray setGLBChunks(const hifi::ByteArray& data); - + graphics::MaterialKey::OpacityMapMode getMaterialAlphaMode(const QString& type); int getAccessorType(const QString& type); int getAnimationSamplerInterpolation(const QString& interpolation); @@ -805,7 +805,7 @@ private: int getImageMimeType(const QString& mime); int getMeshPrimitiveRenderingMode(const QString& type); - bool getIndexFromObject(const QJsonObject& object, const QString& field, + bool getIndexFromObject(const QJsonObject& object, const QString& field, int& outidx, QMap& defined); bool setAsset(const QJsonObject& object); @@ -832,17 +832,17 @@ private: template bool readArray(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType, bool normalized); + QVector& outarray, int accessorType); template bool addArrayOfType(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType, int componentType, bool normalized); + QVector& outarray, int accessorType, int componentType); template bool addArrayFromAccessor(GLTFAccessor& accessor, QVector& outarray); - void retriangulate(const QVector& in_indices, const QVector& in_vertices, - const QVector& in_normals, QVector& out_indices, + void retriangulate(const QVector& in_indices, const QVector& in_vertices, + const QVector& in_normals, QVector& out_indices, QVector& out_vertices, QVector& out_normals); std::tuple requestData(hifi::URL& url); @@ -857,4 +857,4 @@ private: void glTFDebugDump(); }; -#endif // hifi_GLTFSerializer_h \ No newline at end of file +#endif // hifi_GLTFSerializer_h diff --git a/libraries/fbx/src/OBJSerializer.cpp b/libraries/model-serializers/src/OBJSerializer.cpp similarity index 99% rename from libraries/fbx/src/OBJSerializer.cpp rename to libraries/model-serializers/src/OBJSerializer.cpp index 416f343a47..7acc663828 100644 --- a/libraries/fbx/src/OBJSerializer.cpp +++ b/libraries/model-serializers/src/OBJSerializer.cpp @@ -1,6 +1,6 @@ // // OBJSerializer.cpp -// libraries/fbx/src/ +// libraries/model-serializers/src // // Created by Seth Alves on 3/7/15. // Copyright 2013 High Fidelity, Inc. @@ -15,7 +15,7 @@ #include "OBJSerializer.h" #include // .obj files are not locale-specific. The C/ASCII charset applies. -#include +#include #include #include @@ -263,16 +263,16 @@ void OBJSerializer::parseMaterialLibrary(QIODevice* device) { default: materials[matName] = currentMaterial; #ifdef WANT_DEBUG - qCDebug(modelformat) << + qCDebug(modelformat) << "OBJSerializer Last material illumination model:" << currentMaterial.illuminationModel << - " shininess:" << currentMaterial.shininess << + " shininess:" << currentMaterial.shininess << " opacity:" << currentMaterial.opacity << - " diffuse color:" << currentMaterial.diffuseColor << - " specular color:" << currentMaterial.specularColor << - " emissive color:" << currentMaterial.emissiveColor << - " diffuse texture:" << currentMaterial.diffuseTextureFilename << - " specular texture:" << currentMaterial.specularTextureFilename << - " emissive texture:" << currentMaterial.emissiveTextureFilename << + " diffuse color:" << currentMaterial.diffuseColor << + " specular color:" << currentMaterial.specularColor << + " emissive color:" << currentMaterial.emissiveColor << + " diffuse texture:" << currentMaterial.diffuseTextureFilename << + " specular texture:" << currentMaterial.specularTextureFilename << + " emissive texture:" << currentMaterial.emissiveTextureFilename << " bump texture:" << currentMaterial.bumpTextureFilename << " opacity texture:" << currentMaterial.opacityTextureFilename; #endif @@ -352,7 +352,7 @@ void OBJSerializer::parseMaterialLibrary(QIODevice* device) { } } } -} +} void OBJSerializer::parseTextureLine(const hifi::ByteArray& textureLine, hifi::ByteArray& filename, OBJMaterialTextureOptions& textureOptions) { // Texture options reference http://paulbourke.net/dataformats/mtl/ @@ -803,7 +803,7 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V n0 = checked_at(normals, face.normalIndices[0]); n1 = checked_at(normals, face.normalIndices[1]); n2 = checked_at(normals, face.normalIndices[2]); - } else { + } else { // generate normals from triangle plane if not provided n0 = n1 = n2 = glm::cross(v1 - v0, v2 - v0); } @@ -932,7 +932,7 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V bool applyNonMetallic = false; bool fresnelOn = false; - // Illumination model reference http://paulbourke.net/dataformats/mtl/ + // Illumination model reference http://paulbourke.net/dataformats/mtl/ switch (objMaterial.illuminationModel) { case 0: // Color on and Ambient off // We don't support ambient = do nothing? @@ -976,7 +976,7 @@ HFMModel::Pointer OBJSerializer::read(const hifi::ByteArray& data, const hifi::V case 10: // Casts shadows onto invisible surfaces // Do nothing? break; - } + } if (applyTransparency) { hfmMaterial.opacity = std::max(hfmMaterial.opacity, ILLUMINATION_MODEL_MIN_OPACITY); diff --git a/libraries/fbx/src/OBJSerializer.h b/libraries/model-serializers/src/OBJSerializer.h similarity index 99% rename from libraries/fbx/src/OBJSerializer.h rename to libraries/model-serializers/src/OBJSerializer.h index 6fdd95e2c3..20633e90e4 100644 --- a/libraries/fbx/src/OBJSerializer.h +++ b/libraries/model-serializers/src/OBJSerializer.h @@ -1,6 +1,6 @@ // // OBJSerializer.h -// libraries/fbx/src/ +// libraries/model-serializers/src // // Created by Seth Alves on 3/6/15. // Copyright 2015 High Fidelity, Inc. @@ -93,7 +93,7 @@ class OBJSerializer: public QObject, public HFMSerializer { // QObject so we can public: MediaType getMediaType() const override; std::unique_ptr getFactory() const override; - + typedef QVector FaceGroup; QVector vertices; QVector vertexColors; @@ -102,7 +102,7 @@ public: QVector faceGroups; QString currentMaterialName; QHash materials; - + HFMModel::Pointer read(const hifi::ByteArray& data, const hifi::VariantHash& mapping, const hifi::URL& url = hifi::URL()) override; private: diff --git a/libraries/fbx/src/OBJWriter.cpp b/libraries/model-serializers/src/OBJWriter.cpp similarity index 99% rename from libraries/fbx/src/OBJWriter.cpp rename to libraries/model-serializers/src/OBJWriter.cpp index b2e191bcbf..dec35c7aac 100644 --- a/libraries/fbx/src/OBJWriter.cpp +++ b/libraries/model-serializers/src/OBJWriter.cpp @@ -1,6 +1,6 @@ // // OBJWriter.cpp -// libraries/fbx/src/ +// libraries/model-serializers/src // // Created by Seth Alves on 2017-1-27. // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/fbx/src/OBJWriter.h b/libraries/model-serializers/src/OBJWriter.h similarity index 94% rename from libraries/fbx/src/OBJWriter.h rename to libraries/model-serializers/src/OBJWriter.h index 536e8cf837..34f6d93658 100644 --- a/libraries/fbx/src/OBJWriter.h +++ b/libraries/model-serializers/src/OBJWriter.h @@ -1,6 +1,6 @@ // // OBJWriter.h -// libraries/fbx/src/ +// libraries/model-serializers/src // // Created by Seth Alves on 2017-1-27. // Copyright 2017 High Fidelity, Inc. diff --git a/libraries/render-utils/CMakeLists.txt b/libraries/render-utils/CMakeLists.txt index 833d78bb74..4c444bcd15 100644 --- a/libraries/render-utils/CMakeLists.txt +++ b/libraries/render-utils/CMakeLists.txt @@ -3,7 +3,7 @@ set(TARGET_NAME render-utils) # pull in the resources.qrc file qt5_add_resources(QT_RESOURCES_FILE "${CMAKE_CURRENT_SOURCE_DIR}/res/fonts/fonts.qrc") setup_hifi_library(Gui Network Qml Quick Script) -link_hifi_libraries(shared task ktx gpu shaders graphics graphics-scripting material-networking model-networking render animation fbx image procedural) +link_hifi_libraries(shared task ktx gpu shaders graphics graphics-scripting material-networking model-networking render animation model-serializers image procedural) include_hifi_library_headers(audio) include_hifi_library_headers(networking) include_hifi_library_headers(octree) diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 9052cb89e9..6def6c185f 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -7,7 +7,7 @@ if (NOT ANDROID) target_quazip() endif () -link_hifi_libraries(shared networking shaders material-networking model-networking recording avatars fbx entities controllers animation audio midi) +link_hifi_libraries(shared networking shaders material-networking model-networking recording avatars model-serializers entities controllers animation audio midi) include_hifi_library_headers(gl) include_hifi_library_headers(hfm) include_hifi_library_headers(gpu) diff --git a/plugins/openvr/CMakeLists.txt b/plugins/openvr/CMakeLists.txt index 9690ee3fb5..0b9358242d 100644 --- a/plugins/openvr/CMakeLists.txt +++ b/plugins/openvr/CMakeLists.txt @@ -10,9 +10,9 @@ if ((WIN32 OR UNIX AND NOT APPLE) AND NOT USE_GLES) set(TARGET_NAME openvr) setup_hifi_plugin(Gui Qml Multimedia) - link_hifi_libraries(shared task gl qml networking controllers ui + link_hifi_libraries(shared task gl qml networking controllers ui plugins display-plugins ui-plugins input-plugins script-engine - audio-client render-utils graphics shaders gpu render material-networking model-networking model-baker hfm fbx ktx image procedural ${PLATFORM_GL_BACKEND}) + audio-client render-utils graphics shaders gpu render material-networking model-networking model-baker hfm model-serializers ktx image procedural ${PLATFORM_GL_BACKEND}) include_hifi_library_headers(octree) target_openvr() diff --git a/tools/oven/CMakeLists.txt b/tools/oven/CMakeLists.txt index 9a159d8cb1..4f48570428 100644 --- a/tools/oven/CMakeLists.txt +++ b/tools/oven/CMakeLists.txt @@ -2,7 +2,7 @@ set(TARGET_NAME oven) setup_hifi_project(Widgets Gui Concurrent) -link_hifi_libraries(shared shaders image gpu ktx fbx hfm baking graphics networking procedural material-networking model-baker task) +link_hifi_libraries(shared shaders image gpu ktx model-serializers hfm baking graphics networking procedural material-networking model-baker task) setup_memory_debugger() setup_thread_debugger() diff --git a/tools/skeleton-dump/CMakeLists.txt b/tools/skeleton-dump/CMakeLists.txt index cf95c302e8..38aaa3832b 100644 --- a/tools/skeleton-dump/CMakeLists.txt +++ b/tools/skeleton-dump/CMakeLists.txt @@ -2,6 +2,6 @@ set(TARGET_NAME skeleton-dump) setup_hifi_project(Core) setup_memory_debugger() setup_thread_debugger() -link_hifi_libraries(shared fbx hfm graphics gpu gl animation) +link_hifi_libraries(shared model-serializers hfm graphics gpu gl animation) include_hifi_library_headers(image) diff --git a/tools/vhacd-util/CMakeLists.txt b/tools/vhacd-util/CMakeLists.txt index 3c4d17122e..5d7fba79e3 100644 --- a/tools/vhacd-util/CMakeLists.txt +++ b/tools/vhacd-util/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET_NAME vhacd-util) setup_hifi_project(Core) -link_hifi_libraries(shared fbx hfm graphics gpu gl) +link_hifi_libraries(shared model-serializers hfm graphics gpu gl) include_hifi_library_headers(image) From b1852eabd4f44bca5aa08f89c2194b65cbcd1000 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gro=C3=9F?= Date: Thu, 15 Apr 2021 19:45:52 +0200 Subject: [PATCH 2/5] Update jsdoc entry --- tools/jsdoc/plugins/hifi.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/jsdoc/plugins/hifi.js b/tools/jsdoc/plugins/hifi.js index 3c1ec08bb0..d757a4d5cb 100644 --- a/tools/jsdoc/plugins/hifi.js +++ b/tools/jsdoc/plugins/hifi.js @@ -44,7 +44,7 @@ exports.handlers = { '../../libraries/controllers/src/controllers/impl/', '../../libraries/display-plugins/src/display-plugins/', '../../libraries/entities/src', - '../../libraries/fbx/src', + '../../libraries/model-serializers/src', '../../libraries/graphics/src/graphics/', '../../libraries/graphics-scripting/src/graphics-scripting/', '../../libraries/image/src/image', From 8573425f68325e55efc4795f0681ac204433af5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gro=C3=9F?= Date: Thu, 15 Apr 2021 20:15:36 +0200 Subject: [PATCH 3/5] Update library headers --- libraries/avatars-renderer/CMakeLists.txt | 2 +- libraries/display-plugins/CMakeLists.txt | 2 +- libraries/entities-renderer/CMakeLists.txt | 2 +- libraries/entities/CMakeLists.txt | 4 ++-- libraries/physics/CMakeLists.txt | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/libraries/avatars-renderer/CMakeLists.txt b/libraries/avatars-renderer/CMakeLists.txt index deba2913c1..0175d1113a 100644 --- a/libraries/avatars-renderer/CMakeLists.txt +++ b/libraries/avatars-renderer/CMakeLists.txt @@ -4,7 +4,7 @@ link_hifi_libraries(shared shaders gpu graphics animation material-networking mo include_hifi_library_headers(avatars) include_hifi_library_headers(networking) include_hifi_library_headers(hfm) -include_hifi_library_headers(fbx) +include_hifi_library_headers(model-serializers) include_hifi_library_headers(recording) include_hifi_library_headers(ktx) include_hifi_library_headers(procedural) diff --git a/libraries/display-plugins/CMakeLists.txt b/libraries/display-plugins/CMakeLists.txt index cdc6263025..07b70c310f 100644 --- a/libraries/display-plugins/CMakeLists.txt +++ b/libraries/display-plugins/CMakeLists.txt @@ -7,7 +7,7 @@ include_hifi_library_headers(model-networking) include_hifi_library_headers(networking) include_hifi_library_headers(graphics) include_hifi_library_headers(hfm) -include_hifi_library_headers(fbx) +include_hifi_library_headers(model-serializers) include_hifi_library_headers(image) include_hifi_library_headers(ktx) include_hifi_library_headers(render) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index e1896cf674..5f40c8d5fe 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -9,7 +9,7 @@ include_hifi_library_headers(audio) include_hifi_library_headers(physics) include_hifi_library_headers(animation) include_hifi_library_headers(hfm) -include_hifi_library_headers(fbx) +include_hifi_library_headers(model-serializers) include_hifi_library_headers(entities) include_hifi_library_headers(avatars) include_hifi_library_headers(controllers) diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index 3157a6552b..bddd4b5e67 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -1,8 +1,8 @@ set(TARGET_NAME entities) setup_hifi_library(Network Script) -target_include_directories(${TARGET_NAME} PRIVATE "${OPENSSL_INCLUDE_DIR}") +target_include_directories(${TARGET_NAME} PRIVATE "${OPENSSL_INCLUDE_DIR}") include_hifi_library_headers(hfm) -include_hifi_library_headers(fbx) +include_hifi_library_headers(model-serializers) include_hifi_library_headers(gpu) include_hifi_library_headers(image) include_hifi_library_headers(ktx) diff --git a/libraries/physics/CMakeLists.txt b/libraries/physics/CMakeLists.txt index c1410a6bfc..ad4900e4ba 100644 --- a/libraries/physics/CMakeLists.txt +++ b/libraries/physics/CMakeLists.txt @@ -12,7 +12,7 @@ include_hifi_library_headers(image) include_hifi_library_headers(ktx) include_hifi_library_headers(gpu) include_hifi_library_headers(hfm) -include_hifi_library_headers(fbx) +include_hifi_library_headers(model-serializers) include_hifi_library_headers(graphics) target_bullet() From 12c3bd80e5c46acbb54f60559b88a042c66eae66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gro=C3=9F?= Date: Thu, 15 Apr 2021 23:49:02 +0200 Subject: [PATCH 4/5] Fix GLTFSerializer not being up to date --- .../model-serializers/src/GLTFSerializer.cpp | 35 ++++++++++++------- .../model-serializers/src/GLTFSerializer.h | 6 ++-- 2 files changed, 26 insertions(+), 15 deletions(-) mode change 100644 => 100755 libraries/model-serializers/src/GLTFSerializer.cpp mode change 100644 => 100755 libraries/model-serializers/src/GLTFSerializer.h diff --git a/libraries/model-serializers/src/GLTFSerializer.cpp b/libraries/model-serializers/src/GLTFSerializer.cpp old mode 100644 new mode 100755 index 3c59e51b1b..edb1c47a0b --- a/libraries/model-serializers/src/GLTFSerializer.cpp +++ b/libraries/model-serializers/src/GLTFSerializer.cpp @@ -1863,7 +1863,7 @@ void GLTFSerializer::setHFMMaterial(HFMMaterial& hfmMat, const GLTFMaterial& mat template bool GLTFSerializer::readArray(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType) { + QVector& outarray, int accessorType, bool normalized) { QDataStream blobstream(bin); blobstream.setByteOrder(QDataStream::LittleEndian); @@ -1899,12 +1899,22 @@ bool GLTFSerializer::readArray(const hifi::ByteArray& bin, int byteOffset, int c blobstream.setDevice(nullptr); return false; } + + float scale = 1.0f; // Normalized output values should always be floats. + if (normalized) { + scale = (float)(std::numeric_limits::max)(); + } + for (int i = 0; i < count; ++i) { for (int j = 0; j < bufferCount; ++j) { if (!blobstream.atEnd()) { T value; blobstream >> value; - outarray.push_back(value); + if (normalized) { + outarray.push_back(std::max((float)value / scale, -1.0f)); + } else { + outarray.push_back(value); + } } else { blobstream.setDevice(nullptr); return false; @@ -1917,24 +1927,24 @@ bool GLTFSerializer::readArray(const hifi::ByteArray& bin, int byteOffset, int c } template bool GLTFSerializer::addArrayOfType(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType, int componentType) { + QVector& outarray, int accessorType, int componentType, bool normalized) { switch (componentType) { case GLTFAccessorComponentType::BYTE: {} case GLTFAccessorComponentType::UNSIGNED_BYTE: { - return readArray(bin, byteOffset, count, outarray, accessorType); + return readArray(bin, byteOffset, count, outarray, accessorType, normalized); } case GLTFAccessorComponentType::SHORT: { - return readArray(bin, byteOffset, count, outarray, accessorType); + return readArray(bin, byteOffset, count, outarray, accessorType, normalized); } case GLTFAccessorComponentType::UNSIGNED_INT: { - return readArray(bin, byteOffset, count, outarray, accessorType); + return readArray(bin, byteOffset, count, outarray, accessorType, normalized); } case GLTFAccessorComponentType::UNSIGNED_SHORT: { - return readArray(bin, byteOffset, count, outarray, accessorType); + return readArray(bin, byteOffset, count, outarray, accessorType, normalized); } case GLTFAccessorComponentType::FLOAT: { - return readArray(bin, byteOffset, count, outarray, accessorType); + return readArray(bin, byteOffset, count, outarray, accessorType, normalized); } } return false; @@ -1951,11 +1961,11 @@ bool GLTFSerializer::addArrayFromAccessor(GLTFAccessor& accessor, QVector& ou int accBoffset = accessor.defined["byteOffset"] ? accessor.byteOffset : 0; success = addArrayOfType(buffer.blob, bufferview.byteOffset + accBoffset, accessor.count, outarray, accessor.type, - accessor.componentType); + accessor.componentType, accessor.normalized); } else { for (int i = 0; i < accessor.count; ++i) { T value; - memset(&value, 0, sizeof(T)); // Make sure the dummy array is initalised to zero. + memset(&value, 0, sizeof(T)); // Make sure the dummy array is initialized to zero. outarray.push_back(value); } } @@ -1971,7 +1981,7 @@ bool GLTFSerializer::addArrayFromAccessor(GLTFAccessor& accessor, QVector& ou success = addArrayOfType(sparseIndicesBuffer.blob, sparseIndicesBufferview.byteOffset + accSIBoffset, accessor.sparse.count, out_sparse_indices_array, GLTFAccessorType::SCALAR, - accessor.sparse.indices.componentType); + accessor.sparse.indices.componentType, false); if (success) { QVector out_sparse_values_array; @@ -1981,7 +1991,8 @@ bool GLTFSerializer::addArrayFromAccessor(GLTFAccessor& accessor, QVector& ou int accSVBoffset = accessor.sparse.values.defined["byteOffset"] ? accessor.sparse.values.byteOffset : 0; success = addArrayOfType(sparseValuesBuffer.blob, sparseValuesBufferview.byteOffset + accSVBoffset, - accessor.sparse.count, out_sparse_values_array, accessor.type, accessor.componentType); + accessor.sparse.count, out_sparse_values_array, accessor.type, accessor.componentType, + accessor.normalized); if (success) { for (int i = 0; i < accessor.sparse.count; ++i) { diff --git a/libraries/model-serializers/src/GLTFSerializer.h b/libraries/model-serializers/src/GLTFSerializer.h old mode 100644 new mode 100755 index 676d91b32b..3ce38ead5e --- a/libraries/model-serializers/src/GLTFSerializer.h +++ b/libraries/model-serializers/src/GLTFSerializer.h @@ -527,7 +527,7 @@ struct GLTFAccessor { int componentType; //required int count; //required int type; //required - bool normalized{ false }; + bool normalized { false }; QVector max; QVector min; GLTFAccessorSparse sparse; @@ -832,11 +832,11 @@ private: template bool readArray(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType); + QVector& outarray, int accessorType, bool normalized); template bool addArrayOfType(const hifi::ByteArray& bin, int byteOffset, int count, - QVector& outarray, int accessorType, int componentType); + QVector& outarray, int accessorType, int componentType, bool normalized); template bool addArrayFromAccessor(GLTFAccessor& accessor, QVector& outarray); From f6d9cd6fb8e9b5611ef1d917ab9cb6263faa4100 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julian=20Gro=C3=9F?= Date: Thu, 15 Apr 2021 23:52:35 +0200 Subject: [PATCH 5/5] Fix Android building --- android/apps/interface/CMakeLists.txt | 2 +- android/apps/questInterface/CMakeLists.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/android/apps/interface/CMakeLists.txt b/android/apps/interface/CMakeLists.txt index 500d555915..2f21d22b12 100644 --- a/android/apps/interface/CMakeLists.txt +++ b/android/apps/interface/CMakeLists.txt @@ -1,6 +1,6 @@ set(TARGET_NAME native-lib) setup_hifi_library() -link_hifi_libraries(shared task networking gl gpu qml image fbx hfm render-utils physics entities octree ${PLATFORM_GL_BACKEND}) +link_hifi_libraries(shared task networking gl gpu qml image model-serializers hfm render-utils physics entities octree ${PLATFORM_GL_BACKEND}) target_opengl() target_bullet() diff --git a/android/apps/questInterface/CMakeLists.txt b/android/apps/questInterface/CMakeLists.txt index 97ca46f6e5..72448cc9cf 100644 --- a/android/apps/questInterface/CMakeLists.txt +++ b/android/apps/questInterface/CMakeLists.txt @@ -2,7 +2,7 @@ set(TARGET_NAME questInterface) setup_hifi_library() link_hifi_libraries( shared task networking qml - image fbx hfm render-utils physics entities octree + image model-serializers hfm render-utils physics entities octree oculusMobile oculusMobilePlugin gl gpu ${PLATFORM_GL_BACKEND} )