Manifestor
Manifestor

Reputation: 615

When to use SCNGeometrySource

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")?

Upvotes: 4

Views: 856

Answers (2)

Phi
Phi

Reputation: 157

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!

Upvotes: 1

Hal Mueller
Hal Mueller

Reputation: 7646

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

Upvotes: 1

Related Questions