载入中...
搜索中...
未找到
eve::fluids::ShallowWaterField类 参考

GPU-first shallow-water (2D Saint-Venant) free-surface solver. 更多...

#include <ShallowWaterField.h>

Public 成员函数

 ~ShallowWaterField ()
 
 ShallowWaterField (const ShallowWaterField &)=delete
 
ShallowWaterField & operator= (const ShallowWaterField &)=delete
 
Result< void > step (float dt)
 Advance the free surface by dt seconds (CFL substeps).
 
Result< void > setColliders (std::span< const ShallowWaterCollider > colliders)
 Replace analytic interactors atomically.
 
Result< void > setBed (std::span< const float > beds)
 Replace bed heights; call fillSurface afterwards to initialize a level lake.
 
Result< void > fillDepth (float depth)
 Fill every cell with a uniform water depth (momentum cleared).
 
Result< void > fillSurface (float surfaceY)
 Fill to a world-space free-surface elevation, leaving high terrain dry.
 
Result< void > disturbAt (float worldX, float worldZ, float radius, float heightDelta, float radialSpeed=0.f)
 Inject a localized height bump and radial outflow (mouse / splash).
 
Result< void > addImpulse (float worldX, float worldZ, float radius, float strength)
 Convenience splash: positive strength raises water, negative digs.
 
int resolutionX () const noexcept
 
int resolutionZ () const noexcept
 
float cellSize () const noexcept
 
int cellCount () const noexcept
 
glm::vec3 origin () const noexcept
 
bool usingGpu () const noexcept
 
bool usedBackendFallback () const noexcept
 
std::span< const float > depths () const noexcept
 
std::span< const float > beds () const noexcept
 
std::span< const float > momentumX () const noexcept
 
std::span< const float > momentumZ () const noexcept
 
std::span< const ShallowWaterCollider > colliders () const noexcept
 
float surfaceHeightAt (float worldX, float worldZ) const noexcept
 Bilinear free-surface height b + h at a world XZ point.
 
float depthAt (float worldX, float worldZ) const noexcept
 Bilinear water depth at a world XZ point.
 
glm::vec2 velocityAt (float worldX, float worldZ) const noexcept
 Bilinear horizontal velocity at a world XZ point.
 
Result< void > buildSurfaceMesh (std::vector< float > &positionsXYZ, std::vector< float > &normalsXYZ, std::vector< float > &uvsST, std::vector< uint32_t > &indices, float visualHeightGain=1.f, std::vector< float > *colorsRGBA=nullptr) const
 Build a Y-up triangle mesh of the free surface for Graphics upload.
 
Result< void > copyFieldToImage (image::ImageData &image, float velocityScale=2.f, float depthContrast=0.f) const
 Pack per-cell depth / velocity into an RGBA8 image (resolutionX × resolutionZ).
 
Result< void > copyShadedAlbedoToImage (image::ImageData &image, float restDepth, float velocityScale=2.f) const
 Write a shaded water albedo (RGBA8, same size as the grid) for Material upload.
 
Result< void > copyNormalToImage (image::ImageData &image, float normalStrength=6.f) const
 Write tangent-space normals from free-surface slopes (RGBA8, same grid size).
 
ShallowWaterSettings settings () const noexcept
 

静态 Public 成员函数

static Result< std::unique_ptr< ShallowWaterField > > create (const ShallowWaterSettings &settings)
 Validate settings and allocate a filled lake.
 

详细描述

GPU-first shallow-water (2D Saint-Venant) free-surface solver.

Owns height h, momentum (hu, hv) and bed b on a Cartesian XZ grid. The CPU reference mirrors the GLSL kernels 1:1 and is selected automatically when compute is unavailable. Character-leg capsules write displacement / momentum sources before each integrate pass.

@thread Graphics/device owner thread for GPU path; CPU path is reentrant for distinct instances only.

在文件 ShallowWaterField.h 第 100 行定义.

构造及析构函数说明

◆ ~ShallowWaterField()

eve::fluids::ShallowWaterField::~ShallowWaterField ( )

在文件 ShallowWaterField.cpp 第 140 行定义.

◆ ShallowWaterField()

eve::fluids::ShallowWaterField::ShallowWaterField ( const ShallowWaterField &  )
delete

成员函数说明

◆ addImpulse()

Result< void > eve::fluids::ShallowWaterField::addImpulse ( float  worldX,
float  worldZ,
float  radius,
float  strength 
)

