载入中...
搜索中...
未找到
OceanHullMask.cpp
浏览该文件的文档.
2
3#include <cmath>
4
5namespace eve::fluids {
6namespace {
7bool finite(glm::dvec3 p) { return std::isfinite(p.x) && std::isfinite(p.y) && std::isfinite(p.z); }
10 DiagnosticCode::InvalidArgument, "Invalid ocean hull volume or render origin", "fluids.ocean.hull"));
11}
12} // namespace
14 if (volumes_.size() > 32 || !finite(origin) || glm::any(glm::greaterThan(glm::abs(origin), glm::dvec3(1e9))))
15 return invalid();
17 out.origin_ = origin;
18 out.rows_.reserve(volumes_.size() * 17);
19 for (const auto& volume : volumes_) {
20 const auto relative = volume.center - origin;
21 const double qLength = glm::length(volume.rotation);
22 if (!finite(volume.center) || !finite(relative) ||
23 glm::any(glm::greaterThan(glm::abs(relative), glm::dvec3(1e6))) || !finite(volume.halfExtent) ||
24 glm::any(glm::lessThanEqual(volume.halfExtent, glm::dvec3(0.0))) ||
25 glm::any(glm::greaterThan(volume.halfExtent, glm::dvec3(10000.0))) || !std::isfinite(qLength) ||
26 std::abs(qLength - 1.0) > 1e-6 || volume.bevels.size() > 10)
27 return invalid();
28 const auto rotation = glm::normalize(volume.rotation);
29 const auto first = out.rows_.size();
30 out.rows_.resize(first + 17, glm::vec4(0));
31 out.rows_[first].x = static_cast<float>(6 + volume.bevels.size());
32 auto append = [&](unsigned index, glm::dvec3 normal, double offset) {
33 const auto worldNormal = rotation * normal;
34 out.rows_[first + 1 + index] = glm::vec4(worldNormal, offset + glm::dot(worldNormal, relative));
35 };
36 for (unsigned axis = 0; axis < 3; ++axis) {
37 glm::dvec3 normal(0);
38 normal[axis] = 1;
39 append(axis * 2, normal, volume.halfExtent[axis]);
40 append(axis * 2 + 1, -normal, volume.halfExtent[axis]);
41 }
42 for (unsigned i = 0; i < volume.bevels.size(); ++i) {
43 const auto plane = volume.bevels[i];
44 const double length = glm::length(glm::dvec3(plane));
45 if (!finite(glm::dvec3(plane)) || !std::isfinite(plane.w) || length < 1e-12 || !std::isfinite(length) ||
46 std::abs(plane.w / length) > 10000.0)
47 return invalid();
48 append(i + 6, glm::dvec3(plane) / length, plane.w / length);
49 }
50 }
52}
54 if (!finite(worldPoint)) return false;
55 const auto relative = worldPoint - origin_;
56 if (!finite(relative) || glm::any(glm::greaterThan(glm::abs(relative), glm::dvec3(2e6)))) return false;
57 const glm::vec3 point(relative);
58 for (std::size_t first = 0; first < rows_.size(); first += 17) {
59 bool inside = true;
60 const auto count = static_cast<unsigned>(rows_[first].x);
61 for (unsigned i = 0; i < count; ++i) {
62 const auto plane = rows_[first + 1 + i];
63 if (glm::dot(glm::vec3(plane), point) > plane.w) {
64 inside = false;
65 break;
66 }
67 }
68 if (inside) return true;
69 }
70 return false;
71}
72} // namespace eve::fluids
Vec3 relative
Definition AnimSmr.cpp:164
double volume
glm::vec4 p[6]
std::int32_t first
float length
JointPoint2D axis
size_t offset
std::array< float, 4 > rotation
Texture * normal
bool finite
ScriptStructure out
int count
uint32_t index
std::vector< char > inside
glm::vec3 point
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< OceanHullMaskFrame > build() const
Validate the entire batch then return its owning render projection.
Immutable owning render-only union of convex dry volumes. No body handles, callbacks,...
EVENGINE_API_DOMAINS bool contains(glm::dvec3 worldPoint) const
Reference fragment classification; nonfinite points are outside, boundary is inside....
Status invalid(const char *message)
GLSL compute kernels for the GPU surface-flow solver.
Definition FluidTarget.h:12