Add brush mode randomisation

This commit is contained in:
2026-01-26 04:08:49 +01:00
parent ba6d3c09f2
commit 304b3cad46
5 changed files with 117 additions and 7 deletions

View File

@@ -68,6 +68,12 @@ bool editor_mode::update()
Console::Update(); // to i tak trzeba wywoływać Console::Update(); // to i tak trzeba wywoływać
#endif #endif
m_userinterface->update(); m_userinterface->update();
// brush settings window
editor_ui *ui = static_cast<editor_ui *>(m_userinterface.get());
auto const mode = static_cast<editor_ui *>(m_userinterface.get())->mode();
ui->toggleBrushSettings(mode == nodebank_panel::BRUSH);
if (mouseHold) if (mouseHold)
{ {
auto const mode = static_cast<editor_ui *>(m_userinterface.get())->mode(); auto const mode = static_cast<editor_ui *>(m_userinterface.get())->mode();
@@ -83,7 +89,9 @@ bool editor_mode::update()
if (mode == nodebank_panel::BRUSH) if (mode == nodebank_panel::BRUSH)
{ {
const std::string *src = ui->get_active_node_template(); const std::string *src = ui->get_active_node_template();
// std::string name = "editor_" + std::to_string(LocalRandom(0.0, 100000.0)); // std::string name = "editor_" + std::to_string(LocalRandom(0.0, 100000.0));
std::string name = "editor_" + generate_uuid_v4(); std::string name = "editor_" + generate_uuid_v4();

View File

@@ -23,6 +23,7 @@ editor_ui::editor_ui()
add_external_panel(&m_itempropertiespanel); add_external_panel(&m_itempropertiespanel);
add_external_panel(&m_nodebankpanel); add_external_panel(&m_nodebankpanel);
add_external_panel(&m_functionspanel); add_external_panel(&m_functionspanel);
add_external_panel(&m_brushobjects);
} }
// updates state of UI elements // updates state of UI elements
@@ -41,6 +42,16 @@ void editor_ui::update()
ui_layer::update(); ui_layer::update();
m_itempropertiespanel.update(m_node); m_itempropertiespanel.update(m_node);
m_functionspanel.update(m_node); m_functionspanel.update(m_node);
auto ptr = get_active_node_template(true);
if (ptr)
m_brushobjects.update(*ptr);
}
void editor_ui::toggleBrushSettings(bool isVisible)
{
if (m_brushobjects.is_open != isVisible)
m_brushobjects.is_open = isVisible;
} }
void editor_ui::set_node(scene::basic_node *Node) void editor_ui::set_node(scene::basic_node *Node)
@@ -53,8 +64,12 @@ void editor_ui::add_node_template(const std::string &desc)
m_nodebankpanel.add_template(desc); m_nodebankpanel.add_template(desc);
} }
std::string const *editor_ui::get_active_node_template() std::string const *editor_ui::get_active_node_template(bool bypassRandom)
{ {
if (!bypassRandom && m_brushobjects.is_open && m_brushobjects.useRandom && m_brushobjects.Objects.size() > 0)
{
return m_brushobjects.GetRandomObject();
}
return m_nodebankpanel.get_active_template(); return m_nodebankpanel.get_active_template();
} }
@@ -64,7 +79,7 @@ nodebank_panel::edit_mode editor_ui::mode()
} }
float editor_ui::getSpacing() float editor_ui::getSpacing()
{ {
return m_nodebankpanel.spacing; return m_brushobjects.spacing;
} }
functions_panel::rotation_mode editor_ui::rot_mode() functions_panel::rotation_mode editor_ui::rot_mode()

View File

@@ -33,14 +33,16 @@ class editor_ui : public ui_layer
float rot_val(); float rot_val();
bool rot_from_last(); bool rot_from_last();
functions_panel::rotation_mode rot_mode(); functions_panel::rotation_mode rot_mode();
const std::string *get_active_node_template(); const std::string *get_active_node_template(bool bypassRandom = false);
nodebank_panel::edit_mode mode(); nodebank_panel::edit_mode mode();
float getSpacing(); float getSpacing();
void toggleBrushSettings(bool isVisible);
private: private:
// members // members
itemproperties_panel m_itempropertiespanel{"Node Properties", true}; itemproperties_panel m_itempropertiespanel{"Node Properties", true};
functions_panel m_functionspanel{"Functions", true}; functions_panel m_functionspanel{"Functions", true};
nodebank_panel m_nodebankpanel{"Node Bank", true}; nodebank_panel m_nodebankpanel{"Node Bank", true};
brush_object_list m_brushobjects{"Brush properties", false};
scene::basic_node *m_node{nullptr}; // currently bound scene node, if any scene::basic_node *m_node{nullptr}; // currently bound scene node, if any
}; };