Convenience splash: positive strength raises water, negative digs.

在文件 ShallowWaterField.cpp 第 289 行定义.

引用了 disturbAt(), radius , 以及 strength.

◆ beds()

std::span< const float > eve::fluids::ShallowWaterField::beds ( ) const
inlinenoexcept
返回
Bed heights.

在文件 ShallowWaterField.h 第 180 行定义.

被这些函数引用 setBed().

◆ buildSurfaceMesh()

Result< void > eve::fluids::ShallowWaterField::buildSurfaceMesh ( std::vector< float > &  positionsXYZ,
std::vector< float > &  normalsXYZ,
std::vector< float > &  uvsST,
std::vector< uint32_t > &  indices,
float  visualHeightGain = 1.f,
std::vector< float > *  colorsRGBA = nullptr 
) const

Build a Y-up triangle mesh of the free surface for Graphics upload.

参数
[out]positionsXYZVertex positions (3 floats each).
[out]normalsXYZVertex normals (3 floats each).
[out]uvsSTVertex UVs in [0,1]^2 (2 floats each).
[out]indicesTriangle indices.
visualHeightGainDisplay-only scale for (h - rest) relative to the last fill depth per cell; 1 keeps physical heights. Values in (0, 32] exaggerate centimetre waves for readability.
[out]colorsRGBAOptional per-vertex RGBA (4 floats each) for coloured meshes; pass nullptr to skip. Packs the same channel layout as copyFieldToImage with rest-relative depth (depthContrast = 0.12 * meanH, velocityScale = 1.5).

在文件 ShallowWaterField.cpp 第 349 行定义.

引用了 c, cellCount(), cx, dx, dz, h, index, indices, n, p, pos, reference, eve::Result< T >::success(), u, eve::fluids::ocean_script::vector(), vx, vz, x, y , 以及 z.

◆ cellCount()

int eve::fluids::ShallowWaterField::cellCount ( ) const
inlinenoexcept
返回
Cell count (resolutionX * resolutionZ).

在文件 ShallowWaterField.h 第 169 行定义.

被这些函数引用 buildSurfaceMesh(), copyFieldToImage(), setBed() , 以及 step().

◆ cellSize()

float eve::fluids::ShallowWaterField::cellSize ( ) const
inlinenoexcept
返回
Cell edge length in meters.

在文件 ShallowWaterField.h 第 167 行定义.

◆ colliders()

std::span< const ShallowWaterCollider > eve::fluids::ShallowWaterField::colliders ( ) const
inlinenoexcept
返回
Live collider samples.

在文件 ShallowWaterField.h 第 186 行定义.

被这些函数引用 setColliders().

◆ copyFieldToImage()

Result< void > eve::fluids::ShallowWaterField::copyFieldToImage ( image::ImageData &  image,
float  velocityScale = 2.f,
float  depthContrast = 0.f 
) const

Pack per-cell depth / velocity into an RGBA8 image (resolutionX × resolutionZ).

参数
imageDestination; must be RGBA8 with width=resolutionX and height=resolutionZ.
velocityScaleHorizontal speed that maps to the full channel range, in (0, 50].
depthContrastWhen <= 0, R stores absolute h / maxDepth. When > 0, R stores a crest heat map clamp((h - meanH) / depthContrast, 0, 1) so rest water stays dark and centimetre waves still paint red (range (0, maxDepth]).

Channel layout (row z, column x, matching mesh UVs):

  • R: water depth (absolute h/maxDepth, or crest heat when depthContrast > 0)
  • G: 0.5 + 0.5 * clamp(vx / velocityScale, -1, 1)
  • B: 0.5 + 0.5 * clamp(vz / velocityScale, -1, 1)
  • A: clamp(|v| / velocityScale, 0, 1) (foam / speed mask) @ownership Does not retain image; caller owns the pixel buffer for the call duration.
    返回
    Success, or InvalidArgument when the image shape/format/scale is rejected.

在文件 ShallowWaterField.cpp 第 449 行定义.

引用了 cellCount(), h, image, index, p, pixels, shape, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), vx, vz, x , 以及 z.

◆ copyNormalToImage()

Result< void > eve::fluids::ShallowWaterField::copyNormalToImage ( image::ImageData &  image,
float  normalStrength = 6.f 
) const

Write tangent-space normals from free-surface slopes (RGBA8, same grid size).

