Call from iOS SDK script events in Lens

Options
Jorge Costa
Jorge Costa Posts: 13 🔥

Lens can run scripts and can have events.

Is it possible to call an event available on the Lens's script from the iOS SDK?

Eg: I would like to call using Swift the "TapEvent"

script.createEvent("TapEvent").bind(onTap);

function onTap(eventData) {
    eventData.getTapPosition().x > 0.3
        ? story.turnPage("FORWARD")
        : story.turnPage("BACKWARD");
}
Tagged:

Comments

  • cdublin
    cdublin Posts: 2 👻
    Options

    @Jorge Costa Hey! Thanks for raising this! We're getting this over to the Engineering team for more insight.

  • ForumChris
    ForumChris Posts: 23 👻
    Options

    Hello @Jorge Costa That is possible through Remote APIs

    Since all requests via Remote APIs are initiated from the Lens you would send it to the app at launch and then call your onTap function when you get the response. In the Button Press example in the Lens you would interpret parsedResponse with the values you are sending in, and do something like:

    var req = global.RemoteApiRequest.create();
    req.endpoint = "turn_page";
    
    script.remoteServiceModule.performApiRequest(req, responseHandler); 
    
    function responseHandler( response) {
            var parsedResponse =  JSON.parse(response.body);  
            if(parsedResponse.forward == true)
                  story .turnPage("FORWARD")
            ...
           // Then you would send the request again so the app could respond:
           script.remoteServiceModule.performApiRequest(req, responseHandler);
    }
    ....
    

    And from the application flow stand point:

    1. Lens Launches
    2. Lens sends request to app via Remote APIs
    3. App responds to request whenever it is necessary.
    4. Lens handles response to request by reading the response and calling the desired function in the Lens
    5. Repeat steps 2-4.

    Hope this helps provide some clarity.

  • Jorge Costa
    Jorge Costa Posts: 13 🔥
    Options

    @ForumChris is it possible to download 3D models through Remote APIs?

  • ForumChris
    ForumChris Posts: 23 👻
    Options

    Hey @Jorge Costa, yep it's possible! Take a look at this forum post which shows the workflow for importing an image and will largely be the same as for a GLB model.

    Additionally, here is the image example on our docs page

    You will leverage a Remote Media Module (which can be added from the Lens Studio Resources Panel) and use its built in loadResourceAsGLTF function. This will take in the entire unparsed response to the Remote request as a parameter(similar to how that example is shown for images).

    If it is read successfully (ensure the model is GLB), you will now have a GLTF asset that can be instantiated as any other prefab. Ensure that you are applying the GLTF material to it (also from the Lens Studio Resources Panel) and that will automatically apply any built in materials/ textures as mentioned on this forum Post