【问题标题】:In ARKit placing a node on another node with same orientation在 ARKit 中,将一个节点放在另一个具有相同方向的节点上
【发布时间】:2018-05-22 08:53:01
【问题描述】:

我正在使用 ARKit 创建一个 AR 应用,我必须将电视放在墙上。由于目前 ARKit 不支持垂直平面检测,因此我使用https://github.com/bjarnel/arkit-occlusion 之类的技术创建了一面墙。现在我必须在这面墙上放一台电视机。但是当我将电视模型放在这面墙上时,它的方向不正确。我对电视模型使用与墙壁相同的欧拉角。但我无法正确放置它。

创建墙的代码 -

class func node(from:SCNVector3,
                to:SCNVector3) -> SCNNode {
    let distance = from.distance(vector: to)


    let wall = SCNPlane(width: CGFloat(distance),
                        height: HEIGHT)

    wall.firstMaterial = wallMaterial()
    let node = SCNNode(geometry: wall)

    // always render before the beachballs
    node.renderingOrder = 10

    // get center point
    node.position = SCNVector3(from.x + (to.x - from.x) * 0.5,
                               from.y + Float(HEIGHT) * 0.5,
                               from.z + (to.z - from.z) * 0.5)

    node.eulerAngles = SCNVector3(0, -atan2(to.x - node.position.x, from.z - node.position.z) - Float.pi * 0.5, 0)
    return node
}

将电视模型加载到墙上的代码 -

let tvScene = SCNScene(named: "art.scnassets/\(name)")
let tvNode = tvScene?.rootNode.childNode(withName: "TV", 
recursively: true)
tvNode?.position = SCNVector3(hitResult.worldTransform.columns.3.x, hitResult.worldTransform.columns.3.y, wall.position.z)
tvNode?.eulerAngles = SCNVector3(-90, wall.eulerAngles.y, 180)
           self.sceneView.scene.rootNode.addChildNode(tvNode!)

请帮帮我。

【问题讨论】:

    标签: ios scenekit ios11 augmented-reality arkit


    【解决方案1】:

    我不知道你的角度计算是否正确。但是 SCNNode 需要弧度而不是度数的角度

    SCNVector3(-90, wall.eulerAngles.y, 180)
    

    应该是

    SCNVector3(-.pi / 2, wall.eulerAngles.y, pi)
    

    希望对你有帮助

    【讨论】:

      猜你喜欢
      • 2018-12-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-01-21
      • 1970-01-01
      • 2016-05-03
      相关资源
      最近更新 更多