我希望添加与此应用类似的广告牌效果:https://twitter.com/marpi_/status/897130955105644544
我希望使用SCNText几何体的SCNode始终面向相机。
我试图取得成功:
开箱即用,SKLabelNode将始终面向ARKit中的相机,这正是我想要的,除了使用SCNText。
答案 0 :(得分:5)
更新代码
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
似乎将广告牌约束直接应用于文本节点会重置其位置和比例,因此文本节点变得庞大并且相对于相机定位在0,0,0。不知道为什么:(但将约束应用于父节点工作正常。
答案 1 :(得分:4)
你快到了!
只需修改文本节点的枢轴,将其旋转180度(Obj-C)。
node.pivot = SCNMatrix4MakeRotation(M_PI, 0, 1, 0);