我正在尝试使用SceneKit渲染点云(最终用于ARKit)。但是,我发现在尝试修改pointSize
时会忽略minimumPointScreenSpaceRadius
(和SCNGeometryElement
)属性。有this解决方案来调用底层的OpenGL属性,但这似乎只适用于模拟。无论我放入什么pointSize
,积分都是相同的。这大致就是我的代码的布局方式。我想知道我的GeometryElement
设置是否有问题?
var index: Int = 0
for x_pos in stride(from: start , to: end, by: increment) {
for y_pos in stride(from: start , to: end, by: increment) {
for z_pos in stride(from: start , to: end, by: increment) {
let pos:SCNVector3 = SCNVector3(x: x_pos, y: y_pos, z: z_pos)
positions.append(pos)
normals.append(normal)
indices.append(index)
index = index + 1
}
}
}
let pt_positions : SCNGeometrySource = SCNGeometrySource.init(vertices: positions)
let n_positions: SCNGeometrySource = SCNGeometrySource.init(normals: normals)
let pointer = UnsafeRawPointer(indices)
let indexData = NSData(bytes: pointer, length: MemoryLayout<Int32>.size * indices.count)
let elements = SCNGeometryElement(data: indexData as Data, primitiveType: .point, primitiveCount: positions.count, bytesPerIndex: MemoryLayout<Int>.size)
elements.pointSize = 10.0 //being ignored
elements.minimumPointScreenSpaceRadius = 10 //also being ignored
let pointCloud = SCNGeometry (sources: [pt_positions, n_positions], elements: [elements])
pointCloud.firstMaterial?.lightingModel = SCNMaterial.LightingModel.constant
let ptNode = SCNNode(geometry: pointCloud)
scene.rootNode.addChildNode(ptNode)
您还应该同时指定element.minimumPointScreenSpaceRadius和element.maximumPointScreenSpaceRadius。如果是这样你的点大小工作! :)