Overte C++ Documentation
FSTReader.h
1 //
2 // FSTReader.h
3 //
4 //
5 // Created by Clement on 3/26/15.
6 // Copyright 2015 High Fidelity, Inc.
7 //
8 // Distributed under the Apache License, Version 2.0.
9 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
10 //
11 
12 #ifndef hifi_FSTReader_h
13 #define hifi_FSTReader_h
14 
15 #include <QBuffer>
16 #include <QVariantHash>
17 #include "shared/HifiTypes.h"
18 
19 static const unsigned int FST_VERSION = 1;
20 static const QString FST_VERSION_FIELD = "version";
21 static const QString NAME_FIELD = "name";
22 static const QString TYPE_FIELD = "type";
23 static const QString FILENAME_FIELD = "filename";
24 static const QString TEXDIR_FIELD = "texdir";
25 static const QString LOD_FIELD = "lod";
26 static const QString JOINT_INDEX_FIELD = "jointIndex";
27 static const QString SCALE_FIELD = "scale";
28 static const QString TRANSLATION_X_FIELD = "tx";
29 static const QString TRANSLATION_Y_FIELD = "ty";
30 static const QString TRANSLATION_Z_FIELD = "tz";
31 static const QString JOINT_FIELD = "joint";
32 static const QString BLENDSHAPE_FIELD = "bs";
33 static const QString SCRIPT_FIELD = "script";
34 static const QString JOINT_NAME_MAPPING_FIELD = "jointMap";
35 static const QString MATERIAL_MAPPING_FIELD = "materialMap";
36 static const QString COMMENT_FIELD = "comment";
37 
38 class FSTReader {
39 public:
40 
41  enum ModelType {
42  ENTITY_MODEL,
43  HEAD_MODEL,
44  BODY_ONLY_MODEL,
45  HEAD_AND_BODY_MODEL,
46  ATTACHMENT_MODEL
47  };
48 
50  static hifi::VariantMultiHash readMapping(const QByteArray& data);
51 
53  static QByteArray writeMapping(const hifi::VariantMultiHash& mapping);
54 
56  static ModelType predictModelType(const hifi::VariantMultiHash& mapping);
57 
58  static QVector<QString> getScripts(const QUrl& fstUrl, const hifi::VariantMultiHash& mapping = QVariantHash());
59 
60  static QString getNameFromType(ModelType modelType);
61  static FSTReader::ModelType getTypeFromName(const QString& name);
62  static hifi::VariantMultiHash downloadMapping(const QString& url);
63 
64 private:
65  static void writeVariant(QBuffer& buffer, QVariantHash::const_iterator& it);
66  static hifi::VariantMultiHash parseMapping(QIODevice* device);
67 
68  static QHash<FSTReader::ModelType, QString> _typesToNames;
69  static QHash<QString, FSTReader::ModelType> _namesToTypes;
70 };
71 
72 #endif // hifi_FSTReader_h