载入中...
搜索中...
未找到
ClothModule.cpp
浏览该文件的文档.
2
3#include "gpgpu/Gpgpu.h"
8
9#include <simplesquirrel/simplesquirrel.hpp>
10
11#include <functional>
12
13namespace eve::cloth {
14
16
17eve::physics::Cloth* Cloth::newCloth(int cols, int rows, float spacing, float originX, float originY) {
18 return new eve::physics::Cloth(cols, rows, spacing, originX, originY);
19}
20
21eve::physics::Cloth3D* Cloth::newCloth3D(int cols, int rows, float spacing, float originX, float originY,
22 float originZ) {
23 return new eve::physics::Cloth3D(cols, rows, spacing, originX, originY, originZ);
24}
25
26std::unique_ptr<eve::physics::Cloth3D> Cloth::createCloth(const eve::physics::ClothModel& model) {
27 return std::make_unique<eve::physics::Cloth3D>(model);
28}
29
30eve::physics::ClothGPU* Cloth::newClothGPU(int cols, int rows, float spacing, float originX, float originY) {
31 auto* gpgpu = eve::ModuleManager::getInstance<eve::gpgpu::Gpgpu>("Gpgpu");
32 if (!gpgpu) gpgpu = eve::gpgpu::Gpgpu::create();
33 return new eve::physics::ClothGPU(gpgpu, cols, rows, spacing, originX, originY);
34}
35
36void Cloth::expose(ssq::Table& table) {
37 auto module = table.addClass(name, Cloth::create, false);
38 expose(module);
39
41 using Cloth3D = eve::physics::Cloth3D;
42 using ClothGPU = eve::physics::ClothGPU;
43
44 auto cloth =
45 table.addClass<Cloth>("Cloth2D", std::function<Cloth*()>([]() -> Cloth* { return nullptr; }), true);
46 cloth.addFunc("update", &Cloth::update);
47 cloth.addFunc("setGravity", &Cloth::setGravity);
48 cloth.addFunc("getGravityX", &Cloth::getGravityX);
49 cloth.addFunc("getGravityY", &Cloth::getGravityY);
50 cloth.addFunc("setStiffness", &Cloth::setStiffness);
51 cloth.addFunc("getStiffness", &Cloth::getStiffness);
52 cloth.addFunc("setIterations", &Cloth::setIterations);
53 cloth.addFunc("getIterations", &Cloth::getIterations);
54 cloth.addFunc("setDamping", &Cloth::setDamping);
55 cloth.addFunc("getDamping", &Cloth::getDamping);
56 cloth.addFunc("setParticleSize", &Cloth::setParticleSize);
57 cloth.addFunc("getParticleSize", &Cloth::getParticleSize);
58 cloth.addFunc("setParticleMass", &Cloth::setParticleMass);
59 cloth.addFunc("getParticleMass", &Cloth::getParticleMass);
60 cloth.addFunc("setSelfCollision", &Cloth::setSelfCollision);
61 cloth.addFunc("getSelfCollision", &Cloth::getSelfCollision);
62 cloth.addFunc("setFoldStiffness", &Cloth::setFoldStiffness);
63 cloth.addFunc("getFoldStiffness", &Cloth::getFoldStiffness);
64 cloth.addFunc("setMaxFoldAngle", &Cloth::setMaxFoldAngle);
65 cloth.addFunc("getMaxFoldAngle", &Cloth::getMaxFoldAngle);
66 cloth.addFunc("setBounds", &Cloth::setBounds);
67 cloth.addFunc("clearBounds", &Cloth::clearBounds);
68 cloth.addFunc("pin", &Cloth::pin);
69 cloth.addFunc("unpin", &Cloth::unpin);
70 cloth.addFunc("pinTopRow", &Cloth::pinTopRow);
71 cloth.addFunc("isPinned", &Cloth::isPinned);
72 cloth.addFunc("grabAt", &Cloth::grabAt);
73 cloth.addFunc("moveGrab", &Cloth::moveGrab);
74 cloth.addFunc("releaseGrab", &Cloth::releaseGrab);
75 cloth.addFunc("isGrabbing", &Cloth::isGrabbing);
76 cloth.addFunc("getGrabIndex", &Cloth::getGrabIndex);
77 cloth.addFunc("applyForce", &Cloth::applyForce);
78 cloth.addFunc("interactAt", &Cloth::interactAt);
79 cloth.addFunc("setCollideWorld", &Cloth::setCollideWorld);
80 cloth.addFunc("getCollideWorld", &Cloth::getCollideWorld);
81 cloth.addFunc("reset", &Cloth::reset);
82 cloth.addFunc("setColor", &Cloth::setColor);
83 cloth.addFunc("draw", &Cloth::draw);
84 cloth.addFunc("getCols", &Cloth::getCols);
85 cloth.addFunc("getRows", &Cloth::getRows);
86 cloth.addFunc("getParticleCount", &Cloth::getParticleCount);
87 cloth.addFunc("getParticleX", &Cloth::getParticleX);
88 cloth.addFunc("getParticleY", &Cloth::getParticleY);
89 cloth.addFunc("setParticlePosition", &Cloth::setParticlePosition);
90 cloth.addFunc("getSpacing", &Cloth::getSpacing);
91 cloth.addFunc("destroy", &Cloth::destroy);
92
93 auto cloth3 =
94 table.addClass<Cloth3D>("Cloth3D", std::function<Cloth3D*()>([]() -> Cloth3D* { return nullptr; }), true);
95 cloth3.addFunc("update", &Cloth3D::update);
96 cloth3.addFunc("setGravity", &Cloth3D::setGravity);
97 cloth3.addFunc("getGravityX", &Cloth3D::getGravityX);
98 cloth3.addFunc("getGravityY", &Cloth3D::getGravityY);
99 cloth3.addFunc("getGravityZ", &Cloth3D::getGravityZ);
100 cloth3.addFunc("setStiffness", &Cloth3D::setStiffness);
101 cloth3.addFunc("getStiffness", &Cloth3D::getStiffness);
102 cloth3.addFunc("setStretchCompliance", &Cloth3D::setStretchCompliance);
103 cloth3.addFunc("getStretchCompliance", &Cloth3D::getStretchCompliance);
104 cloth3.addFunc("setShearCompliance", &Cloth3D::setShearCompliance);
105 cloth3.addFunc("getShearCompliance", &Cloth3D::getShearCompliance);
106 cloth3.addFunc("setBendCompliance", &Cloth3D::setBendCompliance);
107 cloth3.addFunc("getBendCompliance", &Cloth3D::getBendCompliance);
108 cloth3.addFunc("setTetherScale", &Cloth3D::setTetherScale);
109 cloth3.addFunc("getTetherScale", &Cloth3D::getTetherScale);
110 cloth3.addFunc("setTetherCompliance", &Cloth3D::setTetherCompliance);
111 cloth3.addFunc("getTetherCompliance", &Cloth3D::getTetherCompliance);
112 cloth3.addFunc("setPressure", &Cloth3D::setPressure);
113 cloth3.addFunc("getPressure", &Cloth3D::getPressure);
114 cloth3.addFunc("getBackendName", &Cloth3D::getBackendName);
115 cloth3.addFunc("supportsFeature", &Cloth3D::supportsFeature);
116 cloth3.addFunc("setVolumeCompliance", &Cloth3D::setVolumeCompliance);
117 cloth3.addFunc("getVolumeCompliance", &Cloth3D::getVolumeCompliance);
118 cloth3.addFunc("getCurrentVolume", &Cloth3D::getCurrentVolume);
119 cloth3.addFunc("setIterations", &Cloth3D::setIterations);
120 cloth3.addFunc("getIterations", &Cloth3D::getIterations);
121 cloth3.addFunc("setDamping", &Cloth3D::setDamping);
122 cloth3.addFunc("getDamping", &Cloth3D::getDamping);
123 cloth3.addFunc("setParticleSize", &Cloth3D::setParticleSize);
124 cloth3.addFunc("getParticleSize", &Cloth3D::getParticleSize);
125 cloth3.addFunc("setParticleMass", &Cloth3D::setParticleMass);
126 cloth3.addFunc("getParticleMass", &Cloth3D::getParticleMass);
127 cloth3.addFunc("setSelfCollision", &Cloth3D::setSelfCollision);
128 cloth3.addFunc("getSelfCollision", &Cloth3D::getSelfCollision);
129 cloth3.addFunc("setFoldStiffness", &Cloth3D::setFoldStiffness);
130 cloth3.addFunc("getFoldStiffness", &Cloth3D::getFoldStiffness);
131 cloth3.addFunc("setMaxFoldAngle", &Cloth3D::setMaxFoldAngle);
132 cloth3.addFunc("getMaxFoldAngle", &Cloth3D::getMaxFoldAngle);
133 cloth3.addFunc("setBounds", &Cloth3D::setBounds);
134 cloth3.addFunc("clearBounds", &Cloth3D::clearBounds);
135 cloth3.addFunc("setCollisionMaterial", &Cloth3D::setCollisionMaterial);
136 cloth3.addFunc("getCollisionFriction", &Cloth3D::getCollisionFriction);
137 cloth3.addFunc("getCollisionRestitution", &Cloth3D::getCollisionRestitution);
138 cloth3.addFunc("setCollisionFilter", &Cloth3D::setCollisionFilter);
139 cloth3.addFunc("getCollisionCategoryBits", &Cloth3D::getCollisionCategoryBits);
140 cloth3.addFunc("getCollisionMaskBits", &Cloth3D::getCollisionMaskBits);
141 cloth3.addFunc("setTearThreshold", &Cloth3D::setTearThreshold);
142 cloth3.addFunc("getTearThreshold", &Cloth3D::getTearThreshold);
143 cloth3.addFunc("setMaxTearsPerStep", &Cloth3D::setMaxTearsPerStep);
144 cloth3.addFunc("getMaxTearsPerStep", &Cloth3D::getMaxTearsPerStep);
145 cloth3.addFunc("tearConstraint", &Cloth3D::tearConstraint);
146 cloth3.addFunc("getTornConstraintCount", &Cloth3D::getTornConstraintCount);
147 cloth3.addFunc("pin", &Cloth3D::pin);
148 cloth3.addFunc("unpin", &Cloth3D::unpin);
149 cloth3.addFunc("pinTopRow", &Cloth3D::pinTopRow);
150 cloth3.addFunc("isPinned", &Cloth3D::isPinned);
151 cloth3.addFunc("setParticleInverseMass", &Cloth3D::setParticleInverseMass);
152 cloth3.addFunc("getParticleInverseMass", &Cloth3D::getParticleInverseMass);
153 cloth3.addFunc("setSkinConstraint", &Cloth3D::setSkinConstraint);
154 cloth3.addFunc("updateSkinReference", &Cloth3D::updateSkinReference);
155 cloth3.addFunc("clearSkinConstraint", &Cloth3D::clearSkinConstraint);
156 cloth3.addFunc("hasSkinConstraint", &Cloth3D::hasSkinConstraint);
157 cloth3.addFunc("attachParticle", &Cloth3D::attachParticle);
158 cloth3.addFunc("updateAttachment", &Cloth3D::updateAttachment);
159 cloth3.addFunc("detachParticle", &Cloth3D::detachParticle);
160 cloth3.addFunc("isAttached", &Cloth3D::isAttached);
161 cloth3.addFunc("grabAt", &Cloth3D::grabAt);
162 cloth3.addFunc("moveGrab", &Cloth3D::moveGrab);
163 cloth3.addFunc("releaseGrab", &Cloth3D::releaseGrab);
164 cloth3.addFunc("isGrabbing", &Cloth3D::isGrabbing);
165 cloth3.addFunc("getGrabIndex", &Cloth3D::getGrabIndex);
166 cloth3.addFunc("applyForce", &Cloth3D::applyForce);
167 cloth3.addFunc("setWindVelocity", &Cloth3D::setWindVelocity);
168 cloth3.addFunc("getWindVelocityX", &Cloth3D::getWindVelocityX);
169 cloth3.addFunc("getWindVelocityY", &Cloth3D::getWindVelocityY);
170 cloth3.addFunc("getWindVelocityZ", &Cloth3D::getWindVelocityZ);
171 cloth3.addFunc("setAerodynamics", &Cloth3D::setAerodynamics);
172 cloth3.addFunc("getAirDensity", &Cloth3D::getAirDensity);
173 cloth3.addFunc("getDragCoefficient", &Cloth3D::getDragCoefficient);
174 cloth3.addFunc("getLiftCoefficient", &Cloth3D::getLiftCoefficient);
175 cloth3.addFunc("interactAt", &Cloth3D::interactAt);
176 cloth3.addFunc("setCollideWorld", &Cloth3D::setCollideWorld);
177 cloth3.addFunc("getCollideWorld", &Cloth3D::getCollideWorld);
178 cloth3.addFunc("reset", &Cloth3D::reset);
179 cloth3.addFunc("setColor", &Cloth3D::setColor);
180 cloth3.addFunc("draw", &Cloth3D::draw);
181 cloth3.addFunc("getCols", &Cloth3D::getCols);
182 cloth3.addFunc("getRows", &Cloth3D::getRows);
183 cloth3.addFunc("getParticleCount", &Cloth3D::getParticleCount);
184 cloth3.addFunc("getTriangleCount", &Cloth3D::getTriangleCount);
185 cloth3.addFunc("getDistanceConstraintCount", &Cloth3D::getDistanceConstraintCount);
186 cloth3.addFunc("getTetherConstraintCount", &Cloth3D::getTetherConstraintCount);
187 cloth3.addFunc("getSkinConstraintCount", &Cloth3D::getSkinConstraintCount);
188 cloth3.addFunc("getAttachmentCount", &Cloth3D::getAttachmentCount);
189 cloth3.addFunc("getParticleX", &Cloth3D::getParticleX);
190 cloth3.addFunc("getParticleY", &Cloth3D::getParticleY);
191 cloth3.addFunc("getParticleZ", &Cloth3D::getParticleZ);
192 cloth3.addFunc("setParticlePosition", &Cloth3D::setParticlePosition);
193 cloth3.addFunc("getSpacing", &Cloth3D::getSpacing);
194 cloth3.addFunc("getOriginX", &Cloth3D::getOriginX);
195 cloth3.addFunc("getOriginY", &Cloth3D::getOriginY);
196 cloth3.addFunc("getOriginZ", &Cloth3D::getOriginZ);
197 cloth3.addFunc("destroy", &Cloth3D::destroy);
198
199 auto clothGpu =
200 table.addClass<ClothGPU>("ClothGPU", std::function<ClothGPU*()>([]() -> ClothGPU* { return nullptr; }), true);
201 clothGpu.addFunc("update", &ClothGPU::update);
202 clothGpu.addFunc("getBackendName", &ClothGPU::getBackendName);
203 clothGpu.addFunc("supportsFeature", &ClothGPU::supportsFeature);
204 clothGpu.addFunc("setGravity", &ClothGPU::setGravity);
205 clothGpu.addFunc("getGravityX", &ClothGPU::getGravityX);
206 clothGpu.addFunc("getGravityY", &ClothGPU::getGravityY);
207 clothGpu.addFunc("setStiffness", &ClothGPU::setStiffness);
208 clothGpu.addFunc("getStiffness", &ClothGPU::getStiffness);
209 clothGpu.addFunc("setIterations", &ClothGPU::setIterations);
210 clothGpu.addFunc("getIterations", &ClothGPU::getIterations);
211 clothGpu.addFunc("setDamping", &ClothGPU::setDamping);
212 clothGpu.addFunc("getDamping", &ClothGPU::getDamping);
213 clothGpu.addFunc("setParticleSize", &ClothGPU::setParticleSize);
214 clothGpu.addFunc("getParticleSize", &ClothGPU::getParticleSize);
215 clothGpu.addFunc("setSelfCollision", &ClothGPU::setSelfCollision);
216 clothGpu.addFunc("getSelfCollision", &ClothGPU::getSelfCollision);
217 clothGpu.addFunc("setBounds", &ClothGPU::setBounds);
218 clothGpu.addFunc("clearBounds", &ClothGPU::clearBounds);
219 clothGpu.addFunc("pin", &ClothGPU::pin);
220 clothGpu.addFunc("unpin", &ClothGPU::unpin);
221 clothGpu.addFunc("pinTopRow", &ClothGPU::pinTopRow);
222 clothGpu.addFunc("isPinned", &ClothGPU::isPinned);
223 clothGpu.addFunc("applyForce", &ClothGPU::applyForce);
224 clothGpu.addFunc("interactAt", &ClothGPU::interactAt);
225 clothGpu.addFunc("setColor", &ClothGPU::setColor);
226 clothGpu.addFunc("draw", &ClothGPU::draw);
227 clothGpu.addFunc("getCols", &ClothGPU::getCols);
228 clothGpu.addFunc("getRows", &ClothGPU::getRows);
229 clothGpu.addFunc("getParticleCount", &ClothGPU::getParticleCount);
230 clothGpu.addFunc("getParticleX", &ClothGPU::getParticleX);
231 clothGpu.addFunc("getParticleY", &ClothGPU::getParticleY);
232 clothGpu.addFunc("getSpacing", &ClothGPU::getSpacing);
233 clothGpu.addFunc("getOriginX", &ClothGPU::getOriginX);
234 clothGpu.addFunc("getOriginY", &ClothGPU::getOriginY);
235 clothGpu.addFunc("reset", &ClothGPU::reset);
236 clothGpu.addFunc("destroy", &ClothGPU::destroy);
237}
238
239void Cloth::expose(ssq::Class& cls) {
240 cls.addFunc("newCloth", &eve::cloth::Cloth::newCloth);
241 cls.addFunc("newCloth3D", &eve::cloth::Cloth::newCloth3D);
242 cls.addFunc("newClothGPU", &eve::cloth::Cloth::newClothGPU);
243}
244
245} // namespace eve::cloth
HSQOBJECT cls
Definition ECS.cpp:21
int rows
int cols
#define Module_IMPL(ModuleName, newExpr)
Definition Module.h:26
glm::mat4 model
int spacing
Script-facing owner and factory for 2D, 3D, and GPU cloth runtimes.
Definition ClothModule.h:17
eve::physics::Cloth * newCloth(int cols, int rows, float spacing, float originX, float originY)
Create a caller-owned 2D cloth grid in pixel space.
eve::physics::Cloth3D * newCloth3D(int cols, int rows, float spacing, float originX, float originY, float originZ)
Create a caller-owned 3D cloth grid in meter space.
std::unique_ptr< eve::physics::Cloth3D > createCloth(const eve::physics::ClothModel &model)
Create an independent 3D runtime by copying a validated model.
eve::physics::ClothGPU * newClothGPU(int cols, int rows, float spacing, float originX, float originY)
Create a caller-owned Vulkan-compute 2D cloth grid.
Interactive 3D cloth — Verlet particles + distance constraints. Meter space, +Y up,...
Definition Cloth3D.h:32
GPU-accelerated 2D cloth — Verlet integration and distance-constraint relaxation run in a Vulkan comp...
Definition ClothGPU.h:31
Reusable, validated cloth simulation asset.
Definition ClothModel.h:73
Interactive 2D cloth — Verlet particles + distance constraints. Pixel space (same convention as Box2D...
Definition Cloth.h:28
gpgpu::Gpgpu * gpgpu