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

added staticBody test #303

Merged
merged 1 commit into from
Nov 6, 2022
Merged

added staticBody test #303

merged 1 commit into from
Nov 6, 2022

Conversation

Hurleyworks
Copy link

I'm having problems with some static meshes crashing while using ndPolygonSoupBuilder. I tried to reproduce with this Newton test but there is no crash when using this Bunny mesh. Here's the test in case you want to add it to the pile.

@JulioJerez JulioJerez merged commit 0885e01 into MADEAPPS:master Nov 6, 2022
@JulioJerez
Copy link
Contributor

JulioJerez commented Nov 6, 2022

ok, I merged
I made two changes that you might want to check, it may be why you get those problems.

the first changes is line below in function BuildStaticBunny
const ndFloat32* const vertexBegin = verticesBegin + triIndices[j] ;

it should be
const ndFloat32* const vertexBegin = verticesBegin + triIndices[j] * 3;
because vertexBegin is an array of floats, not an array of points.

the second is line
meshBuilder.AddFace(&triangle[0].m_x, sizeof(ndVector), 3, i);

that would work, but imply that each face has a unique material, I doubt that's what you meant, so I changes to this

		ndInt32 materialId = faceMaterialId[i];
		meshBuilder.AddFace(&triangle[0].m_x, sizeof(ndVector), 3, materialId);

faceMaterialId would be a series of ID painted by an artist in an visual authoring tool.

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 6, 2022

it should be
const ndFloat32 const vertexBegin = verticesBegin + triIndices[j] * 3;*
Oops. Thanks for catching that. I have it right in my own code which uses Eigen for linear algebra.

I did have the materialID wrong in my own code and have fixed it. Thanks. Unfortunately it does fix the crashing problems I'm hitting on some but not all meshes.

@JulioJerez
Copy link
Contributor

Where is the crash happening? Does it has a stack trace?

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 6, 2022 via email

@JulioJerez
Copy link
Contributor

ah, that make a lot easy to debug it.
form the video I see that it is no on teh optimization part. so that make simpler.
It seems to happen on the function that compact the vertex array. probably some memory overrun.

assuming is reproducible with the same mesh.
Ther is a debug function that In the pass I use to check the correctness of intermediate meshes.
I just test to make sure still works.

maybe you can do something like this.
after you submit all the faces to the mesh builder and before you call the end function,
you can save the mesh to a ply file.
something like this

	ndPolygonSoupBuilder meshBuilder;
	meshBuilder.Begin();
	meshBuilder.AddFaceIndirect(&floor[0].m_x, sizeof(ndVector), 31, &index[0][0], 3);
	meshBuilder.AddFaceIndirect(&floor[0].m_x, sizeof(ndVector), 31, &index[1][0], 3);

	meshBuilder.SavePLY("xxxx.ply");
	meshBuilder.End(optimized);

them you can send the file to me so that I can debug it. I do not have a loader yet, but I can add that for the debug.
also tha could be useful for showing build to mesh for a file.

before you send the mesh to me, try loading in some viewer,
if you do no have one you can try https://www.meshlab.net/
it is free and very usefull for these kind of stuff

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 6, 2022 via email

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 6, 2022

newton_static_mesh

original_mesh

@Hurleyworks
Copy link
Author

Here's the ply mesh
static_mesh.zip

@JulioJerez
Copy link
Contributor

ok I can see that the input mesh is already wrong.
I should not crash, so I will try to debug that, is the mesh can repro the crash.

but I suspect the reason the mesh is missing face is because
1- I may have double faces.
2-Some triangles are probably too small.

where are you getting the mesh from, can you save as a fbx, so that I can check the original?

@JulioJerez
Copy link
Contributor

I just load the mesh, but I do not get any crash, in debug or release.
did that mesh cause a crash for you?
if so, maybe you can send a fbx file of the original.

@JulioJerez
Copy link
Contributor

JulioJerez commented Nov 6, 2022

ok when loading the mesh in https://www.meshlab.net/
I can definitely see that the mesh has duplicated faces.
mesh lab has an option that shows single of double faces, triangle and cull.
so in cull mode, I should not be able to see the inside of the mesh, but I do in some places like the fins.
the mesh will be problematic, but the loader should not crash.
for me to detect the crash, I will have to see what happen when loading the original mesh.

@JulioJerez
Copy link
Contributor

