void cloth::SwFactory::extractCollisionData(const Cloth& cloth, Range<PxVec4> spheres, Range<uint32_t> capsules, Range<PxVec4> planes, Range<uint32_t> convexes, Range<PxVec3> triangles) const { PX_ASSERT(&cloth.getFactory() == this); const SwCloth& swCloth = static_cast<const SwClothImpl&>(cloth).mCloth; PX_ASSERT(spheres.empty() || spheres.size() == swCloth.mStartCollisionSpheres.size()); PX_ASSERT(capsules.empty() || capsules.size() == swCloth.mCapsuleIndices.size() * 2); PX_ASSERT(planes.empty() || planes.size() == swCloth.mStartCollisionPlanes.size()); PX_ASSERT(convexes.empty() || convexes.size() == swCloth.mConvexMasks.size()); PX_ASSERT(triangles.empty() || triangles.size() == swCloth.mStartCollisionTriangles.size()); if(!swCloth.mStartCollisionSpheres.empty() && !spheres.empty()) memcpy(spheres.begin(), &swCloth.mStartCollisionSpheres.front(), swCloth.mStartCollisionSpheres.size() * sizeof(PxVec4)); if(!swCloth.mCapsuleIndices.empty() && !capsules.empty()) memcpy(capsules.begin(), &swCloth.mCapsuleIndices.front(), swCloth.mCapsuleIndices.size() * sizeof(IndexPair)); if(!swCloth.mStartCollisionPlanes.empty() && !planes.empty()) memcpy(planes.begin(), &swCloth.mStartCollisionPlanes.front(), swCloth.mStartCollisionPlanes.size() * sizeof(PxVec4)); if(!swCloth.mConvexMasks.empty() && !convexes.empty()) memcpy(convexes.begin(), &swCloth.mConvexMasks.front(), swCloth.mConvexMasks.size() * sizeof(uint32_t)); if(!swCloth.mStartCollisionTriangles.empty() && !triangles.empty()) memcpy(triangles.begin(), &swCloth.mStartCollisionTriangles.front(), swCloth.mStartCollisionTriangles.size() * sizeof(PxVec3)); }
void cloth::SwFactory::extractParticleAccelerations(const Cloth& cloth, Range<PxVec4> destAccelerations) const { PX_ASSERT(&cloth.getFactory() == this); const SwCloth& swCloth = static_cast<const SwClothImpl&>(cloth).mCloth; if(!swCloth.mParticleAccelerations.empty()) { // make sure dest array is big enough PX_ASSERT(destAccelerations.size() == swCloth.mParticleAccelerations.size()); memcpy(destAccelerations.begin(), &swCloth.mParticleAccelerations.front(), swCloth.mParticleAccelerations.size() * sizeof(PxVec4)); } }
void cloth::SwFactory::extractVirtualParticles(const Cloth& cloth, Range<uint32_t[4]> indices, Range<PxVec3> weights) const { PX_ASSERT(this == &cloth.getFactory()); const SwCloth& swCloth = static_cast<const SwClothImpl&>(cloth).mCloth; uint32_t numIndices = cloth.getNumVirtualParticles(); uint32_t numWeights = cloth.getNumVirtualParticleWeights(); PX_ASSERT(indices.size() == numIndices || indices.empty()); PX_ASSERT(weights.size() == numWeights || weights.empty()); if ( weights.size() == numWeights ) { PxVec3* wDestIt = reinterpret_cast<PxVec3*>(weights.begin()); // convert weights from vec4 to vec3 cloth::Vec4fAlignedVector::ConstIterator wIt = swCloth.mVirtualParticleWeights.begin(); cloth::Vec4fAlignedVector::ConstIterator wEnd= wIt + numWeights; for (; wIt != wEnd; ++wIt, ++wDestIt) *wDestIt = PxVec3(wIt->x, wIt->y, wIt->z); PX_ASSERT(wDestIt == weights.end()); } if ( indices.size() == numIndices ) { // convert indices Vec4u* iDestIt = reinterpret_cast<Vec4u*>(indices.begin()); Vector<Vec4us>::Type::ConstIterator iIt = swCloth.mVirtualParticleIndices.begin(); Vector<Vec4us>::Type::ConstIterator iEnd = swCloth.mVirtualParticleIndices.end(); uint32_t numParticles = uint32_t(swCloth.mCurParticles.size()); for (; iIt != iEnd; ++iIt) { // skip dummy indices if (iIt->x < numParticles) // byte offset to element index *iDestIt++ = Vec4u(*iIt); } PX_ASSERT(&array(*iDestIt) == indices.end()); } }
void cloth::SwFactory::extractSeparationConstraints(const Cloth& cloth, Range<PxVec4> destConstraints) const { PX_ASSERT(&cloth.getFactory() == this); const SwCloth& swCloth = static_cast<const SwClothImpl&>(cloth).mCloth; Vec4fAlignedVector const& srcConstraints = !swCloth.mSeparationConstraints.mTarget.empty() ? swCloth.mSeparationConstraints.mTarget : swCloth.mSeparationConstraints.mStart; if(!srcConstraints.empty()) { // make sure dest array is big enough PX_ASSERT(destConstraints.size() == srcConstraints.size()); memcpy(destConstraints.begin(), &srcConstraints.front(), srcConstraints.size() * sizeof(PxVec4)); } }