RealityKit
Recently, I was playing with RealityKit. I saw a 3D animation in the App Store and was curious on how to implement it.
It turns out I have to read a couple of 3D formats like USDZ, GLB, OBJ. Everything was new to me but nevertheless valuable since Apple is investing tons of resources to 3D, Metal, VisionOS, etc.
The simplest implementation of adding 3D with animations assuming your usdz filename is Talking.usdz
.
import SwiftUI
import RealityKit
RealityView { content in
if let model = try? await Entity(named: "Talking") {
model.position = [0, -0.2, 0]
model.components.set(InputTargetComponent())
model.generateCollisionShapes(recursive: false)
let animations = model.availableAnimations
if !animations.isEmpty {
model.playAnimation(animations[0].repeat())
}
content.add(model)
}
}
.edgesIgnoringSafeArea(.all)