我有一个块正在传递数据,我想将其转换为浮点数组 - 例如 [[0.1,0.2,0.3, 1.0], [0.3, 0.4, 0.5, 1.0], [0.5, 0.6、0.7、1.0]]。data:UnsafeMutablePointer<UnsafeMutableRawPointer>
此数据以(内部数组是 RGBA 值)的形式传递给我
fwiw -- 块参数来自SCNParticleEventBlock
如何将数据取消引用到 [[Float]]?一旦我有了包含内部数组的数组,我可以使用以下方法引用内部数组 (colorArray) 数据:
let rgba: UnsafeMutablePointer<Float> = UnsafeMutablePointer(mutating: colorArray)
let count = 4
for i in 0..<count {
print((rgba+i).pointee)
}
fwiw - 这是 Apple 用于引用数据的示例 Objective-C 代码(来自 SCNParticleSystem handle(_:forProperties:handler:))
[system handleEvent:SCNParticleEventBirth
forProperties:@[SCNParticlePropertyColor]
withBlock:^(void **data, size_t *dataStride, uint32_t *indices , NSInteger count) {
for (NSInteger i = 0; i < count; ++i) {
float *color = (float *)((char *)data[0] + dataStride[0] * i);
if (rand() & 0x1) { // Switch the green and red color components.
color[0] = color[1];
color[1] = 0;
}
}
}];