SceneKit。哪种方式起来了? [英] SceneKit. Which way is up?

查看:139
本文介绍了SceneKit。哪种方式起来了?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

似乎大多数3D创作应用程序都使用Z作为向上轴。而SceneKit使用Y作为'向上'轴。 SceneKit允许您将场景加载为Collada .DAE文件。通过以下任一方式加载场景时:

  SCNScene(名为:String?,inDirectory:String ?, options:[NSObject:AnyObject] ?)

  SCNSceneSource(URL网址:NSURL!,选项:[NSObject:AnyObject]!)

您可以指定选项,包括SCNSceneSourceConvertToYUpKey和SCNSceneSourceConvertUnitsToMetersKey。



相应地设置这些,我预计当我将它们添加到从加载场景中的节点构造的我自己的场景中时,各个节点将被转换和缩放。但这些选项似乎没有效果。

 让myScene = SCNScene(名为:Scene.dae,inDirectory:nil,options:[SCNSceneSourceConvertToYUpKey:true,SCNSceneSourceConvertUnitsToMetersKey: 25.4])

我是否误解了这些选项参数的含义?

解决方案

SceneKit不直接在iOS上加载DAE(或ABC)文件 - 它从私有Apple格式加载场景,Xcode会在您包含场景时自动转换为项目中的文件。转换的一部分是转换向上轴的选项。



当您只是将DAE文件作为捆绑资源包含时,我不相信该选项会被公开。 (这可能是。



这里有另一个选项 - 所有SceneKit对象都实现 NSSecureCoding 协议,因此您可以在OS X上加载和预处理场景,然后使用 NSKeyedArchiver 把它写出来。将生成的文件作为捆绑包资源包含在iOS项目中,Xcode不会对其进行预处理(它已经过压缩和优化) - 如果您使用 .scn <命名它/ code>扩展名,您可以使用所有 SCNScene SCNSceneSource 方法加载它就像你一样一个(预处理的)DAE文件。


It seems that most 3D authoring applications use Z as the 'Up' axis. While SceneKit uses Y as the 'Up' axis. SceneKit allows you to load scenes as Collada .DAE files. When loading a Scene via either:

SCNScene(named: String?, inDirectory: String?, options: [NSObject : AnyObject]?)

or

SCNSceneSource(URL url: NSURL!, options: [NSObject : AnyObject]!)

You can specify options including SCNSceneSourceConvertToYUpKey and SCNSceneSourceConvertUnitsToMetersKey.

Setting these accordingly, I expected the various nodes to be transformed and scaled when I added them to my own scene constructed from Nodes in the loaded scene. But these options appear to have no effect.

let myScene = SCNScene(named: "Scene.dae", inDirectory: nil, options: [SCNSceneSourceConvertToYUpKey:true, SCNSceneSourceConvertUnitsToMetersKey:25.4])

Have I misunderstood the meaning of these option parameters?

解决方案

SceneKit does not directly load DAE (or ABC) files on iOS -- it loads scenes from a private Apple format, which Xcode automatically converts to when you include scene files in your project. Part of this conversion is the option to transform the up axis.

I don't believe that option is exposed when you simply include the DAE file as a bundle resource. (That might be a good bug to file.) However, it's a good idea to use the new SceneKit Asset Catalog feature instead, anyway -- put your DAE files and whatever external resources (textures) into a folder with a .scnassets extension, and Xcode will process them together to optimize for the target device when you build. Then, when you select that folder in the Xcode navigator, you'll get an editor for scene building options:

All the boxes there are good to check. :) (Since the first one doesn't come with an explanation: interleaving means organizing the vertex data for a geometry so you get better GPU-memory locality for fewer cache misses during vertex processing, which is important for performance on embedded devices.)

Hm, I don't see anything about units in there, though. Might be another good bug to file.

There's another option, too -- all SceneKit objects implement the NSSecureCoding protocol, so you can load and preprocess your scene on OS X, then use NSKeyedArchiver to write it out. Include the resulting file in your iOS project as a bundle resource, and Xcode won't preprocess it (it's already as compressed and optimized as it can get) -- and if you name it with an .scn extension, you can use all the SCNScene and SCNSceneSource methods for loading it just like you would a (preprocessed) DAE file.

这篇关于SceneKit。哪种方式起来了?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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