UIViewController 未加载属性检查器中指定的 DAE 文件
DAE file specified in attribute inspector is not loaded by UIViewController
我在 Xcode 6.1.1 上使用 iOS 游戏模板创建了一个新项目,选项是:
Language: Swift
Game Technology: SceneKit
Device: Universal
应用程序运行正常 "as is",但现在我想直接从 Xcode 上的 Interface Builder 指定 .dae 文件,所以我在视图控制器中更改了方法,如下所示:
override func viewDidLoad() {
super.viewDidLoad()
let scnView = self.view as SCNView
// customize the loaded scene
if let scene = scnView.scene {
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// the code here is never executed because scnView.scene is nil
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
// create and add a light to the scene
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)
// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode)
// retrieve the ship node
let ship = scene.rootNode.childNodeWithName("ship", recursively: true)!
// animate the 3d object
ship.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(0, y: 2, z: 0, duration: 1)))
}
}
...然后像这样在故事板上挑选出 ship.dae 文件
为什么没有加载 .dae 文件?例如,当使用图像视图而不是 SceneKit 视图时,并从应用程序包中的资源中选择一些 .png 文件
This是项目的zip文件,如果有人想试一试。
我做了一些广泛的测试,我认为这是一个错误。
IB 属性 除了场景一外,其他都有效。如果删除 GameViewController.swift
中的所有代码,您将看到背景为红色,正如您在 IB 中定义的那样。
我在 Swift 和 Objective-C、iOS 和 OSX、游戏模板和常规应用程序、故事板和经典 IB 中创建了一堆新项目。他们都有同样的问题。
我查看了 IB 文件,没有发现任何异常。 属性 被命名为 sceneName
,所以我不得不检查问题是否来自 Scenekit。
我决定深入挖掘一下,看看问题出在哪里。我发现 SCNView 有一个私有 属性、NSString *__ibSceneName;
。对此进行测试证明它已正确设置。还有一个叫做- (void)set_ibSceneName:(id)arg1;
的私有方法。对其进行子类化证明它被正确调用(尽管它可能只是一个经典 setter)。
为了确保最后一次,我使用仪器记录了所有文件系统交互。以下是普通模板的结果:
这是来自 IB 的结果:
我的猜测是这个函数的实现可能只是丢失了,或者没有正确创建 SCNScene。我会向 Apple 提交错误报告。
同时,您可以简单地将 SCNView 子类化,并添加自定义字符串 属性,例如 myScene
。然后您可以在 IB 中设置它:
然后,只需从 属性 导入场景并在您的自定义子类中将其设置为初始化。如果您需要代码示例,请告诉我!
编辑 7 月 1 日:这是我从 Apple 收到的消息:
We believe this issue has been addressed in the latest Xcode 7 beta.
This release includes the Xcode IDE, Swift 2 compiler, Instruments,
Simulator, and latest SDKs for OS X, iOS, and watchOS.
Please test with this release. If you still have issues, please
provide any relevant logs or information that could help us
investigate.
Xcode 7 beta https://developer.apple.com/xcode/downloads/
指定 art.scnassets/ship.dae
而不是 ship.dae
应该可以。
我在 Xcode 6.1.1 上使用 iOS 游戏模板创建了一个新项目,选项是:
Language: Swift
Game Technology: SceneKit
Device: Universal
应用程序运行正常 "as is",但现在我想直接从 Xcode 上的 Interface Builder 指定 .dae 文件,所以我在视图控制器中更改了方法,如下所示:
override func viewDidLoad() {
super.viewDidLoad()
let scnView = self.view as SCNView
// customize the loaded scene
if let scene = scnView.scene {
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// the code here is never executed because scnView.scene is nil
//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
// create and add a camera to the scene
let cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode)
// place the camera
cameraNode.position = SCNVector3(x: 0, y: 0, z: 15)
// create and add a light to the scene
let lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = SCNVector3(x: 0, y: 10, z: 10)
scene.rootNode.addChildNode(lightNode)
// create and add an ambient light to the scene
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode)
// retrieve the ship node
let ship = scene.rootNode.childNodeWithName("ship", recursively: true)!
// animate the 3d object
ship.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(0, y: 2, z: 0, duration: 1)))
}
}
...然后像这样在故事板上挑选出 ship.dae 文件
为什么没有加载 .dae 文件?例如,当使用图像视图而不是 SceneKit 视图时,并从应用程序包中的资源中选择一些 .png 文件
This是项目的zip文件,如果有人想试一试。
我做了一些广泛的测试,我认为这是一个错误。
IB 属性 除了场景一外,其他都有效。如果删除 GameViewController.swift
中的所有代码,您将看到背景为红色,正如您在 IB 中定义的那样。
我在 Swift 和 Objective-C、iOS 和 OSX、游戏模板和常规应用程序、故事板和经典 IB 中创建了一堆新项目。他们都有同样的问题。
我查看了 IB 文件,没有发现任何异常。 属性 被命名为 sceneName
,所以我不得不检查问题是否来自 Scenekit。
我决定深入挖掘一下,看看问题出在哪里。我发现 SCNView 有一个私有 属性、NSString *__ibSceneName;
。对此进行测试证明它已正确设置。还有一个叫做- (void)set_ibSceneName:(id)arg1;
的私有方法。对其进行子类化证明它被正确调用(尽管它可能只是一个经典 setter)。
为了确保最后一次,我使用仪器记录了所有文件系统交互。以下是普通模板的结果:
这是来自 IB 的结果:
我的猜测是这个函数的实现可能只是丢失了,或者没有正确创建 SCNScene。我会向 Apple 提交错误报告。
同时,您可以简单地将 SCNView 子类化,并添加自定义字符串 属性,例如 myScene
。然后您可以在 IB 中设置它:
然后,只需从 属性 导入场景并在您的自定义子类中将其设置为初始化。如果您需要代码示例,请告诉我!
编辑 7 月 1 日:这是我从 Apple 收到的消息:
We believe this issue has been addressed in the latest Xcode 7 beta. This release includes the Xcode IDE, Swift 2 compiler, Instruments, Simulator, and latest SDKs for OS X, iOS, and watchOS.
Please test with this release. If you still have issues, please provide any relevant logs or information that could help us investigate.
Xcode 7 beta https://developer.apple.com/xcode/downloads/
指定 art.scnassets/ship.dae
而不是 ship.dae
应该可以。