Jan 2 • Ashray Pai

Building Location-Based AR Experiences with WebXR

WebXR has unlocked endless possibilities for creating location-based AR experiences.

By integrating Immersal VPS technology into the Zapworks Mattercraft tool, developers can create applications like pathfinding in malls, interactive games in parks, or industry-focused solutions such as overlaying BIM models.

This guide will walk you through creating a basic AR pathfinding experience using Zapworks Mattercraft and Immersal VPS integration.

YouTube

Want to watch the video instead?

Prerequisites

Before diving into development, ensure the following prerequisites are met:

  1. Immersal Developer Account:
    • Sign up for a free account here. The free plan is sufficient for prototyping, but the Pro plan (with features like spatial map editing and Polycam support) is recommended for large-scale projects.
       Use the coupon code ImmersiveInsiders for a free Pro license valid until January 31, 2025.
  2. Immersal Mapper App:
    • Download the app from the Play Store or App Store.
    • Map your environment by capturing images from various angles. Use manual mode for detailed mesh generation, which is essential for this project.

    Mattercraft - The WebXR Tool

    For those of you who don't know, Mattercraft is an immersive 3D web-based developer tool that allows us to build AR applications for mobile devices, WebXR applications for headsets such as Apple Vision Pro, Meta Quest, and others.

    This tool also enables us to create 3D websites. If you check out the Mattercraft page, you'll see it has a bunch of features like instant live review, real-time physics, particle effects, and the best part—experiences built using this tool can be accessed via any device's web browser.

    Head to the Zapworks website. If you're here for the first time, you'll have to create a new account. You get a 14-day free trial, and after that, you can opt in for a developer plan, which is pretty cheap to continue accessing this tool.

    Setting Up the Project

    1. Creating the Project:
      • Visit the Zapworks website and create an account.
      • Select the Mattercraft project type, name your project, and choose the Immersal VPS template. 
    1. Configuring VPS Settings:
      • Visit the immers developer portal -> click on menu -> account and copy your developer token. Go back inside Mattercraft, select ImmersalAnchorGroup and paste the token in the Developer Token parameter.
      • Once again go back to the developers portal click on menu -> click on maps and copy the ID of the map that you'd like to download.Go back inside mattercraft and paste this inside map ID and click on enter. After a couple of seconds you should be able to see the mesh of your environment

    Download the Source Code

    To save time, download the base project here, modify it, or use it as a reference. Extract the files, open a new Mattercraft project, and select the unzipped folder to get started.

    Designing the AR Experience


    Adding Target Locations

    • Import 3D models (GLB format) or use primitives like cubes to mark target locations.
    • Place and rename these objects appropriately, then hide them by unchecking visibility.


    Creating UI Buttons

    1. Download a CSS Stylesheet:
      • Import it into your project to simplify UI creation.
    2. Add HTML Components:
      • Now to create the UI buttons, inside the group, we can create a new HTML component.
        Then select the style CSS file and drag and drop it inside the HTML component.

      • Next, to create a Div component as a child of HTML, click on these three dots, click on new, and select Div. Rename this as footer container. In the node properties, create a class list called footer container (ensure "f" is lowercase to match the stylesheet). From the display dropdown, select Flex. Scroll down and set the width as 100, but not in pixels—instead, select viewport width (VW).

      • For this app, we want to anchor everything at the bottom. Select HTML, scroll down, and set the vertical anchor as bottom. Now we can create UI buttons as a child of the footer container. Create a new div, rename it as location one, set the class list as footer item, set the display to inline block, and set the size to 20 VW.

      • Inside this location, add an image. Add a class list called IMG and leave the rest of the settings as is. Similarly, create a text of type H2, set the class list as text, and write the text for your button. Now, if you click on location one, this whole thing will be your button.

      • Since we have two locations, duplicate this button and rename the second one as location two. The stylesheet will automatically space the buttons equally. If more locations are needed, duplicate further. For now, keep it simple with two locations. To add images, first upload them to your project, then drag and drop them into the source. If unnecessary, delete extra items.



    Implementing the Direction Pointer

    • Import a 3D arrow model.
    • Add a Look At Node component within a Camera Transform.
    • Adjust the arrow’s orientation to point toward selected targets.


    Configuring Interactions


    1. Set Up States:
      • Now all that's left to do is for us to change the target based on the UI button pressed. Here’s how:
        • First, remove the Target and hide the Look At component.
        • Open the animation window and create a new layer. Give your layer a name, and inside the layer, create a new state. Call this state "LookAtLocation1."
        • Select the "LookAtLocation1" state. In the node properties, set a Target and assign it to "Location 1." Also, set the visibility to True.
        • Add another state to this layer and name it "LookAtLocation2." Select this new state, set a Target, and assign it to "Location 2." Make sure to set the visibility to True here as well.
    2. Button Behaviors:
      • Close the animation window and open the HTML. Select the first UI button ("Location1"), click the plus symbol under Behaviors, and navigate to Animation Action. Select "Activate State."
      • Set the event to "On Click," and the state to activate will be inside the "Switch Location" layer. Select "LookAtLocation1."
      • Similarly, select "location two," click the plus symbol under Behaviors, navigate to Animation Action, and select "Activate State." Set the event to "On Click," and choose "Switch Location > look at location two."


    Testing and Publishing


    1. Live Preview:
      • Save your changes and scan the QR code to preview on a mobile device.
      • Localize your environment and test the experience.


    2. Publishing:
      • Publish the project to generate a shareable QR code.
      • Users can scan the environment to access the AR experience on both iOS and Android devices.


    Conclusion

    Creating location-based WebXR experiences has never been easier with tools like Zapworks Mattercraft and Immersal VPS technology.

    Experiment with these steps to develop innovative AR applications that can transform navigation, entertainment, and industrial processes.

    Thanks for reading this blog post 🧡

    If you've enjoyed the insights shared here, why not spread the word? Share the post with your friends and colleagues who might also find it valuable.
    Your support means the world to us and helps us create more content you'll love.