From ccf968f23155a4a91f58c1b5e6928021f95b8b2f Mon Sep 17 00:00:00 2001 From: jdibenes <58836755+jdibenes@users.noreply.github.com> Date: Sat, 1 Apr 2023 02:36:15 -0400 Subject: [PATCH] sm patch --- hl2ss/hl2ss/locator.cpp | 11 ++++++++++- hl2ss/hl2ss/locator.h | 1 + hl2ss/hl2ss/main.cpp | 2 -- hl2ss/hl2ss/spatial_mapping.cpp | 7 +++++-- unity/Hololens2SensorStreaming.cs | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/hl2ss/hl2ss/locator.cpp b/hl2ss/hl2ss/locator.cpp index f3b757a3e..a6fe39843 100644 --- a/hl2ss/hl2ss/locator.cpp +++ b/hl2ss/hl2ss/locator.cpp @@ -57,11 +57,20 @@ float4x4 Locator_GetTransformTo(SpatialCoordinateSystem const& src, SpatialCoord return location ? location.Value() : float4x4(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); } +// OK +SpatialCoordinateSystem Locator_GetWorldCoordinateSystemInternal(PerceptionTimestamp const& ts) +{ + return (g_locatability == SpatialLocatability::PositionalTrackingActive) ? g_referenceFrame.CoordinateSystem() : g_attachedReferenceFrame.GetStationaryCoordinateSystemAtTimestamp(ts); +} + // OK SpatialCoordinateSystem Locator_GetWorldCoordinateSystem(PerceptionTimestamp const& ts) { + { SRWLock srw(&g_lock, false); - return g_world_override ? g_world_override : ((g_locatability == SpatialLocatability::PositionalTrackingActive) ? g_referenceFrame.CoordinateSystem() : g_attachedReferenceFrame.GetStationaryCoordinateSystemAtTimestamp(ts)); + if (g_world_override) { return g_world_override; } + } + return Locator_GetWorldCoordinateSystemInternal(ts); } // OK diff --git a/hl2ss/hl2ss/locator.h b/hl2ss/hl2ss/locator.h index 6e578f99f..7351a2aab 100644 --- a/hl2ss/hl2ss/locator.h +++ b/hl2ss/hl2ss/locator.h @@ -10,3 +10,4 @@ winrt::Windows::Foundation::Numerics::float4x4 Locator_Locate(winrt::Windows::Pe winrt::Windows::Foundation::Numerics::float4x4 Locator_GetTransformTo(winrt::Windows::Perception::Spatial::SpatialCoordinateSystem const& src, winrt::Windows::Perception::Spatial::SpatialCoordinateSystem const& dst); winrt::Windows::Perception::Spatial::SpatialCoordinateSystem Locator_GetWorldCoordinateSystem(winrt::Windows::Perception::PerceptionTimestamp const& ts); void Locator_OverrideWorldCoordinateSystem(winrt::Windows::Perception::Spatial::SpatialCoordinateSystem const& scs); +winrt::Windows::Perception::Spatial::SpatialCoordinateSystem Locator_GetWorldCoordinateSystemInternal(winrt::Windows::Perception::PerceptionTimestamp const& ts); diff --git a/hl2ss/hl2ss/main.cpp b/hl2ss/hl2ss/main.cpp index 90f24e6f7..238703f9f 100644 --- a/hl2ss/hl2ss/main.cpp +++ b/hl2ss/hl2ss/main.cpp @@ -87,8 +87,6 @@ struct App : winrt::implements SU_Initialize(); VI_Initialize(); - PrintSystemInfo(); - m_init = true; } diff --git a/hl2ss/hl2ss/spatial_mapping.cpp b/hl2ss/hl2ss/spatial_mapping.cpp index 2b8a32588..bfcead3f5 100644 --- a/hl2ss/hl2ss/spatial_mapping.cpp +++ b/hl2ss/hl2ss/spatial_mapping.cpp @@ -24,6 +24,9 @@ struct SSM SpatialSurfaceMesh mesh = nullptr; }; +// Notes +// GetObservedSurfaces crashes when using OpenXR coordinate system (in Windows.Mirage.dll) + //----------------------------------------------------------------------------- // Global Variables //----------------------------------------------------------------------------- @@ -77,7 +80,7 @@ void SpatialMapping_SetVolumes(SpatialMapping_VolumeDescription const* vd, size_ { std::vector volumes; - g_world = Locator_GetWorldCoordinateSystem(QPCTimestampToPerceptionTimestamp(GetCurrentQPCTimestamp())); + g_world = Locator_GetWorldCoordinateSystemInternal(QPCTimestampToPerceptionTimestamp(GetCurrentQPCTimestamp())); for (int i = 0; i < size; ++i) { @@ -158,7 +161,7 @@ static void SpatialMapping_ComputeMesh(SpatialMapping_MeshTask* task) g_observed_meshes_info[task->index].vpd = vertex_positions.data(); g_observed_meshes_info[task->index].tid = triangle_indices.data(); g_observed_meshes_info[task->index].vnd = compute_normals ? vertex_normals.data() : NULL; - g_observed_meshes_info[task->index].pose = Locator_GetTransformTo(ssm.CoordinateSystem(), g_world); + g_observed_meshes_info[task->index].pose = Locator_GetTransformTo(ssm.CoordinateSystem(), g_world) * Locator_GetTransformTo(g_world, Locator_GetWorldCoordinateSystem(QPCTimestampToPerceptionTimestamp(GetCurrentQPCTimestamp()))); g_observed_meshes_info[task->index].scale = ssm.VertexPositionScale(); g_observed_meshes_info[task->index].bsz = compute_bounds ? sizeof(SpatialBoundingOrientedBox) : 0; if (compute_bounds) diff --git a/unity/Hololens2SensorStreaming.cs b/unity/Hololens2SensorStreaming.cs index f8c1020e1..ac7a59d6d 100644 --- a/unity/Hololens2SensorStreaming.cs +++ b/unity/Hololens2SensorStreaming.cs @@ -32,7 +32,7 @@ public class Hololens2SensorStreaming : MonoBehaviour void Start() { - if (!skipInitialization) { hl2ss.Initialize(enableRM, enablePV, enableMC, enableRC, enableSM, enableSU, enableVI); } hl2ss.UpdateCoordinateSystem(); + if (!skipInitialization) { hl2ss.Initialize(enableRM, enablePV, enableMC, enableRC, enableSM, enableSU, enableVI); } } }