4

I'm building a game using SceneKit and I can't decide is it better to store .dae model in .scnassets folder and load .dae model or create model programmatically in runtime using Vertices/Indecies/Normals.

In case of performance is it worth to create SCNGeometry manually with SCNGeometrySource and SCNGeometryElement using Vertices/Indecies/Normals? Or it is fine just to load model using SCNScene(named: "Scenes.scnassets/ModelName.scn")?

Manifestor
  • 575
  • 5
  • 19

2 Answers2

1

You mentioned three approaches: DAE files, SCN files, and programmatically generated geometry. SCN and DAE are not the same thing. DAE is an XML format (compressed, for iOS targets, using Apple's internal scntool). SCN is an archived NSObject.

The fastest performance will come from using a SceneKit Scene Document (.SCN file).

If your model is already built in a 3D tool, you can import the DAE file and save it as SCN using Xcode's scene editor (how to convert .dae to .scn files in SceneKit). You can create this programmatically from your SCNScene instance with NSSecureCoding.

Use SCNGeometrySource (or SCNGeometry) if you have to generate your scene programmatically. But if you can build it before your app ships, you should write an auxiliary program to do the scene creation, and then archive with NSSecureCoding. Then you'll have a .SCN file you can embed in the final product.

Take a look at the Model I/O framework for more file format options (specifically MDLAsset).

Hal Mueller
  • 7,019
  • 2
  • 24
  • 42
  • Thank you for reply Hal. Sorry for pointing .dae, actually I'm using .scn converted from .dae and the choice is between manual generating geometry and loading it from .scn file. I thing that generating geometry programmatically is faster because there is no need to open and unarchive file (.scn). – Manifestor Dec 10 '16 at 09:03
  • Measure. If you've already written the code to generate geometry programmatically, you can quickly write a timed test to compare unarchiving to on-the-fly creation. – Hal Mueller Dec 10 '16 at 09:08
1

I agree with Hal, using SceneKit's native file format would be best (.scn).

I just wanted to share with you some of my insights on the question of importing models from Collada files or to create them programmatically using vertex/index/normals.

From my personal testing I noticed Collada files import geometry using unique vertices, while importing geometry programmatically you can use shared vertices.

As an example, I imported a model using shared vertices that came out to be around 70K vertices. When I imported that same model using Collada (unique vertices) the vertex count went over 200K.

Good luck with your SceneKit game!

Phi
  • 157
  • 1
  • 8
  • Oh that's a useful tidbit! Have you compared Collada to other Model I/O supported formats for that same model? – Hal Mueller Dec 13 '16 at 22:15
  • Actually I have, they all use unique vertices. The only way I've found to use shared vertices is to do it programmatically. Yea I was really surprised when I learned this, especially when developing for mobile devices where every bit counts. Good to see you around Hal thanks for helping the community so much. – Phi Dec 13 '16 at 22:17
  • Just another detail to keep in mind. If you import your model programmatically to use shared vertices, if you export that model in any other format besides .scn it will convert it back to unique vertices. – Phi Dec 13 '16 at 22:23