载入中...
搜索中...
未找到
OceanMesh.cpp
浏览该文件的文档.
1#include "fluids/OceanMesh.h"
2
3#include <cmath>
4
5namespace eve::fluids {
7 const auto& s = settings;
8 if (s.segments < 16 || s.segments > 1024 || s.segments % 8 != 0 || s.rings < 2 || s.rings > 512 ||
9 !std::isfinite(s.firstRadius) || !std::isfinite(s.outerRadius) || s.firstRadius < 0.01 ||
10 s.outerRadius < s.firstRadius * s.rings || s.outerRadius > 1e6)
12 DiagnosticCode::InvalidArgument, "Invalid ocean mesh extent or tessellation", "fluids.ocean.mesh"));
13
14 // Geometric widths rather than geometric radii preserve a dense central patch.
15 auto extent = [&](double growth) {
16 double width = s.firstRadius, total = 0.0;
17 for (unsigned ring = 0; ring < s.rings; ++ring) {
18 total += width;
19 width *= growth;
20 }
21 return total;
22 };
23 double lo = 1.0, hi = 1.0 + s.outerRadius / s.firstRadius;
24 for (unsigned iteration = 0; iteration < 100; ++iteration) {
25 const double mid = (lo + hi) * 0.5;
26 if (extent(mid) < s.outerRadius)
27 lo = mid;
28 else
29 hi = mid;
30 }
31 const double growth = (lo + hi) * 0.5;
33 result.parameterOffsets.reserve(1 + s.segments * s.rings);
34 result.indices.reserve(3 * s.segments * (2 * s.rings - 1));
35 result.radii.reserve(s.rings);
36 result.parameterOffsets.emplace_back(0.0);
37 double radius = 0.0, width = s.firstRadius;
38 for (unsigned ring = 0; ring < s.rings; ++ring) {
39 radius += width;
40 width *= growth;
41 if (ring + 1 == s.rings) radius = s.outerRadius;
42 result.radii.push_back(radius);
43 // Equal spacing along each square side includes all four corners exactly.
44 for (unsigned segment = 0; segment < s.segments; ++segment) {
45 const unsigned side = segment / (s.segments / 4);
46 const double t = 2.0 * (segment % (s.segments / 4)) / (s.segments / 4) - 1.0;
47 glm::dvec2 direction;
48 switch (side) {
49 case 0: direction = {1.0, t}; break;
50 case 1: direction = {-t, 1.0}; break;
51 case 2: direction = {-1.0, -t}; break;
52 default: direction = {t, -1.0}; break;
53 }
54 result.parameterOffsets.push_back(direction * radius);
55 const auto outer = 1 + ring * s.segments + segment;
56 const auto next = 1 + ring * s.segments + (segment + 1) % s.segments;
57 if (ring == 0)
58 result.indices.insert(result.indices.end(), {0, next, outer});
59 else {
60 const auto inner = outer - s.segments;
61 const auto innerNext = next - s.segments;
62 result.indices.insert(result.indices.end(), {inner, next, outer, inner, innerNext, next});
63 }
64 }
65 }
66 return Result<OceanMeshData>::success(std::move(result));
67}
68} // namespace eve::fluids
int mid
Definition AnimSmr.cpp:120
const std::string & s
std::uint32_t width
Poco::JSON::Object::Ptr result
double radius
Definition MeleeHit.cpp:42
float t
RoadLaneDirection direction
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
Move-only operation result carrying either a value or Status.
Definition Result.h:176
static Result success(T value)
Construct a successful result owning value.
Definition Result.h:185
static Result failure(Status status)
Construct a failed result from a structured status.
Definition Result.h:196
EVENGINE_API_DOMAINS Result< OceanMeshData > build() const
Build positively oriented triangles on XZ, graded geometrically from near water to horizon.
Definition OceanMesh.cpp:6
OceanMeshSettings settings
Definition OceanMesh.h:38
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12
Owning immutable topology projection; XZ offsets are relative to the render origin....
Definition OceanMesh.h:29
std::vector< glm::dvec2 > parameterOffsets
Definition OceanMesh.h:30