How to access Native Bullet's constraintsolver numIterations?

Hi folks,

I’d like to increase the Number of Iteration of the Native Bullet constraintsolver to reduce joint separation and a few other issues. Unfortunately, increasing the overall accuracy is not an option. In JBullet it is possible to access this parameter through:
BulletAppState.getPhysicsSpace().getDynamicsWorld().getSolverInfo().numIterations=20;

Is there any way to do the same thing in Native Bullet?
As a mechanical engineering student I’m not very familiar with c, or c++ development. So I’d prefer to access this parameter through java-code. :smiley:

No (insert grumpy cat meme)

Native bullet supports this, but the required method(s) need to be exposed on the Java side via JNI (Java Native Interface).
If you would like, you can make a pull request on GitHub.

Thank you. :smiley:

It took me a while to read into JNI-Wrappers. But I believe i understand the basic concepts now.

I have downloaded the jME3 source via svn and opened the engine-directory as a project in the sdk. To keep it simple I have added the required methods to the PhysicsSpace class and its c++ counterpart. I`m not too familiar with c++, so basically I copy-pasted some of Normens original methods and changed the names.
(Insert I have no idea what i am doing meme)

In PhysicsSpace.java:

public void setNumIterations(int numIterations)
{
    this.numIterations = numIterations;
   setNumIterations(physicsSpaceId, numIterations);
}    
private native void setNumIterations(long space, int numIterations);

In PhysicsSpace.h:

/*
 * Class:     com_jme3_bullet_PhysicsSpace
 * Method:    setNumIterations
 * Signature: (JI)V
 */
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setNumIterations
(JNIEnv *, jobject, jlong, jint);

And in PhysicsSpace.cpp:

 /*
 * Class:     com_jme3_bullet_PhysicsSpace
 * Method:    setNumIterations
 * Signature: (JI)V
 */
JNIEXPORT void JNICALL Java_com_jme3_bullet_PhysicsSpace_setNumIterations
(JNIEnv *env, jobject object, jlong spaceId, jint value) {
    jmePhysicsSpace* space = reinterpret_cast<jmePhysicsSpace*>(spaceId);
    if (space == NULL) {
        jclass newExc = env->FindClass("java/lang/NullPointerException");
        env->ThrowNew(newExc, "The native object does not exist.");
        return;
    }
    space->getDynamicsWorld()->getSolverInfo().m_numIterations = value;
}

I hope, that this will do the job.
I then tried to build the required librarys to test it. But while the jME3-bullet.jar is building correctly I am not able to build the jME3-bullet-natives.jar with the sdk.
I work on a windows 64bit system. I installed mingw with the 4.7.3 GCC version and installed CMake, as recommended in the bullet-native-build.txt. But when I try to run the ant target I get this error on the console:

jnlp:
jar:
build-bullet-natives:
build bullet natives.create-native-headers:
-- Configuring incomplete, errors occurred!CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.

CMake Error: CMake was unable to find a build program corresponding to "MinGW Makefiles".  CMAKE_MAKE_PROGRAM is not set.  You probably need to select a different build tool.
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_C_COMPILER
CMake Error: Could not find cmake module file: C:/[...]/trunk/bullet-2.82-r2704/CMakeFiles/3.2.2/CMakeCCompiler.cmake
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER_ENV_VAR
CMake Error: Error required internal CMake variable not set, cmake may be not be built correctly.
Missing variable is:
CMAKE_CXX_COMPILER
CMake Error: Could not find cmake module file: C:/[...]/trunk/bullet-2.82-r2704/CMakeFiles/3.2.2/CMakeCXXCompiler.cmake
CMake Error at CMakeLists.txt:7 (PROJECT):
  No CMAKE_C_COMPILER could be found.

  Tell CMake where to find the compiler by setting the CMake cache entry
  CMAKE_C_COMPILER to the full path to the compiler, or to the compiler name
  if it is in the PATH.


CMake Error at CMakeLists.txt:7 (PROJECT):
  No CMAKE_CXX_COMPILER could be found.

  Tell CMake where to find the compiler by setting the CMake cache entry
  CMAKE_CXX_COMPILER to the full path to the compiler, or to the compiler
  name if it is in the PATH.


CMake Error: CMAKE_C_COMPILER not set, after EnableLanguage
CMake Error: CMAKE_CXX_COMPILER not set, after EnableLanguage
C:\[...]\trunk\engine\build.xml:10: The following error occurred while executing this line:
C:\[...]\trunk\engine\nbproject\build-bullet-natives.xml:538: exec returned: 1
BUILD FAILED (total time: 8 seconds)

I do need some help with this. Which build program is CMake looking for, and how do i set the path to the compiler?

I guess you need to have the mingw bin folder inside the PATH environment variable?

Allmost there…

I have set the environment variable to:
C:\Program Files (x86)\CMake\bin;C:\MinGW\bin;C:\MinGW\lib;C:\MinGW\bin\include
The result didn’t change. But after reinstalling cmake and mingw the build script seems to do its thing… For a while. After 22% it stops with some compile errors. Here is the (almost) full output on the console:

    	ant -f C:\\[…]\\trunk\\engine build-bullet-natives
	init:
	Deleting: C:\[…]\trunk\engine\build\built-jar.properties
	deps-jar:
	Updating property file: C:\[…]\trunk\engine\build\built-jar.properties
	Compile Core
	Compiling 1 source file to C:\[…]\trunk\engine\build\core
	warning: [options] bootstrap class path not set in conjunction with -source 1.5
	1 warning
	Compile Effects
	Compile Networking

	[…]

	Compile Tests
	compile:
	Building Engine JAR files..
	Building TestData JAR file..
	Copying 1 file to C:\[…]\trunk\engine\build
	Copy libraries to C:\[…]\trunk\engine\dist\lib.
	To run this application from the command line without Ant, try:
	java -jar "C:\[…]\trunk\engine\dist\jMonkeyEngine3.jar"
	Moving optional packages
	Moving 1 file to C:\[…]\trunk\engine\dist\opt\native-bullet
	Moving 1 file to C:\[…]\trunk\engine\dist\opt\native-bullet
	Copying 1 file to C:\[…]\trunk\engine\dist\opt\native-bullet
	 
	[…]

	Copying 1 file to C:\[…]\trunk\engine\dist\opt\ios
	jnlp:
	jar:
	build-bullet-natives:
	build bullet natives.create-native-headers:
	-- WARNING: you are using the obsolete 'GLU' package, please use 'OpenGL' insteadINTEL OPENCL NOT FOUND
	
	NVidia OPENCL NOT FOUND
	OPENGL FOUND
	glu32opengl32
	GLUT NOT FOUND not found, trying to use MINGW glut32
	#NAME?
	
	#NAME?
	#NAME?
	CMake Warning:-- Build files have been written to: C:/[…]/trunk/bullet-2.82-r2704
	
	  Manually-specified variables were not used by the project:
	
	    CMAKE_LD_FLAGS
	
	
	[  1%] Building CXX object src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/btSoftBody.obj
	[  1%] Building CXX object src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/btSoftBodyConcaveCollisionAlgorithm.obj
	[  2%] Building CXX object src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/btSoftBodyHelpers.obj
	
	[…]

	[ 21%] Building CXX object src/BulletCollision/CMakeFiles/BulletCollision.dir/CollisionDispatch/btGhostObject.obj
	[ 21%] Building CXX object src/BulletCollision/CMakeFiles/BulletCollision.dir/CollisionDispatch/btHashedSimplePairCache.obj
	[ 22%] Building CXX object src/BulletCollision/CMakeFiles/BulletCollision.dir/CollisionDispatch/btInternalEdgeUtility.obj
	C:\[…]\trunk\bullet-2.82-r2704\src\BulletCollision\CollisionDispatch\btInternalEdgeUtility.cpp: In member function 'virtual void btConnectivityProcessor::processTriangle(btVector3*, int, int)':
	C:\[…]\trunk\bullet-2.82-r2704\src\BulletCollision\CollisionDispatch\btInternalEdgeUtility.cpp:310:2: internal compiler error: Segmentation fault
	  }
	
	This application has requested the Runtime to terminate it in an unusual way.
	Please contact the application's support team for more information.
	
	C:\[…]\trunk\bullet-2.82-r2704\src\BulletCollision\CollisionDispatch\btInternalEdgeUtility.cpp:310:2: internal compiler error: Aborted
	
	This application has requested the Runtime to terminate it in an unusual way.
	Please contact the application's support team for more information.
	g++.exe: internal compiler error: Aborted (program cc1plus)
	src\BulletCollision\CMakeFiles\BulletCollision.dir\build.make:702: recipe for target 'src/BulletCollision/CMakeFiles/BulletCollision.dir/CollisionDispatch/btInternalEdgeUtility.obj' failedlibbacktrace could not find executable to open
	
	CMakeFiles\Makefile2:154: recipe for target 'src/BulletCollision/CMakeFiles/BulletCollision.dir/all' failedPlease submit a full bug report,
	
	Makefile:115: recipe for target 'all' failedwith preprocessed source if appropriate.
	
	See <http://gcc.gnu.org/bugs.html> for instructions.
	mingw32-make[2]: *** [src/BulletCollision/CMakeFiles/BulletCollision.dir/CollisionDispatch/btInternalEdgeUtility.obj] Error 4
	mingw32-make[1]: *** [src/BulletCollision/CMakeFiles/BulletCollision.dir/all] Error 2
	mingw32-make: *** [all] Error 2
	Result: 2
	INTEL OPENCL NOT FOUND-- WARNING: you are using the obsolete 'GLU' package, please use 'OpenGL' instead
	
	NVidia OPENCL NOT FOUND
	OPENGL FOUND
	glu32opengl32
	#NAME?
	#NAME?
	GLUT NOT FOUND not found, trying to use MINGW glut32
	GLUT NOT FOUND
	#NAME?
	-- Build files have been written to: C:/[…]/trunk/bullet-2.82-r2704
	CMake Warning:
	  Manually-specified variables were not used by the project:
	
	    CMAKE_LD_FLAGS
	
	
	[  1%] Building CXX object src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/btSoftBody.obj
	C:\[…]\trunk\bullet-2.82-r2704\src\BulletSoftBody\btSoftBody.cpp:1:0: sorry, unimplemented: 64-bit mode not compiled in
	 /*
	src\BulletSoftBody\CMakeFiles\BulletSoftBody.dir\build.make:54: recipe for target 'src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/btSoftBody.obj' failed ^
	
	CMakeFiles\Makefile2:104: recipe for target 'src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/all' failed
	mingw32-make[2]: *** [src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/btSoftBody.obj] Error 1
	mingw32-make[1]: *** [src/BulletSoftBody/CMakeFiles/BulletSoftBody.dir/all] Error 2Makefile:115: recipe for target 'all' failed
	
	mingw32-make: *** [all] Error 2
	Result: 2
	build bullet natives.compile-bullet-sources:
	build bullet natives.compile-native-library:
	build bullet natives.compile-android:
	build bullet natives.build-bullet-natives:
	Updating native jME3-bullet-natives.jar
	BUILD SUCCESSFUL (total time: 59 seconds)

Maybe you just change it in the github version, the native build process is different there and if you want to contribute this it would have to be done against the master version anyway. jm3-bullet in master itself should be compatible to the 3.0 SDK if you want to use it with that. If you use svn be sure to use the 3.0-final branch, the trunk is a random development version between 3.0 and 3.1-pre-alpha as it is in github.

Looks like you won’t have to toil any further :smile:
I already added this in GitHub master:
https://github.com/jMonkeyEngine/jmonkeyengine/commit/cd1d14500571da1d771b9748d6eda912edeb40bd

Please add this to jbullet too then, they should be largely compatible/swappable. I know you can do it by directly accessing the jbullet classes but then it wouldn’t be swappable, jme3-jbullet wraps the jbullet methods.

Isn’t jbullet going to be deprecated when 3.1 lands?

No?

Then why do you use a question mark? :smile:

Quoting from your post from 4 years ago :

If the integration and use of the native version proves to be painless
the native bullet might become the default implementation with jME3.1.

Somehow, I thought that default implementation= scrap the other one.

No it doesn’t (full stop)

1 Like

Its already supported

No its not. Again, the signature has to be the same. com.jme3.bullet.PhysicsSpace doesn’t expose that method in jme3-jbullet.

Not sure what you mean? Here’s the signatures for both:

Oh right, sorry. I was searching for “setNum” when I looked it up, my bad.

Thank you very much. :grinning:

But the toiling is not quite over. To know how to access native-bullet features (that are not necessarily beneficial for the community) might prove to be useful later. I still want to find a way to edit the librarys and will look into that again, when I find the time.