Note that there are some explanatory texts on larger screens.

plurals
  1. POSceneKit on OS X with thousands of objects
    primarykey
    data
    text
    <p>I'm following this tutorial: <a href="http://blog.bignerdranch.com/754-scenekit-in-mountain-lion/">http://blog.bignerdranch.com/754-scenekit-in-mountain-lion/</a></p> <p>I'm interested in using Scene Kit, but my scenes might potentially have thousands of spheres. To stress-test Scene Kit I tried this:</p> <pre><code>SCNSphere *sphere = [SCNSphere sphereWithRadius:0.5]; for (int i=0; i&lt;10; i++) { for(int j=0; j&lt;10; j++){ for(int k=0; k&lt;10; k++){ SCNNode *myNode = [SCNNode nodeWithGeometry:sphere]; myNode.position = SCNVector3Make(i,j,k); [root addChildNode:myNode]; } } } </code></pre> <p>This works fine for, say, 1000 spheres (10^3) but fails (perhaps unsurprisingly) for 1,000,000 spheres (100^3). I don't mind not being able to use a million spheres, but I'd like to work out what the sensible upper bound is (5,000? 15,000?) and how to increase it.</p> <p>What can I do to mitigate this? e.g. I've tried sphere.segmentCount = 3 and while that speeds up rendering, it doesn't have much effect on memory usage, which I suspect is the limiting factor.</p> <p>Also, there doesn't seem to be a SCNPoint class. I was thinking about switching to just displaying a point when the number of spheres is too high, but I can't see from the SceneKit documentation how to display a simple point -- the simplest I can see is a triangle.</p> <p>Any help is much appreciated.</p> <p><strong>Edit:</strong> @toyos suggested that the SCNSphere objects are merged into single SCNGeometry object (provided they don't need to be independently animated, which they don't), but I can't find an easy way to do this.</p> <p>SCNGeometry is created by using <code>[SCNGeometry geometryWithSources:(* NSArray)sources geometryWithElements:(* NSArray) elements]</code> as documented <a href="https://developer.apple.com/library/mac/#documentation/SceneKit/Reference/SCNGeometry_Class/Reference/SCNGeometry.html">here</a>, but I'm not clear as to how to create an <code>SCNGeometry</code> object from my spheres.</p> <p>e.g. for a single sphere, I could see using <code>sphere.geometryElementCount</code> to get the number of elements and then using that to populate an array using <code>[sphere geometryElementAtIndex:(NSInteger)elementIndex]</code> which would give me the elements, but I'm not sure how to get the "sources" (or what they even are). The method to get the geometry sources is <code>[sphere geometrySourcesForSemantic:(NSString*) semantic]</code>, but what is this semantic string? (is it meant to be "normals" or "vertices" or is this something else? the documentation quite helpfully says the semantic is "The semantic value of the geometry source." without saying what possible values of the semantic are)</p> <p>That's just for a single sphere, which would be fairly pointless (since <code>SCNSphere</code> is just a subclass of <code>SCNGeometry</code> anyway), so now I have to add multiple spheres. So would I have to manually translate the vertices of the sphere when adding them to my <code>SCNGeometry</code> object?</p> <p>I'm just trying to figure out the most sensible way to do this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload