簡體   English   中英

如何在 Xcode 構建中使我的 USDZ 背景透明/黑色?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM