载入中...
搜索中...
未找到
OceanMeshFrame.cpp
浏览该文件的文档.
1#include "fluids/OceanMesh.h"
3
4#include <cmath>
5
6namespace eve::fluids {
8 auto valid = [](double value) { return std::isfinite(value) && std::abs(value) <= 1e9; };
9 if (!valid(center.x) || !valid(center.y) || !valid(origin.x) || !valid(origin.y) || !valid(origin.z) ||
10 mesh_.parameterOffsets.empty() || mesh_.parameterOffsets.size() > 524289)
12 DiagnosticCode::InvalidArgument, "Invalid ocean mesh frame coordinates or size", "fluids.ocean.mesh"));
15 frame.time = water_.time();
16 frame.positions.reserve(mesh_.parameterOffsets.size() * 3);
17 frame.normals.reserve(mesh_.parameterOffsets.size() * 3);
18 frame.surface.reserve(mesh_.parameterOffsets.size() * 2);
19 for (const auto offset : mesh_.parameterOffsets) {
20 auto surface = water_.geometry(center + offset);
21 if (!surface) return Result<OceanMeshFrame>::failure(surface.status());
22 const auto local = surface.value().position - origin;
23 const auto normal = surface.value().normal();
24 const auto& geometry = surface.value();
25 frame.surface.push_back(static_cast<float>(geometry.foam));
26 frame.surface.push_back(
27 static_cast<float>(geometry.tangentX.x * geometry.tangentZ.z - geometry.tangentZ.x * geometry.tangentX.z));
28 if (!std::isfinite(normal.x) || !std::isfinite(normal.y) || !std::isfinite(normal.z))
30 DiagnosticCode::Unsupported, "Degenerate ocean surface tangent", "fluids.ocean.mesh"));
31 for (unsigned axis = 0; axis < 3; ++axis) {
32 frame.positions.push_back(static_cast<float>(local[axis]));
33 frame.normals.push_back(static_cast<float>(normal[axis]));
34 }
35 }
36 return Result<OceanMeshFrame>::success(std::move(frame));
37}
38} // namespace eve::fluids
JointPoint2D axis
std::string local
size_t offset
bool valid
Texture * normal
ssq::Object frame
Object::Ptr value
std::string geometry
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
glm::dvec2 center
Double-precision world XZ center; continuous camera movement does not change wave phase.
Definition OceanMesh.h:69
EVENGINE_API_DOMAINS Result< OceanMeshFrame > build() const
Build an atomic owning vertex projection; invalid queries or degenerate tangents reject the whole fra...
glm::dvec3 origin
Render origin subtracted before float conversion; use the same origin for camera and scene.
Definition OceanMesh.h:71
double time() const
Shared injected simulation timestamp.
EVENGINE_API_DOMAINS Result< OceanSurfaceGeometry > geometry(glm::dvec2 parameterXZ) const
Evaluate combined position and tangents directly; wake gradients follow displaced world XZ.
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12
std::vector< glm::dvec2 > parameterOffsets
Definition OceanMesh.h:30
Owning CPU reference projection, ready for a mesh upload; simulation time and origin identify the fra...
Definition OceanMesh.h:49