// // FBXSerializer.h // libraries/fbx/src // // Created by Andrzej Kapolka on 9/18/13. // Copyright 2013 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_FBXSerializer_h #define hifi_FBXSerializer_h #include #include #include #include #include #include #include #include #include #include #include #include "FBX.h" #include #include #include 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; glm::vec2 UVScaling; glm::vec4 cropping; QString UVSet; glm::vec3 translation; glm::vec3 rotation; glm::vec3 scaling; uint8_t alphaSource; uint8_t currentTextureBlendMode; bool useMaterial; template bool assign(T& ref, const T& v) { if (ref == v) { return false; } else { ref = v; isDefault = false; return true; } } bool isDefault; TextureParam() : UVTranslation(0.0f), UVScaling(1.0f), cropping(0.0f), UVSet("map1"), translation(0.0f), rotation(0.0f), scaling(1.0f), alphaSource(0), currentTextureBlendMode(0), useMaterial(true), isDefault(true) {} TextureParam(const TextureParam& src) : UVTranslation(src.UVTranslation), UVScaling(src.UVScaling), cropping(src.cropping), UVSet(src.UVSet), translation(src.translation), rotation(src.rotation), scaling(src.scaling), alphaSource(src.alphaSource), currentTextureBlendMode(src.currentTextureBlendMode), useMaterial(src.useMaterial), isDefault(src.isDefault) {} }; class ExtractedMesh; 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::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); HFMModel* extractHFMModel(const QVariantHash& mapping, const QString& url); static ExtractedMesh extractMesh(const FBXNode& object, unsigned int& meshIndex, bool deduplicate = true); QHash meshes; static void buildModelMesh(HFMMesh& extractedMesh, const QString& url); static glm::vec3 normalizeDirForPacking(const glm::vec3& dir); HFMTexture getTexture(const QString& textureID); QHash _textureNames; // Hashes the original RelativeFilename of textures QHash _textureFilepaths; // Hashes the place to look for textures, in case they are not inlined QHash _textureFilenames; // Hashes texture content by filepath, in case they are inlined QHash _textureContent; QHash _textureParams; QHash diffuseTextures; QHash diffuseFactorTextures; QHash transparentTextures; QHash bumpTextures; QHash normalTextures; QHash specularTextures; QHash metallicTextures; QHash roughnessTextures; QHash shininessTextures; QHash emissiveTextures; QHash ambientTextures; QHash ambientFactorTextures; QHash occlusionTextures; QHash _hfmMaterials; void consolidateHFMMaterials(const QVariantHash& mapping); bool _loadLightmaps { true }; float _lightmapOffset { 0.0f }; float _lightmapLevel { 1.0f }; QMultiMap _connectionParentMap; QMultiMap _connectionChildMap; static glm::vec3 getVec3(const QVariantList& properties, int index); static QVector createVec4Vector(const QVector& doubleVector); static QVector createVec4VectorRGBA(const QVector& doubleVector, glm::vec4& average); static QVector createVec3Vector(const QVector& doubleVector); static QVector createVec2Vector(const QVector& doubleVector); static glm::mat4 createMat4(const QVector& doubleVector); static QVector getIntVector(const FBXNode& node); static QVector getFloatVector(const FBXNode& node); static QVector getDoubleVector(const FBXNode& node); }; #endif // hifi_FBXSerializer_h