RealityKit – Playing multiple animations in USDZ file - swift

Has anyone found a workflow to create multiple animations for a skeletal mesh packaged in a USDZ file and playback the animations using RealityKit?
I have a skeletal mesh with two animations (idle & run). I want to package them into a single USDZ file (or even multiple USDZ files if I have to) to be used in RealityKit.
I have been able to create an FBX for export of my skeletal mesh and the animations, and ship them up to sketchfab for a valid USDZ export that RealityKit can understand. I do not know how to package the second animation into a single USDZ file and then use SWIFT to playback the specific animations based off of specific events.
There seem to be a lot of posts from about a year ago on the topic with no real answers and little activity since. Any pointers would be appreciated.

Although in SceneKit you can play multiple animations using .dae model, in RealityKit 2.0 you still have no possibility to play multiple animations found in any .usdz model. Look at this post and this post.
There is only one animation is accessible using the following code now:
let robot = try ModelEntity.load(named: "drummer")
let anchor = AnchorEntity()
anchor.children.append(robot)
arView.scene.anchors.append(anchor)
robot.playAnimation(robot.availableAnimations[0].repeat(duration: .infinity),
transitionDuration: 0.5,
startsPaused: false)
When you choose second or third element in collection (if it really exists), your app crashes:
modelWithMultipleAnimations.availableAnimations[1]
modelWithMultipleAnimations.availableAnimations[2]

Related

Best way to render 3D animations in Swift from Maya

I've got two apps, one in Unity and one in iOS (created using Swift in Xcode). For the Unity game, our animator exports the 3D models from Maya into an fbx file which we are then able to render in the game.
Our challenge now is being able to render those same animations in the iOS game. I've read documentation that iOS supports usdz files. However, I'm having lots of trouble exporting the fbx files into usdz. These are the things I've tried:
I had our animator export the Maya file into Blender and then had them export to usd, which I then ran converted to usdz through Reality Converter. However, nothing shows up in the SCNScene (just a blank screen).
I downloaded all the appropriate SDKs from Apple and Autodesk to try and convert the the fbx file directly to usdz through Reality Converter, but when I run it in Swift, the textures seem to get messed up (we have a second layer of texture for eyes). Some fbx files turned out better than others. The below was the best one I could get.
Lastly, I created a .scn file and dragged the different dae/usdz files into the scene which I'm able to see in the scene editor, but when I load the scene using SCNScene(named: "filename"), I get an empty scene (with a sky and ground though).
Worth mentioning, I've tried converting the animations to dae and gtlf files as well, but with no luck.
I've tried two permutations of code to load the animations into the scene:
directly into the scene:
guard let url = Bundle.main.url(forResource: "ferox", withExtension: "usdz") else { fatalError() }
let scene = try! SCNScene(url: url, options: [.checkConsistency: true])
and also using an intermediary MDLAsset:
guard let url = Bundle.main.url(forResource: "ferox", withExtension: "usdz") else { fatalError() }
let asset = MDLAsset(url: url)
let scene = SCNScene(mdlAsset: asset)
There has to be a way to do this since fbx files are so common. Can someone tell me what I'm doing wrong (or even where, since there are so many different steps)?

Is there a to export RealityKit scene to USDZ?

I have a RealityKit scene I would Like to export to and file format (preferably to USDZ) I haven’t found any solution for it. I know it is possible to do with SceneKit but not RealityKit.
You can use the Reality Converter app, just drop in a file in(ex. obj or dae) and it'll convert it to USDZ format. You can also customize your 3D models on it so it's pretty sweet. You can check it out here: https://developer.apple.com/news/?id=01132020a

How to integrate Spine animations to a SpriteKit game

I need to integrate animations to an iOS SpriteKit game. The artist provides them in Spine format. Such animation consists of a set of images, a .spine file describing the animations and a .json file describing the metadata.
I see two possible ways to solve this problem:
Find (or make) a module allowing to add nodes and related animations from Spine files to a SpriteKit scene.
Convert the animation to a different format which can be imported to SpriteKit easily.
Please, share your experience. Any help is welcomed!
There is a library that allows you to do exactly that. Installing & usage examples are in the description of the library.
https://github.com/maxgribov/Spine

How to load animations made in Blender to ARKit?

I made a 3D object in Blender and made some custom animation to it. However, I manage to load the object to the scene, but not the animation.
This is what it appears to me at the Entities tab
I was searching about "How to load custom animations in ARKit", but couldn't find anything besides this link:
https://blog.pusher.com/animating-3d-model-ar-arkit-mixamo/
In there it tells you how to download and play some animations with Mixamo, but I want to load the animations that I made in Blender.
Just for the record, I'm new in this field of ARKit programming and I'm learning by myself.
Any suggestions? Thanks in advance!
When we're talking about animation it's better to talk in context of SceneKit and Core Animation frameworks.
Here's what Apple says about it:
SceneKit also uses CAAnimation objects for animations created using external 3D authoring tools (3dsMax, Maya, Blender) and saved in scene files. For example, an artist might create a game character with animations for walking, jumping, and other actions. You incorporate these animations into your game by loading animation objects from the scene file using the SCNSceneSource class and attaching them to the SCNNode object that represents the game character.
But remember: you need to export your animations as .dae file format. And your animations must be baked (you need to transform all animation and deformations into keyframes (for every frame) on the timeline regardless of how the animation is done).

Using SceneKit within a Cocoa Application

Is it possible to use SceneKit for GPU accelerated graphics within a cocoa Application?
I'm looking for a way to do 2D animations in a PowerPoint like application, and not sure which direction to take to have GPU accelerated animations.
Picked up xCode about a week ago and went straight into swift with no Objective-C background. Didn't find any information on the topic, hoping to get this answered here.
Your screenshot depicts the template selection in the project creator. What template you use has no impact on what features is possible in your application. It is perfectly possible to create a Cocoa app and simply drag and drop a SCNView and set it to run a SceneKit scene.
That being said, SceneKit or SpriteKit is definitely overkill just for doing "2D animations like in PowerPoint". You should look into Core Animation:
https://developer.apple.com/library/mac/documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html