【问题标题】:Metal-generated mesh in SceneKitSceneKit 中的金属生成网格
【发布时间】:2018-02-16 18:34:49
【问题描述】:

我正在使用 Metal 计算内核来生成网格数据(目前是三角形汤)。

是否可以有效地(无需任何复制)将网格数据导入 SceneKit 以利用 SceneKit 的渲染器?网格数据会经常更新,因此避免数据复制非常重要。三角形的数量也可能在每一帧中发生变化。

【问题讨论】:

    标签: scenekit metal


    【解决方案1】:

    您可以将 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));
    

    【讨论】:

    猜你喜欢
    • 2017-03-21
    • 2015-09-05
    • 2016-10-08
    • 1970-01-01
    • 1970-01-01
    • 2018-11-06
    • 1970-01-01
    • 2019-12-27
    • 2020-07-22
    相关资源
    最近更新 更多