我在尝试将网格导入我的程序以使用粒子/弹簧系统进行布料模拟物理时遇到了一些问题。我是图形编程的初学者,很抱歉,如果这非常明显并且我只是遗漏了一些东西。我使用 C++ 和 OpenGL,以及 Assimp 来导入模型。我相当确定我计算约束/弹簧和步进每个粒子的代码是正确的,因为我使用生成的网格(使用四边形而不是三角形)对其进行了测试,它看起来不错,但是 idk。
我一直在使用此链接来研究如何实际执行此操作:https ://nccastaff.bournemouth.ac.uk/jmacey/MastersProjects/MSc2010/07LuisPereira/Thesis/LuisPereira_Thesis.pdf
引擎内的样子:https ://www.youtube.com/watch?v=RyAan27wryU
我很确定这是连接/弹簧的问题,因为在大多数情况下,只是平面的进口模型似乎可以正常工作。另一个模型虽然..似乎只是分崩离析。我一直在看这方面的论文,据我所知,一切都应该正常工作,因为我似乎正确地连接了边缘/弯曲弹簧,并且物理方面似乎是从平面上工作的。我这辈子真的想不通!任何提示/帮助将不胜感激!:)
将Mesh加工成Cloth的代码:
// Container to temporarily hold faces while we process springs
std::vector<Face> faces;
// Go through indices and take the ones making a triangle.
// Indices come from assimp, so i think this is the right thing to do to get each face?
for (int i = 0; i < this->indices.size(); i+=3)
{
std::vector<unsigned int> faceIds = { this->indices.at(i), this->indices.at(i + 1), this->indices.at(i + 2) };
Face face;
face.vertexIDs = faceIds;
faces.push_back(face);
}
// Iterate through faces and add constraints when needed.
for (int l = 0; l < faces.size(); l++)
{
// Adding edge springs.
Face temp = faces[l];
makeConstraint(particles.at(temp.vertexIDs[0]), particles.at(temp.vertexIDs[1]));
makeConstraint(particles.at(temp.vertexIDs[0]), particles.at(temp.vertexIDs[2]));
makeConstraint(particles.at(temp.vertexIDs[1]), particles.at(temp.vertexIDs[2]));
// We need to get the bending springs as well, and i've just written a function to do that.
for (int x = 0; x < faces.size(); x++)
{
Face temp2 = faces[x];
if (l != x)
{
verticesShared(temp, temp2);
}
}
}
这是我处理弯曲弹簧的代码:
// Container for any indices the two faces have in common.
std::vector<glm::vec2> traversed;
// Loop through both face's indices, to see if they match eachother.
for (int i = 0; i < a.vertexIDs.size(); i++)
{
for (int k = 0; k < b.vertexIDs.size(); k++)
{
// If we do get a match, we push a vector into the container containing the two indices of the faces so we know which ones are equal.
if (a.vertexIDs.at(i) == b.vertexIDs.at(k))
{
traversed.push_back(glm::vec2(i, k));
}
}
// If we're here, if means we have an edge in common, aka that we have two vertices shared between the two faces.
if (traversed.size() == 2)
{
// Get the adjacent vertices.
int face_a_adj_ind = 3 - ((traversed[0].x) + (traversed[1].x));
int face_b_adj_ind = 3 - ((traversed[0].y) + (traversed[1].y));
// Turn the stored ones from earlier and just get the ACTUAL indices from the face. Indices of indices, eh.
unsigned int adj_1 = a.vertexIDs[face_a_adj_ind];
unsigned int adj_2 = b.vertexIDs[face_b_adj_ind];
// And finally, make a bending spring between the two adjacent particles.
makeConstraint(particles.at(adj_1), particles.at(adj_2));
}
}