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

Update MeshHelper to fix #8140 #8307

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from

Conversation

grasshopperhamburger
Copy link

Hello,

I've modified MeshHelper to address the issue mentioned in #8140 .
Based on my understanding, the values in each of the VertexContent "Channels" should be indexed to match their corresponding vertex in the "Positions" index.
The previous code incorrectly indexed them using the vertex positions in the parent Mesh collection.

fixed CalculateNormal indexing
@SimonDarksideJ
Copy link
Contributor

@grasshopperhamburger to ensure the resolution is correcting an issue, can you also please add a Unit test to validate what this PR is resolving please

@grasshopperhamburger
Copy link
Author

@SimonDarksideJ
i'm sorry i should have mentioned that the associated issue in question #8140 has already an associated Test in MeshHelperTest , "TestMergePositionsMultipleGeometries". The issue itself is in fact the failing test.
My PR addresses the specific index out of bound exception and now all the Tests are green.
Should i add a more specific Unit Test with a narrower scope?

@SimonDarksideJ
Copy link
Contributor

If it helps prove the case better then yes, as it then protects against such changes in the future. Ideally, make that a separate pr, so the test shows as failing, then retest with these changes to prove it now passes.

@@ -95,9 +95,9 @@ public static void CalculateNormals(GeometryContent geom, bool overwriteExisting
// by Shuangshuang Jin, Robert R. Lewis, David West.
//

normals[positionIndices[ia]] += faceNormal;
Copy link
Member

Choose a reason for hiding this comment

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

@grasshopperhamburger what makes you say that positionIndices is the parent positions?

If that is correct then certainly this code was wrong and this is the right fix.

@@ -95,9 +95,9 @@ public static void CalculateNormals(GeometryContent geom, bool overwriteExisting
// by Shuangshuang Jin, Robert R. Lewis, David West.
Copy link
Member

Choose a reason for hiding this comment

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

@github managed to screw up code review again.

@grasshopperhamburger If you look up at line 65:

var normals = new Vector3[positionIndices.Count];

Is this allocation wrong then? We should have the same amount of normals as we do positions in the current mesh.

Choose a reason for hiding this comment

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

Sorry for the delay.
It is not wrong, every channel has a length equal to the positionIndices (and VertexContent.Positions) collection (for a given geometry), which in turn is less or equal the actual positions (stored in MeshContent.Positions) once the mesh is finalized. It may be less (such as the case in the failing test) when between two geometries (same mesh) there is no full overlap of used vertices

@tomspilman
Copy link
Member

So yeah i don't remember this code well enough to say if this is right or not @SimonDarksideJ .

A unit test would be best to verify the old code was broken and the new code works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants