Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Control scale behavior ARKit

That seems a weird behavior but I'm wondering if there is a way to have nodes that have the same size on screen no matter how far it is from the camera?

I'm trying to show 2D elements in a city (just a text and an image) and some of them can be far but I still want the text and images to be visible but I also don't want it to look gigantic when I'm too close from it.

I'm currently using Apple SpriteKit example:

override func touchesBegan(_ touches: Set<UITouch>, with event: UIEvent?) 
{
    guard let sceneView = self.view as? ARSKView else 
    {
        return
    }

    // Create anchor using the camera's current position
    if let currentFrame = sceneView.session.currentFrame 
    {            
        // Create a transform with a translation of 0.2 meters in front of the camera
        var translation = matrix_identity_float4x4
        translation.columns.3.z = -0.2
        let transform = simd_mul(currentFrame.camera.transform, translation)

        // Add a new anchor to the session
        let anchor = ARAnchor(transform: transform)
        sceneView.session.add(anchor: anchor)
    }
}
like image 882
pierre23 Avatar asked Oct 21 '25 11:10

pierre23


1 Answers

The only thing that 'works' for me so far is re-update the scale value for each Node:

func view(_ view: ARSKView, didUpdate node: SKNode, for anchor: ARAnchor)
{ 
   node.setScale(1)
}
like image 133
pierre23 Avatar answered Oct 22 '25 23:10

pierre23