我正在使用 Metal 计算内核生成网格数据(目前是三角汤)。
是否可以高效(无需任何复制)将网格数据导入 SceneKit 以利用 SceneKit 的渲染器?网格数据会经常更新,因此避免数据复制非常重要。三角形的数量也可能在每一帧发生变化。
最佳答案
您可以将 MTLBuffer 传递给 SCNGeometrySource(无副本):
+ (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));
并且你可以在 SCNGeometryElement 上动态调整元素的数量(实际上你只能裁剪,所以你必须预先分配一个足够大的缓冲区):
@property(nonatomic) NSRange primitiveRange API_AVAILABLE(macos(10.13), ios(11.0), tvos(11.0), watchos(4.0));
关于scenekit - SceneKit 中 Metal 生成的网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46106212/