MADEAPPS / newton-dynamics

Newton Dynamics is an integrated solution for real time simulation of physics environments.
http://www.newtondynamics.com
Other
928 stars 183 forks source link

added staticBody test #303

Closed Hurleyworks closed 1 year ago

Hurleyworks commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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

Hurleyworks commented 1 year ago

It happens on line 339 of ndPolygonSoupBuilder.cpp in the Finalize() function.

Here's a video of what I get. Some meshes work without crashing. https://youtu.be/SNnMa52b3Gs

On Sun, Nov 6, 2022 at 9:28 AM NewtonDynamics @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1304814117, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PP6PTM56INWK5IJ2W7DWG6W6PANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

JulioJerez commented 1 year ago

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 commented 1 year ago

Definitely something weird going on. Here's the view's of the original mesh and the ply mesh saved from ndPolygonSoupBuilder. I also am including the ply mesh

On Sun, Nov 6, 2022 at 12:28 PM NewtonDynamics @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1304851309, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PPZCPBHMW4P64AIRSULWG7L23ANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

Hurleyworks commented 1 year ago

newton_static_mesh

original_mesh

Hurleyworks commented 1 year ago

Here's the ply mesh static_mesh.zip

JulioJerez commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

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 commented 1 year ago

No crash for me either using meshBuilder.LoadPLY("sword.ply");

Here's the 2 sword meshes wireframe in my viewer.

original_sword_gltf

sword_ply

On Sun, Nov 6, 2022 at 3:15 PM NewtonDynamics @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1304884449, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PPYWFYRBBJHPYAJSU3TWG77TFANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

Hurleyworks commented 1 year ago

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 commented 1 year ago

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

Hurleyworks commented 1 year ago

Yes, it definitely seems like memory corruption. It's odd that some models work consistently and some crash.

Poly Haven has a bunch of free high quality models, many of which can be downloaded in FBX format. Maybe you can find one that crashes too. https://polyhaven.com/models

On Sun, Nov 6, 2022 at 5:06 PM NewtonDynamics @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1304906354, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PP74WYLGOTUNCA4LGI3WHAMURANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

Hurleyworks commented 1 year ago

Okay, I found a FBX mesh from PolyHaven( ceramic_vase_03_4k.fbx ) that crashes in the "static mesh" Newton demo. It only crashes if optimize is set to false (meshBuilder.End(false); )

I modified the BuildPlayArena

ndBodyKinematic BuildPlayArena(ndDemoEntityManager const scene) { ndMeshEffectNode const meshEffectNode = LoadFbxMeshEffectNode("ceramic_vase_03_4k.fbx"); ndDemoEntity const entity = new ndDemoEntity(scene, meshEffectNode); scene->AddEntity(entity);

Here's the file. I just unzipped into the "build/applications/media" folder ceramic_vase_03_4k.fbx.zip https://drive.google.com/file/d/1uaiCHTqjTR1l47ZIzJi9yv1dio62RlB0/view?usp=drive_web

On Sun, Nov 6, 2022 at 6:21 PM Hurleyworks @.***> wrote:

Yes, it definitely seems like memory corruption. It's odd that some models work consistently and some crash.

Poly Haven has a bunch of free high quality models, many of which can be downloaded in FBX format. Maybe you can find one that crashes too. https://polyhaven.com/models

On Sun, Nov 6, 2022 at 5:06 PM NewtonDynamics @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1304906354, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PP74WYLGOTUNCA4LGI3WHAMURANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

Hurleyworks commented 1 year ago

And here's the video of the crash in Newton Demos https://youtu.be/vHcd2wprwFw

On Mon, Nov 7, 2022 at 9:46 AM Hurleyworks @.***> wrote:

Okay, I found a FBX mesh from PolyHaven( ceramic_vase_03_4k.fbx ) that crashes in the "static mesh" Newton demo. It only crashes if optimize is set to false (meshBuilder.End(false); )

I modified the BuildPlayArena

ndBodyKinematic BuildPlayArena(ndDemoEntityManager const scene) { ndMeshEffectNode const meshEffectNode = LoadFbxMeshEffectNode("ceramic_vase_03_4k.fbx"); ndDemoEntity const entity = new ndDemoEntity(scene, meshEffectNode); scene->AddEntity(entity);

Here's the file. I just unzipped into the "build/applications/media" folder ceramic_vase_03_4k.fbx.zip https://drive.google.com/file/d/1uaiCHTqjTR1l47ZIzJi9yv1dio62RlB0/view?usp=drive_web

On Sun, Nov 6, 2022 at 6:21 PM Hurleyworks @.***> wrote:

Yes, it definitely seems like memory corruption. It's odd that some models work consistently and some crash.

Poly Haven has a bunch of free high quality models, many of which can be downloaded in FBX format. Maybe you can find one that crashes too. https://polyhaven.com/models

On Sun, Nov 6, 2022 at 5:06 PM NewtonDynamics @.***> wrote:

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

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1304906354, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PP74WYLGOTUNCA4LGI3WHAMURANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

JulioJerez commented 1 year ago

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 commented 1 year ago

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

Hurleyworks commented 1 year ago

request access tell me I nee to be approved.

I just approved you. The file was too big for email so I had to put on GoogleDrive

On Mon, Nov 7, 2022 at 10:13 AM NewtonDynamics @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305759418, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PPZHFYLZQCINFFLQ743WHEL7JANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

JulioJerez commented 1 year ago

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 commented 1 year ago

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

now I can work to get this fixed.

Hurleyworks commented 1 year ago

I can't get back to my computer for a couple hours but just as a sanity check did you remember to set the optimize off. If optimize is on I don't get a crash either

On Mon, Nov 7, 2022, 12:32 PM NewtonDynamics @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305953937, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PP4VAVTAMI5J6F4EWXTWHE4KFANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

JulioJerez commented 1 year ago

Alright, it was a memory overrun in a vertex list to index list class. You can sync and try again. At least, I think that crash is resolved.

On Mon, Nov 7, 2022, 9:40 AM Steve Hurley @.***> wrote:

I can't get back to my computer for a couple hours but just as a sanity check did you remember to set the optimize off. If optimize is on I don't get a crash either

On Mon, Nov 7, 2022, 12:32 PM NewtonDynamics @.***> wrote:

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.

— Reply to this email directly, view it on GitHub < https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305953937 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AB56PP4VAVTAMI5J6F4EWXTWHE4KFANCNFSM6AAAAAARYFCSTE

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305963797, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6EPJFIUD2PDP2D4SYZP23WHE5HXANCNFSM6AAAAAARYFCSTE . You are receiving this because you modified the open/close state.Message ID: @.***>

Hurleyworks commented 1 year ago

Great, It's working now. Thanks!

On Mon, Nov 7, 2022 at 1:11 PM NewtonDynamics @.***> wrote:

Alright, it was a memory overrun in a vertex list to index list class. You can sync and try again. At least, I think that crash is resolved.

On Mon, Nov 7, 2022, 9:40 AM Steve Hurley @.***> wrote:

I can't get back to my computer for a couple hours but just as a sanity check did you remember to set the optimize off. If optimize is on I don't get a crash either

On Mon, Nov 7, 2022, 12:32 PM NewtonDynamics @.***> wrote:

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.

— Reply to this email directly, view it on GitHub <

https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305953937

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AB56PP4VAVTAMI5J6F4EWXTWHE4KFANCNFSM6AAAAAARYFCSTE

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305963797 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AB6EPJFIUD2PDP2D4SYZP23WHE5HXANCNFSM6AAAAAARYFCSTE

. You are receiving this because you modified the open/close state.Message ID: @.***>

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1306000506, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB56PP64GI6MLIZSE2KC3UTWHFA5BANCNFSM6AAAAAARYFCSTE . You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

JulioJerez commented 1 year ago

Yes thatvwas a big one. But I also found some other problems, when I was debugging that problem yesterday. I am fixing the tonight. It has to do when a large object hit a ver small polygon. It is generation contact outside the perimeter of the face. I had a comment there, from a long time. And I guess it is time to adressit now.

On Mon, Nov 7, 2022, 11:45 AM Steve Hurley @.***> wrote:

Great, It's working now. Thanks!

On Mon, Nov 7, 2022 at 1:11 PM NewtonDynamics @.***> wrote:

Alright, it was a memory overrun in a vertex list to index list class. You can sync and try again. At least, I think that crash is resolved.

On Mon, Nov 7, 2022, 9:40 AM Steve Hurley @.***> wrote:

I can't get back to my computer for a couple hours but just as a sanity check did you remember to set the optimize off. If optimize is on I don't get a crash either

On Mon, Nov 7, 2022, 12:32 PM NewtonDynamics @.***> wrote:

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.

— Reply to this email directly, view it on GitHub <

https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305953937

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AB56PP4VAVTAMI5J6F4EWXTWHE4KFANCNFSM6AAAAAARYFCSTE

. You are receiving this because you authored the thread.Message ID: @.***>

— Reply to this email directly, view it on GitHub <

https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1305963797

, or unsubscribe <

https://github.com/notifications/unsubscribe-auth/AB6EPJFIUD2PDP2D4SYZP23WHE5HXANCNFSM6AAAAAARYFCSTE

. You are receiving this because you modified the open/close state.Message ID: @.***>

— Reply to this email directly, view it on GitHub < https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1306000506 , or unsubscribe < https://github.com/notifications/unsubscribe-auth/AB56PP64GI6MLIZSE2KC3UTWHFA5BANCNFSM6AAAAAARYFCSTE

. You are receiving this because you authored the thread.Message ID: @.***>

-- -Steve http://berserko.hurleyworks.com/ http://www.hurleyworks.com

— Reply to this email directly, view it on GitHub https://github.com/MADEAPPS/newton-dynamics/pull/303#issuecomment-1306102327, or unsubscribe https://github.com/notifications/unsubscribe-auth/AB6EPJH3MGDGKN6QA36QVLLWHFL4RANCNFSM6AAAAAARYFCSTE . You are receiving this because you modified the open/close state.Message ID: @.***>