In the SceneKit framework, I want to render a point cloud and need to set the minimumPointScreenSpaceRadius property of the SCNGeometryElement class, but it doesn't work. I searched for related issues on the Internet, but didn't get a final solution. Here is my code:
- (SCNGeometry *)createGeometryWithVector3Data:(NSData *)vData colorData: (NSData * _Nullable)cData{
int stride = sizeof(SCNVector3);
long count = vData.length / stride;
SCNGeometrySource *dataSource = [SCNGeometrySource geometrySourceWithData:vData
semantic:SCNGeometrySourceSemanticVertex
vectorCount:count
floatComponents:YES
componentsPerVector:3
bytesPerComponent:sizeof(float)
dataOffset:0
dataStride:stride];
SCNGeometryElement *element = [SCNGeometryElement geometryElementWithData:nil
primitiveType:SCNGeometryPrimitiveTypePoint
primitiveCount:count
bytesPerIndex:sizeof(int)];
element.minimumPointScreenSpaceRadius = 1.0; // not work
element.maximumPointScreenSpaceRadius = 20.0;
SCNGeometry *pointCloudGeometry;
SCNGeometrySource *colorSource;
if (cData && cData.length != 0) {
colorSource = [SCNGeometrySource geometrySourceWithData:cData
semantic:SCNGeometrySourceSemanticColor
vectorCount:count
floatComponents:YES
componentsPerVector:3
bytesPerComponent:sizeof(float)
dataOffset:0
dataStride:stride];
pointCloudGeometry = [SCNGeometry geometryWithSources:@[dataSource, colorSource] elements:@[element]];
} else {
pointCloudGeometry = [SCNGeometry geometryWithSources:@[dataSource] elements:@[element]];
}
return pointCloudGeometry;
}
Hello @opeli,
The documentation for minimumPointScreenSpaceRadius states:
"To render a geometry element as a point cloud, you must set three properties: pointSize, minimumPointScreenSpaceRadius, and maximumPointScreenSpaceRadius."
Your code does not set the pointSize property.
Please let me know if setting that property resolves your issue!
-- Greg