Nice! Getting closer - however now my animation does not start paused when it is loaded, and the animation.speed toggle stops working if I allow the animation to play all the way through. Am I instantiating the AnimationPlaybackController class correctly?
import RealityKit
import RealityKitContent
struct ModelView: View {
var isPlaying: Bool
@State private var scene: Entity? = nil
@State private var animationController: AnimationPlaybackController? = nil
@State private var playerDefinition: AnimationDefinition?
@State private var playerResource: AnimationResource? = nil
var body: some View {
RealityView { content in
// Specify the name of the Entity you want
scene = try? await Entity(named: "TestAsset", in: realityKitContentBundle)
scene!.generateCollisionShapes(recursive: true)
scene!.components.set(InputTargetComponent())
content.add(scene!)
playerDefinition = scene?.availableAnimations[0].definition
playerDefinition?.repeatMode = .none
playerResource = try! AnimationResource.generate(with: playerDefinition!)
animationController = scene!.playAnimation(playerResource!, startsPaused: true)
} .installGestures()
.onChange(of: isPlaying) {
animationController?.speed = isPlaying ? -1.0 : 1.0
}
}
}
Topic:
Spatial Computing
SubTopic:
General
Tags: