klm*_*ll2 2 scenekit sprite-kit ios11 arkit
我希望添加类似于此应用程序的广告牌效果:https://twitter.com/marpi_/status/897130955105644544
我希望使用SCNText几何体的SCNodes始终面向相机.
我试图取得成功:
开箱即用,SKLabelNode将始终面对ARKit中的相机,这正是我想要的,除了使用SCNText.
更新的代码
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.不知道为什么:(但是将约束应用于父节点工作正常.
你快到了!
只需修改文本节点的枢轴以将其旋转 180 度 (Obj-C)。
node.pivot = SCNMatrix4MakeRotation(M_PI, 0, 1, 0);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2437 次 |
| 最近记录: |