【问题标题】:ARKit billboarding effect with SceneKit带有 SceneKit 的 ARKit 广告牌效果
【发布时间】:2018-01-25 04:22:51
【问题描述】:

我正在寻找与此应用程序类似的广告牌效果:https://twitter.com/marpi_/status/897130955105644544

我希望使用 SCNText 几何图形的 SCNode 始终面向相机。

我尝试过但没有成功:

  • SCNLookAtConstraint 以sceneView.pointOfView 为目标,但这会旋转节点使其背向相机,导致文本向后,并且无法更改节点位置或欧拉角。

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

【问题讨论】:

    标签: sprite-kit scenekit ios11 arkit


    【解决方案1】:

    你应该看看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
    

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

    【讨论】:

    • 对我来说,这似乎是一个比使用约束 + 旋转更好的解决方案,但由于某种原因我无法让 textNode 出现在场景中。
    • 我的textNode 也不会与SCNBillboardConstraint 一起出现!有人有运气吗?
    • 我觉得应该是:billboardConstraint.freeAxes = [.Y]
    【解决方案2】:

    你快到了!

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

    node.pivot = SCNMatrix4MakeRotation(M_PI, 0, 1, 0);
    

    【讨论】:

    • 谢谢!这按预期工作。我之前尝试过旋转和rotateby,但都没有工作。
    • 您可能也想查看 SCNBillboardConstraint 而不是 SCNLookAtConstraint。
    猜你喜欢
    • 2021-12-15
    • 2018-12-25
    • 2019-12-27
    • 2020-06-24
    • 2017-02-17
    • 2013-11-12
    • 1970-01-01
    • 2017-11-27
    • 1970-01-01
    相关资源
    最近更新 更多