载入中...
搜索中...
未找到
ClothGPU.h
浏览该文件的文档.
1#pragma once
2
4
5#include <cstdint>
6#include <string>
7#include <vector>
8
9namespace eve::graphics {
10class Graphics;
11}
12
13namespace eve::gpgpu {
14class Gpgpu;
15class ComputeShader;
16class GpuBuffer;
17class Sequence;
18} // namespace eve::gpgpu
19
20namespace eve::physics {
21
32public:
33 static constexpr int kMaxLinksPerParticle = 16;
34
44 ClothGPU(eve::gpgpu::Gpgpu *gpgpu, int cols, int rows, float spacing, float originX,
45 float originY);
47 ~ClothGPU();
48
49 ClothGPU(const ClothGPU &) = delete;
50 ClothGPU &operator=(const ClothGPU &) = delete;
51
53 void update(float dt);
54
56 [[nodiscard("check the GPU cloth step outcome")]]
59 [[nodiscard]] SimulationObservation observation() const noexcept override { return observation_; }
61 [[nodiscard]] SimulationBackendKind kind() const noexcept override { return SimulationBackendKind::Gpu; }
63 [[nodiscard]] SimulationDeterminism determinism() const noexcept override {
64 return SimulationDeterminism::ToleranceBounded;
65 }
67 [[nodiscard]] std::string getBackendName() const { return "gpu"; }
69 [[nodiscard]] bool supportsFeature(const std::string &feature) const;
71 [[nodiscard("check GPU cloth observation restore")]]
72 eve::Result<void> restoreObservation(const SimulationObservation &observation) override;
73
75 void setGravity(float gx, float gy);
77 float getGravityX() const { return gravityX_; }
79 float getGravityY() const { return gravityY_; }
80
82 void setStiffness(float stiffness);
84 float getStiffness() const { return stiffness_; }
85
87 void setIterations(int iterations);
89 int getIterations() const { return iterations_; }
90
92 void setDamping(float damping);
94 float getDamping() const { return damping_; }
95
97 void setParticleSize(float size);
99 float getParticleSize() const { return particleSize_; }
100
108 void setSelfCollision(bool on);
110 bool getSelfCollision() const { return selfCollision_; }
111
113 void setBounds(float x, float y, float w, float h);
115 void clearBounds();
116
118 void pin(int index);
120 void unpin(int index);
122 void pinTopRow();
124 bool isPinned(int index) const;
125
128 void applyForce(float fx, float fy);
129
134 void interactAt(float x, float y, float radius, float strength);
135
137 void setColor(float r, float g, float b, float a = 1.f);
139 float getColorR() const { return colorR_; }
141 float getColorG() const { return colorG_; }
143 float getColorB() const { return colorB_; }
145 float getColorA() const { return colorA_; }
146
148 void draw(graphics::Graphics *gfx);
149
151 int getCols() const { return cols_; }
153 int getRows() const { return rows_; }
155 int getParticleCount() const { return cols_ * rows_; }
157 float getParticleX(int index) const;
159 float getParticleY(int index) const;
160
162 float getSpacing() const { return spacing_; }
164 float getOriginX() const { return originX_; }
166 float getOriginY() const { return originY_; }
167
169 void reset();
170
172 void destroy();
173
174private:
175 struct Link {
176 int other = -1;
177 float rest = 0.f;
178 };
179
180 void rebuildLinks();
181 void uploadInitialState();
182 void uploadPinned();
183 void ensureHashBuffers();
184 eve::Result<void> stepGpu(float dt, int substeps);
185
186 eve::gpgpu::Gpgpu *gpgpu_ = nullptr;
187 int cols_ = 0;
188 int rows_ = 0;
189 float spacing_ = 10.f;
190 float originX_ = 0.f;
191 float originY_ = 0.f;
192
193 float gravityX_ = 0.f;
194 float gravityY_ = 980.f;
195 float stiffness_ = 0.85f;
196 int iterations_ = 4;
197 float damping_ = 0.01f;
198 float particleSize_ = 3.f;
199
200 bool hasBounds_ = false;
201 float boundX_ = 0.f, boundY_ = 0.f, boundW_ = 0.f, boundH_ = 0.f;
202
203 float forceX_ = 0.f, forceY_ = 0.f;
204 float interactX_ = 0.f, interactY_ = 0.f;
205 float interactRadius_ = 0.f;
206 float interactStrength_ = 0.f;
207
208 float colorR_ = 0.75f, colorG_ = 0.82f, colorB_ = 0.95f, colorA_ = 1.f;
209
210 bool destroyed_ = false;
211 SimulationObservation observation_;
212
213 std::vector<Link> links_; // particle-major, kMaxLinksPerParticle slots
214 std::vector<float> posCpu_; // x,y,px,py per particle (readback)
215 std::vector<float> flagsCpu_; // 1 = pinned
216 std::vector<float> linkCpu_; // other,rest,0,0 per slot
217
218 eve::gpgpu::ComputeShader *shader_ = nullptr;
219 eve::gpgpu::Sequence *seq_ = nullptr;
220 eve::gpgpu::GpuBuffer *posBuf_ = nullptr;
221 eve::gpgpu::GpuBuffer *posBufB_ = nullptr;
222 eve::gpgpu::GpuBuffer *linkBuf_ = nullptr;
223 eve::gpgpu::GpuBuffer *flagBuf_ = nullptr;
224 eve::gpgpu::GpuBuffer *staging_ = nullptr;
225 eve::gpgpu::GpuBuffer *cellHeadBuf_ = nullptr;
226 eve::gpgpu::GpuBuffer *cellNextBuf_ = nullptr;
227 eve::gpgpu::GpuBuffer *cellItemsBuf_ = nullptr;
228 eve::gpgpu::GpuBuffer *cellSlotBuf_ = nullptr;
229 int hashNx_ = 0;
230 int hashNy_ = 0;
231 bool selfCollision_ = false;
232};
233
234} // namespace eve::physics
float w
Definition AnimClip.cpp:738
float y
Definition AnimClip.cpp:738
float x
Definition AnimClip.cpp:738
#define EVENGINE_API_DOMAINS
Definition Export.h:110
int rows
int cols
tensor::Graph g
Definition GpuGraph.cpp:7
double r
int h
void(* destroy)(void *)
MeleePoint3 b
Definition MeleeHit.cpp:41
MeleePoint3 a
Definition MeleeHit.cpp:40
MeshVfxBatchedDraw draw
float radius
Backend-neutral, observable fixed-step contract for physics domains.
TerrainThermalSettings settings
int spacing
int iterations
Definition TreeMesh.cpp:311
float step
Definition TreeMesh.cpp:314
float size
Definition TreeMesh.cpp:156
uint32_t index
Move-only operation result carrying either a value or Status.
Definition Result.h:155
Backend-agnostic compute program. Bind storage buffers then dispatch via Gpgpu::dispatch....
GPGPU module — compute shaders + storage buffers via the active Graphics backend. Uses the graphics q...
Definition Gpgpu.h:23
Backend-agnostic GPU buffer for compute (storage) or CPU staging transfers. Squirrel-owned; derived c...
Definition GpuBuffer.h:18
EVENGINE_API_WORLD public API.
Definition Sequence.h:41
GPU-accelerated 2D cloth — Verlet integration and distance-constraint relaxation run in a Vulkan comp...
Definition ClothGPU.h:31
int getRows() const
Returns the rows.
Definition ClothGPU.h:153
float getColorG() const
Returns the color g.
Definition ClothGPU.h:141
float getSpacing() const
Returns the spacing.
Definition ClothGPU.h:162
int getParticleCount() const
Returns the particle count.
Definition ClothGPU.h:155
ClothGPU & operator=(const ClothGPU &)=delete
ClothGPU(const ClothGPU &)=delete
bool getSelfCollision() const
Returns the self collision.
Definition ClothGPU.h:110
float getGravityY() const
Returns the gravity y.
Definition ClothGPU.h:79
SimulationBackendKind kind() const noexcept override
Identifies this real accelerator backend.
Definition ClothGPU.h:61
float getColorB() const
Returns the color b.
Definition ClothGPU.h:143
float getOriginY() const
Returns the origin y.
Definition ClothGPU.h:166
float getColorA() const
Returns the color a.
Definition ClothGPU.h:145
float getDamping() const
Returns the damping.
Definition ClothGPU.h:94
int getIterations() const
Returns the iterations.
Definition ClothGPU.h:89
float getStiffness() const
Returns the stiffness.
Definition ClothGPU.h:84
float getOriginX() const
Returns the origin x.
Definition ClothGPU.h:164
int getCols() const
Returns the cols.
Definition ClothGPU.h:151
float getParticleSize() const
Returns the particle size.
Definition ClothGPU.h:99
SimulationDeterminism determinism() const noexcept override
GPU/CPU parity is numerically bounded, not bit exact.
Definition ClothGPU.h:63
float getColorR() const
Returns the color r.
Definition ClothGPU.h:139
std::string getBackendName() const
Return stable backend name for scripts and diagnostics.
Definition ClothGPU.h:67
SimulationObservation observation() const noexcept override
Returns completed tick/time observables.
Definition ClothGPU.h:59
float getGravityX() const
Returns the gravity x.
Definition ClothGPU.h:77
Minimal observable contract for physics simulation providers.
Fluids module — interactive surface fluid simulation.
Definition Fluids.h:34
卡牌游戏 UI 工具模块:工厂 + 脚本绑定入口。 功能参考 ycarowr/UiCard:扇形手牌布局、抽牌/洗牌、悬浮放大、拖拽到落牌区、 敌方手牌(背面/偷看)、费用不足置灰,以及可实时调节的布局...
Definition Animation.h:25
Optional physics backend for vehicle mobility and body attach.
Definition Climbing.h:36
SimulationBackendKind
Kind of implementation that owns a simulation step.
SimulationDeterminism
Determinism guarantee made by a simulation backend.
One deterministic fixed-step emitted by SimulationClock.
Definition Time.h:158
Observable backend progress shared by CPU and accelerator providers.
Validated solver policy for one simulation step.
gpgpu::Gpgpu * gpgpu