ARKit - 在 Swift 3 中的平面上的 2 个矢量点之间放置一个 SCNPlane [英] ARKit - place a SCNPlane between 2 vector points on a plane in Swift 3
问题描述
类似于您可以在 ARKit 中看到的一些测量应用程序,我有一个平面,上面有 2 个标记节点,并在 2 个标记节点之间画了一条线.但我需要的是 2 个之间的 SCNPlane.所以,如果你的原件是地板,你在墙的两边放了一个标记,你可以在你的 AR 世界中用 SCNPlane 来代表物理墙.
Similar to some of the measuring apps you can see being demonstrated in ARKit, I have a plane with 2 marker nodes on it and a line drawn between the 2. What I need though is an SCNPlane between the 2. So, if your original was the floor and you put a marker either side of a wall, you could represent the physical wall with a SCNPlane in your AR world.
目前我正在放置带有以下代码的行:
Currently I'm placing the line with the following code:
let line = SCNGeometry.lineFrom(vector: firstPoint.position, toVector: secondPoint.position)
let lineNode = SCNNode(geometry: line)
lineNode.geometry?.firstMaterial?.diffuse.contents = UIColor.white
sceneView.scene.rootNode.addChildNode(lineNode)
行从:
extension SCNGeometry {
class func lineFrom(vector vector1: SCNVector3, toVector vector2: SCNVector3) -> SCNGeometry {
let indices: [Int32] = [0, 1]
let source = SCNGeometrySource(vertices: [vector1, vector2])
let element = SCNGeometryElement(indices: indices, primitiveType: .line)
return SCNGeometry(sources: [source], elements: [element])
}
}
我知道那里有类似的问题:例如 35002232.但我认为我所追求的更简单.那里有一个用户的回答:Windchill 我几乎可以用飞机来工作,但我不禁想到,飞机是一个更简单的对象,必须有一个简单的解决方案.
I know there are similar questions out there: 35002232 for example. But I think what I'm after is simpler. There is an answer there by a user: Windchill that I can almost get to work with a plane but I can't help but think as the plane is a simpler object, there must be a simple solution.
我所需要的只是让平面具有两点之间距离的宽度,我已经知道这一点.而且高度不重要.
All I need is for the plane to have a width of the distance between the 2 points, I already know this. and the height isn't important.
距离计算:
let position = SCNVector3Make(secondPoint.position.x - firstPoint.position.x, secondPoint.position.y - firstPoint.position.y, secondPoint.position.z - firstPoint.position.z)
let result = sqrt(position.x*position.x + position.y*position.y + position.z*position.z)
谢谢
推荐答案
您可以在 ARKit 中的 2 个向量之间创建节点.
You can create a node between 2 vectors in ARKit.
在此处查看 GitHub 项目,https://github.com/max6363/ARKit-LineNode-Between-2-Points.
See GitHub project here, https://github.com/max6363/ARKit-LineNode-Between-2-Points.
继续摇摆....享受....:)
Keep rocking.... Enjoy.... :)
这篇关于ARKit - 在 Swift 3 中的平面上的 2 个矢量点之间放置一个 SCNPlane的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!