I created a SCNBox in real time based on a group of anchors that I do not know the locations in advance. I create the SCNBox using the following code:
let nodes: [SCNNode] = getMyNodes()
for node in nodes {
if(sceneView.anchor(for: node)?.name != nil) && (sceneView.anchor(for: node)?.name != "dot"){
parentNode.addChildNode(node)
}
}
let width = (abs(parentNode.boundingBox.0.x) + abs(parentNode.boundingBox.1.x))
let height = (abs(parentNode.boundingBox.0.y) + abs(parentNode.boundingBox.1.y))
let length = (abs(parentNode.boundingBox.0.z) + abs(parentNode.boundingBox.1.z))
let box = SCNBox(width: CGFloat(width), height: CGFloat(height), length: CGFloat(0.3), chamferRadius: 0)
let boxNode = SCNNode(geometry: box)
boxNode.position = parentNode.boundingSphere.center
box.firstMaterial?.diffuse.contents = UIColor.white
box.firstMaterial?.transparency = 0.4
boxNode.position = parentNode.boundingSphere.center
boxNode.name = "box"
boxNode.addChildNode(parentNode)
sceneView.scene.rootNode.addChildNode(boxNode)
boundingBox = boxNode
So how do I get the vertices position of the box? The geometry of the node contains the location, length, width and height but it does not contain the location of its vertices.
I also obtain the the location of the finger using the vision framework. I need to know the location of the vertex so I can enlarge or shrink the box with respect to the finger location. I tried to to calculate the vertex using the position of the center and the length and with but the location does not add back to the finger location. I think this has to do something with different scale system.