|
@@ -35,21 +35,6 @@ JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(SoftBodySharedSettings::Edge)
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::Edge, mCompliance)
|
|
|
}
|
|
|
|
|
|
-JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(SoftBodySharedSettings::IsometricBend)
|
|
|
-{
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mVertex)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mCompliance)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ01)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ02)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ03)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ11)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ12)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ13)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ22)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ23)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::IsometricBend, mQ33)
|
|
|
-}
|
|
|
-
|
|
|
JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(SoftBodySharedSettings::DihedralBend)
|
|
|
{
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings::DihedralBend, mVertex)
|
|
@@ -97,7 +82,6 @@ JPH_IMPLEMENT_SERIALIZABLE_NON_VIRTUAL(SoftBodySharedSettings)
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings, mFaces)
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings, mEdgeConstraints)
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings, mEdgeGroupEndIndices)
|
|
|
- JPH_ADD_ATTRIBUTE(SoftBodySharedSettings, mIsometricBendConstraints)
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings, mDihedralBendConstraints)
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings, mVolumeConstraints)
|
|
|
JPH_ADD_ATTRIBUTE(SoftBodySharedSettings, mSkinnedConstraints)
|
|
@@ -211,20 +195,6 @@ void SoftBodySharedSettings::CreateConstraints(const VertexAttributes *inVertexA
|
|
|
add_edge(v_min, v_max, a_min.mBendCompliance, a_max.mBendCompliance);
|
|
|
break;
|
|
|
|
|
|
- case EBendType::Isometric:
|
|
|
- // Test if both opposite vertices are free to move
|
|
|
- if ((mVertices[vopposite0].mInvMass > 0.0f || mVertices[vopposite1].mInvMass > 0.0f)
|
|
|
- && a_min.mBendCompliance < FLT_MAX && a_max.mBendCompliance < FLT_MAX)
|
|
|
- {
|
|
|
- // Get the vertices that form the common edge
|
|
|
- uint32 vedge0 = f0.mVertex[e0.mEdgeIdx % 3];
|
|
|
- uint32 vedge1 = f0.mVertex[(e0.mEdgeIdx + 1) % 3];
|
|
|
-
|
|
|
- // Create a bend constraint
|
|
|
- mIsometricBendConstraints.emplace_back(vedge0, vedge1, vopposite0, vopposite1, 0.5f * (a_min.mBendCompliance + a_max.mBendCompliance));
|
|
|
- }
|
|
|
- break;
|
|
|
-
|
|
|
case EBendType::Dihedral:
|
|
|
// Test if both opposite vertices are free to move
|
|
|
if ((mVertices[vopposite0].mInvMass > 0.0f || mVertices[vopposite1].mInvMass > 0.0f)
|
|
@@ -276,67 +246,8 @@ void SoftBodySharedSettings::CalculateLRALengths()
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-static float sCotangent(Vec3Arg inV1, Vec3Arg inV2)
|
|
|
-{
|
|
|
- float dot = inV1.Dot(inV2);
|
|
|
- float cross = inV1.Cross(inV2).Length();
|
|
|
- return dot / cross;
|
|
|
-}
|
|
|
-
|
|
|
void SoftBodySharedSettings::CalculateBendConstraintConstants()
|
|
|
{
|
|
|
- for (IsometricBend &b : mIsometricBendConstraints)
|
|
|
- {
|
|
|
- // Get positions
|
|
|
- Vec3 x0 = Vec3(mVertices[b.mVertex[0]].mPosition);
|
|
|
- Vec3 x1 = Vec3(mVertices[b.mVertex[1]].mPosition);
|
|
|
- Vec3 x2 = Vec3(mVertices[b.mVertex[2]].mPosition);
|
|
|
- Vec3 x3 = Vec3(mVertices[b.mVertex[3]].mPosition);
|
|
|
-
|
|
|
- /*
|
|
|
- Figure in section 2 of "A Quadratic Bending Model for Inextensible Surfaces"
|
|
|
- x2
|
|
|
- e1/ \e3
|
|
|
- / \
|
|
|
- x0----x1
|
|
|
- \ e0 /
|
|
|
- e2\ /e4
|
|
|
- x3
|
|
|
- */
|
|
|
-
|
|
|
- // Calculate edges
|
|
|
- Vec3 e0 = x1 - x0;
|
|
|
- Vec3 e1 = x2 - x0;
|
|
|
- Vec3 e2 = x3 - x0;
|
|
|
- Vec3 e3 = x2 - x1;
|
|
|
- Vec3 e4 = x3 - x1;
|
|
|
-
|
|
|
- // Calculate cotangents
|
|
|
- float c02 = sCotangent(e0, e2);
|
|
|
- float c03 = sCotangent(-e0, e3);
|
|
|
- float c04 = sCotangent(-e0, e4);
|
|
|
- float c01 = sCotangent(e0, e1);
|
|
|
-
|
|
|
- // 2x area of both triangles
|
|
|
- float two_a0 = e0.Cross(e1).Length();
|
|
|
- float two_a1 = e0.Cross(e2).Length();
|
|
|
-
|
|
|
- // Calculate Q, note that this matrix is symmetric so we don't need to store all elements
|
|
|
- Vec4 k0(c03 + c04, c01 + c02, -c01 - c03, -c02 - c04);
|
|
|
- Mat44 k0_dot_k0_t(k0.GetX() * k0, k0.GetY() * k0, k0.GetZ() * k0, k0.GetW() * k0);
|
|
|
- Mat44 q = (6.0f / (two_a0 + two_a1)) * k0_dot_k0_t;
|
|
|
- // q00 is not used since we set x0 to be the origin
|
|
|
- b.mQ01 = q(0, 1);
|
|
|
- b.mQ02 = q(0, 2);
|
|
|
- b.mQ03 = q(0, 3);
|
|
|
- b.mQ11 = q(1, 1);
|
|
|
- b.mQ12 = q(1, 2);
|
|
|
- b.mQ13 = q(1, 3);
|
|
|
- b.mQ22 = q(2, 2);
|
|
|
- b.mQ23 = q(2, 3);
|
|
|
- b.mQ33 = q(3, 3);
|
|
|
- }
|
|
|
-
|
|
|
for (DihedralBend &b : mDihedralBendConstraints)
|
|
|
{
|
|
|
// Get positions
|
|
@@ -518,7 +429,6 @@ void SoftBodySharedSettings::SaveBinaryState(StreamOut &inStream) const
|
|
|
inStream.Write(mFaces);
|
|
|
inStream.Write(mEdgeConstraints);
|
|
|
inStream.Write(mEdgeGroupEndIndices);
|
|
|
- inStream.Write(mIsometricBendConstraints);
|
|
|
inStream.Write(mDihedralBendConstraints);
|
|
|
inStream.Write(mVolumeConstraints);
|
|
|
inStream.Write(mSkinnedConstraints);
|
|
@@ -539,7 +449,6 @@ void SoftBodySharedSettings::RestoreBinaryState(StreamIn &inStream)
|
|
|
inStream.Read(mFaces);
|
|
|
inStream.Read(mEdgeConstraints);
|
|
|
inStream.Read(mEdgeGroupEndIndices);
|
|
|
- inStream.Read(mIsometricBendConstraints);
|
|
|
inStream.Read(mDihedralBendConstraints);
|
|
|
inStream.Read(mVolumeConstraints);
|
|
|
inStream.Read(mSkinnedConstraints);
|