Bob5421
Bob5421

Reputation: 9183

Big SCNGeometry SceneKit for iOS

I am working on a cocoa/iOS projet. I have a common swift class which manage a Scenekit scene.

I want to draw a big terrain (about 5000x5000 points). I have 2 triangles per 4 points. I have created a scngeometry object for the whole terrain (is it a good thing ?)

I decided to store those points in a 6-Float structure (x,y,z and r,g,b). I tried to create an empty array or to allocate a big array at the begining : i got the same issue. I work with Int datatype for indices array. The project works fine on Cocoa but i get memory errors on iOS. I think this is because of the need to have a big and contigous array for vertex.

I tried to create several chunks of geometry objects but scene kit does not like if we erase a previous buffer.

What is the best practice in this case ?

Is there a way to store vertex on the mass storage instead of memory arrays/buffers ?

Thanks

Upvotes: 2

Views: 637

Answers (1)

Hal Mueller
Hal Mueller

Reputation: 7665

So...twice as many terrain points as there are pixels on a shiny new 5K display? That's a huge amount of memory to be using at once on iOS. And you won't be able to see that resolution on an iOS device.

So how about:

  • Break your 25 million pixel terrain into smaller tiles, each in its own SCNNode. Loop through the tiles, create one SCNNode, throw away the 6-Float array for that tile and move to the next.
  • Use SCNLevelOfDetail to produce much simpler versions of those nodes, for display when they're very far away.
  • Do the construction work on OS X. Archive your scene (NSSecureCoding). Bundle that scene into the iOS app.
  • Consider using reference nodes in your main SCNScene, and archive each tile as a separate SCNScene file.
  • Hopefully you're already using triangle strips, not triangles, to build your geometry.

Upvotes: 2

Related Questions