Skip to content

Commit 23a7817

Browse files
committed
Updated to latest ARKit SDK (still the deprecated version)
1 parent b11de49 commit 23a7817

File tree

313 files changed

+62961
-1156
lines changed

Some content is hidden

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

313 files changed

+62961
-1156
lines changed

Diff for: sdkproject/Assets/UnityARInterface/ARRemote/Scripts/ARRemoteDevice.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
using UnityEngine;
66
using UnityEngine.Events;
77
using UnityEngine.Networking.PlayerConnection;
8-
using Utils;
8+
using UnityEngine.XR.iOS.Utils;
99

1010
// Runs on the remote device. Talks to the Editor.
1111
namespace UnityARInterface

Diff for: sdkproject/Assets/UnityARInterface/ARRemote/Scripts/ARRemoteEditorInterface.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using System.Collections.Generic;
22
using UnityEngine;
33
using UnityEngine.Networking.PlayerConnection;
4-
using Utils;
4+
using UnityEngine.XR.iOS.Utils;
55
using System.Collections;
66
using UnityEngine.XR;
77

Diff for: sdkproject/Assets/UnityARInterface/ARRemote/Scripts/ARSerializableObjects.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.Collections.Generic;
33
using System.Text;
44
using UnityEngine;
5-
using Utils;
5+
using UnityEngine.XR.iOS.Utils;
66

77
namespace UnityARInterface
88
{

Diff for: sdkproject/Assets/UnityARInterface/Scripts/ARKitInterface.cs

+9-7
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
namespace UnityARInterface
1111
{
12+
#if !UNITY_EDITOR && UNITY_IOS
1213
public class ARKitInterface : ARInterface
1314
{
1415
private Material m_ClearMaterial;
@@ -137,7 +138,7 @@ void UpdateFrame(UnityARCamera camera)
137138
m_TexturesInitialized = true;
138139
}
139140

140-
m_PointCloudData = camera.pointCloudData;
141+
m_PointCloudData = camera.pointCloud.Points;
141142
m_LightEstimate.capabilities = LightEstimateCapabilities.AmbientColorTemperature | LightEstimateCapabilities.AmbientIntensity;
142143
m_LightEstimate.ambientColorTemperature = camera.lightData.arLightEstimate.ambientColorTemperature;
143144

@@ -240,7 +241,7 @@ public override bool TryGetUnscaledPose(ref Pose pose)
240241
public override bool TryGetCameraImage(ref CameraImage cameraImage)
241242
{
242243
ARTextureHandles handles = nativeInterface.GetARVideoTextureHandles();
243-
if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero)
244+
if (handles.TextureY == System.IntPtr.Zero || handles.TextureCbCr == System.IntPtr.Zero)
244245
return false;
245246

246247
if (!m_TexturesInitialized)
@@ -300,7 +301,7 @@ public override void UpdateCamera(Camera camera)
300301
return;
301302

302303
ARTextureHandles handles = UnityARSessionNativeInterface.GetARSessionNativeInterface().GetARVideoTextureHandles();
303-
if (handles.textureY == System.IntPtr.Zero || handles.textureCbCr == System.IntPtr.Zero)
304+
if (handles.TextureY == System.IntPtr.Zero || handles.TextureCbCr == System.IntPtr.Zero)
304305
{
305306
m_CanRenderBackground = false;
306307
return;
@@ -315,7 +316,7 @@ public override void UpdateCamera(Camera camera)
315316
if (_videoTextureY == null)
316317
{
317318
_videoTextureY = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
318-
TextureFormat.R8, false, false, (System.IntPtr)handles.textureY);
319+
TextureFormat.R8, false, false, (System.IntPtr)handles.TextureY);
319320
_videoTextureY.filterMode = FilterMode.Bilinear;
320321
_videoTextureY.wrapMode = TextureWrapMode.Repeat;
321322
m_ClearMaterial.SetTexture("_textureY", _videoTextureY);
@@ -325,14 +326,14 @@ public override void UpdateCamera(Camera camera)
325326
if (_videoTextureCbCr == null)
326327
{
327328
_videoTextureCbCr = Texture2D.CreateExternalTexture(currentResolution.width, currentResolution.height,
328-
TextureFormat.RG16, false, false, (System.IntPtr)handles.textureCbCr);
329+
TextureFormat.RG16, false, false, (System.IntPtr)handles.TextureCbCr);
329330
_videoTextureCbCr.filterMode = FilterMode.Bilinear;
330331
_videoTextureCbCr.wrapMode = TextureWrapMode.Repeat;
331332
m_ClearMaterial.SetTexture("_textureCbCr", _videoTextureCbCr);
332333
}
333334

334-
_videoTextureY.UpdateExternalTexture(handles.textureY);
335-
_videoTextureCbCr.UpdateExternalTexture(handles.textureCbCr);
335+
_videoTextureY.UpdateExternalTexture(handles.TextureY);
336+
_videoTextureCbCr.UpdateExternalTexture(handles.TextureCbCr);
336337

337338
m_ClearMaterial.SetMatrix("_DisplayTransform", m_DisplayTransform);
338339
}
@@ -377,4 +378,5 @@ public override void DestroyAnchor(ARAnchor arAnchor)
377378
}
378379
}
379380
}
381+
#endif
380382
}

