Overte C++ Documentation
AnimationCache.h
1 //
2 // AnimationCache.h
3 // libraries/animation/src/
4 //
5 // Created by Andrzej Kapolka on 4/14/14.
6 // Copyright (c) 2014 High Fidelity, Inc. All rights reserved.
7 // Copyright Overte e.V. 2023
8 //
9 // Distributed under the Apache License, Version 2.0.
10 // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
11 // SPDX-License-Identifier: Apache-2.0
12 //
13 
14 #ifndef hifi_AnimationCache_h
15 #define hifi_AnimationCache_h
16 
17 #include <QtCore/QRunnable>
18 #include <QtCore/QSharedPointer>
19 
20 #include <DependencyManager.h>
21 #include <hfm/HFM.h>
22 #include <ResourceCache.h>
23 
24 class Animation;
25 
26 using AnimationPointer = QSharedPointer<Animation>;
27 
28 class AnimationCache : public ResourceCache, public Dependency {
29  Q_OBJECT
30  SINGLETON_DEPENDENCY
31 
32 public:
33 
34  Q_INVOKABLE AnimationPointer getAnimation(const QString& url) { return getAnimation(QUrl(url)); }
35  Q_INVOKABLE AnimationPointer getAnimation(const QUrl& url);
36 
37 protected:
38  virtual QSharedPointer<Resource> createResource(const QUrl& url) override;
39  QSharedPointer<Resource> createResourceCopy(const QSharedPointer<Resource>& resource) override;
40 
41 private:
42  explicit AnimationCache(QObject* parent = NULL);
43  virtual ~AnimationCache() { }
44 
45 };
46 
47 Q_DECLARE_METATYPE(AnimationPointer)
48 
49 class Animation : public Resource {
51  Q_OBJECT
52 
53 public:
54 
55  Animation(const Animation& other) : Resource(other), _hfmModel(other._hfmModel) {}
56  Animation(const QUrl& url) : Resource(url) {}
57 
58  QString getType() const override { return "Animation"; }
59 
60  const HFMModel& getHFMModel() const { return *_hfmModel; }
61 
62  virtual bool isLoaded() const override;
63 
64  Q_INVOKABLE QStringList getJointNames() const;
65 
66  Q_INVOKABLE QVector<HFMAnimationFrame> getFrames() const;
67 
68  const QVector<HFMAnimationFrame>& getFramesReference() const;
69 
70 protected:
71  virtual void downloadFinished(const QByteArray& data) override;
72 
73 protected slots:
74  void animationParseSuccess(HFMModel::Pointer hfmModel);
75  void animationParseError(int error, QString str);
76 
77 private:
78 
79  HFMModel::Pointer _hfmModel;
80 };
81 
83 class AnimationReader : public QObject, public QRunnable {
84  Q_OBJECT
85 
86 public:
87  AnimationReader(const QUrl& url, const QByteArray& data);
88  virtual void run() override;
89 
90 signals:
91  void onSuccess(HFMModel::Pointer hfmModel);
92  void onError(int error, QString str);
93 
94 private:
95  QUrl _url;
96  QByteArray _data;
97 };
98 
99 
100 #endif // hifi_AnimationCache_h
An animation loaded from the network.
Definition: AnimationCache.h:83
Base class for resource caches.
Definition: ResourceCache.h:196
virtual QSharedPointer< Resource > createResource(const QUrl &url)=0
Creates a new resource.
Base class for resources.
Definition: ResourceCache.h:409
The runtime model format.
Definition: HFM.h:302