Change ModelEntity.loadModel
to ModelEntity.load
and it should now have the animations.
It's very weird and I don't know why, but that has worked for me in the past.
Also HasPhysics inherits Entity, so to save yourself looking for the anchor's children etc, you should be able to replace that guard let modelEntity...
line with this:
guard let modelEntity = modelToLoad as? HasPhysics else { return }
EDIT:
I just ran this in playground and the animation runs fine:
import PlaygroundSupport
import UIKit
import RealityKit
let arview = ARView(frame: .zero, cameraMode: .nonAR, automaticallyConfigureSession: true)
arview.environment.lighting.intensityExponent = 3
let newAnchor = AnchorEntity(world: .zero)
let newEnt = try! Entity.load(named: "toy_robot_vintage")
newAnchor.addChild(newEnt)
arview.scene.addAnchor(newAnchor)
for anim in newEnt.availableAnimations {
newEnt.playAnimation(anim.repeat(duration: .infinity), transitionDuration: 1.25, startsPaused: false)
}
PlaygroundSupport.PlaygroundPage.current.liveView = arview
The issue is that a model imported this way does not conform to HasPhysics (useful if you mentioned that's where it was now failing for you).
Apply the ModelComponent to another entity class or ModelEntity instead.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…