我目前正在尝试使用 ARImageTrackingConfiguration 时将SCNNode 固定在适当位置,该操作没有进行平面检测,但由于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的情况下将cylinderLine SCNNode固定在适当的位置?
(注意:我曾在nodeForAnchor委托方法上尝试过ARAnchor,但随着相机移动,它仍在移动)
答案 0 :(得分:0)
您可以显示您的nodeForAnchors方法吗? 那是节点被“固定”到图像的地方,所以我猜测某个地方存在错误。这是该委托的一个示例应用程序:
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)
}
}
让我知道这是否有帮助;)