|
@@ -67,149 +67,6 @@ Ref<SoftBodySharedSettings> CreateClothWithFixatedCorners(uint inGridSizeX, uint
|
|
|
return CreateCloth(inGridSizeX, inGridSizeZ, inGridSpacing, inv_mass);
|
|
|
}
|
|
|
|
|
|
-Ref<SoftBodySharedSettings> CreateCube(uint inGridSize, float inGridSpacing)
|
|
|
-{
|
|
|
- const Vec3 cOffset = Vec3::sReplicate(-0.5f * inGridSpacing * (inGridSize - 1));
|
|
|
-
|
|
|
- // Create settings
|
|
|
- SoftBodySharedSettings *settings = new SoftBodySharedSettings;
|
|
|
- for (uint z = 0; z < inGridSize; ++z)
|
|
|
- for (uint y = 0; y < inGridSize; ++y)
|
|
|
- for (uint x = 0; x < inGridSize; ++x)
|
|
|
- {
|
|
|
- SoftBodySharedSettings::Vertex v;
|
|
|
- (cOffset + Vec3::sReplicate(inGridSpacing) * Vec3(float(x), float(y), float(z))).StoreFloat3(&v.mPosition);
|
|
|
- settings->mVertices.push_back(v);
|
|
|
- }
|
|
|
-
|
|
|
- // Function to get the vertex index of a point on the cloth
|
|
|
- auto vertex_index = [inGridSize](uint inX, uint inY, uint inZ) -> uint
|
|
|
- {
|
|
|
- return inX + inY * inGridSize + inZ * inGridSize * inGridSize;
|
|
|
- };
|
|
|
-
|
|
|
- // Create edges
|
|
|
- for (uint z = 0; z < inGridSize; ++z)
|
|
|
- for (uint y = 0; y < inGridSize; ++y)
|
|
|
- for (uint x = 0; x < inGridSize; ++x)
|
|
|
- {
|
|
|
- SoftBodySharedSettings::Edge e;
|
|
|
- e.mVertex[0] = vertex_index(x, y, z);
|
|
|
- if (x < inGridSize - 1)
|
|
|
- {
|
|
|
- e.mVertex[1] = vertex_index(x + 1, y, z);
|
|
|
- settings->mEdgeConstraints.push_back(e);
|
|
|
- }
|
|
|
- if (y < inGridSize - 1)
|
|
|
- {
|
|
|
- e.mVertex[1] = vertex_index(x, y + 1, z);
|
|
|
- settings->mEdgeConstraints.push_back(e);
|
|
|
- }
|
|
|
- if (z < inGridSize - 1)
|
|
|
- {
|
|
|
- e.mVertex[1] = vertex_index(x, y, z + 1);
|
|
|
- settings->mEdgeConstraints.push_back(e);
|
|
|
- }
|
|
|
- }
|
|
|
- settings->CalculateEdgeLengths();
|
|
|
-
|
|
|
- // Tetrahedrons to fill a cube
|
|
|
- const int tetra_indices[6][4][3] = {
|
|
|
- { {0, 0, 0}, {0, 1, 1}, {0, 0, 1}, {1, 1, 1} },
|
|
|
- { {0, 0, 0}, {0, 1, 0}, {0, 1, 1}, {1, 1, 1} },
|
|
|
- { {0, 0, 0}, {0, 0, 1}, {1, 0, 1}, {1, 1, 1} },
|
|
|
- { {0, 0, 0}, {1, 0, 1}, {1, 0, 0}, {1, 1, 1} },
|
|
|
- { {0, 0, 0}, {1, 1, 0}, {0, 1, 0}, {1, 1, 1} },
|
|
|
- { {0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {1, 1, 1} }
|
|
|
- };
|
|
|
-
|
|
|
- // Create volume constraints
|
|
|
- for (uint z = 0; z < inGridSize - 1; ++z)
|
|
|
- for (uint y = 0; y < inGridSize - 1; ++y)
|
|
|
- for (uint x = 0; x < inGridSize - 1; ++x)
|
|
|
- for (uint t = 0; t < 6; ++t)
|
|
|
- {
|
|
|
- SoftBodySharedSettings::Volume v;
|
|
|
- for (uint i = 0; i < 4; ++i)
|
|
|
- v.mVertex[i] = vertex_index(x + tetra_indices[t][i][0], y + tetra_indices[t][i][1], z + tetra_indices[t][i][2]);
|
|
|
- settings->mVolumeConstraints.push_back(v);
|
|
|
- }
|
|
|
-
|
|
|
- settings->CalculateVolumeConstraintVolumes();
|
|
|
-
|
|
|
- // Create faces
|
|
|
- for (uint y = 0; y < inGridSize - 1; ++y)
|
|
|
- for (uint x = 0; x < inGridSize - 1; ++x)
|
|
|
- {
|
|
|
- SoftBodySharedSettings::Face f;
|
|
|
-
|
|
|
- // Face 1
|
|
|
- f.mVertex[0] = vertex_index(x, y, 0);
|
|
|
- f.mVertex[1] = vertex_index(x, y + 1, 0);
|
|
|
- f.mVertex[2] = vertex_index(x + 1, y + 1, 0);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- f.mVertex[1] = vertex_index(x + 1, y + 1, 0);
|
|
|
- f.mVertex[2] = vertex_index(x + 1, y, 0);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- // Face 2
|
|
|
- f.mVertex[0] = vertex_index(x, y, inGridSize - 1);
|
|
|
- f.mVertex[1] = vertex_index(x + 1, y + 1, inGridSize - 1);
|
|
|
- f.mVertex[2] = vertex_index(x, y + 1, inGridSize - 1);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- f.mVertex[1] = vertex_index(x + 1, y, inGridSize - 1);
|
|
|
- f.mVertex[2] = vertex_index(x + 1, y + 1, inGridSize - 1);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- // Face 3
|
|
|
- f.mVertex[0] = vertex_index(x, 0, y);
|
|
|
- f.mVertex[1] = vertex_index(x + 1, 0, y + 1);
|
|
|
- f.mVertex[2] = vertex_index(x, 0, y + 1);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- f.mVertex[1] = vertex_index(x + 1, 0, y);
|
|
|
- f.mVertex[2] = vertex_index(x + 1, 0, y + 1);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- // Face 4
|
|
|
- f.mVertex[0] = vertex_index(x, inGridSize - 1, y);
|
|
|
- f.mVertex[1] = vertex_index(x, inGridSize - 1, y + 1);
|
|
|
- f.mVertex[2] = vertex_index(x + 1, inGridSize - 1, y + 1);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- f.mVertex[1] = vertex_index(x + 1, inGridSize - 1, y + 1);
|
|
|
- f.mVertex[2] = vertex_index(x + 1, inGridSize - 1, y);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- // Face 5
|
|
|
- f.mVertex[0] = vertex_index(0, x, y);
|
|
|
- f.mVertex[1] = vertex_index(0, x, y + 1);
|
|
|
- f.mVertex[2] = vertex_index(0, x + 1, y + 1);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- f.mVertex[1] = vertex_index(0, x + 1, y + 1);
|
|
|
- f.mVertex[2] = vertex_index(0, x + 1, y);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- // Face 6
|
|
|
- f.mVertex[0] = vertex_index(inGridSize - 1, x, y);
|
|
|
- f.mVertex[1] = vertex_index(inGridSize - 1, x + 1, y + 1);
|
|
|
- f.mVertex[2] = vertex_index(inGridSize - 1, x, y + 1);
|
|
|
- settings->AddFace(f);
|
|
|
-
|
|
|
- f.mVertex[1] = vertex_index(inGridSize - 1, x + 1, y);
|
|
|
- f.mVertex[2] = vertex_index(inGridSize - 1, x + 1, y + 1);
|
|
|
- settings->AddFace(f);
|
|
|
- }
|
|
|
-
|
|
|
- // Optimize the settings
|
|
|
- settings->Optimize();
|
|
|
-
|
|
|
- return settings;
|
|
|
-}
|
|
|
-
|
|
|
Ref<SoftBodySharedSettings> CreateSphere(float inRadius, uint inNumTheta, uint inNumPhi, SoftBodySharedSettings::EBendType inBendType, const SoftBodySharedSettings::VertexAttributes &inVertexAttributes)
|
|
|
{
|
|
|
// Create settings
|