Q: How to import a 3D model from the web?

Options
Eric G
Eric G Posts: 10

Hello, thanks for taking the time to read this. I've been exploring the RemoteAPI offering and have been able to implement it with json data, image data but am having trouble with 3D data. Any help would be greatly appreciated!

  • Request
    For the request I have defined an API spec with an appropriate response size definition.

  • Response
    For the response I am handling the request via a CameraKit iOS app. I am intercepting the request, retrieving a gltf asset from bundle and reading it into a Data object. This Data object is what I am returning in the response to the lens.

  • Load
    ApiModule.prototype.requestRemoteModel = function(mediaManager, callback) {
    var req = global.RemoteApiRequest.create();
    req.endpoint = "requestRemoteModel";

    this.remoteServiceModule.performApiRequest(req, function(response) {
    mediaManager.loadResourceAsGltfAsset(
    response.asResource(),
    function (gltfAsset) {
    callback(gltfAsset)
    },
    function (error) {
    callback(null);
    });
    });
    };

  • Display
    To display I am attempting to call 'tryInstantiate' method on the gltfAsset but am receiving errors. I have defined an empty scene object in the Camera and a Material object in the Resources and attempt to use these for the inputs to 'tryInstantiate'

[error] Cannot parse file : Unsupported file format
[error] Error importing glTF file with material: glTF asset does not contain a root SceneObject

Answers

  • nhbg yhjm
    nhbg yhjm Posts: 2
    Options

    I'd be happy to help you out! From what you've described, it sounds like you're experiencing some connectivity issues with your 5G Wi-Fi. It's possible that the firmware version you're using could be causing the problem, as you've already tried downgrading the firmware without success.

    One thing you could try is resetting your router to its default settings, which may help resolve the issue. Alternatively, you could try contacting your internet service provider or the manufacturer of your router for further assistance.

    If you find that you're still experiencing issues, it may be best to switch over to an ethernet connection to ensure a stable connection. Let me know if there's anything else I can do to assist you.

  • Eric G
    Eric G Posts: 10
    Options

    Thanks for the response, I don't think it's related to my connection however!

  • Nikola
    Nikola Posts: 2
    Options

    I'm struggling with the exact same thing albeit I'm using Android. Did you ever manage to figure out what the lens is expecting in the response?

  • Eric G
    Eric G Posts: 10
    Options

    I did end up figuring it out, I don't have time to look for the solution today but ping this thread again next Friday and I can spend a bit looking for it if you don't get the solution before then.

  • Nikola
    Nikola Posts: 2
    Options

    Thanks for your response, any help would be appreciated if you have the time. I'm in the SnapAR discord server and my discord username is yotov96

  • Eric G
    Eric G Posts: 10
    Options

    When I was testing this I had a collection of 'glb' models. I loaded url for the asset on file system and retrieved the data from the file url. This is what I sent back to the lens response.

    // App Side
    let models: [(name: String, ext: String)] = [
        ("WaterBottle", "glb")
    ]
    
    private func modelResponse(
            _ request: LensRemoteApiRequest,
            responseHandler: @escaping (LensRemoteApiServiceCallStatus, LensRemoteApiResponseProtocol) -> Void
        ) -> LensRemoteApiServiceCall {
        let model = models[0]
    
        guard let fileURL = Bundle.main.url(forResource: model.name, withExtension: model.ext),
                  let fileData = try? Data(contentsOf: fileURL) else {
                return IgnoredRemoteApiServiceCall()
        }
    
        DispatchQueue.global(qos: .background).async {
            responseHandler(.answered, LensRemoteApiResponse(
                request: request,
                status: .success,
                metadata: [:],
                body: fileData))
        }
    
        return ResponseRemoteApiServiceCall()
    }
    
    
    // Lens Side
    ApiModule.prototype.remote_model = function(mediaManager, cb) {
        var req = global.RemoteApiRequest.create();
        req.endpoint = "remote_model";
    
        this.remoteServiceModule.performApiRequest(req, function(response) {
            if (response.statusCode !== 1) {
                // Error
                cb(true, null);
            } else {
                mediaManager.loadResourceAsGltfAsset(
                    response.asResource(),
                    function (gltfAsset) {
                        // Asset
                        cb(false, gltfAsset);
                    },
                    function (error) {
                        // Error
                        cb(true, null);
                    });
            }
        });
    };