63 void update(
float dt);
66 [[nodiscard(
"check the cloth step outcome")]]
74 return SimulationDeterminism::ToleranceBounded;
79 [[nodiscard]]
bool supportsFeature(
const std::string& feature)
const;
81 [[nodiscard(
"check cloth observation restore")]]
85 void setGravity(
float gx,
float gy,
float gz);
94 void setStiffness(
float stiffness);
99 void setStretchCompliance(
float compliance);
101 [[nodiscard]]
float getStretchCompliance()
const;
103 void setShearCompliance(
float compliance);
105 [[nodiscard]]
float getShearCompliance()
const;
107 void setBendCompliance(
float compliance);
109 [[nodiscard]]
float getBendCompliance()
const;
112 void setTetherScale(
float scale);
114 [[nodiscard]]
float getTetherScale()
const;
116 void setTetherCompliance(
float compliance);
118 [[nodiscard]]
float getTetherCompliance()
const;
121 void setPressure(
float pressure);
123 [[nodiscard]]
float getPressure()
const;
125 void setVolumeCompliance(
float compliance);
127 [[nodiscard]]
float getVolumeCompliance()
const;
129 [[nodiscard]]
float getCurrentVolume()
const;
137 void setDamping(
float damping);
145 void setParticleSize(
float size);
155 void setSelfCollision(
bool on);
163 void setParticleMass(
float mass);
168 void setFoldStiffness(
float k);
178 void setMaxFoldAngle(
float degrees);
183 void setBounds(
float x,
float y,
float z,
float w,
float h,
float d);
188 void setCollisionMaterial(
float friction,
float restitution);
190 [[nodiscard]]
float getCollisionFriction()
const;
192 [[nodiscard]]
float getCollisionRestitution()
const;
194 void setCollisionFilter(uint64_t categoryBits, uint64_t maskBits);
196 [[nodiscard]] uint64_t getCollisionCategoryBits()
const;
198 [[nodiscard]] uint64_t getCollisionMaskBits()
const;
201 void setTearThreshold(
float strain);
203 [[nodiscard]]
float getTearThreshold()
const;
205 void setMaxTearsPerStep(
int count);
207 [[nodiscard]]
int getMaxTearsPerStep()
const;
209 void tearConstraint(
int particleA,
int particleB);
211 [[nodiscard]]
int getTornConstraintCount()
const;
215 void unpin(
int index);
219 bool isPinned(
int index)
const;
221 void setParticleInverseMass(
int index,
float inverseMass);
223 [[nodiscard]]
float getParticleInverseMass(
int index)
const;
226 void setSkinConstraint(
int index,
float x,
float y,
float z,
float nx,
float ny,
float nz,
float radius,
227 float backstopDistance = -1.f,
float backstopRadius = 0.f,
float compliance = 0.f);
229 void updateSkinReference(
int index,
float x,
float y,
float z,
float nx,
float ny,
float nz);
231 void clearSkinConstraint(
int index);
233 [[nodiscard]]
bool hasSkinConstraint(
int index)
const;
236 void attachParticle(
int index,
float x,
float y,
float z,
float compliance = 0.f);
238 void updateAttachment(
int index,
float x,
float y,
float z);
240 void detachParticle(
int index);
242 [[nodiscard]]
bool isAttached(
int index)
const;
248 int grabAt(
float x,
float y,
float z,
float radius = 0.3f);
250 void moveGrab(
float x,
float y,
float z);
260 void applyForce(
float fx,
float fy,
float fz);
272 void setWindVelocity(
float vx,
float vy,
float vz);
274 [[nodiscard]]
float getWindVelocityX()
const;
276 [[nodiscard]]
float getWindVelocityY()
const;
278 [[nodiscard]]
float getWindVelocityZ()
const;
298 void setAerodynamics(
float airDensity,
float dragCoefficient,
float liftCoefficient);
300 [[nodiscard]]
float getAirDensity()
const;
302 [[nodiscard]]
float getDragCoefficient()
const;
304 [[nodiscard]]
float getLiftCoefficient()
const;
339 void setColor(
float r,
float g,
float b,
float a = 1.f);
359 [[nodiscard]]
int getTriangleCount()
const;
361 [[nodiscard]]
int getDistanceConstraintCount()
const;
363 [[nodiscard]]
int getTetherConstraintCount()
const;
365 [[nodiscard]]
int getSkinConstraintCount()
const;
368 float getParticleX(
int index)
const;
370 float getParticleY(
int index)
const;
372 float getParticleZ(
int index)
const;
374 void setParticlePosition(
int index,
float x,
float y,
float z);
390 float x = 0.f,
y = 0.f,
z = 0.f;
391 float px = 0.f,
py = 0.f,
pz = 0.f;
392 float inverseMass = 1.f;
398 ClothConstraintKind
kind = ClothConstraintKind::Structural;
402 int v[3] = {0, 0, 0};
406 int a = 0,
b = 0, k = 0, l = 0;
411 float maxLength = 0.f;
414 struct SkinConstraint {
416 float x = 0.f,
y = 0.f,
z = 0.f;
417 float nx = 0.f,
ny = 1.f,
nz = 0.f;
419 float backstopDistance = -1.f;
420 float backstopRadius = 0.f;
421 float compliance = 0.f;
426 float x = 0.f,
y = 0.f,
z = 0.f;
427 float compliance = 0.f;
432 void initializeFromModel(
const ClothModel&
model);
433 void updateSubsteps(
float dt,
int substeps);
434 void rebuildTriangles();
435 void buildLinkKeys();
436 bool areLinked(
int a,
int b)
const;
437 void integrate(
float dt);
438 void accumulateAerodynamicAcceleration(
float dt, std::vector<float>& accelerations)
const;
439 void solveConstraints(
float dt);
440 void solveTetherConstraints(
float dt);
441 void solveVolumeConstraint(
float dt);
442 void solveSkinConstraints(
float dt);
443 void solveAttachments(
float dt);
444 void applyAutomaticTearing();
445 void tearLink(
size_t linkIndex);
446 void rebuildFoldPairsFromTriangles();
447 void solveFoldConstraint();
448 void solveSelfCollision();
449 void solveSelfCollisionTriangles();
450 void collideWorld(
float dt);
451 void collideBounds();
453 bool validIndex(
int index)
const;
454 int64_t cellKey(
int cx,
int cy,
int cz)
const;
458 float spacing_ = 0.4f;
459 float originX_ = 0.f, originY_ = 0.f, originZ_ = 0.f;
461 float gravityX_ = 0.f;
462 float gravityY_ = -9.8f;
463 float gravityZ_ = 0.f;
464 float stiffness_ = 0.85f;
465 float stretchCompliance_ = 0.f;
466 float shearCompliance_ = 0.f;
467 float bendCompliance_ = 0.f;
468 float tetherScale_ = 0.f;
469 float tetherCompliance_ = 0.f;
470 float pressure_ = 0.f;
471 float volumeCompliance_ = 0.f;
472 float restVolume_ = 0.f;
473 float volumeLambda_ = 0.f;
474 float damping_ = 0.01f;
476 float particleSize_ = 0.1f;
477 float particleMass_ = 0.1f;
478 bool selfCollision_ =
true;
479 float foldStiffness_ = 0.5f;
480 float maxFoldAngle_ = 120.f * 3.14159265f / 180.f;
481 float collisionFriction_ = 0.2f;
482 float collisionRestitution_ = 0.15f;
483 uint64_t collisionCategoryBits_ = ~uint64_t{0};
484 uint64_t collisionMaskBits_ = ~uint64_t{0};
485 float tearThreshold_ = 0.f;
486 int maxTearsPerStep_ = 1;
487 int tornConstraintCount_ = 0;
489 bool hasBounds_ =
false;
490 float boundX_ = 0.f, boundY_ = 0.f, boundZ_ = 0.f;
491 float boundW_ = 0.f, boundH_ = 0.f, boundD_ = 0.f;
494 float grabX_ = 0.f, grabY_ = 0.f, grabZ_ = 0.f;
495 float forceX_ = 0.f, forceY_ = 0.f, forceZ_ = 0.f;
496 float windVelocityX_ = 0.f, windVelocityY_ = 0.f, windVelocityZ_ = 0.f;
497 float airDensity_ = 1.225f;
498 float dragCoefficient_ = 0.f;
499 float liftCoefficient_ = 0.f;
500 float interactX_ = 0.f, interactY_ = 0.f, interactZ_ = 0.f;
501 float interactRadius_ = 0.f;
502 float interactStrength_ = 0.f;
506 float colorR_ = 0.75f, colorG_ = 0.82f, colorB_ = 0.95f, colorA_ = 1.f;
508 bool destroyed_ =
false;
509 SimulationObservation observation_;
511 std::vector<Particle> particles_;
512 std::vector<Particle> restParticles_;
513 std::vector<Link> links_;
514 std::vector<Tri> triangles_;
515 std::vector<FoldPair> foldPairs_;
516 std::vector<Tether> tethers_;
517 std::vector<SkinConstraint> skinConstraints_;
518 std::vector<Attachment> attachments_;
519 std::unordered_set<int64_t> linkKeys_;
520 std::unordered_map<int64_t, std::vector<int>> hash_;
522 graphics::Mesh* mesh_ =
nullptr;
523 int meshVertexCount_ = 0;
524 int meshIndexCount_ = 0;