从起始值到结束值ARKit绘制直线

时间:2017-08-28 10:00:15

标签: ios swift arkit

一如既往,我需要你的帮助。我需要从起始值(声明为SCNVector3)绘制一条直线并连接到现实世界中的位置直到结束点。

有人可以用一些代码向我解释我该怎么办? 谢谢!

1 个答案:

答案 0 :(得分:4)

您需要实施: <div id="popUp"></div> <button onclick="popUp(this, 'im pop text', 'aqua')"> POP </button> <button onclick="clearPop()"> CLOSE </button> <script type="text/javascript"> function popUp(event, text, color) { var popElem = document.getElementById("popUp"); var x = window.event.clientX + 15; var y = window.event.clientY + 15; popElem.style.left = x + "px"; popElem.style.top = y + "px"; popElem.style.backgroundColor = color; popElem.innerHTML = text; popElem.style.display = "block"; } function clearPop() { var popElem = document.getElementById('popUp'); popElem.style.display = "none"; } </script>touchesBegantouchesMovedtouchesEnded 为您的相机视图控制器。 在touchesCancelled中,您需要为touchesBegan位置的当前ARFrame设置hitTest。然后,您将拥有UITouchstartPosition,这是您的开始lastTouch

然后你需要添加UITouch间隔(60Hz)的计时器,当相机移动时,它会用0.016_667更新你的最后一个触摸位置。你将在hitTest函数中做同样的事情。在touchesMoved中,您还会更新touchesMoved。因此,此时您将拥有lastTouchstartPosition,即currentPosition。如果你需要直线,你可以重新绘制SCNCylinder(例如,半径为0.001米)。

SCNVector3的最后一步,你将修复你的行,或者如果touchesEnded你将删除它并清除touchesCancelled

<强> UPD

如果您需要在屏幕上显示2D行,那么您需要为您的ARSceneView使用lastTouch

3D线条图

为了绘制3D线,您可以projectPoint使用扩展名:

SCNGeometry

使用:

extension SCNGeometry {
    class func line(from vector1: SCNVector3, to 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])
    }
}