Flutter Engine
The Flutter Engine
node.h
Go to the documentation of this file.
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#ifndef FLUTTER_IMPELLER_SCENE_NODE_H_
6#define FLUTTER_IMPELLER_SCENE_NODE_H_
7
8#include <memory>
9#include <optional>
10#include <vector>
11
19#include "impeller/scene/mesh.h"
21#include "impeller/scene/skin.h"
22
23namespace impeller {
24namespace scene {
25
26class Node final {
27 public:
29 public:
32 };
33
35 std::string animation_name;
36 bool playing = false;
37 bool loop = false;
40 };
41
43 std::string animation_name;
44 float time = 0;
45 };
46
47 using Entry = std::
48 variant<SetTransformEntry, SetAnimationStateEntry, SeekAnimationEntry>;
49
50 void Append(const Entry& entry);
51
52 private:
53 std::optional<std::vector<Entry>> Flush();
54
55 RWMutex write_mutex_;
56 bool dirty_ IPLR_GUARDED_BY(write_mutex_) = false;
57 std::vector<Entry> entries_ IPLR_GUARDED_BY(write_mutex_);
58
59 friend Node;
60 };
61
62 static std::shared_ptr<Node> MakeFromFlatbuffer(
63 const fml::Mapping& ipscene_mapping,
64 Allocator& allocator);
65 static std::shared_ptr<Node> MakeFromFlatbuffer(const fb::Scene& scene,
66 Allocator& allocator);
67
68 Node();
70
71 const std::string& GetName() const;
72 void SetName(const std::string& new_name);
73
74 Node* GetParent() const;
75
76 std::shared_ptr<Node> FindChildByName(
77 const std::string& name,
78 bool exclude_animation_players = false) const;
79
80 std::shared_ptr<Animation> FindAnimationByName(const std::string& name) const;
81 AnimationClip* AddAnimation(const std::shared_ptr<Animation>& animation);
82
85
88
89 bool AddChild(std::shared_ptr<Node> child);
90 std::vector<std::shared_ptr<Node>>& GetChildren();
91
92 void SetMesh(Mesh mesh);
93 Mesh& GetMesh();
94
95 void SetIsJoint(bool is_joint);
96 bool IsJoint() const;
97
99 Allocator& allocator,
100 const Matrix& parent_transform);
101
102 void AddMutation(const MutationLog::Entry& entry);
103
104 private:
105 void UnpackFromFlatbuffer(
106 const fb::Node& node,
107 const std::vector<std::shared_ptr<Node>>& scene_nodes,
108 const std::vector<std::shared_ptr<Texture>>& textures,
109 Allocator& allocator);
110
111 mutable MutationLog mutation_log_;
112
113 Matrix local_transform_;
114
115 std::string name_;
116 bool is_root_ = false;
117 bool is_joint_ = false;
118 Node* parent_ = nullptr;
119 std::vector<std::shared_ptr<Node>> children_;
120 Mesh mesh_;
121
122 // For convenience purposes, deserialized nodes hang onto an animation library
123 std::vector<std::shared_ptr<Animation>> animations_;
124 mutable std::optional<AnimationPlayer> animation_player_;
125
126 std::unique_ptr<Skin> skin_;
127
128 Node(const Node&) = delete;
129
130 Node& operator=(const Node&) = delete;
131
132 friend Scene;
133};
134
135} // namespace scene
136} // namespace impeller
137
138#endif // FLUTTER_IMPELLER_SCENE_NODE_H_
An object that allocates device memory.
Definition: allocator.h:22
std::variant< SetTransformEntry, SetAnimationStateEntry, SeekAnimationEntry > Entry
Definition: node.h:48
void Append(const Entry &entry)
Definition: node.cc:29
void SetIsJoint(bool is_joint)
Definition: node.cc:337
bool AddChild(std::shared_ptr< Node > child)
Definition: node.cc:300
void SetLocalTransform(Matrix transform)
Definition: node.cc:278
void SetGlobalTransform(Matrix transform)
Definition: node.cc:286
Node * GetParent() const
Definition: node.cc:240
std::shared_ptr< Animation > FindAnimationByName(const std::string &name) const
Definition: node.cc:261
Matrix GetGlobalTransform() const
Definition: node.cc:293
AnimationClip * AddAnimation(const std::shared_ptr< Animation > &animation)
Definition: node.cc:271
void AddMutation(const MutationLog::Entry &entry)
Definition: node.cc:412
bool Render(SceneEncoder &encoder, Allocator &allocator, const Matrix &parent_transform)
Definition: node.cc:345
const std::string & GetName() const
Definition: node.cc:232
void SetName(const std::string &new_name)
Definition: node.cc:236
std::shared_ptr< Node > FindChildByName(const std::string &name, bool exclude_animation_players=false) const
Definition: node.cc:244
Mesh & GetMesh()
Definition: node.cc:333
std::vector< std::shared_ptr< Node > > & GetChildren()
Definition: node.cc:325
void SetMesh(Mesh mesh)
Definition: node.cc:329
bool IsJoint() const
Definition: node.cc:341
Matrix GetLocalTransform() const
Definition: node.cc:282
static std::shared_ptr< Node > MakeFromFlatbuffer(const fml::Mapping &ipscene_mapping, Allocator &allocator)
Definition: node.cc:47
SkMesh mesh
Definition: SkRecords.h:345
DEF_SWITCHES_START aot vmservice shared library name
Definition: switches.h:32
float Scalar
Definition: scalar.h:18
static SkColor4f transform(SkColor4f c, SkColorSpace *src, SkColorSpace *dst)
Definition: p3.cpp:47
A 4x4 matrix using column-major storage.
Definition: matrix.h:37