Skip to content

xpenatan/jJolt

Repository files navigation

jJolt

Build

Maven Central Version Static Badge

jJolt is a Java binding for the C++ library Jolt Physics, utilizing JNI/FFM for desktop, JNI for Android, and Emscripten for web platforms. It provides a one-to-one correspondence with the C++ code, meaning it mirrors the exact same class and method names. Its samples and rendering integrations target libfdx.

The binding leverages jParser, a custom C/C++ build tool and WebIDL Java code generator, which automatically generates 99% of all classes. Only a small number of essential classes are coded manually, making updates to new Jolt Physics versions quick and efficient.

image

Web/TeaVM Examples

Platform Status

Emscripten Windows Linux Mac Android iOS
Yes Yes Yes Yes Yes No
  • Yes: Have a working build.
  • No: Build not ready.

Setup

// Use -SNAPSHOT or any released git-tag version.

// Add repository to root Gradle.
repositories {
    mavenLocal()
    mavenCentral()
    maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
}

// Core module
implementation("com.github.xpenatan.jJolt:core:-SNAPSHOT")
implementation("io.github.libfdx:application:-SNAPSHOT")
implementation("io.github.libfdx:g3d:-SNAPSHOT")

// Desktop module
dependencies {
   implementation("com.github.xpenatan.jJolt:desktop-jni:-SNAPSHOT")
   implementation("com.github.xpenatan.jJolt:desktop-ffm:-SNAPSHOT")
   implementation("io.github.libfdx:backend_desktop:-SNAPSHOT")
   implementation("io.github.libfdx:gl_desktop:-SNAPSHOT")
   implementation("io.github.libfdx:vulkan_desktop:-SNAPSHOT")
   implementation("io.github.libfdx:wgpu_desktop_jni:-SNAPSHOT")
   implementation("io.github.libfdx:wgpu_desktop_ffm:-SNAPSHOT")
}

// TeaVM module
dependencies {
   implementation("com.github.xpenatan.jJolt:web-wasm:-SNAPSHOT")
   implementation("io.github.libfdx:backend_web:-SNAPSHOT")
   implementation("io.github.libfdx:gl_web:-SNAPSHOT")
   implementation("io.github.libfdx:wgpu_web:-SNAPSHOT")
}

// Android module
dependencies {
   implementation("com.github.xpenatan.jJolt:android-jni:-SNAPSHOT")
   implementation("io.github.libfdx:backend_android:-SNAPSHOT")
   implementation("io.github.libfdx:wgpu_android_jni:-SNAPSHOT")
   implementation("io.github.libfdx:vulkan_android_jni:-SNAPSHOT")
}

Notes

  • In most classes, new instances are created using JoltNew.[TYPE] instead of standard Java constructors. This approach is necessary due to limitations in constructor overloading within WebIDL when targeting Emscripten.
  • Methods that return an object typically return a temporary object. You should not retain a reference to it, as calling the method again with another instance will overwrite the previously returned object.
  • Classes are not disposed automatically; the dispose method must be called when they are no longer in use. However, classes in a WebIDL file marked with NoDelete do not require disposal.

Source Build Prerequisites

  • Java 17 or later
  • Gradle
  • Android NDK (only needed for Android native artifacts)
  • Mingw64 or Visual Studio C++ (only needed for desktop native artifacts)
  • Emscripten (only needed for WebAssembly native artifacts)

To try the samples with your build, change LibExt.useRepoLibs to false in buildSrc/src/main/kotlin/LibExt.kt. This will allow you to use the local jJolt source code instead of the remote repository.

How To Run The Samples

  • Desktop OpenGL/JNI: ./gradlew :samples:gdx:gl:platforms:desktop-jni:jolt_sample_desktop_gl_jni_run
  • Desktop WGPU/JNI: ./gradlew :samples:gdx:gl:platforms:desktop-jni:jolt_sample_desktop_wgpu_jni_run
  • Desktop WGPU/FFM: ./gradlew :samples:gdx:gl:platforms:desktop-jni:jolt_sample_desktop_wgpu_ffm_run
  • Desktop Vulkan/JNI: ./gradlew :samples:gdx:gl:platforms:desktop-jni:jolt_sample_desktop_vulkan_jni_run
  • Desktop Vulkan/FFM: ./gradlew :samples:gdx:gl:platforms:desktop-jni:jolt_sample_desktop_vulkan_ffm_run
  • WebGL JS/Wasm: ./gradlew :samples:fdx:platforms:web:jolt_sample_webgl_js_build :samples:fdx:platforms:web:jolt_sample_webgl_wasm_build
  • WebGPU JS/Wasm: ./gradlew :samples:fdx:platforms:web:jolt_sample_webgpu_js_build :samples:fdx:platforms:web:jolt_sample_webgpu_wasm_build
  • Android GLES/WGPU/Vulkan: ./gradlew :samples:gdx:gl:platforms:android:jolt_sample_android_gles_build :samples:gdx:gl:platforms:android:jolt_sample_android_wgpu_jni_build :samples:gdx:gl:platforms:android:jolt_sample_android_vulkan_build

How To Build From Source

./gradlew :jolt:builder:jolt_download_source

# Generate binding sources for JNI, FFM, and web.
./gradlew :jolt:builder:jolt_build_project

# Generate and build native platform targets.
./gradlew :jolt:builder:jolt_build_project_windows64_jni :jolt:builder:jolt_build_project_windows64_ffm
./gradlew :jolt:builder:jolt_build_project_linux64_jni :jolt:builder:jolt_build_project_linux64_ffm
./gradlew :jolt:builder:jolt_build_project_mac64_jni :jolt:builder:jolt_build_project_mac64_ffm
./gradlew :jolt:builder:jolt_build_project_macArm_jni :jolt:builder:jolt_build_project_macArm_ffm
./gradlew :jolt:builder:jolt_build_project_android_jni
./gradlew :jolt:builder:jolt_build_project_web_wasm

About

Jolt Physics Java Bindings

Topics

Resources

License

Stars

12 stars

Watchers

1 watching

Forks

Sponsor this project

 

Packages

 
 
 

Contributors

Languages