appHACDDemo (and Convex Decomposition tool)

Show what you made with Bullet Physics SDK: Games, Demos, Integrations with a graphics engine, modeler or any other application
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: appHACDDemo (and Convex Decomposition tool)

Post by Flix »

ananas wrote:I've manged to successfully compile and launch HACDdemo, but I am struggling with decomposition of a torus-like mesh. I see that BulletDefaultTorusMesh.off gets decomposed properly for all but one objects in the torus demo, but if I replace it with my torus mesh created in blender with "spin" tool, and exported to the waveform format it doesn't have central hole.
Could you give some hints on how to create a torus mesh that would fit the convex decomposition algorithm requirements?
Well, you should see the code (inside HACDDemo.cpp) I used to "fill the hole" in the default torus mesh: this was made with some settings of the HACD parameters.
Once you detect the right parameters, you must replicate them in the "appHACDDemoCmdLineParams.txt" file and save the file before decomposing the mesh.
I'm not sure abut it, but I think that if you simply drag (on Windows) the torus.off file contained in the demo onto the appHACDDemo.exe icon, its central hole will be filled (with the default values of the HACD params in "appHACDDemoCommanLineParams.txt").
So you can use it as a test to see if your changes in the HACD params are actually detected by the program. (*)

(*) Please note that if you're using a unix system, this is more difficult to achieve. Anyway any changing parameter (from the default values of the HACD parameters) in "appHACDDemoCmdLineParams.txt" should be displayed in the console (so you are sure that the program is finding it). I suggest you launch the appHACDDemo.exe from the folder of the model you want to decompose.
ananas
Posts: 8
Joined: Wed Apr 24, 2013 7:57 pm

Re: appHACDDemo (and Convex Decomposition tool)

Post by ananas »

After increasing nClusters param my mesh got decomposed succesfuly. But collission of the two btCompoundShapes produced by the HACDdemo has malfunctions - objects penetrate each other and intensive shaking occurs. The issue doesn't appear when I test collision of this btCompoundShape with btConvexHullShape. My shape is decomposed to 192 child shapes - could this cause performance issue?
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: appHACDDemo (and Convex Decomposition tool)

Post by Flix »

ananas wrote:objects penetrate each other and intensive shaking occurs. The issue doesn't appear when I test collision of this btCompoundShape with btConvexHullShape.
This may be caused by the size of the clusters being too small. In addition you can play with the collision margin and see what's happaning. There is no golden rule that you can use here as far s I know. You can use a smaller Bullet timestep and see if it's something related to the simulation performance too.
ananas wrote:My shape is decomposed to 192 child shapes - could this cause performance issue?
For sure (when you collide it with another compound shape, the number of collision shapes involved in the contact resolution may be very big). Maybe you can try and use V-HACD to reduce it (since the shapes should not overlap), but I've never experienced performance problems because of this overlap so far: anyway having another decomposition algorithm to exploit might help in having a lower number of decomposed collision clusters, and that will probably help in your case (anyway V-HACD doesn't allow you to specify the number of vertices per cluster: so you might have pros and cons).

P.S. you can try changing the size of your mesh and see what's happening too.
sussumu
Posts: 3
Joined: Fri Mar 20, 2015 3:43 pm

Re: appHACDDemo (and Convex Decomposition tool)

Post by sussumu »

I'm just a beginner, so this may seem a little stupid but I couldn't set up the load .bcs method.

I imported the "btBulletWorldImporter.h" from Extras folder and it went alright. Also used the function provided by you but I'm getting this:

"Error C2039: 'btCollisionShape' : is not a member of 'btBulletWorldImporter'"

I looked the files and btCollisionShape is a class from btWorldImporter and btBulletWorldImporter derives from it, so it should work.


I know that there are another methods to achieve this mesh decomposition but actually I'm searching for an easy one since this is just a small part from my project. Thanks!
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: appHACDDemo (and Convex Decomposition tool)

Post by Flix »

sussumu wrote:I'm just a beginner, so this may seem a little stupid but I couldn't set up the load .bcs method.
First: this "Tool/Demo" is rather old and won't work with the current "git" version of VHACD-2: I've just added a note in the first post. I suppose you use the plain HACD version.
sussumu wrote:I imported the "btBulletWorldImporter.h" from Extras folder and it went alright. Also used the function provided by you
Do you mean this code ?

