gpt4 book ai didi

swift - 如何在 SwiftUI 中更改 SceneView 3D 对象的背景颜色

转载 作者:行者123 更新时间:2023-12-05 01:07:18 28 4
gpt4 key购买 nike

有人知道如何更改 SceneView 对象的背景颜色吗?我正在尝试将背景属性放置到 SceneView,但它并没有改变它,仍然具有默认背景。 In this case I wanted to the background be green, but it's keeps gray/white

import SwiftUI
import SceneKit

struct ContentView: View {
var body: some View {

ZStack{
Color.red
SceneView(
scene: SCNScene(named: "Earth.scn"),
options: [.autoenablesDefaultLighting,.allowsCameraControl]
)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/2, alignment: .center)
.background(Color.green)
.border(Color.blue, width: 3)

}
}
}

struct ContentView_Previews: PreviewProvider {
static var previews: some View {
ContentView()
}
}

最佳答案

您看到的灰色来自 SCNScenebackground属性(property)。您需要将其设置为 UIColor.green

struct ContentView: View {
var body: some View {

ZStack{
Color.red
SceneView(
scene: {
let scene = SCNScene(named: "Earth.scn")!
scene.background.contents = UIColor.green /// here!
return scene
}(),
options: [.autoenablesDefaultLighting,.allowsCameraControl]
)
.frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.height/2, alignment: .center)
.border(Color.blue, width: 3)

}
}
}

结果:

green background in SceneView

关于swift - 如何在 SwiftUI 中更改 SceneView 3D 对象的背景颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67767360/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com