Flutter Impeller
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"
14
#include "
impeller/base/thread.h
"
15
#include "
impeller/base/thread_safety.h
"
16
#include "
impeller/core/texture.h
"
17
#include "
impeller/geometry/matrix.h
"
18
#include "
impeller/renderer/render_target.h
"
19
#include "
impeller/scene/animation/animation.h
"
20
#include "
impeller/scene/animation/animation_clip.h
"
21
#include "
impeller/scene/animation/animation_player.h
"
22
#include "
impeller/scene/camera.h
"
23
#include "
impeller/scene/mesh.h
"
24
#include "
impeller/scene/scene_encoder.h
"
25
#include "
impeller/scene/skin.h
"
26
27
namespace
impeller
{
28
namespace
scene {
29
30
class
Node
final {
31
public
:
32
class
MutationLog
{
33
public
:
34
struct
SetTransformEntry
{
35
Matrix
transform
;
36
};
37
38
struct
SetAnimationStateEntry
{
39
std::string
animation_name
;
40
bool
playing
=
false
;
41
bool
loop
=
false
;
42
Scalar
weight
= 0;
43
Scalar
time_scale
= 1;
44
};
45
46
struct
SeekAnimationEntry
{
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
();
73
~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
87
void
SetLocalTransform
(
Matrix
transform);
88
Matrix
GetLocalTransform
()
const
;
89
90
void
SetGlobalTransform
(
Matrix
transform);
91
Matrix
GetGlobalTransform
()
const
;
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
102
bool
Render
(
SceneEncoder
& encoder,
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_
animation.h
impeller::scene::Node::Node
Node()
Definition:
node.cc:224
impeller::scene::Node::GetLocalTransform
Matrix GetLocalTransform() const
Definition:
node.cc:282
impeller::scene::Node::GetParent
Node * GetParent() const
Definition:
node.cc:240
impeller::Scalar
float Scalar
Definition:
scalar.h:18
impeller::scene::Mesh
Definition:
mesh.h:21
impeller::scene::Node::FindChildByName
std::shared_ptr< Node > FindChildByName(const std::string &name, bool exclude_animation_players=false) const
Definition:
node.cc:244
impeller::scene::Node::~Node
~Node()
impeller::scene::Node::SetIsJoint
void SetIsJoint(bool is_joint)
Definition:
node.cc:337
impeller::scene::Node::MutationLog::SetAnimationStateEntry::playing
bool playing
Definition:
node.h:40
animation_player.h
impeller::scene::Node::SetMesh
void SetMesh(Mesh mesh)
Definition:
node.cc:329
impeller::scene::AnimationClip
Definition:
animation_clip.h:22
impeller::scene::Node::GetName
const std::string & GetName() const
Definition:
node.cc:232
scene_encoder.h
impeller::scene::Node::GetChildren
std::vector< std::shared_ptr< Node > > & GetChildren()
Definition:
node.cc:325
impeller::scene::Node::SetName
void SetName(const std::string &new_name)
Definition:
node.cc:236
matrix.h
impeller::scene::Node::MutationLog::SetTransformEntry::transform
Matrix transform
Definition:
node.h:35
impeller::scene::Node::FindAnimationByName
std::shared_ptr< Animation > FindAnimationByName(const std::string &name) const
Definition:
node.cc:261
animation_clip.h
impeller::scene::Node::MutationLog::SeekAnimationEntry::animation_name
std::string animation_name
Definition:
node.h:47
thread_safety.h
impeller::scene::Node::MutationLog::SeekAnimationEntry::time
float time
Definition:
node.h:48
impeller::scene::Node::MutationLog::SetAnimationStateEntry
Definition:
node.h:38
impeller::Allocator
An object that allocates device memory.
Definition:
allocator.h:22
impeller::scene::Node::GetMesh
Mesh & GetMesh()
Definition:
node.cc:333
mesh.h
impeller::scene::Node::MutationLog::SetTransformEntry
Definition:
node.h:34
camera.h
impeller::scene::Node::SetGlobalTransform
void SetGlobalTransform(Matrix transform)
Definition:
node.cc:286
impeller::scene::Node::AddChild
bool AddChild(std::shared_ptr< Node > child)
Definition:
node.cc:300
impeller::scene::Node::Render
bool Render(SceneEncoder &encoder, Allocator &allocator, const Matrix &parent_transform)
Definition:
node.cc:345
impeller::scene::Node::MutationLog::SetAnimationStateEntry::time_scale
Scalar time_scale
Definition:
node.h:43
impeller::scene::Node::MutationLog::Entry
std::variant< SetTransformEntry, SetAnimationStateEntry, SeekAnimationEntry > Entry
Definition:
node.h:52
textures
std::vector< std::shared_ptr< FakeTexture > > textures
Definition:
content_context_unittests.cc:92
impeller::scene::Node::IsJoint
bool IsJoint() const
Definition:
node.cc:341
impeller::scene::Node::MutationLog::SeekAnimationEntry
Definition:
node.h:46
impeller::scene::Node::MutationLog::SetAnimationStateEntry::loop
bool loop
Definition:
node.h:41
texture.h
impeller::scene::Node::AddAnimation
AnimationClip * AddAnimation(const std::shared_ptr< Animation > &animation)
Definition:
node.cc:271
impeller::scene::Node
Definition:
node.h:30
impeller::scene::Scene
Definition:
scene.h:21
impeller::scene::Node::AddMutation
void AddMutation(const MutationLog::Entry &entry)
Definition:
node.cc:412
impeller::scene::SceneEncoder
Definition:
scene_encoder.h:30
render_target.h
impeller::scene::Node::SetLocalTransform
void SetLocalTransform(Matrix transform)
Definition:
node.cc:278
impeller::scene::Node::MakeFromFlatbuffer
static std::shared_ptr< Node > MakeFromFlatbuffer(const fml::Mapping &ipscene_mapping, Allocator &allocator)
Definition:
node.cc:47
impeller::scene::Node::MutationLog::SetAnimationStateEntry::animation_name
std::string animation_name
Definition:
node.h:39
thread.h
impeller
Definition:
aiks_blur_unittests.cc:20
impeller::scene::Node::MutationLog::Append
void Append(const Entry &entry)
Definition:
node.cc:29
skin.h
impeller::scene::Node::MutationLog
Definition:
node.h:32
impeller::scene::Node::GetGlobalTransform
Matrix GetGlobalTransform() const
Definition:
node.cc:293
impeller::Matrix
A 4x4 matrix using column-major storage.
Definition:
matrix.h:37
impeller::scene::Node::MutationLog::SetAnimationStateEntry::weight
Scalar weight
Definition:
node.h:42
impeller
scene
node.h
Generated by
1.8.17