参数
imageDestination RGBA8 resolutionX × resolutionZ.
normalStrengthSlope exaggeration in (0, 64]; higher values make small waves catch light.

RGB stores 0.5 + 0.5 * n with n in tangent space (Z-up in texture); A = 1. @ownership Does not retain image.

在文件 ShallowWaterField.cpp 第 530 行定义.

引用了 cx, image, index, n, normalStrength, p, pixels, shape, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), x , 以及 z.

◆ copyShadedAlbedoToImage()

Result< void > eve::fluids::ShallowWaterField::copyShadedAlbedoToImage ( image::ImageData &  image,
float  restDepth,
float  velocityScale = 2.f 
) const

Write a shaded water albedo (RGBA8, same size as the grid) for Material upload.

参数
imageDestination RGBA8 resolutionX × resolutionZ.
restDepthReference depth used to exaggerate crests/troughs; typically initialDepth.
velocityScaleSpeed scale for foam / flow tint, in (0, 50].

Deep water is dark cyan; crests lighten; horizontal flow shifts green/magenta; foam (near-white) follows speed. Intended for setAlbedoTexture / setTexture. @ownership Does not retain image.

在文件 ShallowWaterField.cpp 第 487 行定义.

引用了 b, g, h, image, index, p, pixels, r, shape, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), vx, vz, x , 以及 z.

◆ create()

Result< std::unique_ptr< ShallowWaterField > > eve::fluids::ShallowWaterField::create ( const ShallowWaterSettings &  settings)
static

Validate settings and allocate a filled lake.

参数
settingsBorrowed immutable configuration.
返回
Owned solver, or InvalidArgument when ranges fail.

在文件 ShallowWaterField.cpp 第 108 行定义.

引用了 eve::fluids::ShallowWaterSettings::bedHeight, cells, eve::fluids::ocean_codec::field(), eve::fluids::ShallowWaterSettings::initialDepth, settings() , 以及 valid.

被这些函数引用 eve::fluids::Fluids::newShallowWater().

◆ depthAt()

float eve::fluids::ShallowWaterField::depthAt ( float  worldX,
float  worldZ 
) const
noexcept

Bilinear water depth at a world XZ point.

在文件 ShallowWaterField.cpp 第 315 行定义.

引用了 a, b, index, inside, eve::fluids::ocean_script::vector(), x , 以及 z.

◆ depths()

std::span< const float > eve::fluids::ShallowWaterField::depths ( ) const
inlinenoexcept
返回
Water-column heights (authoritative CPU mirror).

在文件 ShallowWaterField.h 第 178 行定义.

◆ disturbAt()

Result< void > eve::fluids::ShallowWaterField::disturbAt ( float  worldX,
float  worldZ,
float  radius,
float  heightDelta,
float  radialSpeed = 0.f 
)

Inject a localized height bump and radial outflow (mouse / splash).

参数
worldXWorld X of the disturbance center.
worldZWorld Z of the disturbance center.
radiusInfluence radius in meters.
heightDeltaAdded water column height.
radialSpeedOutward horizontal speed applied under the bump.

在文件 ShallowWaterField.cpp 第 259 行定义.

引用了 dx, dz, h, index, radius, eve::Result< T >::success(), eve::fluids::ocean_script::vector(), w, wx, wz, x , 以及 z.

被这些函数引用 addImpulse().

◆ fillDepth()

Result< void > eve::fluids::ShallowWaterField::fillDepth ( float  depth)

Fill every cell with a uniform water depth (momentum cleared).

在文件 ShallowWaterField.cpp 第 232 行定义.

引用了 depth, eve::Result< T >::success() , 以及 eve::fluids::ocean_script::vector().

◆ fillSurface()

Result< void > eve::fluids::ShallowWaterField::fillSurface ( float  surfaceY)

Fill to a world-space free-surface elevation, leaving high terrain dry.

参数
surfaceYFinite elevation in the same coordinates as setBed.
返回
InvalidArgument for invalid elevation or depth exceeding maxDepth; failure is atomic. @ownership Copies reference depths internally; no borrowed input is retained. @thread Owner thread, not concurrent with step or queries; invokes no callbacks. @cost Linear in grid cells, more expensive than a point query; amortize over lake initialization.

在文件 ShallowWaterField.cpp 第 242 行定义.

引用了 eve::Result< T >::success() , 以及 eve::fluids::ocean_script::vector().

◆ momentumX()