Code: Select all

	#include <BulletWorldImporter/btBulletWorldImporter.h>		// In "Bullet/Extra/Serialize". Needs link to: BulletWorldImporter.lib
	btCollisionShape* Load(const char* filename,bool verbose)	{	
		btBulletWorldImporter loader(0);//don't store info into the world
		loader.setVerboseMode(verbose);
		if (!loader.loadFile(filename)) return NULL;
	
		btCollisionShape* shape = NULL;
		if (loader.getNumCollisionShapes()>0) shape = loader.getCollisionShapeByIndex(0);
	
		//TODO: Cleaner way:
		// 1) Deep clone Collision Shape	
		// 2) loader.deleteAllData(); // deletes all (collision shapes included)
		// 3) return Deep cloned Collision Shape
	
		// Here we don't delete all data from the loader. (leaks?)
		return shape;	
	}
sussumu wrote:but I'm getting this:
"Error C2039: 'btCollisionShape' : is not a member of 'btBulletWorldImporter'"
I looked the files and btCollisionShape is a class from btWorldImporter and btBulletWorldImporter derives from it, so it should work.
Well, maybe something is changed in the btBulletWorldImporter.h/cpp code and now that code does not work anymore.
  • What version of Bullet are you using ? (I've never tested it with the version of Bullet2 that can be found in the Bullet3 repository)
  • Have you tried using "btHACDCompoundShape.h" alone (i.e. without serialization) ? Does it work ?
  • That error is strange. Have you compiled the cpp files in the folder: Extra/Serialization/btBulletWorldImporter/*.cpp (not sure, but maybe Extra/Serialization/BulletFileLoader/*.cpp are required as well).
  • In the version I use btBulletWorldImporter derives from btWorldImporter that derives from nothing. btCollisionShape is really NOT a member of btBulletWorldImporter.
sussumu
Posts: 3
Joined: Fri Mar 20, 2015 3:43 pm

Re: appHACDDemo (and Convex Decomposition tool)

Post by sussumu »

I saw this V-HACD and read how to include it (http://kmamou.blogspot.com.br/2014/12/v ... oject.html) but I'm really a beginner and don't know what to do with the data that it returns in line 18.

Code: Select all

IVHACD::ConvexHull ch;
Probably I should study the code in Bullet examples because I think I can found the answers there.

I'm using the last version 2 from github. I forgot to compile the libraries before but I tried today and it gave me a lot of "incorrect number of arguments" errors.

Can you point me other ways to generate a custom bullet shape with precision? I use it to create concave shapes for tweezers that are really small e detailed. Then I'll have to use it with soft body organs, so I really need that precision. I achieved good results with your program, setting the variables on that text file.

Thanks again!
Flix
Posts: 456
Joined: Tue Dec 25, 2007 1:06 pm

Re: appHACDDemo (and Convex Decomposition tool)

Post by Flix »

sussumu wrote:I saw this V-HACD and read how to include it [...] I'm using the last version 2 from github.
Then you can't use appHACDDemo tool in the first place, because I wrote:
Flix wrote:First: this "Tool/Demo" is rather old and won't work with the current "git" version of VHACD-2: I've just added a note in the first post. I suppose you use the plain HACD version.
So, no way you can generate a ".bcs" shape using V_HACD2, unless you write the code (and that's not very easy if you're a beginner :oops: ).
sussumu wrote:Can you point me other ways to generate a custom bullet shape with precision? I use it to create concave shapes for tweezers that are really small e detailed. Then I'll have to use it with soft body organs, so I really need that precision. I achieved good results with your program, setting the variables on that text file.
Then, if you have saved a good .bcs shape, you just need to be able to compile Bullet with serialization support to be able to load it back in your program (".bcs" files are the same as ".bullet" files: they just contain a single collision shape).
If you can make a Bullet program that can load a ".bullet" file (and there's one example in the Bullet Demos, the Serialization Demo AFAIR), you "should" be able to load a ".bcs" file as well, using the code I posted... unless some recent changes in the Bullet2 libraries prevent you to do so. That's why I was asking about your version of Bullet: to understand if it's still possible to load ".bcs" files.

As an alternative, if you manually compile the HACD library (it's not the same as V-HACD, and it's much easier to compile: just include all its .cpp files in your project and add a few include directories to find the headers), you can manually use the file "btHACDCompoundShape.h" alone (it's part of the appHACDDemo tool): you can copy and paste in your source code a portion of "that text file" with the variables that are good for you (you might need to adapt the pasted code slightly: but "that text file" syntax is very compatible with C++): this way you can get around to loading ".bcs" files at the cost of generating the collision shape at init time in your program (not the best strategy at all, but if you really can't load a ".bcs" file... :? ).

Hope this helps :)