【问题标题】:SceneKit: Changing the pivot/axis of SceneKit textSceneKit:更改 SceneKit 文本的枢轴/轴
【发布时间】:2016-06-14 03:32:17
【问题描述】:

我通过使用 Interface Builder 将 3D 文本拖到场景中来创建了这个 SceneKit 文本。

它是这样创建的:

轴在左下方。有没有办法使用界面生成器使轴在该文本上居中?

【问题讨论】:

    标签: ios iphone scenekit scnnode


    【解决方案1】:

    不在场景编辑器中。

    在代码中,您可以通过检查边界框来更改节点的轴心以匹配其几何图形的中心点。例如:

    func centerPivot(for node: SCNNode) {
        var min = SCNVector3Zero
        var max = SCNVector3Zero
        node.getBoundingBoxMin(&min, max: &max)
        node.pivot = SCNMatrix4MakeTranslation(
            min.x + (max.x - min.x)/2,
            min.y + (max.y - min.y)/2,
            min.z + (max.z - min.z)/2
        )
    }
    

    【讨论】:

      【解决方案2】:

      Swift 4 更新

      let min = node.boundingBox.min
      let max = node.boundingBox.max
      
      node.pivot = SCNMatrix4MakeTranslation(
          min.x + (max.x - min.x)/2,
          min.y + (max.y - min.y)/2,
          min.z + (max.z - min.z)/2
      )
      

      【讨论】:

      • 接受的评论在 Swift 4 中,但是,这是一种更简单的方法。
      • 编辑:这里的变化是“node.boundBox”而不是“node.getBoundBox”
      猜你喜欢
      • 1970-01-01
      • 2018-03-01
      • 2017-11-30
      • 2018-08-05
      • 2015-03-10
      • 1970-01-01
      • 2019-08-05
      • 2016-06-27
      • 2016-05-16
      相关资源
      最近更新 更多