View File

@@ -322,6 +322,75 @@ bool itemproperties_panel::render_group()
return true; return true;
} }
brush_object_list::brush_object_list(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen)
{
size_min = {50, 100};
size_max = {1000, 500};
}
bool brush_object_list::VectorGetter(void *data, int idx, const char **out_text)
{
auto *vec = static_cast<std::vector<std::string> *>(data);
if (idx < 0 || idx >= vec->size())
return false;
*out_text = (*vec)[idx].c_str();
return true;
}
void brush_object_list::update(std::string nodeTemplate)
{
Template = nodeTemplate;
}
std::string *brush_object_list::GetRandomObject()
{
static std::string empty; // fallback
if (Objects.empty())
return &empty;
static std::mt19937 rng{std::random_device{}()};
std::uniform_int_distribution<size_t> dist(0, Objects.size() - 1);
return &Objects[dist(rng)];
}
void brush_object_list::render()
{
if (false == is_open)
{
return;
}
auto flags = ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoCollapse | (size.x > 0 ? ImGuiWindowFlags_NoResize : 0);
if (ImGui::Begin("Brush random set", nullptr, flags))
{
ImGui::SliderFloat("Spacing", &spacing, 0.1f, 20.0f, "%.1f m");
ImGui::Checkbox("Enable brush random from set", &useRandom);
if (useRandom)
{
ImGui::Text("Set of objects to choose from:");
ImGui::ListBox("", &idx, VectorGetter, (void *)&Objects, Objects.size(), 6);
if (ImGui::Button("Add"))
{
if (!Template.empty())
Objects.push_back(Template);
}
ImGui::SameLine();
if (ImGui::Button("Remove") && idx >= 0 && idx < Objects.size())
{
Objects.erase(Objects.begin() + idx);
}
if (ImGui::Button("Remove all") && idx >= 0 && idx < Objects.size())
{
Objects.clear();
}
}
ImGui::End();
}
}
nodebank_panel::nodebank_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen) nodebank_panel::nodebank_panel(std::string const &Name, bool const Isopen) : ui_panel(Name, Isopen)
{ {
size_min = {100, 50}; size_min = {100, 50};
@@ -386,7 +455,6 @@ void nodebank_panel::nodebank_reload()
void nodebank_panel::render() void nodebank_panel::render()
{ {
if (false == is_open) if (false == is_open)
{ {
return; return;
@@ -422,7 +490,7 @@ void nodebank_panel::render()
if (mode == BRUSH) if (mode == BRUSH)
{ {
ImGui::SliderFloat("Spacing", &spacing, 0.1f, 20.0f, "%.1f m"); // ImGui::SliderFloat("Spacing", &spacing, 0.1f, 20.0f, "%.1f m");
} }
ImGui::PushItemWidth(-1); ImGui::PushItemWidth(-1);

View File

@@ -47,6 +47,25 @@ class itemproperties_panel : public ui_panel
std::vector<text_line> m_grouplines; std::vector<text_line> m_grouplines;
}; };
class brush_object_list : public ui_panel
{
private:
int idx;
static bool VectorGetter(void *data, int idx, const char **out_text);
std::string Template;
public:
brush_object_list(std::string const &Name, bool const Isopen);
void render() override;
void update(std::string nodeTemplate);
// class use
std::vector<std::string> Objects;
std::string *GetRandomObject();
bool useRandom = {false};
float spacing{1.0f};
};
class nodebank_panel : public ui_panel class nodebank_panel : public ui_panel
{ {
@@ -60,8 +79,6 @@ class nodebank_panel : public ui_panel
}; };
edit_mode mode = MODIFY; edit_mode mode = MODIFY;
float spacing{1.0f};
nodebank_panel(std::string const &Name, bool const Isopen); nodebank_panel(std::string const &Name, bool const Isopen);
void nodebank_reload(); void nodebank_reload();
void render() override; void render() override;