19 #include <glm/glm.hpp>
20 #include <glm/gtc/quaternion.hpp>
23 #include <Transform.h>
25 #include <graphics/Geometry.h>
26 #include <graphics/Material.h>
28 #include <image/ColorChannel.h>
30 #if defined(Q_OS_ANDROID)
31 #define HFM_PACK_NORMALS 0
33 #define HFM_PACK_NORMALS 1
37 using NormalType = glm::uint32;
38 #define HFM_NORMAL_ELEMENT gpu::Element::VEC4F_NORMALIZED_XYZ10W2
40 using NormalType = glm::vec3;
41 #define HFM_NORMAL_ELEMENT gpu::Element::VEC3F_XYZ
44 #define HFM_PACK_COLORS 1
47 using ColorType = glm::uint32;
48 #define HFM_COLOR_ELEMENT gpu::Element::COLOR_RGBA_32
50 using ColorType = glm::vec3;
51 #define HFM_COLOR_ELEMENT gpu::Element::VEC3F_XYZ
54 const int MAX_NUM_PIXELS_FOR_FBX_TEXTURE = 8192 * 8192;
57 using ShapeVertices = std::vector<glm::vec3>;
59 static const int DRACO_MESH_VERSION = 3;
61 static const int DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES = 1000;
62 static const int DRACO_ATTRIBUTE_MATERIAL_ID = DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES;
63 static const int DRACO_ATTRIBUTE_TEX_COORD_1 = DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES + 1;
64 static const int DRACO_ATTRIBUTE_ORIGINAL_INDEX = DRACO_BEGIN_CUSTOM_HIFI_ATTRIBUTES + 2;
73 QVector<glm::vec3> vertices;
74 QVector<glm::vec3> normals;
75 QVector<glm::vec3> tangents;
78 struct JointShapeInfo {
81 std::vector<float> dots;
82 std::vector<glm::vec3> points;
83 std::vector<glm::vec3> debugLines;
89 JointShapeInfo shapeInfo;
91 float distanceToParent;
95 glm::vec3 translation;
96 glm::mat4 preTransform;
97 glm::quat preRotation;
99 glm::quat postRotation;
100 glm::mat4 postTransform;
105 glm::vec3 rotationMin;
106 glm::vec3 rotationMax;
107 glm::quat inverseDefaultRotation;
108 glm::quat inverseBindRotation;
109 glm::mat4 bindTransform;
111 bool isSkeletonJoint;
112 bool bindTransformFoundInCluster;
115 bool hasGeometricOffset;
116 glm::vec3 geometricTranslation;
117 glm::quat geometricRotation;
118 glm::vec3 geometricScaling;
127 glm::mat4 inverseBindMatrix;
128 Transform inverseBindTransform;
139 image::ColorChannel sourceChannel { image::ColorChannel::NONE };
142 int maxNumPixels { MAX_NUM_PIXELS_FOR_FBX_TEXTURE };
144 QString texcoordSetName;
146 bool isBumpmap{
false };
148 bool isNull()
const {
return name.isEmpty() && filename.isEmpty() && content.isEmpty(); }
155 QVector<int> quadIndices;
156 QVector<int> quadTrianglesIndices;
157 QVector<int> triangleIndices;
165 Material(
const glm::vec3& diffuseColor,
const glm::vec3& specularColor,
const glm::vec3& emissiveColor,
166 float shininess,
float opacity) :
167 diffuseColor(diffuseColor),
168 specularColor(specularColor),
169 emissiveColor(emissiveColor),
170 shininess(shininess),
173 void getTextureNames(QSet<QString>& textureList)
const;
174 void setMaxNumPixelsPerTexture(
int maxNumPixels);
176 glm::vec3 diffuseColor { 1.0f };
177 float diffuseFactor { 1.0f };
178 glm::vec3 specularColor { 0.02f };
179 float specularFactor { 1.0f };
181 glm::vec3 emissiveColor { 0.0f };
182 float emissiveFactor { 0.0f };
184 float shininess { 23.0f };
185 float opacity { 1.0f };
187 float metallic { 0.0f };
188 float roughness { 1.0f };
189 float emissiveIntensity { 1.0f };
190 float ambientFactor { 1.0f };
192 float bumpMultiplier { 1.0f };
194 graphics::MaterialKey::OpacityMapMode alphaMode { graphics::MaterialKey::OPACITY_MAP_BLEND };
195 float alphaCutoff { 0.5f };
199 QString shadingModel;
200 graphics::MaterialPointer _material;
213 glm::vec2 lightmapParams { 0.0f, 1.0f };
216 bool isPBSMaterial {
false };
218 bool useNormalMap {
false };
219 bool useAlbedoMap {
false };
220 bool useOpacityMap {
false };
221 bool useRoughnessMap {
false };
222 bool useSpecularMap {
false };
223 bool useMetallicMap {
false };
224 bool useEmissiveMap {
false };
225 bool useOcclusionMap {
false };
228 bool isMToonMaterial {
false };
235 bool needTangentSpace()
const;
242 QVector<MeshPart> parts;
244 QVector<glm::vec3> vertices;
245 QVector<glm::vec3> normals;
246 QVector<glm::vec3> tangents;
247 QVector<glm::vec3> colors;
248 QVector<glm::vec2> texCoords;
249 QVector<glm::vec2> texCoords1;
250 QVector<uint16_t> clusterIndices;
251 QVector<uint16_t> clusterWeights;
252 QVector<int32_t> originalIndices;
254 QVector<Cluster> clusters;
257 glm::mat4 modelTransform;
259 QVector<Blendshape> blendshapes;
261 unsigned int meshIndex;
263 graphics::MeshPointer _mesh;
264 bool wasCompressed {
false };
270 QVector<glm::quat> rotations;
271 QVector<glm::vec3> translations;
295 QVariantMap _physicsConfig;
296 QVariantMap _collisionsConfig;
297 bool shouldInitFlow()
const {
return _physicsConfig.size() > 0; }
298 bool shouldInitCollisions()
const {
return _collisionsConfig.size() > 0; }
304 using Pointer = std::shared_ptr<Model>;
305 using ConstPointer = std::shared_ptr<const Model>;
311 QVector<Joint> joints;
313 bool hasSkeletonJoints;
315 QVector<Mesh> meshes;
316 QVector<QString> scripts;
318 QHash<QString, Material> materials;
327 QVector<AnimationFrame> animationFrames;
329 int getJointIndex(
const QString& name)
const {
return jointIndices.value(name) - 1; }
330 QStringList getJointNames()
const;
332 bool hasBlendedMeshes()
const;
336 const Extents& getMeshExtents()
const {
return meshExtents; }
338 bool convexHullContains(
const glm::vec3& point)
const;
340 QHash<int, QString> meshIndicesToModelNames;
346 QList<QString> blendshapeChannelNames;
348 QMap<int, glm::quat> jointRotationOffsets;
349 std::vector<ShapeVertices> shapeVertices;
377 class ExtractedMesh {
380 QMultiHash<int, int> newIndices;
381 QVector<QHash<int, int> > blendshapeIndexMaps;
382 QVector<QPair<int, int> > partMaterialTextures;
383 QHash<QString, size_t> texcoordSetMap;
387 typedef hfm::JointShapeInfo HFMJointShapeInfo;
392 typedef hfm::Material HFMMaterial;
397 typedef hfm::FlowData FlowData;
400 Q_DECLARE_METATYPE(QVector<HFMAnimationFrame>)
402 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:268
A single blendshape.
Definition: HFM.h:70
A single binding to a joint.
Definition: HFM.h:123
A single joint (transformation node).
Definition: HFM.h:87
A light.
Definition: HFM.h:275
A single mesh (with optional blendshapes).
Definition: HFM.h:239
A single part of a mesh (with the same material).
Definition: HFM.h:152
The runtime model format.
Definition: HFM.h:302
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:362
int loadErrorCount
Get the number of errors that were generated when loading this model.
Definition: HFM.h:371
QString applicationName
the name of the application that generated the model
Definition: HFM.h:309
QHash< QString, int > jointIndices
1-based, so as to more easily detect missing indices
Definition: HFM.h:312
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:132