droidgfxsim

A graphical 3D physics simulator supporting Android and desktop builds written in C++.

This Android app uses a native OpenGL ES 2/3 compatable render system along with the Bullet Physics SDK. It provides an XML-defined graphical 3D simulation and can be built as a standalone desktop application. The Android portion of application is derived from the gles3jni Android SDK sample.

Building the Desktop Application:

All third-party dependencies are either included in the repository or installed via the ExternalProject_Add function provided by the CMake build system and Git. It can be built for Windows with MSVC, MinGW or Linux.

$ cmake -G"MinGW Makefiles" /path/to/source/native && cmake --build .

The build script will attempt to download and build all dependencies then link them statically. An advantage of this approach is the ability to specify different compiler flags and anable debug symbols which is done automatically unless -DCMAKE_BUILD_TYPE:STRING=Release is specified. Note: changing from Debug to Release after the initial build will cause problems, it is recommended to use a separate directory when compiling Debug and Release builds. The following dependencies will be fetched via Git:

Exising versions of these dependencies can be specified by enabling the following CMake parameters:

-DUSE_EXISTING_GLFW3:BOOL=ON
-DUSE_EXISTING_GLM:BOOL=ON
-DUSE_EXISTING_BULLET:BOOL=ON
-DUSE_EXISTING_TINYOBJLOADER:BOOL=ON

Running the Desktop Application

There are various assets found in app/src/main/assets that need to be in the current directory in order for the application to work correctly.

$ cd app/src/main/assets
$ /path/to/binary/desktop_app

Building the Android Application

This application requires the Android NDK and relies on a slightly different CMake build script than the desktop application and will be used to produce shared libraries for multiple architectures. The CMake build is triggered by the top-level Gradle build script:

$ gradlew build

Configuring the Simulation Data

The droidgfxsim simulation can be modified by editing data.xml from the assets directory. Wavefront .obj files can be specified with the WavefrontFile tag, and boxes and convex hull objects can be specified. Note: The Wavefront files must specify objects with names and all textures defined in the associated .mtl files must have relative paths. Blender can be used to export .obj files by choosing the "Objects as OBJ Objects" checkbox and selecting "Strip Path" for "Path Mode" when exporting to Wavefront .obj.

Example data.xml

<?xml version="1.0" ?>
<SimulationConfiguration>
	<WavefrontFile filename="monkey.obj">
		<PhysicsNode name="Suzanne" mass="0.1">
			<CollisionShape>ConvexHull</CollisionShape>
		</PhysicsNode>
	</WavefrontFile>
	<WavefrontFile filename="cylinders.obj">
		<PhysicsNode name="Cylinder" mass="100.0">
			<CollisionShape>ConvexHull</CollisionShape>
		</PhysicsNode>
		<PhysicsNode name="Cone" mass="100.0">
			<CollisionShape>ConvexHull</CollisionShape>
		</PhysicsNode>
		<PhysicsNode name="Cube" mass="100.0">
			<CollisionShape>ConvexHull</CollisionShape>
		</PhysicsNode>
	</WavefrontFile>
	<WavefrontFile filename="boxes_and_rocks.obj">
		<PhysicsNode name="Floor" mass="0.0">
			<CollisionShape>ConvexHull</CollisionShape>
		</PhysicsNode>
			<PhysicsNode name="Cube.000" mass="1">
			<CollisionShape width="1" height="1" length="1"
				offset_x="0" offset_y="0" offset_z="0">Box</CollisionShape>
		</PhysicsNode>
		<PhysicsNode name="Cube.001" mass="1">
			<CollisionShape width="1" height="1" length="1"
				offset_x="0" offset_y="0" offset_z="0">Box</CollisionShape>
		</PhysicsNode>
		...
		<PhysicsNode name="Rock.000" mass="800">
			<CollisionShape>ConvexHull</CollisionShape>
		</PhysicsNode>
		<PhysicsNode name="Rock.001" mass="50">
			<CollisionShape>ConvexHull</CollisionShape>
		</PhysicsNode>
		...
	</WavefrontFile>
</SimulationConfiguration>

License Information

Source files included from the Android Open Source Project are included:

These files use the Apache License, Version 2.0 ( see LICENSE-2.0 ) which were copied from the gles3jni Android sample and used for compatibility. There are a number of included dependencies that use various permissive open source licences such as stb_image.h, rapidxml.hpp, and OpenGL extension loading provided by the GLAD code generator. All sources in this directory authored by Chris Liebert are provided under the MIT license, for more see LICENSE.