[英]How can I make my USDZ background transparent/black in my Xcode build?
有谁知道如何使 USDZ 文件的背景透明或黑色? 在构建我的 Xcode 项目时,我似乎无法将背景设置为黑色,即使将 USDZ 的背景和照明更改为黑色也是如此。 我在下面附上了代码。 不幸的是,我不会上传 USDZ 文件,因为我找不到分享它的方法。
// ContentView.swift
// USDZviewer
//
// Created by Conqueriings on 31/10/21.
// CREDITS: Kavsoft
import SwiftUI
import SceneKit
struct ContentView: View {
var body: some View {
Home()
}
}
struct ContentView_Previews: PreviewProvider {
static var previews: some View {
Home()
}
}
struct Home : View {
@State var models = [
Model(id: 0, name: "Cookie", modelName: "cookie.usdz"),
Model(id: 0, name: "Micro:Bit (Front)", modelName: "mbfront.usdz"),
Model(id: 0, name: "Micro:Bit (Back)", modelName: "mb2.usdz"),
Model(id: 0, name: "RaspberryPi 4", modelName: "RPIv5.usdz")
]
@State var index = 0
var body: some View{
VStack {
SceneView(scene: SCNScene(named: models[index].modelName), options: [.autoenablesDefaultLighting, .allowsCameraControl])
.frame(width: UIScreen.main.bounds.width , height: UIScreen.main.bounds.height / 2)
ZStack{
HStack{
Button(action: {
withAnimation{
if index > 0{
index -= 1
}
}
}, label: {
Image(systemName: "chevron.left")
.font(.system(size: 35, weight: .bold))
.opacity(index == 0 ? 0.3 : 1)
})
.disabled(index == 0 ? true : false)
Spacer(minLength: 0)
Button(action: {
withAnimation{
if index < models.count{
index += 1
}
}
}, label: {
Image(systemName: "chevron.right")
.font(.system(size: 35, weight: .bold))
// disabling button when no other data ....
.opacity(index == models.count - 1 ? 0.3 : 1)
})
.disabled(index == models.count - 1 ? true : false)
}
Text(models[index].name)
.font(.system(size: 25, weight: .bold))
}
.foregroundColor(.white)
.padding(.horizontal)
.padding(.vertical,30)
}
}
}
// Data Model...
struct Model : Identifiable {
var id : Int
var name : String
var modelName : String
}
我知道这是一篇旧帖子,但我能够使用以下方法创建黑色背景:
SceneView(
scene: {
let scene = SCNScene(named: "modelName")
scene!.background.contents = UIColor.black
}() ,options: [.autoenablesDefaultLighting]
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.