Skip to content

Latest commit

 

History

History
97 lines (73 loc) · 5.04 KB

README.md

File metadata and controls

97 lines (73 loc) · 5.04 KB

Build Xcode 16.0+ Swift 6.0+ iOS 18.0+ visionOS 2.0+ macOS 15.0+ License: MIT

VimKit

VimKit is an open-source swift package for reading and rendering VIM files on Apple platforms (iOS, macOS, visionOS) with Metal.

vimkit.mov

Overview

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.

VimKit

Provides the core library for reading and rendering VIM files on macOS and iOS.

References

VimKitCompositor

Provides the core library for rendering VIM files on visionOS (Apple Vision Pro) using CompositorServices.

References

VimKitShaders

C Library that provides types and enums shared between Metal Shaders and Swift.

VisionOS Usage

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)
    }
}