swift - 如何在 Xcode 中使用 Swift 链接多个 collada 动画?
问题描述
我无法按顺序加载四个 collada 动画。使用此代码,动画同时开始,彼此之间没有顺序。我想先用 SU.dae 然后 FTW.dae 等等,比如使用 Xcode 的大型动画。
有谁知道如何正确解决这个问题?
import UIKit
import SceneKit
import ARKit
class ViewController: UIViewController, ARSCNViewDelegate {
@IBOutlet var sceneView: ARSCNView!
var animations = [String: CAAnimation]()
var Stand_Up:Bool = true
override func viewDidLoad() {
super.viewDidLoad()
// Set the view's delegate
sceneView.delegate = self
// Show statistics such as fps and timing information
sceneView.showsStatistics = true
// Create a new scene
let scene = SCNScene()
// Set the scene to the view
sceneView.scene = scene
// Loaf the DAE amimation
loadAnimations (sceneName: "art.scnassets/animation/SU.dae")
loadAnimations (sceneName: "art.scnassets/animation/FTW.dae")
loadAnimations (sceneName: "art.scnassets/animation/R.dae")
loadAnimations (sceneName: "art.scnassets/animation/BAE.dae")
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
// Create a session configuration
let configuration = ARWorldTrackingConfiguration()
// Run the view's session
sceneView.session.run(configuration)
}
override func viewWillDisappear(_ animated: Bool) {
super.viewWillDisappear(animated)
// Pause the view's session
sceneView.session.pause()
}
func loadAnimations (sceneName:String) {
// Load the character in the idle animation
let idleScene = SCNScene(named: sceneName)!
// This node will be parent of all the animation models
let node = SCNNode()
// Add all the child nodes to the parent node
for child in idleScene.rootNode.childNodes {
node.addChildNode(child)
}
// Set up some properties
node.position = SCNVector3(0, -1, -2)
node.scale = SCNVector3(0.2, 0.2, 0.2)
// Add the node to the scene
sceneView.scene.rootNode.addChildNode(node)
animateEntireNodeTreeOnce(mostRootNode: node)
}
func animateEntireNodeTreeOnce(mostRootNode node: SCNNode){
onlyAnimateThisNodeOnce(node)
for childNode in node.childNodes {
animateEntireNodeTreeOnce(mostRootNode: childNode)
}
}
func onlyAnimateThisNodeOnce(_ node: SCNNode) {
if node.animationKeys.count > 0 {
for key in node.animationKeys {
let animation = node.animation(forKey: key)!
animation.repeatCount = 1
animation.duration = 5;
animation.isRemovedOnCompletion = false
node.removeAllAnimations()
node.addAnimation(animation, forKey: key)
}
}
}
func session(_ session: ARSession, didFailWithError error: Error) {
// Present an error message to the user
}
func sessionWasInterrupted(_ session: ARSession) {
// Inform the user that the session has been interrupted, for example, by presenting an overlay
}
func sessionInterruptionEnded(_ session: ARSession) {
// Reset tracking and/or remove existing anchors if consistent tracking is required
}
}
解决方案
推荐阅读
- python - 烧瓶 api 路由请求获取参数丢失错误
- pandas - 具有多个条件的 Pandas drop_duplicates
- multidimensional-array - 如何快速对多维数组进行排序
- node.js - 如何呈现特定选项卡
- css - 在图像上显示版权作为标题
- c++ - cmake/cpack 分发一个库及其依赖项
- javascript - node.js net.connect() 错误,尽管 try-catch
- powershell - 术语“Install-ChocolateyPackage”未被识别为 cmdlet、函数的名称
- python - 将列中的值移动到该列中每个空白行之前的一行
- python - 考虑到去年的第一天,今年的第一周