0

我正在尝试使用 swiftUI 放置 AR 对象,但配置显示不支持,因此我的设备是 iPhone 7plus

'''' 如果 ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh){ config.sceneReconstruction = .mesh

    } else {
        print(UIDevice.modelName)
        print("config not supported")
    }

这个 if 不起作用,它不属于“else”语句'''

struct ARViewContainer: UIViewRepresentable {
    @Binding var selectedModalNameforPlaceable:String?
    func makeUIView(context: Context) -> ARView {
        
        let arView = ARView(frame: .zero)
        
        let config = ARWorldTrackingConfiguration()
        config.planeDetection = [.horizontal,.vertical]
        config.environmentTexturing = .automatic
        'my code go to else '
        if ARWorldTrackingConfiguration.supportsSceneReconstruction(.mesh){
            config.sceneReconstruction = .mesh
            
        } else {
            print(UIDevice.modelName)
            print("config not supported")
        }
        
        arView.session.run(config)
        return arView
        
    }
    
    func updateUIView(_ uiView: ARView, context: Context) {
        if let selectedMoadal = self.selectedModalNameforPlaceable {
            let fileName = selectedMoadal + ".usdz"
            print(fileName)
            let modalEntity = try! ModelEntity.loadModel(named: fileName)
            
            let anchorEntity = AnchorEntity(plane: .any)
            anchorEntity.addChild(modalEntity)
            
            uiView.scene.addAnchor(anchorEntity)
            //            print("selecte \(selectedMoadal)")
            DispatchQueue.main.async {
                self.selectedModalNameforPlaceable=nil
            }
        }
        
    }
    
}

'''

4

0 回答 0