9#include "flutter/fml/mapping.h"
10#include "flutter/testing/testing.h"
23#include "impeller/scene/importer/scene_flatbuffers.h"
27#include "third_party/flatbuffers/include/flatbuffers/verifier.h"
28#include "third_party/imgui/imgui.h"
38 auto scene_context = std::make_shared<SceneContext>(
GetContext());
41 auto allocator =
GetContext()->GetResourceAllocator();
42 auto scene =
Scene(scene_context);
66 scene.Render(render_target, camera);
74 auto allocator =
GetContext()->GetResourceAllocator();
78 ASSERT_NE(mapping,
nullptr);
80 flatbuffers::Verifier verifier(mapping->GetMapping(), mapping->GetSize());
81 ASSERT_TRUE(fb::VerifySceneBuffer(verifier));
83 std::shared_ptr<Node> gltf_scene =
85 ASSERT_NE(gltf_scene,
nullptr);
86 ASSERT_EQ(gltf_scene->GetChildren().size(), 1u);
87 ASSERT_EQ(gltf_scene->GetChildren()[0]->GetMesh().GetPrimitives().size(), 1u);
89 auto scene_context = std::make_shared<SceneContext>(
GetContext());
90 auto scene =
Scene(scene_context);
91 scene.GetRoot().AddChild(std::move(gltf_scene));
95 Quaternion rotation({0, 1, 0}, -GetSecondsElapsed() * 0.5);
96 Vector3 start_position(-1, -1.5, -5);
101 rotation * start_position)
106 scene.Render(render_target, camera);
115 GTEST_SKIP_(
"Temporarily disabled.");
117 auto allocator =
GetContext()->GetResourceAllocator();
121 ASSERT_NE(mapping,
nullptr);
123 std::shared_ptr<Node> gltf_scene =
125 ASSERT_NE(gltf_scene,
nullptr);
127 auto animation = gltf_scene->FindAnimationByName(
"Metronome");
128 ASSERT_NE(animation,
nullptr);
130 AnimationClip* metronome_clip = gltf_scene->AddAnimation(animation);
131 ASSERT_NE(metronome_clip,
nullptr);
133 metronome_clip->
Play();
135 auto scene_context = std::make_shared<SceneContext>(
GetContext());
136 auto scene =
Scene(scene_context);
137 scene.GetRoot().AddChild(std::move(gltf_scene));
140 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
142 static Scalar playback_time_scale = 1;
144 static bool loop =
true;
146 ImGui::SliderFloat(
"Playback time scale", &playback_time_scale, -5, 5);
147 ImGui::SliderFloat(
"Weight", &weight, -2, 2);
148 ImGui::Checkbox(
"Loop", &loop);
149 if (ImGui::Button(
"Play")) {
150 metronome_clip->
Play();
152 if (ImGui::Button(
"Pause")) {
153 metronome_clip->
Pause();
155 if (ImGui::Button(
"Stop")) {
156 metronome_clip->
Stop();
169 static ImVec2 mouse_pos_prev = ImGui::GetMousePos();
170 ImVec2 mouse_pos = ImGui::GetMousePos();
172 Vector2(mouse_pos.x - mouse_pos_prev.x, mouse_pos.y - mouse_pos_prev.y);
174 static Vector3 position(0, 1, -5);
175 static Vector3 cam_position = position;
177 Vector3(ImGui::IsKeyDown(ImGuiKey_D) - ImGui::IsKeyDown(ImGuiKey_A),
178 ImGui::IsKeyDown(ImGuiKey_E) - ImGui::IsKeyDown(ImGuiKey_Q),
179 ImGui::IsKeyDown(ImGuiKey_W) - ImGui::IsKeyDown(ImGuiKey_S));
180 position += strafe * 0.5;
181 cam_position = cam_position.
Lerp(position, 0.02);
188 cam_position +
Vector3(0, 0, 1),
191 scene.Render(render_target, camera);
199 auto allocator =
GetContext()->GetResourceAllocator();
209 ASSERT_NE(mapping,
nullptr);
211 std::shared_ptr<Node> gltf_scene =
213 ASSERT_NE(gltf_scene,
nullptr);
215 auto walk_anim = gltf_scene->FindAnimationByName(
"Walk");
216 ASSERT_NE(walk_anim,
nullptr);
218 AnimationClip* walk_clip = gltf_scene->AddAnimation(walk_anim);
219 ASSERT_NE(walk_clip,
nullptr);
223 auto run_anim = gltf_scene->FindAnimationByName(
"Run");
224 ASSERT_NE(walk_anim,
nullptr);
226 AnimationClip* run_clip = gltf_scene->AddAnimation(run_anim);
227 ASSERT_NE(run_clip,
nullptr);
231 auto scene_context = std::make_shared<SceneContext>(
GetContext());
232 auto scene =
Scene(scene_context);
233 scene.GetRoot().AddChild(std::move(gltf_scene));
236 ImGui::Begin(
"Controls",
nullptr, ImGuiWindowFlags_AlwaysAutoResize);
238 static Scalar playback_time_scale = 1;
241 static bool loop =
true;
243 ImGui::SliderFloat(
"Playback time scale", &playback_time_scale, -5, 5);
244 ImGui::SliderFloat(
"Walk weight", &walk, 0, 1);
245 ImGui::SliderFloat(
"Run weight", &
run, 0, 1);
246 ImGui::Checkbox(
"Loop", &loop);
247 if (ImGui::Button(
"Play")) {
251 if (ImGui::Button(
"Pause")) {
255 if (ImGui::Button(
"Stop")) {
274 static ImVec2 mouse_pos_prev = ImGui::GetMousePos();
275 ImVec2 mouse_pos = ImGui::GetMousePos();
277 Vector2(mouse_pos.x - mouse_pos_prev.x, mouse_pos.y - mouse_pos_prev.y);
279 static Vector3 position(0, 1, -5);
280 static Vector3 cam_position = position;
282 Vector3(ImGui::IsKeyDown(ImGuiKey_D) - ImGui::IsKeyDown(ImGuiKey_A),
283 ImGui::IsKeyDown(ImGuiKey_E) - ImGui::IsKeyDown(ImGuiKey_Q),
284 ImGui::IsKeyDown(ImGuiKey_W) - ImGui::IsKeyDown(ImGuiKey_S));
285 position += strafe * 0.5;
286 cam_position = cam_position.
Lerp(position, 0.02);
293 cam_position +
Vector3(0, 0, 1),
296 scene.Render(render_target, camera);
std::function< bool(RenderTarget &render_target)> RenderCallback
void SetPlaybackTimeScale(Scalar playback_speed)
Sets the animation playback speed. Negative values make the clip play in reverse.
void SetWeight(Scalar weight)
void SetLoop(bool looping)
static Camera MakePerspective(Radians fov_y, Vector3 position)
Camera LookAt(Vector3 target, Vector3 up=Vector3(0, -1, 0)) const
static std::shared_ptr< CuboidGeometry > MakeCuboid(Vector3 size)
static std::unique_ptr< UnlitMaterial > MakeUnlit()
void SetLocalTransform(Matrix transform)
std::vector< std::shared_ptr< Node > > & GetChildren()
Matrix GetLocalTransform() const
static std::shared_ptr< Node > MakeFromFlatbuffer(const fml::Mapping &ipscene_mapping, Allocator &allocator)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
SK_API GrDirectContext * GetContext(const SkImage *src)
std::unique_ptr< fml::Mapping > OpenFixtureAsMapping(const std::string &fixture_name)
Opens a fixture of the given file name and returns a mapping to its contents.
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
INSTANTIATE_PLAYGROUND_SUITE(SceneTest)
TEST_P(SceneTest, CuboidUnlit)
static constexpr Color Red()
static constexpr Matrix MakeTranslation(const Vector3 &t)
static constexpr Matrix MakeScale(const Vector3 &s)
static Matrix MakeRotation(Quaternion q)
constexpr Vector3 Lerp(const Vector3 &v, Scalar t) const