【问题标题】:How to call glPointSize() (or the SceneKit equivalent) when making custom geometries using SceneKit and SCNGeometryPrimitiveTypePoint使用 SceneKit 和 SCNGeometryPrimitiveTypePoint 制作自定义几何图形时如何调用 glPointSize()(或等效的 SceneKit)
【发布时间】:2016-11-10 11:20:37
【问题描述】:

我正在编写一个 iOS 应用程序,它使用自定义几何体在 SceneKit 中呈现点云。 This post 非常有助于让我到达那里(尽管我将其翻译为 Objective-C),正如 David Rönnqvist 的书 3D Graphics with SceneKit 一样(参见关于自定义几何的章节)。该代码工作正常,但我想让点以更大的点大小呈现 - 目前这些点非常小。

根据 OpenGL 文档,您可以通过调用 glPointSize() 来完成此操作。据我了解,SceneKit 是建立在 OpenGL 之上的,所以我希望有一种方法可以访问此功能或使用 SceneKit 进行等效操作。任何建议将不胜感激!

我的代码如下。我还在 bitbucket 上发布了一个小示例应用程序,可访问 here

// set the number of points
NSUInteger numPoints = 10000;

// set the max distance points
int randomPosUL = 2;
int scaleFactor = 10000; // because I want decimal points
                         // but am getting random values using arc4random_uniform

PointcloudVertex pointcloudVertices[numPoints];

for (NSUInteger i = 0; i < numPoints; i++) {

    PointcloudVertex vertex;

    float x = (float)(arc4random_uniform(randomPosUL * 2 * scaleFactor));
    float y = (float)(arc4random_uniform(randomPosUL * 2 * scaleFactor));
    float z = (float)(arc4random_uniform(randomPosUL * 2 * scaleFactor));

    vertex.x = (x - randomPosUL * scaleFactor) / scaleFactor;
    vertex.y = (y - randomPosUL * scaleFactor) / scaleFactor;
    vertex.z = (z - randomPosUL * scaleFactor) / scaleFactor;

    vertex.r = arc4random_uniform(255) / 255.0;
    vertex.g = arc4random_uniform(255) / 255.0;
    vertex.b = arc4random_uniform(255) / 255.0;

    pointcloudVertices[i] = vertex;

    //        NSLog(@"adding vertex #%lu with position - x: %.3f y: %.3f z: %.3f | color - r:%.3f g: %.3f b: %.3f",
    //              (long unsigned)i,
    //              vertex.x,
    //              vertex.y,
    //              vertex.z,
    //              vertex.r,
    //              vertex.g,
    //              vertex.b);
}

// convert array to point cloud data (position and color)
NSData *pointcloudData = [NSData dataWithBytes:&pointcloudVertices length:sizeof(pointcloudVertices)];

// create vertex source
SCNGeometrySource *vertexSource = [SCNGeometrySource geometrySourceWithData:pointcloudData
                                                                   semantic:SCNGeometrySourceSemanticVertex
                                                                vectorCount:numPoints
                                                            floatComponents:YES
                                                        componentsPerVector:3
                                                          bytesPerComponent:sizeof(float)
                                                                 dataOffset:0
                                                                 dataStride:sizeof(PointcloudVertex)];

// create color source
SCNGeometrySource *colorSource = [SCNGeometrySource geometrySourceWithData:pointcloudData
                                                                  semantic:SCNGeometrySourceSemanticColor
                                                               vectorCount:numPoints
                                                           floatComponents:YES
                                                       componentsPerVector:3
                                                         bytesPerComponent:sizeof(float)
                                                                dataOffset:sizeof(float) * 3
                                                                dataStride:sizeof(PointcloudVertex)];

// create element
SCNGeometryElement *element = [SCNGeometryElement geometryElementWithData:nil
                                                            primitiveType:SCNGeometryPrimitiveTypePoint
                                                           primitiveCount:numPoints
                                                            bytesPerIndex:sizeof(int)];

// create geometry
SCNGeometry *pointcloudGeometry = [SCNGeometry geometryWithSources:@[ vertexSource, colorSource ] elements:@[ element]];

// add pointcloud to scene
SCNNode *pointcloudNode = [SCNNode nodeWithGeometry:pointcloudGeometry];
[self.myView.scene.rootNode addChildNode:pointcloudNode];

【问题讨论】:

    标签: ios scenekit point-clouds


    【解决方案1】:

    我自己正在研究在 ios 中渲染点云,并通过“vade”在 twitter 上找到了一个解决方案,并认为我将其发布在这里供其他人使用:

    专业提示:SceneKit 着色器修改器很有用:

    mat.shaderModifiers = @{SCNShaderModifierEntryPointGeometry : @"gl_PointSize = 16.0;"};
    

    【讨论】:

      猜你喜欢
      • 2016-04-01
      • 2016-04-26
      • 2016-11-25
      • 2019-03-02
      • 2021-08-01
      • 2017-11-12
      • 1970-01-01
      • 2013-07-19
      • 2019-05-16
      相关资源
      最近更新 更多