12 #ifndef hifi_ModelCache_h
13 #define hifi_ModelCache_h
15 #include <QtCore/QSharedPointer>
17 #include <DependencyManager.h>
18 #include <ResourceCache.h>
20 #include <graphics/Asset.h>
22 #include "FBXSerializer.h"
23 #include <procedural/ProceduralMaterialCache.h>
24 #include <material-networking/TextureCache.h>
25 #include "ModelLoader.h"
29 using GeometryMappingPair = std::pair<QUrl, QVariantHash>;
30 Q_DECLARE_METATYPE(GeometryMappingPair)
34 using Pointer = std::shared_ptr<Geometry>;
35 using WeakPointer = std::weak_ptr<Geometry>;
38 Geometry(
const Geometry& geometry);
39 virtual ~Geometry() =
default;
42 using GeometryMeshes = std::vector<std::shared_ptr<const graphics::Mesh>>;
43 using GeometryMeshParts = std::vector<std::shared_ptr<const MeshPart>>;
46 using NetworkMaterials = std::vector<std::shared_ptr<NetworkMaterial>>;
48 bool isHFMModelLoaded()
const {
return (
bool)_hfmModel; }
50 const HFMModel& getHFMModel()
const {
return *_hfmModel; }
51 const HFMModel::ConstPointer& getConstHFMModelPointer()
const {
return _hfmModel; }
52 const MaterialMapping& getMaterialMapping()
const {
return _materialMapping; }
53 const GeometryMeshes& getMeshes()
const {
return *_meshes; }
54 const std::shared_ptr<NetworkMaterial> getShapeMaterial(
int shapeID)
const;
56 const QVariantMap getTextures()
const;
57 void setTextures(
const QVariantMap& textureMap);
59 virtual bool areTexturesLoaded()
const;
60 const QUrl& getAnimGraphOverrideUrl()
const {
return _animGraphOverrideUrl; }
61 bool shouldWaitForWearables()
const {
return _waitForWearables; }
62 const QVariantHash& getMapping()
const {
return _mapping; }
66 HFMModel::ConstPointer _hfmModel;
67 MaterialMapping _materialMapping;
68 std::shared_ptr<const GeometryMeshes> _meshes;
69 std::shared_ptr<const GeometryMeshParts> _meshParts;
72 NetworkMaterials _materials;
74 QUrl _animGraphOverrideUrl;
75 QVariantHash _mapping;
76 bool _waitForWearables {
false };
79 mutable bool _areTexturesLoaded {
false };
86 using Pointer = QSharedPointer<GeometryResource>;
91 QString getType()
const override {
return "Geometry"; }
93 virtual void deleter()
override;
96 void setExtra(
void* extra)
override;
98 virtual bool areTexturesLoaded()
const override {
return isLoaded() && Geometry::areTexturesLoaded(); }
101 void onGeometryMappingLoaded(
bool success);
106 Q_INVOKABLE
void setGeometryDefinition(HFMModel::Pointer hfmModel,
const MaterialMapping& materialMapping);
110 bool shouldSetTextures()
const {
return _hfmModel && _materials.empty(); }
112 void resetTextures();
114 virtual bool isCacheable()
const override {
return _loaded && _isCacheable; }
117 ModelLoader _modelLoader;
118 GeometryMappingPair _mappingPair;
119 QUrl _textureBaseURL;
122 GeometryResource::Pointer _geometryResource;
123 QMetaObject::Connection _connection;
125 bool _isCacheable{
true };
128 class GeometryResourceWatcher :
public QObject {
131 using Pointer = std::shared_ptr<GeometryResourceWatcher>;
133 GeometryResourceWatcher() =
delete;
134 GeometryResourceWatcher(Geometry::Pointer& geometryPtr) : _geometryRef(geometryPtr) {}
136 void setResource(GeometryResource::Pointer resource);
138 QUrl getURL()
const {
return (
bool)_resource ? _resource->getURL() : QUrl(); }
139 int getResourceDownloadAttempts() {
return _resource ? _resource->getDownloadAttempts() : 0; }
140 int getResourceDownloadAttemptsRemaining() {
return _resource ? _resource->getDownloadAttemptsRemaining() : 0; }
143 void startWatching();
147 void finished(
bool success);
150 void resourceFinished(
bool success);
151 void resourceRefreshed();
154 GeometryResource::Pointer _resource;
155 Geometry::Pointer& _geometryRef;
165 GeometryResource::Pointer getGeometryResource(
const QUrl& url,
166 const GeometryMappingPair& mapping =
167 GeometryMappingPair(QUrl(), QVariantHash()),
168 const QUrl& textureBaseUrl = QUrl());
170 GeometryResource::Pointer getCollisionGeometryResource(
const QUrl& url,
171 const GeometryMappingPair& mapping =
172 GeometryMappingPair(QUrl(), QVariantHash()),
173 const QUrl& textureBaseUrl = QUrl());
178 virtual QSharedPointer<Resource>
createResource(
const QUrl& url)
override;
179 QSharedPointer<Resource> createResourceCopy(
const QSharedPointer<Resource>& resource)
override;
184 ModelLoader _modelLoader;
189 MeshPart(
int mesh,
int part,
int material) : meshID { mesh }, partID { part }, materialID { material } {}
192 int materialID { -1 };
A geometry loaded from the network.
Definition: ModelCache.h:83
virtual bool isCacheable() const override
Checks whether the resource is cacheable.
Definition: ModelCache.h:114
virtual void downloadFinished(const QByteArray &data) override
Definition: ModelCache.cpp:220
Stores cached model geometries.
Definition: ModelCache.h:159
virtual QSharedPointer< Resource > createResource(const QUrl &url) override
Creates a new resource.
Definition: ModelCache.cpp:392
Base class for resource caches.
Definition: ResourceCache.h:197
Base class for resources.
Definition: ResourceCache.h:415
virtual bool isLoaded() const
Checks whether the resource has loaded.
Definition: ResourceCache.h:439
The runtime model format.
Definition: HFM.h:305