LONG STORY SHORT:
=================

Please copy the folder "appHACDDemoMeshes" and the file "appHACDDemo.exe.cmdlineParams.txt" in the same folder of the executable "appDemo.exe".

To compile the code HACD.lib is needed (http://sourceforge.net/projects/hacd/).
At the time of writing the HACD SVN version is needed, NOT the one in the Bullet Extras/HACD folder .


LONG STORY LONG:
================

Convex decomposition is the process used to decompose a concave mesh into a set of convex meshes. This process can be used to compute the
collision shape used by physic engines to represent the mesh, expecially when the shape is supposed to model dynamic objects.

This is a new Bullet Demo about it.
It's based on the library HACD ("Hierarchical approximate convex decomposition" by Khaled Mamou), which is included
in the Bullet library package (in the "Extra" section) starting from Bullet version 2.79.
However at the time of writing that library is not up to date and fully compatible with the HACD SVN repository (http://sourceforge.net/projects/hacd/);
that's why the latter is NEEDED to compile the demo.

The demo can be used in three ways:

1) As a common Bullet Demo, it's similiar to the appConvexDecompositionDemo, but with a better interface.
The heart of the demo is the (header only) file (and class) "btHACDCompoundShape.h", that can be easily integrated into existing applications and
that takes a btStridingMeshInterface* as an argument in its constructor together with an optional structure with some decomposition parameters.
Currently the demo is composed by four scenes; keys '[' and ']' can be used to change the current scene.

To compile the demo, a reference to (the SVN) HACD.lib is needed and STL is required (STL is also used in lib HACD itself).
The demo depends on lib BulletWorldImporter too, and glut (or freeglut) is needed..

IMPORTANT: Please copy the file "appHACDDemo.exe.cmdlineParams.txt" AND the folder "appHACDDemoMeshes" in the same directory of the executable "appHACDDemo.exe".
The folder "appHACDDemoMeshes" contains three simple OBJ files I've made using Wings3d, that are needed in some of the scenes (together with the "Bunny mesh" and
the "Torus mesh" that were included in appGImpactTestDemo).


2) As a standalone decomposition tool that takes a Wavefront OBJ file (recommended because the loader keeps track of all the submeshes in the model), 
or an .OFF file as an argument (on Windows you can drag the model directly onto the appHACDDemo.exe icon in Explorer). The resulting "plain" Bullet 
btCompoundShape can be optionally saved to disk as a file with the ".bcs" (Bullet Collision Shape) extension. 
Additional decomposition paramters are not passed through the command line (too many), but can be edited directly in a text file named "appHACDDemo.exe.cmdlineParams.txt",
in the same folder of appHACDDemo.exe).

".bcs" files can be loaded in plain Bullet applications with the following code:
[code]	#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);
		// Hope there are no leaks.
		return shape;
	}
[/code]The advantages of loading ".bcs" files, instead of adding "btHACDCompoundSape.h" to a project are:
1) No need to use STL.
2) No need to link to HACD.lib
3) Only simple models can be decomposed "at runtime" with "btHACDCompoundSape.h", because the decomposition
process can take several seconds. Much better to load btCompoundShapes directly from disk.

3) As a ".bcs" (Bullet Collision Shape) file viewer, when the command line argument has a ".bcs" extension (on Windows you can drag it onto the .exe).

Hope you like it and find it useful.
Flix

LAST UPDATE:
=============
-> btConvexHullComputer is used instead of btShapeHull (limitation problem of the old update removed).
-> A bunch of new decomposition params added:
	--O-- params.targetNTrianglesDecimatedMesh (from HACD SVN).
	--O-- params.smallClusterThreshold		   (from HACD SVN).
	--O-- params.keepSubmeshesSeparatedNClusters
	--O-- params.keepSubmeshesSeparatedMaxHullVertices 	
	--O-- params.decomposeATranslatedCopyOfTheMesh
	--O-- extraParams.decomposeBCSInputFileIfShapeIsCompatible	
-> CollisionShapes with a striding mesh interface inside them can now be directly decomposed (though the new btHACDCompoundShape ctr), or loaded inside a btTriangleMeshEx.
-> The GlutDemoApplication class (inside OpenGLSupport.lib) has been extended to support these features: 
	--O--	btTriangleMeshEx "static footprints" (they're basically "sets of display lists" (one per submesh))
			can be assigned to btCollisionShapes/btCollisionObjects.	('r' key).
	--O--	Frustum culling.
	--O--	Alternative camera mode (Free camera).		('a' key (use LMB drag to look around)).
	--O-- 	Improved Ortho mode.						('o' key).
	--O-- 	Raytrace screenshots. 						('R' key (uppercase) to show/hide them).
-> Known Bug: when meshes are displayed ('r' key), the (default btShapeHull based) stencil shadows may produce artifacts, color bleeding and blinking. 
   The 'g' key can be used to disable them.

HOW TO COMPILE THE CODE: 
========================
Prerequisites:
1) Bullet 2.79 (or upper)
2) HACD (http://sourceforge.net/projects/hacd/). At the time of writing only the HACD SVN version is compatible, NOT the one in the Bullet Extras/HACD folder.

To compile the code using QtDesigner/QtMake a .pro file has been added (needs minimal editing to set the correct folders) and tested on Ubuntu64.
A CMakeList.txt file is present too, but it just shares the same structure as the other Bullet Demos, and it might need some tweaking to make it work.

In case of problems, as a general guideline, the dependencies are similiar to the ones in the appConvexDecompositionDemo, (with the addition of BulletSoftbody),
and the HACD include and link folders must be replaced from the Bullet/Extras/HACD folder to the new HACD SVN folders (please read the .pro file for further info).

OLD UPDATE:
=============
-> Changed the way colors are displayed. 'c' can be used to switch color mode.
-> Added: params.reduceHullVerticesUsingBtShapeHull	(false by default)
	(not very useful in most cases: params.maxHullVertices should be used, but in some rare case with a lot of child shapes it may be useful; for example when using HACD full-hull feature (params.maxHullVertices=0)).
-> Now the number of hull vertices per child shape is displayed in the console window.
-> Now the Bullet Collision Shape Viewer accepts files with the .bullet extension (but they are handled exactly as .bcs files: only the first collision shape inside them is shown).
-> Limitation: BulletOpenGLSupport.lib seems to use btShapeHull to simplify convex hulls before displaying them (most likely for good performance reasons).
	That means that convex hulls with more than 42 vertices are "cut down" in their visual representation.
	This could be improved using the information provided by HACD.lib itself (vertex and index arrays), but I'm too lazy to do it (I've just done the change in color mode and I'm happy with it).
	Feel free to modify the code and add this fix, if you need it. FIXED IN THE NEW UPDATE!
