Thanks for being a part of WWDC25!

How did we do? We’d love to know your thoughts on this year’s conference. Take the survey here

SceneKit minimumPointScreenSpaceRadius not work

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;
}
Answered by DTS Engineer in 835038022

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

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

Helo Greg, I have tried setting the pointSize, but that doesn't seem to work Here is my test code:

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.sceneView = [[SCNView alloc] initWithFrame:self.view.frame];
    self.sceneView.backgroundColor = [UIColor grayColor];
    SCNScene *scene = [SCNScene new];
    self.sceneView.scene = scene;
    self.sceneView.allowsCameraControl = YES;
    self.sceneView.showsStatistics = YES;
    [self.view addSubview:self.sceneView];
    SCNNode *camNode = [SCNNode node];
    camNode.name = @"cam";
    camNode.camera = [SCNCamera camera];
    camNode.position = SCNVector3Make(0, 0, 100);
    SCNCameraController *camController = [SCNCameraController new];
    camController.pointOfView = camNode;
    camController.target = SCNVector3Zero;
    [self.sceneView.scene.rootNode addChildNode:camNode];
    self.sceneView.pointOfView = camNode;
    // test cloud point
    NSInteger count = 10000;
    NSMutableData *vertexData = [NSMutableData data];
    NSMutableData *colorData = [NSMutableData data];
    for (int i = 0; i < count; ++i) {
        float x = (float)(arc4random() % 20001) / 100.0f - 100.0f;
        float y = (float)(arc4random() % 20001) / 100.0f - 100.0f;
        float z = (float)(arc4random() % 20001) / 100.0f - 100.0f;
        
        SCNVector3 point = SCNVector3Make(x / 2, y / 2, z / 2);
        [vertexData appendBytes:&point length:sizeof(SCNVector3)];
        float r = (float)(arc4random() % 255) / 255.0f;
        float g = (float)(arc4random() % 255) / 255.0f;
        float b = (float)(arc4random() % 255) / 255.0f;
        [colorData appendBytes:&r length:sizeof(float)];
        [colorData appendBytes:&g length:sizeof(float)];
        [colorData appendBytes:&b length:sizeof(float)];
    }
    
    SCNGeometrySource *vertexSource = [SCNGeometrySource geometrySourceWithData:vertexData
                                                                       semantic:SCNGeometrySourceSemanticVertex
                                                                    vectorCount:count
                                                                floatComponents:YES
                                                            componentsPerVector:3
                                                              bytesPerComponent:sizeof(float)
                                                                     dataOffset:0
                                                                     dataStride:sizeof(SCNVector3)];
    
    SCNGeometrySource *colorSource = [SCNGeometrySource geometrySourceWithData:colorData
                                                                      semantic:SCNGeometrySourceSemanticColor
                                                                   vectorCount:count
                                                               floatComponents:YES
                                                           componentsPerVector:3
                                                             bytesPerComponent:sizeof(float)
                                                                    dataOffset:0
                                                                    dataStride:sizeof(SCNVector3)];
    
    SCNGeometryElement *element = [SCNGeometryElement geometryElementWithData:nil
                                                                primitiveType:SCNGeometryPrimitiveTypePoint
                                                               primitiveCount:count
                                                                bytesPerIndex:sizeof(int)];
    element.pointSize = 10; // set a value, But it doesn't seem to work
    element.minimumPointScreenSpaceRadius = 1.0;
    element.maximumPointScreenSpaceRadius = 10.0;
    
    SCNGeometry *geometry = [SCNGeometry geometryWithSources:@[vertexSource, colorSource] elements:@[element]];
    SCNNode *node = [SCNNode nodeWithGeometry:geometry];
    [self.sceneView.scene.rootNode addChildNode:node];
}

SceneKit minimumPointScreenSpaceRadius not work
 
 
Q