| 1 | // Copyright 2013 The Flutter Authors. All rights reserved. |
|---|---|
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #pragma once |
| 6 | |
| 7 | #include <memory> |
| 8 | #include <string> |
| 9 | #include <vector> |
| 10 | |
| 11 | #include "flutter/fml/hash_combine.h" |
| 12 | #include "flutter/fml/macros.h" |
| 13 | #include "impeller/base/timing.h" |
| 14 | #include "impeller/geometry/quaternion.h" |
| 15 | #include "impeller/geometry/scalar.h" |
| 16 | #include "impeller/geometry/vector.h" |
| 17 | #include "impeller/scene/animation/property_resolver.h" |
| 18 | #include "impeller/scene/importer/scene_flatbuffers.h" |
| 19 | |
| 20 | namespace impeller { |
| 21 | namespace scene { |
| 22 | |
| 23 | class Node; |
| 24 | |
| 25 | class Animation final { |
| 26 | public: |
| 27 | static std::shared_ptr<Animation> MakeFromFlatbuffer( |
| 28 | const fb::Animation& animation, |
| 29 | const std::vector<std::shared_ptr<Node>>& scene_nodes); |
| 30 | |
| 31 | enum class Property { |
| 32 | kTranslation, |
| 33 | kRotation, |
| 34 | kScale, |
| 35 | }; |
| 36 | |
| 37 | struct BindKey { |
| 38 | std::string node_name; |
| 39 | Property property = Property::kTranslation; |
| 40 | |
| 41 | struct Hash { |
| 42 | std::size_t operator()(const BindKey& o) const { |
| 43 | return fml::HashCombine(o.node_name, o.property); |
| 44 | } |
| 45 | }; |
| 46 | |
| 47 | struct Equal { |
| 48 | bool operator()(const BindKey& lhs, const BindKey& rhs) const { |
| 49 | return lhs.node_name == rhs.node_name && lhs.property == rhs.property; |
| 50 | } |
| 51 | }; |
| 52 | }; |
| 53 | |
| 54 | struct Channel { |
| 55 | BindKey bind_target; |
| 56 | std::unique_ptr<PropertyResolver> resolver; |
| 57 | }; |
| 58 | ~Animation(); |
| 59 | |
| 60 | const std::string& GetName() const; |
| 61 | |
| 62 | const std::vector<Channel>& GetChannels() const; |
| 63 | |
| 64 | SecondsF GetEndTime() const; |
| 65 | |
| 66 | private: |
| 67 | Animation(); |
| 68 | |
| 69 | std::string name_; |
| 70 | std::vector<Channel> channels_; |
| 71 | SecondsF end_time_; |
| 72 | |
| 73 | FML_DISALLOW_COPY_AND_ASSIGN(Animation); |
| 74 | }; |
| 75 | |
| 76 | } // namespace scene |
| 77 | } // namespace impeller |
| 78 |
