-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathAREnvironmentProbeAnchor.cs
203 lines (163 loc) · 7 KB
/
AREnvironmentProbeAnchor.cs
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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using System.Runtime.InteropServices;
using AOT;
namespace UnityEngine.XR.iOS
{
public enum UnityAREnvironmentTexturing
{
UnityAREnvironmentTexturingNone,
UnityAREnvironmentTexturingManual,
UnityAREnvironmentTexturingAutomatic
};
public enum UnityAREnvironmentTextureFormat : long
{
// NOTE: Not a complete set, but an initial mapping that matches an internal set of texture readback mappings.
UnityAREnvironmentTextureFormatR16,
UnityAREnvironmentTextureFormatRG16,
UnityAREnvironmentTextureFormatBGRA32,
UnityAREnvironmentTextureFormatRGBA32,
UnityAREnvironmentTextureFormatRGBAFloat,
UnityAREnvironmentTextureFormatRGBAHalf,
UnityAREnvironmentTextureFormatDefault = UnityAREnvironmentTextureFormatBGRA32
};
public struct UnityAREnvironmentProbeCubemapData
{
public IntPtr cubemapPtr;
public UnityAREnvironmentTextureFormat textureFormat;
public int width;
public int height;
public int mipmapCount;
};
public struct UnityAREnvironmentProbeAnchorData
{
public IntPtr ptrIdentifier;
/**
The transformation matrix that defines the anchor's rotation, translation and scale in world coordinates.
*/
public UnityARMatrix4x4 transform;
public UnityAREnvironmentProbeCubemapData cubemapData;
public Vector3 probeExtent;
};
public static class UnityAREnvironmentProbeCubemapDataMethods
{
public static TextureFormat GetTextureFormat(this UnityAREnvironmentTextureFormat unityAREnvironmentTextureFormat)
{
switch (unityAREnvironmentTextureFormat)
{
case UnityAREnvironmentTextureFormat.UnityAREnvironmentTextureFormatR16:
return TextureFormat.R16;
case UnityAREnvironmentTextureFormat.UnityAREnvironmentTextureFormatRG16:
return TextureFormat.RG16;
case UnityAREnvironmentTextureFormat.UnityAREnvironmentTextureFormatRGBA32:
return TextureFormat.RGBA32;
case UnityAREnvironmentTextureFormat.UnityAREnvironmentTextureFormatRGBAFloat:
return TextureFormat.RGBAFloat;
case UnityAREnvironmentTextureFormat.UnityAREnvironmentTextureFormatRGBAHalf:
return TextureFormat.RGBAHalf;
case UnityAREnvironmentTextureFormat.UnityAREnvironmentTextureFormatBGRA32:
default:
return TextureFormat.BGRA32;
}
}
}
public class AREnvironmentProbeAnchor
{
UnityAREnvironmentProbeAnchorData envProbeAnchorData;
public AREnvironmentProbeAnchor(UnityAREnvironmentProbeAnchorData uarepad)
{
envProbeAnchorData = uarepad;
}
public string identifier { get { return Marshal.PtrToStringAuto(envProbeAnchorData.ptrIdentifier); } }
public Matrix4x4 transform {
get {
Matrix4x4 matrix = new Matrix4x4 ();
matrix.SetColumn (0, envProbeAnchorData.transform.column0);
matrix.SetColumn (1, envProbeAnchorData.transform.column1);
matrix.SetColumn (2, envProbeAnchorData.transform.column2);
matrix.SetColumn (3, envProbeAnchorData.transform.column3);
return matrix;
}
}
public Cubemap Cubemap
{
get
{
if (envProbeAnchorData.cubemapData.cubemapPtr != IntPtr.Zero) {
Cubemap cubemap = Cubemap.CreateExternalTexture(envProbeAnchorData.cubemapData.width,
envProbeAnchorData.cubemapData.textureFormat.GetTextureFormat(),
(envProbeAnchorData.cubemapData.mipmapCount > 1),
envProbeAnchorData.cubemapData.cubemapPtr);
cubemap.filterMode = FilterMode.Trilinear;
return cubemap;
} else {
return null;
}
}
}
public Vector3 Extent
{
get { return envProbeAnchorData.probeExtent; }
}
}
public partial class UnityARSessionNativeInterface
{
// Object Anchors
public delegate void AREnvironmentProbeAnchorAdded(AREnvironmentProbeAnchor anchorData);
public static event AREnvironmentProbeAnchorAdded AREnvironmentProbeAnchorAddedEvent;
public delegate void AREnvironmentProbeAnchorUpdated(AREnvironmentProbeAnchor anchorData);
public static event AREnvironmentProbeAnchorUpdated AREnvironmentProbeAnchorUpdatedEvent;
public delegate void AREnvironmentProbeAnchorRemoved(AREnvironmentProbeAnchor anchorData);
public static event AREnvironmentProbeAnchorRemoved AREnvironmentProbeAnchorRemovedEvent;
delegate void internal_AREnvironmentProbeAnchorAdded(UnityAREnvironmentProbeAnchorData anchorData);
delegate void internal_AREnvironmentProbeAnchorUpdated(UnityAREnvironmentProbeAnchorData anchorData);
delegate void internal_AREnvironmentProbeAnchorRemoved(UnityAREnvironmentProbeAnchorData anchorData);
public UnityAREnvironmentProbeAnchorData AddEnvironmentProbeAnchor(UnityAREnvironmentProbeAnchorData anchorData)
{
#if !UNITY_EDITOR && UNITY_IOS
return SessionAddEnvironmentProbeAnchor(m_NativeARSession, anchorData);
#else
return new UnityAREnvironmentProbeAnchorData();
#endif
}
#if !UNITY_EDITOR && UNITY_IOS
#region Environment Probe Anchors
[MonoPInvokeCallback(typeof(internal_AREnvironmentProbeAnchorAdded))]
static void _envprobe_anchor_added(UnityAREnvironmentProbeAnchorData anchor)
{
if (AREnvironmentProbeAnchorAddedEvent != null)
{
AREnvironmentProbeAnchor arEnvProbeAnchor = new AREnvironmentProbeAnchor(anchor);
AREnvironmentProbeAnchorAddedEvent(arEnvProbeAnchor);
}
}
[MonoPInvokeCallback(typeof(internal_AREnvironmentProbeAnchorUpdated))]
static void _envprobe_anchor_updated(UnityAREnvironmentProbeAnchorData anchor)
{
if (AREnvironmentProbeAnchorUpdatedEvent != null)
{
AREnvironmentProbeAnchor arEnvProbeAnchor = new AREnvironmentProbeAnchor(anchor);
AREnvironmentProbeAnchorUpdatedEvent(arEnvProbeAnchor);
}
}
[MonoPInvokeCallback(typeof(internal_AREnvironmentProbeAnchorRemoved))]
static void _envprobe_anchor_removed(UnityAREnvironmentProbeAnchorData anchor)
{
if (AREnvironmentProbeAnchorRemovedEvent != null)
{
AREnvironmentProbeAnchor arEnvProbeAnchor = new AREnvironmentProbeAnchor(anchor);
AREnvironmentProbeAnchorRemovedEvent(arEnvProbeAnchor);
}
}
#endregion
[DllImport("__Internal")]
private static extern void session_SetEnvironmentProbeAnchorCallbacks(IntPtr nativeSession, internal_AREnvironmentProbeAnchorAdded envprobeAnchorAddedCallback,
internal_AREnvironmentProbeAnchorUpdated envprobeAnchorUpdatedCallback,
internal_AREnvironmentProbeAnchorRemoved envprobeAnchorRemovedCallback);
[DllImport("__Internal")]
private static extern UnityAREnvironmentProbeAnchorData SessionAddEnvironmentProbeAnchor (IntPtr nativeSession, UnityAREnvironmentProbeAnchorData anchorData);
#endif //!UNITY_EDITOR && UNITY_IOS
}
}