JoltPhysics is available as a Swift Package for iOS, macOS, tvOS and visionOS

Hello ladies and gentlemen,

I’ve released a precompiled version of JoltPhysics as an xcframework, it also includes recently released Metal GPU compute system. The library is compiled as a static library for iOS, macOS, tvOS and visionOS, and wrapped in an xcframework and released as a Swift Package.

The package also includes a separate target with Metal compute shaders (generated by the build system). They are not precompiled because I did not yet find a way to bundle compiled libraries for each platform the similar way xcframework works. The initialisation of the ComputeSystem is pretty straightforward though and described in the readme.

I think the package may be suitable for people building custom engines, physics-heavy applications, games or 3D tooling. I'm exploring now the ways how to provide Swift interfaces without any runtime penalties. I use this package in my upcoming game.

Here is the Swift Package, here is the original project. Let me know what you think, feedbacks are very welcome :)

2 Likes

Do you have a small driver written in Swift, demonstrating how to use the JoltPhysics engine from Swift?

I went in there but could not find any Swift code apart from Package.swift. Did I miss something? :slight_smile:

Thanks for checking out the package :) As I briefly mentioned, I'm working on providing Swift interfaces and I think I'll use apinotes, helper functions and extensions. If you use the latest commit on the main branch (about two hours ago), you can import the "JoltPhysics" module in Swift and access its APIs through the JPH enum:

import JoltPhysics

func joltTest() {
    // Register the default allocator
    JPH.RegisterDefaultAllocator()
    
    // Create compute system
    let result = JPH.CreateComputeSystem()
    if result.HasError() {
        return
    }
    
    // The "Get()" method is not exposed because the "ComputeSystem" class is a reference type and thus was not automatically bridged to Swift yet. Such methods usually ported as "__<method_name>Unsafe" and not visible in the autocompletion suggestions in Xcode
    let computeSystem = result.__GetUnsafe()
    // ...
}
1 Like