关于使用以下代码播放USDZ文件的动画,我遵循了这个问题的答案:
@IBOutlet var arView: ARView!
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
arView = ARView(frame: self.view.frame)
self.view.addSubview(arView)
arView.cameraMode = .nonAR
let newAnchor = AnchorEntity(world: .zero)
let newEnt = try! Entity.load(named: "Vintage Toy Robot")
newAnchor.addChild(newEnt)
arView.scene.addAnchor(newAnchor)
print(newEnt.availableAnimations)
for anim in newEnt.availableAnimations {
newEnt.playAnimation(anim.repeat(duration: .infinity),
transitionDuration: 1.25, startsPaused: false)
}
}
但是,动画不播放,USDZ文件只是静态的。
从AR Quick Look页面下载机器人模型和动画。你的代码正在工作。不要使用Reality Composer库中的非动画机器人。
let entity = try! Entity.load(named: "toy_robot_vintage.usdz")
并删除这两行代码(你有2个ARView
,它阻塞了动画):
arView = ARView(frame: self.view.frame)
self.view.addSubview(arView)