1 | #pragma once |
---|---|
2 | |
3 | #include <vector> |
4 | |
5 | #include "taichi/program/field_info.h" |
6 | #include "taichi/ui/common/renderable_info.h" |
7 | #include "taichi/ui/common/camera.h" |
8 | #include "taichi/ui/utils/utils.h" |
9 | |
10 | namespace taichi::ui { |
11 | |
12 | struct alignas(16) PointLight { |
13 | glm::vec4 pos; |
14 | glm::vec4 color; |
15 | }; |
16 | |
17 | struct MeshAttributeInfo { |
18 | FieldInfo mesh_attribute; |
19 | bool has_attribute{false}; |
20 | }; |
21 | |
22 | struct MeshInfo { |
23 | RenderableInfo renderable_info; |
24 | glm::vec3 color; |
25 | bool two_sided{false}; |
26 | int object_id{0}; |
27 | int num_instances{1}; |
28 | int start_instance{0}; |
29 | MeshAttributeInfo mesh_attribute_info; |
30 | }; |
31 | |
32 | struct ParticlesInfo { |
33 | RenderableInfo renderable_info; |
34 | glm::vec3 color; |
35 | float radius{0}; |
36 | int object_id{0}; |
37 | }; |
38 | |
39 | struct SceneLinesInfo { |
40 | RenderableInfo renderable_info; |
41 | glm::vec3 color; |
42 | float width{0}; |
43 | int object_id{0}; |
44 | }; |
45 | |
46 | class SceneBase { |
47 | public: |
48 | void set_camera(const Camera &camera) { |
49 | camera_ = camera; |
50 | } |
51 | void lines(const SceneLinesInfo &info) { |
52 | scene_lines_infos_.push_back(info); |
53 | scene_lines_infos_.back().object_id = next_object_id_++; |
54 | } |
55 | void mesh(const MeshInfo &info) { |
56 | mesh_infos_.push_back(info); |
57 | mesh_infos_.back().object_id = next_object_id_++; |
58 | } |
59 | void particles(const ParticlesInfo &info) { |
60 | particles_infos_.push_back(info); |
61 | particles_infos_.back().object_id = next_object_id_++; |
62 | } |
63 | void point_light(glm::vec3 pos, glm::vec3 color) { |
64 | point_lights_.push_back({glm::vec4(pos, 1.0), glm::vec4(color, 1.0)}); |
65 | } |
66 | void ambient_light(glm::vec3 color) { |
67 | ambient_light_color_ = color; |
68 | } |
69 | virtual ~SceneBase() = default; |
70 | |
71 | protected: |
72 | Camera camera_; |
73 | glm::vec3 ambient_light_color_ = glm::vec3(0.1, 0.1, 0.1); |
74 | std::vector<PointLight> point_lights_; |
75 | std::vector<SceneLinesInfo> scene_lines_infos_; |
76 | std::vector<MeshInfo> mesh_infos_; |
77 | std::vector<ParticlesInfo> particles_infos_; |
78 | int next_object_id_ = 0; |
79 | }; |
80 | |
81 | } // namespace taichi::ui |
82 |