Как связать несколько анимаций Collada, используя Swift в Xcode? - PullRequest
0 голосов
/ 30 апреля 2020

У меня проблемы с загрузкой четырех анимаций коллады в последовательности. Используя этот код, анимации начинаются одновременно, и между ними нет последовательности. Я хотел бы начать с 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

    }
}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...