Skip to content

Instantly share code, notes, and snippets.

@vade
Created July 18, 2014 21:52
Show Gist options
  • Save vade/de705ff3dd8ebbfc6871 to your computer and use it in GitHub Desktop.
Save vade/de705ff3dd8ebbfc6871 to your computer and use it in GitHub Desktop.
Hi Toyos. Thanks for taking the time to read this.
Basically, I have a SCNNode 'Agent' which contain child nodes (maybe a hundred or so) which are simple textured planes which respond to a physics field (or 4).
Every frame, I want to draw a connection between the nodes.
My thought was to :
In the "Agent" node - parent to all the child nodes - override the custom rendering. I would:
A) enumerate the children and get a position of the their presentationNode (so I get correct positions) and make them relative to the Agent nodes coordinate system via convertPosition:
B) Gather that data into a line strip /index for use with something like CPU side Vertex Array (since data changes every frame)
C) Hopefully bind a SCNMaterial I can just make.
D) Draw To GL
E) Happy me!
Right now I think I can gather the positions correctly via presentationNode, but I am unsure of details of C and D, ( I know GL, but it appears i may need a my own shader loaders etc).
Another option was to abuse SCNGeometry and then alter data - but my gut says thats a no-no. I also expect generating SCNGeometry per frame is a bad idea™.
@vade
Copy link
Author

vade commented Jul 18, 2014

Since the Agent node isn't drawing any SCNGeometry (custom rendering), I don't have a SCNGeometry and thus I don't have an SCNMaterial associated. I assume I would have to call some sort of a 'bind' method, or manually load my own shader into this, no?

@toyos
Copy link

toyos commented Jul 18, 2014

I think I would do what you describe with the custom vertex array. But you can't bind a SCNMaterial to it unfortunately. When using a node delegate you have the full control but you loose SceneKit's convenience to render that geometry.
What you would need here is a SCNMutableGeometry that exposes the vertex array data. You should file a request for this.

@vade
Copy link
Author

vade commented Jul 18, 2014

Awesome. Thanks again. I went with the node render delegate and custom GL. Thanks again for the help!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment