加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

swift – 在ARKIt中使用SCNFloor

发布时间:2020-12-14 04:58:04 所属栏目:百科 来源:网络整理
导读:几乎在ARKit的所有教程中,似乎我们总是使用ARPlane作为地板. let planeGeometry = SCNPlane(width:CGFloat(planeAnchor.extent.x),height:CGFloat(planeAnchor.extent.z))let planeNode = SCNNode(geometry:planeGeometry)planeNode.position = SCNVector3(x
几乎在ARKit的所有教程中,似乎我们总是使用ARPlane作为地板.

let planeGeometry = SCNPlane(width:CGFloat(planeAnchor.extent.x),height:CGFloat(planeAnchor.extent.z))
let planeNode = SCNNode(geometry:planeGeometry)
planeNode.position = SCNVector3(x:planeAnchor.center.x,y:0,z:planeAnchor.center.y)
planeNode.transform = SCNMatrix4MakeRotation(-Float.pi / 2,1.0,0)

如果你想要一个无限平面(用于投射阴影)怎么办?我试过SCNFloor,结果很奇怪 – 地板挂在半空中:

let planeGeometry = SCNFloor()
let planeNode = SCNNode(geometry:planeGeometry)
planeNode.position = SCNVector3(planeAnchor.center.x,planeAnchor.center.z)

我已经完成了谷歌搜索,我得到的唯一结果就是这个(这也行不通):https://github.com/arirawr/ARKit-FloorIsLava/blob/master/FloorIsLava/ViewController.swift

SCNFloor()在ARKit中有效吗?如果没有,我该怎么做才能创造出一架大飞机?

解决方法

如果将地板节点添加到rootNode中,则应更改Y位置:

planeNode.position = SCNVector3(planeAnchor.center.x,-1.0,planeAnchor.center.z)

在这种情况下,我使用减一米^

您可以使用表面检测来查找地板表面锚点,然后将地板添加到此锚点的相关节点中.锚点的世界坐标已经正确(减去Y),因此您可以使用SCNVector3Zero作为地板的位置.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读