Skip to content

Instantly share code, notes, and snippets.

@Vatyx
Created October 25, 2016 16:31
Show Gist options
  • Save Vatyx/6224c73b1da308b2c1f934cf0964c1ba to your computer and use it in GitHub Desktop.
Save Vatyx/6224c73b1da308b2c1f934cf0964c1ba to your computer and use it in GitHub Desktop.
void flapOptimization()
{
vector<unsigned int> vertexCount(g.halfmesh.totalVerts);
vector<HE_Face*> faceTracker(g.halfmesh.totalVerts);
map<unsigned int, HE_Face*> flaps;
for(unsigned int i = 0; i < g.halfmesh.totalFaces; i++)
{
for(unsigned int j = 0; j < 3; j++)
{
auto test = g.halfmesh.faceData[i].vi.v[j];
vertexCount[g.halfmesh.faceData[i].vi.v[j]]++;
faceTracker[g.halfmesh.faceData[i].vi.v[j]] = &g.halfmesh.faceData[i];
}
}
for(unsigned int i = 0; i < vertexCount.size(); i++)
{
if(vertexCount[i] == 1)
{
HE_Vertex p1;
HE_Vertex p2;
HE_Vertex p3;
if(i == faceTracker[i]->vi[0])
{
p3 = g.halfmesh.vertexData[i];
p1 = g.halfmesh.vertexData[faceTracker[i]->vi[1]];
p2 = g.halfmesh.vertexData[faceTracker[i]->vi[2]];
}
else if(i == faceTracker[i]->vi[1])
{
p3 = g.halfmesh.vertexData[i];
p1 = g.halfmesh.vertexData[faceTracker[i]->vi[0]];
p2 = g.halfmesh.vertexData[faceTracker[i]->vi[2]];
}
else
{
p3 = g.halfmesh.vertexData[i];
p1 = g.halfmesh.vertexData[faceTracker[i]->vi[0]];
p2 = g.halfmesh.vertexData[faceTracker[i]->vi[1]];
}
auto alpha = ( (p3.pos - p1.pos).dot(p2.pos - p1.pos) ) / (p2.pos - p1.pos).length();
auto L = (p3.pos - ((p3.pos - p1.pos).dot(p2.pos - p1.pos) / (p2.pos - p1.pos).dot(p2.pos - p1.pos)) * (p2.pos - p1.pos)).length();
auto p2p1perp = p2.uvpos - p1.uvpos;
auto temp = p2p1perp[0];
p2p1perp[0] = -p2p1perp[1];
p2p1perp[1] = temp;
p3.uvpos = (1 - alpha)*p1.uvpos + alpha * p2.uvpos + (p2p1perp * L / (p2.uvpos - p1.uvpos).length());
g.halfmesh.vertexData[i] = p3;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment