// // /*===============================================================================
// // 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 System.Collections.Generic;
using Phantom.XRMOD.ActionNotification.Runtime;
using Phantom.XRMOD.Core.Runtime;
using UnityEngine;
using UnityEngine.XR;
using UnityEngine.XR.ARFoundation;
namespace Phantom.XRMOD.QuestModule.Runtime
{
///
/// Feature decorator for Meta Quest Meshing.
///
/// Manages the and dispatches notifications when meshes are added, updated, or removed.
///
///
public class MetaQuestMeshingDecorator : BaseMetaQuestFeatureDecorator
{
private OnEventMeshEventArgs onEventMeshEventArgs;
private ARMeshManager meshManager;
private ArchitectureComponentsModel architectureComponentsModel;
private List subsystems = new();
///
/// Starts the meshing algorithm.
///
/// Activates the Mesh Manager and subscribes to mesh change events.
///
///
public override void StartAlgorithm()
{
base.StartAlgorithm();
SubsystemManager.GetSubsystems(subsystems);
architectureComponentsModel = IocContainer.GetIoc.Resolve();
meshManager = architectureComponentsModel.MeshManager;
onEventMeshEventArgs = new OnEventMeshEventArgs();
meshManager.meshesChanged += OnMeshesChanged;
meshManager.gameObject.SetActive(true);
}
///
/// Callback for mesh changes.
///
/// Posts an notification with mesh data.
///
///
/// Event arguments containing changed meshes.
private void OnMeshesChanged(ARMeshesChangedEventArgs _obj)
{
onEventMeshEventArgs.Added = _obj.added;
onEventMeshEventArgs.Updated = _obj.updated;
onEventMeshEventArgs.Removed = _obj.removed;
ActionNotificationCenter.DefaultCenter.PostNotification(nameof(ActionParameterDataType.OnEvent),
onEventMeshEventArgs);
}
///
/// Determines if this feature is supported.
///
/// True if XR Mesh Subsystems are available.
public override bool SupportThisFeature()
{
return subsystems.Count > 0;
}
///
/// Pauses the algorithm.
///
public override void PauseAlgorithm()
{
}
///
/// Stops the meshing algorithm.
///
/// Destroys all meshes and deactivates the Mesh Manager.
///
///
public override void StopAlgorithm()
{
meshManager?.DestroyAllMeshes();
IocContainer.GetIoc.Resolve().MeshManager.gameObject.SetActive(false);
}
}
}