相关疑难解决方法(0)

使用SceneKit在两点之间画一条线

我有两个类型SCNVector3的点(我们称之为pointA和pointB).我想在它们之间画一条线.看起来应该很容易,但找不到办法.

我看到两个选项,都有问题:

使用半径非常小的SCNCylinder,长度为| pointA-pointB | 然后定位/旋转它.

使用自定义SCNGeometry但不确定如何; 或许必须定义两个三角形才能形成一个非常薄的矩形?

似乎应该有一种更简单的方法来做到这一点,但我似乎无法找到一个.

编辑:使用三角形方法给我这个在(0,0,0)和(10,10,10)之间画一条线:

CGFloat delta = 0.1;
SCNVector3 positions[] = {  SCNVector3Make(0,0,0),
    SCNVector3Make(10, 10, 10),
    SCNVector3Make(0+delta, 0+delta, 0+delta),
    SCNVector3Make(10+delta, 10+delta, 10+delta)};
int indicies[] = {
    0,2,1,
    1,2,3
};

SCNGeometrySource *vertexSource = [SCNGeometrySource geometrySourceWithVertices:positions count:4];
NSData *indexData = [NSData dataWithBytes:indicies length:sizeof(indicies)];
SCNGeometryElement *element = [SCNGeometryElement geometryElementWithData:indexData primitiveType:SCNGeometryPrimitiveTypeTriangles primitiveCount:2 bytesPerIndex:sizeof(int)];
SCNGeometry *line = [SCNGeometry geometryWithSources:@[vertexSource] elements:@[element]];

SCNNode *lineNode = [SCNNode nodeWithGeometry:line];
[root addChildNode:lineNode];
Run Code Online (Sandbox Code Playgroud)

但是有一些问题:由于法线,你只能从一边看到这条线!它从另一边看不见.此外,如果"delta"太小,则根本看不到该线.实际上,它在技术上是一个矩形,而不是我想要的线,如果我想绘制多个连接线,可能会导致小的图形故障.

opengl macos cocoa objective-c scenekit

21
推荐指数
5
解决办法
2万
查看次数

标签 统计

cocoa ×1

macos ×1

objective-c ×1

opengl ×1

scenekit ×1