[HoloLens2MRTK] ScenUnderstanding을 통해 설정된 대상을 만들 때의 이벤트 가져오기

우선 MRTK의 ScenUnderstainding은...

  • 참조
  • https://qiita.com/Futo_Horio/items/2759f9ca2b892709ab66
  • https://redhologerbera.hatenablog.com/entry/2020/12/28/232605
  • 바닥, 벽 등을 인식하고 간단한 그래픽을 구성할 수 있음
  • SceneUnderstanding에서 체크의 업데이트 빈도와 결과 객체를 설정할 수 있습니다.
    Image from Gyazo
    그림에서 벽을 5초만 업데이트하고 대상을 생성합니다

    컨디션

  • Unity v2019.4.18
  • MRTK v2.7.2
  • SceneUnderstanding v0.6.0
  • 대상에 이벤트 추가 코드 가져오기


    using Microsoft.MixedReality.Toolkit.Examples.Demos;
    using Microsoft.MixedReality.Toolkit.Experimental.SpatialAwareness;
    using Microsoft.MixedReality.Toolkit.SpatialAwareness;
    using UnityEngine;
    
    public class SceneUnderstandingController : DemoSpatialMeshHandler, IMixedRealitySpatialAwarenessObservationHandler<SpatialAwarenessSceneObject>
    {
        protected override void Start()
        {
        }
    
         protected override void OnEnable()
        {
            RegisterEventHandlers<IMixedRealitySpatialAwarenessObservationHandler<SpatialAwarenessSceneObject>, SpatialAwarenessSceneObject>();
        }
    
        protected override void OnDisable()
        {
            UnregisterEventHandlers<IMixedRealitySpatialAwarenessObservationHandler<SpatialAwarenessSceneObject>, SpatialAwarenessSceneObject>();
        }
    
        protected override void OnDestroy()
        {
            UnregisterEventHandlers<IMixedRealitySpatialAwarenessObservationHandler<SpatialAwarenessSceneObject>, SpatialAwarenessSceneObject>();
        }
    
        public void OnObservationAdded(MixedRealitySpatialAwarenessEventData<SpatialAwarenessSceneObject> eventData)
        {
            Debug.Log("added!!");
            Debug.Log(eventData);
        }
    
        public void OnObservationUpdated(MixedRealitySpatialAwarenessEventData<SpatialAwarenessSceneObject> eventData)
        {
        }
    
        public void OnObservationRemoved(MixedRealitySpatialAwarenessEventData<SpatialAwarenessSceneObject> eventData)
        {
            Debug.Log("removed!!");
            Debug.Log(eventData);
        }
    
    }
    
    
    DemoSpatialMeshHandler MRTK의 Example을 넣고 Package Manager에서 Spatial Awarreness를 추가하면 사용 가능
    Image from Gyazo
    전선
    DemoSpatialMeshHandler
    #region アセンブリ Microsoft.MixedReality.Toolkit.Examples, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
    // C:\Users\Honeycomb-lab\Documents\ono\LIXIL_holo2\LIXLI_holo2\Library\ScriptAssemblies\Microsoft.MixedReality.Toolkit.Examples.dll
    #endregion
    
    using Microsoft.MixedReality.Toolkit.SpatialAwareness;
    using UnityEngine;
    using UnityEngine.EventSystems;
    
    namespace Microsoft.MixedReality.Toolkit.Examples.Demos
    {
        [AddComponentMenu("Scripts/MRTK/Examples/DemoSpatialMeshHandler")]
        public class DemoSpatialMeshHandler : MonoBehaviour, IMixedRealitySpatialAwarenessObservationHandler<SpatialAwarenessMeshObject>, IEventSystemHandler
        {
            protected bool isRegistered;
    
            public DemoSpatialMeshHandler();
    
            public virtual void OnObservationAdded(MixedRealitySpatialAwarenessEventData<SpatialAwarenessMeshObject> eventData);
            public virtual void OnObservationRemoved(MixedRealitySpatialAwarenessEventData<SpatialAwarenessMeshObject> eventData);
            public virtual void OnObservationUpdated(MixedRealitySpatialAwarenessEventData<SpatialAwarenessMeshObject> eventData);
            protected void AddToData(int eventDataId);
            protected virtual void OnDestroy();
            protected virtual void OnDisable();
            protected virtual void OnEnable();
            protected virtual void RegisterEventHandlers<T, U>()
                where T : IMixedRealitySpatialAwarenessObservationHandler<U>
                where U : BaseSpatialAwarenessObject;
            protected void RemoveFromData(int eventDataId);
            protected virtual void Start();
            protected virtual void UnregisterEventHandlers<T, U>()
                where T : IMixedRealitySpatialAwarenessObservationHandler<U>
                where U : BaseSpatialAwarenessObject;
            protected void UpdateData(int eventDataId);
        }
    }
    
    그러고 보니 5초OnObservationRemoved 간격으로 검출된 벽과 바닥의 몇 분만 집행하고, 이어서OnObservationAdded 집행된 느낌
    그래서 실제로 벽과 바닥의 대상은 반짝이는 것처럼 보인다
    Image from Gyazo
    해결책은 지금 쓰고 있는데...

    좋은 웹페이지 즐겨찾기