【问题标题】:Get the position of a sphere created in scn file获取在 scn 文件中创建的球体的位置
【发布时间】:2019-06-27 16:32:53
【问题描述】:

我使用 Xcode 创建了一个 scn 文件(如下所示),其中有两个节点(一个球体和一个平台)。我设置了球体的位置:

我使用了一个创建节点平台的类,你可以调整它的大小和移动它:

Screenshot

按下按钮后,它会放置我的 scn 文件而不是那个平台(具有相同的比例、位置和方向)问题是我不知道如何从场景视图中获取球体的位置。

  let sphere = SCNNode()
  self.scene.parent!.enumerateChildNodes { (node, _) in
        if node.name == "sphere" {
            sphere = node
            sphere.position = node.position
            print(sphere.position)
        }
    }

使用该代码,它总是打印我在 scn 文件中设置的位置(如您在上面看到的),但我想要它在视图中的真实位置。

ScreenShot

【问题讨论】:

    标签: swift scenekit arkit scnscene arscnview


    【解决方案1】:

    使用sphere.position,您将获得sphere 相对于其父节点的位置。如果你想要在场景中的位置,你必须使用sphere.worldPosition

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-12-02
      • 2020-05-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-03
      • 1970-01-01
      • 2013-02-27
      相关资源
      最近更新 更多