简体   繁体   中英

How to display (add) plane text node between two points?

How to display distance value plane surface between two points in measurement ARKit/SceneKit? Same as on image.

在此处输入图片说明

Here's a simple principle how to place a label with 3D text between two points.

let p1 = SCNNode()                    // POINT 1
p1.geometry = SCNSphere(radius: 0.3)
p1.position = SCNVector3(-1, -2, -3)
p1.geometry?.firstMaterial?.diffuse.contents = NSColor.red
scene.rootNode.addChildNode(p1)

let p2 = SCNNode()                    // POINT 2
p2.geometry = SCNSphere(radius: 0.2)
p2.position = SCNVector3(4, 5, 6)
p2.geometry?.firstMaterial?.diffuse.contents = NSColor.red
scene.rootNode.addChildNode(p2) 

let x = (p1.position.x + p2.position.x) / 2
let y = (p1.position.y + p2.position.y) / 2
let z = (p1.position.z + p2.position.z) / 2

let label = SCNNode()
let text = SCNText(string: "label", extrusionDepth: 5)
label.geometry = text

// Shifting text's pivot to its center. Default pivot's position is lower left corner.

label.simdPivot.columns.3.x = Float((text.boundingBox.min.x +     
                                     text.boundingBox.max.x) / 2)

label.simdPivot.columns.3.y = Float((text.boundingBox.min.y + 
                                     text.boundingBox.max.y) / 2)

label.scale = SCNVector3(0.02, 0.02, 0.02)
label.position = SCNVector3(x, y, z)
label.geometry?.firstMaterial?.diffuse.contents = NSColor.red
scene.rootNode.addChildNode(label)

let constraint = SCNBillboardConstraint()
label.constraints = [constraint]

let plane = SCNNode()
plane.geometry = SCNPlane(width: 2, height: 1)
plane.position = SCNVector3(x, y, z)
plane.geometry?.firstMaterial?.diffuse.contents = NSColor.white
scene.rootNode.addChildNode(plane)

plane.constraints = [constraint]

The same way you may add ARAnchor and attach any label to it.

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM