Problem with new VHACD

Report any bugs here and we'll post fixes

Moderators: Sascha Willems, Thomas

Problem with new VHACD

Postby Bird » Sat May 07, 2022 7:23 am

Hi Julio,

I'm not having any luck trying to get the new VHACD working in my project. I'm mostly using your code from the ndBasicCompoundCollision demo but I'm having penetration problems and crashes when I run the engine. For debugging, I'd like to be able to render the separate convex hull parts of the compound but I can's seem to figure out how to extract the vertices and triangle indices for each shape in the ndShapeCompound. Can you tell me how to do that please?

Here's a stack dump from a crash.
25.100914 DEBUG [3292 NewtonOps.cpp->createCollisionShape:102] created 512 convex hulls
******* STACKDUMP *******
stack dump [0] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndShapeConvexHull.cpp L: 829 ndShapeConvexHull::SupportVertexBruteForce
stack dump [1] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndShapeConvexHull.cpp L: 985 ndShapeConvexHull::SupportVertex
stack dump [2] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndShapeInstance.h L: 264 ndShapeInstance::SupportVertex
stack dump [3] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndShapeConvexPolygon.cpp L: 568 ndShapeConvexPolygon::CalculateContactToConvexHullDescrete
stack dump [4] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndContactSolver.cpp L: 3170 ndContactSolver::CalculatePolySoupToHullContactsDescrete
stack dump [5] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndContactSolver.cpp L: 3267 ndContactSolver::ConvexToSaticStaticBvhContactsNodeDescrete
stack dump [6] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndContactSolver.cpp L: 3378 ndContactSolver::CompoundToShapeStaticBvhContactsDiscrete
stack dump [7] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndContactSolver.cpp L: 2524 ndContactSolver::CalculateContactsDiscrete
stack dump [8] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndScene.cpp L: 965 ndScene::CalculateJointContacts
stack dump [9] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndScene.cpp L: 1712 ndScene::CalculateContacts
stack dump [10] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCore\ndThreadPool.h L: 130 ndFunction<<lambda_469435bfd5342606033bbf7b4463c8d3> >::operator()<int,int>
stack dump [11] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCore\ndThreadPool.h L: 205 ndThreadPool::ParallelExecute<ndFunction<<lambda_469435bfd5342606033bbf7b4463c8d3> > >
stack dump [12] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCollision\ndScene.cpp L: 1492 ndScene::CalculateContacts
stack dump [13] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dNewton\ndWorld.cpp L: 425 ndWorld::ThreadFunction
stack dump [14] D:\ActiveWorks\OpenSource\latestNewton\newton-dynamics\newton-4.00\sdk\dCore\ndThread.cpp L: 111 ndThread::ThreadFunctionCallback
stack dump [15] C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.31.31103\include\thread L: 56 std::thread::_Invoke<std::tuple<void (__cdecl ndThread::*)(void),ndThread *>,0,1>
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with new VHACD

Postby Bird » Sat May 07, 2022 8:14 am

Nevermind, I guess I can just get the vertices and triangles from VHACD

Code: Select all
ndShapeCompound* const compoundShape = compoundShapeInstance->GetShape()->GetAsShapeCompound();
compoundShape->BeginAddRemove();
ndInt32 hullCount = interfaceVHACD->GetNConvexHulls();
for (ndInt32 i = 0; i < hullCount; ++i)
{
   VHACD::IVHACD::ConvexHull ch;
   interfaceVHACD->GetConvexHull (i, ch);
   
   // Points in the convex hull as doubles x1,y1,z1,x2,y2,z2...
    ch.m_points{nullptr};     
    
    // Triangle indices
    ch.m_triangles{nullptr};       
}
compoundShape->EndAddRemove();
Bird
 
Posts: 623
Joined: Tue Nov 22, 2011 1:27 am

Re: Problem with new VHACD

Postby Julio Jerez » Sat May 07, 2022 9:46 am

There are two v-hacd
Do not use v-hacd new. Yet.

That one I added as a comparison with the version that I modify.
I am cooperating with a guy from nvidial in making the modification to the original version so that there is only one fix all.

But so far thier version is not quite as good as the newton one, dies not produces same quality decomposition, and is not as fast.
How ever thier version has lot of bug fixes and more option so it is on the vest interest to change in the future.

That why I have there, it is for a side by side comparison.

Basically he is taking the modifications I made and adding it to the official version. And as soon as there two version are similar I will simply switch to the original. But for now it is a long way to go.

This is yet another case where you see people in the court maje opinion of how good compare to newton every thing is.
Until you compare these thing side by side. The quality of the newton version is not just better is order of magnitude better and faster.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with new VHACD

Postby Julio Jerez » Sat May 07, 2022 9:49 am

And yes in newton 4 this is not part of the engine.
It is just a library that the app can link and get a generic set of convex meshes made of vertices and triangles that they can use to make a compound collision.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles

Re: Problem with new VHACD

Postby Julio Jerez » Sat May 07, 2022 11:48 am

you are correct it is no clear how to irate over the array of shape of a compound.
here is a code shape, from the debug code of the shape.

Code: Select all
void DebugShape(ndShapeCompound* const shapeInstance)
{
   const ndShapeCompound::ndTreeArray& shapeList = shapeInstance->GetTree();
   ndShapeCompound::ndTreeArray::Iterator iter(shapeList);
   for (iter.Begin(); iter; iter++)
   {
      ndShapeInstance* const collision = iter.GetNode()->GetInfo()->GetShape();
      /// do what you wnat here
   }
}


it is better to use that since the convex shapes are optimized to be a made of faces for performance reason and fewer contacts. of course you will have to get them to triangle for rendering.
but at least you have a way to get the info form the shape. which is handy in cases where the compound is made manually.

in many case the automatic convex decomposition is an over kill and a user can make a better judgment. but there yo uhave it.
Julio Jerez
Moderator
Moderator
 
Posts: 12249
Joined: Sun Sep 14, 2003 2:18 pm
Location: Los Angeles


Return to Bugs and Fixes

Who is online

Users browsing this forum: No registered users and 4 guests

cron