Diff for: sdkproject/Assets/UnityARKitPlugin.meta

+2-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
using UnityEngine;
2+
using UnityEngine.Networking.PlayerConnection;
3+
using System.Text;
4+
using UnityEngine.XR.iOS.Utils;
5+
6+
#if UNITY_EDITOR
7+
8+
using UnityEditor.Networking.PlayerConnection;
9+
10+
namespace UnityEngine.XR.iOS
11+
{
12+
public class ARKitFaceTrackingRemoteConnection : MonoBehaviour
13+
{
14+
[Header("AR FaceTracking Config Options")]
15+
public bool enableLightEstimation = true;
16+
17+
[Header("Run Options")]
18+
public bool resetTracking = true;
19+
public bool removeExistingAnchors = true;
20+
21+
EditorConnection editorConnection ;
22+
23+
int currentPlayerID = -1;
24+
string guimessage = "none";
25+
26+
Texture2D remoteScreenYTex;
27+
Texture2D remoteScreenUVTex;
28+
29+
bool bTexturesInitialized;
30+
31+
// Use this for initialization
32+
void Start () {
33+
34+
bTexturesInitialized = false;
35+
36+
37+
editorConnection = EditorConnection.instance;
38+
editorConnection.Initialize ();
39+
editorConnection.RegisterConnection (PlayerConnected);
40+
editorConnection.RegisterDisconnection (PlayerDisconnected);
41+
editorConnection.Register (ConnectionMessageIds.updateCameraFrameMsgId, UpdateCameraFrame);
42+
editorConnection.Register (ConnectionMessageIds.addFaceAnchorMsgeId, AddFaceAnchor);
43+
editorConnection.Register (ConnectionMessageIds.updateFaceAnchorMsgeId, UpdateFaceAnchor);
44+
editorConnection.Register (ConnectionMessageIds.removePlaneAnchorMsgeId, RemoveFaceAnchor);
45+
editorConnection.Register (ConnectionMessageIds.screenCaptureYMsgId, ReceiveRemoteScreenYTex);
46+
editorConnection.Register (ConnectionMessageIds.screenCaptureUVMsgId, ReceiveRemoteScreenUVTex);
47+
48+
}
49+
50+
void PlayerConnected(int playerID)
51+
{
52+
currentPlayerID = playerID;
53+
54+
}
55+
56+
void OnGUI()
57+
{
58+
59+
if (!bTexturesInitialized)
60+
{
61+
if (currentPlayerID != -1) {
62+
guimessage = "Connected to ARKit Remote device : " + currentPlayerID.ToString ();
63+
64+
if (GUI.Button (new Rect ((Screen.width / 2) - 200, (Screen.height / 2) - 200, 400, 100), "Start Remote ARKit FaceTracking Session"))
65+
{
66+
SendInitToPlayer ();
67+
}
68+
}
69+
else
70+
{
71+
guimessage = "Please connect to player in the console menu";
72+
}
73+
74+
GUI.Box (new Rect ((Screen.width / 2) - 200, (Screen.height / 2) + 100, 400, 50), guimessage);
75+
}
76+
77+
}
78+
79+
void PlayerDisconnected(int playerID)
80+
{
81+
if (currentPlayerID == playerID) {
82+
currentPlayerID = -1;
83+
}
84+
}
85+
86+
void OnDestroy()
87+
{
88+
#if UNITY_2017_1_OR_NEWER
89+
if(editorConnection != null) {
90+
editorConnection.DisconnectAll ();
91+
}
92+
#endif
93+
}
94+
95+
96+
void InitializeTextures(UnityARCamera camera)
97+
{
98+
int yWidth = camera.videoParams.yWidth;
99+
int yHeight = camera.videoParams.yHeight;
100+
int uvWidth = yWidth / 2;
101+
int uvHeight = yHeight / 2;
102+
if (remoteScreenYTex == null || remoteScreenYTex.width != yWidth || remoteScreenYTex.height != yHeight) {
103+
if (remoteScreenYTex) {
104+
Destroy (remoteScreenYTex);
105+
}
106+
remoteScreenYTex = new Texture2D (yWidth, yHeight, TextureFormat.R8, false, true);
107+
}
108+
if (remoteScreenUVTex == null || remoteScreenUVTex.width != uvWidth || remoteScreenUVTex.height != uvHeight) {
109+
if (remoteScreenUVTex) {
110+
Destroy (remoteScreenUVTex);
111+
}
112+
remoteScreenUVTex = new Texture2D (uvWidth, uvHeight, TextureFormat.RG16, false, true);
113+
}
114+
115+
bTexturesInitialized = true;
116+
}
117+
118+
void UpdateCameraFrame(MessageEventArgs mea)
119+
{
120+
serializableUnityARCamera serCamera = mea.data.Deserialize<serializableUnityARCamera> ();
121+
122+
UnityARCamera scamera = new UnityARCamera ();
123+
scamera = serCamera;
124+
125+
InitializeTextures (scamera);
126+
127+
UnityARSessionNativeInterface.SetStaticCamera (scamera);
128+
UnityARSessionNativeInterface.RunFrameUpdateCallbacks ();
129+
}
130+
131+
void AddFaceAnchor(MessageEventArgs mea)
132+
{
133+
serializableUnityARFaceAnchor serFaceAnchor = mea.data.Deserialize<serializableUnityARFaceAnchor> ();
134+
135+
ARFaceAnchor arFaceAnchor = serFaceAnchor;
136+
UnityARSessionNativeInterface.RunAddAnchorCallbacks (arFaceAnchor);
137+
}
138+
139+
void UpdateFaceAnchor(MessageEventArgs mea)
140+
{
141+
serializableUnityARFaceAnchor serFaceAnchor = mea.data.Deserialize<serializableUnityARFaceAnchor> ();
142+
143+
ARFaceAnchor arFaceAnchor = serFaceAnchor;
144+
UnityARSessionNativeInterface.RunUpdateAnchorCallbacks (arFaceAnchor);
145+
}
146+
147+
void RemoveFaceAnchor(MessageEventArgs mea)
148+
{
149+
serializableUnityARFaceAnchor serFaceAnchor = mea.data.Deserialize<serializableUnityARFaceAnchor> ();
150+
151+
ARFaceAnchor arFaceAnchor = serFaceAnchor;
152+
UnityARSessionNativeInterface.RunRemoveAnchorCallbacks (arFaceAnchor);
153+
}
154+
155+
void ReceiveRemoteScreenYTex(MessageEventArgs mea)
156+
{
157+
if (!bTexturesInitialized)
158+
return;
159+
remoteScreenYTex.LoadRawTextureData(CompressionHelper.ByteArrayDecompress(mea.data));
160+
remoteScreenYTex.Apply ();
161+
UnityARVideo arVideo = Camera.main.GetComponent<UnityARVideo>();
162+
if (arVideo) {
163+
arVideo.SetYTexure(remoteScreenYTex);
164+
}
165+
166+
}
167+
168+
void ReceiveRemoteScreenUVTex(MessageEventArgs mea)
169+
{
170+
if (!bTexturesInitialized)
171+
return;
172+
remoteScreenUVTex.LoadRawTextureData(CompressionHelper.ByteArrayDecompress(mea.data));
173+
remoteScreenUVTex.Apply ();
174+
UnityARVideo arVideo = Camera.main.GetComponent<UnityARVideo>();
175+
if (arVideo) {
176+
arVideo.SetUVTexure(remoteScreenUVTex);
177+
}
178+
179+
}
180+
181+
182+
void SendInitToPlayer()
183+
{
184+
185+
//we're going to reuse ARSessionConfiguration and only use its lightestimation field.
186+
187+
serializableFromEditorMessage sfem = new serializableFromEditorMessage ();
188+
sfem.subMessageId = SubMessageIds.editorInitARKitFaceTracking;
189+
serializableARSessionConfiguration ssc = new serializableARSessionConfiguration (UnityARAlignment.UnityARAlignmentCamera, UnityARPlaneDetection.None, false, enableLightEstimation, true);
190+
UnityARSessionRunOption roTracking = resetTracking ? UnityARSessionRunOption.ARSessionRunOptionResetTracking : 0;
191+
UnityARSessionRunOption roAnchors = removeExistingAnchors ? UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors : 0;
192+
sfem.arkitConfigMsg = new serializableARKitInit (ssc, roTracking | roAnchors);
193+
SendToPlayer (ConnectionMessageIds.fromEditorARKitSessionMsgId, sfem);
194+
}
195+
196+
void SendToPlayer(System.Guid msgId, byte[] data)
197+
{
198+
editorConnection.Send (msgId, data);
199+
}
200+
201+
public void SendToPlayer(System.Guid msgId, object serializableObject)
202+
{
203+
byte[] arrayToSend = serializableObject.SerializeToByteArray ();
204+
SendToPlayer (msgId, arrayToSend);
205+
}
206+
207+
208+
// Update is called once per frame
209+
void Update () {
210+
211+
}
212+
213+
}
214+
}
215+
#endif

