Using SCNFloor in ARKIt

In almost all ARKit tutorials, it seems like we always use ARPlane for the floor.

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, 0)

What if you need an endless plane (to cast shadows)? I tried SCNFloor, and the result was strange - the floor was hanging in the air:

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

I did a google search, and the only result I came across was (which also doesn't work): https://github.com/arirawr/ARKit-FloorIsLava/blob/master/FloorIsLava/ViewController.swift

Does SCNFloor () work in ARKit? If not, what can I do to create a large plane?

+4
source share
2 answers

node rootNode, Y :

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

^

, , node . ( Y), SCNVector3Zero .

+1

, , :

let planeGeometry = SCNPlane(width:CGFloat(planeAnchor.extent.x),height:CGFloat(planeAnchor.extent.z)

, , ARKit .

:

let overHang:CGFloat = 0.2
...
let planeGeometry = SCNNode(geometry: SCNPlane(width: CGFloat(planeAnchor.extent.x)+overHang, height: CGFloat(planeAnchor.extent.z)+overHang))

CGFloat, :

let theSize:CGFloat = 4.0
...
let planeGeometry = SCNNode(geometry: SCNPlane(width: theSize, height: theSize))
+1
source

Source: https://habr.com/ru/post/1684642/


All Articles