Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
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 <mutex>
10#include <optional>
11#include <vector>
12
13#include "flutter/fml/macros.h"
23#include "impeller/scene/mesh.h"
25#include "impeller/scene/skin.h"
26
27namespace impeller {
28namespace scene {
29
30class Node final {
31 public:
33 public:
37
39 std::string animation_name;
40 bool playing = false;
41 bool loop = false;
44 };
45
47 std::string animation_name;
48 float time = 0;
49 };
50
51 using Entry = std::
52 variant<SetTransformEntry, SetAnimationStateEntry, SeekAnimationEntry>;
53
54 void Append(const Entry& entry);
55
56 private:
57 std::optional<std::vector<Entry>> Flush();
58
59 RWMutex write_mutex_;
60 bool dirty_ IPLR_GUARDED_BY(write_mutex_) = false;
61 std::vector<Entry> entries_ IPLR_GUARDED_BY(write_mutex_);
62
63 friend Node;
64 };
65
66 static std::shared_ptr<Node> MakeFromFlatbuffer(
67 const fml::Mapping& ipscene_mapping,
68 Allocator& allocator);
69 static std::shared_ptr<Node> MakeFromFlatbuffer(const fb::Scene& scene,
70 Allocator& allocator);
71
72 Node();
74
75 const std::string& GetName() const;
76 void SetName(const std::string& new_name);
77
78 Node* GetParent() const;
79
80 std::shared_ptr<Node> FindChildByName(
81 const std::string& name,
82 bool exclude_animation_players = false) const;
83
84 std::shared_ptr<Animation> FindAnimationByName(const std::string& name) const;
85 AnimationClip* AddAnimation(const std::shared_ptr<Animation>& animation);
86
89
92
93 bool AddChild(std::shared_ptr<Node> child);
94 std::vector<std::shared_ptr<Node>>& GetChildren();
95
96 void SetMesh(Mesh mesh);
97 Mesh& GetMesh();
98
99 void SetIsJoint(bool is_joint);
100 bool IsJoint() const;
101
103 Allocator& allocator,
104 const Matrix& parent_transform);
105
106 void AddMutation(const MutationLog::Entry& entry);
107
108 private:
109 void UnpackFromFlatbuffer(
110 const fb::Node& node,
111 const std::vector<std::shared_ptr<Node>>& scene_nodes,
112 const std::vector<std::shared_ptr<Texture>>& textures,
113 Allocator& allocator);
114
115 mutable MutationLog mutation_log_;
116
117 Matrix local_transform_;
118
119 std::string name_;
120 bool is_root_ = false;
121 bool is_joint_ = false;
122 Node* parent_ = nullptr;
123 std::vector<std::shared_ptr<Node>> children_;
124 Mesh mesh_;
125
126 // For convenience purposes, deserialized nodes hang onto an animation library
127 std::vector<std::shared_ptr<Animation>> animations_;
128 mutable std::optional<AnimationPlayer> animation_player_;
129
130 std::unique_ptr<Skin> skin_;
131
132 Node(const Node&) = delete;
133
134 Node& operator=(const Node&) = delete;
135
136 friend Scene;
137};
138
139} // namespace scene
140} // namespace impeller
141
142#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:52
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
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
std::vector< std::shared_ptr< FakeTexture > > textures
const char * name
Definition fuchsia.cc:50
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
#define IPLR_GUARDED_BY(x)