|
5 | 5 | #include <array> |
6 | 6 | #include <cmath> |
7 | 7 | #include <iostream> |
| 8 | +#include <memory> |
8 | 9 | #include <tuple> |
9 | 10 | #include <utility> |
10 | 11 |
|
11 | 12 | #include "flutter/testing/testing.h" |
12 | 13 | #include "impeller/aiks/aiks_playground.h" |
13 | 14 | #include "impeller/aiks/canvas.h" |
14 | 15 | #include "impeller/aiks/image.h" |
| 16 | +#include "impeller/entity/contents/color_source_contents.h" |
15 | 17 | #include "impeller/entity/contents/filters/inputs/filter_input.h" |
| 18 | +#include "impeller/entity/contents/scene_contents.h" |
16 | 19 | #include "impeller/entity/contents/tiled_texture_contents.h" |
17 | 20 | #include "impeller/geometry/color.h" |
18 | 21 | #include "impeller/geometry/geometry_unittests.h" |
|
21 | 24 | #include "impeller/playground/widgets.h" |
22 | 25 | #include "impeller/renderer/command_buffer.h" |
23 | 26 | #include "impeller/renderer/snapshot.h" |
| 27 | +#include "impeller/scene/material.h" |
| 28 | +#include "impeller/scene/node.h" |
24 | 29 | #include "impeller/typographer/backends/skia/text_frame_skia.h" |
25 | 30 | #include "impeller/typographer/backends/skia/text_render_context_skia.h" |
26 | 31 | #include "third_party/skia/include/core/SkData.h" |
@@ -1700,5 +1705,53 @@ TEST_P(AiksTest, SaveLayerFiltersScaleWithTransform) { |
1700 | 1705 | ASSERT_TRUE(OpenPlaygroundHere(canvas.EndRecordingAsPicture())); |
1701 | 1706 | } |
1702 | 1707 |
|
| 1708 | +TEST_P(AiksTest, SceneColorSource) { |
| 1709 | + // Load up the scene. |
| 1710 | + auto mapping = |
| 1711 | + flutter::testing::OpenFixtureAsMapping("flutter_logo.glb.ipscene"); |
| 1712 | + ASSERT_NE(mapping, nullptr); |
| 1713 | + |
| 1714 | + std::shared_ptr<scene::Node> gltf_scene = scene::Node::MakeFromFlatbuffer( |
| 1715 | + *mapping, *GetContext()->GetResourceAllocator()); |
| 1716 | + ASSERT_NE(gltf_scene, nullptr); |
| 1717 | + |
| 1718 | + // Assign a material (temporary stopgap). |
| 1719 | + std::shared_ptr<scene::UnlitMaterial> material = scene::Material::MakeUnlit(); |
| 1720 | + auto color_baked = CreateTextureForFixture("flutter_logo_baked.png"); |
| 1721 | + ASSERT_NE(color_baked, nullptr); |
| 1722 | + material->SetColorTexture(std::move(color_baked)); |
| 1723 | + material->SetVertexColorWeight(0); |
| 1724 | + |
| 1725 | + ASSERT_EQ(gltf_scene->GetChildren().size(), 1u); |
| 1726 | + ASSERT_EQ(gltf_scene->GetChildren()[0]->GetMesh().GetPrimitives().size(), 1u); |
| 1727 | + gltf_scene->GetChildren()[0]->GetMesh().GetPrimitives()[0].material = |
| 1728 | + std::move(material); |
| 1729 | + |
| 1730 | + auto callback = [&](AiksContext& renderer, RenderTarget& render_target) { |
| 1731 | + Paint paint; |
| 1732 | + |
| 1733 | + paint.color_source_type = Paint::ColorSourceType::kScene; |
| 1734 | + paint.color_source = [this, gltf_scene]() { |
| 1735 | + Scalar angle = GetSecondsElapsed(); |
| 1736 | + Scalar distance = 2; |
| 1737 | + auto camera_position = |
| 1738 | + Vector3(distance * std::sin(angle), 2, -distance * std::cos(angle)); |
| 1739 | + auto contents = std::make_shared<SceneContents>(); |
| 1740 | + contents->SetNode(gltf_scene); |
| 1741 | + contents->SetCameraTransform( |
| 1742 | + Matrix::MakePerspective(Degrees(45), GetWindowSize(), 0.1, 1000) * |
| 1743 | + Matrix::MakeLookAt(camera_position, {0, 0, 0}, {0, 1, 0})); |
| 1744 | + return contents; |
| 1745 | + }; |
| 1746 | + |
| 1747 | + Canvas canvas; |
| 1748 | + canvas.Scale(GetContentScale()); |
| 1749 | + canvas.DrawPaint(paint); |
| 1750 | + return renderer.Render(canvas.EndRecordingAsPicture(), render_target); |
| 1751 | + }; |
| 1752 | + |
| 1753 | + ASSERT_TRUE(OpenPlaygroundHere(callback)); |
| 1754 | +} |
| 1755 | + |
1703 | 1756 | } // namespace testing |
1704 | 1757 | } // namespace impeller |
0 commit comments