简体   繁体   English

如何在Swift中访问多个动画?

[英]How can I access multiple animations in Swift?

Image of the file hierarchy in xcode of my animation file 我的动画文件的xcode中的文件层次结构图像

Issue: 问题:

xcode is recognizing multiple animations for a single Collada (.dae) file. xcode正在识别单个Collada(.dae)文件的多个动画。 But I can't find any documentation on how to access these animations directly. 但是我找不到任何有关如何直接访问这些动画的文档。 I tried using the fox game example, but it only loads one of the animations. 我尝试使用狐狸游戏示例,但它仅加载动画之一。

Here's my code: 这是我的代码:

let modelNode = self.addModel_DAE_return(x: 0, y: 0, z: 0, scaleFactor: 0.0005, fileName: "models.scnassets/export_014/export_014_model.dae")

// add the animation to the model

let modelAnim = self.loadAnim_DAE(fileName: "models.scnassets/export_014/export_014_anim.dae")
                modelNode.addAnimationPlayer(modelAnim, forKey: "headMove")

modelAnim.play()

// add the model to the scene
node.addChildNode(modelNode)

How can I access and load in the other animations? 如何访问和加载其他动画?

Context: 内容:

I'm making an AR app. 我正在制作一个AR应用程序。 I'm using the Apple Image Recognition example as a base. 我以Apple Image Recognition示例为基础。

Here's a link to it: https://developer.apple.com/documentation/arkit/recognizing_images_in_an_ar_experience 这是它的链接: https : //developer.apple.com/documentation/arkit/recognizing_images_in_an_ar_experience

I animated a skeleton in Maya and exported the animation to a COLLADA (.DAE) file using the OpenCollada extension for Maya. 我在Maya中对骨骼进行了动画处理,并使用Maya的OpenCollada扩展名将动画导出到COLLADA(.DAE)文件。

I exported separate files for the model and the animation, because if I export them as a single file, none of my animations export and xcode crashes every time I try to access the file to check if it registers any animations. 我为模型和动画导出了单独的文件,因为如果将它们导出为单个文件,则每次尝试访问文件以检查是否注册了任何动画时,我的动画都不会导出并且xcode崩溃。

I want to access the "Entities" of my animation file so I can just loop over, load and attach the animations, but I can't 我想访问动画文件的“实体”,所以我可以循环播放,加载和附加动画,但是我不能

also I have looked into GameKit kind of but, is there not a way to do this with SceneKit? 我也研究过GameKit,但是,是否有办法用SceneKit做到这一点?

Each joint in the rig has animation information Originally I was only getting the information the first joint that had animations on it and not its children that also had animations attached 钻机中的每个关节都有动画信息最初,我只是获得该信息的第一个关节上有动画的关节,而不是其子节点上还附加了动画的信息。

ie lets say your rig hierarchy is hips > rightShoulder > arm > elbow > wrist 即,假设您的装备层次为臀部>右肩>手臂>肘部>手腕

and your animations were on the shoulder, arm, elbow, and wrist joints 而您的动画位于肩膀,手臂,肘部和腕关节

you do not have any animations on your hip joint 你的髋关节上没有任何动画

using enumerateChildNodes will only grab the information from the shoulder joint 使用enumerateChildNodes只会从肩关节获取信息

using enumerateHierarchy will grab all the animation information from the shoulder, the elbow, AND the wrist joint 使用enumerateHierarchy将捕获来自肩膀,肘部和腕关节的所有动画信息

see below for my function that I used: note that I had separately loaded and saved my 3D model onto an SCNNode and that was passed in so I could attach the animations to it 参见以下有关我使用的功能的说明: 请注意,我已将3D模型分别加载并保存到SCNNode上,并且已将其传递给我,以便可以将动画附加到该模型上

func loadAttachAnim_DAE(fileName: String, modelNode: SCNNode){
        let scene = SCNScene(named: fileName)!

        //find top level animation
        var animationPlayer: SCNAnimationPlayer! = nil


        scene.rootNode.enumerateHierarchy{ (child, stop)  in
            if !child.animationKeys.isEmpty {
                print ("child = \(child) -----------------")
                animationPlayer = child.animationPlayer(forKey: child.animationKeys[0])

                modelNode.addAnimationPlayer(animationPlayer, forKey: "\(child)")
                animationPlayer.play()

            }
        }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM