-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathSceneSelector.cpp
110 lines (88 loc) · 2.67 KB
/
SceneSelector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
// Copyright 2023-2024 The Khronos Group
// SPDX-License-Identifier: Apache-2.0
#include "SceneSelector.h"
// anari_viewer
#include "anari_viewer/ui_anari.h"
namespace anari_viewer::windows {
static bool UI_callback(void *_stringList, int index, const char **out_text)
{
auto &stringList = *(std::vector<std::string> *)_stringList;
*out_text = stringList[index].c_str();
return true;
}
static void buildUISceneHandle(
anari::scenes::SceneHandle s, helium::ParameterInfo &p)
{
if (ui::buildUI(p))
anari::scenes::setParameter(s, p.name, p.value);
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
SceneSelector::SceneSelector(const char *name) : Window(name, true)
{
m_categories = anari::scenes::getAvailableSceneCategories();
m_scenes.resize(m_categories.size());
for (int i = 0; i < m_categories.size(); i++) {
m_scenes[i] =
anari::scenes::getAvailableSceneNames(m_categories[i].c_str());
}
}
SceneSelector::~SceneSelector()
{
anari::scenes::release(m_scene);
}
void SceneSelector::buildUI()
{
bool newCategory = ImGui::Combo("category##whichCategory",
&m_currentCategory,
UI_callback,
&m_categories,
m_categories.size());
if (newCategory)
m_currentScene = 0;
auto &sceneList = m_scenes[m_currentCategory];
bool newScene = ImGui::Combo("scene##whichScene",
&m_currentScene,
UI_callback,
&sceneList,
sceneList.size());
if (newCategory || newScene)
notify();
ImGui::Separator();
if (m_parameters.empty())
return;
for (auto &p : m_parameters)
buildUISceneHandle(m_scene, p);
ImGui::NewLine();
if (ImGui::Button("update")) {
try {
anari::scenes::commit(m_scene);
} catch (const std::runtime_error &e) {
printf("%s\n", e.what());
}
}
}
void SceneSelector::setCallback(SceneSelectionCallback cb)
{
m_callback = cb;
notify();
}
void SceneSelector::setScene(anari::scenes::SceneHandle scene)
{
anari::scenes::release(m_scene);
m_scene = scene;
m_parameters = getParameters(scene);
}
void SceneSelector::notify()
{
if (m_callback) {
const char *c = m_categories[m_currentCategory].c_str();
const char *s = m_scenes[m_currentCategory][m_currentScene].c_str();
m_callback(c, s);
}
}
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
} // namespace anari_viewer::windows