Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Metal-generated mesh in SceneKit

Tags:

scenekit

metal

I'm using a Metal compute kernel to generate mesh data (triangle soup, currently).

Is it possible to efficiently (without any copying) bring the mesh data into SceneKit to utilize SceneKit's renderer? The mesh data would be updated frequently, so avoiding copying of data is very important. The number of triangles may also change each frame.

like image 787
Taylor Avatar asked Dec 03 '25 13:12

Taylor


1 Answers

you can pass a MTLBuffer to SCNGeometrySource (no copy):

+ (instancetype)geometrySourceWithBuffer:(id <MTLBuffer>)mtlBuffer vertexFormat:(MTLVertexFormat)vertexFormat semantic:(SCNGeometrySourceSemantic)semantic vertexCount:(NSInteger)vertexCount dataOffset:(NSInteger)offset dataStride:(NSInteger)stride API_AVAILABLE(macos(10.11), ios(9.0));

and you can adjust the number of elements dynamically (actually you can only crop, so you have to pre-allocate a buffer that is large enough) on SCNGeometryElement with:

@property(nonatomic) NSRange primitiveRange API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0));
like image 71
Toyos Avatar answered Dec 07 '25 15:12

Toyos



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!