18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-03 11:15:23 +01:00
Files
maszyna/editor/editorScatter.hpp
miloszunio a87a94d36d fix(editor): the brush after the review of 30.11: a second uniform stroke doubles nothing, the step of a stroke by its serial
- the uniform fill is told of the models which stand near the dab already (scatter::dab(), Standing) and leaves the points of
  its grid alone where one stands: a second stroke over the same ground adds nothing, as the description says. After a Ctrl+Z
  of the first the ground is filled again
- the step of the history of a stroke is made with its first model and looked up by its serial for each model
  (editor_mode::brush_step()): a step pushed while the button is held (Del) no longer takes the later models of the stroke,
  and a press which puts nothing (on the sky, no model chosen) leaves the steps to redo as they were
- the settings of the brush are bounded before they are used (scatter: sane()): a number typed into a field which isn't
  finite gives no place nor transform which isn't, and the fields clamp what is typed (ImGuiSliderFlags_AlwaysClamp).
  Within the ranges of the panel nothing changes
- tests: the second stroke, the settings which aren't numbers, the ranges of the panel
- redo_last() ends the stroke after the step of the terrain, and tests/unit/CMakeLists.txt lists editorScatter.cpp apart from
  the lines #311, #430 and #431 add, so the four merge without a conflict
2026-11-30 22:16:26 +00:00

132 lines
5.6 KiB
C++

#pragma once
// where the brush of models puts them, and how it turns and scales each: engine-free, so it can be tested on its own
#include <random>
#include <unordered_map>
#include <vector>
#include <glm/glm.hpp>
namespace scatter
{
// how the models fill the circle of the brush
enum class fill
{
random, // anywhere in the circle, no closer to each other than the spacing
// on a grid of triangles as wide as the spacing, fixed to the world: strokes over one another come to the same points, and a
// point where a model stands already (the Standing ones given to dab()) gets no second one
uniform,
feathered, // anywhere, fewer and fewer towards the edge of the circle
};
struct dab_settings
{
double radius{5.0}; // m
fill mode{fill::random};
double spacing{2.0}; // m: the least distance between two models; the step of the grid of the uniform fill
// models a 100 m² of the ground the stroke goes over, as much as the spacing lets: for the random fill everywhere under the
// circle, for the feathered one in the middle of the stroke, fewer and fewer towards its edge
double density{4.0};
};
// the circle a dab of the stroke has filled already
struct dab_circle
{
glm::dvec2 centre;
double radius;
};
// what a stroke of the brush has done so far. the circles of its dabs overlap, and the cursor may come back over them: the
// ground a dab has filled gets no more from the next ones, so it holds as many models as the density says, not that many
// from each dab that went over it
struct stroke
{
std::vector<glm::dvec2> taken; // the places of the models put (x, z)
std::vector<dab_circle> dabs; // the circles filled
};
// the most models one dab puts, whatever the fill: a dab wider or denser than that is cut short
int constexpr dab_most{2000};
// the places of the models of one dab of the brush round Centre (x, z): inside the circle, Spacing from each other and from those
// the Stroke put so far at least, on the ground the stroke hasn't filled yet. the dab is added to the Stroke: its circle, and its
// places, whether a model ends up standing there or not.
// Standing: the places (x, z) of the models which stand near the circle already, whoever put them. the uniform fill leaves the
// points of its grid alone where one of them stands within half the spacing, so a second stroke over the same ground adds
// nothing to the first; the other fills don't look at them.
// settings which aren't finite numbers are taken for the least ones, far too large ones are cut (see sane() in the .cpp)
std::vector<glm::dvec2> dab(glm::dvec2 const &Centre, dab_settings const &Settings, stroke &Stroke, std::mt19937 &Random, std::vector<glm::dvec2> const &Standing = {}); // NOSONAR(cpp:S2245) placement of scenery models, not security
// how many models the density asks for in the whole circle of a dab of the random or the feathered fill; more than dab_most
// of them and the dab is cut short
double dab_wanted(dab_settings const &Settings);
// the distance the cursor goes before the next dab: the circles of two dabs overlap by half
double dab_step(dab_settings const &Settings);
// how the models stand along a line drawn on the ground
enum class line_fill
{
regular, // in rows along the line, Spacing apart along it and across it, every other row shifted by half
irregular, // anywhere in the band, no closer to each other than the spacing
};
struct line_settings
{
double width{0.0}; // m each side of the line: 0 is one row on the line itself
line_fill mode{line_fill::regular};
double spacing{4.0}; // m: the step along the line and between the rows; the least distance for the irregular fill
double jitter{0.0}; // the regular fill moved off its places by up to this share of the spacing each way, 0 to 0.5
double density{4.0}; // models a 100 m² of the band for the irregular fill (on a line of no width: per spacing of it)
bool thin_out{false}; // the irregular fill fewer and fewer towards the edges of the band
double edge_scale{100.0}; // percent of their size the models at the edges of the band get, down from the full size on the line
};
// a place along the line: where (x, z), the height of the line there, and how far out in the band it is (0 on the line, 1 at the edge)
struct line_place
{
glm::dvec2 point;
double height;
double side;
};
// the most models one line puts
int constexpr line_most{20000};
// the places of the models along the line through Points (x, height, z), two points at least
std::vector<line_place> along(std::vector<glm::dvec3> const &Points, line_settings const &Settings, std::mt19937 &Random); // NOSONAR(cpp:S2245) placement of scenery models, not security
// the share of its size a model gets at the place Side of the band (0 on the line, 1 at the edge)
float side_scale(line_settings const &Settings, double Side);
// a setting the same for every model, or drawn for each from a range
enum class vary
{
fixed,
random,
};
struct look_settings
{
vary turn{vary::random};
glm::vec3 angles{0.0f}; // degrees about x, y, z, for the fixed turn
glm::vec3 angle_range{0.0f, 180.0f, 0.0f}; // degrees each way about x, y, z, for the random turn
vary size{vary::fixed};
glm::vec3 scale{100.0f}; // percent along x, y, z, for the fixed scale
glm::vec3 scale_range{0.0f}; // percent each way along x, y, z, for the random scale
bool same_scale{true}; // the random scale one for all the axes (the x range), the model keeps its shape
};
struct look
{
glm::vec3 angles{0.0f}; // degrees about x, y, z
glm::vec3 scale{1.0f}; // factors along x, y, z, never under 1%
};
// the turn and the scale of one model
look pick(look_settings const &Settings, std::mt19937 &Random); // NOSONAR(cpp:S2245) placement of scenery models, not security
} // namespace scatter