12constexpr float kPi = 3.14159265358979323846f;
23constexpr LayerSpec kDefaultLayers[] = {
24 {1.00f, 0.10f, 0.045f, 0.15f},
25 {0.72f, 0.14f, 0.38f, 0.55f},
26 {0.48f, 0.20f, 0.68f, 0.70f},
27 {0.28f, 0.28f, 1.00f, 0.85f},
30float clampf(
float v,
float lo,
float hi) {
return std::max(lo, std::min(hi,
v)); }
32float easeOutCubic(
float t) {
33 const float u = 1.f -
t;
34 return 1.f -
u *
u *
u;
37float radiusAt(
const LayerSpec &spec,
float halfW,
float t) {
38 const float blend = (1.f - spec.flareBias) *
t + spec.flareBias * easeOutCubic(
t);
39 return halfW * (spec.baseRadius + (spec.topRadius - spec.baseRadius) *
blend);
42void addFlaredSheet(MeshBuild &
out,
const LayerSpec &spec,
float height,
float halfW,
int radialSegments,
44 const int sides = radialSegments;
45 const int rings = heightSegments;
46 const float layerH =
height * spec.heightScale;
47 if (layerH < 1e-4f ||
halfW < 1e-4f)
return;
49 const uint32_t base = uint32_t(
out.getVertexCount());
50 for (
int y = 0;
y <= rings; ++
y) {
51 const float v = float(
y) / float(rings);
53 const float u = float(
x) / float(
sides);
54 const float angle =
u * 2.f * kPi;
57 const float lip = easeOutCubic(
clampf((
v - 0.72f) / 0.28f, 0.f, 1.f));
58 const float curl = lip *
halfW * 0.035f;
60 const float py = layerH *
v;
63 const float dr = (spec.topRadius - spec.baseRadius) *
halfW;
65 float ny = -dr / std::max(layerH, 1e-3f);
67 const float nlen = std::sqrt(
nx *
nx +
ny *
ny +
nz *
nz);
77 for (
int y = 0;
y < rings; ++
y) {
80 const uint32_t
a = base + uint32_t(
y *
sides +
x);
81 const uint32_t
b = base + uint32_t(
y *
sides +
nx);
82 const uint32_t
c = base + uint32_t((
y + 1) *
sides +
x);
83 const uint32_t
d = base + uint32_t((
y + 1) *
sides +
nx);
96 const float height = std::max(0.2f,
params.getFloat(
"height", 2.4f));
97 const float width = std::max(0.3f,
params.getFloat(
"width", 3.2f));
99 const int layers = std::clamp(
params.getInt(
"layers", 4), 2, 4);
102 const int onlyLayer =
params.getInt(
"onlyLayer", -1);
103 const int sides = std::clamp(
params.getInt(
"radialSegments", 32), 8, 64);
104 const int rings = std::clamp(
params.getInt(
"heightSegments", 12), 3, 32);
105 const float flare = clampf(
params.getFloat(
"flare", 1.0f), 0.35f, 1.75f);
107 if (onlyLayer >= layers) {
108 error =
"mesh.water_splash: onlyLayer must be < layers";
114 out.setActiveGroup(
"splash");
116 for (
int i = 0; i < layers; ++i) {
117 if (onlyLayer >= 0 && i != onlyLayer)
continue;
118 LayerSpec spec = kDefaultLayers[i];
120 spec.topRadius *= flare;
121 spec.flareBias = clampf(spec.flareBias * (0.65f + 0.35f * flare), 0.f, 1.f);
123 const std::string
group = i == 0 ?
"spire" : (
"crown" + std::to_string(i));
128 out.setMeta(
"recipe",
"mesh.water_splash");
129 out.setMeta(
"seed", std::to_string(
seed));
130 out.setMeta(
"layers", std::to_string(layers));
131 out.setMeta(
"sheet",
"clay");
133 error =
"mesh.water_splash: generated an empty mesh";
AbilityActivationGroup group
CPU triangle mesh from procedural mesh recipes (e.g. marching cubes). Positions/normals are xyz-packe...
Owning, typed generation parameters.
constexpr float clampf(float v, float lo, float hi) noexcept
Clampf.
bool generateWaterSplashMesh(const Params ¶ms, MeshBuild &out, std::string &error)
Build deterministic clay-sheet crowns for a stylized water splash.