SnowballToss: Meshing and Occlusion

Demonstrates how to use the ARDK meshing function to build a mesh of your real-world surroundings in realtime. The scene then shows how the ARDK mesh can be used for placing virtual objects, detecting collisions, and occlusion.

Overview

After some instructions, the app turns on the device’s camera and the player is prompted to scan their surroundings, enabling the app to create a 3D mesh of their environment. If the device has LIDAR, the resulting mesh will be more refined. Feature points of the environment geometry are also displayed to visualize scanning.

Once enough mesh is discovered, rings of snowy ice appear throughout the open areas of the environment, casting shadows on the environment geometry. A button with a snowball appears near the bottom of the screen; pressing it tosses the snowball forward, colliding / bouncing / bursting on the snow rings and/or environment geometry, leaving melting snow particles or persistent snow splats behind.

Mesh scanning continues during the game; if new mesh is discovered that collides with existing snow rings, those snow rings go away.

The top of the screen displays a 45 second game timer and the player’s cumulative score, 100 points for each snowball tossed through a ring.

ARDK Features in use

  • ARSceneManager

  • ARMeshManager - Manages detection of the AR environment mesh, including instantiation and destruction of MeshCollliderChunk geometry objects that align with the detected mesh

  • MeshColliderChunks - occlude other virtual assets, but use a custom transparent material

    • Note: the other scenes implement occlusion via ARDepthManager

Additional Helpers

  • ARFeaturePointHelper - to visualize the mesh scanning process

  • ARMeshFloorFallback - fallback mesh floor plane

  • SnowballTossDebugManager - manages the debug functionality for the scene

States

StateInstructions

A UI displaying instructions.

StateWarning

A UI displaying a warning about using AR; this is only displayed once per execution of the app, before the user enters an ARSession for the first time.

StateScanning

The device’s camera is turned on, and the player is prompted to scan their surroundings, enabling the app to create a 3D mesh of their environment. If the device has LIDAR, the resulting mesh will be more refined. Feature points of the environment geometry are also displayed to visualize scanning.

StateCountdown

3-second animated countdown display before the tossing game begins.

StateTossing

45-second game where the player tries to toss snowballs through snow rings. A maximum of 3 snow rings appear at once; a ring auto-expires after ~15 seconds. In the Snowring class, the method SearchVectorForValidRingPlacement divides the environment into sectors, attempting to distribute snow rings in empty areas around the player, preferring empty spots somewhat near and in front of the player, using Physics.OverlapSphereNonAlloc to test for empty areas. It conducts its environment search over time, to stay performant.

StateGameOver

UI displaying the player’s final score, and an option to Restart, or Return to Map.

Editor-Only Mock Support

When developing ARDK applications in editor, to avoid always requiring building to a device, it is convenient to employ mock versions of AR assets that function in Unity Editor. Each scene’s mock objects are attached to the scene’s MockScene GameObject. This object has a MockSceneConfiguration component that will destroy the object if outside of Unity Editor.

This scene’s MockScene object includes:

  • a mock environment mesh