实际上,我正在工作名片图像检测以显示那里的业务资料。 我已经实现了图像检测,平面动画。这是我的问题,当检测到图像以及飞机时,应显示用户名标签,个人资料和网站。我正在尝试显示用户名标签,但是我已经在SCNText中完成了。如何使用SCNNode标签用户iamge。
这是我尝试的代码:
guard let imageAnchor = anchor as? ARImageAnchor else {return}
if let imageName = imageAnchor.referenceImage.name {
print(imageName)
if imageName == "card" {
// let planeGeometry = SCNPlane(width: 25, height: 25)
// planeGeometry.firstMaterial?.isDoubleSided = true
// planeGeometry.firstMaterial?.diffuse.contents = UIColor.blue.withAlphaComponent(0.5)
//--
let plane = SCNPlane(width: 4,
height: 10)
plane.firstMaterial?.diffuse.contents = UIColor.init(red: 0, green: 189, blue: 255, alpha: 0.88)
plane.cornerRadius = 0.25
let planeNode = SCNNode(geometry: plane)
planeNode.opacity = 0.25
planeNode.eulerAngles.x = -.pi / 2
// planeNode.position = SCNVector3(x:0, y:0, z:2)
planeNode.runAction(SCNAction.moveBy(x: 0, y: 0, z: 5, duration: 0.5))
let nameText = SCNText()
nameText.firstMaterial?.diffuse.contents = "Gowdhaman"
nameText.font = UIFont(name: "Avenir-medium", size: 16)
nameText.firstMaterial?.diffuse.contents = UIColor.red
nameText.firstMaterial?.diffuse.contents = SCNVector3.init(0, 0, 0)
// nameText.firstMaterial?.diffuse.contents =
// nameText.firstMaterial?.diffuse.contents = SCNAction.moveBy(x: 0, y: 0, z: 5, duration: 1)
let nameLabelNode = SCNNode(geometry: nameText)
let eulerAngles =
self.sceneView.session.currentFrame?.camera.eulerAngles
nameLabelNode.eulerAngles = SCNVector3((eulerAngles?.x)!,
(eulerAngles?.y)!, (eulerAngles?.z)! - .pi/6)
planeNode.addChildNode(nameLabelNode)
node.addChildNode(planeNode)
self.sceneView.scene.rootNode.addChildNode(node)
}
}
答案 0 :(得分:1)
我目前正在从事一个非常相似的项目!我尝试过的一件事是创建一个SCNPlane,然后将其内容设置为renderer函数内部的图像
func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {
let node = SCNNode()
......
// create a plane to contain the image
let profilePlane = SCNPlane(width: 0.035, height: 0.035)
// Add the profile picture file in your assets folder to the contents of your plane
profilePlane.firstMaterial?.diffuse.contents = "ProfilePictureName"
let profilePlaneNode = SCNNode(geometry: profilePlane)
node.addChildNode(profilePlaneNode)
}
使用此代码,它将在imageAnchor的中心生成一个正方形,因此您需要在之后调整一些内容