【发布时间】: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