std::span< const float > eve::fluids::ShallowWaterField::momentumX ( ) const
inlinenoexcept
返回
X momentum hu.

在文件 ShallowWaterField.h 第 182 行定义.

◆ momentumZ()

std::span< const float > eve::fluids::ShallowWaterField::momentumZ ( ) const
inlinenoexcept
返回
Z momentum hv.

在文件 ShallowWaterField.h 第 184 行定义.

◆ operator=()

ShallowWaterField & eve::fluids::ShallowWaterField::operator= ( const ShallowWaterField &  )
delete

◆ origin()

glm::vec3 eve::fluids::ShallowWaterField::origin ( ) const
inlinenoexcept
返回
World origin of cell (0,0).

在文件 ShallowWaterField.h 第 171 行定义.

◆ resolutionX()

int eve::fluids::ShallowWaterField::resolutionX ( ) const
inlinenoexcept
返回
Grid resolution along X.

在文件 ShallowWaterField.h 第 163 行定义.

◆ resolutionZ()

int eve::fluids::ShallowWaterField::resolutionZ ( ) const
inlinenoexcept
返回
Grid resolution along Z.

在文件 ShallowWaterField.h 第 165 行定义.

◆ setBed()

Result< void > eve::fluids::ShallowWaterField::setBed ( std::span< const float >  beds)

Replace bed heights; call fillSurface afterwards to initialize a level lake.

参数
bedsBorrowed cellCount() heights in row-major Z/X order, copied during this call.
返回
InvalidArgument for wrong size or nonfinite data; failure leaves the field unchanged. @thread Owner thread, not concurrent with step or queries; no callbacks/reentrancy. @cost Linear in grid cells, more expensive than a point query; amortize over terrain setup.

在文件 ShallowWaterField.cpp 第 222 行定义.

引用了 beds(), cellCount(), eve::Result< T >::success(), v, eve::fluids::ocean_script::vector() , 以及 eve::gpgpu::GpuBuffer::writeFloat32s().

◆ setColliders()

Result< void > eve::fluids::ShallowWaterField::setColliders ( std::span< const ShallowWaterCollider >  colliders)

Replace analytic interactors atomically.

参数
collidersBorrowed samples valid only for the call duration.

在文件 ShallowWaterField.cpp 第 199 行定义.

引用了 eve::fluids::Box, c, eve::fluids::Capsule, colliders(), label, eve::fluids::Sphere, eve::Result< T >::success() , 以及 eve::fluids::ocean_script::vector().

◆ settings()

ShallowWaterSettings eve::fluids::ShallowWaterField::settings ( ) const
noexcept
返回
Mutable tuning copy (does not resize the grid).

在文件 ShallowWaterField.cpp 第 180 行定义.

引用了 eve::fluids::ShallowWaterSettings::resolutionX , 以及 s.

被这些函数引用 create().

◆ step()

Result< void > eve::fluids::ShallowWaterField::step ( float  dt)

Advance the free surface by dt seconds (CFL substeps).

在文件 ShallowWaterField.cpp 第 691 行定义.

引用了 cellCount(), dt, gpu, h, eve::Result< T >::success(), u, v , 以及 eve::fluids::ocean_script::vector().

◆ surfaceHeightAt()

float eve::fluids::ShallowWaterField::surfaceHeightAt ( float  worldX,
float  worldZ 
) const
noexcept

Bilinear free-surface height b + h at a world XZ point.

在文件 ShallowWaterField.cpp 第 294 行定义.

引用了 a, b, index, inside, eve::fluids::ocean_script::vector(), x , 以及 z.

◆ usedBackendFallback()

bool eve::fluids::ShallowWaterField::usedBackendFallback ( ) const
inlinenoexcept
返回
True when GPU was requested but CPU was selected.

在文件 ShallowWaterField.h 第 175 行定义.

◆ usingGpu()

bool eve::fluids::ShallowWaterField::usingGpu ( ) const
inlinenoexcept
返回
True when the GPU compute path is active.

在文件 ShallowWaterField.h 第 173 行定义.

◆ velocityAt()

glm::vec2 eve::fluids::ShallowWaterField::velocityAt ( float  worldX,
float  worldZ 
) const
noexcept

Bilinear horizontal velocity at a world XZ point.

在文件 ShallowWaterField.cpp 第 331 行定义.

引用了 a, b, h, index, inside, eve::fluids::ocean_script::vector(), x , 以及 z.


该类的文档由以下文件生成: