载入中...
搜索中...
未找到
MacFluidGrid.h
浏览该文件的文档.
1#pragma once
2#include "common/Export.h"
3
4#include "common/Result.h"
8
9#include <cstddef>
10#include <cstdint>
11#include <vector>
12
13#include <glm/vec3.hpp>
14
15namespace eve::graphics::fog {
16
17class FogInteractor;
18
27public:
28 static constexpr float kDefaultFixedDt = 1.f / 60.f;
29 static constexpr float kMaxAccumulated = 0.25f;
30
32 [[nodiscard]] Result<void> configure(const FogDensityField& field, float fixedDt = kDefaultFixedDt);
33
34 [[nodiscard]] int width() const noexcept { return width_; }
35 [[nodiscard]] int height() const noexcept { return height_; }
36 [[nodiscard]] int depth() const noexcept { return depth_; }
37 [[nodiscard]] const FogWorldBounds& bounds() const noexcept { return bounds_; }
38 [[nodiscard]] glm::vec3 cellSize() const noexcept { return cellSize_; }
39 [[nodiscard]] float fixedDt() const noexcept { return fixedDt_; }
40 [[nodiscard]] float accumulatedTime() const noexcept { return accumulator_; }
41 [[nodiscard]] std::uint64_t stepCount() const noexcept { return stepCount_; }
42
44 [[nodiscard]] Result<void> pullDensity(const FogDensityField& field);
46 [[nodiscard]] Result<void> pushDensity(FogDensityField& field) const;
47
49 [[nodiscard]] float densityAt(int x, int y, int z) const noexcept;
50 void setDensity(int x, int y, int z, float density);
51
53 [[nodiscard]] float uAt(int i, int y, int z) const noexcept;
54 [[nodiscard]] float vAt(int x, int j, int z) const noexcept;
55 [[nodiscard]] float wAt(int x, int y, int k) const noexcept;
56
58 [[nodiscard]] glm::vec3 velocityAtCell(int x, int y, int z) const noexcept;
59
66 [[nodiscard]] Result<FogCflReport> step(float dt, SceneWind& wind, FogInteractor* interactor,
67 float simTime);
68
70 [[nodiscard]] FogCflReport diagnoseCfl() const noexcept;
71
72private:
73 friend class FogInteractor;
74
75 [[nodiscard]] std::size_t cellIndex(int x, int y, int z) const noexcept;
76 [[nodiscard]] std::size_t uIndex(int i, int y, int z) const noexcept;
77 [[nodiscard]] std::size_t vIndex(int x, int j, int z) const noexcept;
78 [[nodiscard]] std::size_t wIndex(int x, int y, int k) const noexcept;
79
80 void applyForcesAndWind(const SceneWind& wind, float dt, float simTime);
81 void advectVelocity(float dt);
82 void projectPressure();
83 void advectDensity(float dt, const FogInteractor* interactor);
84 [[nodiscard]] glm::vec3 sampleVelocity(const glm::vec3& localCell) const noexcept;
85 [[nodiscard]] float sampleDensityLocal(const glm::vec3& localCell) const noexcept;
86 [[nodiscard]] glm::vec3 traceBounded(const glm::vec3& start, const glm::vec3& delta,
87 const FogInteractor* interactor) const noexcept;
88
89 int width_ = 0;
90 int height_ = 0;
91 int depth_ = 0;
92 FogWorldBounds bounds_{};
93 glm::vec3 cellSize_{1.f};
94 float fixedDt_ = kDefaultFixedDt;
95 float accumulator_ = 0.f;
96 std::uint64_t stepCount_ = 0;
97
98 std::vector<float> u_;
99 std::vector<float> v_;
100 std::vector<float> w_;
101 std::vector<float> density_;
102 std::vector<float> pressure_;
103 std::vector<float> divergence_;
104 std::vector<float> tmpDensity_;
105 std::vector<float> tmpU_;
106 std::vector<float> tmpV_;
107 std::vector<float> tmpW_;
108 std::vector<std::uint8_t> solid_;
109};
110
111} // namespace eve::graphics::fog
Duration start
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
float z
Definition AnimClip.cpp:738
#define EVENGINE_API_WORLD
Definition Export.h:109
Move-only, checked operation results for the common layer.
float step
Definition TreeMesh.cpp:314
Move-only operation result carrying either a value or Status.
Definition Result.h:155
World-space density bands, curl assist velocity, and lighting helpers.
Analytic solid proxies that carve fog and inject wake into the MAC field.
MAC (Marker-And-Cell) staggered-grid Eulerian fog fluid.
const FogWorldBounds & bounds() const noexcept
glm::vec3 cellSize() const noexcept
int height() const noexcept
float accumulatedTime() const noexcept
float fixedDt() const noexcept
std::uint64_t stepCount() const noexcept
World-space wind provider for MAC fog transport.
Definition SceneWind.h:18
CFL stability snapshot for the MAC fluid solver.
Definition FogTypes.h:130
Axis-aligned world bounds for a fog simulation domain.
Definition FogTypes.h:96