From b126b4f5846734fe430c10c961a6caa096d52b73 Mon Sep 17 00:00:00 2001 From: David Kline Date: Fri, 14 May 2021 10:51:51 -0700 Subject: [PATCH] Merge pull request #9819 from fast-slow-still/spatFix Correct parenting of spatial mesh to preserve local transform. --- .../Providers/XRSDK/GenericXRSDKSpatialMeshObserver.cs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Assets/MRTK/Providers/XRSDK/GenericXRSDKSpatialMeshObserver.cs b/Assets/MRTK/Providers/XRSDK/GenericXRSDKSpatialMeshObserver.cs index e6071406e61..b0daa0227a5 100644 --- a/Assets/MRTK/Providers/XRSDK/GenericXRSDKSpatialMeshObserver.cs +++ b/Assets/MRTK/Providers/XRSDK/GenericXRSDKSpatialMeshObserver.cs @@ -495,8 +495,12 @@ private void MeshGenerationAction(MeshGenerationResult meshGenerationResult) } meshes.Add(meshObject.Id, meshObject); - meshObject.GameObject.transform.parent = (ObservedObjectParent.transform != null) ? - ObservedObjectParent.transform : null; + // This is important. We need to preserve the mesh's local transform here, not its global pose. + // Think of it like this. If we set the camera's coordinates 3 meters to the left, the physical camera + // hasn't moved, only its coordinates have changed. Likewise, the physical room hasn't moved (relative to + // the physical camera), so we also want to set its coordinates 3 meters to the left. + Transform meshObjectParent = (ObservedObjectParent.transform != null) ? ObservedObjectParent.transform : null; + meshObject.GameObject.transform.SetParent(meshObjectParent, false); meshEventData.Initialize(this, meshObject.Id, meshObject); if (isMeshUpdate)