Skip to content

Commit d2589e2

Browse files
committed
ARDK UPM 3.12.0
1 parent 4137b59 commit d2589e2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+641
-355
lines changed

Runtime/ARFoundation/Overrides/LocationAR/ARLocationManager.cs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,6 @@ public int MaxLocationTrackingCount
9797
private ARSessionState _lastARSessionState = ARSessionState.None;
9898
private ARLocationTrackedEventArgs? _lastLocationTrackedEventArgs;
9999

100-
// Workaround for frequent anchor pose updates
101-
private Pose _lastAnchorPose;
102-
103100
protected override void OnEnable()
104101
{
105102
// This will invoke OnBeforeStart and then start the subsystem. Put any initialization logic
@@ -330,7 +327,6 @@ private void HandleARPersistentAnchorStateChanged(
330327

331328
var args = new ARLocationTrackedEventArgs(arLocation, tracking, reason, anchor.trackingConfidence);
332329
InvokeTrackingStateChangedWithARSessionState(args, _lastARSessionState);
333-
_lastAnchorPose = anchor.PredictedPose;
334330
_lastLocationTrackedEventArgs = args;
335331
}
336332
else
@@ -361,7 +357,6 @@ private void HandleARPersistentAnchorStateChanged(
361357
// Note: You could call arLocation.gameObject.SetActive(false) in locationTrackingStateChanged event if you wanted to de-activate gameObject when tracking is lost
362358
var args = new ARLocationTrackedEventArgs(arLocation, false, reason, anchor.trackingConfidence);
363359
InvokeTrackingStateChangedWithARSessionState(args, _lastARSessionState);
364-
_lastAnchorPose = anchor.PredictedPose;
365360
_lastLocationTrackedEventArgs = args;
366361
}
367362
}
@@ -376,25 +371,6 @@ private void InvokeTrackingStateChangedWithARSessionState(ARLocationTrackedEvent
376371
return;
377372
}
378373

379-
// If we've previously localized, check that there is new info to report
380-
// This is a temporary workaround for native firing multiple identical updates
381-
if (_lastLocationTrackedEventArgs.HasValue)
382-
{
383-
var locationTransform = args.Value.ARLocation.transform;
384-
var allInfoIdentical = _lastAnchorPose.position ==
385-
locationTransform.position &&
386-
_lastAnchorPose.rotation == locationTransform.rotation &&
387-
args.Value.Tracking == _lastLocationTrackedEventArgs.Value.Tracking &&
388-
args.Value.TrackingStateReason ==
389-
_lastLocationTrackedEventArgs.Value.TrackingStateReason &&
390-
sessionState == _lastARSessionState;
391-
392-
if (allInfoIdentical)
393-
{
394-
return;
395-
}
396-
}
397-
398374
var newArgs = args.Value;
399375

400376
// If ARSessionState is not SessionTracking, fire the event as not tracking

Runtime/ARFoundation/Overrides/Occlusion/Extension/Features/Stabilization.cs

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@ protected override string Keyword
5050
private CommandBuffer _meshObserverCommandBuffer;
5151

5252
// Additional resources
53-
private Texture2D _defaultNonLinearDepthTexture;
53+
private Texture2D _defaultMeshDepthTexture;
5454
public RenderTexture MeshDepthTexture { get; private set; }
5555

5656
// URP render pass
5757
#if MODULE_URP_ENABLED
5858
private OffScreenBlitPass _renderPass;
59+
60+
private RTHandle _meshDepthTextureHandle;
61+
62+
private RTHandleSystem _rtHandleSystem;
5963
#endif
6064

6165
/// <summary>
@@ -143,6 +147,10 @@ public bool Configure(
143147
_renderPass = new OffScreenBlitPass(
144148
name: "Lightship Occlusion Extension (Stabilization)",
145149
renderPassEvent: RenderPassEvent.AfterRendering);
150+
151+
_rtHandleSystem = new RTHandleSystem();
152+
_rtHandleSystem.Initialize(KFusedDepthWidth, KFusedDepthHeight);
153+
_meshDepthTextureHandle = _rtHandleSystem.Alloc(MeshDepthTexture);
146154
#endif
147155
return true;
148156
}
@@ -156,16 +164,20 @@ protected override void OnMaterialAttach(Material mat)
156164

157165
// The default texture bound to the fused depth property on the material.
158166
// It lets every pixel pass through until the real depth texture is ready to use.
159-
if (_defaultNonLinearDepthTexture == null)
167+
if (_defaultMeshDepthTexture == null)
160168
{
161-
var val = OcclusionExtensionUtils.IsDepthReversed() ? 0.0f : 1.0f;
162-
_defaultNonLinearDepthTexture = new Texture2D(2, 2, TextureFormat.RFloat, mipChain: false);
163-
_defaultNonLinearDepthTexture.SetPixelData(new[] {val, val, val, val}, 0);
164-
_defaultNonLinearDepthTexture.Apply(false);
169+
// The mesh depth texture contains linear eye depth
170+
// Here we default to 1000 meters, because we don't
171+
// have access to the camera's far clip plane.
172+
const float val = 1000.0f;
173+
174+
_defaultMeshDepthTexture = new Texture2D(2, 2, TextureFormat.RFloat, mipChain: false);
175+
_defaultMeshDepthTexture.SetPixelData(new[] {val, val, val, val}, 0);
176+
_defaultMeshDepthTexture.Apply(false);
165177
}
166178

167179
// Bind pass-through texture by default
168-
mat.SetTexture(ShaderProperties.FusedDepthTextureId, _defaultNonLinearDepthTexture);
180+
mat.SetTexture(ShaderProperties.FusedDepthTextureId, _defaultMeshDepthTexture);
169181
}
170182

171183
protected override void OnMaterialDetach(Material mat)
@@ -252,16 +264,23 @@ protected override void OnReleaseResources()
252264
Object.Destroy(_meshObserverMaterialInternal);
253265
}
254266

255-
if (_defaultNonLinearDepthTexture != null)
267+
if (_defaultMeshDepthTexture != null)
256268
{
257-
Object.Destroy(_defaultNonLinearDepthTexture);
269+
Object.Destroy(_defaultMeshDepthTexture);
258270
}
259271

260272
if (MeshDepthTexture != null)
261273
{
262274
Object.Destroy(MeshDepthTexture);
263275
}
264276

277+
#if MODULE_URP_ENABLED
278+
if( _meshDepthTextureHandle != null )
279+
{
280+
_meshDepthTextureHandle.Release();
281+
}
282+
#endif
283+
265284
_meshObserverCommandBuffer?.Dispose();
266285
}
267286

@@ -315,7 +334,7 @@ private void EnqueueUniversalRenderPass(ScriptableRenderContext context, Camera
315334
if (cam == _meshObserverCamera)
316335
{
317336
// Configure the render pass
318-
_renderPass.Setup(Material, MeshDepthTexture);
337+
_renderPass.Setup(Material, MeshDepthTexture, _meshDepthTextureHandle);
319338

320339
// Enqueue the render pass
321340
cam.GetUniversalAdditionalCameraData().scriptableRenderer.EnqueuePass(_renderPass);

Runtime/ARFoundation/Overrides/Occlusion/Extension/OcclusionComponentDeployment.cs

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Niantic.Lightship.AR.Utilities.Logging;
88
using Niantic.Lightship.AR.XRSubsystems;
99
using UnityEngine;
10+
using UnityEngine.Rendering;
1011
using UnityEngine.Serialization;
1112
using UnityEngine.XR.ARFoundation;
1213
using UnityEngine.XR.ARSubsystems;
@@ -160,11 +161,15 @@ protected override bool OnAddRenderComponent(RenderComponent component)
160161
// The occlusion stabilization feature requires the mesh manager
161162
case Stabilization occlusionStabilization:
162163
{
163-
#if NIANTIC_LIGHTSHIP_ML2_ENABLED
164-
// TODO(ahegedus): Unlock this feature for ML2
165-
Log.Error("Occlusion stabilization is not yet supported on ML2.");
166-
return false;
167-
#endif
164+
// https://docs.unity3d.com/2022.3/Documentation/Manual/SL-CameraDepthTexture.html
165+
// Direct3D 11+ (Windows), OpenGL 3+ (Mac/Linux), OpenGL ES 3.0+ (iOS), Metal (iOS)
166+
// and popular consoles support depth textures.
167+
if (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Vulkan)
168+
{
169+
Log.Error("Occlusion stabilization is not yet supported on Vulkan devices.");
170+
return false;
171+
}
172+
168173
if (_meshManager == null)
169174
{
170175
// Attempt to find the mesh manager

Runtime/ARFoundation/Overrides/Occlusion/LightshipFusedDepthCamera.cs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,11 @@ internal Material Material
3636
/// </summary>
3737
internal RenderTexture GpuTexture { get; private set; }
3838

39+
#if MODULE_URP_ENABLED
40+
internal RTHandle GpuTextureHandle {get; private set;}
41+
internal RTHandleSystem RtHandleSystem {get; private set;}
42+
#endif
43+
3944
// Resources
4045
private Camera _camera;
4146
private Material _internalMaterial;
@@ -104,6 +109,12 @@ private void Awake()
104109

105110
GpuTexture.Create();
106111

112+
#if MODULE_URP_ENABLED
113+
RtHandleSystem = new RTHandleSystem();
114+
RtHandleSystem.Initialize(1024, 1024);
115+
GpuTextureHandle = RtHandleSystem.Alloc(GpuTexture);
116+
#endif
117+
107118
// Allocate a camera
108119
_camera = gameObject.AddComponent<Camera>();
109120

@@ -127,6 +138,13 @@ private void OnDestroy()
127138
{
128139
Destroy(GpuTexture);
129140
}
141+
142+
#if MODULE_URP_ENABLED
143+
if( GpuTextureHandle != null)
144+
{
145+
GpuTextureHandle.Release();
146+
}
147+
#endif
130148
}
131149

132150
#if !MODULE_URP_ENABLED
@@ -160,7 +178,7 @@ private void OnBeginCameraRendering(ScriptableRenderContext context, Camera cam)
160178
if (cam == _camera)
161179
{
162180
// Configure the render pass
163-
_renderPass.Setup(Material, GpuTexture);
181+
_renderPass.Setup(Material, GpuTexture, GpuTextureHandle);
164182

165183
// Enqueue the render pass
166184
cam.GetUniversalAdditionalCameraData().scriptableRenderer.EnqueuePass(_renderPass);

Runtime/ARFoundation/Overrides/Occlusion/URP/OffScreenBlitPass.cs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ internal sealed class OffScreenBlitPass : FullScreenBlitPass
1515
{
1616
// The target render texture
1717
private RenderTexture _target;
18+
private RTHandle _targetHandle;
1819

1920
public OffScreenBlitPass(string name, RenderPassEvent renderPassEvent)
2021
: base(name, renderPassEvent) { }
@@ -24,18 +25,19 @@ public OffScreenBlitPass(string name, RenderPassEvent renderPassEvent)
2425
/// </summary>
2526
/// <param name="material">The material used to render the image.</param>
2627
/// <param name="target">The target to render the image to.</param>
27-
public void Setup(Material material, RenderTexture target)
28+
public void Setup(Material material, RenderTexture target, RTHandle targetHandle)
2829
{
2930
SetMaterial(material);
3031
_target = target;
32+
_targetHandle = targetHandle;
3133
}
3234

3335
public override void Configure(CommandBuffer cmd, RenderTextureDescriptor cameraTextureDescriptor)
3436
{
3537
base.Configure(cmd, cameraTextureDescriptor);
36-
38+
3739
// TODO(ahegedus): Make this use RTHandle instead of RenderTexture
38-
ConfigureTarget(_target);
40+
ConfigureTarget(_targetHandle);
3941
}
4042
}
4143
}

Runtime/ARFoundation/Overrides/PersistentAnchors/MeshDownload/Api/MeshDownloadHelper.cs

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ internal static class MeshDownloadHelper
2424
private static string configEndpointFormatter = "{0}/vps_frontend.protogen.Localizer/{1}";
2525
private static string meshingMethod = "GetMeshUrl";
2626
private static string graphMethod = "GetGraph";
27+
private static string replacedNodeMethod = "GetReplacedNodes";
2728
private static string spaceDataMethod = "GetSpaceData";
2829
private const int KB = 1024;
2930

@@ -228,7 +229,7 @@ await HttpClient.SendPostAsync<
228229
// 4. Add an entry for the each node and edge pair to the return list
229230
// 6. Add the last remaining node with no edge (origin of the space)
230231
// 7. Return the List<NodeToLoad> with node transforms and mesh urls
231-
private static async Task<List<NodeToLoad>> GetNodesInSpace(string nodeId, Dictionary<string, string> headers)
232+
private static async Task<List<NodeToLoad>> GetNodesInSpace(string nodeId, Dictionary<string, string> headers, bool searchForReplacedNode = true)
232233
{
233234
var nodesToLoad = new List<NodeToLoad>();
234235

@@ -266,6 +267,16 @@ await HttpClient.SendPostAsync<
266267
response.nodes == null ||
267268
response.nodes.Length == 0)
268269
{
270+
if ((response.nodes == null || response.nodes.Length == 0) && searchForReplacedNode)
271+
{
272+
// Check if the node has been replaced with a new active node
273+
var replacedNodeResponse = await TryGetNodesInSpaceForReplacedNode(nodeId, headers);
274+
if (replacedNodeResponse != null)
275+
{
276+
return replacedNodeResponse;
277+
}
278+
}
279+
269280
// This class uses Debug instead of ARLog to support editor logging without Lightship Native loaded
270281
Debug.LogWarning("Failed to get nodes to load");
271282
return null;
@@ -371,6 +382,62 @@ await HttpClient.SendPostAsync<
371382
return nodesToLoad;
372383
}
373384

385+
private static async Task<List<NodeToLoad>> TryGetNodesInSpaceForReplacedNode
386+
(
387+
string nodeId,
388+
Dictionary<string, string> headers
389+
)
390+
{
391+
var replacedNodeRequest = new MeshDownloadRequestResponse.GetReplacedNodesRequest
392+
{
393+
requestIdentifier = Guid.NewGuid().ToString("N").ToUpper(),
394+
nodeIdentifiers = new []{nodeId}
395+
};
396+
397+
var endpoint = GetUrlForMethod(replacedNodeMethod);
398+
var replacedNodeResponse =
399+
await HttpClient.SendPostAsync<
400+
MeshDownloadRequestResponse.GetReplacedNodesRequest,
401+
MeshDownloadRequestResponse.GetReplacedNodesResponse>
402+
(
403+
endpoint,
404+
replacedNodeRequest,
405+
headers
406+
);
407+
408+
if (replacedNodeResponse.Status == ResponseStatus.Success)
409+
{
410+
var response = replacedNodeResponse.Data;
411+
if (response.transformToActiveNode != null && response.transformToActiveNode.Length > 0)
412+
{
413+
var replacedNode = response.transformToActiveNode[0];
414+
var activeNode = replacedNode.activeNode;
415+
var transform = replacedNode.transformFromReplacedToActiveNode;
416+
417+
var nodesInNewSpace = await GetNodesInSpace(activeNode, headers, false);
418+
if (nodesInNewSpace != null && nodesInNewSpace.Count > 0)
419+
{
420+
nodesInNewSpace.Add
421+
(
422+
new NodeToLoad
423+
(
424+
nodeId,
425+
nodesInNewSpace.First().spaceId,
426+
transform.translation,
427+
transform.rotation
428+
)
429+
);
430+
431+
return nodesInNewSpace;
432+
}
433+
434+
return null;
435+
}
436+
}
437+
438+
return null;
439+
}
440+
374441
// Use a HEAD request to get the total download size of the meshes
375442
private static async Task<ulong> GetTotalDownloadSize
376443
(

0 commit comments

Comments
 (0)