Я пишу приложение iOS, которое отображает pointcloud в SceneKit с использованием настраиваемой геометрии. This post было очень полезно получить меня там (хотя я перевел это на Objective-C), как и книга Дэвида Роннквиста «3D-графика с SceneKit» (см. Главу о пользовательских геометриях). Код работает отлично, но я хотел бы сделать точки рендеринга при большем размере точки - на данный момент точки очень маленькие.Как вызвать glPointSize() (или эквивалент SceneKit) при создании пользовательских геометрий с использованием SceneKit и SCNGeometryPrimitiveTypePoint
Согласно документам 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];
Можете ли вы объяснить, как этот ответ решает вопрос? – soundslikeodd
Это решение сработало для меня. –