Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void Mesh::subdivide() {
- for (size_t step = 0; step < subdivSteps; step++) {
- vector<Triangle> newTriangles;
- vector<Vector> newVertices;
- printf("STEP %d: \n", step + 1);
- /// Iterate every triangle and generate 4 new for each of them
- for (auto ¤tT : triangles) {
- printf("START\n");
- /// All the neighbours of the current triangle
- vector<Triangle> neighbours = getNeighbours(currentT);
- /// All the direct adjacent vertices of each point from the triangle
- vector<vector<Vector>> adjacents(3);
- /// All of the neighbours with a common side with the current triangle
- Triangle commonSideNeighbours[3];
- /// Collect all the edgepoints in this array
- Vector edgePoints[3];
- /// Collect all the vertexpoints in this array
- Vector vertexPoints[3];
- /// Compute the Vector Points
- computeVertexPoints(neighbours, currentT, commonSideNeighbours,
- adjacents);
- /// Compute the Edge Points
- computeEdgePoints(currentT, commonSideNeighbours, edgePoints);
- /// Add the new Points
- size_t newVSIZE = newVertices.size();;
- size_t vertexPointsIndices[3];
- size_t edgePointsIndices[3];
- Vector vertexPoint, edgePoint;
- int foundIndex;
- for (size_t j = 0; j < 3; j++) {
- vertexPoint = getVertexPoint(vertices[currentT.v[j]], adjacents[j]);
- foundIndex = memberOf(newVertices, vertexPoint);
- if (foundIndex == -1) {
- newVertices.push_back(vertexPoint);
- vertexPointsIndices[j] = newVSIZE;
- newVSIZE++;
- }
- else {
- vertexPointsIndices[j] = foundIndex;
- }
- // printf("V: %f, %f, %f\n", vertexPoint.x, vertexPoint.y,
- // vertexPoint.z);
- }
- printf("\n");
- for (size_t j = 0; j < 3; j++) {
- foundIndex = memberOf(newVertices, edgePoints[j]);
- if (foundIndex == -1) {
- newVertices.push_back(edgePoints[j]);
- edgePointsIndices[j] = newVSIZE;
- newVSIZE++;;
- }
- else {
- edgePointsIndices[j] = foundIndex;
- }
- }
- addNewTriangles(newVertices, newTriangles, vertexPointsIndices, edgePointsIndices);
- printf("END\n\n\n");
- }
- // Change the current mesh's Ts, Vs, uvs and normals with the new one
- triangles = newTriangles;
- vertices = newVertices;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement