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 const QVariantHash& getMapping()
const {
return _mapping; }
65 HFMModel::ConstPointer _hfmModel;
66 MaterialMapping _materialMapping;
67 std::shared_ptr<const GeometryMeshes> _meshes;
68 std::shared_ptr<const GeometryMeshParts> _meshParts;
71 NetworkMaterials _materials;
73 QUrl _animGraphOverrideUrl;
74 QVariantHash _mapping;
77 mutable bool _areTexturesLoaded {
false };
84 using Pointer = QSharedPointer<GeometryResource>;
89 QString getType()
const override {
return "Geometry"; }
91 virtual void deleter()
override;
94 void setExtra(
void* extra)
override;
96 virtual bool areTexturesLoaded()
const override {
return isLoaded() && Geometry::areTexturesLoaded(); }
99 void onGeometryMappingLoaded(
bool success);
104 Q_INVOKABLE
void setGeometryDefinition(HFMModel::Pointer hfmModel,
const MaterialMapping& materialMapping);
108 bool shouldSetTextures()
const {
return _hfmModel && _materials.empty(); }
110 void resetTextures();
112 virtual bool isCacheable()
const override {
return _loaded && _isCacheable; }
115 ModelLoader _modelLoader;
116 GeometryMappingPair _mappingPair;
117 QUrl _textureBaseURL;
120 GeometryResource::Pointer _geometryResource;
121 QMetaObject::Connection _connection;
123 bool _isCacheable{
true };
126 class GeometryResourceWatcher :
public QObject {
129 using Pointer = std::shared_ptr<GeometryResourceWatcher>;
131 GeometryResourceWatcher() =
delete;
132 GeometryResourceWatcher(Geometry::Pointer& geometryPtr) : _geometryRef(geometryPtr) {}
134 void setResource(GeometryResource::Pointer resource);
136 QUrl getURL()
const {
return (
bool)_resource ? _resource->getURL() : QUrl(); }
137 int getResourceDownloadAttempts() {
return _resource ? _resource->getDownloadAttempts() : 0; }
138 int getResourceDownloadAttemptsRemaining() {
return _resource ? _resource->getDownloadAttemptsRemaining() : 0; }
141 void startWatching();
145 void finished(
bool success);
148 void resourceFinished(
bool success);
149 void resourceRefreshed();
152 GeometryResource::Pointer _resource;
153 Geometry::Pointer& _geometryRef;
163 GeometryResource::Pointer getGeometryResource(
const QUrl& url,
164 const GeometryMappingPair& mapping =
165 GeometryMappingPair(QUrl(), QVariantHash()),
166 const QUrl& textureBaseUrl = QUrl());
168 GeometryResource::Pointer getCollisionGeometryResource(
const QUrl& url,
169 const GeometryMappingPair& mapping =
170 GeometryMappingPair(QUrl(), QVariantHash()),
171 const QUrl& textureBaseUrl = QUrl());
176 virtual QSharedPointer<Resource>
createResource(
const QUrl& url)
override;
177 QSharedPointer<Resource> createResourceCopy(
const QSharedPointer<Resource>& resource)
override;
182 ModelLoader _modelLoader;
187 MeshPart(
int mesh,
int part,
int material) : meshID { mesh }, partID { part }, materialID { material } {}
190 int materialID { -1 };
A geometry loaded from the network.
Definition: ModelCache.h:81
virtual bool isCacheable() const override
Checks whether the resource is cacheable.
Definition: ModelCache.h:112
virtual void downloadFinished(const QByteArray &data) override
Definition: ModelCache.cpp:220
Stores cached model geometries.
Definition: ModelCache.h:157
virtual QSharedPointer< Resource > createResource(const QUrl &url) override
Creates a new resource.
Definition: ModelCache.cpp:391
Base class for resource caches.
Definition: ResourceCache.h:196
Base class for resources.
Definition: ResourceCache.h:409
virtual bool isLoaded() const
Checks whether the resource has loaded.
Definition: ResourceCache.h:439
The runtime model format.
Definition: HFM.h:302