【问题标题】:USDZ export from SceneKit results in dull models从 SceneKit 导出 USDZ 会导致模型变暗
【发布时间】:2020-08-10 15:29:01
【问题描述】:

我正在尝试使用新的 iOS13 功能从 SCNScene 导出 usdz 文件,使用 func write(to url: URL, options: [String : Any]? = nil, delegate: SCNSceneExportDelegate?, progressHandler: SCNSceneExportProgressHandler? = nil) -> Bool SCNScene 的功能。

如果我使用未经修改的烘焙 .scn 文件,效果很好,但是当我尝试插入自己的纹理时会遇到各种问题。

let scene = SCNScene(named: "scene.scnassets/original.scn")!
let node = scene.rootNode.childNode(withName: "Plane", recursively: true)
let plane = SCNPlane(width: 1, height: 1)
node?.geometry = plane
node?.geometry?.firstMaterial?.diffuse.contents = UIColor.black
node?.geometry?.firstMaterial?.roughness.contents = NSNumber(value: 0.0) //or UIColor.black doesn't work either

let documentsUrl = self.fileManager.urls(for: .documentDirectory, in: .userDomainMask)
guard !documentsUrl.isEmpty,
let url = documentsUrl.first else {
    completion(nil)
    return
}
let finalUrl = url.appendingPathComponent("result.usdz")
_ = scene.write(to: finalUrl, delegate: nil)

original.scn 只是有一个光泽平面,我尝试在更改材质时再次将粗糙度设置为 0。生成的 usdz 始终将粗糙度设置为 0.9。有其他人经历过这种情况并找到解决方法吗?

【问题讨论】:

    标签: ios swift scenekit usdz


    【解决方案1】:

    默认光照模型是SCNLightingModelBlinn,这意味着用于plane 几何体的材质不是基于物理的。 USDZ 仅支持基于物理的材质,并且在导出时 SceneKit 会尝试从 Blinn 材质构建 PBR 材质,并会代表您推断出roughness

    修复包括将lightingModelName 设置为SCNLightingModelPhysicallyBased

    【讨论】:

    • 成功了,谢谢!我只需要添加以下行node.geometry?.firstMaterial?.lightingModel = .physicallyBased
    猜你喜欢
    • 2020-12-08
    • 2019-07-15
    • 2020-08-19
    • 2021-04-23
    • 1970-01-01
    • 2019-10-04
    • 1970-01-01
    • 2018-10-24
    • 2019-11-01
    相关资源
    最近更新 更多