ARKitEnvironmentProbeSubsystem.cs
7.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
using System;
using Unity.Collections;
using UnityEngine.Scripting;
using UnityEngine.XR.ARSubsystems;
namespace UnityEngine.XR.ARKit
{
/// <summary>
/// This subsystem provides implementing functionality for the <c>XREnvironmentProbeSubsystem</c> class.
/// </summary>
[Preserve]
class ARKitEnvironmentProbeSubsystem : XREnvironmentProbeSubsystem
{
/// <summary>
/// Create and register the environment probe subsystem descriptor to advertise a providing implementation for
/// environment probe functionality.
/// </summary>
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
static void Register()
{
if (!Api.AtLeast12_0())
return;
const string subsystemId = "ARKit-EnvironmentProbe";
XREnvironmentProbeSubsystemCinfo environmentProbeSubsystemInfo = new XREnvironmentProbeSubsystemCinfo()
{
id = subsystemId,
#if UNITY_2020_2_OR_NEWER
providerType = typeof(ARKitEnvironmentProbeSubsystem.ARKitProvider),
subsystemTypeOverride = typeof(ARKitEnvironmentProbeSubsystem),
#else
implementationType = typeof(ARKitEnvironmentProbeSubsystem),
#endif
supportsManualPlacement = true,
supportsRemovalOfManual = true,
supportsAutomaticPlacement = true,
supportsRemovalOfAutomatic = true,
supportsEnvironmentTexture = true,
supportsEnvironmentTextureHDR = Api.AtLeast13_0(),
};
XREnvironmentProbeSubsystem.Register(environmentProbeSubsystemInfo);
}
#if !UNITY_2020_2_OR_NEWER
protected override Provider CreateProvider() => new ARKitProvider();
#endif
class ARKitProvider : Provider
{
public ARKitProvider() => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_Construct();
public override void Start() => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_Start();
/// <summary>
/// Stops the environment probe subsystem by disabling the environment probe state.
/// </summary>
public override void Stop() => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_Stop();
/// <summary>
/// Destroy the environment probe subsystem by first ensuring that the subsystem has been stopped and then
/// destroying the provider.
/// </summary>
public override void Destroy() => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_Destruct();
/// <summary>
/// Enable or disable automatic placement of environment probes by the provider.
/// </summary>
/// <param name='value'><c>true</c> if the provider should automatically place environment probes in the scene.
/// Otherwise, <c>false</c></param>.
public override bool automaticPlacementRequested
{
get => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_GetAutomaticPlacementRequested();
set => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_SetAutomaticPlacementRequested(value);
}
/// <summary>
/// Queries whether automatic placement is currently enabled.
/// </summary>
public override bool automaticPlacementEnabled => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_GetAutomaticPlacementEnabled();
/// <summary>
/// Get or set the requested state of HDR environment texture generation.
/// </summary>
/// <returns>
/// Whether the HDR environment texture generation is requested.
/// </returns>
public override bool environmentTextureHDRRequested
{
get => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_GetEnvironmentTextureHDRRequested();
set => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_SetEnvironmentTextureHDRRequested(value);
}
/// <summary>
/// Query whether HDR texture generation is enabled.
/// </summary>
public override bool environmentTextureHDREnabled => EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_GetEnvironmentTextureHDREnabled();
public override bool TryAddEnvironmentProbe(Pose pose, Vector3 scale, Vector3 size, out XREnvironmentProbe environmentProbe)
{
return EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_TryAddEnvironmentProbe(pose, scale, size, out environmentProbe);
}
/// <summary>
/// Remove the environment probe matching the trackable ID from the AR session..
/// </summary>
/// <param name='trackableId'>The trackable ID for the environment probe to be removed.</param>
/// <returns>
/// <c>true</c> if an environment probe matching the trackable ID is found and will be removed from the AR
/// session. Otherwise, <c>false</c>.
/// </returns>
public override bool RemoveEnvironmentProbe(TrackableId trackableId)
{
return EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_TryRemoveEnvironmentProbe(trackableId);
}
public override TrackableChanges<XREnvironmentProbe> GetChanges(XREnvironmentProbe defaultEnvironmentProbe,
Allocator allocator)
{
int numAddedEnvironmentProbes;
IntPtr addedEnvironmentProbesPointer;
int numUpdatedEnvironmentProbes;
IntPtr updatedEnvironmentProbesPointer;
int numRemovedEnvironmentProbeIds;
IntPtr removedEnvironmentProbeIdsPointer;
int stride;
var context = EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_AcquireChanges(out numAddedEnvironmentProbes, out addedEnvironmentProbesPointer,
out numUpdatedEnvironmentProbes, out updatedEnvironmentProbesPointer,
out numRemovedEnvironmentProbeIds, out removedEnvironmentProbeIdsPointer,
out stride);
try
{
unsafe
{
// Wrap the navite pointers into a native array and then copy them into a separate native array enabled
// with temporary allocations.
return new TrackableChanges<XREnvironmentProbe>(
(void*)addedEnvironmentProbesPointer, numAddedEnvironmentProbes,
(void*)updatedEnvironmentProbesPointer, numUpdatedEnvironmentProbes,
(void*)removedEnvironmentProbeIdsPointer, numRemovedEnvironmentProbeIds,
defaultEnvironmentProbe, stride,
allocator);
}
}
finally
{
EnvironmentProbeApi.UnityARKit_EnvironmentProbeProvider_ReleaseChanges(context);
}
}
}
}
}