Init
This commit is contained in:
@@ -0,0 +1,123 @@
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class PXR_ARCameraEffectManager : MonoBehaviour
|
||||
{
|
||||
public bool enableCameraEffect = false;
|
||||
[HideInInspector]
|
||||
public float colortempValue;
|
||||
[HideInInspector]
|
||||
public float brightnessValue;
|
||||
[HideInInspector]
|
||||
public float saturationValue;
|
||||
[HideInInspector]
|
||||
public float contrastValue;
|
||||
[HideInInspector]
|
||||
public Texture2D lutTex1;
|
||||
[HideInInspector]
|
||||
public Texture2D lutTex2;
|
||||
[HideInInspector]
|
||||
public Texture2D lutTex3;
|
||||
[HideInInspector]
|
||||
public Texture2D lutTex4;
|
||||
[HideInInspector]
|
||||
public Texture2D lutTex5;
|
||||
|
||||
private const string TAG = "PXR_ARCameraEffectManager";
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
Camera camera = Camera.main;
|
||||
camera.clearFlags = CameraClearFlags.SolidColor;
|
||||
camera.backgroundColor = new Color(0, 0, 0, 0);
|
||||
if (enableCameraEffect)
|
||||
{
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Colortemp, colortempValue, 1);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Brightness, brightnessValue, 1);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Saturation, saturationValue, 1);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Contrast, contrastValue, 1);
|
||||
}
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
void Update()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void SetColortemp(float x)
|
||||
{
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Colortemp, x, 1);
|
||||
}
|
||||
|
||||
public void SetBrightness(float x)
|
||||
{
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Brightness, x, 1);
|
||||
}
|
||||
|
||||
public void SetSaturation(float x)
|
||||
{
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Saturation, x, 1);
|
||||
}
|
||||
|
||||
public void SetContrast(float x)
|
||||
{
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughEffect(PxrLayerEffect.Contrast, x, 1);
|
||||
}
|
||||
|
||||
public void EnableLut(bool enable)
|
||||
{
|
||||
PLog.d(TAG, $"SetLutRow lutTex={lutTex1}, enable={enable} ");
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(enable);
|
||||
if (lutTex1 && enable)
|
||||
{
|
||||
PLog.d(TAG, $"SetLutRow lutTex={lutTex1}");
|
||||
PXR_MixedReality.SetVideoSeeThroughLut(lutTex1, 8, 8);
|
||||
}
|
||||
}
|
||||
|
||||
public void SetLut(int index)
|
||||
{
|
||||
PLog.d(TAG, $"SetLutRow index={index}");
|
||||
switch (index)
|
||||
{
|
||||
case 0:
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(false);
|
||||
break;
|
||||
case 1:
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughLut(lutTex1, 8, 8);
|
||||
break;
|
||||
case 2:
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughLut(lutTex2, 8, 8);
|
||||
break;
|
||||
case 3:
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughLut(lutTex3, 8, 8);
|
||||
break;
|
||||
case 4:
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughLut(lutTex4, 8, 8);
|
||||
break;
|
||||
case 5:
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(true);
|
||||
PXR_MixedReality.SetVideoSeeThroughLut(lutTex5, 8, 8);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
PXR_MixedReality.EnableVideoSeeThroughEffect(false);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d49336162c2023d45a1366799de154fb
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,335 @@
|
||||
#if AR_FOUNDATION_5 || AR_FOUNDATION_6
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARSubsystems;
|
||||
|
||||
namespace Unity.XR.PXR
|
||||
{
|
||||
public class PXR_AnchorSubsystem : XRAnchorSubsystem
|
||||
{
|
||||
internal const string k_SubsystemId = "PXR_AnchorSubsystem";
|
||||
|
||||
class PXR_AnchorProvider : Provider
|
||||
{
|
||||
private Dictionary<TrackableId, ulong> trackableIdToHandleMap;
|
||||
private Dictionary<ulong, XRAnchor> handleToXRAnchorMap;
|
||||
private HashSet<ulong> managedAnchorHandles;
|
||||
private Dictionary<Guid, ulong> lastAnchorToTime;
|
||||
private bool isInit = false;
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
StartSpatialAnchorProvider();
|
||||
}
|
||||
|
||||
private async void StartSpatialAnchorProvider()
|
||||
{
|
||||
var result = await PXR_MixedReality.StartSenseDataProvider(PxrSenseDataProviderType.SpatialAnchor);
|
||||
if (result == PxrResult.SUCCESS)
|
||||
{
|
||||
if (!isInit)
|
||||
{
|
||||
trackableIdToHandleMap = new Dictionary<TrackableId, ulong>();
|
||||
handleToXRAnchorMap = new Dictionary<ulong, XRAnchor>();
|
||||
managedAnchorHandles = new HashSet<ulong>();
|
||||
isInit = true;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Spatial Anchor Provider Start Failed:" + result);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
var result = PXR_MixedReality.StopSenseDataProvider(PxrSenseDataProviderType.SpatialAnchor);
|
||||
if (result == PxrResult.SUCCESS)
|
||||
{
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Spatial Anchor Provider Stop Failed:" + result);
|
||||
}
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override TrackableChanges<XRAnchor> GetChanges(XRAnchor defaultAnchor, Allocator allocator)
|
||||
{
|
||||
return new TrackableChanges<XRAnchor>();
|
||||
}
|
||||
|
||||
#if AR_FOUNDATION_5
|
||||
public override bool TryAddAnchor(Pose pose, out XRAnchor anchor)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<(PxrResult result, ulong anchorHandle, Guid uuid)>();
|
||||
var tcs2 = new TaskCompletionSource<PxrResult>();
|
||||
Task.Run(() =>
|
||||
{
|
||||
var (pxrResult, handle, guid) = PXR_MixedReality.CreateSpatialAnchorAsync(pose.position, pose.rotation).Result;
|
||||
|
||||
tcs.SetResult((pxrResult, handle, guid));
|
||||
});
|
||||
var (result, anchorHandle, uuid) = tcs.Task.Result;
|
||||
if (result == PxrResult.SUCCESS)
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var pxrResult = PXR_MixedReality.PersistSpatialAnchorAsync(anchorHandle).Result;
|
||||
|
||||
tcs2.SetResult(pxrResult);
|
||||
});
|
||||
|
||||
var result2 = tcs2.Task.Result;
|
||||
if (result2 == PxrResult.SUCCESS)
|
||||
{
|
||||
var bytes = uuid.ToByteArray();
|
||||
var trackabledId = new TrackableId(BitConverter.ToUInt64(bytes, 0), BitConverter.ToUInt64(bytes, 8));
|
||||
var nativePtr = new IntPtr((long)anchorHandle);
|
||||
anchor = new XRAnchor(trackabledId, pose, TrackingState.Tracking, nativePtr);
|
||||
trackableIdToHandleMap[trackabledId] = anchorHandle;
|
||||
handleToXRAnchorMap[anchorHandle] = anchor;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
anchor = XRAnchor.defaultValue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
anchor = XRAnchor.defaultValue;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override bool TryRemoveAnchor(TrackableId anchorId)
|
||||
{
|
||||
if (trackableIdToHandleMap.TryGetValue(anchorId, out var anchorHandle))
|
||||
{
|
||||
var result = PXR_MixedReality.DestroyAnchor(anchorHandle);
|
||||
if (result == PxrResult.SUCCESS)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<PxrResult>();
|
||||
Task.Run(() =>
|
||||
{
|
||||
var pxrResult = PXR_MixedReality.UnPersistSpatialAnchorAsync(anchorHandle).Result;
|
||||
|
||||
tcs.SetResult(pxrResult);
|
||||
});
|
||||
var result1 = tcs.Task.Result;
|
||||
if (result1 == PxrResult.SUCCESS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
public override Awaitable<Result<XRAnchor>> TryAddAnchorAsync(Pose pose)
|
||||
{
|
||||
var synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnknownError);
|
||||
var awaitable = new AwaitableCompletionSource<Result<XRAnchor>>();
|
||||
var anchor = XRAnchor.defaultValue;
|
||||
|
||||
var tcs = new TaskCompletionSource<(PxrResult result, ulong anchorHandle, Guid uuid)>();
|
||||
Task.Run(() =>
|
||||
{
|
||||
var (pxrResult, handle, guid) = PXR_MixedReality.CreateSpatialAnchorAsync(pose.position, pose.rotation).Result;
|
||||
|
||||
tcs.SetResult((pxrResult, handle, guid));
|
||||
});
|
||||
var (result, anchorHandle, uuid) = tcs.Task.Result;
|
||||
if (result == PxrResult.SUCCESS)
|
||||
{
|
||||
var bytes = uuid.ToByteArray();
|
||||
var trackabledId = new TrackableId(BitConverter.ToUInt64(bytes, 0), BitConverter.ToUInt64(bytes, 8));
|
||||
var nativePtr = new IntPtr((long)anchorHandle);
|
||||
synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnqualifiedSuccess);
|
||||
anchor = new XRAnchor(trackabledId, pose, TrackingState.Tracking, nativePtr);
|
||||
trackableIdToHandleMap[trackabledId] = anchorHandle;
|
||||
handleToXRAnchorMap[anchorHandle] = anchor;
|
||||
}
|
||||
|
||||
var returnResult = new Result<XRAnchor>(synchronousResultStatus, anchor);
|
||||
awaitable.SetResult(returnResult);
|
||||
return awaitable.Awaitable;
|
||||
}
|
||||
|
||||
public override Awaitable<Result<SerializableGuid>> TrySaveAnchorAsync(TrackableId anchorId, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tcs2 = new TaskCompletionSource<PxrResult>();
|
||||
var synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnknownError);
|
||||
var awaitable = new AwaitableCompletionSource<Result<SerializableGuid>>();
|
||||
var returnResult = new Result<SerializableGuid>(synchronousResultStatus, default);
|
||||
|
||||
if (trackableIdToHandleMap.TryGetValue(anchorId, out var anchorHandle))
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var pxrResult = PXR_MixedReality.PersistSpatialAnchorAsync(anchorHandle, cancellationToken).Result;
|
||||
|
||||
tcs2.SetResult(pxrResult);
|
||||
});
|
||||
|
||||
var result2 = tcs2.Task.Result;
|
||||
if (result2 == PxrResult.SUCCESS)
|
||||
{
|
||||
synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnqualifiedSuccess);
|
||||
returnResult = new Result<SerializableGuid>(synchronousResultStatus, anchorId);
|
||||
}
|
||||
else
|
||||
{
|
||||
synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.PlatformError, (int)result2);
|
||||
returnResult = new Result<SerializableGuid>(synchronousResultStatus, default);
|
||||
}
|
||||
|
||||
}
|
||||
awaitable.SetResult(returnResult);
|
||||
return awaitable.Awaitable;
|
||||
}
|
||||
|
||||
public override Awaitable<XRResultStatus> TryEraseAnchorAsync(SerializableGuid savedAnchorGuid, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<PxrResult>();
|
||||
var synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnknownError);
|
||||
var awaitable = new AwaitableCompletionSource<XRResultStatus>();
|
||||
|
||||
if (trackableIdToHandleMap.TryGetValue(savedAnchorGuid, out var anchorHandle))
|
||||
{
|
||||
Task.Run(() =>
|
||||
{
|
||||
var pxrResult = PXR_MixedReality.UnPersistSpatialAnchorAsync(anchorHandle, cancellationToken).Result;
|
||||
|
||||
tcs.SetResult(pxrResult);
|
||||
});
|
||||
var result1 = tcs.Task.Result;
|
||||
if (result1 == PxrResult.SUCCESS)
|
||||
{
|
||||
synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnqualifiedSuccess);
|
||||
}
|
||||
else
|
||||
{
|
||||
synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.PlatformError, (int)result1);
|
||||
}
|
||||
}
|
||||
awaitable.SetResult(synchronousResultStatus);
|
||||
return awaitable.Awaitable;
|
||||
}
|
||||
|
||||
public override bool TryRemoveAnchor(TrackableId anchorId)
|
||||
{
|
||||
if (trackableIdToHandleMap.TryGetValue(anchorId, out var anchorHandle))
|
||||
{
|
||||
var result = PXR_MixedReality.DestroyAnchor(anchorHandle);
|
||||
if (result == PxrResult.SUCCESS)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public override Awaitable<Result<XRAnchor>> TryLoadAnchorAsync(SerializableGuid savedAnchorGuid, CancellationToken cancellationToken = default)
|
||||
{
|
||||
var tcs = new TaskCompletionSource<(PxrResult result, List<ulong> anchorHandleList)>();
|
||||
var synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnknownError);
|
||||
var awaitable = new AwaitableCompletionSource<Result<XRAnchor>>();
|
||||
var anchor = XRAnchor.defaultValue;
|
||||
var guid = savedAnchorGuid.guid;
|
||||
Guid[] guids = { guid };
|
||||
Task.Run(() =>
|
||||
{
|
||||
var pxrResult = PXR_MixedReality.QuerySpatialAnchorAsync(guids).Result;
|
||||
|
||||
tcs.SetResult(pxrResult);
|
||||
});
|
||||
var result1 = tcs.Task.Result;
|
||||
if (result1.result == PxrResult.SUCCESS)
|
||||
{
|
||||
for (int i = 0; i < result1.anchorHandleList.Count; i++)
|
||||
{
|
||||
var nativePtr = new IntPtr((long)result1.anchorHandleList[i]);
|
||||
synchronousResultStatus = new XRResultStatus(XRResultStatus.StatusCode.UnqualifiedSuccess);
|
||||
PXR_MixedReality.LocateAnchor(result1.anchorHandleList[i], out var position, out var quaternion);
|
||||
anchor = new XRAnchor(savedAnchorGuid, new Pose(position,quaternion), TrackingState.Tracking, nativePtr);
|
||||
|
||||
trackableIdToHandleMap[savedAnchorGuid] = result1.anchorHandleList[i];
|
||||
handleToXRAnchorMap[result1.anchorHandleList[i]] = anchor;
|
||||
}
|
||||
}
|
||||
var returnResult = new Result<XRAnchor>(synchronousResultStatus, anchor);
|
||||
awaitable.SetResult(returnResult);
|
||||
return awaitable.Awaitable;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void RegisterDescriptor()
|
||||
{
|
||||
|
||||
#if AR_FOUNDATION_5
|
||||
var cInfo = new XRAnchorSubsystemDescriptor.Cinfo()
|
||||
{
|
||||
id = k_SubsystemId,
|
||||
providerType = typeof(PXR_AnchorProvider),
|
||||
subsystemTypeOverride = typeof(PXR_AnchorSubsystem),
|
||||
supportsTrackableAttachments = false
|
||||
};
|
||||
XRAnchorSubsystemDescriptor.Create(cInfo);
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
var cInfo = new XRAnchorSubsystemDescriptor.Cinfo()
|
||||
{
|
||||
id = k_SubsystemId,
|
||||
providerType = typeof(PXR_AnchorProvider),
|
||||
subsystemTypeOverride = typeof(PXR_AnchorSubsystem),
|
||||
supportsTrackableAttachments = false,
|
||||
supportsSynchronousAdd = false,
|
||||
supportsSaveAnchor = true,
|
||||
supportsLoadAnchor = true,
|
||||
supportsEraseAnchor = true,
|
||||
supportsGetSavedAnchorIds = false,
|
||||
supportsAsyncCancellation = false
|
||||
};
|
||||
XRAnchorSubsystemDescriptor.Register(cInfo);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19cb04e12d027e842b3c606ef47c61ac
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,139 @@
|
||||
#if AR_FOUNDATION_5 || AR_FOUNDATION_6
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Unity.XR.PXR
|
||||
{
|
||||
public class PXR_BlendShapeVisualizer : MonoBehaviour
|
||||
{
|
||||
[SerializeField]
|
||||
float m_CoefficientScale = 100.0f;
|
||||
|
||||
public float coefficientScale
|
||||
{
|
||||
get { return m_CoefficientScale; }
|
||||
set { m_CoefficientScale = value; }
|
||||
}
|
||||
|
||||
[SerializeField]
|
||||
SkinnedMeshRenderer m_SkinnedMeshRenderer;
|
||||
|
||||
public SkinnedMeshRenderer skinnedMeshRenderer
|
||||
{
|
||||
get
|
||||
{
|
||||
return m_SkinnedMeshRenderer;
|
||||
}
|
||||
set
|
||||
{
|
||||
m_SkinnedMeshRenderer = value;
|
||||
CreateFeatureBlendMapping();
|
||||
}
|
||||
}
|
||||
|
||||
private PXR_FaceSubsystem m_PICOFaceSubsystem;
|
||||
private Dictionary<BlendShapeIndex, int> m_FaceBlendShapeIndexMap;
|
||||
private PxrFaceTrackingInfo ftInfo = new PxrFaceTrackingInfo();
|
||||
|
||||
|
||||
void Awake()
|
||||
{
|
||||
CreateFeatureBlendMapping();
|
||||
}
|
||||
|
||||
void CreateFeatureBlendMapping()
|
||||
{
|
||||
if (skinnedMeshRenderer == null || skinnedMeshRenderer.sharedMesh == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
const string strPrefix = "blendShape2.";
|
||||
m_FaceBlendShapeIndexMap = new Dictionary<BlendShapeIndex, int>();
|
||||
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookDown_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookDown_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.NoseSneer_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "noseSneer_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookIn_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookIn_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.BrowInnerUp] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "browInnerUp");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.BrowDown_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "browDown_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthClose] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthClose");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthLowerDown_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthLowerDown_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.JawOpen] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "jawOpen");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthUpperUp_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthUpperUp_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthShrugUpper] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthShrugUpper");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthFunnel] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthFunnel");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookIn_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookIn_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookDown_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookDown_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.NoseSneer_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "noseSneer_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthRollUpper] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthRollUpper");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.JawRight] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "jawRight");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.BrowDown_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "browDown_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthShrugLower] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthShrugLower");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthRollLower] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthRollLower");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthSmile_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthSmile_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthPress_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthPress_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthSmile_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthSmile_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthPress_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthPress_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthDimple_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthDimple_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthLeft] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthLeft");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.JawForward] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "jawForward");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeSquint_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeSquint_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthFrown_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthFrown_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeBlink_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeBlink_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.CheekSquint_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "cheekSquint_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.BrowOuterUp_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "browOuterUp_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookUp_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookUp_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.JawLeft] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "jawLeft");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthStretch_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthStretch_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthPucker] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthPucker");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookUp_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookUp_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.BrowOuterUp_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "browOuterUp_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.CheekSquint_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "cheekSquint_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeBlink_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeBlink_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthUpperUp_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthUpperUp_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthFrown_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthFrown_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeSquint_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeSquint_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthStretch_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthStretch_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.CheekPuff] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "cheekPuff");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookOut_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookOut_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeLookOut_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeLookOut_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeWide_R] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeWide_R");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.EyeWide_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "eyeWide_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthDimple_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthDimple_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthLowerDown_L] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthLowerDown_L");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.MouthRight] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "mouthRight");
|
||||
m_FaceBlendShapeIndexMap[BlendShapeIndex.TongueOut] = skinnedMeshRenderer.sharedMesh.GetBlendShapeIndex(strPrefix + "tongueOut");
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (skinnedMeshRenderer == null || !skinnedMeshRenderer.enabled || skinnedMeshRenderer.sharedMesh == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
UpdateBlendShapeWeight();
|
||||
}
|
||||
|
||||
unsafe private void UpdateBlendShapeWeight()
|
||||
{
|
||||
PXR_FaceSubsystem.GetBlendShapeCoefficients(ref ftInfo);
|
||||
if (ftInfo.videoInputValid[0] == 1)
|
||||
{
|
||||
for (int i = 0; i < PXR_FaceSubsystem.FACE_COUNT; i++)
|
||||
{
|
||||
int mappedBlendShapeIndex;
|
||||
if (m_FaceBlendShapeIndexMap.TryGetValue((BlendShapeIndex)i, out mappedBlendShapeIndex))
|
||||
{
|
||||
if (mappedBlendShapeIndex >= 0)
|
||||
{
|
||||
skinnedMeshRenderer.SetBlendShapeWeight(mappedBlendShapeIndex, ftInfo.blendShapeWeight[i] * coefficientScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3cbf521a995e21e4f921345df29c6686
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,99 @@
|
||||
#if AR_FOUNDATION_5 || AR_FOUNDATION_6
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARSubsystems;
|
||||
|
||||
public class PXR_CameraSubsystem : XRCameraSubsystem
|
||||
{
|
||||
internal const string k_SubsystemId = "PXR_CameraSubsystem";
|
||||
|
||||
internal static PXR_CameraSubsystem instance { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Do not call this directly. Call create on a valid <see cref="XRCameraSubsystemDescriptor"/> instead.
|
||||
/// </summary>
|
||||
public PXR_CameraSubsystem()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
class CameraProvider : Provider
|
||||
{
|
||||
/// <summary>
|
||||
/// Start the camera functionality.
|
||||
/// </summary>
|
||||
public override void Start()
|
||||
{
|
||||
Debug.Log($"{k_SubsystemId} Start().");
|
||||
PXR_Plugin.Boundary.UPxr_SetSeeThroughBackground(true);
|
||||
PXR_Plugin.System.SessionStateChanged += EnableVST;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Stop the camera functionality.
|
||||
/// </summary>
|
||||
public override void Stop()
|
||||
{
|
||||
Debug.Log($"{k_SubsystemId} Stop().");
|
||||
PXR_Plugin.Boundary.UPxr_SetSeeThroughBackground(false);
|
||||
PXR_Plugin.System.SessionStateChanged -= EnableVST;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Destroy any resources required for the camera functionality.
|
||||
/// </summary>
|
||||
public override void Destroy() { }
|
||||
|
||||
public void EnableVST(XrSessionState state)
|
||||
{
|
||||
if (state == XrSessionState.Ready)
|
||||
{
|
||||
PXR_Plugin.Boundary.UPxr_SetSeeThroughBackground(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void RegisterDescriptor()
|
||||
{
|
||||
#if AR_FOUNDATION_5
|
||||
var cameraSubsystemCinfo = new XRCameraSubsystemCinfo
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
var cameraSubsystemCinfo = new XRCameraSubsystemDescriptor.Cinfo
|
||||
#endif
|
||||
{
|
||||
id = k_SubsystemId,
|
||||
providerType = typeof(CameraProvider),
|
||||
subsystemTypeOverride = typeof(PXR_CameraSubsystem),
|
||||
supportsAverageBrightness = false,
|
||||
supportsAverageColorTemperature = false,
|
||||
supportsColorCorrection = false,
|
||||
supportsDisplayMatrix = false,
|
||||
supportsProjectionMatrix = false,
|
||||
supportsTimestamp = false,
|
||||
supportsCameraConfigurations = false,
|
||||
supportsCameraImage = false,
|
||||
supportsAverageIntensityInLumens = false,
|
||||
supportsFocusModes = false,
|
||||
supportsFaceTrackingAmbientIntensityLightEstimation = false,
|
||||
supportsFaceTrackingHDRLightEstimation = false,
|
||||
supportsWorldTrackingAmbientIntensityLightEstimation = false,
|
||||
supportsWorldTrackingHDRLightEstimation = false,
|
||||
supportsCameraGrain = false,
|
||||
};
|
||||
|
||||
#if AR_FOUNDATION_5
|
||||
if (!XRCameraSubsystem.Register(cameraSubsystemCinfo))
|
||||
{
|
||||
PLog.e(k_SubsystemId, $"Failed to register the {k_SubsystemId} subsystem.");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
XRCameraSubsystemDescriptor.Register(cameraSubsystemCinfo);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 871b6ba16680eb74d9d891e95cf83bdc
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,126 @@
|
||||
#if AR_FOUNDATION_5 || AR_FOUNDATION_6
|
||||
using Unity.XR.PXR;
|
||||
using System;
|
||||
using Unity.Collections;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARSubsystems;
|
||||
|
||||
public class PXR_FaceSubsystem : XRFaceSubsystem
|
||||
{
|
||||
internal const string k_SubsystemId = "PXR_FaceSubsystem";
|
||||
|
||||
internal const int FACE_COUNT = 52;
|
||||
internal const int LIPSYNC_COUNT = 20;
|
||||
|
||||
public override TrackableChanges<XRFace> GetChanges(Allocator allocator)
|
||||
{
|
||||
return base.GetChanges(allocator);
|
||||
}
|
||||
|
||||
public unsafe static int GetBlendShapeCoefficients(ref PxrFaceTrackingInfo ftInfo)
|
||||
{
|
||||
// PXR_System.GetFaceTrackingData(0, GetDataType.PXR_GET_FACE_DATA_DEFAULT, ref ftInfo);
|
||||
return 0;
|
||||
}
|
||||
|
||||
class FaceProvider : Provider
|
||||
{
|
||||
bool isFaceTrackingSupported = false;
|
||||
int inited;
|
||||
|
||||
int supportedModesCount;
|
||||
FaceTrackingMode[] supportedModes;
|
||||
public override int supportedFaceCount => base.supportedFaceCount;
|
||||
|
||||
public override int requestedMaximumFaceCount { get => base.requestedMaximumFaceCount; set => base.requestedMaximumFaceCount = value; }
|
||||
|
||||
public override int currentMaximumFaceCount => base.currentMaximumFaceCount;
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
PLog.i(k_SubsystemId, "Destroy");
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return base.Equals(obj);
|
||||
}
|
||||
|
||||
public unsafe override TrackableChanges<XRFace> GetChanges(XRFace defaultFace, Allocator allocator)
|
||||
{
|
||||
return new TrackableChanges<XRFace>();
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return base.GetHashCode();
|
||||
}
|
||||
|
||||
public override void Start()
|
||||
{
|
||||
// PXR_MotionTracking.GetFaceTrackingSupported(ref isFaceTrackingSupported, ref supportedModesCount, ref supportedModes);
|
||||
// if (isFaceTrackingSupported)
|
||||
// {
|
||||
// FaceTrackingStartInfo startInfo = new FaceTrackingStartInfo();
|
||||
// startInfo.mode = FaceTrackingMode.PXR_FTM_FACE_LIPS_BS;
|
||||
// inited = PXR_MotionTracking.StartFaceTracking(ref startInfo);
|
||||
// }
|
||||
// Debug.Log($"{k_SubsystemId} Start(). isFaceTrackingSupported:{isFaceTrackingSupported}, init:{inited}");
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
// if (isFaceTrackingSupported)
|
||||
// {
|
||||
// FaceTrackingStopInfo stopInfo = new FaceTrackingStopInfo();
|
||||
// stopInfo.pause = 0;
|
||||
// inited = PXR_MotionTracking.StopFaceTracking(ref stopInfo);
|
||||
// }
|
||||
// Debug.Log($"{k_SubsystemId} Stop(). isFaceTrackingSupported:{isFaceTrackingSupported}, init:{inited}");
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return base.ToString();
|
||||
}
|
||||
|
||||
protected override bool TryInitialize()
|
||||
{
|
||||
PXR_Plugin.System.UPxr_EnableFaceTracking(true);
|
||||
PXR_Plugin.MotionTracking.UPxr_WantFaceTrackingService();
|
||||
return base.TryInitialize();
|
||||
}
|
||||
}
|
||||
|
||||
// this method is run on startup of the app to register this provider with XR Subsystem Manager
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void RegisterDescriptor()
|
||||
{
|
||||
PLog.i(k_SubsystemId, "RegisterDescriptor");
|
||||
#if AR_FOUNDATION_5
|
||||
var descriptorParams = new FaceSubsystemParams
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
var descriptorParams = new XRFaceSubsystemDescriptor.Cinfo
|
||||
#endif
|
||||
{
|
||||
supportsFacePose = false,
|
||||
supportsFaceMeshVerticesAndIndices = true,
|
||||
supportsFaceMeshUVs = true,
|
||||
supportsFaceMeshNormals = true,
|
||||
id = k_SubsystemId,
|
||||
providerType = typeof(FaceProvider),
|
||||
subsystemTypeOverride = typeof(PXR_FaceSubsystem)
|
||||
};
|
||||
|
||||
#if AR_FOUNDATION_5
|
||||
XRFaceSubsystemDescriptor.Create(descriptorParams);
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
XRFaceSubsystemDescriptor.Register(descriptorParams);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4536988f3bbe0e749aac969d1074d0cf
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,231 @@
|
||||
#if AR_FOUNDATION_5 || AR_FOUNDATION_6
|
||||
using Unity.Collections;
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARSubsystems;
|
||||
#if PICO_OPENXR_SDK
|
||||
using Unity.XR.OpenXR.Features.PICOSupport;
|
||||
#endif
|
||||
public class PXR_HumanBodySubsystem : XRHumanBodySubsystem
|
||||
{
|
||||
internal const string k_SubsystemId = "PXR_HumanBodySubsystem";
|
||||
|
||||
class HumanBodyProvider : Provider
|
||||
{
|
||||
bool isBodyTrackingSupported = false;
|
||||
bool init = false;
|
||||
|
||||
private BodyTrackingGetDataInfo bdi = new BodyTrackingGetDataInfo();
|
||||
private BodyTrackingData bd = new BodyTrackingData();
|
||||
BodyTrackingStatus bs = new BodyTrackingStatus();
|
||||
bool istracking = false;
|
||||
public override void Start()
|
||||
{
|
||||
PLog.i(k_SubsystemId, "Start");
|
||||
init = true;
|
||||
}
|
||||
|
||||
public override void Stop()
|
||||
{
|
||||
PLog.i(k_SubsystemId, "Stop");
|
||||
#if PICO_OPENXR_SDK
|
||||
int ret = BodyTrackingFeature.StopBodyTracking();
|
||||
#else
|
||||
int ret = PXR_MotionTracking.StopBodyTracking();
|
||||
#endif
|
||||
}
|
||||
|
||||
public override void Destroy()
|
||||
{
|
||||
PLog.i(k_SubsystemId, "Destroy");
|
||||
}
|
||||
|
||||
public override void GetSkeleton(TrackableId trackableId, Allocator allocator, ref NativeArray<XRHumanBodyJoint> skeleton)
|
||||
{
|
||||
PLog.d(k_SubsystemId, $"GetSkeleton isBodyTrackingSupported={isBodyTrackingSupported}");
|
||||
#if UNITY_ANDROID
|
||||
if (isBodyTrackingSupported)
|
||||
{
|
||||
// Get the position and orientation data of each body node.
|
||||
#if PICO_OPENXR_SDK
|
||||
BodyTrackingFeature.GetBodyTrackingState(ref istracking, ref bs);
|
||||
#else
|
||||
PXR_MotionTracking.GetBodyTrackingState(ref istracking, ref bs);
|
||||
#endif
|
||||
// Debug.Log($"GetBodyTrackingState stateCode = {bs.stateCode} message = {bs.message} ");
|
||||
// If not calibrated, invoked system motion tracker app for calibration.
|
||||
|
||||
|
||||
// If not calibrated, invoked system motion tracker app for calibration.
|
||||
if (bs.stateCode!=BodyTrackingStatusCode.BT_VALID)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int ret = -1;
|
||||
|
||||
#if PICO_OPENXR_SDK
|
||||
ret = BodyTrackingFeature.GetBodyTrackingData(ref bdi, ref bd);
|
||||
#else
|
||||
ret = PXR_MotionTracking.GetBodyTrackingData(ref bdi, ref bd);
|
||||
#endif
|
||||
|
||||
// if the return is successful
|
||||
if (ret == 0)
|
||||
{
|
||||
skeleton = new NativeArray<XRHumanBodyJoint>((int)BodyTrackerRole.ROLE_NUM, allocator);
|
||||
for (int i = 0; i < (int)BodyTrackerRole.ROLE_NUM; i++)
|
||||
{
|
||||
BodyTrackerTransPose localPose = bd.roleDatas[i].localPose;
|
||||
Vector3 pos = new Vector3((float)bd.roleDatas[i].localPose.PosX, (float)bd.roleDatas[i].localPose.PosY,
|
||||
(float)bd.roleDatas[i].localPose.PosZ);
|
||||
Quaternion qu = new Quaternion((float)bd.roleDatas[i].localPose.RotQx, (float)bd.roleDatas[i].localPose.RotQy,
|
||||
(float)bd.roleDatas[i].localPose.RotQz, (float)bd.roleDatas[i].localPose.RotQw);
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 180, 0));
|
||||
}
|
||||
else if (i == 1)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 0, -95));
|
||||
}
|
||||
else if (i == 2)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 0, 95));
|
||||
}
|
||||
else if (i == 4)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 0, -90));
|
||||
}
|
||||
else if (i == 3 || i == 5 || i == 12)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 0, 90));
|
||||
}
|
||||
else if (i == 7)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(180, -90, 0));
|
||||
}
|
||||
else if (i == 6 || i == 9 || i == 15)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 90, 90));
|
||||
}
|
||||
else if (i == 8 || i == 10 || i == 11)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 90, 0));
|
||||
}
|
||||
else if (i == 13 || i == 14 || i == 16 || i == 17 || i == 18 || i == 19 || i == 20)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(0, 0, 180));
|
||||
}
|
||||
else if (i == 21)
|
||||
{
|
||||
qu *= Quaternion.Euler(new Vector3(180, 0, 180));
|
||||
}
|
||||
|
||||
Pose pose = new Pose(pos, qu);
|
||||
XRHumanBodyJoint mXRHumanBodyJoint = new XRHumanBodyJoint(i, 0, Vector3.one, pose, Vector3.one, pose, true);
|
||||
skeleton[i] = mXRHumanBodyJoint;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
public override TrackableChanges<XRHumanBody> GetChanges(XRHumanBody defaultHumanBody, Allocator allocator)
|
||||
{
|
||||
PLog.d(k_SubsystemId, $"GetChanges init={init}, bodyTracking={PXR_ProjectSetting.GetProjectConfig().bodyTracking} ");
|
||||
if (init)
|
||||
{
|
||||
if (PXR_ProjectSetting.GetProjectConfig().bodyTracking)
|
||||
{
|
||||
PXR_Plugin.MotionTracking.UPxr_WantBodyTrackingService();
|
||||
|
||||
// Query whether the current device supports human body tracking.
|
||||
#if PICO_OPENXR_SDK
|
||||
isBodyTrackingSupported = BodyTrackingFeature.IsBodyTrackingSupported();
|
||||
#else
|
||||
PXR_MotionTracking.GetBodyTrackingSupported(ref isBodyTrackingSupported);
|
||||
#endif
|
||||
if (isBodyTrackingSupported)
|
||||
{
|
||||
BodyTrackingBoneLength bones = new BodyTrackingBoneLength();
|
||||
|
||||
#if PICO_OPENXR_SDK
|
||||
// Start BodyTracking
|
||||
BodyTrackingFeature.StartBodyTracking(BodyJointSet.BODY_JOINT_SET_BODY_FULL_START, bones);
|
||||
// Has Pico motion tracker completed calibration (0: not completed; 1: completed)?
|
||||
BodyTrackingFeature.GetBodyTrackingState(ref istracking, ref bs);
|
||||
#else
|
||||
// Start BodyTracking
|
||||
PXR_MotionTracking.StartBodyTracking(BodyJointSet.BODY_JOINT_SET_BODY_FULL_START, bones);
|
||||
// Has Pico motion tracker completed calibration (0: not completed; 1: completed)?
|
||||
PXR_MotionTracking.GetBodyTrackingState(ref istracking, ref bs);
|
||||
#endif
|
||||
// Debug.Log($"GetBodyTrackingState stateCode = {bs.stateCode} message = {bs.message} ");
|
||||
// If not calibrated, invoked system motion tracker app for calibration.
|
||||
|
||||
if (bs.stateCode!=BodyTrackingStatusCode.BT_VALID)
|
||||
{
|
||||
if (bs.message==BodyTrackingMessage.BT_MESSAGE_TRACKER_NOT_CALIBRATED||bs.message==BodyTrackingMessage.BT_MESSAGE_UNKNOWN)
|
||||
{
|
||||
#if PICO_OPENXR_SDK
|
||||
BodyTrackingFeature.StartMotionTrackerCalibApp();
|
||||
#else
|
||||
PXR_MotionTracking.StartMotionTrackerCalibApp();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
// If not calibrated, invoked system motion tracker app for calibration.
|
||||
|
||||
}
|
||||
}
|
||||
init = false;
|
||||
return new TrackableChanges<XRHumanBody>(1, 0, 0, allocator);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new TrackableChanges<XRHumanBody>(0, 1, 0, allocator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void RegisterDescriptor()
|
||||
{
|
||||
PLog.i(k_SubsystemId, "RegisterDescriptor");
|
||||
#if AR_FOUNDATION_5
|
||||
var mXRHumanBodySubsystemCinfo = new XRHumanBodySubsystemCinfo
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
var mXRHumanBodySubsystemCinfo = new XRHumanBodySubsystemDescriptor.Cinfo
|
||||
#endif
|
||||
{
|
||||
id = k_SubsystemId,
|
||||
providerType = typeof(HumanBodyProvider),
|
||||
subsystemTypeOverride = typeof(PXR_HumanBodySubsystem),
|
||||
supportsHumanBody2D = false,
|
||||
supportsHumanBody3D = true,
|
||||
supportsHumanBody3DScaleEstimation = true,
|
||||
};
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
XRHumanBodySubsystemDescriptor.Register(mXRHumanBodySubsystemCinfo);
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_5
|
||||
if (!Register(mXRHumanBodySubsystemCinfo))
|
||||
{
|
||||
PLog.e(k_SubsystemId, $"Failed to register the {k_SubsystemId} subsystem.");
|
||||
}
|
||||
else
|
||||
{
|
||||
PLog.i(k_SubsystemId, $"success to register the {k_SubsystemId} subsystem.");
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b8f20b849cca864f824ae59d6db4891
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,47 @@
|
||||
#if AR_FOUNDATION_5 || AR_FOUNDATION_6
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARSubsystems;
|
||||
|
||||
public class PXR_RaycastSubsystem : XRRaycastSubsystem
|
||||
{
|
||||
internal const string k_SubsystemId = "PXR_RaycastSubsystem";
|
||||
|
||||
internal static PXR_RaycastSubsystem instance { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Do not call this directly. Call create on a valid <see cref="XRSessionSubsystemDescriptor"/> instead.
|
||||
/// </summary>
|
||||
public PXR_RaycastSubsystem()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
class RaycastProvider : Provider
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void RegisterDescriptor()
|
||||
{
|
||||
#if AR_FOUNDATION_5
|
||||
XRRaycastSubsystemDescriptor.RegisterDescriptor(new XRRaycastSubsystemDescriptor.Cinfo
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
XRRaycastSubsystemDescriptor.Register(new XRRaycastSubsystemDescriptor.Cinfo
|
||||
#endif
|
||||
{
|
||||
id = k_SubsystemId,
|
||||
providerType = typeof(RaycastProvider),
|
||||
subsystemTypeOverride = typeof(PXR_RaycastSubsystem),
|
||||
supportsViewportBasedRaycast = false,
|
||||
supportsWorldBasedRaycast = false,
|
||||
supportedTrackableTypes = TrackableType.PlaneWithinBounds,
|
||||
supportsTrackedRaycasts = false,
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0d33758f4e2801945954a5fca74e7894
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,106 @@
|
||||
#if AR_FOUNDATION_5 || AR_FOUNDATION_6
|
||||
using Unity.XR.PXR;
|
||||
using UnityEngine;
|
||||
using UnityEngine.XR.ARSubsystems;
|
||||
|
||||
public class PXR_SessionSubsystem : XRSessionSubsystem
|
||||
{
|
||||
internal const string k_SubsystemId = "PXR_SessionSubsystem";
|
||||
|
||||
internal static PXR_SessionSubsystem instance { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Do not call this directly. Call create on a valid <see cref="XRSessionSubsystemDescriptor"/> instead.
|
||||
/// </summary>
|
||||
public PXR_SessionSubsystem()
|
||||
{
|
||||
instance = this;
|
||||
}
|
||||
|
||||
internal void OnSessionStateChange(XrSessionState newState)
|
||||
=> ((SessionProvider)provider).OnSessionStateChange(newState);
|
||||
|
||||
class SessionProvider : Provider
|
||||
{
|
||||
XrSessionState m_SessionState;
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override TrackingState trackingState
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (m_SessionState)
|
||||
{
|
||||
case XrSessionState.Idle:
|
||||
case XrSessionState.Ready:
|
||||
case XrSessionState.Synchronized:
|
||||
return TrackingState.Limited;
|
||||
|
||||
case XrSessionState.Visible:
|
||||
case XrSessionState.Focused:
|
||||
return TrackingState.Tracking;
|
||||
|
||||
case XrSessionState.Unknown:
|
||||
case XrSessionState.Stopping:
|
||||
case XrSessionState.LossPending:
|
||||
case XrSessionState.Exiting:
|
||||
default:
|
||||
return TrackingState.None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override NotTrackingReason notTrackingReason
|
||||
{
|
||||
get
|
||||
{
|
||||
switch (m_SessionState)
|
||||
{
|
||||
case XrSessionState.Idle:
|
||||
case XrSessionState.Ready:
|
||||
case XrSessionState.Synchronized:
|
||||
return NotTrackingReason.Initializing;
|
||||
|
||||
case XrSessionState.Visible:
|
||||
case XrSessionState.Focused:
|
||||
return NotTrackingReason.None;
|
||||
|
||||
case XrSessionState.Unknown:
|
||||
case XrSessionState.Stopping:
|
||||
case XrSessionState.LossPending:
|
||||
case XrSessionState.Exiting:
|
||||
default:
|
||||
return NotTrackingReason.Unsupported;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void OnSessionStateChange(XrSessionState newState)
|
||||
{
|
||||
m_SessionState = newState;
|
||||
PLog.i(k_SubsystemId, $" OnSessionStateChange m_SessionState:{m_SessionState}");
|
||||
}
|
||||
}
|
||||
|
||||
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.SubsystemRegistration)]
|
||||
static void RegisterDescriptor()
|
||||
{
|
||||
#if AR_FOUNDATION_5
|
||||
XRSessionSubsystemDescriptor.RegisterDescriptor(new XRSessionSubsystemDescriptor.Cinfo
|
||||
#endif
|
||||
|
||||
#if AR_FOUNDATION_6
|
||||
XRSessionSubsystemDescriptor.Register(new XRSessionSubsystemDescriptor.Cinfo
|
||||
#endif
|
||||
{
|
||||
id = k_SubsystemId,
|
||||
providerType = typeof(SessionProvider),
|
||||
subsystemTypeOverride = typeof(PXR_SessionSubsystem),
|
||||
supportsInstall = false,
|
||||
supportsMatchFrameRate = false
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8ad7dc197117a6c429594221f005b844
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user