'tangents' was deprecated in visionOS 2.0: Use cp_drawable_compute_projection instead

I'm using a class with tangents to render on RealityKit for VisionOS but in Vision26 it cause a crash on App and there not documentation how implement cp_drawable_compute_projection I have tried a few options but without success. Could you help me to implement it ?

The part of code is:

return drawable.views.map { view in
            let userViewpointMatrix = (simdDeviceAnchor * view.transform).inverse
          
                  let projectionMatrix = ProjectiveTransform3D(
                      leftTangent: Double(view.tangents[0]),
                      rightTangent: Double(view.tangents[1]),
                      topTangent: Double(view.tangents[2]),
                      bottomTangent: Double(view.tangents[3]),
                      nearZ: Double(drawable.depthRange.y),
                      farZ: Double(drawable.depthRange.x),
                      reverseZ: true
                  )


                  let screenSize = SIMD2(x: Int(view.textureMap.viewport.width),
                                         y: Int(view.textureMap.viewport.height))
            return ModelRendererViewportDescriptor(viewport: view.textureMap.viewport,
                                                   projectionMatrix: .init(projectionMatrix),
                                                   viewMatrix: userViewpointMatrix * translationMatrix * rotationMatrix * scalingMatrix * commonUpCalibration,
                                                   screenSize: screenSize)
        }
Accepted Answer

After some testing, I was able to find a solution. The issue comes from the use of .tangents, which is deprecated in visionOS 2.0 and caused crashes in my RealityKit-based app.

The correct approach now is to use drawable.computeProjection(viewIndex:) instead. Here's the working version of the updated code:

return drawable.views.enumerated().map { (index, view) in
    let userViewpointMatrix = (simdDeviceAnchor * view.transform).inverse

    // New method to get the projection matrix
    let projectionMatrix = drawable.computeProjection(viewIndex: index)

    let screenSize = SIMD2(
        x: Int(view.textureMap.viewport.width),
        y: Int(view.textureMap.viewport.height)
    )

    return ModelRendererViewportDescriptor(
        viewport: view.textureMap.viewport,
        projectionMatrix: projectionMatrix, // No need to wrap in `.init(...)`
        viewMatrix: userViewpointMatrix * translationMatrix * rotationMatrix * scalingMatrix * commonUpCalibration,
        screenSize: screenSize
    )
}

This removed the deprecation warnings and resolved the crashes.

It would be great if Apple improved the deprecation message for .tangents, especially since it currently says “use cp_drawable_compute_projection” which isn’t a symbol available in public APIs. Using computeProjection() is the actual method to can replace it.

'tangents' was deprecated in visionOS 2.0: Use cp_drawable_compute_projection instead
 
 
Q