MCPcopy Create free account
hub / github.com/RenderKit/embree / createClothSheet

Function createClothSheet

tutorials/collide/collide_device.cpp:187–285  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

185}
186
187unsigned int createClothSheet (RTCScene scene)
188{
189 std::unique_ptr<collide2::ClothModel> cloth (new collide2::ClothModel());
190 cloth->x_0_.resize (NX*NZ);
191 cloth->x_.resize (NX*NZ);
192 cloth->x_old_.resize (NX*NZ);
193 cloth->x_last_.resize (NX*NZ);
194 collide2::vec_t nullvec(0.f, 0.f, 0.f);
195 collide2::vec_t gravity(0.f, -9.8f, 0.f);
196 cloth->v_.resize (NX*NZ, nullvec);
197 cloth->a_.resize (NX*NZ, gravity);
198 cloth->m_.resize (NX*NZ, m);
199 cloth->m_inv_.resize (NX*NZ, 1.f / m);
200 cloth->tris_.resize (2*(NX-1)*(NZ-1));
201
202 initializeClothPositions (*cloth);
203
204 // init topology
205 for (size_t i=0; i<NX-1; ++i) {
206 for (size_t j=0; j<NZ-1; ++j) {
207 cloth->tris_[2*(i*(NZ-1)+j)].v0 = i*NZ+j;
208 cloth->tris_[2*(i*(NZ-1)+j)].v1 = i*NZ+j+1;
209 cloth->tris_[2*(i*(NZ-1)+j)].v2 = (i+1)*NZ+j+1;
210
211 cloth->tris_[2*(i*(NZ-1)+j)+1].v0 = (i+1)*NZ+j+1;
212 cloth->tris_[2*(i*(NZ-1)+j)+1].v1 = (i+1)*NZ+j;
213 cloth->tris_[2*(i*(NZ-1)+j)+1].v2 = i*NZ+j;
214 }
215 }
216
217 cloth->k_stretch_ = ks;
218 cloth->k_damp_ = damping;
219
220 // set distance constraints
221 for (size_t vID=0; vID<NX*NZ; ++vID) {
222
223 size_t i = vID/NZ;
224 size_t j = vID%NZ;
225
226 std::vector<size_t> sIDs;
227
228 if (i<NX-1) sIDs.push_back (vID+NZ);
229 if (j<NZ-1) sIDs.push_back (vID+1);
230
231 if (i<NX-1) {
232 if (j<NZ-1) {
233 sIDs.push_back (vID+NZ+1);
234 }
235 }
236
237 if (i>0) {
238 if (j<NZ-1) {
239 sIDs.push_back (vID-NZ+1);
240 }
241 }
242
243 for (auto id : sIDs) {
244 auto c = new collide2::DistanceConstraint ();

Callers 1

device_initFunction · 0.85

Calls 12

initializeClothPositionsFunction · 0.85
rtcAttachGeometryFunction · 0.85
rtcSetGeometryUserDataFunction · 0.85
rtcCommitGeometryFunction · 0.85
rtcReleaseGeometryFunction · 0.85
initConstraintMethod · 0.80
resizeMethod · 0.45
push_backMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected