Does anyone knows how to clear the background of a SceneView 3D Object? I’m trying using UIColor.clear, but it makes it white.
[]
import SwiftUI
import SceneKit
struct TestView: View {
var body: some View {
ZStack{
Color.green
SceneView(
scene: {
let scene = SCNScene(named: "Earth.scn")!
scene.background.contents = UIColor.clear
return scene
}(),
options: [.autoenablesDefaultLighting,.allowsCameraControl]
)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/2, alignment: .center)
}
}
}
struct TestView_Previews: PreviewProvider {
static var previews: some View {
TestView()
}
}
2
Answers
Here’s a solution that worked for me, mostly adopted from the answers here:
Then you can use it in your view as:
I know that I’m late, but here is a refined approach described in the other answers:
You just need to replace the
SceneView
toLegacySceneView
. No other changes are required. Enjoy!