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);
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;
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;
324 void setCollideWorld(
World3D* world);
339 void setColor(
float r,
float g,
float b,
float a = 1.f);
366 [[nodiscard]]
int getTriangleCount()
const;
368 [[nodiscard]]
int getDistanceConstraintCount()
const;
370 [[nodiscard]]
int getTetherConstraintCount()
const;
372 [[nodiscard]]
int getSkinConstraintCount()
const;
375 float getParticleX(
int index)
const;
377 float getParticleY(
int index)
const;
379 float getParticleZ(
int index)
const;
381 void setParticlePosition(
int index,
float x,
float y,
float z);
398 float x = 0.f,
y = 0.f,
z = 0.f;
399 float px = 0.f,
py = 0.f,
pz = 0.f;
410 int v[3] = {0, 0, 0};
414 int a = 0,
b = 0, k = 0, l = 0;
419 float maxLength = 0.f;
422 struct SkinConstraint {
424 float x = 0.f,
y = 0.f,
z = 0.f;
425 float nx = 0.f,
ny = 1.f,
nz = 0.f;
427 float backstopDistance = -1.f;
428 float backstopRadius = 0.f;
429 float compliance = 0.f;
434 float x = 0.f,
y = 0.f,
z = 0.f;
435 float compliance = 0.f;
440 void initializeFromModel(
const ClothModel&
model);
441 void updateSubsteps(
float dt,
int substeps);
442 void rebuildTriangles();
443 void buildLinkKeys();
444 bool areLinked(
int a,
int b)
const;
445 void integrate(
float dt);
446 void accumulateAerodynamicAcceleration(
float dt, std::vector<float>& accelerations)
const;
447 void solveConstraints(
float dt);
448 void solveTetherConstraints(
float dt);
449 void solveVolumeConstraint(
float dt);
450 void solveSkinConstraints(
float dt);
451 void solveAttachments(
float dt);
452 void applyAutomaticTearing();
453 void tearLink(
size_t linkIndex);
454 void rebuildFoldPairsFromTriangles();
455 void solveFoldConstraint();
456 void solveSelfCollision();
457 void solveSelfCollisionTriangles();
458 void collideWorld(
float dt);
459 void collideBounds();
461 bool validIndex(
int index)
const;
462 int64_t cellKey(
int cx,
int cy,
int cz)
const;
466 float spacing_ = 0.4f;
467 float originX_ = 0.f, originY_ = 0.f, originZ_ = 0.f;
469 float gravityX_ = 0.f;
470 float gravityY_ = -9.8f;
471 float gravityZ_ = 0.f;
472 float stiffness_ = 0.85f;
473 float stretchCompliance_ = 0.f;
474 float shearCompliance_ = 0.f;
475 float bendCompliance_ = 0.f;
476 float tetherScale_ = 0.f;
477 float tetherCompliance_ = 0.f;
478 float pressure_ = 0.f;
479 float volumeCompliance_ = 0.f;
480 float restVolume_ = 0.f;
481 float volumeLambda_ = 0.f;
482 float damping_ = 0.01f;
484 float particleSize_ = 0.1f;
485 float particleMass_ = 0.1f;
486 bool selfCollision_ =
true;
487 float foldStiffness_ = 0.5f;
488 float maxFoldAngle_ = 120.f * 3.14159265f / 180.f;
489 float collisionFriction_ = 0.2f;
490 float collisionRestitution_ = 0.15f;
491 uint64_t collisionCategoryBits_ = ~uint64_t{0};
492 uint64_t collisionMaskBits_ = ~uint64_t{0};
493 float tearThreshold_ = 0.f;
494 int maxTearsPerStep_ = 1;
495 int tornConstraintCount_ = 0;
497 bool hasBounds_ =
false;
498 float boundX_ = 0.f, boundY_ = 0.f, boundZ_ = 0.f;
499 float boundW_ = 0.f, boundH_ = 0.f, boundD_ = 0.f;
502 float grabX_ = 0.f, grabY_ = 0.f, grabZ_ = 0.f;
503 float forceX_ = 0.f, forceY_ = 0.f, forceZ_ = 0.f;
504 float windVelocityX_ = 0.f, windVelocityY_ = 0.f, windVelocityZ_ = 0.f;
505 float airDensity_ = 1.225f;
506 float dragCoefficient_ = 0.f;
507 float liftCoefficient_ = 0.f;
508 float interactX_ = 0.f, interactY_ = 0.f, interactZ_ = 0.f;
509 float interactRadius_ = 0.f;
510 float interactStrength_ = 0.f;
514 float colorR_ = 0.75f, colorG_ = 0.82f, colorB_ = 0.95f, colorA_ = 1.f;
516 bool destroyed_ =
false;
517 SimulationObservation observation_;
519 std::vector<Particle> particles_;
520 std::vector<Particle> restParticles_;
521 std::vector<Link> links_;
522 std::vector<Tri> triangles_;
523 std::vector<FoldPair> foldPairs_;
524 std::vector<Tether> tethers_;
525 std::vector<SkinConstraint> skinConstraints_;
526 std::vector<Attachment> attachments_;
527 std::unordered_set<int64_t> linkKeys_;
528 std::unordered_map<int64_t, std::vector<int>> hash_;
530 graphics::Mesh* mesh_ =
nullptr;
531 int meshVertexCount_ = 0;
532 int meshIndexCount_ = 0;