【问题标题】:pointSize property in SceneKit being IgnoredSceneKit 中的 pointSize 属性被忽略
【发布时间】:2018-09-03 01:23:43
【问题描述】:

我正在尝试使用 SceneKit(最终用于 ARKit)渲染点云。但是,我发现在尝试修改SCNGeometryElement 时忽略了pointSize(和minimumPointScreenSpaceRadius)属性。有 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)  

【问题讨论】:

  • 你在使用 SceneKit 的 Metal 渲染器吗?那是SCNRenderingAPIMetal,这是设备上的默认设置(iOS 模拟器不支持 Metal),并且没有 PrefersOpenGL 设置。
  • 哦!所以这行得通!我使用的是 Metal Renderer 而不是 OpenGL。一旦我将 PrefersOpenGL 设置为 Yes,glPointSize 命令就可以正常工作。这是有道理的。但问题是:如何更改默认 Metal 渲染器上的粒子大小?
  • 我的意思是您应该使用 Metal 渲染器。 pointSizeminimumPointScreenSpaceRadius 仅适用于 Metal 渲染器,我想确保您不使用 OpenGL。
  • 哦。我明白你的意思了。所以我最初没有任何PrefersOpenGL 设置。我假设它默认为金属。有没有其他方法可以确保这一点?
  • @pj_mukh 感谢您的快速回答!它现在确实适用于金属..我只是没有检查 pointSize = 1 是默认值......所以设置为它时它没有改变......(:

标签: swift scenekit


【解决方案1】:

您还应该同时指定 element.minimumPointScreenSpaceRadius 和 element.maximumPointScreenSpaceRadius。如果是这样,您的磅值有效! :)

【讨论】:

    猜你喜欢
    • 2013-01-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-01-15
    相关资源
    最近更新 更多