【问题标题】:Can I convert a USDZ to solid mesh such as stl我可以将 USDZ 转换为实体网格,例如 stl
【发布时间】:2019-07-16 03:49:59
【问题描述】:

我使用 ios 应用程序使用 arkit 创建了一个 usdz 文件,但现在我想将扫描转换为实体 3d 模型,例如 stl 或 obj。是否有允许此转换的 ios 或 mac 应用程序。除了 xcode 和预览之外,我找不到任何可以打开它们的应用程序,但都不允许我导出到 3d 模型。

【问题讨论】:

    标签: xcode arkit 3d-modelling usdz


    【解决方案1】:

    ModelIO can,至少在 iOS 中。

    import ModelIO
    
    let usdz = URL(fileURLWithPath: "model.usdz")
    let asset = MDLAsset(url: usdz)
    let stl = URL(fileURLWithPath: "model.stl")
    try asset.export(to: stl)
    

    .usdz 只是一个带有纹理的压缩文件.usdc(来自官方documentation)。 如果要在mac上导出文件,请将文件扩展名更改为.zip,解压缩文件并使用ModelIO导出.stl文件。

    打开 Xcode,新建 Playground,选择 macOS 作为平台。我从Apple's Quick Look Gallery 下载了一个测试文件,并将一个示例解压缩到我的Downlaods 目录中的stratocoaster_usdz/。然后使用以下代码:

    import ModelIO
    
    // Get the path to the Downloads directory in your home folder
    let directory = FileManager.default.urls(for: .downloadsDirectory, in: .userDomainMask).first!
    let usdc = URL(fileURLWithPath: "stratocaster_usdz/Stratocaster.usdc", relativeTo: directory)
    
    // Load the usdc file that was packed in the usdz file
    let asset = MDLAsset(url: usdc)
    
    do {
        let target = URL(fileURLWithPath: "stratocaster.stl", relativeTo: directory)
        // Export to .stl
        try asset.export(to: target)
    } catch {
        error
    }
    

    【讨论】:

      【解决方案2】:

      谢谢!正是我想要的。 我创建了一个 Mac OS 脚本来在终端中自动执行此操作。我还在 Automator 快速操作中做了类似的事情,通过右键单击文件从 Finder 运行,但无法找到将其附加到此处的方法。

      #!/usr/bin/env osascript -l JavaScript
      
      // Save to a file, e.g. usdz2stl.js
      // chmod +x usdz2stl.js
      // usdz2stl.js /path/to/model.usdz
      
      ObjC.import('ModelIO')
      
      function run(argv) {
        var inFile = argv[0];
        var outFile = inFile + ".stl";
        console.log("Converting " + inFile + " ...");
        var usdz = $.NSURL.alloc.initFileURLWithPath(inFile);
        var asset = $.MDLAsset.alloc.initWithURL(usdz);
        var stl = $.NSURL.alloc.initFileURLWithPath(outFile);
        asset.exportAssetToURL(stl);
        console.log("Conversion Complete: " + outFile);
      }
      

      【讨论】:

      • 我试过你的脚本。不幸的是,我收到一个错误:./usdz2stl.js:440:489: script error: Error on line 16: SyntaxError: Unexpected end of script (-2700)。明白了:我忘了复制末尾的 }
      【解决方案3】:

      直接在 XCODE 中打开 .USDZ 或 USDC 文件

      如果您已解压缩 .zip,您将保留一个 .USDC 文件和一个名为“0”的文件夹,其中包含 .PNG 中的所有纹理、材质和 alpha。

      在 XCODE 中打开 .USDZ 或 .USDC >> 文件 >> 导出

      您可以直接选择主要的 .OBJ .STL 格式和许多其他格式

      【讨论】:

      • 不幸的是,将其导出到 DAE 或 OBJ 会导致 Xcode 崩溃
      猜你喜欢
      • 2021-11-04
      • 1970-01-01
      • 2012-07-31
      • 2020-01-16
      • 2019-06-28
      • 1970-01-01
      • 1970-01-01
      • 2012-06-05
      • 2020-06-07
      相关资源
      最近更新 更多