feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -541,6 +541,10 @@ void SoftBodySharedSettings::Optimize(OptimizationResults &outResults)
if (group_idx[i] == -1)
bounds.Encapsulate(Vec3(mVertices[i].mPosition));
// If the bounds are invalid, it means that there were no ungrouped vertices
if (!bounds.IsValid())
break;
// Determine longest and shortest axis
Vec3 bounds_size = bounds.GetSize();
uint max_axis = bounds_size.GetHighestComponentIndex();
@ -1029,4 +1033,147 @@ SoftBodySharedSettings::SettingsResult SoftBodySharedSettings::sRestoreWithMater
return result;
}
Ref<SoftBodySharedSettings> SoftBodySharedSettings::sCreateCube(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 cube
auto vertex_index = [inGridSize](uint inX, uint inY, uint inZ)
{
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;
}
JPH_NAMESPACE_END