Diff for: sdkproject/Assets/UnityARKitPlugin/ARKitRemote/ARKitFaceTrackingRemoteConnection.cs.meta

+12
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: sdkproject/Assets/UnityARKitPlugin/ARKitRemote/ARKitRemoteConnection.cs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using UnityEngine;
22
using UnityEngine.Networking.PlayerConnection;
33
using System.Text;
4-
using Utils;
4+
using UnityEngine.XR.iOS.Utils;
55

66
#if UNITY_EDITOR
77

@@ -16,6 +16,7 @@ public class ARKitRemoteConnection : MonoBehaviour
1616
public UnityARPlaneDetection planeDetection = UnityARPlaneDetection.Horizontal;
1717
public bool getPointCloud = true;
1818
public bool enableLightEstimation = true;
19+
public bool enableAutoFocus = true;
1920

2021
[Header("Run Options")]
2122
public bool resetTracking = true;
@@ -159,7 +160,7 @@ void ReceiveRemoteScreenYTex(MessageEventArgs mea)
159160
{
160161
if (!bTexturesInitialized)
161162
return;
162-
remoteScreenYTex.LoadRawTextureData(mea.data);
163+
remoteScreenYTex.LoadRawTextureData(CompressionHelper.ByteArrayDecompress(mea.data));
163164
remoteScreenYTex.Apply ();
164165
UnityARVideo arVideo = Camera.main.GetComponent<UnityARVideo>();
165166
if (arVideo) {
@@ -172,7 +173,7 @@ void ReceiveRemoteScreenUVTex(MessageEventArgs mea)
172173
{
173174
if (!bTexturesInitialized)
174175
return;
175-
remoteScreenUVTex.LoadRawTextureData(mea.data);
176+
remoteScreenUVTex.LoadRawTextureData(CompressionHelper.ByteArrayDecompress(mea.data));
176177
remoteScreenUVTex.Apply ();
177178
UnityARVideo arVideo = Camera.main.GetComponent<UnityARVideo>();
178179
if (arVideo) {
@@ -186,7 +187,7 @@ void SendInitToPlayer()
186187
{
187188
serializableFromEditorMessage sfem = new serializableFromEditorMessage ();
188189
sfem.subMessageId = SubMessageIds.editorInitARKit;
189-
serializableARSessionConfiguration ssc = new serializableARSessionConfiguration (startAlignment, planeDetection, getPointCloud, enableLightEstimation);
190+
serializableARSessionConfiguration ssc = new serializableARSessionConfiguration (startAlignment, planeDetection, getPointCloud, enableLightEstimation, enableAutoFocus);
190191
UnityARSessionRunOption roTracking = resetTracking ? UnityARSessionRunOption.ARSessionRunOptionResetTracking : 0;
191192
UnityARSessionRunOption roAnchors = removeExistingAnchors ? UnityARSessionRunOption.ARSessionRunOptionRemoveExistingAnchors : 0;
192193
sfem.arkitConfigMsg = new serializableARKitInit (ssc, roTracking | roAnchors);

0 commit comments

Comments
 (0)