iOS: Issue with lightning in USDZ file

3k Views Asked by At

I am trying to show an AR content with QLPreviewController. Everything works fine except the lighting. If I preview the file using Xcode or macOS's quick look the lighting is natural, but when I preview it using QLPreviewController the object is too dark!. Is there any possible way to adjust the lighting, scale, and other settings?

2

There are 2 best solutions below

1
On

Please make sure your 3D mesh has UV layout while creating the model. Without UV the 3D object will appear dark on iOS devices and in QLPreviewController, although it might appear fine on MacOS when using 3D or ARQuickLook.

For more info, please refer the below mentioned link:

https://forums.developer.apple.com/thread/107094

For Eg: If you are creating models with Blender, this might help:

https://blender.stackexchange.com/questions/1022/adding-uv-mapping-to-mesh

If you open the usdz object in XCode, check the material inspector, you will find that the illumination colour is set to Black. That's why its appearing dark in AR world but it will look fine in ARQuickLook.

Setting the UV Map will solve your issue.

Other hacks that I have tried are (Not Recommended):

1) Change emissiveColor while creating USDZ model. Using Python-based tool(USDPython) for generating usdz file.

https://developer.apple.com/download/more/?=USDPython

usdzconvert Model.obj -diffuseColor modelDiffuse.png -normal modelNormal.png -metallic 1 -roughness 1 -occlusion 1 -emissiveColor 0.5,0.5,0.5

2) Set the illumination colour to White.

First convert .usdz to .scn -> change illumination -> convert .scn to .usdz

let scnScene = SCNScene(named: "sceneName", inDirectory: "art.scnassets", options: nil)

scnScene!.write(to: fileUrl.appendingPathComponent("Model.usdz"), delegate: nil)

You can take help from this WWDC talk (Exporting USDZ from Scenekit):

https://developer.apple.com/videos/play/wwdc2019/602/

0
On

In Xcode 13/12 there are no such issues

AR QuickLook framework is based on RealityKit rendering engine. AR QuickLook has minimum parameters to control a AR scene. There's no parameters for controlling lighting. AR QuickLook inherits automatic Light Estimation from RealityKit. In Xcode 12.1 and higher I see no bugs presenting unlit (black) models. You can quickly test it with the following code:

import QuickLook

class ViewController: UIViewController,
                      QLPreviewControllerDelegate,
                      QLPreviewControllerDataSource {

    override func viewDidAppear(_ animated: Bool) {
        let previewController = QLPreviewController()
        previewController.dataSource = self
        previewController.delegate = self
        present(previewController, animated: true, completion: nil)
    }

    func numberOfPreviewItems(in controller: QLPreviewController) -> Int {
        return 1
    }

    func previewController(_ controller: QLPreviewController,
                    previewItemAt index: Int) -> QLPreviewItem {
        
        guard let path = Bundle.main.path(forResource: "path/to/gramophone",
                                               ofType: "usdz")
        else {
            fatalError("Couldn't find a file.")
        }
        let url = URL(fileURLWithPath: path)
        return url as QLPreviewItem
    }
}

P.S.

If you're still experiencing issues with unlit PBR models – it's not a problem of AR QuickLook, it's rather a problem of your USDZ model.