简体   繁体   English

SceneKit。 哪种方式起来了?

[英]SceneKit. Which way is up?

It seems that most 3D authoring applications use Z as the 'Up' axis. 似乎大多数3D创作应用程序使用Z作为“向上”轴。 While SceneKit uses Y as the 'Up' axis. 而SceneKit使用Y作为'向上'轴。 SceneKit allows you to load scenes as Collada .DAE files. SceneKit允许您将场景加载为Collada .DAE文件。 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. 您可以指定选项,包括SCNSceneSourceConvertToYUpKey和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. SceneKit不直接在iOS上加载DAE(或ABC)文件 - 它从私有Apple格式加载场景,当您在项目中包含场景文件时,Xcode会自动转换为该格式。 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. 当您只是将DAE文件包含为捆绑资源时,我不相信该选项会暴露。 (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. (这可能是一个很好的文件错误 。)但是,最好使用新的SceneKit资源目录功能,无论如何 - 将DAE文件和任何外部资源(纹理)放入扩展名为.scnassets的文件夹中,和Xcode将一起处理它们以在构建时优化目标设备。 Then, when you select that folder in the Xcode navigator, you'll get an editor for scene building options: 然后,当您在Xcode导航器中选择该文件夹时,您将获得场景构建选项的编辑器:

SceneKit资产目录选项

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.) :)(由于第一个没有解释:交错意味着组织几何的顶点数据,因此您可以获得更好的GPU内存位置,以便在顶点处理期间减少缓存未命中,这对于嵌入式设备的性能非常重要。)

Hm, I don't see anything about units in there, though. 嗯,我在那里看不到任何关于单位的事情。 Might be another good bug to file . 可能是另一个好的bug提交

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

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

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