GPU-accelerated 2D cloth — Verlet integration and distance-constraint relaxation run in a Vulkan compute shader; positions are read back each frame for drawing. Same pixel-space conventions and script API shape as Cloth. 更多...
#include <ClothGPU.h>
Public 成员函数 | |
| ClothGPU (eve::gpgpu::Gpgpu *gpgpu, int cols, int rows, float spacing, float originX, float originY) | |
| Cloth gpu. | |
| ~ClothGPU () | |
| Cloth gpu. | |
| ClothGPU (const ClothGPU &)=delete | |
| ClothGPU & | operator= (const ClothGPU &)=delete |
| void | update (float dt) |
| Updates . | |
| eve::Result< void > | step (const eve::SimulationStep &step, const SimulationSettings &settings) override |
| Advances the production GPU cloth with the shared ticked contract. | |
| SimulationObservation | observation () const noexcept override |
| Returns completed tick/time observables. | |
| SimulationBackendKind | kind () const noexcept override |
| Identifies this real accelerator backend. | |
| SimulationDeterminism | determinism () const noexcept override |
| GPU/CPU parity is numerically bounded, not bit exact. | |
| std::string | getBackendName () const |
| Return stable backend name for scripts and diagnostics. | |
| bool | supportsFeature (const std::string &feature) const |
| Query a stable cloth feature name; unsupported features never silently fall back. | |
| eve::Result< void > | restoreObservation (const SimulationObservation &observation) override |
| Restores tick/progress metadata after an owner-level restore. | |
| void | setGravity (float gx, float gy) |
| Sets the gravity. | |
| float | getGravityX () const |
| Returns the gravity x. | |
| float | getGravityY () const |
| Returns the gravity y. | |
| void | setStiffness (float stiffness) |
| Constraint relaxation strength in [0,1] (default 0.85). | |
| float | getStiffness () const |
| Returns the stiffness. | |
| void | setIterations (int iterations) |
| Constraint solver iterations per substep (default 4). | |
| int | getIterations () const |
| Returns the iterations. | |
| void | setDamping (float damping) |
| Damping applied to Verlet velocity [0,1] (default 0.01). | |
| float | getDamping () const |
| Returns the damping. | |
| void | setParticleSize (float size) |
| Particle draw size in pixels (default 3). | |
| float | getParticleSize () const |
| Returns the particle size. | |
| void | setSelfCollision (bool on) |
| Enable proximity-based self-collision between non-adjacent particles Default is false. Particles keep at least twice particleSize apart. When bounds are set, uses a GPU spatial hash (atomicExchange linked lists per cell, overflow-free) with 3x3 neighbor traversal — scales to tens of thousands of particles. Without bounds it falls back to an O(n²) scan. | |
| bool | getSelfCollision () const |
| Returns the self collision. | |
| void | setBounds (float x, float y, float w, float h) |
| Axis-aligned walls; particles are clamped (with a small bounce). | |
| void | clearBounds () |
| Clears bounds. | |
| void | pin (int index) |
| Pin. | |
| void | unpin (int index) |
| Unpin. | |
| void | pinTopRow () |
| Pin top row. | |
| bool | isPinned (int index) const |
| True when pinned. | |
| void | applyForce (float fx, float fy) |
| Applies force. | |
| void | interactAt (float x, float y, float radius, float strength) |
| Pointer-field interaction like Fluid2D::interactAt: positive strength attracts, negative repels within radius (pixels) during the next update. | |
| void | setColor (float r, float g, float b, float a=1.f) |
| Sets the color. | |
| float | getColorR () const |
| Returns the color r. | |
| float | getColorG () const |
| Returns the color g. | |
| float | getColorB () const |
| Returns the color b. | |
| float | getColorA () const |
| Returns the color a. | |
| void | draw (graphics::Graphics *gfx) |
| Draw links + particles from the latest GPU readback. | |
| int | getCols () const |
| Returns the cols. | |
| int | getRows () const |
| Returns the rows. | |
| int | getParticleCount () const |
| Returns the particle count. | |
| float | getParticleX (int index) const |
| Returns the particle x. | |
| float | getParticleY (int index) const |
| Returns the particle y. | |
| float | getSpacing () const |
| Returns the spacing. | |
| float | getOriginX () const |
| Returns the origin x. | |
| float | getOriginY () const |
| Returns the origin y. | |
| void | reset () |
| Restore the flat grid pose (top row pinned) and re-upload state. | |
| void | destroy () |
| Destroys . | |
Public 成员函数 继承自 eve::physics::ISimulationBackend | |
| virtual | ~ISimulationBackend ()=default |
| Releases the backend; borrowed domain state is not destroyed. | |
静态 Public 属性 | |
| static constexpr int | kMaxLinksPerParticle = 16 |
详细描述
GPU-accelerated 2D cloth — Verlet integration and distance-constraint relaxation run in a Vulkan compute shader; positions are read back each frame for drawing. Same pixel-space conventions and script API shape as Cloth.
One thread owns one particle and solves its fixed-size link list, so no atomics or ping-pong buffers are needed. Requires the Gpgpu module and a compute-capable Graphics backend; construction throws when unavailable.
在文件 ClothGPU.h 第 31 行定义.
构造及析构函数说明
◆ ClothGPU() [1/2]
| eve::physics::ClothGPU::ClothGPU | ( | eve::gpgpu::Gpgpu * | gpgpu, |
| int | cols, | ||
| int | rows, | ||
| float | spacing, | ||
| float | originX, | ||
| float | originY | ||
| ) |
Cloth gpu.
- 参数
-
gpgpu active Gpgpu module (compute shader compiler + buffers) cols grid columns (>= 2) rows grid rows (>= 2) spacing particle spacing in pixels originX top-left particle X (pixels) originY top-left particle Y (pixels)
在文件 ClothGPU.cpp 第 255 行定义.
引用了 c, count, getParticleCount(), gpgpu, eve::gpgpu::Sequence::isAvailable(), kMaxLinksPerParticle, eve::gpgpu::Gpgpu::newBuffer(), eve::gpgpu::Gpgpu::newSequence(), eve::gpgpu::Gpgpu::newShader() , 以及 r.
◆ ~ClothGPU()
| eve::physics::ClothGPU::~ClothGPU | ( | ) |
◆ ClothGPU() [2/2]
|
delete |
成员函数说明
◆ applyForce()
| void eve::physics::ClothGPU::applyForce | ( | float | fx, |
| float | fy | ||
| ) |
Applies force.
Uniform wind / force impulse applied this frame (pixels/s²).
在文件 ClothGPU.cpp 第 488 行定义.
◆ clearBounds()
| void eve::physics::ClothGPU::clearBounds | ( | ) |
◆ destroy()
| void eve::physics::ClothGPU::destroy | ( | ) |
◆ determinism()
|
inlineoverridevirtualnoexcept |
GPU/CPU parity is numerically bounded, not bit exact.
实现了 eve::physics::ISimulationBackend.
在文件 ClothGPU.h 第 63 行定义.
◆ draw()
| void eve::physics::ClothGPU::draw | ( | graphics::Graphics * | gfx | ) |
Draw links + particles from the latest GPU readback.
在文件 ClothGPU.cpp 第 664 行定义.
引用了 count, eve::graphics::Graphics::drawSolidRect(), dx, dy, getParticleCount(), kMaxLinksPerParticle, s, steps , 以及 t.
◆ getBackendName()
|
inline |
Return stable backend name for scripts and diagnostics.
在文件 ClothGPU.h 第 67 行定义.
◆ getColorA()
|
inline |
Returns the color a.
在文件 ClothGPU.h 第 145 行定义.
◆ getColorB()
|
inline |
Returns the color b.
在文件 ClothGPU.h 第 143 行定义.
◆ getColorG()
|
inline |
Returns the color g.
在文件 ClothGPU.h 第 141 行定义.
◆ getColorR()
|
inline |
Returns the color r.
在文件 ClothGPU.h 第 139 行定义.
◆ getCols()
|
inline |
Returns the cols.
在文件 ClothGPU.h 第 151 行定义.
◆ getDamping()
|
inline |
Returns the damping.
在文件 ClothGPU.h 第 94 行定义.
◆ getGravityX()
|
inline |
Returns the gravity x.
在文件 ClothGPU.h 第 77 行定义.
◆ getGravityY()
|
inline |
Returns the gravity y.
在文件 ClothGPU.h 第 79 行定义.
◆ getIterations()
|
inline |
Returns the iterations.
在文件 ClothGPU.h 第 89 行定义.
◆ getOriginX()
|
inline |
Returns the origin x.
在文件 ClothGPU.h 第 164 行定义.
◆ getOriginY()
|
inline |
Returns the origin y.
在文件 ClothGPU.h 第 166 行定义.
◆ getParticleCount()
|
inline |
Returns the particle count.
在文件 ClothGPU.h 第 155 行定义.
被这些函数引用 ClothGPU(), draw(), getParticleX(), getParticleY(), isPinned(), pin() , 以及 unpin().
◆ getParticleSize()
|
inline |
Returns the particle size.
在文件 ClothGPU.h 第 99 行定义.
◆ getParticleX()
| float eve::physics::ClothGPU::getParticleX | ( | int | index | ) | const |
◆ getParticleY()
| float eve::physics::ClothGPU::getParticleY | ( | int | index | ) | const |
◆ getRows()
|
inline |
Returns the rows.
在文件 ClothGPU.h 第 153 行定义.
◆ getSelfCollision()
|
inline |
Returns the self collision.
在文件 ClothGPU.h 第 110 行定义.
◆ getSpacing()
|
inline |
Returns the spacing.
在文件 ClothGPU.h 第 162 行定义.
◆ getStiffness()
|
inline |
Returns the stiffness.
在文件 ClothGPU.h 第 84 行定义.
◆ interactAt()
| void eve::physics::ClothGPU::interactAt | ( | float | x, |
| float | y, | ||
| float | radius, | ||
| float | strength | ||
| ) |
Pointer-field interaction like Fluid2D::interactAt: positive strength attracts, negative repels within radius (pixels) during the next update.
在文件 ClothGPU.cpp 第 493 行定义.
◆ isPinned()
| bool eve::physics::ClothGPU::isPinned | ( | int | index | ) | const |
◆ kind()
|
inlineoverridevirtualnoexcept |
Identifies this real accelerator backend.
实现了 eve::physics::ISimulationBackend.
在文件 ClothGPU.h 第 61 行定义.
◆ observation()
|
inlineoverridevirtualnoexcept |
Returns completed tick/time observables.
实现了 eve::physics::ISimulationBackend.
在文件 ClothGPU.h 第 59 行定义.
被这些函数引用 restoreObservation().
◆ operator=()
◆ pin()
| void eve::physics::ClothGPU::pin | ( | int | index | ) |
◆ pinTopRow()
| void eve::physics::ClothGPU::pinTopRow | ( | ) |
◆ reset()
| void eve::physics::ClothGPU::reset | ( | ) |
Restore the flat grid pose (top row pinned) and re-upload state.
在文件 ClothGPU.cpp 第 517 行定义.
引用了 c, pinTopRow() , 以及 r.
◆ restoreObservation()
|
overridevirtual |
Restores tick/progress metadata after an owner-level restore.
重载 eve::physics::ISimulationBackend .
在文件 ClothGPU.cpp 第 653 行定义.
引用了 eve::Applied, eve::Diagnostic::error(), eve::Result< T >::failure(), observation(), eve::PreconditionViolation, eve::Status::success(), eve::Result< T >::success() , 以及 valid.
◆ setBounds()
| void eve::physics::ClothGPU::setBounds | ( | float | x, |
| float | y, | ||
| float | w, | ||
| float | h | ||
| ) |
Axis-aligned walls; particles are clamped (with a small bounce).
在文件 ClothGPU.cpp 第 450 行定义.
引用了 clearBounds(), h, w, x , 以及 y.
◆ setColor()
| void eve::physics::ClothGPU::setColor | ( | float | r, |
| float | g, | ||
| float | b, | ||
| float | a = 1.f |
||
| ) |
◆ setDamping()
| void eve::physics::ClothGPU::setDamping | ( | float | damping | ) |
Damping applied to Verlet velocity [0,1] (default 0.01).
在文件 ClothGPU.cpp 第 440 行定义.
◆ setGravity()
| void eve::physics::ClothGPU::setGravity | ( | float | gx, |
| float | gy | ||
| ) |
Sets the gravity.
在文件 ClothGPU.cpp 第 427 行定义.
◆ setIterations()
| void eve::physics::ClothGPU::setIterations | ( | int | iterations | ) |
◆ setParticleSize()
| void eve::physics::ClothGPU::setParticleSize | ( | float | size | ) |
◆ setSelfCollision()
| void eve::physics::ClothGPU::setSelfCollision | ( | bool | on | ) |
Enable proximity-based self-collision between non-adjacent particles Default is false. Particles keep at least twice particleSize apart. When bounds are set, uses a GPU spatial hash (atomicExchange linked lists per cell, overflow-free) with 3x3 neighbor traversal — scales to tens of thousands of particles. Without bounds it falls back to an O(n²) scan.
在文件 ClothGPU.cpp 第 448 行定义.
◆ setStiffness()
| void eve::physics::ClothGPU::setStiffness | ( | float | stiffness | ) |
Constraint relaxation strength in [0,1] (default 0.85).
在文件 ClothGPU.cpp 第 432 行定义.
◆ step()
|
overridevirtual |
Advances the production GPU cloth with the shared ticked contract.
实现了 eve::physics::ISimulationBackend.
在文件 ClothGPU.cpp 第 630 行定义.
引用了 eve::Applied, eve::SimulationStep::delta, error, eve::Diagnostic::error(), eve::Failed, eve::Result< T >::failure(), eve::PreconditionViolation, eve::Duration::seconds(), settings, eve::Status::success(), eve::Result< T >::success() , 以及 valid.
◆ supportsFeature()
| bool eve::physics::ClothGPU::supportsFeature | ( | const std::string & | feature | ) | const |
Query a stable cloth feature name; unsupported features never silently fall back.
在文件 ClothGPU.cpp 第 18 行定义.
◆ unpin()
| void eve::physics::ClothGPU::unpin | ( | int | index | ) |
◆ update()
| void eve::physics::ClothGPU::update | ( | float | dt | ) |
Updates .
在文件 ClothGPU.cpp 第 534 行定义.
类成员变量说明
◆ kMaxLinksPerParticle
|
staticconstexpr |
在文件 ClothGPU.h 第 33 行定义.
被这些函数引用 ClothGPU() , 以及 draw().
该类的文档由以下文件生成:
- src/modules/physics/cloth/ClothGPU.h
- src/modules/physics/cloth/ClothGPU.cpp
Public 成员函数 继承自