Hey there! To play a model's animation, you have to store the animation on your model as an Animation Resource and then pass that into the .playAnimation method.
let animScene = try await Entity(named: "anim", in: realityKitContentBundle)
guard let animModel = animScene.findEntity(named: "anim") else { return }
guard let animResource = animModel.availableAnimations.first else { return }
let anim = try AnimationResource.generate(with: animResource.repeat().definition)
animModel.playAnimation(anim)
Make note, you can only play the first available animation on a .usdz file at the moment. If you want to play multiple animations, you have to either load in separate .usdz files that have the animations you want to store as Animation Resources, or create Animation Clips as shown in the WWDC 21 video "Dive into Reality Kit 2"
Post
Replies
Boosts
Views
Activity
Hey @sadaotokuyama ! Tassilo von Gerlach made a good video about using anchor entities that attach to the .head I'm wondering if you could have some way of capturing the coordinates of .head when you need to and updating the position of the entity when the action occurs? https://www.youtube.com/watch?v=NZ-TJ8Ln7NY&pp=ygUSYXNzaWxvIHZvbiBHZXJsYWNo Would love to follow the progress on this as I've thought about how I would go about creating something similar. Good luck!
This would be awesome, please do update here if you find a way to do this! I haven't seen anybody do this so far, but the hacky solution I would suggest if this is not currently possible is to load in your desired model at room scale into the museum scene and hope it doesn't clip with any of the walls around it. The benches would probably be the only thing you would still see. Alternatively, you could load your desired room scale model with .setPosition to something like x=50 so that it loads outside of the simulated environment and then you could walk over to that model instead lol. Hacky but might be the easiest solution to get this up and running quickly
Unless I'm misunderstanding your desired result, I believe you would want to include a view as an attachment to your RealityView inside of your ImmersiveSpace that would have a button or some toggle to be able to then dismiss the immersive view and return to your ContentView
Does the RealityView attachment closure not satisfy what you're trying to achieve? I wrote these notes on the WWDC video that explains the attachment closure, but I know it is a bit outdated as they made a significant update to the way the attachment closure works in the latest RealityView protocol. Hopefully this is a helpful start though https://www.wwdcnotes.com/notes/wwdc23/10081/
Also curious if you found any source code here
Also curious if anybody has any good sample code from here.
Hey @senicy by chance were you able to find any? Been searching online but haven't had any luck myself. I just want to test quickly rather than author a file. Thanks for any response you can offer!
Hi @fportela is this example still compiling for you? I also am trying to use the sample code provided by Apple in the link you shared, but anytime I try to initialize the VideoMaterial(avPlayer: player) line, I get the error: "Argument passed to call that takes no arguments" Curious if you are seeing this? I'm using the latest beta 8
I'm completely new to SwiftUI and building in the apple ecosystem, so apologies if this doesn't help as I'm not fully sure why it would, but in my function I'm calling
{
await dismissImmersiveSpace()
switch await openImmersiveSpace(id: "MyFullSpace") {
case .opened:
myFullSpaceIsShown = true
case .userCancelled:
return
case .error:
return
@unknown default:
return
}
Perhaps the switch await will solve it?