SceneKit:虽然在 Xcode 场景编辑器中工作,但无法以编程方式添加 SCNReferenceNode [英] SceneKit: cannot add SCNReferenceNode programmatically though works in Xcode Scene Editor

查看:52
本文介绍了SceneKit:虽然在 Xcode 场景编辑器中工作,但无法以编程方式添加 SCNReferenceNode的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从 Xcode 场景编辑器添加 SCNReferenceNode 即可.然而,当使用下面的代码以编程方式完成时,场景中什么也没有出现.

Adding a SCNReferenceNode works when done from the Xcode Scene Editor. When done programmatically with the code below, however, nothing appears in the scene.

filePath 包含一个由 print 语句证明的有效路径以及代码单步执行.

filePath contains a valid path as proven by the print statement as well as stepping through the code.

帮助?

    if let filePath = NSBundle.mainBundle().pathForResource("RefTest", ofType: "scn", inDirectory: "TestScene.scnassets") {
        let referenceURL = NSURL(fileURLWithPath: filePath)

        if #available(iOS 9.0, *) {
            let referenceNode = SCNReferenceNode(URL: referenceURL)
            scene!.rootNode.addChildNode(referenceNode!)
            print(referenceNode)
        }
    }

推荐答案

类文档声称加载策略指示 SCNReferenceNode 默认立即加载:

The class docs claim that the loading policy instructs the SCNReferenceNode to load immediately by default:

当引用节点加载其内容时(自动,根据 loadingPolicy 属性,或者当你调用 load方法),SceneKit 加载引用的场景文件.的所有孩子场景文件的根节点成为参考节点的子节点.

When the reference node loads its content (either automatically, according to the loadingPolicy property, or when you call the load method), SceneKit loads the referenced scene file. All children of the scene file’s root node become children of the reference node.

但是,默认情况下似乎不会发生这种情况.您必须像这样调用 load 函数:

However, this doesn't seem to happen by default. You must invoke the load function like so:

let referenceNode = SCNReferenceNode(URL: referenceURL
referenceNode.load()

或者,也许您也可以使用 loadingPolicy 属性,但调用 load 函数肯定有效.

Alternatively, perhaps you could play with the loadingPolicy property as well, but invoking the load function definitely works.

这篇关于SceneKit:虽然在 Xcode 场景编辑器中工作,但无法以编程方式添加 SCNReferenceNode的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