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.
Topic:
Graphics & Games
SubTopic:
RealityKit
Tags: