ObjectTrackingActivity
Overview
The ObjectTrackingActivity is a dedicated AR activity for detecting and tracking pre-registered physical objects using the MultiSet SDK. Once an object is successfully tracked, its 3D mesh is fetched from the MultiSet platform and rendered in the AR scene with an animated glowing outline shader.
Description
This activity is responsible for:
Establishing an AR session with ARCore and Sceneform
Fetching and rendering 3D object meshes from the MultiSet platform
Sending camera frames to the MultiSet Object Tracking API
Applying an animated outline-only shader to tracked object meshes
Managing background tracking and auto-retry behavior
Forwarding tracking results to the host application via
MultiSetSDKCallback
Launching the Activity
Object codes can be passed either directly via an intent extra, or pre-configured on ObjectTrackingConfig.
// Option A: pass codes via Intent extra
val objectCodes = arrayOf("OBJ_001", "OBJ_002")
val intent = Intent(this, ObjectTrackingActivity::class.java)
intent.putExtra(ObjectTrackingActivity.EXTRA_OBJECT_CODES, objectCodes)
startActivity(intent)
// Option B: configure via ObjectTrackingConfig (codes are read automatically)
ObjectTrackingConfig.objectCodes = arrayOf("OBJ_001", "OBJ_002")
ObjectTrackingConfig.validate()
startActivity(Intent(this, ObjectTrackingActivity::class.java))Intent Extras
EXTRA_OBJECT_CODES
Array<String>
Array of object codes to track (max 10)
Prerequisites
The SDK must be initialized and authenticated before launching this activity. If the SDK is not authenticated, the activity will finish immediately with a toast message.
Key Features
Auto-Tracking
When ObjectTrackingConfig.autoTracking is true, tracking starts automatically once the AR session is ready and the device camera is in a stable tracking state. A 1-second stabilization delay ensures a good initial frame.
Background Tracking
When ObjectTrackingConfig.backgroundTracking is true, the activity continues sending tracking requests at the configured interval (bgTrackingDurationSeconds) after the first successful track. This keeps the object pose updated over time.
Manual Tracking Trigger
A capture button is visible in the AR view. Tapping it manually triggers a new tracking request regardless of auto or background settings.
Animated Outline Mesh
Once an object is tracked, its 3D GLB mesh is fetched from the MultiSet platform (with local caching) and placed in the AR scene. A custom Filament shader renders only the mesh outline with:
Rim-lit edge glow
Animated spark particles (dual-layer noise)
Traveling wave along the Y axis
Pulse modulation
Configurable glow intensity and color
Confidence Filtering
When ObjectTrackingConfig.confidenceCheck is true, tracking results below confidenceThreshold are discarded and the activity retries automatically.
Re-tracking on AR Loss
When ObjectTrackingConfig.restartTracking is true, the activity detects AR tracking state changes (PAUSED/STOPPED) and automatically re-initiates tracking when the device recovers.
Configuration
The activity reads all settings from ObjectTrackingConfig at session startup:
See ObjectTrackingConfig for full property details.
Session Wiring
The activity builds an ArFrameSource, creates an ObjectTrackingSession from the SDK, applies ObjectTrackingConfig to it, and attaches callbacks. The SDK owns capture scheduling, retry and background re-tracking.
As with localization, capture is deferred until ARCore reports TRACKING, and session.stop() cancels both the scheduled capture and any request already in flight.
Callbacks (MultiSetSDKCallback Interface)
Results are forwarded to the callback registered via MultiSetSDK.initialize().
onObjectTrackingSuccess(result: ObjectTrackingResult)
Called when an object is successfully tracked.
result
ObjectTrackingResult
Contains object code, pose, and confidence
onObjectTrackingFailure(error: String)
Called when tracking fails (after all retries are exhausted, if firstTrackingUntilSuccess is false).
error
String
Error message describing the failure
onTrackingStateChanged(state: TrackingState)
Called when the underlying AR tracking state changes.
state
TrackingState
Current state: TRACKING, PAUSED, or STOPPED
ObjectTrackingResult
objectCode
String
Code of the tracked object
objectCodes
List<String>
All object codes returned by the API
position
FloatArray
XYZ position in ARCore world space
rotation
FloatArray
XYZW quaternion orientation
confidence
Float
Tracking confidence score (0.0–1.0)
AR Session Setup
The activity configures the ARCore session with settings optimized for object tracking:
Update Mode
LATEST_CAMERA_IMAGE
Focus Mode
AUTO
Light Estimation
DISABLED
Depth Mode
AUTOMATIC
Plane Finding
DISABLED
Plane rendering is disabled to keep the view clean during object tracking.
Lifecycle
onCreate
Validates SDK auth, sets up AR, fetches mesh, starts animation
onDestroy
Stops animation, releases tracking manager and mesh handler
The activity does not persist the SDK instance. This is managed by the host MainActivity.
Related
Last updated
Was this helpful?

