18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-04 23:45:17 +01:00

feat(editor): the brush of models as one model or many in a circle

The brush of the node bank put one model under the cursor every time it went the spacing further, with no idea of an area. It's two ways now:

- Single model: LMB puts one model at the cross on the ground.
- Many models: while LMB is held, models land in a circle of the radius chosen along the cursor's path, a new dab every half radius (or spacing). The circle fills at random (a density a 100 m², no closer than the spacing), uniformly (a grid of triangles as wide as the spacing, fixed to the world, so strokes over one another don't double it) or feathered (fewer towards the edge). A whole stroke is one step of the history.

Every model is turned (fixed angles about x, y, z, or random up to ± degrees about each) and scaled (fixed percent along x, y, z, or random ± percent, one for all the axes or each its own). A cross under the cursor and the circle of the brush are drawn on the ground.

Where the models go and how they're turned and scaled is in editor/editorScatter (engine-free), with tests in tests/unit/test_scatter.cpp.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DDcMn1Q7wdYkbxDUWscNHZ
This commit is contained in:
Claude
2026-11-14 22:07:19 +01:00
parent 0371581049
commit afc43b5832
13 changed files with 733 additions and 54 deletions
+16 -45
View File
@@ -795,51 +795,6 @@ void editor_mode::snap_to_ground(scene::basic_node *node, bool const Alone, bool
m_editor.translate(node, target, true); // true == apply the computed Y (free vertical move)
}
void editor_mode::handle_brush_mouse_hold(int Action, int Button)
{
auto const mode = ui()->mode();
auto const rotation_mode = ui()->rot_mode();
auto const fixed_rotation_value = ui()->rot_val();
if(mode != nodebank_panel::BRUSH)
return;
GfxRenderer->Pick_Node_Callback(
[this, mode, rotation_mode, fixed_rotation_value, Action, Button](scene::basic_node * /*node*/) {
// picks are resolved a few frames later; drop the ones queued before the button went up,
// or for a press that turned out to belong to the UI
if (!mouseHold || !viewport_click())
return;
// spacing is measured in world space: the mouse offset is camera-relative and the camera may move mid-stroke
glm::dvec3 const newPos = Camera.Pos + clamp_mouse_offset_to_max(GfxRenderer->Mouse_Position());
if (m_brush_has_last && glm::distance(newPos, oldPos) < ui()->getSpacing())
return;
// picked only when a placement is due, so a random pick from a set isn't drawn every tick
const std::string *src = ui()->get_active_node_template();
if (!src || src->starts_with(editor_includes::directive_mark)) // scenery templates are placed one at a time
return;
// NOTE: no name for what the brush puts in, as with thousands of nodes the names take their share of the time
// the scenery needs to load. a node which needs one, to be referred to by an event, gets it in the node properties
TAnimModel *cloned = simulation::State.create_model(*src, std::string{}, placement_on_ground(newPos));
oldPos = newPos;
m_brush_has_last = true;
if (!cloned)
return;
apply_rotation_for_new_node(cloned, rotation_mode, fixed_rotation_value);
std::string as_text;
cloned->export_as_text(as_text);
push_snapshot(cloned, EditorSnapshot::Action::Add, as_text);
m_node = cloned;
ui()->set_node(m_node);
});
}
void editor_mode::add_to_hierarchy(scene::basic_node *node)
{
if (!node) return;
@@ -1489,6 +1444,11 @@ bool editor_mode::update()
if(ui()->mode() == nodebank_panel::BRUSH)
handle_brush_mouse_hold(GLFW_REPEAT, GLFW_MOUSE_BUTTON_LEFT);
}
else
{
// the button let go: the stroke's models make one step of the history
end_brush_stroke();
}
// decelerate camera velocity with thresholding
Camera.Velocity *= 0.65f;
@@ -1703,6 +1663,9 @@ bool editor_mode::update()
// --- area fill: outline overlay while the mode is active (its settings are drawn in the node bank window) ---
if (ui()->mode() == nodebank_panel::FILL)
draw_area_fill_outline();
// --- the brush of models: the cross on the ground under the cursor, the circle of the brush of many ---
if (ui()->mode() == nodebank_panel::BRUSH && false == ImGui::GetIO().WantCaptureMouse)
draw_brush_cursor();
background->PopClipRect();
draw_ortho_compass();
@@ -7677,6 +7640,14 @@ void editor_mode::on_mouse_button(int const Button, int const Action, int const
mouseHold = true;
m_brush_has_last = false; // every brush stroke starts with a placement
// the brush puts models, it doesn't select
if (mode == nodebank_panel::BRUSH)
{
brush_press();
m_input.mouse.button(Button, Action);
return;
}
// in area fill mode the left button only adds outline points, it doesn't touch the selection
if (mode == nodebank_panel::FILL)
{