// // /*===============================================================================
// // Copyright (C) 2025 PhantomsXR Ltd. All Rights Reserved.
// //
// // This file is part of the Phantom.XRMOD.QuestModule.Runtime.
// //
// // The XR-MOD cannot be copied, distributed, or made available to
// // third-parties for commercial purposes without written permission of PhantomsXR Ltd.
// //
// // Contact nswell@phantomsxr.com for licensing requests.
// // ===============================================================================*/
using Phantom.XRMOD.ActionNotification.Runtime;
using Phantom.XRMOD.Core.Runtime;
using UnityEngine.XR.ARFoundation;
namespace Phantom.XRMOD.QuestModule.Runtime
{
///
/// Feature decorator for handling AR Bounding Boxes on Meta Quest.
///
/// Initializes the and listens for trackable changes, notifying the system via .
///
///
public class MetaQuestBoundingBoxesDecorator : BaseMetaQuestFeatureDecorator
{
private ArchitectureComponentsModel architectureComponentsModel;
private ARBoundingBoxArgs boundingBoxArgs;
///
/// Starts the bounding box algorithm.
///
/// Sets up the if missing and subscribes to trackable changes.
///
///
public override void StartAlgorithm()
{
base.StartAlgorithm();
architectureComponentsModel = IocContainer.GetIoc.Resolve();
if (architectureComponentsModel.BoundingBoxManager == null)
{
architectureComponentsModel.BoundingBoxManager =
architectureComponentsModel.XRRig.AddComponent();
}
boundingBoxArgs = new ARBoundingBoxArgs();
architectureComponentsModel.BoundingBoxManager.trackablesChanged.AddListener(TrackableChanged);
}
///
/// Callback for when AR Bounding Boxes change (added, updated, removed).
///
/// Posts notifications with containing updated data.
///
///
/// The event arguments containing changed bounding boxes.
private void TrackableChanged(ARTrackablesChangedEventArgs _arg0)
{
foreach (var tmp_Updated in _arg0.added)
{
boundingBoxArgs.Classification = tmp_Updated.classifications.ToString();
boundingBoxArgs.Size = tmp_Updated.size;
ActionNotificationCenter.DefaultCenter.PostNotification("", boundingBoxArgs);
}
foreach (var tmp_Updated in _arg0.updated)
{
boundingBoxArgs.Classification = tmp_Updated.classifications.ToString();
boundingBoxArgs.Size = tmp_Updated.size;
ActionNotificationCenter.DefaultCenter.PostNotification("", boundingBoxArgs);
}
foreach (var tmp_Updated in _arg0.removed)
{
boundingBoxArgs.TrackingId = tmp_Updated.Key.ToString();
boundingBoxArgs.Classification = tmp_Updated.Value.classifications.ToString();
boundingBoxArgs.Size = tmp_Updated.Value.size;
ActionNotificationCenter.DefaultCenter.PostNotification("", boundingBoxArgs);
}
}
///
/// Determines if this feature is supported.
///
/// Always returns true.
public override bool SupportThisFeature()
{
return true;
}
///
/// Pauses the bounding box algorithm.
///
public override void PauseAlgorithm()
{
}
///
/// Stops the bounding box algorithm.
///
public override void StopAlgorithm()
{
}
}
}