Hi,
I'm trying to understand what SceneKit does to load assets — when it loads them, where it loads them, etc..
I cannot find detailed documentation on this but maybe I'm looking in the wrong place. The best I've found so far
is the discussion sections in the API docs for SCNSceneRenderer.prepare(_:withCompletionHandler: ) and SCNSceneRenderer.prepare(_:shouldAbortBlock: ).
Both of these methods have discussion sections that say the following:
By default, SceneKit lazily loads resources onto the GPU for rendering. This approach uses memory and GPU bandwidth efficiently, but can lead to stutters in an otherwise smooth frame rate when you add large amounts of new content to an animated scene. To avoid such issues, use this method to prepare content for drawing before adding it to the scene. You can call this method on a secondary thread to prepare content asynchronously.
SceneKit prepares all content associated with the
parameter you provide. If you provide anobject
object, SceneKit loads any texture images assigned to its material properties. If you provide anSCNMaterial
object, SceneKit loads all materials attached to the geometry, as well as its vertex data. If you provide anSCNGeometry
orSCNNode
object, SceneKit loads all geometries and materials associated with the node and all its child nodes, or with the entire node hierarchy of the scene.SCNScene
...
You can observe the progress of this operation with the
class. For details, seeProgress
.Progress
This raises more questions for me, some of them probably pretty basic (I'm no expert in 3D graphics programming), and some maybe not so dumb:
- Does "loads resources onto the GPU" mean it is loading the assets into dedicated memroy separate from normal RAM? Or into normal RAM reserved for the GPU? Or into some kind of memory that's actually on the GPU? (This is the dumb question, I bet.)
- How many assets can be loaded ahead of time in this way?
- What happens if I try to load more than can fit?
- If SceneKit uses "a secondary thread to prepare content asynchronously", what happens if I try to access the content before the background loading operation completes? Does my access block or fail?
- If I can observe the operation with an NSProgress object, then how come these methods do not return NSProgress instances? Or how come the SCNSceneRenderer does not provide an accessor to get return an NSProgress instance?
I'd appreciate any insight into these questions, or pointers to WWDC videos, documentation, or third-party books that go into enough detail that they would address these questions.
Thanks!