VimKit is an open-source swift package for reading and rendering VIM files on Apple platforms (iOS, macOS, visionOS) with Metal.
vimkit.mov
The VimKit package is broken down into 3 seperate modules (VimKit, VimKitCompositor, VimKitShaders).
VIM files are composed of BFAST containers that provide the necessary geometry, assets, entities, and strings buffers used to render and interrogate all of the 3D instances contained in a file.
Although it is possible to render each Instance individually, VimKit leverages instancing to render all Instance's that share the same Mesh in a single draw call.
Geometry.swift and ShaderTypes.h are the best sources to understand the details of how the geometry, positions, indices and data structures used for rendering are organized.
Provides the core library for reading and rendering VIM files on macOS and iOS.
Provides the core library for rendering VIM files on visionOS (Apple Vision Pro) using CompositorServices.
- WWDC 2023 - Discover Metal for immersive apps
- WWDC 2023 - Meet ARKit for spatial computing
- Drawing fully immersive content using Metal
C Library that provides types and enums shared between Metal Shaders and Swift.
The following is an example of the simplest usage of rendering a VIM file on visionOS:
import CompositorServices
import SwiftUI
import VimKit
import VimKitCompositor
/// The id of our immersive space
fileprivate let immersiveSpaceId = "VimImmersiveSpace"
@main
struct VimViewerApp: App {
/// Sample Vim File
let vim = Vim(URL(string: "https://vim02.azureedge.net/samples/residence.v1.2.75.vim")!)
/// Holds the composite layer configuration
let configuration = VimCompositorLayerConfiguration()
/// The ARKit DataProvider context
let dataProviderContext = DataProviderContext()
/// Build the scene body
var body: some Scene {
// Displays a 2D Window
WindowGroup {
Button {
Task {
// Launch the immersive space
await openImmersiveSpace(id: immersiveSpaceId)
}
} label: {
Text("Show Immersive Space")
}
.task {
// Start the ARKit HandTracking
await dataProviderContext.start()
}
}
// Displays the fully immersive 3D scene
ImmersiveSpace(id: immersiveSpaceId) {
VimImmersiveSpaceContent(vim: vim,
configuration: configuration,
dataProviderContext: dataProviderContext)
}
.immersionStyle(selection: .constant(.full), in: .full)
}
}