A project that enables using glTF files in Swift.
- Decodes glTF and GLB files and makes them available as
MDLAsset
in Swift - High-performance glTF rendering with Metal
- glTF animation support
- glTF extension support
- Customizable rendering pipeline
- 3D model editing and exporting features
- VRM format support
And more.
- iOS 15.0+
- macOS 13.0+
dependencies: [
.package(url: "https://github.com/nhiroyasu/SwiftGLTF.git", branch: "main")
]
import SwiftGLTF
let gltfUrl = // URL to your glTF or GLB file
let gltfView = GLTFView(frame: view.frame, url: gltfUrl)
view.addSubview(gltfView)
import SwiftGLTF
var body: some View {
@State private var gltfUrl = // URL to your glTF or GLB file
GLTFMetalView(url: gltfUrl)
}
- Unsupported features are planned to be added in future updates.
Format | Supported |
---|---|
glTF Binary (.glb) | ✅ |
glTF JSON (.gltf) | ✅ |
Format | Supported |
---|---|
External .bin file | ✅ |
Embedded (data URI in .gltf) | ✅ |
Format | Supported |
---|---|
PNG | ✅ |
JPEG | ✅ |
KTX2 | ❌ |
Extension | Supported |
---|---|
KHR_draco_mesh_compression | ❌ |
Property | Supported |
---|---|
baseColorFactor | ✅ |
baseColorTexture | ✅ |
metallicFactor | ✅ |
roughnessFactor | ✅ |
metallicRoughnessTexture | ✅ |
Property | Supported |
---|---|
normalTexture | ✅ |
occlusionTexture | ✅ |
emissiveTexture | ✅ |
emissiveFactor | ✅ |
alphaMode | ✅ |
alphaCutoff | ✅ |
doubleSided | ❌ |
Attribute | Supported |
---|---|
POSITION | ✅ |
NORMAL | ✅ |
TANGENT | ✅ |
TEXCOORD_0 | ✅ |
TEXCOORD_1 | ✅ |
COLOR_0 | ✅ |
JOINTS_0 | ❌ |
WEIGHTS_0 | ❌ |
Feature | Supported |
---|---|
Node hierarchy | ✅ |
matrix (4x4 transform matrix) | ✅ |
translation / rotation / scale (TRS) | ✅ |
Channel | Supported |
---|---|
translation | ❌ |
rotation | ❌ |
scale | ❌ |
morph target weights | ❌ |
Feature | Supported |
---|---|
Multiple scenes | ❌ |
Feature | Supported |
---|---|
Camera | ❌ |
- You can build the sample project by opening
SwiftGLTFSample.xcodeproj
.
- A library for rendering glTF files using Metal.
- A library that parses glTF and converts it into
MDLAsset
for use in Swift.
- Provides
GLTFView
andGLTFMetalView
components to display glTF files in UIKit and SwiftUI views.
- A library that defines the core data structures of glTF.
- Performs normal vector computation for glTF
- Based on mmikk/MikkTSpace