19 #include <glm/glm.hpp>
20 #include <glm/gtc/quaternion.hpp>
23 #include <Transform.h>
25 #include <gpu/Texture.h>
26 #include <graphics/Geometry.h>
27 #include <graphics/Material.h>
29 #include <image/ColorChannel.h>
31 #if defined(Q_OS_ANDROID)
32 #define HFM_PACK_NORMALS 0
34 #define HFM_PACK_NORMALS 1
38 using NormalType = glm::uint32;
39 #define HFM_NORMAL_ELEMENT gpu::Element::VEC4F_NORMALIZED_XYZ10W2
41 using NormalType = glm::vec3;
42 #define HFM_NORMAL_ELEMENT gpu::Element::VEC3F_XYZ
45 #define HFM_PACK_COLORS 1
48 using ColorType = glm::uint32;
49 #define HFM_COLOR_ELEMENT gpu::Element::COLOR_RGBA_32
51 using ColorType = glm::vec3;
52 #define HFM_COLOR_ELEMENT gpu::Element::VEC3F_XYZ
55 const int MAX_NUM_PIXELS_FOR_FBX_TEXTURE = 8192 * 8192;
58 using ShapeVertices = std::vector<glm::vec3>;
60 static const int DRACO_MESH_VERSION = 3;
62 static const int DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES = 1000;
63 static const int DRACO_ATTRIBUTE_MATERIAL_ID = DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES;
64 static const int DRACO_ATTRIBUTE_TEX_COORD_1 = DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES + 1;
65 static const int DRACO_ATTRIBUTE_ORIGINAL_INDEX = DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES + 2;
74 QVector<glm::vec3> vertices;
75 QVector<glm::vec3> normals;
76 QVector<glm::vec3> tangents;
79 struct JointShapeInfo {
82 std::vector<float> dots;
83 std::vector<glm::vec3> points;
84 std::vector<glm::vec3> debugLines;
90 JointShapeInfo shapeInfo;
92 float distanceToParent;
96 glm::vec3 translation;
97 glm::mat4 preTransform;
98 glm::quat preRotation;
100 glm::quat postRotation;
101 glm::mat4 postTransform;
106 glm::vec3 rotationMin;
107 glm::vec3 rotationMax;
108 glm::quat inverseDefaultRotation;
109 glm::quat inverseBindRotation;
110 glm::mat4 bindTransform;
112 bool isSkeletonJoint;
113 bool bindTransformFoundInCluster;
116 bool hasGeometricOffset;
117 glm::vec3 geometricTranslation;
118 glm::quat geometricRotation;
119 glm::vec3 geometricScaling;
128 glm::mat4 inverseBindMatrix;
129 Transform inverseBindTransform;
140 image::ColorChannel sourceChannel { image::ColorChannel::NONE };
143 int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE };
145 QString texcoordSetName;
147 bool isBumpmap {
false };
151 bool isNull()
const {
return name.isEmpty() && filename.isEmpty() && content.isEmpty(); }
158 QVector<int> quadIndices;
159 QVector<int> quadTrianglesIndices;
160 QVector<int> triangleIndices;
168 Material(
const glm::vec3& diffuseColor,
const glm::vec3& specularColor,
const glm::vec3& emissiveColor,
169 float shininess,
float opacity) :
170 diffuseColor(diffuseColor),
171 specularColor(specularColor),
172 emissiveColor(emissiveColor),
173 shininess(shininess),
176 void getTextureNames(QSet<QString>& textureList)
const;
177 void setMaxNumPixelsPerTexture(
int maxNumPixels);
179 glm::vec3 diffuseColor { 1.0f };
180 float diffuseFactor { 1.0f };
181 glm::vec3 specularColor { 0.02f };
182 float specularFactor { 1.0f };
184 glm::vec3 emissiveColor { 0.0f };
185 float emissiveFactor { 0.0f };
187 float shininess { 23.0f };
188 float opacity { 1.0f };
190 float metallic { 0.0f };
191 float roughness { 1.0f };
192 float emissiveIntensity { 1.0f };
193 float ambientFactor { 1.0f };
195 float bumpMultiplier { 1.0f };
197 graphics::MaterialKey::OpacityMapMode alphaMode { graphics::MaterialKey::OPACITY_MAP_BLEND };
198 float alphaCutoff { 0.5f };
202 QString shadingModel;
203 graphics::MaterialPointer _material;
216 glm::vec2 lightmapParams { 0.0f, 1.0f };
219 bool isPBSMaterial {
false };
221 bool useNormalMap {
false };
222 bool useAlbedoMap {
false };
223 bool useOpacityMap {
false };
224 bool useRoughnessMap {
false };
225 bool useSpecularMap {
false };
226 bool useMetallicMap {
false };
227 bool useEmissiveMap {
false };
228 bool useOcclusionMap {
false };
231 bool isMToonMaterial {
false };
238 bool needTangentSpace()
const;
245 QVector<MeshPart> parts;
247 QVector<glm::vec3> vertices;
248 QVector<glm::vec3> normals;
249 QVector<glm::vec3> tangents;
250 QVector<glm::vec3> colors;
251 QVector<glm::vec2> texCoords;
252 QVector<glm::vec2> texCoords1;
253 QVector<uint16_t> clusterIndices;
254 QVector<uint16_t> clusterWeights;
255 QVector<int32_t> originalIndices;
257 QVector<Cluster> clusters;
260 glm::mat4 modelTransform;
262 QVector<Blendshape> blendshapes;
264 unsigned int meshIndex;
266 graphics::MeshPointer _mesh;
267 bool wasCompressed {
false };
273 QVector<glm::quat> rotations;
274 QVector<glm::vec3> translations;
298 QVariantMap _physicsConfig;
299 QVariantMap _collisionsConfig;
300 bool shouldInitFlow()
const {
return _physicsConfig.size() > 0; }
301 bool shouldInitCollisions()
const {
return _collisionsConfig.size() > 0; }
307 using Pointer = std::shared_ptr<Model>;
308 using ConstPointer = std::shared_ptr<const Model>;
314 QVector<Joint> joints;
316 bool hasSkeletonJoints;
318 QVector<Mesh> meshes;
319 QVector<QString> scripts;
321 QHash<QString, Material> materials;
330 QVector<AnimationFrame> animationFrames;
332 int getJointIndex(
const QString& name)
const {
return jointIndices.value(name) - 1; }
333 QStringList getJointNames()
const;
335 bool hasBlendedMeshes()
const;
339 const Extents& getMeshExtents()
const {
return meshExtents; }
341 bool convexHullContains(
const glm::vec3& point)
const;
343 QHash<int, QString> meshIndicesToModelNames;
349 QList<QString> blendshapeChannelNames;
351 QMap<int, glm::quat> jointRotationOffsets;
352 std::vector<ShapeVertices> shapeVertices;
380 class ExtractedMesh {
383 QMultiHash<int, int> newIndices;
384 QVector<QHash<int, int> > blendshapeIndexMaps;
385 QVector<QPair<int, int> > partMaterialTextures;
386 QHash<QString, size_t> texcoordSetMap;
390 typedef hfm::JointShapeInfo HFMJointShapeInfo;
395 typedef hfm::Material HFMMaterial;
400 typedef hfm::FlowData FlowData;
403 Q_DECLARE_METATYPE(QVector<HFMAnimationFrame>)
405 Q_DECLARE_METATYPE(HFMModel::Pointer)
A simple object wrapper for an OpenGL texture.
Definition: material-networking/src/material-networking/TextureCache.h:39
A single animation frame.
Definition: HFM.h:271
A single blendshape.
Definition: HFM.h:71
A single binding to a joint.
Definition: HFM.h:124
A single joint (transformation node).
Definition: HFM.h:88
A light.
Definition: HFM.h:278
A single mesh (with optional blendshapes).
Definition: HFM.h:242
A single part of a mesh (with the same material).
Definition: HFM.h:155
The runtime model format.
Definition: HFM.h:305
Extents getUnscaledMeshExtents() const
Returns the unscaled extents of the model's mesh.
Definition: HFM.cpp:113
int loadWarningCount
Get the number of warnings that were generated when loading this model.
Definition: HFM.h:365
int loadErrorCount
Get the number of errors that were generated when loading this model.
Definition: HFM.h:374
QString applicationName
the name of the application that generated the model
Definition: HFM.h:312
QHash< QString, int > jointIndices
1-based, so as to more easily detect missing indices
Definition: HFM.h:315
QString getModelNameOfMesh(int meshIndex) const
given a meshIndex this will return the name of the model that mesh belongs to if known
Definition: HFM.cpp:175
A texture map.
Definition: HFM.h:133