Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.x] Fix duplicated edges in convex hull generator #52046

Closed

Conversation

pouleyKetchoupp
Copy link
Contributor

@pouleyKetchoupp pouleyKetchoupp commented Aug 24, 2021

All edges where accumulated from all faces, which ended up with double the amount in the final mesh data leading to performance issues in godot physics.

Fix #51909 (regression from #48533)
CC @mortarroad if you would like to review

If this fix is ok I'll make a PR on master tomorrow.

All edges where accumulated from all faces, which ended up with double
the amount in the final mesh data leading to performance issues in godot
physics.
}

ConvexHullComputer ch;
ch.compute(p_points, p_point_count, -1.0, -1.0);

r_mesh.vertices = ch.vertices;
int vertex_count = r_mesh.vertices.size();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could do with a comment here and at the resize at the bottom of the function to explain why this is being done - it is clear in the PR text, but not in the source.

if (face.indices.size() >= 3) {
face.plane = Plane(r_mesh.vertices[face.indices[0]], r_mesh.vertices[face.indices[1]], r_mesh.vertices[face.indices[2]]);
} else {
WARN_PRINT("Too few vertices per face.");
}
}

r_mesh.edges.resize(edge_count);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add comment to explain.

@lawnjelly
Copy link
Member

Looks fine to me, I'd just add a couple of comments to explain what is going on in the source because it isn't immediately clear.

@mortarroad
Copy link
Contributor

Ah, you're of course right. Since this is a half edge data structure, there's a reverse edge for every edge.

Rather than going through a set, you can simply pick one of the two as the canonical edge. (E.g. the one where source_vertex < target_vertex, which will only be true for one of them.)

@mortarroad
Copy link
Contributor

I made a PR with my approach: #52059

@pouleyKetchoupp
Copy link
Contributor Author

Closing in favor of #52059.

@pouleyKetchoupp pouleyKetchoupp deleted the fix-convex-hull-edges-3.x branch August 24, 2021 22:39
@aaronfranke aaronfranke removed this from the 3.4 milestone Oct 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants