我目前正在尝试将 SCNNode 固定到位,同时使用 ARImageTrackingConfiguration,它没有平面检测,但似乎无法正常工作,因为 SCNNode 在移动时相机移动
下面是代码:
/// show cylinder line
func showCylinderLine(point a: SCNVector3, point b: SCNVector3, object: VirtualObject) {
let length = Vector3Helper.distanceBetweenPoints(a: a, b: b)
let cyclinderLine = GeometryHelper.drawCyclinderBetweenPoints(a: a, b: b, length: length, radius: 0.001, radialSegments: 10)
cyclinderLine.name = "line"
cyclinderLine.geometry?.firstMaterial?.diffuse.contents = UIColor.red
self.sceneView.scene.rootNode.addChildNode(cyclinderLine)
cyclinderLine.look(at: b, up: self.sceneView.scene.rootNode.worldUp, localFront: cyclinderLine.worldUp)
}
是否可以在不使用 ARPlaneAnchor 的情况下将圆柱体线 SCNNode 固定到位?
(注意:我在nodeForAnchor委托(delegate)方法上尝试过ARAnchor,它仍然随着相机移动而移动)
最佳答案
你能展示一下你的nodeForAnchors方法吗? 这就是节点“固定”到图像的地方,所以我猜测某处存在错误。以下是该委托(delegate)的一个示例应用程序:
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
if let _ = anchor as? ARImageAnchor {
if let objectScene = SCNScene(named: "ARassets.scnassets/object.scn") {
//creates a new node that is connected to the image. This is what makes your object "fixed"
let objectNode = objectScene.rootNode.childNodes.first!
objectNode.position = SCNVector3Zero
objectNode.position.y = 0.15
node.addChildNode(planeNode)
}
}
请告诉我这是否有帮助;)
关于ios - 将 SCNNode 固定到位,无需 ARPlaneAnchor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53589929/