代码之家  ›  专栏  ›  技术社区  ›  PvDev

如何在arkit中添加带有手势动作的scnnode中的标签节点和用户图像?

  •  0
  • PvDev  · 技术社区  · 6 年前

    实际上,我正在工作名片图像检测,以显示那里的业务概况。 我已经实现了图像检测,平面动画。这是我的问题,当图像检测到与飞机,它应该显示用户名标签,个人资料和网站。我正在尝试显示用户名标签,但我已经在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)
    
    
    
        }
    
    }
    
    1 回复  |  直到 6 年前
        1
  •  1
  •   fannolo    6 年前

    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)
    
    }