JulioJerez commented Nov 6, 2022

ok I found the source of the mesh, it is a 3d paint mesh.
the problomen is that the mesh is repeated not only once, but four time.
I exported as an fbx and load it max.
them after deleting all the helper nodes,
what is left is four nodes rending the same mesh.
here is an image

image

I selected the node and translated them to see if was different. but is just repeat the same mesh for time
I stop using mesh form 3dpaint, because of that reason, there are really dirty, in fact some I can't even load in Max.

you can still load mesh like that but you have to do some authoring like selecting a node that you want to use for collision.

@JulioJerez
Copy link
Contributor

JulioJerez commented Nov 6, 2022

ah I see what is going on, the author of the mesh generated four LOD
image

that's something people do in video games and cinematics.
however, it is bad for physics, because my guess is that those are automatic LOD produced for smooth
interpolation, which means the vertex is the same, but the triangles are different so at some point the will be many identical triangles, and that is as problematic as double faces,
you will have to select one node and use the face of that node for collision.
maybe the mid res.

@Hurleyworks
Copy link
Author

I have the mesh in glTF format. I think I probably got it from Sketchfab
https://sketchfab.com/

They have a lot of models that can be downloaded in many formats, including fbx. Let me see if I can find another model that crashes.

@Hurleyworks
Copy link
Author

Okay, here's one that crashes when I load the glTF version. It also has a .fbx version that you can download
https://sketchfab.com/3d-models/bastard-sword-lowpoly-46e8b2fc85904759b26b6b9ee4bbcb96

@Hurleyworks
Copy link
Author

Here's the ply version saved from ndPolygonSoupBuilder. When I load it in my viewer it looks fine but crashes in Newton
sword.zip

@JulioJerez
Copy link
Contributor

ther sword.zip I just pasted in teh new sandbox, like this

	ndPolygonSoupBuilder meshBuilder;
	meshBuilder.Begin();
	meshBuilder.AddFaceIndirect(&floor[0].m_x, sizeof(ndVector), 31, &index[0][0], 3);
	meshBuilder.AddFaceIndirect(&floor[0].m_x, sizeof(ndVector), 31, &index[1][0], 3);
	//meshBuilder.LoadPLY("static_mesh.ply");
	meshBuilder.LoadPLY("sword.ply");
	meshBuilder.End(optimized);

and is load just fine. I still do no see why it is crashing on your side.
also I can't download the FPX version for sketchfab, I suspect that model also have duplicated layers.
teh give away is ther missing faces on the corners, because thoso are the areas where polygon will be identical from LOD to LOD

@JulioJerez
Copy link
Contributor

if you sync I added the code that load the PLY file,
maybe you can try place some where, in teh code where is repro the crash.
I am probably no doing teh same way you are doing it.

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 6, 2022 via email

@Hurleyworks
Copy link
Author

I stepped through in the latest git version and the crash happens in a different place. Here's a video
https://youtu.be/OHBJR-9kFqk

@JulioJerez
Copy link
Contributor

That does not makes any sense.
It is as if something is corrupting the memory heap, and tge code crash ramdome.

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 6, 2022 via email

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 7, 2022 via email

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 7, 2022 via email

@JulioJerez
Copy link
Contributor

when I click teh link, I get this
(https://drive.google.com/)
You need access
Request access, or switch to an account with access.

request access tell me I nee to be approved.

@JulioJerez
Copy link
Contributor

can you just load the file to you site so that I can download it?

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 7, 2022 via email

@JulioJerez
Copy link
Contributor

ok, I download the mesh and place like you show in the video.
I am not getting a crash, in my machine at home, nor I get a crash on my work system

if you sync, the sandbox is set to recreate what you did, maybe I am doing something different, but I am not getting a crash.

The mesh looks weird, but the first thing is to see why it is crashing for everyone except for me.

@JulioJerez
Copy link
Contributor

oh, nice.
I set optimization false, and I get the crash.
Thanks for that repro.

now I can work to get this fixed.

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 7, 2022 via email

@JulioJerez
Copy link
Contributor

JulioJerez commented Nov 7, 2022 via email

@Hurleyworks
Copy link
Author

Hurleyworks commented Nov 7, 2022 via email

@JulioJerez
Copy link
Contributor

JulioJerez commented Nov 7, 2022 via email

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.

2 participants