UIViewController未加载属性检查器中指定的DAE文件 [英] DAE file specified in attribute inspector is not loaded by UIViewController

查看:115
本文介绍了UIViewController未加载属性检查器中指定的DAE文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Xcode 6.1.1上使用iOS游戏模板创建了一个新项目,选项包括:

 语言:Swift 

游戏技术:SceneKit

设备:通用

应用程序运行正常按原样,但现在我想直接从Xcode上的Interface Builder指定.dae文件,所以我在视图控制器中更改了这样的方法:

 覆盖func viewDidLoad(){
super.viewDidLoad()

让scnView = self.view为SCNView

//如果让scene = scnView.scene {

// !!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
//此处的代码永远不会执行,因为scnView.scene是nil
// !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//为场景创建并添加摄像头
让cameraNode = SCNNode()
cameraNode.camera = SCNCamera()
scene.rootNode.addChildNode(cameraNode) )

//放置相机
cameraNode.position = SCNVector3(x:0,y:0,z:15)

//创建并添加一个光到场景
让lightNode = SCNNode()
lightNode.light = SCNLight()
lightNode.light!.type = SCNLightTypeOmni
lightNode.position = SCNVector3(x:0 ,y:10,z:10)
scene.rootNode.addChildNode(lightNode)

//为场景创建并添加环境光
let ambientLightNode = SCNNode()
ambientLightNode.light = SCNLight()
ambientLightNode.light!.type = SCNLightTypeAmbient
ambientLightNode.light!.color = UIColor.darkGrayColor()
scene.rootNode.addChildNode(ambientLightNode )

//检索ship node
let ship = scene.rootNode.childNodeWithName(ship,递归:true)!

//为3d对象设置动画
ship.runAction(SCNAction.repeatActionForever(SCNAction.rotateByX(0,y:2,z:0,duration:1)))
}
}

...并在故事板上挑选出ship.dae文件这个





为什么不加载.dae文件?例如,当使用图像视图而不是SceneKit视图,并从应用程序包中的资源中选择一些.png文件时





I created a new project using the iOS game template on Xcode 6.1.1, the options were:

Language: Swift

Game Technology: SceneKit

Device: Universal

The app runs ok "as is", but now I want to specify the .dae file directly from the Interface Builder on Xcode, so I changed the method in the view controller like this:

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)))
    }
}

...and picked out the ship.dae file on the storyboard like this

Why isn't the .dae file being loaded? like for instance when using an Image View instead of a SceneKit View, and choosing some .png file from the resources in the application bundle

This is the zip file with the project, if anyone want's to give it a try.

解决方案

I did some extensive testing, and I believe this is a bug.

The IB property all work, besides the scene one. If you remove all the code in GameViewController.swift you will see the background is red, as you defined it in IB.

I created a bunch of new projects, in both Swift and Objective-C, iOS and OSX, Game Template and regular application, Storyboard and classic IB. They all had the same problem.

I looked into the IB file, and did not see anything unusual. The property is named sceneName, so I had to chececk if the problem was from Scenekit.

I decided to dig a little deeper and see where the problem is. I found out SCNView has a private property, NSString *__ibSceneName;. Testing this proved that it is correctly set. There is also a private method called - (void)set_ibSceneName:(id)arg1;. Subclassing it proved that it is correctly called (although it might just be a classic setter).

To make sure one last time, I recorded all filesystem interactions using instruments. Here are the results from the normal template:

and here are the results from IB:

My guess is that the implementation of this function might just be missing, or not properly creating the SCNScene. I'll fill a bug report to Apple about it.

In the meantime, you can simply subclass SCNView, and add a custom string property such as myScene. You can then set it in IB:

Then, simply import the scene from the property and set it on init in your custom subclass. Let me know if you need a code sample!

Edit July 1st: Here's the message I received from 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/

这篇关于UIViewController未加载属性检查器中指定的DAE文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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