如何在两个相似的图像上同时加载多个图像?

时间:2019-07-10 14:33:00

标签: swift xcode augmented-reality arkit

我想在同一张图片的上方显示两艘船,但是一次只显示一艘。我怎样才能使其在两者上都可见?

我已经阅读了其他几个问题,并且尝试设置configuration.maximumNumberOfTrackedImages = 2 我也尝试过使用didaddNode渲染器功能。 我在下面附加了一张图片,虽然这些图片看起来模糊,但实际上在现实生活中是清晰的,只是我通过whatsapp获得了它,因此将其压缩 enter image description here

override func viewWillAppear(_ animated: Bool) {
    super.viewWillAppear(animated)

    // Create a session configuration
    let configuration = ARImageTrackingConfiguration()

    guard let trackedImages = ARReferenceImage.referenceImages(inGroupNamed: "Hydrogen", bundle: Bundle.main) else {
        print("No images available")
        return
    }

    configuration.trackingImages = trackedImages
    configuration.maximumNumberOfTrackedImages = 10

    // Run the view's session
    sceneView.session.run(configuration)
}

func renderer(_ renderer: SCNSceneRenderer, nodeFor anchor: ARAnchor) -> SCNNode? {

    let node = SCNNode()

    if let imageAnchor = anchor as? ARImageAnchor{
        let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)

        plane.firstMaterial?.diffuse.contents = UIColor(red: 30/255, green: 30/255, blue: 30/255, alpha: 0.05)

        let planeNode = SCNNode(geometry: plane)
        planeNode.eulerAngles.x = -.pi / 2

        let shipScene = SCNScene(named: "art.scnassets/ship.scn")!
        let shipNode = shipScene.rootNode.childNodes.first!
        shipNode.position = SCNVector3Zero
        shipNode.position.z = 0.15
        shipNode.eulerAngles.x = .pi / 2

        planeNode.addChildNode(shipNode)  
        node.addChildNode(planeNode)          
    }
    return node
}

func renderer(_ renderer: SCNSceneRenderer, didAdd node: SCNNode, for anchor: ARAnchor) -> SCNNode {
    let node = SCNNode()

    if let imageAnchor = anchor as? ARImageAnchor{
        let plane = SCNPlane(width: imageAnchor.referenceImage.physicalSize.width, height: imageAnchor.referenceImage.physicalSize.height)

        plane.firstMaterial?.diffuse.contents = UIColor(red: 30/255, green: 30/255, blue: 30/255, alpha: 0.05)

        let planeNode = SCNNode(geometry: plane)
        planeNode.eulerAngles.x = -.pi / 2

        let shipScene = SCNScene(named: "art.scnassets/ship.scn")!
        let shipNode = shipScene.rootNode.childNodes.first!
        shipNode.position = SCNVector3Zero
        shipNode.position.z = 0.15
        shipNode.eulerAngles.x = .pi / 2

        planeNode.addChildNode(shipNode)
        node.addChildNode(planeNode)     
    }
        return node`enter code here`
    }

我希望每张照片上都出现一艘船,但是每张照片上只显示一艘船

0 个答案:

没有答案