我已经从RoomPlan API生成了一个USDZ文件,现在这个USDZ文件在Unity中使用,Unity不支持USDZ文件,所以我必须将这个USDZ转换为FBX & USDZ到OBJ,OBJ转换工作,但当我尝试FBX转换不工作时,目标路径是空白请检查我的代码。
let inputFileName = "Rom2.usdz"//"plantpot.usdz"
let outputFileName = "Rom3.obj"//"Rom3.fbx"
override func viewDidLoad() {
super.viewDidLoad()
let fm = FileManager.default
let docsurl = try! fm.url(for:.documentDirectory, in: .userDomainMask, appropriateFor: nil, create: false)
debugPrint(docsurl)
guard let usdzURL = Bundle.main.url(forResource: "plantpot", withExtension: "usdz") else {
fatalError("Failed to find USDZ file in bundle")
}
// Load the USDZ file using SceneKit
guard let scene = try? SCNScene(url: usdzURL, options: [.checkConsistency: true]) else {
print("Failed to load scene")
return
}
// Create a Model I/O asset from the SceneKit scene
let asset = MDLAsset(scnScene: scene)
debugPrint("Count",asset.count)
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask).first!
let fbxURL = documentsDirectory.appendingPathComponent(outputFileName)
if FileManager.default.fileExists(atPath: fbxURL.path) {
print("Output file already exists")
return
}
if !FileManager.default.isWritableFile(atPath: fbxURL.path) {
print("The file at \(fbxURL.path) exists but is not writable.")
} else {
print("The file at \(fbxURL.path) exists and is writable.")
}
do {
try asset.export(to: fbxURL)
print("Conversion complete. Output file: \(fbxURL.path)")
} catch let error {
print("Error exporting to FBX: \(error.localizedDescription)")
}
print("Conversion complete. Output file: \(fbxURL.path)")
}
字符串
1条答案
按热度按时间2j4z5cfb1#
我相信你的转换不工作的原因是由于
ModelIO.MDLAsset.export()
方法不支持FBX文件格式。我建议您检查您的源代码,如果它支持FBX转换使用以下方法从Apple Docs
字符串
正如文档中所说,
MDLAsset.export
只支持以下扩展:型