使用SceneKit进行ARKit广告牌效果

klm*_*ll2 2 scenekit sprite-kit ios11 arkit

我希望添加类似于此应用程序的广告牌效果:https://twitter.com/marpi_/status/897130955105644544

我希望使用SCNText几何体的SCNodes始终面向相机.

我试图取得成功:

  • SCNLookAtConstraint与sceneView.pointOfView作为目标,但这会使节点面向远离摄像机的方向,从而导致向后文本,并且无法更改节点位置或欧拉角度.

开箱即用,SKLabelNode将始终面对ARKit中的相机,这正是我想要的,除了使用SCNText.

swa*_*sta 6

你应该看看SCNBillboardConstraint

更新的代码

let textGeometry = SCNText(string: "Hello, World!", extrusionDepth: 1.0)
textGeometry.font = UIFont(name: "Arial", size: 2)
textGeometry.firstMaterial!.diffuse.contents = UIColor.red
let textNode = SCNNode(geometry: textGeometry)

// Update object's pivot to its center
// https://stackoverflow.com/questions/44828764/arkit-placing-an-scntext-at-a-particular-point-in-front-of-the-camera
let (min, max) = textGeometry.boundingBox
let dx = min.x + 0.5 * (max.x - min.x)
let dy = min.y + 0.5 * (max.y - min.y)
let dz = min.z + 0.5 * (max.z - min.z)
textNode.pivot = SCNMatrix4MakeTranslation(dx, dy, dz)

textNode.scale = SCNVector3(0.01, 0.01, 0.01)

let plane = SCNPlane(width: 0.2, height: 0.2)
let blueMaterial = SCNMaterial()
blueMaterial.diffuse.contents = UIColor.blue
plane.firstMaterial = blueMaterial
let parentNode = SCNNode(geometry: plane) // this node will hold our text node

let yFreeConstraint = SCNBillboardConstraint()
yFreeConstraint.freeAxes = .Y // optionally
parentNode.constraints = [yFreeConstraint] // apply the constraint to the parent node

parentNode.position = SCNVector3(0, 0, -0.5)
parentNode.addChildNode(textNode)

sceneView.scene.rootNode.addChildNode(parentNode) // add our text holder to the scene
Run Code Online (Sandbox Code Playgroud)

似乎将广告牌约束直接应用于文本节点会重置其位置和比例,因此文本节点变得很大并且相对于相机定位在0,0,0.不知道为什么:(但是将约束应用于父节点工作正常.


div*_*aki 5

你快到了!

只需修改文本节点的枢轴以将其旋转 180 度 (Obj-C)。

node.pivot = SCNMatrix4MakeRotation(M_PI, 0, 1, 0);
Run Code Online (Sandbox Code Playgroud)